Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EvBrowserPluginMain.cpp File Reference
#include "config.h"
#include "EvBrowserPlugin.h"
#include "EvMemoryUtils.h"
#include "npfunctions.h"
#include "npruntime.h"
#include <gdk/gdk.h>
+ Include dependency graph for EvBrowserPluginMain.cpp:

Go to the source code of this file.

Functions

static EvBrowserPluginpluginForInstance (NPP instance)
 
NPError NPP_New (NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *savedData)
 
NPError NPP_Destroy (NPP instance, NPSavedData **saveData)
 
NPError NPP_SetWindow (NPP instance, NPWindow *window)
 
NPError NPP_NewStream (NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype)
 
NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPReason reason)
 
void NPP_StreamAsFile (NPP instance, NPStream *stream, const char *fname)
 
int32_t NPP_WriteReady (NPP instance, NPStream *stream)
 
int32_t NPP_Write (NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
 
void NPP_Print (NPP instance, NPPrint *platformPrint)
 
int16_t NPP_HandleEvent (NPP instance, void *event)
 
void NPP_URLNotify (NPP instance, const char *url, NPReason reason, void *notifyData)
 
NPError NPP_GetValue (NPP instance, NPPVariable variable, void *value)
 
NPError NPP_SetValue (NPP, NPNVariable, void *)
 
static void initializePluginFuncs (NPPluginFuncs *pluginFuncs)
 
NPError NP_Initialize (NPNetscapeFuncs *browserFuncs, NPPluginFuncs *pluginFuncs)
 
NPError NP_Shutdown ()
 
const char * NP_GetMIMEDescription ()
 
NPError NP_GetValue (void *, NPPVariable variable, void *value)
 
NPObjectNPN_CreateObject (NPP instance, NPClass *npClass)
 
void NPN_GetStringIdentifiers (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
 
NPError NPN_GetURL (NPP instance, const char *url, const char *target)
 
const char * NPN_UserAgent (NPP instance)
 
void * NPN_MemAlloc (uint32_t size)
 
void NPN_MemFree (void *ptr)
 
static void __attribute__ ((constructor)) browserPluginConstructor()
 
static void __attribute__ ((destructor)) browserPluginDestructor()
 

Variables

static NPNetscapeFuncsbrowser
 
static unique_gptr< char > mimeDescription
 
struct {
   const char *   mime
 
   const char *   extensions
 
mimeExtensions []
 

Function Documentation

static void __attribute__ ( (constructor)  )
static

Definition at line 354 of file EvBrowserPluginMain.cpp.

355 {
356  ev_init();
357 }
static void __attribute__ ( (destructor)  )
static

Definition at line 359 of file EvBrowserPluginMain.cpp.

360 {
361  ev_shutdown();
362 }
static void initializePluginFuncs ( NPPluginFuncs pluginFuncs)
static

Definition at line 173 of file EvBrowserPluginMain.cpp.

174 {
175  pluginFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
176  pluginFuncs->size = sizeof(pluginFuncs);
177  pluginFuncs->newp = NPP_New;
178  pluginFuncs->destroy = NPP_Destroy;
179  pluginFuncs->setwindow = NPP_SetWindow;
180  pluginFuncs->newstream = NPP_NewStream;
181  pluginFuncs->destroystream = NPP_DestroyStream;
182  pluginFuncs->asfile = NPP_StreamAsFile;
183  pluginFuncs->writeready = NPP_WriteReady;
184  pluginFuncs->write = NPP_Write;
185  pluginFuncs->print = NPP_Print;
186  pluginFuncs->event = NPP_HandleEvent;
187  pluginFuncs->urlnotify = NPP_URLNotify;
188  pluginFuncs->getvalue = NPP_GetValue;
189  pluginFuncs->setvalue = NPP_SetValue;
190 }

+ Here is the caller graph for this function:

const char* NP_GetMIMEDescription ( )

Definition at line 271 of file EvBrowserPluginMain.cpp.

272 {
273  if (mimeDescription)
274  return mimeDescription.get();
275 
276  if (!ev_init())
277  return nullptr;
278 
279 #ifdef GDK_WINDOWING_WAYLAND
280  if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()))
281  return nullptr;
282 #endif
283 
284  GString *mimeDescriptionStr = g_string_new(nullptr);
285 
286  GList *typesInfo = ev_backends_manager_get_all_types_info();
287  for (GList *l = typesInfo; l; l = g_list_next(l)) {
288  EvTypeInfo *info = static_cast<EvTypeInfo *>(l->data);
289 
290  for (unsigned i = 0; info->mime_types[i]; ++i) {
291  const char *extensions = [](const char *mime) -> const char * {
292  for (unsigned i = 0; i < G_N_ELEMENTS(mimeExtensions); ++i) {
293  if (g_ascii_strcasecmp(mimeExtensions[i].mime, mime) == 0)
294  return mimeExtensions[i].extensions;
295  }
296 
297  return nullptr;
298  }(info->mime_types[i]);
299 
300  if (!extensions)
301  continue;
302 
303  g_string_append_printf(mimeDescriptionStr, "%s:%s:%s;",
304  info->mime_types[i],
305  extensions,
306  info->desc);
307  }
308  }
309  g_list_free(typesInfo);
310 
311  mimeDescription.reset(g_string_free(mimeDescriptionStr, FALSE));
312 
313  ev_shutdown();
314 
315  return mimeDescription.get();
316 }
NPError NP_GetValue ( void *  ,
NPPVariable  variable,
void *  value 
)

Definition at line 318 of file EvBrowserPluginMain.cpp.

319 {
320  return NPP_GetValue(nullptr, variable, value);
321 }
NPError NP_Initialize ( NPNetscapeFuncs browserFuncs,
NPPluginFuncs pluginFuncs 
)

Definition at line 192 of file EvBrowserPluginMain.cpp.

193 {
194  if (!browserFuncs || !pluginFuncs)
196 
197  if ((browserFuncs->version >> 8) > NP_VERSION_MAJOR)
199 
200  if (!ev_init())
201  return NPERR_GENERIC_ERROR;
202 
203  gtk_init(nullptr, nullptr);
204 
205 #ifdef GDK_WINDOWING_WAYLAND
206  if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()))
207  return NPERR_GENERIC_ERROR;
208 #endif
209 
210  browser = browserFuncs;
211  initializePluginFuncs(pluginFuncs);
212 
213  GBytes *resourceData = g_resources_lookup_data("/org/gnome/evince/browser/ui/evince-browser.css", G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr);
214  if (resourceData) {
215  GtkCssProvider *cssProvider = gtk_css_provider_new();
216 
217  gtk_css_provider_load_from_data(cssProvider, static_cast<const gchar *>(g_bytes_get_data(resourceData, nullptr)), g_bytes_get_size(resourceData), nullptr);
218  g_bytes_unref(resourceData);
219 
220  gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
221  g_object_unref(cssProvider);
222  }
223 
224  return NPERR_NO_ERROR;
225 }
NPError NP_Shutdown ( )

Definition at line 227 of file EvBrowserPluginMain.cpp.

228 {
229  ev_shutdown();
230  return NPERR_NO_ERROR;
231 }
NPObject* NPN_CreateObject ( NPP  instance,
NPClass npClass 
)

Definition at line 323 of file EvBrowserPluginMain.cpp.

324 {
325  return browser->createobject(instance, npClass);
326 }

+ Here is the caller graph for this function:

void NPN_GetStringIdentifiers ( const NPUTF8 **  names,
int32_t  nameCount,
NPIdentifier identifiers 
)

Definition at line 328 of file EvBrowserPluginMain.cpp.

329 {
330  browser->getstringidentifiers(names, nameCount, identifiers);
331 }

+ Here is the caller graph for this function:

NPError NPN_GetURL ( NPP  instance,
const char *  url,
const char *  target 
)

Definition at line 333 of file EvBrowserPluginMain.cpp.

334 {
335  return browser->geturl(instance, url, target);
336 }

+ Here is the caller graph for this function:

void* NPN_MemAlloc ( uint32_t  size)

Definition at line 343 of file EvBrowserPluginMain.cpp.

344 {
345  return browser->memalloc(size);
346 }

+ Here is the caller graph for this function:

void NPN_MemFree ( void *  ptr)

Definition at line 348 of file EvBrowserPluginMain.cpp.

349 {
350  if (ptr)
351  browser->memfree(ptr);
352 }
const char* NPN_UserAgent ( NPP  instance)

Definition at line 338 of file EvBrowserPluginMain.cpp.

339 {
340  return browser->uagent(instance);
341 }

+ Here is the caller graph for this function:

NPError NPP_Destroy ( NPP  instance,
NPSavedData **  saveData 
)

Definition at line 49 of file EvBrowserPluginMain.cpp.

50 {
51  EvBrowserPlugin *plugin = pluginForInstance(instance);
52  if (!plugin)
54 
55  browser->releaseobject(static_cast<NPObject *>(plugin));
56  return NPERR_NO_ERROR;
57 }

+ Here is the caller graph for this function:

NPError NPP_DestroyStream ( NPP  instance,
NPStream stream,
NPReason  reason 
)

Definition at line 77 of file EvBrowserPluginMain.cpp.

78 {
79  EvBrowserPlugin *plugin = pluginForInstance(instance);
80  if (!plugin)
82 
83  return plugin->destroyStream(stream, reason);
84 }

+ Here is the caller graph for this function:

NPError NPP_GetValue ( NPP  instance,
NPPVariable  variable,
void *  value 
)

Definition at line 140 of file EvBrowserPluginMain.cpp.

141 {
142  switch (variable) {
144  *((char **)value) = const_cast<char *>(EvBrowserPlugin::nameString());
145  return NPERR_NO_ERROR;
147  *((char **)value) = const_cast<char *>(EvBrowserPlugin::descriptionString());
148  return NPERR_NO_ERROR;
150  *((NPBool *)value) = TRUE;
151  return NPERR_NO_ERROR;
153  EvBrowserPlugin *plugin = pluginForInstance(instance);
154  if (!plugin)
156 
157  browser->retainobject(static_cast<NPObject *>(plugin));
158  *((NPObject **)value) = plugin;
159  return NPERR_NO_ERROR;
160  }
161  default:
162  return NPERR_INVALID_PARAM;
163  }
164 
165  return NPERR_GENERIC_ERROR;
166 }

+ Here is the caller graph for this function:

int16_t NPP_HandleEvent ( NPP  instance,
void *  event 
)

Definition at line 122 of file EvBrowserPluginMain.cpp.

123 {
124  EvBrowserPlugin *plugin = pluginForInstance(instance);
125  if (!plugin)
126  return 0;
127 
128  return plugin->handleEvent(static_cast<XEvent *>(event));
129 }

+ Here is the caller graph for this function:

NPError NPP_New ( NPMIMEType  pluginType,
NPP  instance,
uint16_t  mode,
int16_t  argc,
char *  argn[],
char *  argv[],
NPSavedData savedData 
)

Definition at line 41 of file EvBrowserPluginMain.cpp.

42 {
43  if (!instance)
45 
46  return EvBrowserPlugin::create(instance)->initialize(pluginType, mode, argc, argn, argv, savedData);
47 }

+ Here is the caller graph for this function:

NPError NPP_NewStream ( NPP  instance,
NPMIMEType  type,
NPStream stream,
NPBool  seekable,
uint16_t *  stype 
)

Definition at line 68 of file EvBrowserPluginMain.cpp.

69 {
70  EvBrowserPlugin *plugin = pluginForInstance(instance);
71  if (!plugin)
73 
74  return plugin->newStream(type, stream, seekable, stype);
75 }

+ Here is the caller graph for this function:

void NPP_Print ( NPP  instance,
NPPrint platformPrint 
)

Definition at line 113 of file EvBrowserPluginMain.cpp.

114 {
115  EvBrowserPlugin *plugin = pluginForInstance(instance);
116  if (!plugin)
117  return;
118 
119  return plugin->print(platformPrint);
120 }

+ Here is the caller graph for this function:

NPError NPP_SetValue ( NPP  ,
NPNVariable  ,
void *   
)

Definition at line 168 of file EvBrowserPluginMain.cpp.

169 {
170  return NPERR_NO_ERROR;
171 }

+ Here is the caller graph for this function:

NPError NPP_SetWindow ( NPP  instance,
NPWindow window 
)

Definition at line 59 of file EvBrowserPluginMain.cpp.

60 {
61  EvBrowserPlugin *plugin = pluginForInstance(instance);
62  if (!plugin)
64 
65  return plugin->setWindow(window);
66 }

+ Here is the caller graph for this function:

void NPP_StreamAsFile ( NPP  instance,
NPStream stream,
const char *  fname 
)

Definition at line 86 of file EvBrowserPluginMain.cpp.

87 {
88  EvBrowserPlugin *plugin = pluginForInstance(instance);
89  if (!plugin)
90  return;
91 
92  return plugin->streamAsFile(stream, fname);
93 }

+ Here is the caller graph for this function:

void NPP_URLNotify ( NPP  instance,
const char *  url,
NPReason  reason,
void *  notifyData 
)

Definition at line 131 of file EvBrowserPluginMain.cpp.

132 {
133  EvBrowserPlugin *plugin = pluginForInstance(instance);
134  if (!plugin)
135  return;
136 
137  return plugin->urlNotify(url, reason, notifyData);
138 }

+ Here is the caller graph for this function:

int32_t NPP_Write ( NPP  instance,
NPStream stream,
int32_t  offset,
int32_t  len,
void *  buffer 
)

Definition at line 104 of file EvBrowserPluginMain.cpp.

105 {
106  EvBrowserPlugin *plugin = pluginForInstance(instance);
107  if (!plugin)
108  return -1;
109 
110  return plugin->write(stream, offset, len, buffer);
111 }

+ Here is the caller graph for this function:

int32_t NPP_WriteReady ( NPP  instance,
NPStream stream 
)

Definition at line 95 of file EvBrowserPluginMain.cpp.

96 {
97  EvBrowserPlugin *plugin = pluginForInstance(instance);
98  if (!plugin)
99  return -1;
100 
101  return plugin->writeReady(stream);
102 }

+ Here is the caller graph for this function:

static EvBrowserPlugin* pluginForInstance ( NPP  instance)
static

Definition at line 33 of file EvBrowserPluginMain.cpp.

34 {
35  if (!instance)
36  return nullptr;
37 
38  return static_cast<EvBrowserPlugin *>(instance->pdata);
39 }

+ Here is the caller graph for this function:

Variable Documentation

NPNetscapeFuncs* browser
static

Definition at line 30 of file EvBrowserPluginMain.cpp.

const char* extensions

Definition at line 235 of file EvBrowserPluginMain.cpp.

const char* mime

Definition at line 234 of file EvBrowserPluginMain.cpp.

unique_gptr<char> mimeDescription
static

Definition at line 31 of file EvBrowserPluginMain.cpp.

struct { ... } mimeExtensions[]