DumpRenderTree should stop sending unsupported URLs to NSWorkspace
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jul 2013 17:48:01 +0000 (17:48 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jul 2013 17:48:01 +0000 (17:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118514
<rdar://problem/13686836>

Reviewed by Sam Weinig.

Add a new default policy delegate and override decidePolicyForNavigationAction: to not pass unhandled URLs to NSWorkspace.

* DumpRenderTree/DefaultPolicyDelegate.h: Added.
* DumpRenderTree/DefaultPolicyDelegate.m: Added.
(-[DefaultPolicyDelegate webView:decidePolicyForNavigationAction:request:frame:decisionListener:]):
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
Add DefaultPolicyDelegate.h and DefaultPolicyDelegate.m.

* DumpRenderTree/mac/DumpRenderTree.mm:
(allocateGlobalControllers):
Allocate a DefaultPolicyDelegate object.

(resetWebViewToConsistentStateBeforeTesting):
Set the policy delegate to the default policy delegate.

* DumpRenderTree/mac/DumpRenderTreeMac.h:
Declare the defaultPolicyDelegate object.

* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::setCustomPolicyDelegate):
Set the policy delegate to the default delegate if setDelegate is false.

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

Tools/ChangeLog
Tools/DumpRenderTree/DefaultPolicyDelegate.h [new file with mode: 0644]
Tools/DumpRenderTree/DefaultPolicyDelegate.m [new file with mode: 0644]
Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/DumpRenderTree/mac/DumpRenderTreeMac.h
Tools/DumpRenderTree/mac/TestRunnerMac.mm

index f4e21e5..4b5c24f 100644 (file)
@@ -1,3 +1,33 @@
+2013-07-09  Anders Carlsson  <andersca@apple.com>
+
+        DumpRenderTree should stop sending unsupported URLs to NSWorkspace
+        https://bugs.webkit.org/show_bug.cgi?id=118514
+        <rdar://problem/13686836>
+
+        Reviewed by Sam Weinig.
+
+        Add a new default policy delegate and override decidePolicyForNavigationAction: to not pass unhandled URLs to NSWorkspace.
+
+        * DumpRenderTree/DefaultPolicyDelegate.h: Added.
+        * DumpRenderTree/DefaultPolicyDelegate.m: Added.
+        (-[DefaultPolicyDelegate webView:decidePolicyForNavigationAction:request:frame:decisionListener:]):
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        Add DefaultPolicyDelegate.h and DefaultPolicyDelegate.m.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (allocateGlobalControllers):
+        Allocate a DefaultPolicyDelegate object.
+
+        (resetWebViewToConsistentStateBeforeTesting):
+        Set the policy delegate to the default policy delegate.
+
+        * DumpRenderTree/mac/DumpRenderTreeMac.h:
+        Declare the defaultPolicyDelegate object.
+
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::setCustomPolicyDelegate):
+        Set the policy delegate to the default delegate if setDelegate is false.
+
 2013-07-08  Zan Dobersek  <zdobersek@igalia.com>
 
         KURL unit test fixture class should have a meaningful name
diff --git a/Tools/DumpRenderTree/DefaultPolicyDelegate.h b/Tools/DumpRenderTree/DefaultPolicyDelegate.h
new file mode 100644 (file)
index 0000000..6ff5bec
--- /dev/null
@@ -0,0 +1,13 @@
+//
+//  DefaultPolicyDelegate.h
+//  DumpRenderTree
+//
+//  Created by Anders Carlsson on 7/9/13.
+//
+//
+
+#import <WebKit/WebDefaultPolicyDelegate.h>
+
+@interface DefaultPolicyDelegate : WebDefaultPolicyDelegate
+
+@end
diff --git a/Tools/DumpRenderTree/DefaultPolicyDelegate.m b/Tools/DumpRenderTree/DefaultPolicyDelegate.m
new file mode 100644 (file)
index 0000000..4515bfb
--- /dev/null
@@ -0,0 +1,34 @@
+//
+//  DefaultPolicyDelegate.m
+//  DumpRenderTree
+//
+//  Created by Anders Carlsson on 7/9/13.
+//
+//
+
+#import "DefaultPolicyDelegate.h"
+
+#import <WebKit/WebPolicyDelegatePrivate.h>
+#import <WebKit/WebViewPrivate.h>
+
+@implementation DefaultPolicyDelegate
+
+- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id <WebPolicyDecisionListener>)listener
+{
+    if ([WebView _canHandleRequest:request]) {
+        [listener use];
+        return;
+    }
+
+    WebNavigationType navType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
+    if (navType == WebNavigationTypePlugInRequest) {
+        [listener use];
+        return;
+    }
+
+    // The default WebKit policy delegate passes the URL along to -[NSWorkspace openURL:] here,
+    // but we don't want to do that so we just ignore the navigation completely.
+    [listener ignore];
+}
+
+@end
index f28275f..97672ab 100644 (file)
@@ -39,6 +39,8 @@
                1A215A8211F2609C008AD0F5 /* PluginTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A215A8011F2609C008AD0F5 /* PluginTest.h */; };
                1A215BE711F27658008AD0F5 /* DocumentOpenInDestroyStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A215A7511F26072008AD0F5 /* DocumentOpenInDestroyStream.cpp */; };
                1A24BAA9120734EE00FBB059 /* NPRuntimeObjectFromDestroyedPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A24BAA8120734EE00FBB059 /* NPRuntimeObjectFromDestroyedPlugin.cpp */; };
+               1A2FB84E178C80930059FD96 /* DefaultPolicyDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2FB84C178C80920059FD96 /* DefaultPolicyDelegate.h */; };
+               1A2FB84F178C80930059FD96 /* DefaultPolicyDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2FB84D178C80930059FD96 /* DefaultPolicyDelegate.m */; };
                1A31EB3813466AC100017372 /* ConvertPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A31EB3713466AC100017372 /* ConvertPoint.cpp */; };
                1A3E28AA1311D73B00501349 /* GetURLWithJavaScriptURLDestroyingPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3E28A91311D73B00501349 /* GetURLWithJavaScriptURLDestroyingPlugin.cpp */; };
                1A4CCD4F171375A300981040 /* ToStringAndValueOfObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4CCD4E171375A300981040 /* ToStringAndValueOfObject.cpp */; };
                1A215A7F11F2609C008AD0F5 /* PluginTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginTest.cpp; sourceTree = "<group>"; };
                1A215A8011F2609C008AD0F5 /* PluginTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginTest.h; sourceTree = "<group>"; };
                1A24BAA8120734EE00FBB059 /* NPRuntimeObjectFromDestroyedPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NPRuntimeObjectFromDestroyedPlugin.cpp; sourceTree = "<group>"; };
+               1A2FB84C178C80920059FD96 /* DefaultPolicyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DefaultPolicyDelegate.h; sourceTree = "<group>"; };
+               1A2FB84D178C80930059FD96 /* DefaultPolicyDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DefaultPolicyDelegate.m; sourceTree = "<group>"; };
                1A31EB3713466AC100017372 /* ConvertPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConvertPoint.cpp; sourceTree = "<group>"; };
                1A3E28A91311D73B00501349 /* GetURLWithJavaScriptURLDestroyingPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetURLWithJavaScriptURLDestroyingPlugin.cpp; sourceTree = "<group>"; };
                1A4CCD4E171375A300981040 /* ToStringAndValueOfObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ToStringAndValueOfObject.cpp; sourceTree = "<group>"; };
                08FB7794FE84155DC02AAC07 /* DumpRenderTree */ = {
                        isa = PBXGroup;
                        children = (
+                               1A2FB84C178C80920059FD96 /* DefaultPolicyDelegate.h */,
+                               1A2FB84D178C80930059FD96 /* DefaultPolicyDelegate.m */,
                                9830F31E15C81181005AB206 /* DumpRenderTreeCommon.cpp */,
                                32A70AAB03705E1F00C91783 /* DumpRenderTreePrefix.h */,
                                1422A2750AF6F4BD00E1A883 /* Delegates */,
                                BCB284C70CFA83C4007E533E /* PixelDumpSupport.h in Headers */,
                                BCB284D00CFA83CC007E533E /* PixelDumpSupportCG.h in Headers */,
                                BCA18B650C9B08C200114369 /* PolicyDelegate.h in Headers */,
+                               1A2FB84E178C80930059FD96 /* DefaultPolicyDelegate.h in Headers */,
                                BCA18B670C9B08C200114369 /* ResourceLoadDelegate.h in Headers */,
                                3A5626CC131CA036002BE6D9 /* StorageTrackerDelegate.h in Headers */,
                                BC0131DB0C9772010087317D /* TestRunner.h in Headers */,
                                BC0131DA0C9772010087317D /* TestRunner.cpp in Sources */,
                                BCA18B240C9B014B00114369 /* TestRunnerMac.mm in Sources */,
                                BCA18B490C9B02C400114369 /* TextInputController.m in Sources */,
+                               1A2FB84F178C80930059FD96 /* DefaultPolicyDelegate.m in Sources */,
                                BCA18B6A0C9B08C200114369 /* UIDelegate.mm in Sources */,
                                4437730E125CBC3600AAE02C /* WebArchiveDumpSupport.cpp in Sources */,
                                440590711268453800CFD48D /* WebArchiveDumpSupportMac.mm in Sources */,
index 9b44f3e..2f301c8 100644 (file)
@@ -32,6 +32,7 @@
 
 #import "AccessibilityController.h"
 #import "CheckedMalloc.h"
+#import "DefaultPolicyDelegate.h"
 #import "DumpRenderTreeDraggingInfo.h"
 #import "DumpRenderTreePasteboard.h"
 #import "DumpRenderTreeWindow.h"
@@ -148,6 +149,7 @@ static EditingDelegate *editingDelegate;
 static ResourceLoadDelegate *resourceLoadDelegate;
 static HistoryDelegate *historyDelegate;
 PolicyDelegate *policyDelegate;
+DefaultPolicyDelegate *defaultPolicyDelegate;
 StorageTrackerDelegate *storageDelegate;
 
 static int dumpPixelsForAllTests = NO;
@@ -784,6 +786,7 @@ static void allocateGlobalControllers()
     policyDelegate = [[PolicyDelegate alloc] init];
     historyDelegate = [[HistoryDelegate alloc] init];
     storageDelegate = [[StorageTrackerDelegate alloc] init];
+    defaultPolicyDelegate = [[DefaultPolicyDelegate alloc] init];
 }
 
 // ObjC++ doens't seem to let me pass NSObject*& sadly.
@@ -1284,7 +1287,7 @@ static void resetWebViewToConsistentStateBeforeTesting()
     [webView _scaleWebView:1.0 atOrigin:NSZeroPoint];
     [webView _setCustomBackingScaleFactor:0];
     [webView setTabKeyCyclesThroughElements:YES];
-    [webView setPolicyDelegate:nil];
+    [webView setPolicyDelegate:defaultPolicyDelegate];
     [policyDelegate setPermissive:NO];
     [policyDelegate setControllerToNotifyDone:0];
     [frameLoadDelegate resetToConsistentState];
index ce50e5f..6c73311 100644 (file)
@@ -32,6 +32,7 @@
 #include <CoreFoundation/CoreFoundation.h>
 
 #ifdef __OBJC__
+@class DefaultPolicyDelegate;
 @class DumpRenderTreeDraggingInfo;
 @class NavigationController;
 @class PolicyDelegate;
@@ -40,6 +41,7 @@
 @class WebScriptWorld;
 @class WebView;
 #else
+class DefaultPolicyDelegate;
 class DumpRenderTreeDraggingInfo;
 class NavigationController;
 class PolicyDelegate;
@@ -57,6 +59,7 @@ extern DumpRenderTreeDraggingInfo *draggingInfo;
 extern NavigationController* gNavigationController;
 extern PolicyDelegate* policyDelegate;
 extern StorageTrackerDelegate* storageDelegate;
+extern DefaultPolicyDelegate *defaultPolicyDelegate;
 
 void setWaitToDumpWatchdog(CFRunLoopTimerRef);
 bool shouldSetWaitToDumpWatchdog();
index 6b98693..a7d07de 100644 (file)
@@ -30,6 +30,7 @@
 #import "DumpRenderTree.h"
 #import "TestRunner.h"
 
+#import "DefaultPolicyDelegate.h"
 #import "EditingDelegate.h"
 #import "MockGeolocationProvider.h"
 #import "MockWebNotificationProvider.h"
@@ -407,11 +408,13 @@ void TestRunner::setAuthorAndUserStylesEnabled(bool flag)
 
 void TestRunner::setCustomPolicyDelegate(bool setDelegate, bool permissive)
 {
-    if (setDelegate) {
-        [policyDelegate setPermissive:permissive];
-        [[mainFrame webView] setPolicyDelegate:policyDelegate];
-    } else
-        [[mainFrame webView] setPolicyDelegate:nil];
+    if (!setDelegate) {
+        [[mainFrame webView] setPolicyDelegate:defaultPolicyDelegate];
+        return;
+    }
+
+    [policyDelegate setPermissive:permissive];
+    [[mainFrame webView] setPolicyDelegate:policyDelegate];
 }
 
 void TestRunner::setDatabaseQuota(unsigned long long quota)