Changeset 286799 in webkit
- Timestamp:
- Dec 9, 2021, 12:55:16 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 25 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/inspector/InspectorFrontendClient.h (modified) (1 diff)
-
Source/WebCore/inspector/InspectorFrontendHost.cpp (modified) (1 diff)
-
Source/WebCore/inspector/InspectorFrontendHost.h (modified) (1 diff)
-
Source/WebCore/inspector/InspectorFrontendHost.idl (modified) (1 diff)
-
Source/WebInspectorUI/ChangeLog (modified) (1 diff)
-
Source/WebInspectorUI/UserInterface/Controllers/WebInspectorExtensionController.js (modified) (2 diffs)
-
Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js (modified) (2 diffs)
-
Source/WebInspectorUI/UserInterface/Views/WebInspectorExtensionTabContentView.js (modified) (3 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/API/APIInspectorExtensionClient.h (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h (modified) (1 diff)
-
Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h (modified) (2 diffs)
-
Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm (modified) (2 diffs)
-
Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h (modified) (1 diff)
-
Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in (modified) (1 diff)
-
Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h (modified) (1 diff)
-
Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/Inspector/WebInspectorUI.h (modified) (1 diff)
-
Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp (modified) (3 diffs)
-
Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286796 r286799 1 2021-12-08 BJ Burg <bburg@apple.com> 2 3 [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates 4 https://bugs.webkit.org/show_bug.cgi?id=233935 5 <rdar://86123899> 6 7 Reviewed by Patrick Angle. 8 9 Add new InspectorFrontendHost hooks to notify the client about didNavigateExtensionTab(). 10 11 * inspector/InspectorFrontendClient.h: 12 (WebCore::InspectorFrontendClient::didNavigateExtensionTab): 13 * inspector/InspectorFrontendHost.cpp: 14 (WebCore::InspectorFrontendHost::didNavigateExtensionTab): 15 * inspector/InspectorFrontendHost.h: 16 * inspector/InspectorFrontendHost.idl: 17 1 18 2021-12-09 Said Abou-Hallawa <said@apple.com> 2 19 -
trunk/Source/WebCore/inspector/InspectorFrontendClient.h
r284857 r286799 123 123 virtual void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) { } 124 124 virtual void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) { } 125 virtual void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) { } 125 126 virtual void inspectedPageDidNavigate(const URL&) { } 126 127 #endif -
trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp
r283857 r286799 708 708 } 709 709 710 void InspectorFrontendHost::didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const String& newURLString) 711 { 712 if (!m_client) 713 return; 714 715 m_client->didNavigateExtensionTab(extensionID, extensionTabID, { URL(), newURLString }); 716 } 717 710 718 void InspectorFrontendHost::inspectedPageDidNavigate(const String& newURLString) 711 719 { -
trunk/Source/WebCore/inspector/InspectorFrontendHost.h
r283857 r286799 144 144 void didShowExtensionTab(const String& extensionID, const String& extensionTabID); 145 145 void didHideExtensionTab(const String& extensionID, const String& extensionTabID); 146 void didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const String& url); 146 147 void inspectedPageDidNavigate(const String& url); 147 148 ExceptionOr<JSC::JSValue> evaluateScriptInExtensionTab(HTMLIFrameElement& extensionFrame, const String& scriptSource); -
trunk/Source/WebCore/inspector/InspectorFrontendHost.idl
r283857 r286799 101 101 [Conditional=INSPECTOR_EXTENSIONS] undefined didShowExtensionTab(DOMString extensionID, DOMString extensionTabID); 102 102 [Conditional=INSPECTOR_EXTENSIONS] undefined didHideExtensionTab(DOMString extensionID, DOMString extensionTabID); 103 [Conditional=INSPECTOR_EXTENSIONS] undefined didNavigateExtensionTab(DOMString extensionID, DOMString extensionTabID, DOMString newURL); 103 104 [Conditional=INSPECTOR_EXTENSIONS] undefined inspectedPageDidNavigate(DOMString newURL); 104 105 [Conditional=INSPECTOR_EXTENSIONS] any evaluateScriptInExtensionTab(HTMLIFrameElement extensionFrame, DOMString scriptSource); -
trunk/Source/WebInspectorUI/ChangeLog
r286792 r286799 1 2021-12-08 BJ Burg <bburg@apple.com> 2 3 [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates 4 https://bugs.webkit.org/show_bug.cgi?id=233935 5 <rdar://86123899> 6 7 Reviewed by Patrick Angle. 8 9 In order instrument all loads inside the extension iframe, we cannot rely on the <iframe src> attribute 10 to query the currently loaded page, or to change the current page. Use a helper method to query and set 11 the iframe location indirectly using `document.location`. 12 13 * UserInterface/Protocol/InspectorFrontendAPI.js: 14 15 * UserInterface/Controllers/WebInspectorExtensionController.js: 16 (WI.WebInspectorExtensionController.prototype.createTabForExtension): 17 (WI.WebInspectorExtensionController.prototype.showExtensionTab): 18 Standardize on returning {"result": value} from these methods. 19 20 * UserInterface/Views/WebInspectorExtensionTabContentView.js: 21 (WI.WebInspectorExtensionTabContentView): 22 (WI.WebInspectorExtensionTabContentView.prototype.whenPageAvailable): Added. 23 (WI.WebInspectorExtensionTabContentView.prototype._extensionFrameDidLoad): 24 Trigger a load of the actual requested page by evaluating `document.location.href = <url>` 25 in the context of the extension tab iframe. Notify clients when this non-initial load completes. 26 27 (WI.WebInspectorExtensionTabContentView.prototype.async _maybeDispatchDidNavigateExtensionTab): 28 Dispatch didNavigateExtensionTab with the new URL when the extension tab iframe completes a load. 29 Don't notify the client if the extension tab has not yet loaded. 30 1 31 2021-12-09 Razvan Caliman <rcaliman@apple.com> 2 32 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/WebInspectorExtensionController.js
r286329 r286799 94 94 95 95 // The calling convention is to return an error string or a result object. 96 return { extensionTabID};96 return {"result": extensionTabID}; 97 97 } 98 98 … … 184 184 185 185 tabContentView.visible = true; 186 187 // Clients expect to be able to use evaluateScriptInExtensionTab() when this method 188 // returns, so wait for the extension tab to finish its loading sequence. Wrap the result. 189 return tabContentView.whenPageAvailable().then((sourceURL) => { return {"result": sourceURL}; }); 186 190 } 187 191 -
trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorFrontendAPI.js
r286329 r286799 211 211 }, 212 212 213 // Returns a WI.WebInspectorExtension.ErrorCode if an error occurred, otherwise an object 214 // with an 'extensionTabID' key representing the tab identifier for the newly created tab. 213 // Returns a string (WI.WebInspectorExtension.ErrorCode) if an error occurred that prevented creating a tab. 214 // Returns a Promise that is resolved if the evaluation completes and rejected if there was an internal error. 215 // When the promise is fulfilled, it will be either: 216 // - resolved with an object containing a 'result' key and value that is the tab identifier for the new tab. 217 // - rejected with an object containing an 'error' key and value that is the exception that was thrown while evaluating script. 215 218 createTabForExtension(extensionID, tabName, tabIconURL, sourceURL) 216 219 { … … 234 237 }, 235 238 236 // Returns a WI.WebInspectorExtension.ErrorCode if an error occurred, otherwise nothing. 239 // Returns a string (WI.WebInspectorExtension.ErrorCode) if an error occurred before attempting to switch tabs. 240 // Returns a Promise that is resolved if the tab could be shown and rejected if the tab could not be shown. 241 // When the promise is fulfilled, it will be either: 242 // - resolved with no value. 243 // - rejected with an object containing an 'error' key and value that is the exception that was thrown while showing the tab. 237 244 showExtensionTab(extensionTabID) 238 245 { -
trunk/Source/WebInspectorUI/UserInterface/Views/WebInspectorExtensionTabContentView.js
r286329 r286799 41 41 this._sourceURL = sourceURL; 42 42 43 this._iframeFinishedInitialLoad = false; 44 this._whenPageAvailablePromise = new WI.WrappedPromise; 45 43 46 this._iframeElement = this.element.appendChild(document.createElement("iframe")); 44 47 this._iframeElement.addEventListener("load", this._extensionFrameDidLoad.bind(this)); 45 this._iframeElement.src = this._sourceURL;46 47 this._frameContentDidLoad = false;48 48 } 49 49 … … 72 72 { 73 73 return true; 74 } 75 76 whenPageAvailable() 77 { 78 return this._whenPageAvailablePromise.promise; 74 79 } 75 80 … … 110 115 _extensionFrameDidLoad() 111 116 { 112 this._frameContentDidLoad = true; 113 this._maybeDispatchDidShowExtensionTab(); 117 // Bounce from the initial empty page to the requested sourceURL. 118 if (!this._iframeFinishedInitialLoad) { 119 this._iframeFinishedInitialLoad = true; 120 WI.sharedApp.extensionController.evaluateScriptInExtensionTab(this._extensionTabID, `document.location.replace("${this._sourceURL}");`); 121 return; 122 } 123 124 // Signal that the page is available since we already bounced to the requested page. 125 if (!this._whenPageAvailablePromise.settled) 126 this._whenPageAvailablePromise.resolve(this._sourceURL); 127 128 this._maybeDispatchDidNavigateExtensionTab(); 129 } 130 131 async _maybeDispatchDidNavigateExtensionTab() 132 { 133 if (!this.element.isConnected) 134 return; 135 136 let payload = await WI.sharedApp.extensionController.evaluateScriptInExtensionTab(this._extensionTabID, "document.location.href"); 137 console.assert(payload.result, "Should be able to unwrap evaluation in extension tab!", payload.result); 138 139 if (InspectorFrontendHost.supportsWebExtensions) 140 InspectorFrontendHost.didNavigateExtensionTab(this._extension.extensionID, this._extensionTabID, payload.result); 114 141 } 115 142 116 143 _maybeDispatchDidShowExtensionTab() 117 144 { 118 if (!this. _frameContentDidLoad || !this.element.isConnected)145 if (!this.element.isConnected) 119 146 return; 120 147 -
trunk/Source/WebKit/ChangeLog
r286788 r286799 1 2021-12-08 BJ Burg <bburg@apple.com> 2 3 [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates 4 https://bugs.webkit.org/show_bug.cgi?id=233935 5 <rdar://86123899> 6 7 Reviewed by Patrick Angle. 8 9 Add plumbing to notify clients when an extension tab loads. This is implemented similarly to 10 -inspectorExtension:didShowExtensionTab: and -inspectorExtension:didHideExtensionTab:. 11 12 * UIProcess/API/APIInspectorExtensionClient.h: 13 (API::InspectorExtensionClient::didNavigateExtensionTab): 14 15 * UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h: 16 17 * UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h: 18 * UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm: 19 (WebKit::InspectorExtensionDelegate::InspectorExtensionDelegate): 20 (WebKit::InspectorExtensionDelegate::InspectorExtensionClient::didNavigateExtensionTab): 21 22 * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in: 23 * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h: 24 * UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp: 25 (WebKit::WebInspectorUIExtensionControllerProxy::didNavigateExtensionTab): 26 27 * WebProcess/Inspector/RemoteWebInspectorUI.h: 28 * WebProcess/Inspector/RemoteWebInspectorUI.cpp: 29 (WebKit::RemoteWebInspectorUI::didNavigateExtensionTab): 30 31 * WebProcess/Inspector/WebInspectorUI.h: 32 * WebProcess/Inspector/WebInspectorUI.cpp: 33 (WebKit::WebInspectorUI::didHideExtensionTab): 34 (WebKit::WebInspectorUI::didNavigateExtensionTab): 35 36 * WebProcess/Inspector/WebInspectorUIExtensionController.h: 37 * WebProcess/Inspector/WebInspectorUIExtensionController.cpp: 38 (WebKit::WebInspectorUIExtensionController::createTabForExtension): 39 Standardize on returning {result: value} for showExtensionTab. 40 41 (WebKit::WebInspectorUIExtensionController::showExtensionTab): 42 Standardize on returning {result: value} for showExtensionTab. 43 Also, there's no need to inspect the result value if it's not an error. 44 45 (WebKit::WebInspectorUIExtensionController::didNavigateExtensionTab): 46 Add plumbing. 47 1 48 2021-12-09 Brady Eidson <beidson@apple.com> 2 49 -
trunk/Source/WebKit/UIProcess/API/APIInspectorExtensionClient.h
r283857 r286799 38 38 virtual void didShowExtensionTab(const Inspector::ExtensionTabID&) { } 39 39 virtual void didHideExtensionTab(const Inspector::ExtensionTabID&) { } 40 virtual void didNavigateExtensionTab(const Inspector::ExtensionTabID&, const WTF::URL&) { } 40 41 virtual void inspectedPageDidNavigate(const WTF::URL&) { } 41 42 }; -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInspectorExtensionDelegate.h
r283857 r286799 54 54 55 55 /** 56 * @abstract Called when a tab associated with this extension has navigated to a new URL. 57 * @param extension The extension that created the tab. 58 * @param tabIdentifier Identifier for the tab that navigated. 59 * @param URL The new URL for the extension tab's page. 60 */ 61 - (void)inspectorExtension:(_WKInspectorExtension *)extension didNavigateTabWithIdentifier:(NSString *)tabIdentifier newURL:(NSURL *)newURL; 62 63 /** 56 64 * @abstract Called when the inspected page has navigated to a new URL. 65 * @param extension The extension that is being notified. 57 66 * @param url The new URL for the inspected page. 58 67 */ -
trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.h
r283857 r286799 57 57 void didShowExtensionTab(const Inspector::ExtensionTabID&) override; 58 58 void didHideExtensionTab(const Inspector::ExtensionTabID&) override; 59 void didNavigateExtensionTab(const Inspector::ExtensionTabID&, const URL&) override; 59 60 void inspectedPageDidNavigate(const URL&) override; 60 61 … … 68 69 bool inspectorExtensionDidShowTabWithIdentifier : 1; 69 70 bool inspectorExtensionDidHideTabWithIdentifier : 1; 71 bool inspectorExtensionDidNavigateTabWithIdentifier : 1; 70 72 bool inspectorExtensionInspectedPageDidNavigate : 1; 71 73 } m_delegateMethods; -
trunk/Source/WebKit/UIProcess/Inspector/Cocoa/InspectorExtensionDelegate.mm
r283857 r286799 42 42 m_delegateMethods.inspectorExtensionDidShowTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didShowTabWithIdentifier:)]; 43 43 m_delegateMethods.inspectorExtensionDidHideTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didHideTabWithIdentifier:)]; 44 m_delegateMethods.inspectorExtensionDidNavigateTabWithIdentifier = [delegate respondsToSelector:@selector(inspectorExtension:didNavigateTabWithIdentifier:newURL:)]; 44 45 m_delegateMethods.inspectorExtensionInspectedPageDidNavigate = [delegate respondsToSelector:@selector(inspectorExtension:inspectedPageDidNavigate:)]; 45 46 … … 87 88 } 88 89 90 void InspectorExtensionDelegate::InspectorExtensionClient::didNavigateExtensionTab(const Inspector::ExtensionTabID& extensionTabID, const WTF::URL& newURL) 91 { 92 if (!m_inspectorExtensionDelegate.m_delegateMethods.inspectorExtensionDidNavigateTabWithIdentifier) 93 return; 94 95 auto& delegate = m_inspectorExtensionDelegate.m_delegate; 96 if (!delegate) 97 return; 98 99 [delegate inspectorExtension:m_inspectorExtensionDelegate.m_inspectorExtension.get().get() didNavigateTabWithIdentifier:extensionTabID newURL:newURL]; 100 } 101 89 102 void InspectorExtensionDelegate::InspectorExtensionClient::inspectedPageDidNavigate(const WTF::URL& newURL) 90 103 { -
trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.cpp
r286329 r286799 269 269 } 270 270 271 void WebInspectorUIExtensionControllerProxy::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const WTF::URL& newURL) 272 { 273 auto it = m_extensionAPIObjectMap.find(extensionID); 274 if (it == m_extensionAPIObjectMap.end()) 275 return; 276 277 RefPtr<API::InspectorExtension> extension = it->value; 278 auto extensionClient = extension->client(); 279 if (!extensionClient) 280 return; 281 282 extensionClient->didNavigateExtensionTab(extensionTabID, newURL); 283 } 284 271 285 void WebInspectorUIExtensionControllerProxy::inspectedPageDidNavigate(const URL& newURL) 272 286 { -
trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.h
r286329 r286799 69 69 void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&); 70 70 void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&); 71 void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&); 71 72 void inspectedPageDidNavigate(const URL&); 72 73 -
trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIExtensionControllerProxy.messages.in
r283857 r286799 26 26 DidShowExtensionTab(String extensionID, String extensionTabID) 27 27 DidHideExtensionTab(String extensionID, String extensionTabID) 28 DidNavigateExtensionTab(String extensionID, String extensionTabID, URL newURL) 28 29 InspectedPageDidNavigate(URL newURL) 29 30 } -
trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp
r283857 r286799 307 307 } 308 308 309 void RemoteWebInspectorUI:: inspectedPageDidNavigate(const URL& newURL)309 void RemoteWebInspectorUI::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const URL& newURL) 310 310 { 311 311 if (!m_extensionController) 312 312 return; 313 313 314 m_extensionController->didNavigateExtensionTab(extensionID, extensionTabID, newURL); 315 } 316 317 void RemoteWebInspectorUI::inspectedPageDidNavigate(const URL& newURL) 318 { 319 if (!m_extensionController) 320 return; 321 314 322 m_extensionController->inspectedPageDidNavigate(newURL); 315 323 } -
trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h
r283857 r286799 123 123 void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override; 124 124 void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override; 125 void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) override; 125 126 void inspectedPageDidNavigate(const URL&) override; 126 127 #endif -
trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp
r283857 r286799 381 381 } 382 382 383 void WebInspectorUI:: inspectedPageDidNavigate(const URL& newURL)383 void WebInspectorUI::didNavigateExtensionTab(const String& extensionID, const String& extensionTabID, const URL& newURL) 384 384 { 385 385 if (!m_extensionController) 386 386 return; 387 387 388 m_extensionController->didNavigateExtensionTab(extensionID, extensionTabID, newURL); 389 } 390 391 void WebInspectorUI::inspectedPageDidNavigate(const URL& newURL) 392 { 393 if (!m_extensionController) 394 return; 395 388 396 m_extensionController->inspectedPageDidNavigate(newURL); 389 397 } -
trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h
r283857 r286799 157 157 void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override; 158 158 void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&) override; 159 void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&) override; 159 160 void inspectedPageDidNavigate(const URL&) override; 160 161 #endif -
trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp
r286747 r286799 205 205 206 206 auto* frontendGlobalObject = weakThis->m_frontendClient->frontendAPIDispatcher().frontendGlobalObject(); 207 JSC::JSValue foundProperty = objectResult->get(frontendGlobalObject, JSC::Identifier::fromString(frontendGlobalObject->vm(), " extensionTabID"_s));207 JSC::JSValue foundProperty = objectResult->get(frontendGlobalObject, JSC::Identifier::fromString(frontendGlobalObject->vm(), "result"_s)); 208 208 if (!foundProperty || !foundProperty.isString()) { 209 209 completionHandler(makeUnexpected(Inspector::ExtensionError::InternalError)); … … 358 358 359 359 if (auto parsedError = weakThis->parseExtensionErrorFromEvaluationResult(result)) { 360 LOG(Inspector, "Internal error encountered while evaluating upon the frontend: %s", Inspector::extensionErrorToString(*parsedError).utf8().data()); 360 if (!result.value().has_value()) { 361 auto exceptionDetails = result.value().error(); 362 LOG(Inspector, "Internal error encountered while showing extension tab at %s:%d:%d: %s", exceptionDetails.sourceURL.utf8().data(), exceptionDetails.lineNumber, exceptionDetails.columnNumber, exceptionDetails.message.utf8().data()); 363 } else 364 LOG(Inspector, "Internal error encountered while showing extension tab."); 365 361 366 completionHandler(makeUnexpected(*parsedError)); 362 367 return; 363 368 } 369 370 // If this assertion fails, then a `result.error()` was not handled above as expected. 371 ASSERT(result.has_value()); 364 372 365 373 completionHandler({ }); … … 445 453 } 446 454 455 void WebInspectorUIExtensionController::didNavigateExtensionTab(const Inspector::ExtensionID& extensionID, const Inspector::ExtensionTabID& extensionTabID, const URL& newURL) 456 { 457 WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorUIExtensionControllerProxy::DidNavigateExtensionTab { extensionID, extensionTabID, newURL }, m_inspectorPageIdentifier); 458 } 459 447 460 void WebInspectorUIExtensionController::inspectedPageDidNavigate(const URL& newURL) 448 461 { -
trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h
r286329 r286799 77 77 void didShowExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&); 78 78 void didHideExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&); 79 void didNavigateExtensionTab(const Inspector::ExtensionID&, const Inspector::ExtensionTabID&, const URL&); 79 80 void inspectedPageDidNavigate(const URL&); 80 81 -
trunk/Tools/ChangeLog
r286797 r286799 1 2021-12-08 BJ Burg <bburg@apple.com> 2 3 [Cocoa] Web Inspector: provide a way for _WKInspectorExtension clients to be to notified when an extension tab navigates 4 https://bugs.webkit.org/show_bug.cgi?id=233935 5 <rdar://86123899> 6 7 Reviewed by Patrick Angle. 8 9 Add API test coverage for -inspectorExtension:didNavigateTabWithIdentifier:newURL: 10 11 * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtension.mm: 12 (TEST): 13 Drive-by, fix an outdated completion handler type signature. 14 15 * TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm: 16 (-[InspectorExtensionDelegateForTesting inspectorExtension:didNavigateTabWithIdentifier:newURL:]): 17 (TEST): 18 Add a test case which exercises the new delegate method. 19 1 20 2021-12-09 Lauro Moura <lmoura@igalia.com> 2 21 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKInspectorExtensionDelegate.mm
r286329 r286799 44 44 45 45 static RetainPtr<NSURL> sharedNewURLAfterNavigation; 46 static bool extensionTabDidNavigateWasCalled; 46 47 47 48 @interface UIDelegateForTestingInspectorExtensionDelegate : NSObject <WKUIDelegate> … … 83 84 { 84 85 didHideExtensionTabWasCalled = true; 86 } 87 88 - (void)inspectorExtension:(_WKInspectorExtension *)extension didNavigateTabWithIdentifier:(NSString *)tabIdentifier newURL:(NSURL *)newURL 89 { 90 extensionTabDidNavigateWasCalled = true; 85 91 } 86 92 … … 235 241 } 236 242 243 // FIXME: Re-enable this test for debug once webkit.org/b/231847 is fixed. 244 #if !defined(NDEBUG) 245 TEST(WKInspectorExtensionDelegate, DISABLED_ExtensionTabNavigatedCallbacks) 246 #else 247 TEST(WKInspectorExtensionDelegate, ExtensionTabNavigatedCallbacks) 248 #endif 249 { 250 resetGlobalState(); 251 252 // Hook up the test-resource: handler so that we can navigate to a different test file. 253 if (!sharedURLSchemeHandler) 254 sharedURLSchemeHandler = adoptNS([[TestInspectorURLSchemeHandler alloc] init]); 255 256 auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]); 257 webViewConfiguration.get().preferences._developerExtrasEnabled = YES; 258 [webViewConfiguration setURLSchemeHandler:sharedURLSchemeHandler.get() forURLScheme:@"test-resource"]; 259 260 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]); 261 auto uiDelegate = adoptNS([UIDelegateForTestingInspectorExtensionDelegate new]); 262 263 [webView setUIDelegate:uiDelegate.get()]; 264 265 [[webView _inspector] show]; 266 TestWebKitAPI::Util::run(&didAttachLocalInspectorCalled); 267 268 // Register the test extension. 269 auto extensionID = [NSUUID UUID].UUIDString; 270 auto extensionBundleIdentifier = @"com.apple.webkit.ThirdExtension"; 271 auto extensionDisplayName = @"ThirdExtension"; 272 pendingCallbackWasCalled = false; 273 [[webView _inspector] registerExtensionWithID:extensionID extensionBundleIdentifier:extensionBundleIdentifier displayName:extensionDisplayName completionHandler:^(NSError *error, _WKInspectorExtension *extension) { 274 EXPECT_NULL(error); 275 EXPECT_NOT_NULL(extension); 276 sharedInspectorExtension = extension; 277 278 pendingCallbackWasCalled = true; 279 }]; 280 TestWebKitAPI::Util::run(&pendingCallbackWasCalled); 281 282 auto extensionDelegate = adoptNS([InspectorExtensionDelegateForTesting new]); 283 [sharedInspectorExtension setDelegate:extensionDelegate.get()]; 284 285 auto baseURL = [NSURL URLWithString:@"http://example.com/"]; 286 [webView loadHTMLString:@"<head><title>Test page to be inspected</title></head><body><p>Filler content</p></body>" baseURL:baseURL]; 287 [webView _test_waitForDidFinishNavigation]; 288 289 inspectedPageDidNavigateWasCalled = false; 290 TestWebKitAPI::Util::run(&inspectedPageDidNavigateWasCalled); 291 EXPECT_NS_EQUAL(sharedNewURLAfterNavigation.get().absoluteString, baseURL.absoluteString); 292 inspectedPageDidNavigateWasCalled = false; 293 294 // Create an extension tab. 295 auto iconURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-TabIcon-30x30.png"]; 296 auto sourceURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-basic-tab.html"]; 297 298 pendingCallbackWasCalled = false; 299 [sharedInspectorExtension createTabWithName:@"ThirdExtension-Tab" tabIconURL:iconURL sourceURL:sourceURL completionHandler:^(NSError *error, NSString *extensionTabIdentifier) { 300 EXPECT_NULL(error); 301 EXPECT_NOT_NULL(extensionTabIdentifier); 302 sharedExtensionTabIdentifier = extensionTabIdentifier; 303 304 pendingCallbackWasCalled = true; 305 }]; 306 TestWebKitAPI::Util::run(&pendingCallbackWasCalled); 307 308 pendingCallbackWasCalled = false; 309 [[webView _inspector] showExtensionTabWithIdentifier:sharedExtensionTabIdentifier.get() completionHandler:^(NSError *error) { 310 EXPECT_NULL(error); 311 312 pendingCallbackWasCalled = true; 313 }]; 314 TestWebKitAPI::Util::run(&pendingCallbackWasCalled); 315 316 pendingCallbackWasCalled = false; 317 extensionTabDidNavigateWasCalled = false; 318 auto newURL = [NSURL URLWithString:@"test-resource://ThirdExtension/InspectorExtension-basic-page.html"]; 319 [sharedInspectorExtension evaluateScript:[NSString stringWithFormat:@"window.location.replace(\"%@\")", newURL] inTabWithIdentifier:sharedExtensionTabIdentifier.get() completionHandler:^(NSError *error, id result) { 320 EXPECT_NULL(error); 321 322 pendingCallbackWasCalled = true; 323 }]; 324 TestWebKitAPI::Util::run(&pendingCallbackWasCalled); 325 TestWebKitAPI::Util::run(&extensionTabDidNavigateWasCalled); 326 327 // Unregister the test extension. 328 pendingCallbackWasCalled = false; 329 [[webView _inspector] unregisterExtension:sharedInspectorExtension.get() completionHandler:^(NSError * _Nullable error) { 330 EXPECT_NULL(error); 331 332 pendingCallbackWasCalled = true; 333 }]; 334 TestWebKitAPI::Util::run(&pendingCallbackWasCalled); 335 } 336 237 337 #endif // ENABLE(INSPECTOR_EXTENSIONS)
Note:
See TracChangeset
for help on using the changeset viewer.