Return a correct user agent if NPN_UserAgent is called with a null NPP from NPP_New.
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Dec 2010 20:12:50 +0000 (20:12 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Dec 2010 20:12:50 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=50336

Reviewed by Darin Adler.

WebKit2:

* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::NPN_UserAgent):
Call the static NetscapePlugin::userAgent function instead.

* WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
(WebKit::NetscapePlugin::userAgent):
If the passed in NPP is null, get the NetscapePlugin currently executing NPP_New.

(WebKit::NetscapePlugin::initialize):
Keep track of the plug-in currently executing NPP_New.

* WebProcess/Plugins/Netscape/NetscapePlugin.h:

WebKitTools:

* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
Add new test.

* DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp:
(PluginTest::NPP_New):
Add default implementation/

* DumpRenderTree/TestNetscapePlugIn/PluginTest.h:
* DumpRenderTree/TestNetscapePlugIn/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp: Added.
(GetUserAgentWithNullNPPFromNPPNew::GetUserAgentWithNullNPPFromNPPNew):
(GetUserAgentWithNullNPPFromNPPNew::NPP_New):
Get the user agent.

* DumpRenderTree/TestNetscapePlugIn/main.cpp:
(NPP_New):
Call PluginTest::NPP_New.

* DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj:
* DumpRenderTree/qt/TestNetscapePlugin/TestNetscapePlugin.pro:
Add new files.

* DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp:
(webkit_test_plugin_new_instance):
Call PluginTest::NPP_New.

LayoutTests:

Add tests.

* plugins/get-user-agent-with-null-npp-from-npp-new-expected.txt: Added.
* plugins/get-user-agent-with-null-npp-from-npp-new.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@73057 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new-expected.txt [new file with mode: 0644]
LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new.html [new file with mode: 0644]
WebKit2/ChangeLog
WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp
WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp
WebKitTools/DumpRenderTree/TestNetscapePlugIn/PluginTest.h
WebKitTools/DumpRenderTree/TestNetscapePlugIn/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp [new file with mode: 0644]
WebKitTools/DumpRenderTree/TestNetscapePlugIn/main.cpp
WebKitTools/DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj
WebKitTools/DumpRenderTree/qt/TestNetscapePlugin/TestNetscapePlugin.pro
WebKitTools/DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp

index 6d2d007..7823aac 100644 (file)
@@ -1,3 +1,15 @@
+2010-12-01  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Return a correct user agent if NPN_UserAgent is called with a null NPP from NPP_New.
+        https://bugs.webkit.org/show_bug.cgi?id=50336
+
+        Add tests.
+
+        * plugins/get-user-agent-with-null-npp-from-npp-new-expected.txt: Added.
+        * plugins/get-user-agent-with-null-npp-from-npp-new.html: Added.
+
 2010-12-01  Gavin Barraclough  <barraclough@apple.com>
 
         Rubber stamped by Sam Weinig.
diff --git a/LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new-expected.txt b/LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new-expected.txt
new file mode 100644 (file)
index 0000000..cb2af41
--- /dev/null
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 0: PLUGIN: SUCCESS!
+
+This tests that we can get a user agent when calling NPN_UserAgent with a null NPP from NPP_New.
diff --git a/LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new.html b/LayoutTests/plugins/get-user-agent-with-null-npp-from-npp-new.html
new file mode 100644 (file)
index 0000000..64f5abc
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+    </script>
+</head>
+<body>
+    <div>
+        <embed id=testPlugin type="application/x-webkit-test-netscape" test="get-user-agent-with-null-npp-from-npp-new"></embed>
+    </div>
+    <p>This tests that we can get a user agent when calling NPN_UserAgent with a null NPP from NPP_New.</p>
+</body>
+</html>
index 6d01249..97c16d5 100644 (file)
@@ -1,3 +1,23 @@
+2010-12-01  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Return a correct user agent if NPN_UserAgent is called with a null NPP from NPP_New.
+        https://bugs.webkit.org/show_bug.cgi?id=50336
+
+        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+        (WebKit::NPN_UserAgent):
+        Call the static NetscapePlugin::userAgent function instead.
+
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        (WebKit::NetscapePlugin::userAgent):
+        If the passed in NPP is null, get the NetscapePlugin currently executing NPP_New.
+
+        (WebKit::NetscapePlugin::initialize):
+        Keep track of the plug-in currently executing NPP_New.
+
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+
 2010-12-01  Brian Weinstein  <bweinstein@apple.com>
 
         One last Windows build fix.
index 9703d25..bb59cb7 100644 (file)
@@ -327,11 +327,7 @@ static void NPN_Status(NPP npp, const char* message)
     
 static const char* NPN_UserAgent(NPP npp)
 {
-    if (!npp)
-        return 0;
-    
-    RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
-    return plugin->userAgent();
+    return NetscapePlugin::userAgent(npp);
 }
 
 static void* NPN_MemAlloc(uint32_t size)
index 3910743..29095e6 100644 (file)
@@ -40,6 +40,9 @@ using namespace std;
 
 namespace WebKit {
 
+// The plug-in that we're currently calling NPP_New for.
+static NetscapePlugin* currentNPPNewPlugin;
+    
 NetscapePlugin::NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule)
     : m_pluginController(0)
     , m_nextRequestID(0)
@@ -101,6 +104,17 @@ void NetscapePlugin::invalidate(const NPRect* invalidRect)
     m_pluginController->invalidate(rect);
 }
 
+const char* NetscapePlugin::userAgent(NPP npp)
+{
+    if (npp)
+        return fromNPP(npp)->userAgent();
+
+    if (currentNPPNewPlugin)
+        return currentNPPNewPlugin->userAgent();
+
+    return 0;
+}
+
 const char* NetscapePlugin::userAgent()
 {
     if (m_userAgent.isNull()) {
@@ -358,7 +372,6 @@ bool NetscapePlugin::initialize(PluginController* pluginController, const Parame
     uint16_t mode = parameters.loadManually ? NP_FULL : NP_EMBED;
     
     m_loadManually = parameters.loadManually;
-    m_inNPPNew = true;
 
     CString mimeTypeCString = parameters.mimeType.utf8();
 
@@ -378,10 +391,17 @@ bool NetscapePlugin::initialize(PluginController* pluginController, const Parame
         names.append(paramNames[i].data());
         values.append(paramValues[i].data());
     }
+
+    NetscapePlugin* previousNPPNewPlugin = currentNPPNewPlugin;
     
+    m_inNPPNew = true;
+    currentNPPNewPlugin = this;
+
     NPError error = NPP_New(const_cast<char*>(mimeTypeCString.data()), mode, names.size(),
                             const_cast<char**>(names.data()), const_cast<char**>(values.data()), 0);
+
     m_inNPPNew = false;
+    currentNPPNewPlugin = previousNPPNewPlugin;
 
     if (error != NPERR_NO_ERROR)
         return false;
index fda5350..bafa3fa 100644 (file)
@@ -64,7 +64,7 @@ public:
 #endif
 
     void invalidate(const NPRect*);
-    const char* userAgent();
+    static const char* userAgent(NPP);
     void loadURL(const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields,
                  const Vector<uint8_t>& httpBody, bool sendNotification, void* notificationData);
     NPError destroyStream(NPStream*, NPReason);
@@ -110,6 +110,8 @@ private:
     void stopAllStreams();
     bool allowPopups() const;
 
+    const char* userAgent();
+
     bool platformPostInitialize();
     void platformDestroy();
     bool platformInvalidate(const WebCore::IntRect&);
index 5966923..65ff05f 100644 (file)
@@ -1,3 +1,35 @@
+2010-12-01  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Return a correct user agent if NPN_UserAgent is called with a null NPP from NPP_New.
+        https://bugs.webkit.org/show_bug.cgi?id=50336
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        Add new test.
+
+        * DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp:
+        (PluginTest::NPP_New):
+        Add default implementation/
+
+        * DumpRenderTree/TestNetscapePlugIn/PluginTest.h:
+        * DumpRenderTree/TestNetscapePlugIn/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp: Added.
+        (GetUserAgentWithNullNPPFromNPPNew::GetUserAgentWithNullNPPFromNPPNew):
+        (GetUserAgentWithNullNPPFromNPPNew::NPP_New):
+        Get the user agent.
+
+        * DumpRenderTree/TestNetscapePlugIn/main.cpp:
+        (NPP_New):
+        Call PluginTest::NPP_New.
+
+        * DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj:
+        * DumpRenderTree/qt/TestNetscapePlugin/TestNetscapePlugin.pro:
+        Add new files.
+
+        * DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp:
+        (webkit_test_plugin_new_instance):
+        Call PluginTest::NPP_New.
+
 2010-12-01  Kevin Ollivier  <kevino@theolliviers.com>
 
         [wx] Build fixes after recent trunk changes.
index b2eb8e9..34ff710 100644 (file)
@@ -41,6 +41,7 @@
                1AC6C84A0D07638600CD3161 /* PluginObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC6C7800D07589B00CD3161 /* PluginObject.cpp */; };
                1AC6C84B0D07638600CD3161 /* TestObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC6C7810D07589B00CD3161 /* TestObject.cpp */; };
                1AC77DCF120605B6005C19EF /* NPRuntimeRemoveProperty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC77DCE120605B6005C19EF /* NPRuntimeRemoveProperty.cpp */; };
+               1AD4CB2212A6D1350027A7AF /* GetUserAgentWithNullNPPFromNPPNew.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD4CB2012A6D1350027A7AF /* GetUserAgentWithNullNPPFromNPPNew.cpp */; };
                1AD9D2FE12028409001A70D1 /* PluginScriptableNPObjectInvokeDefault.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD9D2FD12028409001A70D1 /* PluginScriptableNPObjectInvokeDefault.cpp */; };
                23BCB8900EA57623003C6289 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23BCB88F0EA57623003C6289 /* OpenGL.framework */; };
                29CFBA10122736E600BC30C0 /* AccessibilityTextMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */; };
                1AC6C7800D07589B00CD3161 /* PluginObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginObject.cpp; sourceTree = "<group>"; };
                1AC6C7810D07589B00CD3161 /* TestObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestObject.cpp; sourceTree = "<group>"; };
                1AC77DCE120605B6005C19EF /* NPRuntimeRemoveProperty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NPRuntimeRemoveProperty.cpp; sourceTree = "<group>"; };
+               1AD4CB2012A6D1350027A7AF /* GetUserAgentWithNullNPPFromNPPNew.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetUserAgentWithNullNPPFromNPPNew.cpp; sourceTree = "<group>"; };
                1AD9D2FD12028409001A70D1 /* PluginScriptableNPObjectInvokeDefault.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginScriptableNPObjectInvokeDefault.cpp; sourceTree = "<group>"; };
                23BCB88F0EA57623003C6289 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
                29CFBA0E122736E600BC30C0 /* AccessibilityTextMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityTextMarker.h; sourceTree = "<group>"; };
                        children = (
                                1A215A7511F26072008AD0F5 /* DocumentOpenInDestroyStream.cpp */,
                                C0E720741281C828004EF533 /* EvaluateJSAfterRemovingPluginElement.cpp */,
+                               1AD4CB2012A6D1350027A7AF /* GetUserAgentWithNullNPPFromNPPNew.cpp */,
                                1A24BAA8120734EE00FBB059 /* NPRuntimeObjectFromDestroyedPlugin.cpp */,
                                1AC77DCE120605B6005C19EF /* NPRuntimeRemoveProperty.cpp */,
                                C0EC3C9B12787F0500939164 /* NullNPPGetValuePointer.cpp */,
                                C06F9ABC1267A7060058E1F6 /* PassDifferentNPPStruct.cpp in Sources */,
                                C0EC3C9C12787F0500939164 /* NullNPPGetValuePointer.cpp in Sources */,
                                C0E720751281C828004EF533 /* EvaluateJSAfterRemovingPluginElement.cpp in Sources */,
+                               1AD4CB2212A6D1350027A7AF /* GetUserAgentWithNullNPPFromNPPNew.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 06c9953..703d9d5 100644 (file)
@@ -50,6 +50,11 @@ PluginTest::~PluginTest()
 {
 }
 
+NPError PluginTest::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
+{
+    return NPERR_NO_ERROR;
+}
+
 NPError PluginTest::NPP_Destroy(NPSavedData**)
 {
     return NPERR_NO_ERROR;
index ae9bd82..2c06079 100644 (file)
@@ -55,6 +55,7 @@ public:
     virtual ~PluginTest();
 
     // NPP functions.
+    virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved);
     virtual NPError NPP_Destroy(NPSavedData**);
     virtual NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
     virtual NPError NPP_GetValue(NPPVariable, void* value);
diff --git a/WebKitTools/DumpRenderTree/TestNetscapePlugIn/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp b/WebKitTools/DumpRenderTree/TestNetscapePlugIn/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp
new file mode 100644 (file)
index 0000000..7c536d1
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "PluginTest.h"
+
+#include "PluginTest.h"
+
+#include "PluginObject.h"
+
+using namespace std;
+
+// Trying to get the user agent with a null instance from NPP_New.
+
+class GetUserAgentWithNullNPPFromNPPNew : public PluginTest {
+public:
+    GetUserAgentWithNullNPPFromNPPNew(NPP npp, const string& identifier)
+        : PluginTest(npp, identifier)
+    {
+    }
+
+private:
+    virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
+    {
+        if (!browser->uagent(0))
+            pluginLog(m_npp, "FAILURE: Null user agent returned.");
+        else
+            pluginLog(m_npp, "SUCCESS!");
+
+        return NPERR_NO_ERROR;
+    }
+
+};
+
+static PluginTest::Register<GetUserAgentWithNullNPPFromNPPNew> getUserAgentWithNullNPPFromNPPNew("get-user-agent-with-null-npp-from-npp-new");
+
index 2110a8a..266b4b5 100644 (file)
@@ -268,10 +268,10 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc
 
 #ifdef XP_UNIX
     // On Unix, plugins only get events if they are windowless.
-    return browser->setvalue(instance, NPPVpluginWindowBool, 0);
-#else
-    return NPERR_NO_ERROR;
+    browser->setvalue(instance, NPPVpluginWindowBool, 0);
 #endif
+
+    return obj->pluginTest->NPP_New(pluginType, mode, argc, argn, argv, saved);
 }
 
 NPError NPP_Destroy(NPP instance, NPSavedData **save)
index 347d66e..4464e2e 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath="..\Tests\GetUserAgentWithNullNPPFromNPPNew.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\Tests\NPRuntimeObjectFromDestroyedPlugin.cpp"
                                >
                        </File>
index 1d460d7..de3cf6a 100644 (file)
@@ -30,6 +30,7 @@ SOURCES = PluginObject.cpp \
           TestObject.cpp \
           Tests/DocumentOpenInDestroyStream.cpp \
           Tests/EvaluateJSAfterRemovingPluginElement.cpp \
+          Tests/GetUserAgentWithNullNPPFromNPPNew.cpp \
           Tests/NPRuntimeObjectFromDestroyedPlugin.cpp \
           Tests/NPRuntimeRemoveProperty.cpp \
           Tests/NullNPPGetValuePointer.cpp \
index a4f7f04..2f7288a 100644 (file)
@@ -53,13 +53,13 @@ extern "C" {
 static void executeScript(const PluginObject* obj, const char* script);
 
 static NPError
-webkit_test_plugin_new_instance(NPMIMEType /*mimetype*/,
+webkit_test_plugin_new_instance(NPMIMEType mimetype,
                                 NPP instance,
-                                uint16_t /*mode*/,
+                                uint16_t mode,
                                 int16_t argc,
                                 char *argn[],
                                 char *argv[],
-                                NPSavedData* /*savedData*/)
+                                NPSavedData* savedData)
 {
     if (browser->version >= 14) {
         PluginObject* obj = (PluginObject*)browser->createobject(instance, getPluginClass());
@@ -100,6 +100,8 @@ webkit_test_plugin_new_instance(NPMIMEType /*mimetype*/,
         browser->getvalue(instance, NPNVprivateModeBool, (void *)&obj->cachedPrivateBrowsingMode);
 
         obj->pluginTest = PluginTest::create(instance, testIdentifier);
+
+        return obj->pluginTest->NPP_New(mimetype, mode, argc, argn, argv, savedData);
     }
 
     return NPERR_NO_ERROR;