diff options
author | Tommi Komulainen <tko@litl.com> | 2009-08-25 10:31:36 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marcopg@litl.com> | 2010-07-27 22:04:22 (GMT) |
commit | 158f60dac9961a0ed044229b224b7943f3770957 (patch) | |
tree | d2642c85fae2677a81b3a4c3253e100344eaf445 | |
parent | 4665a2df604e22bdfe944ef0bd8104647fb81a66 (diff) |
browser-plugin: add title property to return the document title
Though as the document is loaded asynchronously the title might not
(yet) be properly set when accessed.
-rw-r--r-- | browser-plugin/scriptable.cpp | 27 | ||||
-rw-r--r-- | browser-plugin/scriptable.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/browser-plugin/scriptable.cpp b/browser-plugin/scriptable.cpp index d0c2854..2669cac 100644 --- a/browser-plugin/scriptable.cpp +++ b/browser-plugin/scriptable.cpp @@ -21,6 +21,7 @@ #include <scriptable.h> #include "plugin.h" +#include <string.h> void ScriptablePluginObjectBase::Invalidate () @@ -194,6 +195,8 @@ AllocateScriptablePluginObject (NPP npp, NPClass *aClass) ScriptablePluginObject::ScriptablePluginObject (NPP npp) : ScriptablePluginObjectBase (npp) { + mTitleID = NPN_GetStringIdentifier ("title"); + mZoomInID = NPN_GetStringIdentifier ("zoomIn"); mZoomOutID = NPN_GetStringIdentifier ("zoomOut"); mFindPreviousID = NPN_GetStringIdentifier ("findPrevious"); @@ -222,12 +225,36 @@ ScriptablePluginObject::HasMethod (NPIdentifier name) bool ScriptablePluginObject::HasProperty (NPIdentifier name) { + NPIdentifier properties[] = { + mTitleID + }; + + for (guint i = 0; i < G_N_ELEMENTS(properties); i++) { + if (name == properties[i]) { + return true; + } + } + return false; } bool ScriptablePluginObject::GetProperty (NPIdentifier name, NPVariant *result) { + Plugin *plugin = reinterpret_cast<Plugin*> (mNpp->pdata); + + if (name == mTitleID) { + if (plugin->mTitle) { + // STRINGZ_TO_NPVARIANT evaluates its argument twice.. + char *np_string = NPN_StrDup (plugin->mTitle); + STRINGZ_TO_NPVARIANT (np_string, *result); + } else { + NULL_TO_NPVARIANT (*result); + } + + return true; + } + return false; } diff --git a/browser-plugin/scriptable.h b/browser-plugin/scriptable.h index 1835191..0b9bf29 100644 --- a/browser-plugin/scriptable.h +++ b/browser-plugin/scriptable.h @@ -89,6 +89,8 @@ class ScriptablePluginObject : public ScriptablePluginObjectBase NPVariant *result); private: + NPIdentifier mTitleID; + NPIdentifier mZoomInID; NPIdentifier mZoomOutID; NPIdentifier mFindPreviousID; |