Title: [223771] trunk/Source/WebKit
Revision
223771
Author
bb...@apple.com
Date
2017-10-20 10:28:57 -0700 (Fri, 20 Oct 2017)

Log Message

Web Inspector: consolidate code that hosts the Inspector page inside a WKWebView
https://bugs.webkit.org/show_bug.cgi?id=177661
<rdar://problem/34740286>

Reviewed by Joseph Pecoraro.

Modernize the ObjC adapter and related code a bit before it is hooked
into WKInspectorViewController.

* UIProcess/API/C/mac/WKInspectorPrivateMac.h: No need for the
ivar to be declared here, move to @implementation.

* UIProcess/WebInspectorProxy.h: Simplify the name to match modern convention.

* UIProcess/mac/WebInspectorProxyMac.mm:
(-[WKWebInspectorProxyObjCAdapter inspectorRef]):
(-[WKWebInspectorProxyObjCAdapter initWithWebInspectorProxy:]):
(-[WKWebInspectorProxyObjCAdapter invalidate]):
(-[WKWebInspectorProxyObjCAdapter windowDidMove:]):
(-[WKWebInspectorProxyObjCAdapter windowDidResize:]):
(-[WKWebInspectorProxyObjCAdapter windowWillClose:]):
(-[WKWebInspectorProxyObjCAdapter windowDidEnterFullScreen:]):
(-[WKWebInspectorProxyObjCAdapter windowDidExitFullScreen:]):
(-[WKWebInspectorProxyObjCAdapter inspectedViewFrameDidChange:]):
Remove unnecessary casts to and from void*.

(WebKit::WebInspectorProxy::attachmentViewDidChange):
(WebKit::WebInspectorProxy::setInspectorWindowFrame):
(WebKit::WebInspectorProxy::closeTimerFired):
(WebKit::WebInspectorProxy::createInspectorWindow):
(WebKit::WebInspectorProxy::platformCreateInspectorPage):
Fix uses of member variable m_objCAdapter.

(-[WKWebInspectorProxyObjCAdapter close]): Deleted.
Rename this to invalidate to match modern convention. In this context,
'close' might trick someone into thinking that this closes a window/page.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (223770 => 223771)


--- trunk/Source/WebKit/ChangeLog	2017-10-20 17:28:53 UTC (rev 223770)
+++ trunk/Source/WebKit/ChangeLog	2017-10-20 17:28:57 UTC (rev 223771)
@@ -6,6 +6,45 @@
 
         Reviewed by Joseph Pecoraro.
 
+        Modernize the ObjC adapter and related code a bit before it is hooked
+        into WKInspectorViewController.
+
+        * UIProcess/API/C/mac/WKInspectorPrivateMac.h: No need for the
+        ivar to be declared here, move to @implementation.
+
+        * UIProcess/WebInspectorProxy.h: Simplify the name to match modern convention.
+
+        * UIProcess/mac/WebInspectorProxyMac.mm:
+        (-[WKWebInspectorProxyObjCAdapter inspectorRef]):
+        (-[WKWebInspectorProxyObjCAdapter initWithWebInspectorProxy:]):
+        (-[WKWebInspectorProxyObjCAdapter invalidate]):
+        (-[WKWebInspectorProxyObjCAdapter windowDidMove:]):
+        (-[WKWebInspectorProxyObjCAdapter windowDidResize:]):
+        (-[WKWebInspectorProxyObjCAdapter windowWillClose:]):
+        (-[WKWebInspectorProxyObjCAdapter windowDidEnterFullScreen:]):
+        (-[WKWebInspectorProxyObjCAdapter windowDidExitFullScreen:]):
+        (-[WKWebInspectorProxyObjCAdapter inspectedViewFrameDidChange:]):
+        Remove unnecessary casts to and from void*.
+
+        (WebKit::WebInspectorProxy::attachmentViewDidChange):
+        (WebKit::WebInspectorProxy::setInspectorWindowFrame):
+        (WebKit::WebInspectorProxy::closeTimerFired):
+        (WebKit::WebInspectorProxy::createInspectorWindow):
+        (WebKit::WebInspectorProxy::platformCreateInspectorPage):
+        Fix uses of member variable m_objCAdapter.
+
+        (-[WKWebInspectorProxyObjCAdapter close]): Deleted.
+        Rename this to invalidate to match modern convention. In this context,
+        'close' might trick someone into thinking that this closes a window/page.
+
+2017-09-30  Brian Burg  <bb...@apple.com>
+
+        Web Inspector: consolidate code that hosts the Inspector page inside a WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=177661
+        <rdar://problem/34740286>
+
+        Reviewed by Joseph Pecoraro.
+
         Move code that sets up and controls the inspector WebView into WKInspectorViewController.
         This will be shared between RemoteWebInspectorProxy and WebInspectorProxy eventually,
         but for now just pull out code from RemoteWebInspectorProxy. The next patch will move

Modified: trunk/Source/WebKit/UIProcess/API/C/mac/WKInspectorPrivateMac.h (223770 => 223771)


--- trunk/Source/WebKit/UIProcess/API/C/mac/WKInspectorPrivateMac.h	2017-10-20 17:28:53 UTC (rev 223770)
+++ trunk/Source/WebKit/UIProcess/API/C/mac/WKInspectorPrivateMac.h	2017-10-20 17:28:57 UTC (rev 223771)
@@ -39,10 +39,7 @@
 
 // This class is the Web Inspector window delegate. It can be used to add interface
 // actions that need to work when the Web Inspector window is key.
-WK_EXPORT @interface WKWebInspectorProxyObjCAdapter : NSObject <NSWindowDelegate> {
-@private
-    void* _inspectorProxy;
-}
+WK_EXPORT @interface WKWebInspectorProxyObjCAdapter : NSObject <NSWindowDelegate>
 
 @property (readonly) WKInspectorRef inspectorRef;
 

Modified: trunk/Source/WebKit/UIProcess/WebInspectorProxy.h (223770 => 223771)


--- trunk/Source/WebKit/UIProcess/WebInspectorProxy.h	2017-10-20 17:28:53 UTC (rev 223770)
+++ trunk/Source/WebKit/UIProcess/WebInspectorProxy.h	2017-10-20 17:28:57 UTC (rev 223771)
@@ -234,7 +234,7 @@
 #if PLATFORM(MAC) && WK_API_ENABLED
     RetainPtr<WKWebInspectorWKWebView> m_inspectorView;
     RetainPtr<NSWindow> m_inspectorWindow;
-    RetainPtr<WKWebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter;
+    RetainPtr<WKWebInspectorProxyObjCAdapter> m_objCAdapter;
     HashMap<String, RetainPtr<NSURL>> m_suggestedToActualURLMap;
     RunLoop::Timer<WebInspectorProxy> m_closeTimer;
     String m_urlString;

Modified: trunk/Source/WebKit/UIProcess/mac/WebInspectorProxyMac.mm (223770 => 223771)


--- trunk/Source/WebKit/UIProcess/mac/WebInspectorProxyMac.mm	2017-10-20 17:28:53 UTC (rev 223770)
+++ trunk/Source/WebKit/UIProcess/mac/WebInspectorProxyMac.mm	2017-10-20 17:28:57 UTC (rev 223771)
@@ -59,19 +59,21 @@
 
 @interface WKWebInspectorProxyObjCAdapter ()
 
-- (id)initWithWebInspectorProxy:(WebInspectorProxy*)inspectorProxy;
-- (void)close;
+- (instancetype)initWithWebInspectorProxy:(WebInspectorProxy*)inspectorProxy;
+- (void)invalidate;
 
 @end
 
-@implementation WKWebInspectorProxyObjCAdapter
+@implementation WKWebInspectorProxyObjCAdapter {
+    WebInspectorProxy* _inspectorProxy;
+}
 
 - (WKInspectorRef)inspectorRef
 {
-    return toAPI(static_cast<WebInspectorProxy*>(_inspectorProxy));
+    return toAPI(_inspectorProxy);
 }
 
-- (id)initWithWebInspectorProxy:(WebInspectorProxy*)inspectorProxy
+- (instancetype)initWithWebInspectorProxy:(WebInspectorProxy*)inspectorProxy
 {
     ASSERT_ARG(inspectorProxy, inspectorProxy);
 
@@ -78,12 +80,13 @@
     if (!(self = [super init]))
         return nil;
 
-    _inspectorProxy = static_cast<void*>(inspectorProxy); // Not retained to prevent cycles
+    // Unretained to avoid a reference cycle.
+    _inspectorProxy = inspectorProxy;
 
     return self;
 }
 
-- (void)close
+- (void)invalidate
 {
     _inspectorProxy = nullptr;
 }
@@ -90,27 +93,32 @@
 
 - (void)windowDidMove:(NSNotification *)notification
 {
-    static_cast<WebInspectorProxy*>(_inspectorProxy)->windowFrameDidChange();
+    if (_inspectorProxy)
+        _inspectorProxy->windowFrameDidChange();
 }
 
 - (void)windowDidResize:(NSNotification *)notification
 {
-    static_cast<WebInspectorProxy*>(_inspectorProxy)->windowFrameDidChange();
+    if (_inspectorProxy)
+        _inspectorProxy->windowFrameDidChange();
 }
 
 - (void)windowWillClose:(NSNotification *)notification
 {
-    static_cast<WebInspectorProxy*>(_inspectorProxy)->close();
+    if (_inspectorProxy)
+        _inspectorProxy->close();
 }
 
 - (void)windowDidEnterFullScreen:(NSNotification *)notification
 {
-    static_cast<WebInspectorProxy*>(_inspectorProxy)->windowFullScreenDidChange();
+    if (_inspectorProxy)
+        _inspectorProxy->windowFullScreenDidChange();
 }
 
 - (void)windowDidExitFullScreen:(NSNotification *)notification
 {
-    static_cast<WebInspectorProxy*>(_inspectorProxy)->windowFullScreenDidChange();
+    if (_inspectorProxy)
+        _inspectorProxy->windowFullScreenDidChange();
 }
 
 - (void)inspectedViewFrameDidChange:(NSNotification *)notification
@@ -121,9 +129,8 @@
     // of the time the views will already have the correct frames because of autoresizing masks.
 
     dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^{
-        if (!_inspectorProxy)
-            return;
-        static_cast<WebInspectorProxy*>(_inspectorProxy)->inspectedViewFrameDidChange();
+        if (_inspectorProxy)
+            _inspectorProxy->inspectedViewFrameDidChange();
     });
 }
 
@@ -133,8 +140,8 @@
 
 void WebInspectorProxy::attachmentViewDidChange(NSView *oldView, NSView *newView)
 {
-    [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get() name:NSViewFrameDidChangeNotification object:oldView];
-    [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:newView];
+    [[NSNotificationCenter defaultCenter] removeObserver:m_objCAdapter.get() name:NSViewFrameDidChangeNotification object:oldView];
+    [[NSNotificationCenter defaultCenter] addObserver:m_objCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:newView];
 
     if (m_isAttached)
         attach(m_attachmentSide);
@@ -144,6 +151,7 @@
 {
     if (m_isAttached)
         return;
+
     [m_inspectorWindow setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height) display:YES];
 }
 
@@ -165,11 +173,11 @@
         m_inspectorView = nil;
     }
 
-    if (m_inspectorProxyObjCAdapter) {
-        [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get()];
+    if (m_objCAdapter) {
+        [[NSNotificationCenter defaultCenter] removeObserver:m_objCAdapter.get()];
 
-        [m_inspectorProxyObjCAdapter close];
-        m_inspectorProxyObjCAdapter = nil;
+        [m_objCAdapter invalidate];
+        m_objCAdapter = nil;
     }
 }
 
@@ -181,7 +189,7 @@
     NSRect savedWindowFrame = NSRectFromString(savedWindowFrameString);
 
     m_inspectorWindow = WebInspectorProxy::createFrontendWindow(savedWindowFrame);
-    [m_inspectorWindow setDelegate:m_inspectorProxyObjCAdapter.get()];
+    [m_inspectorWindow setDelegate:m_objCAdapter.get()];
 
     NSView *contentView = [m_inspectorWindow contentView];
     [m_inspectorView setFrame:[contentView bounds]];
@@ -263,12 +271,12 @@
     m_closeTimer.stop();
 
     if (m_inspectorView) {
-        ASSERT(m_inspectorProxyObjCAdapter);
+        ASSERT(m_objCAdapter);
         return m_inspectorView->_page.get();
     }
 
     ASSERT(!m_inspectorView);
-    ASSERT(!m_inspectorProxyObjCAdapter);
+    ASSERT(!m_objCAdapter);
 
     NSView *inspectedView = inspectedPage()->inspectorAttachmentView();
 
@@ -296,10 +304,10 @@
             initialRect = [NSWindow contentRectForFrameRect:windowFrame styleMask:windowStyleMask];
     }
 
-    m_inspectorProxyObjCAdapter = adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
-    ASSERT(m_inspectorProxyObjCAdapter);
+    m_objCAdapter = adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
+    ASSERT(m_objCAdapter);
 
-    [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
+    [[NSNotificationCenter defaultCenter] addObserver:m_objCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
 
     auto configuration = WebInspectorProxy::createFrontendConfiguration(inspectedPage(), isUnderTest());
     m_inspectorView = adoptNS([[WKWebInspectorWKWebView alloc] initWithFrame:initialRect configuration:configuration.get()]);

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (223770 => 223771)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-10-20 17:28:53 UTC (rev 223770)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-10-20 17:28:57 UTC (rev 223771)
@@ -9126,7 +9126,6 @@
 				BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */,
 				BC60C5791240A546008C5E29 /* WKBundleRangeHandle.h in Headers */,
 				BC5D24C716CD73C5007D5461 /* WKBundleRangeHandlePrivate.h in Headers */,
-				994BADF41F7D781400B571E7 /* WKInspectorViewController.h in Headers */,
 				BC14DF9F120B635F00826C0C /* WKBundleScriptWorld.h in Headers */,
 				BC4075F6124FF0270068F20A /* WKCertificateInfo.h in Headers */,
 				BC407627124FF0400068F20A /* WKCertificateInfoMac.h in Headers */,
@@ -9215,6 +9214,7 @@
 				0F3C725B196F604E00AEDD0C /* WKInspectorHighlightView.h in Headers */,
 				A54293A4195A43DA002782C7 /* WKInspectorNodeSearchGestureRecognizer.h in Headers */,
 				6EE849C81368D9390038D481 /* WKInspectorPrivateMac.h in Headers */,
+				994BADF41F7D781400B571E7 /* WKInspectorViewController.h in Headers */,
 				51A9E10B1315CD18009E7031 /* WKKeyValueStorageManager.h in Headers */,
 				2D790A9F1AD7164900AB90B3 /* WKLayoutMode.h in Headers */,
 				C98C48AA1B6FD5B500145103 /* WKMediaSessionFocusManager.h in Headers */,
@@ -10624,7 +10624,6 @@
 				2D5C9D0519C81D8F00B3C5C1 /* WebPageOverlay.cpp in Sources */,
 				BC111B0F112F5E4F00337BAB /* WebPageProxy.cpp in Sources */,
 				1AC0273F196622D600C12B75 /* WebPageProxyCocoa.mm in Sources */,
-				994BADF31F7D781100B571E7 /* WKInspectorViewController.mm in Sources */,
 				2DA944AF1884E9BA00ED86DB /* WebPageProxyIOS.mm in Sources */,
 				BC857E8712B71EBB00EDEB2E /* WebPageProxyMac.mm in Sources */,
 				BCBD3914125BB1A800D2C29F /* WebPageProxyMessageReceiver.cpp in Sources */,
@@ -10820,6 +10819,7 @@
 				1C8E293A12761E5B00BC7BD0 /* WKInspector.cpp in Sources */,
 				0F3C725C196F605200AEDD0C /* WKInspectorHighlightView.mm in Sources */,
 				A54293A5195A43DD002782C7 /* WKInspectorNodeSearchGestureRecognizer.mm in Sources */,
+				994BADF31F7D781100B571E7 /* WKInspectorViewController.mm in Sources */,
 				51A9E10A1315CD18009E7031 /* WKKeyValueStorageManager.cpp in Sources */,
 				C98C48A91B6FD5B500145103 /* WKMediaSessionFocusManager.cpp in Sources */,
 				C9CD439E1B4B025300239E33 /* WKMediaSessionMetadata.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to