2010-05-06 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 May 2010 23:23:27 +0000 (23:23 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 May 2010 23:23:27 +0000 (23:23 +0000)
        Reviewed by Darin Adler and Dan Bernstein..

        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
        https://bugs.webkit.org/show_bug.cgi?id=38698
        <rdar://problem/7942075>

        When the plug-in database is initialized, we will register all the MIME types it supports with the global
        WebView dictionary. When plug-ins are disabled for a single web view, the MIME types still need to be
        in the global mapping (because other web views might still have plug-ins enabled).

        Prior to r51617 we would always look at the plug-in database to determine that the MIME type belongs to a
        plug-in, but now we won't even touch the plug-in database when plug-ins are disabled.

        In order to fix this, a new set of registered MIME types that are known to be plug-ins is added. When
        +[WebView _viewClass:andRepresentationClass:forMIMEType:allowingPlugins:] is called and allowingPlugins is FALSE
        we check if the MIME type is a known plug-in MIME type and return false in that case.

        * Plugins/WebPluginDatabase.mm:
        (-[WebPluginDatabase refresh]):
        (-[WebPluginDatabase _removePlugin:]):
        * WebView/WebView.mm:
        (knownPluginMIMETypes):
        (+[WebView _registerPluginMIMEType:]):
        (+[WebView _unregisterPluginMIMEType:]):
        (+[WebView _viewClass:andRepresentationClass:forMIMEType:allowingPlugins:]):
        * WebView/WebViewInternal.h:
2010-05-06  Anders Carlsson  <andersca@apple.com>

        Reviewed by Darin Adler and Dan Bernstein..

        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
        https://bugs.webkit.org/show_bug.cgi?id=38698
        <rdar://problem/7942075>

        Add tests.

        * platform/mac/plugins/disable-plugins-expected.txt: Added.
        * platform/mac/plugins/disable-plugins.html: Added.
2010-05-06  Anders Carlsson  <andersca@apple.com>

        Reviewed by Darin Adler and Dan Bernstein..

        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
        https://bugs.webkit.org/show_bug.cgi?id=38698
        <rdar://problem/7942075>

        Add a 'setPluginsEnabled' layoutTestController function for disabling plug-ins. This is only implemented on Mac currently
        because the bug that needs this functionality is mac specific.

        * DumpRenderTree/LayoutTestController.cpp:
        (setPluginsEnabledCallback):
        (LayoutTestController::staticFunctions):
        * DumpRenderTree/LayoutTestController.h:
        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
        (LayoutTestController::setPluginsEnabled):
        * DumpRenderTree/mac/DumpRenderTree.mm:
        (resetDefaultsToConsistentValues):
        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
        (LayoutTestController::setPluginsEnabled):
        * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
        (LayoutTestController::setPluginsEnabled):
        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
        (LayoutTestController::setPluginsEnabled):
        * DumpRenderTree/wx/LayoutTestControllerWx.cpp:
        (LayoutTestController::setPluginsEnabled):

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/plugins/disable-plugins-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/plugins/disable-plugins.html [new file with mode: 0644]
WebKit/mac/ChangeLog
WebKit/mac/Plugins/WebPluginDatabase.mm
WebKit/mac/WebView/WebView.mm
WebKit/mac/WebView/WebViewInternal.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/gtk/LayoutTestControllerGtk.cpp
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm
WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp
WebKitTools/DumpRenderTree/wx/LayoutTestControllerWx.cpp

index d1042344c22f156ed56f46c6db6c7864248414db..0e4b36f2f14dfc597802b6f8ec67212ad5729b18 100644 (file)
@@ -1,3 +1,16 @@
+2010-05-06  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler and Dan Bernstein..
+
+        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
+        https://bugs.webkit.org/show_bug.cgi?id=38698
+        <rdar://problem/7942075>
+
+        Add tests.
+
+        * platform/mac/plugins/disable-plugins-expected.txt: Added.
+        * platform/mac/plugins/disable-plugins.html: Added.
+
 2010-05-06  John Gregg  <johnnyg@google.com>
 
         Unreviewed, rebaseline for chromium test.
diff --git a/LayoutTests/platform/mac/plugins/disable-plugins-expected.txt b/LayoutTests/platform/mac/plugins/disable-plugins-expected.txt
new file mode 100644 (file)
index 0000000..722ba2d
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that embed and object tags won't load as HTML when plug-ins are disabled (after being enabled first).
+SUCCESS!
+
diff --git a/LayoutTests/platform/mac/plugins/disable-plugins.html b/LayoutTests/platform/mac/plugins/disable-plugins.html
new file mode 100644 (file)
index 0000000..a812f1b
--- /dev/null
@@ -0,0 +1,25 @@
+
+<script>
+function runTest() {
+    if (!window.layoutTestController)
+        alert('this test must be run from DumpRenderTree')
+    
+    layoutTestController.dumpAsText();
+    layoutTestController.setPluginsEnabled(false);
+    
+    var pluginElement = document.getElementById('testPlugin');
+    pluginElement.parentNode.removeChild(pluginElement);
+    
+    document.body.appendChild(pluginElement);
+    if (pluginElement.contentDocument)
+        document.getElementById('result').innerText = "FAILURE - object tag has an HTML document!";
+    else
+        document.getElementById('result').innerText = "SUCCESS!";
+}
+
+</script>
+<body onload="runTest()">    
+    <object id="testPlugin" type="application/x-webkit-test-netscape"></object>
+    <div>This tests that embed and object tags won't load as HTML when plug-ins are disabled (after being enabled first).</div>
+    <div id="result">FAILURE - test did not run!</div>
+</body>
index f2c6ff6d7f6538aeb2c35c8aa7c156e6777e2a61..d7aa5bffba4292c3e90bfa0a55e88b623ca2c0cd 100644 (file)
@@ -1,3 +1,32 @@
+2010-05-06  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler and Dan Bernstein..
+
+        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
+        https://bugs.webkit.org/show_bug.cgi?id=38698
+        <rdar://problem/7942075>
+
+        When the plug-in database is initialized, we will register all the MIME types it supports with the global
+        WebView dictionary. When plug-ins are disabled for a single web view, the MIME types still need to be 
+        in the global mapping (because other web views might still have plug-ins enabled).
+        
+        Prior to r51617 we would always look at the plug-in database to determine that the MIME type belongs to a 
+        plug-in, but now we won't even touch the plug-in database when plug-ins are disabled.
+        
+        In order to fix this, a new set of registered MIME types that are known to be plug-ins is added. When
+        +[WebView _viewClass:andRepresentationClass:forMIMEType:allowingPlugins:] is called and allowingPlugins is FALSE
+        we check if the MIME type is a known plug-in MIME type and return false in that case.
+        
+        * Plugins/WebPluginDatabase.mm:
+        (-[WebPluginDatabase refresh]):
+        (-[WebPluginDatabase _removePlugin:]):
+        * WebView/WebView.mm:
+        (knownPluginMIMETypes):
+        (+[WebView _registerPluginMIMEType:]):
+        (+[WebView _unregisterPluginMIMEType:]):
+        (+[WebView _viewClass:andRepresentationClass:forMIMEType:allowingPlugins:]):
+        * WebView/WebViewInternal.h:
+
 2010-05-06  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Simon Fraser.
index 1856fe1ccad28ba59049689dfe3e01d2853cded7..34f5e0ff3267a5414b015b1b4550fdd740e0e557 100644 (file)
 #import "WebFrameViewInternal.h"
 #import "WebHTMLRepresentation.h"
 #import "WebHTMLView.h"
-#import "WebHTMLView.h"
 #import "WebKitLogging.h"
 #import "WebNSFileManagerExtras.h"
 #import "WebNetscapePluginPackage.h"
 #import "WebPluginController.h"
 #import "WebPluginPackage.h"
 #import "WebViewPrivate.h"
+#import "WebViewInternal.h"
 #import <WebKitSystemInterface.h>
 #import <wtf/Assertions.h>
 
@@ -296,7 +296,7 @@ static NSArray *additionalWebPlugInPaths;
             continue;
         
         if (self == sharedDatabase)
-            [WebView registerViewClass:[WebHTMLView class] representationClass:[WebHTMLRepresentation class] forMIMEType:MIMEType];
+            [WebView _registerPluginMIMEType:MIMEType];
     }
     [MIMETypes release];
     
@@ -415,7 +415,7 @@ static NSArray *additionalWebPlugInPaths;
     while ((MIMEType = [MIMETypeEnumerator nextObject])) {
         if ([registeredMIMETypes containsObject:MIMEType]) {
             if (self == sharedDatabase)
-                [WebView _unregisterViewClassAndRepresentationClassForMIMEType:MIMEType];
+                [WebView _unregisterPluginMIMEType:MIMEType];
             [registeredMIMETypes removeObject:MIMEType];
         }
     }
index 985cb53b7b5b0efbb2323a7725c2b23f8b9bca74..2442846b1ef088a205a215df898ee012e52a1658 100644 (file)
@@ -861,6 +861,25 @@ static bool shouldEnableLoadDeferring()
     return uniqueExtensions;
 }
 
+static NSMutableSet *knownPluginMIMETypes()
+{
+    static NSMutableSet *mimeTypes = [[NSMutableSet alloc] init];
+    
+    return mimeTypes;
+}
+
++ (void)_registerPluginMIMEType:(NSString *)MIMEType
+{
+    [WebView registerViewClass:[WebHTMLView class] representationClass:[WebHTMLRepresentation class] forMIMEType:MIMEType];
+    [knownPluginMIMETypes() addObject:MIMEType];
+}
+
++ (void)_unregisterPluginMIMEType:(NSString *)MIMEType
+{
+    [self _unregisterViewClassAndRepresentationClassForMIMEType:MIMEType];
+    [knownPluginMIMETypes() removeObject:MIMEType];
+}
+
 + (BOOL)_viewClass:(Class *)vClass andRepresentationClass:(Class *)rClass forMIMEType:(NSString *)MIMEType allowingPlugins:(BOOL)allowPlugins
 {
     MIMEType = [MIMEType lowercaseString];
@@ -881,11 +900,20 @@ static bool shouldEnableLoadDeferring()
     }
     
     if (viewClass && repClass) {
-        // Special-case WebHTMLView for text types that shouldn't be shown.
-        if (viewClass == [WebHTMLView class] &&
-            repClass == [WebHTMLRepresentation class] &&
-            [[WebHTMLView unsupportedTextMIMETypes] containsObject:MIMEType]) {
-            return NO;
+        if (viewClass == [WebHTMLView class] && repClass == [WebHTMLRepresentation class]) {
+            // Special-case WebHTMLView for text types that shouldn't be shown.
+            if ([[WebHTMLView unsupportedTextMIMETypes] containsObject:MIMEType])
+                return NO;
+
+            // If the MIME type is a known plug-in we might not want to load it.
+            if (!allowPlugins && [knownPluginMIMETypes() containsObject:MIMEType]) {
+                BOOL isSupportedByWebKit = [[WebHTMLView supportedNonImageMIMETypes] containsObject:MIMEType] ||
+                    [[WebHTMLView supportedMIMETypes] containsObject:MIMEType];
+                
+                // If this is a known plug-in MIME type and WebKit can't show it natively, we don't want to show it.
+                if (!isSupportedByWebKit)
+                    return NO;
+            }
         }
         if (vClass)
             *vClass = viewClass;
index a2ce6462d17a94bc2178a5d69f10b7c64cad1c9a..46435737293fc6b47aaa5bfea422016fcad3f345 100644 (file)
@@ -117,6 +117,8 @@ namespace WebCore {
 - (void)_didStartProvisionalLoadForFrame:(WebFrame *)frame;
 + (BOOL)_viewClass:(Class *)vClass andRepresentationClass:(Class *)rClass forMIMEType:(NSString *)MIMEType allowingPlugins:(BOOL)allowPlugins;
 - (BOOL)_viewClass:(Class *)vClass andRepresentationClass:(Class *)rClass forMIMEType:(NSString *)MIMEType;
++ (void)_registerPluginMIMEType:(NSString *)MIMEType;
++ (void)_unregisterPluginMIMEType:(NSString *)MIMEType;
 + (BOOL)_canShowMIMEType:(NSString *)MIMEType allowingPlugins:(BOOL)allowPlugins;
 - (BOOL)_canShowMIMEType:(NSString *)MIMEType;
 + (NSString *)_MIMETypeForFile:(NSString *)path;
index 1bb4114843a4826fe45fa193bd20e7997d1bb085..4de8b8a0b0e92471b49b24887ca54afca689856b 100644 (file)
@@ -1,3 +1,31 @@
+2010-05-06  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin Adler and Dan Bernstein..
+
+        REGRESSION (r51617): when plugins are disabled, plugins show up as garbage characters
+        https://bugs.webkit.org/show_bug.cgi?id=38698
+        <rdar://problem/7942075>
+
+        Add a 'setPluginsEnabled' layoutTestController function for disabling plug-ins. This is only implemented on Mac currently
+        because the bug that needs this functionality is mac specific.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (setPluginsEnabledCallback):
+        (LayoutTestController::staticFunctions):
+        * DumpRenderTree/LayoutTestController.h:
+        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
+        (LayoutTestController::setPluginsEnabled):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (resetDefaultsToConsistentValues):
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::setPluginsEnabled):
+        * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
+        (LayoutTestController::setPluginsEnabled):
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::setPluginsEnabled):
+        * DumpRenderTree/wx/LayoutTestControllerWx.cpp:
+        (LayoutTestController::setPluginsEnabled):
+
 2010-05-06  Jochen Eisinger  <jochen@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index b4b5bf2eca382ddeca500cfbe3f4c1ba4bd96c79..f564afa1ba37f3f5239bbda8fcb122a8df9ee07d 100644 (file)
@@ -1161,6 +1161,18 @@ static JSValueRef setPopupBlockingEnabledCallback(JSContextRef context, JSObject
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef setPluginsEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    // Has mac & windows implementation
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(context);
+    
+    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    controller->setPluginsEnabled(JSValueToBoolean(context, arguments[0]));
+    
+    return JSValueMakeUndefined(context);
+}    
+
 static JSValueRef setSmartInsertDeleteEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     if (argumentCount < 1)
@@ -1602,6 +1614,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "setPOSIXLocale", setPOSIXLocaleCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setPersistentUserStyleSheetLocation", setPersistentUserStyleSheetLocationCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setPopupBlockingEnabled", setPopupBlockingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "setPluginsEnabled", setPluginsEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setPrinting", setPrintingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setPrivateBrowsingEnabled", setPrivateBrowsingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setSelectTrailingWhitespaceEnabled", setSelectTrailingWhitespaceEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 08f96920acc6aa284b47c799fd9190ab9155e2e2..c6da2ff03e3f9a357c654597744358575a3c130e 100644 (file)
@@ -86,6 +86,7 @@ public:
     void setMockGeolocationError(int code, JSStringRef message);
     void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
     void setPersistentUserStyleSheetLocation(JSStringRef path);
+    void setPluginsEnabled(bool flag);
     void setPopupBlockingEnabled(bool flag);
     void setPrivateBrowsingEnabled(bool flag);
     void setSelectTrailingWhitespaceEnabled(bool flag);
index cbba7ce6e8cab20c36e4e0cf057629c8f975b8ef..4ffab88fef5eeadf6cb5b60e6e9d64fefedd784d 100644 (file)
@@ -466,6 +466,11 @@ void LayoutTestController::setPopupBlockingEnabled(bool flag)
 
 }
 
+void LayoutTestController::setPluginsEnabled(bool flag)
+{
+    // FIXME: Implement
+}
+
 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id) 
 {
     // FIXME: implement
index bd25310fee6f4816334be91c7da29cfc7146a7fe..25b9f4ffe4435326da59d28c61cb504509d7e938 100644 (file)
@@ -427,6 +427,7 @@ static void resetDefaultsToConsistentValues()
     [preferences setXSSAuditorEnabled:NO];
     [preferences setExperimentalNotificationsEnabled:NO];
     [preferences setPluginAllowedRunTime:1];
+    [preferences setPlugInsEnabled:YES];
 
     [preferences setPrivateBrowsingEnabled:NO];
     [preferences setAuthorAndUserStylesEnabled:YES];
index 3b03aec79ac0dcde99f5f9f8d7587f0f2f4cc591..29a5812baefb11be4e9aa2e0812e777d3271487a 100644 (file)
@@ -371,6 +371,11 @@ void LayoutTestController::setPopupBlockingEnabled(bool popupBlockingEnabled)
     [[[mainFrame webView] preferences] setJavaScriptCanOpenWindowsAutomatically:!popupBlockingEnabled];
 }
 
+void LayoutTestController::setPluginsEnabled(bool pluginsEnabled)
+{
+    [[[mainFrame webView] preferences] setPlugInsEnabled:pluginsEnabled];
+}
+
 void LayoutTestController::setJavaScriptCanAccessClipboard(bool enabled)
 {
     [[[mainFrame webView] preferences] setJavaScriptCanAccessClipboard:enabled];
index 977096d97344c4d9f18b55ce7b6ecc81edfb3d7c..3f92b8a054c160f71a337b227f7da10aaebad81c 100644 (file)
@@ -393,6 +393,11 @@ void LayoutTestController::setPopupBlockingEnabled(bool enable)
     m_drt->webPage()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !enable);
 }
 
+void LayoutTestController::setPluginsEnabled(bool flag)
+{
+    // FIXME: Implement
+}
+
 void LayoutTestController::setPOSIXLocale(const QString& locale)
 {
     QLocale qlocale(locale);
index d889cfca9fa3866386207cd178c88a994e64b7d6..112b355d5f3ccbfb408df9210a4e2fbb3b4287d3 100644 (file)
@@ -483,6 +483,11 @@ void LayoutTestController::setPopupBlockingEnabled(bool enabled)
     preferences->setJavaScriptCanOpenWindowsAutomatically(!enabled);
 }
 
+void LayoutTestController::setPluginsEnabled(bool flag)
+{
+    // FIXME: Implement
+}
+
 void LayoutTestController::setJavaScriptCanAccessClipboard(bool enabled)
 {
     COMPtr<IWebView> webView;
index 4614aca1afd586d65c2fa67e614ddc226b14354a..bc157bebcc6bba97a080152b240e812607a3de73 100644 (file)
@@ -202,6 +202,11 @@ void LayoutTestController::setPopupBlockingEnabled(bool popupBlockingEnabled)
     // FIXME: implement
 }
 
+void LayoutTestController::setPluginsEnabled(bool flag)
+{
+    // FIXME: Implement
+}
+
 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id) 
 {
     // FIXME: implement