From 8fd406e9f728f7898dc6dd3d92fd796d3962e577 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Fri, 15 Jan 2010 11:26:46 -0500 Subject: [PATCH] Bug 539755 - Implement NPN_GetValueForURL, NPN_SetValueForURL, and NPN_GetAuthenticationInfo, r=bent --- dom/plugins/PPluginInstance.ipdl | 13 ++++++ dom/plugins/PluginInstanceParent.cpp | 55 ++++++++++++++++++++++ dom/plugins/PluginInstanceParent.h | 20 ++++++++ dom/plugins/PluginMessageUtils.h | 25 ++++++++++ dom/plugins/PluginModuleChild.cpp | 68 +++++++++++++++++++++++++--- 5 files changed, 175 insertions(+), 6 deletions(-) diff --git a/dom/plugins/PPluginInstance.ipdl b/dom/plugins/PPluginInstance.ipdl index a272dbdc74d..63491d48b4b 100644 --- a/dom/plugins/PPluginInstance.ipdl +++ b/dom/plugins/PPluginInstance.ipdl @@ -49,6 +49,7 @@ using NPError; using NPRemoteWindow; using NPRemoteEvent; using NPRect; +using NPNURLVariable; using mozilla::plugins::NativeWindowHandle; namespace mozilla { @@ -126,6 +127,18 @@ parent: rpc NPN_PopPopupsEnabledState() returns (bool aSuccess); + rpc NPN_GetValueForURL(NPNURLVariable variable, nsCString url) + returns (nsCString value, NPError result); + + rpc NPN_SetValueForURL(NPNURLVariable variable, nsCString url, + nsCString value) + returns (NPError result); + + rpc NPN_GetAuthenticationInfo(nsCString protocol_, nsCString host, + int32_t port, nsCString scheme, + nsCString realm) + returns (nsCString username, nsCString password, NPError result); + both: rpc PPluginScriptableObject(); diff --git a/dom/plugins/PluginInstanceParent.cpp b/dom/plugins/PluginInstanceParent.cpp index 8a75f32b400..b9825872ce5 100644 --- a/dom/plugins/PluginInstanceParent.cpp +++ b/dom/plugins/PluginInstanceParent.cpp @@ -747,6 +747,61 @@ PluginInstanceParent::AnswerNPN_PopPopupsEnabledState(bool* aSuccess) return true; } +bool +PluginInstanceParent::AnswerNPN_GetValueForURL(const NPNURLVariable& variable, + const nsCString& url, + nsCString* value, + NPError* result) +{ + char* v; + uint32_t len; + + *result = mNPNIface->getvalueforurl(mNPP, (NPNURLVariable) variable, + url.get(), &v, &len); + if (NPERR_NO_ERROR == *result) + value->Adopt(v, len); + + return true; +} + +bool +PluginInstanceParent::AnswerNPN_SetValueForURL(const NPNURLVariable& variable, + const nsCString& url, + const nsCString& value, + NPError* result) +{ + *result = mNPNIface->setvalueforurl(mNPP, (NPNURLVariable) variable, + url.get(), value.get(), + value.Length()); + return true; +} + +bool +PluginInstanceParent::AnswerNPN_GetAuthenticationInfo(const nsCString& protocol, + const nsCString& host, + const int32_t& port, + const nsCString& scheme, + const nsCString& realm, + nsCString* username, + nsCString* password, + NPError* result) +{ + char* u; + uint32_t ulen; + char* p; + uint32_t plen; + + *result = mNPNIface->getauthenticationinfo(mNPP, protocol.get(), + host.get(), port, + scheme.get(), realm.get(), + &u, &ulen, &p, &plen); + if (NPERR_NO_ERROR == result) { + username->Adopt(u, ulen); + password->Adopt(p, plen); + } + return true; +} + #if defined(OS_WIN) /* windowless drawing helpers */ diff --git a/dom/plugins/PluginInstanceParent.h b/dom/plugins/PluginInstanceParent.h index 45c81ec0229..a9eb905c102 100644 --- a/dom/plugins/PluginInstanceParent.h +++ b/dom/plugins/PluginInstanceParent.h @@ -161,6 +161,26 @@ public: virtual bool AnswerNPN_PopPopupsEnabledState(bool* aSuccess); + NS_OVERRIDE virtual bool + AnswerNPN_GetValueForURL(const NPNURLVariable& variable, + const nsCString& url, + nsCString* value, NPError* result); + + NS_OVERRIDE virtual bool + AnswerNPN_SetValueForURL(const NPNURLVariable& variable, + const nsCString& url, + const nsCString& value, NPError* result); + + NS_OVERRIDE virtual bool + AnswerNPN_GetAuthenticationInfo(const nsCString& protocol, + const nsCString& host, + const int32_t& port, + const nsCString& scheme, + const nsCString& realm, + nsCString* username, + nsCString* password, + NPError* result); + NPError NPP_SetWindow(const NPWindow* aWindow); NPError NPP_GetValue(NPPVariable variable, void *ret_value); diff --git a/dom/plugins/PluginMessageUtils.h b/dom/plugins/PluginMessageUtils.h index 5b277a12de4..b98e3215bb7 100644 --- a/dom/plugins/PluginMessageUtils.h +++ b/dom/plugins/PluginMessageUtils.h @@ -616,6 +616,31 @@ struct ParamTraits } }; +template<> +struct ParamTraits +{ + typedef NPNURLVariable paramType; + + static void Write(Message* aMsg, const paramType& aParam) + { + WriteParam(aMsg, int(aParam)); + } + + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) + { + int intval; + if (ReadParam(aMsg, aIter, &intval)) { + switch (intval) { + case NPNURLVCookie: + case NPNURLVProxy: + *aResult = paramType(intval); + return true; + } + } + return false; + } +}; + } /* namespace IPC */ diff --git a/dom/plugins/PluginModuleChild.cpp b/dom/plugins/PluginModuleChild.cpp index 5973bfb910e..1e8ab4c4912 100644 --- a/dom/plugins/PluginModuleChild.cpp +++ b/dom/plugins/PluginModuleChild.cpp @@ -1295,8 +1295,28 @@ _getvalueforurl(NPP npp, NPNURLVariable variable, const char *url, { PLUGIN_LOG_DEBUG_FUNCTION; AssertPluginThread(); - NS_NOTYETIMPLEMENTED("Implement me!"); - return NPERR_GENERIC_ERROR; + + if (!url) + return NPERR_INVALID_URL; + + if (!npp || !value || !len) + return NPERR_INVALID_PARAM; + + switch (variable) { + case NPNURLVCookie: + case NPNURLVProxy: + nsCString v; + NPError result; + InstCast(npp)-> + CallNPN_GetValueForURL(variable, nsCString(url), &v, &result); + if (NPERR_NO_ERROR == result) { + *value = ToNewCString(v); + *len = v.Length(); + } + return result; + } + + return NPERR_INVALID_PARAM; } NPError NP_CALLBACK @@ -1305,8 +1325,24 @@ _setvalueforurl(NPP npp, NPNURLVariable variable, const char *url, { PLUGIN_LOG_DEBUG_FUNCTION; AssertPluginThread(); - NS_NOTYETIMPLEMENTED("Implement me!"); - return NPERR_GENERIC_ERROR; + + if (!value) + return NPERR_INVALID_PARAM; + + if (!url) + return NPERR_INVALID_URL; + + switch (variable) { + case NPNURLVCookie: + case NPNURLVProxy: + NPError result; + InstCast(npp)->CallNPN_SetValueForURL(variable, nsCString(url), + nsDependentCString(value, len), + &result); + return result; + } + + return NPERR_INVALID_PARAM; } NPError NP_CALLBACK @@ -1318,8 +1354,28 @@ _getauthenticationinfo(NPP npp, const char *protocol, { PLUGIN_LOG_DEBUG_FUNCTION; AssertPluginThread(); - NS_NOTYETIMPLEMENTED("Implement me!"); - return NPERR_GENERIC_ERROR; + + if (!protocol || !host || !scheme || !realm || !username || !ulen || + !password || !plen) + return NPERR_INVALID_PARAM; + + nsCString u; + nsCString p; + NPError result; + InstCast(npp)-> + CallNPN_GetAuthenticationInfo(nsDependentCString(protocol), + nsDependentCString(host), + port, + nsDependentCString(scheme), + nsDependentCString(realm), + &u, &p, &result); + if (NPERR_NO_ERROR == result) { + *username = ToNewCString(u); + *ulen = u.Length(); + *password = ToNewCString(p); + *plen = p.Length(); + } + return result; } uint32_t NP_CALLBACK