Title: [259512] trunk/Source
Revision
259512
Author
timothy_hor...@apple.com
Date
2020-04-03 13:55:39 -0700 (Fri, 03 Apr 2020)

Log Message

Add a visual debug indicator for locating and identifying all kinds of WebViews
https://bugs.webkit.org/show_bug.cgi?id=209982
<rdar://problem/60339870>

Reviewed by Simon Fraser.

Source/WebCore:

Add a debug overlay that can be enabled with a single switch for all
*WebView variants, which indicates the type of *WebView in an unmissable,
gaudy fashion.

This is intended to address some shortcomings of existing mechanisms
that people use to answer the "what kind of web view is X app using?"
question. Specifically:

- it will appear even if the Web Content process does not launch or crashes
- it will appear even if a custom content view is being used (e.g. PDF)
- it will appear even if compositing is not enabled (e.g. in a legacy WebView on macOS)
- it explicitly states in written text the class name of the web view, with no need for interpreting colors
- it covers the entire web view, so cannot be accidentally obscured

No new tests, just debugging UI.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* testing/cocoa/WebViewVisualIdentificationOverlay.h: Added.
* testing/cocoa/WebViewVisualIdentificationOverlay.mm: Added.
(+[WebViewVisualIdentificationOverlay shouldIdentifyWebViews]):
Use a single default across all kinds of WebViews, instead of using
WebPreferences and friends, in order to make it extremely easy to turn on,
and because it's intended to be set globally, and is not useful on a
per-view basis.

(+[WebViewVisualIdentificationOverlay installForWebViewIfNeeded:kind:deprecated:]):
(-[WebViewVisualIdentificationOverlay initWithWebView:kind:deprecated:]):
(-[WebViewVisualIdentificationOverlay dealloc]):
(-[WebViewVisualIdentificationOverlay observeValueForKeyPath:ofObject:change:context:]):
(-[WebViewVisualIdentificationOverlay drawLayer:inContext:]):
Draw a wash and the class name over the entire face of the web view.
The wash is blue for WKWebView and red for all of the deprecated web views (WKView, WebView, UIWebView).

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/mac/WKView.mm:
(-[WKView initWithFrame:processPool:configuration:]):
Adopt in WKWebView and WKView.

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
Adopt for WebView on macOS (UIWebView will install it itself on iOS).

* WebView/WebViewPrivate.h:
Expose _installVisualIdentificationOverlayForViewIfNeeded:kind: for UIWebView's use.
It is slightly unfortunate to expose SPI that uses UIView from a framework
underneath UIKit, but there is no other single place where this code can live
and not be a minor layering problem. Since it's debug UI, it seems passable.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (259511 => 259512)


--- trunk/Source/WebCore/ChangeLog	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebCore/ChangeLog	2020-04-03 20:55:39 UTC (rev 259512)
@@ -1,3 +1,45 @@
+2020-04-03  Tim Horton  <timothy_hor...@apple.com>
+
+        Add a visual debug indicator for locating and identifying all kinds of WebViews
+        https://bugs.webkit.org/show_bug.cgi?id=209982
+        <rdar://problem/60339870>
+
+        Reviewed by Simon Fraser.
+
+        Add a debug overlay that can be enabled with a single switch for all
+        *WebView variants, which indicates the type of *WebView in an unmissable,
+        gaudy fashion.
+
+        This is intended to address some shortcomings of existing mechanisms
+        that people use to answer the "what kind of web view is X app using?"
+        question. Specifically:
+
+        - it will appear even if the Web Content process does not launch or crashes
+        - it will appear even if a custom content view is being used (e.g. PDF)
+        - it will appear even if compositing is not enabled (e.g. in a legacy WebView on macOS)
+        - it explicitly states in written text the class name of the web view, with no need for interpreting colors
+        - it covers the entire web view, so cannot be accidentally obscured
+
+        No new tests, just debugging UI.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * testing/cocoa/WebViewVisualIdentificationOverlay.h: Added.
+        * testing/cocoa/WebViewVisualIdentificationOverlay.mm: Added.
+        (+[WebViewVisualIdentificationOverlay shouldIdentifyWebViews]):
+        Use a single default across all kinds of WebViews, instead of using
+        WebPreferences and friends, in order to make it extremely easy to turn on,
+        and because it's intended to be set globally, and is not useful on a
+        per-view basis.
+
+        (+[WebViewVisualIdentificationOverlay installForWebViewIfNeeded:kind:deprecated:]):
+        (-[WebViewVisualIdentificationOverlay initWithWebView:kind:deprecated:]):
+        (-[WebViewVisualIdentificationOverlay dealloc]):
+        (-[WebViewVisualIdentificationOverlay observeValueForKeyPath:ofObject:change:context:]):
+        (-[WebViewVisualIdentificationOverlay drawLayer:inContext:]):
+        Draw a wash and the class name over the entire face of the web view.
+        The wash is blue for WKWebView and red for all of the deprecated web views (WKView, WebView, UIWebView).
+
 2020-04-03  David Kilzer  <ddkil...@apple.com>
 
         REGRESSION (r8412): Use RetainPtr<> for NSMutableAttributedString in -[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:spellCheck:]

Modified: trunk/Source/WebCore/SourcesCocoa.txt (259511 => 259512)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-04-03 20:55:39 UTC (rev 259512)
@@ -578,6 +578,8 @@
 
 platform/mediastream/libwebrtc/LibWebRTCProviderCocoa.cpp
 
+testing/cocoa/WebViewVisualIdentificationOverlay.mm
+
 // Derived Sources
 
 WHLSLStandardLibraryFunctionMap.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (259511 => 259512)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-04-03 20:55:39 UTC (rev 259512)
@@ -752,6 +752,7 @@
 		2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D6F3E8B1C1ECB1C0061DBD4 /* MockPageOverlay.h */; };
 		2D70BA1318074DDF0001908A /* PlatformCALayerCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D70BA1218074DDF0001908A /* PlatformCALayerCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D76BB821945632400CFD29A /* RunLoopObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D76BB801945632400CFD29A /* RunLoopObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		2D7DA0F22435EB1900F048D1 /* WebViewVisualIdentificationOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D7DA0EF2435EB1700F048D1 /* WebViewVisualIdentificationOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D7ED0AB1BAE99170043B3E5 /* TimerEventBasedMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D7ED0A91BAE99170043B3E5 /* TimerEventBasedMock.h */; };
 		2D81E1CF21A78CC200A32CF4 /* InsertEditableImageCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D81E1CD21A78CC200A32CF4 /* InsertEditableImageCommand.h */; };
 		2D8287F716E4A0380086BD00 /* HitTestLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8287F516E4A0380086BD00 /* HitTestLocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6859,6 +6860,8 @@
 		2D70BA1418074F850001908A /* PlatformCALayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformCALayer.cpp; sourceTree = "<group>"; };
 		2D76BB801945632400CFD29A /* RunLoopObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopObserver.h; sourceTree = "<group>"; };
 		2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopObserver.cpp; sourceTree = "<group>"; };
+		2D7DA0EF2435EB1700F048D1 /* WebViewVisualIdentificationOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewVisualIdentificationOverlay.h; sourceTree = "<group>"; };
+		2D7DA0F12435EB1800F048D1 /* WebViewVisualIdentificationOverlay.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewVisualIdentificationOverlay.mm; sourceTree = "<group>"; };
 		2D7ED0A91BAE99170043B3E5 /* TimerEventBasedMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TimerEventBasedMock.h; sourceTree = "<group>"; };
 		2D81E1CB21A78CC100A32CF4 /* InsertEditableImageCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InsertEditableImageCommand.cpp; sourceTree = "<group>"; };
 		2D81E1CD21A78CC200A32CF4 /* InsertEditableImageCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InsertEditableImageCommand.h; sourceTree = "<group>"; };
@@ -22955,6 +22958,8 @@
 			children = (
 				A1763F3D1E205234001D58DE /* WebArchiveDumpSupport.h */,
 				A1763F3C1E205234001D58DE /* WebArchiveDumpSupport.mm */,
+				2D7DA0EF2435EB1700F048D1 /* WebViewVisualIdentificationOverlay.h */,
+				2D7DA0F12435EB1800F048D1 /* WebViewVisualIdentificationOverlay.mm */,
 			);
 			path = cocoa;
 			sourceTree = "<group>";
@@ -33435,6 +33440,7 @@
 				31DEA4561B39F4D900F77178 /* WebSystemBackdropLayer.h in Headers */,
 				0F580FA31496939100FB5BD8 /* WebTiledBackingLayer.h in Headers */,
 				3F42B31D1881191B00278AAC /* WebVideoFullscreenControllerAVKit.h in Headers */,
+				2D7DA0F22435EB1900F048D1 /* WebViewVisualIdentificationOverlay.h in Headers */,
 				F12171F616A8CF0B000053CA /* WebVTTElement.h in Headers */,
 				5D21A80313ECE5DF00BB7064 /* WebVTTParser.h in Headers */,
 				B10B6980140C174000BC1C26 /* WebVTTToken.h in Headers */,

Added: trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.h (0 => 259512)


--- trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.h	                        (rev 0)
+++ trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.h	2020-04-03 20:55:39 UTC (rev 259512)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(COCOA)
+
+#if USE(APPKIT)
+#include <AppKit/AppKit.h>
+#else
+#include <UIKit/UIKit.h>
+#endif
+
+#include <WebCore/PlatformView.h>
+
+WEBCORE_EXPORT
+@interface WebViewVisualIdentificationOverlay : NSObject
+
++ (void)installForWebViewIfNeeded:(PlatformView *)view kind:(NSString *)kind deprecated:(BOOL)isDeprecated;
+
+@end
+
+#endif // PLATFORM(COCOA)

Added: trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.mm (0 => 259512)


--- trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.mm	                        (rev 0)
+++ trunk/Source/WebCore/testing/cocoa/WebViewVisualIdentificationOverlay.mm	2020-04-03 20:55:39 UTC (rev 259512)
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebViewVisualIdentificationOverlay.h"
+
+#if PLATFORM(COCOA)
+
+#import "Color.h"
+#import "WebCoreCALayerExtras.h"
+#import <CoreText/CoreText.h>
+#import <wtf/WeakObjCPtr.h>
+
+#import <pal/ios/UIKitSoftLink.h>
+
+static void *boundsObservationContext = &boundsObservationContext;
+
+@interface WebViewVisualIdentificationOverlay () <CALayerDelegate>
+@end
+
+const void* const webViewVisualIdentificationOverlayKey = &webViewVisualIdentificationOverlayKey;
+
+@implementation WebViewVisualIdentificationOverlay {
+    RetainPtr<PlatformView> _view;
+
+    RetainPtr<CALayer> _layer;
+    RetainPtr<NSString> _kind;
+}
+
++ (BOOL)shouldIdentifyWebViews
+{
+    static Optional<BOOL> shouldIdentifyWebViews;
+    if (!shouldIdentifyWebViews)
+        shouldIdentifyWebViews = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitDebugIdentifyWebViews"];
+    return *shouldIdentifyWebViews;
+}
+
++ (void)installForWebViewIfNeeded:(PlatformView *)view kind:(NSString *)kind deprecated:(BOOL)isDeprecated
+{
+    if (![self shouldIdentifyWebViews])
+        return;
+    auto overlay = adoptNS([[WebViewVisualIdentificationOverlay alloc] initWithWebView:view kind:kind deprecated:isDeprecated]);
+    objc_setAssociatedObject(self, webViewVisualIdentificationOverlayKey, overlay.get(), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+- (instancetype)initWithWebView:(PlatformView *)webView kind:(NSString *)kind deprecated:(BOOL)isDeprecated
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _kind = kind;
+
+#if USE(APPKIT)
+    _view = adoptNS([[NSView alloc] initWithFrame:webView.bounds]);
+    [_view setWantsLayer:YES];
+    [_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+#else
+    _view = adoptNS([PAL::allocUIViewInstance() initWithFrame:webView.bounds]);
+    [_view setUserInteractionEnabled:NO];
+    [_view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
+#endif
+    [webView addSubview:_view.get()];
+
+#if PLATFORM(MACCATALYST)
+    _kind = [_kind stringByAppendingString:@" (macCatalyst)"];
+#endif
+
+    _layer = adoptNS([[CATiledLayer alloc] init]);
+    [_layer setName:@"WebViewVisualIdentificationOverlay"];
+    [_layer setFrame:CGRectMake(0, 0, [_view bounds].size.width, [_view bounds].size.height)];
+    WebCore::Color viewColor = isDeprecated ? WebCore::Color(255, 0, 0, 32) : WebCore::Color(0, 0, 255, 32);
+    [_layer setBackgroundColor:cachedCGColor(viewColor)];
+    [_layer setZPosition:999];
+    [_layer setDelegate:self];
+    [_layer web_disableAllActions];
+    [[_view layer] addSublayer:_layer.get()];
+
+    [[_view layer] addObserver:self forKeyPath:@"bounds" options:0 context:boundsObservationContext];
+
+    return self;
+}
+
+- (void)dealloc
+{
+    [[_view layer] removeObserver:self forKeyPath:@"bounds" context:boundsObservationContext];
+
+    [super dealloc];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
+{
+    UNUSED_PARAM(keyPath);
+    UNUSED_PARAM(object);
+    UNUSED_PARAM(change);
+    if (context == boundsObservationContext) {
+        [_layer setFrame:CGRectMake(0, 0, [_view bounds].size.width, [_view bounds].size.height)];
+        [_layer setNeedsDisplay];
+    }
+}
+
+static CTFontRef identificationFont()
+{
+    auto matrix = CGAffineTransformIdentity;
+    return (CTFontRef)CFAutorelease(CTFontCreateWithName(CFSTR("Helvetica"), 20, &matrix));
+}
+
+constexpr CGFloat horizontalMargin = 15;
+constexpr CGFloat verticalMargin = 5;
+
+static void drawPattern(void *overlayPtr, CGContextRef ctx)
+{
+    WebViewVisualIdentificationOverlay *overlay = (WebViewVisualIdentificationOverlay *)overlayPtr;
+
+    auto attributes = @{
+        (id)kCTFontAttributeName : (id)identificationFont(),
+        (id)kCTForegroundColorFromContextAttributeName : @YES
+    };
+    auto attributedString = adoptCF(CFAttributedStringCreate(kCFAllocatorDefault, (__bridge CFStringRef)overlay->_kind.get(), (__bridge CFDictionaryRef)attributes));
+    auto line = adoptCF(CTLineCreateWithAttributedString(attributedString.get()));
+
+    CGSize textSize = [overlay->_kind sizeWithAttributes:attributes];
+
+#if PLATFORM(IOS_FAMILY)
+    CGContextScaleCTM(ctx, 1, -1);
+    CGContextTranslateCTM(ctx, 0, -(textSize.height + verticalMargin) * 2);
+#endif
+
+    CGContextSetTextDrawingMode(ctx, kCGTextFill);
+
+    CGContextSetTextPosition(ctx, 0, 0);
+    CGContextSetFillColorWithColor(ctx, cachedCGColor(WebCore::Color::black));
+    CTLineDraw(line.get(), ctx);
+
+    CGContextSetTextPosition(ctx, 0, textSize.height + 5);
+    CGContextSetFillColorWithColor(ctx, cachedCGColor(WebCore::Color::white));
+    CTLineDraw(line.get(), ctx);
+}
+
+- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
+{
+    CGPatternCallbacks callbacks = { 0, &drawPattern, nullptr };
+    auto patternSpace = adoptCF(CGColorSpaceCreatePattern(nullptr));
+    CGContextSetFillColorSpace(ctx, patternSpace.get());
+
+    CGSize textSize = [_kind sizeWithAttributes:@{ (id)kCTFontAttributeName : (id)identificationFont() }];
+    CGSize patternSize = CGSizeMake(textSize.width + horizontalMargin, (textSize.height + verticalMargin) * 2);
+    auto pattern = adoptCF(CGPatternCreate(self, layer.bounds, CGAffineTransformMakeRotation(M_PI_4), patternSize.width, patternSize.height, kCGPatternTilingNoDistortion, true, &callbacks));
+    CGFloat alpha = 0.5;
+    CGContextSetFillPattern(ctx, pattern.get(), &alpha);
+
+    CGContextFillRect(ctx, layer.bounds);
+}
+
+@end
+
+#endif // PLATFORM(COCOA)

Modified: trunk/Source/WebKit/ChangeLog (259511 => 259512)


--- trunk/Source/WebKit/ChangeLog	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKit/ChangeLog	2020-04-03 20:55:39 UTC (rev 259512)
@@ -1,3 +1,17 @@
+2020-04-03  Tim Horton  <timothy_hor...@apple.com>
+
+        Add a visual debug indicator for locating and identifying all kinds of WebViews
+        https://bugs.webkit.org/show_bug.cgi?id=209982
+        <rdar://problem/60339870>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView initWithFrame:processPool:configuration:]):
+        Adopt in WKWebView and WKView.
+
 2020-04-03  Kate Cheney  <katherine_che...@apple.com>
 
         Remove _setIsNavigatingToAppBoundDomain testing SPI

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (259511 => 259512)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2020-04-03 20:55:39 UTC (rev 259512)
@@ -127,6 +127,7 @@
 #import <WebCore/StringUtilities.h>
 #import <WebCore/TextManipulationController.h>
 #import <WebCore/ViewportArguments.h>
+#import <WebCore/WebViewVisualIdentificationOverlay.h>
 #import <WebCore/WritingMode.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/HashMap.h>
@@ -404,6 +405,8 @@
 
     pageToViewMap().add(_page.get(), self);
 
+    [WebViewVisualIdentificationOverlay installForWebViewIfNeeded:self kind:@"WKWebView" deprecated:NO];
+
 #if PLATFORM(IOS_FAMILY)
     auto timeNow = MonotonicTime::now();
     _timeOfRequestForVisibleContentRectUpdate = timeNow;

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKView.mm (259511 => 259512)


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2020-04-03 20:55:39 UTC (rev 259512)
@@ -43,6 +43,7 @@
 #import "WebProcessPool.h"
 #import "WebViewImpl.h"
 #import "_WKLinkIconParametersInternal.h"
+#import <WebCore/WebViewVisualIdentificationOverlay.h>
 #import <WebKit/WKDragDestinationAction.h>
 #import <pal/spi/cocoa/AVKitSPI.h>
 #import <wtf/BlockPtr.h>
@@ -963,6 +964,7 @@
     _data->_impl = makeUnique<WebKit::WebViewImpl>(self, nullptr, processPool.get(), WTFMove(configuration));
 
     [self maybeInstallIconLoadingClient];
+    [WebViewVisualIdentificationOverlay installForWebViewIfNeeded:self kind:@"WKView" deprecated:YES];
 
     return self;
 }

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (259511 => 259512)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2020-04-03 20:55:39 UTC (rev 259512)
@@ -1,3 +1,21 @@
+2020-04-03  Tim Horton  <timothy_hor...@apple.com>
+
+        Add a visual debug indicator for locating and identifying all kinds of WebViews
+        https://bugs.webkit.org/show_bug.cgi?id=209982
+        <rdar://problem/60339870>
+
+        Reviewed by Simon Fraser.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        Adopt for WebView on macOS (UIWebView will install it itself on iOS).
+
+        * WebView/WebViewPrivate.h:
+        Expose _installVisualIdentificationOverlayForViewIfNeeded:kind: for UIWebView's use.
+        It is slightly unfortunate to expose SPI that uses UIView from a framework
+        underneath UIKit, but there is no other single place where this code can live
+        and not be a minor layering problem. Since it's debug UI, it seems passable.
+
 2020-04-03  David Kilzer  <ddkil...@apple.com>
 
         [Xcode] Replace ASAN_OTHER_CFLAGS and ASAN_OTHER_CPLUSPLUSFLAGS with $(inherited)

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (259511 => 259512)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2020-04-03 20:55:39 UTC (rev 259512)
@@ -221,6 +221,7 @@
 #import <WebCore/ValidationBubble.h>
 #import <WebCore/WebCoreObjCExtras.h>
 #import <WebCore/WebCoreView.h>
+#import <WebCore/WebViewVisualIdentificationOverlay.h>
 #import <WebCore/Widget.h>
 #import <WebKitLegacy/DOM.h>
 #import <WebKitLegacy/DOMExtensions.h>
@@ -1600,6 +1601,10 @@
 #endif
 
     _private->page->settings().setContentDispositionAttachmentSandboxEnabled(true);
+
+#if PLATFORM(MAC)
+    [WebViewVisualIdentificationOverlay installForWebViewIfNeeded:self kind:@"WebView" deprecated:YES];
+#endif
 }
 
 - (id)_initWithFrame:(NSRect)f frameName:(NSString *)frameName groupName:(NSString *)groupName
@@ -10220,6 +10225,11 @@
         page->revealCurrentSelection();
 }
 
+- (void)_installVisualIdentificationOverlayForViewIfNeeded:(id)view kind:(NSString *)kind
+{
+    [WebViewVisualIdentificationOverlay installForWebViewIfNeeded:static_cast<UIView *>(view) kind:kind deprecated:YES];
+}
+
 @end
 
 #endif

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h (259511 => 259512)


--- trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h	2020-04-03 20:40:10 UTC (rev 259511)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h	2020-04-03 20:55:39 UTC (rev 259512)
@@ -1088,6 +1088,9 @@
 @interface WebView (WebViewIOSAdditions)
 - (NSArray<DOMElement *> *)_editableElementsInRect:(CGRect)rect;
 - (void)revealCurrentSelection;
+
+// View must be a UIView.
+- (void)_installVisualIdentificationOverlayForViewIfNeeded:(id)view kind:(NSString *)kind;
 @end
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to