Bug 517207 - Implement NPN_GetValue, r?bent. I use separate messages for each getvalue property instead of an integer/enumeration and a variant because for each message, the type returned is static: this avoids a lot of dynamic checking for correct enumeration values and variant types. r=bent
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 15 Sep 2009 16:33:24 -0400
changeset 35923 975893837c9bab44054a23ca116738370ef76656
parent 35922 cb6ed6132f0e95bdd92dfa4517d5a604f61e2ab5
child 35924 83d438dfacf9b03c62cf02c4fd8961ece9f1bcfc
push id10694
push userbsmedberg@mozilla.com
push dateMon, 14 Dec 2009 15:23:10 +0000
treeherderautoland@683dfdc4adf0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, bent
bugs517207
milestone1.9.3a1pre
Bug 517207 - Implement NPN_GetValue, r?bent. I use separate messages for each getvalue property instead of an integer/enumeration and a variant because for each message, the type returned is static: this avoids a lot of dynamic checking for correct enumeration values and variant types. r=bent
dom/plugins/PPluginInstance.ipdl
dom/plugins/PluginInstanceChild.cpp
dom/plugins/PluginInstanceParent.cpp
dom/plugins/PluginInstanceParent.h
--- a/dom/plugins/PPluginInstance.ipdl
+++ b/dom/plugins/PPluginInstance.ipdl
@@ -101,16 +101,27 @@ child:
              uint16_t stype);
 
   rpc NPP_SetWindow(NPWindow window)
     returns (NPError rv);
   rpc NPP_GetValue(nsString key)
     returns (nsString value);
 
 parent:
+  rpc NPN_GetValue_NPNVjavascriptEnabledBool()
+    returns (bool value, NPError result);
+  rpc NPN_GetValue_NPNVisOfflineBool()
+    returns (bool value, NPError result);
+  rpc NPN_GetValue_NPNVWindowNPObject()
+    returns (PPluginScriptableObject value, NPError result);
+  rpc NPN_GetValue_NPNVPluginElementNPObject()
+    returns (PPluginScriptableObject value, NPError result);
+  rpc NPN_GetValue_NPNVprivateModeBool()
+    returns (bool value, NPError result);
+
   rpc NPN_GetURL(nsCString url, nsCString target)
     returns (NPError result);
   rpc NPN_PostURL(nsCString url, nsCString target, nsCString buffer, bool file)
     returns (NPError result);
 
   /**
    * Covers both NPN_GetURLNotify and NPN_PostURLNotify.
    * @TODO This would be more readable as an overloaded method,
--- a/dom/plugins/PluginInstanceChild.cpp
+++ b/dom/plugins/PluginInstanceChild.cpp
@@ -122,16 +122,40 @@ PluginInstanceChild::NPN_GetValue(NPNVar
     case NPNVToolkit:
         *((NPNToolkitType*)aValue) = NPNVGtk2;
         return NPERR_NO_ERROR;
 
 #elif defined(OS_WIN)
     case NPNVToolkit:
         return NPERR_GENERIC_ERROR;
 #endif
+    case NPNVjavascriptEnabledBool: {
+        bool v = false;
+        NPError result;
+        CallNPN_GetValue_NPNVjavascriptEnabledBool(&v, &result);
+        *static_cast<NPBool*>(aValue) = v;
+        return result;
+    }
+
+    case NPNVisOfflineBool: {
+        bool v = false;
+        NPError result;
+        CallNPN_GetValue_NPNVisOfflineBool(&v, &result);
+        *static_cast<NPBool*>(aValue) = v;
+        return result;
+    }
+
+    case NPNVprivateModeBool: {
+        bool v = false;
+        NPError result;
+        CallNPN_GetValue_NPNVprivateModeBool(&v, &result);
+        *static_cast<NPBool*>(aValue) = v;
+        return result;
+    }
+
     default:
         printf("  unhandled var %s\n", NPNVariableToString(aVar));
         return NPERR_GENERIC_ERROR;   
     }
 
 }
 
 nsresult
--- a/dom/plugins/PluginInstanceParent.cpp
+++ b/dom/plugins/PluginInstanceParent.cpp
@@ -74,35 +74,86 @@ PluginInstanceParent::PBrowserStreamDest
                                                const NPError& reason,
                                                const bool& artificial)
 {
     delete stream;
     return NS_OK;
 }
 
 nsresult
+PluginInstanceParent::AnswerNPN_GetValue_NPNVjavascriptEnabledBool(
+                                                       bool* value,
+                                                       NPError* result)
+{
+    NPBool v;
+    *result = mNPNIface->getvalue(mNPP, NPNVjavascriptEnabledBool, &v);
+    *value = v;
+    return NS_OK;
+}
+
+nsresult
+PluginInstanceParent::AnswerNPN_GetValue_NPNVisOfflineBool(bool* value,
+                                                           NPError* result)
+{
+    NPBool v;
+    *result = mNPNIface->getvalue(mNPP, NPNVisOfflineBool, &v);
+    *value = v;
+    return NS_OK;
+}
+
+nsresult
+PluginInstanceParent::AnswerNPN_GetValue_NPNVWindowNPObject(
+                                        PPluginScriptableObjectParent** value,
+                                        NPError* result)
+{
+    // TODO NPRuntime
+    *value = NULL;
+    *result = NPERR_GENERIC_ERROR;
+    return NS_OK;
+}
+
+nsresult
+PluginInstanceParent::AnswerNPN_GetValue_NPNVPluginElementNPObject(
+                                        PluginInstanceParent::PPluginScriptableObjectParent** value,
+                                        NPError* result)
+{
+    // TODO NPRuntime
+    *value = NULL;
+    *result = NPERR_GENERIC_ERROR;
+    return NS_OK;
+}
+
+nsresult
+PluginInstanceParent::AnswerNPN_GetValue_NPNVprivateModeBool(bool* value,
+                                                             NPError* result)
+{
+    NPBool v;
+    *result = mNPNIface->getvalue(mNPP, NPNVprivateModeBool, &v);
+    *value = v;
+    return NS_OK;
+}
+
+nsresult
 PluginInstanceParent::AnswerNPN_GetURL(const nsCString& url,
                                        const nsCString& target,
                                        NPError* result)
 {
     *result = mNPNIface->geturl(mNPP, url.get(), target.get());
-    // TODO: what if the method fails?
     return NS_OK;
 }
 
 nsresult
 PluginInstanceParent::AnswerNPN_PostURL(const nsCString& url,
                                         const nsCString& target,
                                         const nsCString& buffer,
                                         const bool& file,
                                         NPError* result)
 {
     *result = mNPNIface->posturl(mNPP, url.get(), target.get(),
                                  buffer.Length(), buffer.get(), file);
-    // TODO: what if the method fails?
     return NS_OK;
 }
 
 PStreamNotifyParent*
 PluginInstanceParent::PStreamNotifyConstructor(const nsCString& url,
                                                const nsCString& target,
                                                const bool& post,
                                                const nsCString& buffer,
--- a/dom/plugins/PluginInstanceParent.h
+++ b/dom/plugins/PluginInstanceParent.h
@@ -63,22 +63,17 @@ public:
         : mNPP(npp)
         , mNPNIface(npniface)
     {
     }
 
     virtual ~PluginInstanceParent()
     {
     }
-
-    virtual nsresult AnswerNPN_GetValue(const nsString& in, nsString* out)
-    {
-        return NS_OK;
-    }
-
+  
     virtual PPluginScriptableObjectParent*
     PPluginScriptableObjectConstructor(NPError* _retval);
 
     virtual nsresult
     PPluginScriptableObjectDestructor(PPluginScriptableObjectParent* aObject,
                                       NPError* _retval);
 
     virtual PBrowserStreamParent*
@@ -98,16 +93,31 @@ public:
                                    const bool& artificial);
 
     virtual nsresult
     PBrowserStreamDestructor(PBrowserStreamParent* stream,
                              const NPError& reason,
                              const bool& artificial);
 
     virtual nsresult
+    AnswerNPN_GetValue_NPNVjavascriptEnabledBool(bool* value, NPError* result);
+    virtual nsresult
+    AnswerNPN_GetValue_NPNVisOfflineBool(bool* value, NPError* result);
+    virtual nsresult
+    AnswerNPN_GetValue_NPNVWindowNPObject(
+                                       PPluginScriptableObjectParent** value,
+                                       NPError* result);
+    virtual nsresult
+    AnswerNPN_GetValue_NPNVPluginElementNPObject(
+                                       PPluginScriptableObjectParent** value,
+                                       NPError* result);
+    virtual nsresult
+    AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result);
+
+    virtual nsresult
     AnswerNPN_GetURL(const nsCString& url, const nsCString& target,
                      NPError *result);
 
     virtual nsresult
     AnswerNPN_PostURL(const nsCString& url, const nsCString& target,
                       const nsCString& buffer, const bool& file,
                       NPError* result);