Bug 622199: Add support for NPNVdocumentOrigin, ability to pass document origin directly to NPAPI plugins. r=bz

This commit is contained in:
Josh Aas 2011-09-14 12:22:27 -04:00
Родитель adb219fade
Коммит 6d7d90d75c
10 изменённых файлов: 136 добавлений и 2 удалений

Просмотреть файл

@ -70,11 +70,14 @@
#include "nsIDOMDocument.h"
#include "nsPIDOMWindow.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIUnicodeNormalizer.h"
#include "nsDOMJSUtils.h"
#include "nsIPrincipal.h"
#include "nsWildCard.h"
#include "nsContentUtils.h"
#include "nsIXPConnect.h"
@ -2159,6 +2162,46 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
return NPERR_GENERIC_ERROR;
}
case NPNVdocumentOrigin: {
nsNPAPIPluginInstance *inst = (nsNPAPIPluginInstance *)npp->ndata;
if (!inst) {
return NPERR_GENERIC_ERROR;
}
nsCOMPtr<nsIDOMElement> element;
inst->GetDOMElement(getter_AddRefs(element));
if (!element) {
return NPERR_GENERIC_ERROR;
}
nsCOMPtr<nsIContent> content(do_QueryInterface(element));
if (!content) {
return NPERR_GENERIC_ERROR;
}
nsIPrincipal* principal = content->NodePrincipal();
nsAutoString utf16Origin;
res = nsContentUtils::GetUTFOrigin(principal, utf16Origin);
if (NS_FAILED(res)) {
return NPERR_GENERIC_ERROR;
}
nsCOMPtr<nsIUnicodeNormalizer> normalizer = do_GetService(NS_UNICODE_NORMALIZER_CONTRACTID);
if (!normalizer) {
return NPERR_GENERIC_ERROR;
}
nsAutoString normalizedUTF16Origin;
res = normalizer->NormalizeUnicodeNFKC(utf16Origin, normalizedUTF16Origin);
if (NS_FAILED(res)) {
return NPERR_GENERIC_ERROR;
}
*(char**)result = ToNewUTF8String(normalizedUTF16Origin);
return *(char**)result ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
}
#ifdef XP_MACOSX
case NPNVpluginDrawingModel: {
if (npp) {

Просмотреть файл

@ -171,6 +171,8 @@ parent:
returns (bool value, NPError result);
rpc NPN_GetValue_NPNVnetscapeWindow()
returns (NativeWindowHandle value, NPError result);
rpc NPN_GetValue_NPNVdocumentOrigin()
returns (nsCString value, NPError result);
rpc NPN_SetValue_NPPVpluginWindow(bool windowed)
returns (NPError result);

Просмотреть файл

@ -359,6 +359,18 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
return result;
}
case NPNVdocumentOrigin: {
nsCString v;
NPError result;
if (!CallNPN_GetValue_NPNVdocumentOrigin(&v, &result)) {
return NPERR_GENERIC_ERROR;
}
if (result == NPERR_NO_ERROR) {
*static_cast<char**>(aValue) = ToNewCString(v);
}
return result;
}
case NPNVWindowNPObject: // Intentional fall-through
case NPNVPluginElementNPObject: {
NPObject* object;

Просмотреть файл

@ -341,6 +341,18 @@ PluginInstanceParent::AnswerNPN_GetValue_NPNVprivateModeBool(bool* value,
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value,
NPError* result)
{
void *v = nsnull;
*result = mNPNIface->getvalue(mNPP, NPNVdocumentOrigin, &v);
if (*result == NPERR_NO_ERROR && v) {
value->Adopt(static_cast<char*>(v));
}
return true;
}
bool
PluginInstanceParent::AnswerNPN_SetValue_NPPVpluginWindow(
const bool& windowed, NPError* result)

Просмотреть файл

@ -130,6 +130,9 @@ public:
NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result);
virtual bool
AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value, NPError* result);
virtual bool
AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result);

Просмотреть файл

@ -213,6 +213,7 @@ NPNVariableToString(NPNVariable aVar)
VARSTR(NPNVSupportsWindowless);
VARSTR(NPNVprivateModeBool);
VARSTR(NPNVdocumentOrigin);
default: return "???";
}

Просмотреть файл

@ -102,6 +102,7 @@ _MOCHITEST_FILES = \
test_zero_opacity.html \
test_NPPVpluginWantsAllNetworkStreams.html \
test_npruntime_npnsetexception.html \
test_NPNVdocumentOrigin.html \
$(NULL)
# test_plugin_scroll_painting.html \ bug 596491

Просмотреть файл

@ -0,0 +1,34 @@
<html>
<head>
<title>Test NPNVdocumentOrigin</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body onload="runTest()">
<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
function runTest() {
var p1 = document.getElementById("plugin1");
var realOrigin = "http://mochi.test:8888";
// Test with no modifications
is(p1.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin.");
// Mess with window.location.toString
window.location.toString = function() { return 'http://victim.rckc.at/'; }
is(p1.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin afer modifying window.location.toString.");
// Create a plugin in a new window with about:blank
var newWindow = window.open("about:blank");
newWindow.document.writeln('<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>');
var p2 = newWindow.document.getElementById("plugin2");
is(p2.getNPNVdocumentOrigin(), realOrigin, "Checking for expected origin of plugin in new about:blank window.");
newWindow.close();
SimpleTest.finish();
}
</script>
</body>
</html>

Просмотреть файл

@ -37,6 +37,10 @@ Hands back an object which reflects properties as values, e.g.
.getReflector()['foo'] = 'foo'
.getReflector()[1] = 1
* .getNPNVdocumentOrigin()
Returns the origin string retrieved from the browser by a NPNVdocumentOrigin
variable request. Does not cache the value, gets it from the browser every time.
== NPN_ConvertPoint testing ==
* convertPointX(sourceSpace, sourceX, sourceY, destSpace)

Просмотреть файл

@ -167,6 +167,7 @@ static bool constructObject(NPObject* npobj, const NPVariant* args, uint32_t arg
static bool setSitesWithData(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool getNPNVdocumentOrigin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest",
@ -225,7 +226,8 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"constructObject",
"setSitesWithData",
"setSitesWithDataCapabilities",
"getLastKeyText"
"getLastKeyText",
"getNPNVdocumentOrigin"
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[] = {
@ -285,7 +287,8 @@ static const ScriptableFunction sPluginMethodFunctions[] = {
constructObject,
setSitesWithData,
setSitesWithDataCapabilities,
getLastKeyText
getLastKeyText,
getNPNVdocumentOrigin
};
STATIC_ASSERT(ARRAY_LENGTH(sPluginMethodIdentifierNames) ==
@ -3474,3 +3477,22 @@ bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount,
STRINGZ_TO_NPVARIANT(NPN_StrDup(id->lastKeyText.c_str()), *result);
return true;
}
bool getNPNVdocumentOrigin(NPObject* npobj, const NPVariant* args, uint32_t argCount,
NPVariant* result)
{
if (argCount != 0) {
return false;
}
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
char *origin = NULL;
NPError err = NPN_GetValue(npp, NPNVdocumentOrigin, &origin);
if (err != NPERR_NO_ERROR) {
return false;
}
STRINGZ_TO_NPVARIANT(origin, *result);
return true;
}