Bug 660989: Make NPPVpluginWantsAllNetworkStreams work with OOP plugins. r=bsmedberg

This commit is contained in:
Josh Aas 2011-06-08 16:20:53 -04:00
Родитель 2e74a2965d
Коммит eec45c690e
12 изменённых файлов: 145 добавлений и 16 удалений

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

@ -2304,11 +2304,6 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
return inst->SetCached(bCached);
}
case NPPVpluginWantsAllNetworkStreams: {
PRBool bWantsAllNetworkStreams = (result != nsnull);
return inst->SetWantsAllNetworkStreams(bWantsAllNetworkStreams);
}
case NPPVpluginUsesDOMForCursorBool: {
PRBool useDOMForCursor = (result != nsnull);
return inst->SetUsesDOMForCursor(useDOMForCursor);

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

@ -82,7 +82,6 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(nsNPAPIPlugin* plugin)
mWindowlessLocal(PR_FALSE),
mTransparent(PR_FALSE),
mCached(PR_FALSE),
mWantsAllNetworkStreams(PR_FALSE),
mUsesDOMForCursor(PR_FALSE),
mInPluginInitCall(PR_FALSE),
mPlugin(plugin),
@ -680,12 +679,6 @@ NPError nsNPAPIPluginInstance::SetTransparent(PRBool aTransparent)
return NPERR_NO_ERROR;
}
NPError nsNPAPIPluginInstance::SetWantsAllNetworkStreams(PRBool aWantsAllNetworkStreams)
{
mWantsAllNetworkStreams = aWantsAllNetworkStreams;
return NPERR_NO_ERROR;
}
NPError nsNPAPIPluginInstance::SetUsesDOMForCursor(PRBool aUsesDOMForCursor)
{
mUsesDOMForCursor = aUsesDOMForCursor;

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

@ -224,7 +224,6 @@ protected:
PRPackedBool mWindowlessLocal;
PRPackedBool mTransparent;
PRPackedBool mCached;
PRPackedBool mWantsAllNetworkStreams;
PRPackedBool mUsesDOMForCursor;
public:

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

@ -102,9 +102,13 @@ child:
rpc NPP_SetWindow(NPRemoteWindow window);
rpc NPP_GetValue_NPPVpluginWantsAllNetworkStreams()
returns (bool value, NPError result);
// this message is not used on non-X platforms
rpc NPP_GetValue_NPPVpluginNeedsXEmbed()
returns (bool value, NPError result);
rpc NPP_GetValue_NPPVpluginScriptableNPObject()
returns (nullable PPluginScriptableObject value, NPError result);

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

@ -513,6 +513,24 @@ PluginInstanceChild::NPN_SetValue(NPPVariable aVar, void* aValue)
}
}
bool
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginWantsAllNetworkStreams(
bool* wantsAllStreams, NPError* rv)
{
AssertPluginThread();
PRBool value = 0;
if (!mPluginIface->getvalue) {
*rv = NPERR_GENERIC_ERROR;
}
else {
*rv = mPluginIface->getvalue(GetNPP(), NPPVpluginWantsAllNetworkStreams,
&value);
}
*wantsAllStreams = value;
return true;
}
bool
PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(
bool* needs, NPError* rv)

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

@ -87,6 +87,8 @@ class PluginInstanceChild : public PPluginInstanceChild
protected:
virtual bool AnswerNPP_SetWindow(const NPRemoteWindow& window);
virtual bool
AnswerNPP_GetValue_NPPVpluginWantsAllNetworkStreams(bool* wantsAllStreams, NPError* rv);
virtual bool
AnswerNPP_GetValue_NPPVpluginNeedsXEmbed(bool* needs, NPError* rv);
virtual bool

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

@ -920,6 +920,22 @@ PluginInstanceParent::NPP_GetValue(NPPVariable aVariable,
{
switch (aVariable) {
case NPPVpluginWantsAllNetworkStreams: {
bool wantsAllStreams;
NPError rv;
if (!CallNPP_GetValue_NPPVpluginWantsAllNetworkStreams(&wantsAllStreams, &rv)) {
return NPERR_GENERIC_ERROR;
}
if (NPERR_NO_ERROR != rv) {
return rv;
}
(*(NPBool*)_retval) = wantsAllStreams;
return NPERR_NO_ERROR;
}
#ifdef MOZ_X11
case NPPVpluginNeedsXEmbed: {
bool needsXEmbed;

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

@ -100,6 +100,7 @@ _MOCHITEST_FILES = \
test_redirect_handling.html \
test_clear_site_data.html \
test_zero_opacity.html \
test_NPPVpluginWantsAllNetworkStreams.html \
$(NULL)
# test_plugin_scroll_painting.html \ bug 596491

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

@ -0,0 +1,71 @@
<html>
<head>
<title>Test NPPVpluginWantsAllNetworkStreams</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body onload="runNextTest()">
<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
var p = document.getElementById("plugin1");
var missingDoc = "not-found.html";
var expectedWriteURL = "";
var expectedNotifyStatus = -1;
var writeHappened = false;
var expectedWrite = false;
function writeCallback(url) {
writeHappened = true;
}
function notifyCallback(status, data) {
is(writeHappened, expectedWrite, "Test for expected write.");
is(status, expectedNotifyStatus, "Test for expected stream notification status.");
runNextTest();
}
function test1() {
// In this test we do not expect a stream for the missing document.
p.setPluginWantsAllStreams(false);
expectedWriteURL = missingDoc;
expectedNotifyStatus = 1;
writeHappened = false;
expectedWrite = false;
p.streamTest(missingDoc, false, null, writeCallback, notifyCallback, null, false);
}
function test2() {
// In this test we expect a stream for the missing document.
p.setPluginWantsAllStreams(true);
expectedWriteURL = missingDoc;
expectedNotifyStatus = 0;
writeHappened = false;
expectedWrite = true;
p.streamTest(missingDoc, false, null, writeCallback, notifyCallback, null, false);
}
var tests = [test1, test2];
var currentTest = -1;
function runNextTest() {
currentTest++;
if (currentTest < tests.length) {
tests[currentTest]();
} else {
SimpleTest.finish();
}
}
</script>
</body>
</html>

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

@ -354,8 +354,8 @@ If the plugin is instantiated as a full-page plugin, the following defaults
are used:
streammode="seek" frame="testframe" range="100,100"
The streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects)
function will test how NPN_GetURLNotify and NPN_PostURLNotify behave when they are
* streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects)
This will test how NPN_GetURLNotify and NPN_PostURLNotify behave when they are
called with arbitrary (malformed) URLs. The function will return `true` if
NPN_[Get/Post]URLNotify succeeds, and `false` if it fails.
@url url to request
@ -366,6 +366,9 @@ NPN_[Get/Post]URLNotify succeeds, and `false` if it fails.
@redirectCallback will be called from urlredirectnotify if a redirect is attempted
@allowRedirects boolean value indicating whether or not to allow redirects
* setPluginWantsAllStreams(wantsAllStreams)
Set the value returned by the plugin for NPPVpluginWantsAllNetworkStreams.
== Internal consistency ==
* doInternalConsistencyCheck()

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

@ -137,6 +137,7 @@ static bool throwExceptionNextInvoke(NPObject* npobj, const NPVariant* args, uin
static bool convertPointX(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool convertPointY(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool setPluginWantsAllStreams(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool crashPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool crashOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool getObjectValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
@ -195,6 +196,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"convertPointX",
"convertPointY",
"streamTest",
"setPluginWantsAllStreams",
"crash",
"crashOnDestroy",
"getObjectValue",
@ -254,6 +256,7 @@ static const ScriptableFunction sPluginMethodFunctions[] = {
convertPointX,
convertPointY,
streamTest,
setPluginWantsAllStreams,
crashPlugin,
crashOnDestroy,
getObjectValue,
@ -743,6 +746,7 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char*
instanceData->focusEventCount = 0;
instanceData->eventModel = 0;
instanceData->closeStream = false;
instanceData->wantsAllStreams = false;
instance->pdata = instanceData;
TestNPObject* scriptableObject = (TestNPObject*)NPN_CreateObject(instance, &sNPClass);
@ -1172,7 +1176,7 @@ NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buf
if (instanceData->closeStream) {
instanceData->closeStream = false;
if (instanceData->testrange != NULL) {
NPError err = NPN_RequestRead(stream, instanceData->testrange);
NPN_RequestRead(stream, instanceData->testrange);
}
NPN_DestroyStream(instance, stream, NPRES_USER_BREAK);
}
@ -1345,6 +1349,10 @@ NPP_GetValue(NPP instance, NPPVariable variable, void* value)
*(NPBool*)value = instanceData->hasWidget;
return NPERR_NO_ERROR;
}
if (variable == NPPVpluginWantsAllNetworkStreams) {
*(NPBool*)value = instanceData->wantsAllStreams;
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
@ -2553,6 +2561,24 @@ streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant*
return true;
}
static bool
setPluginWantsAllStreams(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (1 != argCount)
return false;
if (!NPVARIANT_IS_BOOLEAN(args[0]))
return false;
bool wantsAllStreams = NPVARIANT_TO_BOOLEAN(args[0]);
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
id->wantsAllStreams = wantsAllStreams;
return true;
}
static bool
crashPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{

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

@ -139,6 +139,7 @@ typedef struct InstanceData {
int32_t eventModel;
bool closeStream;
std::string lastKeyText;
bool wantsAllStreams;
} InstanceData;
void notifyDidPaint(InstanceData* instanceData);