Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser-plugin/scriptable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'browser-plugin/scriptable.cpp')
-rw-r--r--browser-plugin/scriptable.cpp262
1 files changed, 262 insertions, 0 deletions
diff --git a/browser-plugin/scriptable.cpp b/browser-plugin/scriptable.cpp
new file mode 100644
index 0000000..d44a053
--- /dev/null
+++ b/browser-plugin/scriptable.cpp
@@ -0,0 +1,262 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2009 litl, LLC
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <scriptable.h>
+
+#include "plugin.h"
+
+void
+ScriptablePluginObjectBase::Invalidate ()
+{
+}
+
+bool
+ScriptablePluginObjectBase::HasMethod (NPIdentifier name)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::Invoke (NPIdentifier name, const NPVariant *args,
+ uint32_t argCount, NPVariant *result)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::InvokeDefault (const NPVariant *args,
+ uint32_t argCount, NPVariant *result)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::HasProperty (NPIdentifier name)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::GetProperty (NPIdentifier name, NPVariant *result)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::SetProperty (NPIdentifier name,
+ const NPVariant *value)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::RemoveProperty (NPIdentifier name)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::Enumerate (NPIdentifier **identifier,
+ uint32_t *count)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObjectBase::Construct (const NPVariant *args, uint32_t argCount,
+ NPVariant *result)
+{
+ return false;
+}
+
+void
+ScriptablePluginObjectBase::_Deallocate (NPObject *npobj)
+{
+ delete (ScriptablePluginObjectBase *)npobj;
+}
+
+void
+ScriptablePluginObjectBase::_Invalidate (NPObject *npobj)
+{
+ ((ScriptablePluginObjectBase *)npobj)->Invalidate ();
+}
+
+bool
+ScriptablePluginObjectBase::_HasMethod (NPObject *npobj, NPIdentifier name)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->HasMethod (name);
+}
+
+bool
+ScriptablePluginObjectBase::_Invoke (NPObject *npobj, NPIdentifier name,
+ const NPVariant *args, uint32_t argCount,
+ NPVariant *result)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->Invoke (
+ name, args, argCount, result);
+}
+
+bool
+ScriptablePluginObjectBase::_InvokeDefault (NPObject *npobj,
+ const NPVariant *args,
+ uint32_t argCount,
+ NPVariant *result)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->InvokeDefault (
+ args, argCount, result);
+}
+
+bool
+ScriptablePluginObjectBase::_HasProperty (NPObject * npobj, NPIdentifier name)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->HasProperty (name);
+}
+
+bool
+ScriptablePluginObjectBase::_GetProperty (NPObject *npobj, NPIdentifier name,
+ NPVariant *result)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->GetProperty (name, result);
+}
+
+bool
+ScriptablePluginObjectBase::_SetProperty (NPObject *npobj, NPIdentifier name,
+ const NPVariant *value)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->SetProperty (name, value);
+}
+
+bool
+ScriptablePluginObjectBase::_RemoveProperty (NPObject *npobj, NPIdentifier name)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->RemoveProperty (name);
+}
+
+bool
+ScriptablePluginObjectBase::_Enumerate (NPObject *npobj,
+ NPIdentifier **identifier,
+ uint32_t *count)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->Enumerate(identifier, count);
+}
+
+bool
+ScriptablePluginObjectBase::_Construct (NPObject *npobj, const NPVariant *args,
+ uint32_t argCount, NPVariant *result)
+{
+ return ((ScriptablePluginObjectBase *)npobj)->Construct (
+ args, argCount, result);
+}
+
+NPObject *
+AllocateConstructablePluginObject (NPP npp, NPClass *aClass)
+{
+ return new ConstructablePluginObject (npp);
+}
+
+bool
+ConstructablePluginObject::Construct (const NPVariant *args, uint32_t argCount,
+ NPVariant *result)
+{
+ NPObject *myobj = NPN_CreateObject (
+ mNpp, GET_NPOBJECT_CLASS (ConstructablePluginObject));
+ if (!myobj) {
+ return false;
+ }
+
+ OBJECT_TO_NPVARIANT (myobj, *result);
+
+ return true;
+}
+
+NPObject *
+AllocateScriptablePluginObject (NPP npp, NPClass *aClass)
+{
+ return new ScriptablePluginObject (npp);
+}
+
+ScriptablePluginObject::ScriptablePluginObject (NPP npp) :
+ ScriptablePluginObjectBase (npp)
+{
+ mZoomInID = NPN_GetStringIdentifier ("zoomIn");
+ mZoomOutID = NPN_GetStringIdentifier ("zoomOut");
+ mFindPreviousID = NPN_GetStringIdentifier ("findPrevious");
+ mFindNextID = NPN_GetStringIdentifier ("findNext");
+}
+
+bool
+ScriptablePluginObject::HasMethod (NPIdentifier name)
+{
+ NPIdentifier methods[] = {
+ mZoomInID,
+ mZoomOutID,
+ mFindPreviousID,
+ mFindNextID
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS(methods); i++) {
+ if (name == methods[i]) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+ScriptablePluginObject::HasProperty (NPIdentifier name)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObject::GetProperty (NPIdentifier name, NPVariant *result)
+{
+ return false;
+}
+
+bool
+ScriptablePluginObject::Invoke (NPIdentifier name, const NPVariant *args,
+ uint32_t argCount, NPVariant *result)
+{
+ Plugin *plugin = reinterpret_cast<Plugin*> (mNpp->pdata);
+
+ if (name == mZoomInID) {
+ plugin->ZoomIn ();
+ } else if (name == mZoomOutID) {
+ plugin->ZoomOut ();
+ } else if (name == mFindNextID) {
+ if (argCount < 1 || !NPVARIANT_IS_STRING (args[0])) {
+ return false;
+ }
+ plugin->FindNext (NPVARIANT_TO_STRING (args[0]).utf8characters);
+ } else if (name == mFindPreviousID) {
+ if (argCount < 1 || !NPVARIANT_IS_STRING (args[0])) {
+ return false;
+ }
+ plugin->FindPrevious(NPVARIANT_TO_STRING (args[0]).utf8characters);
+ }
+}
+
+bool
+ScriptablePluginObject::InvokeDefault (const NPVariant *args, uint32_t argCount,
+ NPVariant *result)
+{
+ return false;
+}