8000 Expose the inspected web view from _WKInspectorWindow · WebKit/WebKit@5bb44c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bb44c8

Browse files
committed
Expose the inspected web view from _WKInspectorWindow
https://bugs.webkit.org/show_bug.cgi?id=251140 rdar://104628163 Reviewed by Patrick Angle. Introduce _WKInspectorWindow.inspectedWebView to read the web view inspected by the inspector hosted in a _WKInspectorWindow. * Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindow.h: * Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindow.mm: Let the compiler automatically synthesize the properties. Manually implementing them doesn't provide any benefit. (-[_WKInspectorWindow isForRemoteTarget]): Deleted. * Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindowInternal.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindow.h. As minor cleanup, add an internal header to redeclare the SPI as readwrite instead of exposing the properties as writable to WebKit clients who import the main header. * Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h: Add an optional parameter to createFrontendWindow() to specify a WebPageProxy being inspected. This will be used to populate the new `inspectedWebView` property. (WebKit::WebInspectorUIProxy::inspectorWindow const): Deleted. Remove this method. It wasn't being used anywhere. * Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm: (WebKit::WebInspectorUIProxy::createFrontendWindow): If an inspected WebPageProxy was provided, look up the WKWebView to assign to _WKInspectorWindow.inspectedWebView. (WebKit::WebInspectorUIProxy::platformCreateFrontendWindow): Pass the inspected page to createFrontendWindow(). * Source/WebKit/WebKit.xcodeproj/project.pbxproj: Add reference to _WKInspectorWindowInternal.h. Canonical link: https://commits.webkit.org/259393@main
1 parent 6211ce9 commit 5bb44c8

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindow.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@
2727

2828
#if !TARGET_OS_IPHONE
2929

30+
NS_ASSUME_NONNULL_BEGIN
31+
32+
@class WKWebView;
33+
3034
WK_CLASS_AVAILABLE(macos(10.15))
3135
@interface _WKInspectorWindow : NSWindow
3236

33-
@property (nonatomic, getter=isForRemoteTarget) BOOL forRemoteTarget;
37+
@property (nonatomic, readonly, getter=isForRemoteTarget) BOOL forRemoteTarget;
38+
@property (nonatomic, nullable, readonly, weak) WKWebView *inspectedWebView WK_API_AVAILABLE(macos(WK_MAC_TBA));
3439

3540
@end
3641

42+
NS_ASSUME_NONNULL_END
43+
3744
#endif

Source/WebKit/UIProcess/API/Cocoa/_WKInspectorWindow.mm

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424
*/
2525

2626
#import "config.h"
27-
#import "_WKInspectorWindow.h"
27+
#import "_WKInspectorWindowInternal.h"
2828

2929
#if PLATFORM(MAC)
3030

3131
@implementation _WKInspectorWindow
3232

33-
- (BOOL)isForRemoteTarget
34-
{
35-
return _forRemoteTarget;
36-
}
37-
3833
@end
3934

4035
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2023 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#import <WebKit/_WKInspectorWindow.h>
27+
28+
#if !TARGET_OS_IPHONE
29+
30+
NS_ASSUME_NONNULL_BEGIN
31+
32+
@interface _WKInspectorWindow ()
33+
34+
@property (nonatomic, readwrite, getter=isForRemoteTarget) BOOL forRemoteTarget;
35+
@property (nonatomic, nullable, readwrite, weak) WKWebView *inspectedWebView;
36+
37+
@end
38+
39+
NS_ASSUME_NONNULL_END
40+
41+
#endif // !TARGET_OS_IPHONE

Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class WebInspectorUIProxy
131131

132132
#if PLATFORM(MAC)
133133
enum class InspectionTargetType { Local, Remote };
134-
static RetainPtr<NSWindow> createFrontendWindow(NSRect savedWindowFrame, InspectionTargetType);
134+
static RetainPtr<NSWindow> createFrontendWindow(NSRect savedWindowFrame, InspectionTargetType, WebPageProxy* inspectedPage = nullptr);
135135
static void showSavePanel(NSWindow *, NSURL *, Vector<WebCore::InspectorFrontendClient::SaveData>&&, bool forceSaveAs, CompletionHandler<void(NSURL *)>&&);
136136

137137
void didBecomeActive();
@@ -140,7 +140,6 @@ class WebInspectorUIProxy
140140
void inspectedViewFrameDidChange(CGFloat = 0);
141141
void windowFrameDidChange();
142142
void windowFullScreenDidChange();
143-
NSWindow *inspectorWindow() const { return m_inspectorWindow.get(); }
144143

145144
void closeFrontendPage();
146145
void closeFrontendAfterInactivityTimerFired();

Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#import "WebPageProxy.h"
4444
#import "_WKInspectorConfigurationInternal.h"
4545
#import "_WKInspectorInternal.h"
46-
#import "_WKInspectorWindow.h"
46+
#import "_WKInspectorWindowInternal.h"
4747
#import <SecurityInterface/SFCertificatePanel.h>
4848
#import <SecurityInterface/SFCertificateView.h>
4949
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
@@ -356,7 +356,7 @@ - (IBAction)_popUpButtonAction:(id)sender
356356
}
357357
}
358358

359-
RetainPtr<NSWindow> WebInspectorUIProxy::createFrontendWindow(NSRect savedWindowFrame, InspectionTargetType targetType)
359+
RetainPtr<NSWindow> WebInspectorUIProxy::createFrontendWindow(NSRect savedWindowFrame, InspectionTargetType targetType, WebPageProxy* inspectedPage)
360360
{
361361
NSRect windowFrame = !NSIsEmptyRect(savedWindowFrame) ? savedWindowFrame : NSMakeRect(0, 0, initialWindowWidth, initialWindowHeight);
362362
auto window = adoptNS([[_WKInspectorWindow alloc] initWithContentRect:windowFrame styleMask:windowStyleMask backing:NSBackingStoreBuffered defer:NO]);
@@ -367,6 +367,9 @@ - (IBAction)_popUpButtonAction:(id)sender
367367
bool forRemoteTarget = targetType == InspectionTargetType::Remote;
368368
[window setForRemoteTarget:forRemoteTarget];
369369

370+
if (inspectedPage)
371+
[window setInspectedWebView:inspectedPage->cocoaView().get()];
372+
370373
CGFloat approximatelyHalfScreenSize = ([window screen].frame.size.width / 2) - 4;
371374
CGFloat minimumFullScreenWidth = std::max<CGFloat>(636, approximatelyHalfScreenSize);
372375
[window setMinFullScreenContentSize:NSMakeSize(minimumFullScreenWidth, minimumWindowHeight)];
@@ -473,7 +476,7 @@ - (IBAction)_popUpButtonAction:(id)sender
473476
savedWindowFrame = NSRectFromString(savedWindowFrameString);
474477
}
475478

476-
m_inspectorWindow = WebInspectorUIProxy::createFrontendWindow(savedWindowFrame, InspectionTargetType::Local);
479+
m_inspectorWindow = WebInspectorUIProxy::createFrontendWindow(savedWindowFrame, InspectionTargetType::Local, inspectedPage());
477480
[m_inspectorWindow setDelegate:m_objCAdapter.get()];
478481

479482
WKWebView *inspectorView = [m_inspectorViewController webView];

Source/WebKit/WebKit.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,6 +5745,7 @@
57455745
63C32C231E9810D900699BD0 /* _WKGeolocationPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKGeolocationPosition.mm; sourceTree = "<group>"; };
57465746
63C32C241E9810D900699BD0 /* _WKGeolocationPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationPosition.h; sourceTree = "<group>"; };
57475747
63C32C271E98119000699BD0 /* _WKGeolocationPositionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationPositionInternal.h; sourceTree = "<group>"; };
5748+
63DCF6AF2980C0E50016E213 /* _WKInspectorWindowInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKInspectorWindowInternal.h; sourceTree = "<group>"; };
57485749
63FABE191E970D65003011D5 /* _WKGeolocationCoreLocationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKGeolocationCoreLocationProvider.h; sourceTree = "<group>"; };
57495750
650994DF28C942B7006EE6DB /* com.apple.WebKit.WebContent.Crashy.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = com.apple.WebKit.WebContent.Crashy.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
57505751
6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageResourceLoadClient.cpp; sourceTree = "<group>"; };
@@ -10270,6 +10271,7 @@
1027010271
99996A9E25004BCB004F7559 /* _WKInspectorTesting.mm */,
1027110272
A5C0F0AA2000656E00536536 /* _WKInspectorWindow.h */,
1027210273
A5C0F0A92000656E00536536 /* _WKInspectorWindow.mm */,
10274+
63DCF6AF2980C0E50016E213 /* _WKInspectorWindowInternal.h */,
1027310275
31B362942141EBAD007BFA53 /* _WKInternalDebugFeature.h */,
1027410276
31B362922141EBAC007BFA53 /* _WKInternalDebugFeature.mm */,
1027510277
2D790A9C1AD7050D00AB90B3 /* _WKLayoutMode.h */,

0 commit comments

Comments
 (0)
0