Changeset 274697 in webkit
- Timestamp:
- Mar 18, 2021, 7:37:52 PM (6 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 1 added
- 7 edited
- 1 copied
-
ChangeLog (modified) (1 diff)
-
SourcesCocoa.txt (modified) (1 diff)
-
UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h (copied) (copied from trunk/Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm ) (2 diffs)
-
UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm (added)
-
UIProcess/Inspector/mac/WKInspectorViewController.h (modified) (1 diff)
-
UIProcess/Inspector/mac/WKInspectorViewController.mm (modified) (6 diffs)
-
UIProcess/Inspector/mac/WebInspectorProxyMac.mm (modified) (1 diff)
-
WebKit.xcodeproj/project.pbxproj (modified) (4 diffs)
-
WebProcess/Inspector/mac/WebInspectorUIMac.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r274692 r274697 1 2021-03-18 BJ Burg <bburg@apple.com> 2 3 [Cocoa] Web Inspector: load inspector resources using a custom scheme handler 4 https://bugs.webkit.org/show_bug.cgi?id=179904 5 <rdar://problem/10887211> 6 7 Reviewed by Geoff Garen. 8 9 Load WebInspectorUI resources via the inspector-resource:// scheme. 10 Moving off of file:// URLs will allow for a tighter sandbox and 11 will fix the longstanding issue that Web Inspector's settings are 12 part of the file:// scheme and cleared when Safari clears website data. 13 14 This also has the effect of resetting Web Inspector settings since 15 they are no longer associated with file:///. 16 17 Loading via this scheme is exercised by existing inspector tests. 18 19 * SourcesCocoa.txt: Added new file. 20 * WebKit.xcodeproj/project.pbxproj: 21 * UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h: Copied from Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm. 22 * UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm: Added. 23 (-[WKInspectorResourceURLSchemeHandler webView:startURLSchemeTask:]): 24 Use a global concurrent queue and NSOperation / NSOperationQueue to support 25 reading files off the main queue. 26 27 (-[WKInspectorResourceURLSchemeHandler webView:stopURLSchemeTask:]): 28 Translate the request URL to a bundle resource URL, read the data, and send a response 29 with the file data. Return an error if the file could not be found or read. 30 31 * UIProcess/Inspector/mac/WKInspectorViewController.h: 32 * UIProcess/Inspector/mac/WKInspectorViewController.mm: 33 (-[WKInspectorViewController webViewConfiguration]): 34 (+[WKInspectorViewController URLForInspectorResource:]): 35 (-[WKInspectorViewController webView:decidePolicyForNavigationAction:decisionHandler:]): 36 Allow navigations to URIs with the inspector-resource:// scheme. 37 38 * UIProcess/Inspector/mac/WebInspectorProxyMac.mm: 39 (WebKit::WebInspectorProxy::inspectorPageURL): 40 (WebKit::WebInspectorProxy::inspectorTestPageURL): 41 (WebKit::WebInspectorProxy::inspectorBaseURL): 42 Updated. 43 44 * WebProcess/Inspector/mac/WebInspectorUIMac.mm: 45 (WebKit::webInspectorUILocalizedStringsURL): 46 Updated. 47 1 48 2021-03-18 Sihui Liu <sihui_liu@appe.com> 2 49 -
trunk/Source/WebKit/SourcesCocoa.txt
r274462 r274697 430 430 UIProcess/Inspector/mac/RemoteWebInspectorProxyMac.mm 431 431 UIProcess/Inspector/mac/WebInspectorProxyMac.mm 432 UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.mm 432 433 UIProcess/Inspector/mac/WKInspectorViewController.mm 433 434 UIProcess/Inspector/mac/WKInspectorWKWebView.mm -
trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorResourceURLSchemeHandler.h
r274696 r274697 1 1 /* 2 * Copyright (C) 20 10-2019Apple Inc. All rights reserved.2 * Copyright (C) 2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #import "config.h"27 #import "WebInspectorUI.h"28 #import "RemoteWebInspectorUI.h"29 30 26 #if PLATFORM(MAC) 31 27 32 namespace WebKit { 28 #import <WebKit/WKFoundation.h> 29 #import <WebKit/WKURLSchemeHandler.h> 33 30 34 bool WebInspectorUI::canSave() 35 { 36 return true; 37 } 31 @protocol WKInspectorViewControllerDelegate; 38 32 39 static String webInspectorUILocalizedStringsURL() 40 { 41 NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"]; 42 if (!bundle) 43 return String(); 33 NS_ASSUME_NONNULL_BEGIN 44 34 45 NSString *path = [bundle pathForResource:@"localizedStrings" ofType:@"js"]; 46 if (!path) 47 return String(); 48 49 return [NSURL fileURLWithPath:path isDirectory:NO].absoluteString; 50 } 35 @interface WKInspectorResourceURLSchemeHandler : NSObject <WKURLSchemeHandler> 36 @end 51 37 52 String WebInspectorUI::localizedStringsURL() const 53 { 54 return webInspectorUILocalizedStringsURL(); 55 } 56 57 String RemoteWebInspectorUI::localizedStringsURL() const 58 { 59 return webInspectorUILocalizedStringsURL(); 60 } 61 62 } // namespace WebKit 38 NS_ASSUME_NONNULL_END 63 39 64 40 #endif // PLATFORM(MAC) -
trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.h
r269068 r274697 48 48 49 49 + (BOOL)viewIsInspectorWebView:(NSView *)view; 50 + (NSURL * _Nullable)URLForInspectorResource:(NSString *)resource; 50 51 51 52 @end -
trunk/Source/WebKit/UIProcess/Inspector/mac/WKInspectorViewController.mm
r273109 r274697 1 1 /* 2 * Copyright (C) 2017-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 #import "APINavigation.h" 32 32 #import "WKFrameInfo.h" 33 #import "WKInspectorResourceURLSchemeHandler.h" 33 34 #import "WKInspectorWKWebView.h" 34 35 #import "WKNavigationAction.h" … … 47 48 #import <wtf/WeakObjCPtr.h> 48 49 50 static NSString * const WKInspectorResourceScheme = @"inspector-resource"; 51 49 52 @interface WKInspectorViewController () <WKUIDelegate, WKNavigationDelegate, WKInspectorWKWebViewDelegate> 50 53 @end … … 111 114 - (WKWebViewConfiguration *)webViewConfiguration 112 115 { 113 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 116 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 117 RetainPtr<WKInspectorResourceURLSchemeHandler> inspectorSchemeHandler = adoptNS([[WKInspectorResourceURLSchemeHandler alloc] init]); 118 [configuration setURLSchemeHandler:inspectorSchemeHandler.autorelease() forURLScheme:WKInspectorResourceScheme]; 114 119 115 120 WKPreferences *preferences = configuration.get().preferences; … … 159 164 { 160 165 return [view isKindOfClass:[WKInspectorWKWebView class]]; 166 } 167 168 + (NSURL *)URLForInspectorResource:(NSString *)resource 169 { 170 return [NSURL URLWithString:[NSString stringWithFormat:@"%@:///%@", WKInspectorResourceScheme, resource]].URLByStandardizingPath; 161 171 } 162 172 … … 240 250 241 251 // Allow loading of the main inspector file. 242 if ( WebKit::WebInspectorProxy::isMainOrTestInspectorPage(navigationAction.request.URL)) {252 if ([navigationAction.request.URL.scheme isEqualToString:WKInspectorResourceScheme]) { 243 253 decisionHandler(WKNavigationActionPolicyAllow); 244 254 return; -
trunk/Source/WebKit/UIProcess/Inspector/mac/WebInspectorProxyMac.mm
r274106 r274697 780 780 String WebInspectorProxy::inspectorPageURL() 781 781 { 782 NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"]; 783 if (!bundle) 784 return String(); 785 786 NSString *path = [bundle pathForResource:@"Main" ofType:@"html"]; 787 ASSERT(path && path.length); 788 if (!path) 789 return String(); 790 791 return [NSURL fileURLWithPath:path isDirectory:NO].absoluteString; 782 return [WKInspectorViewController URLForInspectorResource:@"Main.html"].absoluteString; 792 783 } 793 784 794 785 String WebInspectorProxy::inspectorTestPageURL() 795 786 { 796 NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"]; 797 if (!bundle) 798 return String(); 799 800 // We might not have a Test.html in Production builds. 801 NSString *path = [bundle pathForResource:@"Test" ofType:@"html"]; 802 if (!path) 803 return String(); 804 805 return [NSURL fileURLWithPath:path isDirectory:NO].absoluteString; 787 return [WKInspectorViewController URLForInspectorResource:@"Test.html"].absoluteString; 806 788 } 807 789 808 790 String WebInspectorProxy::inspectorBaseURL() 809 791 { 810 NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"]; 811 if (!bundle) 812 return String(); 813 814 NSString *path = bundle.resourcePath; 815 ASSERT(path && path.length); 816 817 return [NSURL fileURLWithPath:path isDirectory:YES].absoluteString; 792 return [WKInspectorViewController URLForInspectorResource:@""].absoluteString; 818 793 } 819 794 -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r274558 r274697 1523 1523 9979CA58237F49F10039EC05 /* _WKInspectorPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 9979CA57237F49F00039EC05 /* _WKInspectorPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1524 1524 99996A9F25004BCC004F7559 /* _WKInspectorPrivateForTesting.h in Headers */ = {isa = PBXBuildFile; fileRef = 99996A9D25004BCB004F7559 /* _WKInspectorPrivateForTesting.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1525 99A7ACE526012922006D57FD /* WKInspectorResourceURLSchemeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 99A7ACE326012919006D57FD /* WKInspectorResourceURLSchemeHandler.h */; }; 1525 1526 99B16757252BB7E10073140E /* _WKInspectorExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 99B16754252BB7E00073140E /* _WKInspectorExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1526 1527 99B16758252BB7E10073140E /* _WKInspectorExtensionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 99B16755252BB7E10073140E /* _WKInspectorExtensionInternal.h */; }; … … 4895 4896 999B7ED82550E4A800F450A4 /* InspectorExtensionTypes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorExtensionTypes.cpp; sourceTree = "<group>"; }; 4896 4897 999B7F4F2554BA3F00F450A4 /* APIInspectorExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIInspectorExtension.cpp; sourceTree = "<group>"; }; 4898 99A7ACE326012919006D57FD /* WKInspectorResourceURLSchemeHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKInspectorResourceURLSchemeHandler.h; sourceTree = "<group>"; }; 4899 99A7ACE42601291A006D57FD /* WKInspectorResourceURLSchemeHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKInspectorResourceURLSchemeHandler.mm; sourceTree = "<group>"; }; 4897 4900 99B16754252BB7E00073140E /* _WKInspectorExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorExtension.h; sourceTree = "<group>"; }; 4898 4901 99B16755252BB7E10073140E /* _WKInspectorExtensionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorExtensionInternal.h; sourceTree = "<group>"; }; … … 9260 9263 A5D3504D1D78F0D2005124A9 /* RemoteWebInspectorProxyMac.mm */, 9261 9264 1CA8B935127C774E00576C2B /* WebInspectorProxyMac.mm */, 9265 99A7ACE326012919006D57FD /* WKInspectorResourceURLSchemeHandler.h */, 9266 99A7ACE42601291A006D57FD /* WKInspectorResourceURLSchemeHandler.mm */, 9262 9267 994BADF11F7D77EA00B571E7 /* WKInspectorViewController.h */, 9263 9268 994BADF21F7D77EB00B571E7 /* WKInspectorViewController.mm */, … … 12591 12596 A54293A4195A43DA002782C7 /* WKInspectorNodeSearchGestureRecognizer.h in Headers */, 12592 12597 6EE849C81368D9390038D481 /* WKInspectorPrivateMac.h in Headers */, 12598 99A7ACE526012922006D57FD /* WKInspectorResourceURLSchemeHandler.h in Headers */, 12593 12599 994BADF41F7D781400B571E7 /* WKInspectorViewController.h in Headers */, 12594 12600 A518B5D21FE1D55B00F9FA28 /* WKInspectorWKWebView.h in Headers */, -
trunk/Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm
r255214 r274697 1 1 /* 2 * Copyright (C) 2010-20 19Apple Inc. All rights reserved.2 * Copyright (C) 2010-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #import "WebInspectorUI.h" 28 28 #import "RemoteWebInspectorUI.h" 29 #import "WKInspectorViewController.h" 29 30 30 31 #if PLATFORM(MAC) … … 39 40 static String webInspectorUILocalizedStringsURL() 40 41 { 41 NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"]; 42 if (!bundle) 43 return String(); 44 45 NSString *path = [bundle pathForResource:@"localizedStrings" ofType:@"js"]; 46 if (!path) 47 return String(); 48 49 return [NSURL fileURLWithPath:path isDirectory:NO].absoluteString; 42 return [WKInspectorViewController URLForInspectorResource:@"localizedStrings.js"].absoluteString; 50 43 } 51 44
Note:
See TracChangeset
for help on using the changeset viewer.