Title: [191545] trunk
Revision
191545
Author
[email protected]
Date
2015-10-24 22:59:16 -0700 (Sat, 24 Oct 2015)

Log Message

Add a way to add user style sheets to WKUserContentController
https://bugs.webkit.org/show_bug.cgi?id=150531
<rdar://problem/23191691>

Reviewed by Darin Adler.

* Shared/API/APIObject.h:
* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
Boilerplate for a new API::UserStyleSheet.

* UIProcess/API/APIUserStyleSheet.cpp: Added.
(API::generateIdentifier):
(API::UserStyleSheet::generateUniqueURL):
* UIProcess/API/APIUserStyleSheet.h: Added.
Added API::UserStyleSheet, borrowing URL generation code from API::UserScript.

* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController _addUserStyleSheet:]):
(-[WKUserContentController _removeAllUserStyleSheets]):
Forward add and remove-all to WebUserContentControllerProxy.

* UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.h: Added.
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm: Added.
(toWTFStrings):
(-[_WKUserStyleSheet initWithSource:whitelistedURLPatterns:blacklistedURLPatterns:forMainFrameOnly:]):
(-[_WKUserStyleSheet source]):
(-[_WKUserStyleSheet isForMainFrameOnly]):
(-[_WKUserStyleSheet copyWithZone:]):
(-[_WKUserStyleSheet _apiObject]):
* UIProcess/API/Cocoa/_WKUserStyleSheetInternal.h: Added.
(API::wrapper):
* WebKit2.xcodeproj/project.pbxproj:
Add the new modern API object (as SPI for now).

* TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm:
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (191544 => 191545)


--- trunk/Source/WebKit2/ChangeLog	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-25 05:59:16 UTC (rev 191545)
@@ -1,5 +1,43 @@
 2015-10-24  Tim Horton  <[email protected]>
 
+        Add a way to add user style sheets to WKUserContentController
+        https://bugs.webkit.org/show_bug.cgi?id=150531
+        <rdar://problem/23191691>
+
+        Reviewed by Darin Adler.
+
+        * Shared/API/APIObject.h:
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+        Boilerplate for a new API::UserStyleSheet.
+
+        * UIProcess/API/APIUserStyleSheet.cpp: Added.
+        (API::generateIdentifier):
+        (API::UserStyleSheet::generateUniqueURL):
+        * UIProcess/API/APIUserStyleSheet.h: Added.
+        Added API::UserStyleSheet, borrowing URL generation code from API::UserScript.
+
+        * UIProcess/API/Cocoa/WKUserContentController.mm:
+        (-[WKUserContentController _addUserStyleSheet:]):
+        (-[WKUserContentController _removeAllUserStyleSheets]):
+        Forward add and remove-all to WebUserContentControllerProxy.
+
+        * UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
+        * UIProcess/API/Cocoa/_WKUserStyleSheet.h: Added.
+        * UIProcess/API/Cocoa/_WKUserStyleSheet.mm: Added.
+        (toWTFStrings):
+        (-[_WKUserStyleSheet initWithSource:whitelistedURLPatterns:blacklistedURLPatterns:forMainFrameOnly:]):
+        (-[_WKUserStyleSheet source]):
+        (-[_WKUserStyleSheet isForMainFrameOnly]):
+        (-[_WKUserStyleSheet copyWithZone:]):
+        (-[_WKUserStyleSheet _apiObject]):
+        * UIProcess/API/Cocoa/_WKUserStyleSheetInternal.h: Added.
+        (API::wrapper):
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add the new modern API object (as SPI for now).
+
+2015-10-24  Tim Horton  <[email protected]>
+
         Expose more information about the exception in WKErrorJavaScriptExceptionOccurred errors
         https://bugs.webkit.org/show_bug.cgi?id=150525
 

Modified: trunk/Source/WebKit2/Shared/API/APIObject.h (191544 => 191545)


--- trunk/Source/WebKit2/Shared/API/APIObject.h	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/Shared/API/APIObject.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -82,6 +82,7 @@
         URLResponse,
         UserContentURLPattern,
         UserScript,
+        UserStyleSheet,
         WebArchive,
         WebArchiveResource,
 

Modified: trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm (191544 => 191545)


--- trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2015-10-25 05:59:16 UTC (rev 191545)
@@ -67,6 +67,7 @@
 #import "_WKProcessPoolConfigurationInternal.h"
 #import "_WKUserContentExtensionStoreInternal.h"
 #import "_WKUserContentFilterInternal.h"
+#import "_WKUserStyleSheetInternal.h"
 #import "_WKVisitedLinkStoreInternal.h"
 #import <objc/objc-auto.h>
 
@@ -211,6 +212,10 @@
         wrapper = [WKUserScript alloc];
         break;
 
+    case Type::UserStyleSheet:
+        wrapper = [_WKUserStyleSheet alloc];
+        break;
+
     case Type::VisitedLinkStore:
         wrapper = [_WKVisitedLinkStore alloc];
         break;

Modified: trunk/Source/WebKit2/UIProcess/API/APIUserScript.cpp (191544 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/APIUserScript.cpp	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/UIProcess/API/APIUserScript.cpp	2015-10-25 05:59:16 UTC (rev 191545)
@@ -42,7 +42,7 @@
     StringBuilder urlStringBuilder;
     urlStringBuilder.appendLiteral("user-script:");
     urlStringBuilder.appendNumber(generateIdentifier());
-    return WebCore::URL { WebCore::URL { }, urlStringBuilder.toString() };
+    return { { }, urlStringBuilder.toString() };
 }
 
 

Modified: trunk/Source/WebKit2/UIProcess/API/APIUserScript.h (191544 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/APIUserScript.h	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/UIProcess/API/APIUserScript.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -37,7 +37,7 @@
 
     static Ref<UserScript> create(WebCore::UserScript userScript)
     {
-        return adoptRef(*new UserScript(userScript));
+        return adoptRef(*new UserScript(WTF::move(userScript)));
     }
 
     UserScript(WebCore::UserScript userScript)
@@ -45,11 +45,6 @@
     {
     }
 
-    ~UserScript()
-    {
-    }
-
-    WebCore::UserScript& userScript() { return m_userScript; }
     const WebCore::UserScript& userScript() const { return m_userScript; }
 
 private:

Added: trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp (0 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.cpp	2015-10-25 05:59:16 UTC (rev 191545)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#include "config.h"
+#include "APIUserStyleSheet.h"
+
+#include <wtf/text/StringBuilder.h>
+
+namespace API {
+
+static uint64_t generateIdentifier()
+{
+    static uint64_t identifier;
+
+    return ++identifier;
+}
+
+WebCore::URL UserStyleSheet::generateUniqueURL()
+{
+    StringBuilder urlStringBuilder;
+    urlStringBuilder.appendLiteral("user-style-sheet:");
+    urlStringBuilder.appendNumber(generateIdentifier());
+    return { { }, urlStringBuilder.toString() };
+}
+
+
+} // namespace API

Added: trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h (0 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/APIUserStyleSheet.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#ifndef APIUserStyleSheet_h
+#define APIUserStyleSheet_h
+
+#include "APIObject.h"
+#include <WebCore/UserStyleSheet.h>
+
+namespace API {
+
+class UserStyleSheet final : public ObjectImpl<Object::Type::UserStyleSheet> {
+public:
+    static WebCore::URL generateUniqueURL();
+
+    UserStyleSheet(WebCore::UserStyleSheet userStyleSheet)
+        : m_userStyleSheet(userStyleSheet)
+    {
+    }
+
+    const WebCore::UserStyleSheet& userStyleSheet() const { return m_userStyleSheet; }
+
+private:
+    WebCore::UserStyleSheet m_userStyleSheet;
+};
+
+} // namespace API
+
+#endif // APIUserStyleSheet_h

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm (191544 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm	2015-10-25 05:59:16 UTC (rev 191545)
@@ -38,6 +38,7 @@
 #import "WebScriptMessageHandler.h"
 #import "WebUserContentControllerProxy.h"
 #import "_WKUserContentFilterInternal.h"
+#import "_WKUserStyleSheetInternal.h"
 #import <WebCore/SecurityOrigin.h>
 #import <WebCore/SecurityOriginData.h>
 #import <WebCore/SerializedScriptValue.h>
@@ -146,6 +147,16 @@
 #endif
 }
 
+- (void)_addUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet
+{
+    _userContentControllerProxy->addUserStyleSheet(userStyleSheet->_userStyleSheet->userStyleSheet());
+}
+
+- (void)_removeAllUserStyleSheets
+{
+    _userContentControllerProxy->removeAllUserStyleSheets();
+}
+
 @end
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h (191544 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -28,6 +28,7 @@
 #if WK_API_ENABLED
 
 @class _WKUserContentFilter;
+@class _WKUserStyleSheet;
 
 @interface WKUserContentController (WKPrivate)
 
@@ -35,6 +36,9 @@
 - (void)_removeUserContentFilter:(NSString *)userContentFilterName WK_AVAILABLE(10_11, 9_0);
 - (void)_removeAllUserContentFilters WK_AVAILABLE(10_11, 9_0);
 
+- (void)_addUserStyleSheet:(_WKUserStyleSheet *)userStyleSheet WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+- (void)_removeAllUserStyleSheets WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
 @end
 
 #endif

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.h (0 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <Foundation/Foundation.h>
+
+WK_ASSUME_NONNULL_BEGIN
+
+WK_CLASS_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA)
+@interface _WKUserStyleSheet : NSObject <NSCopying>
+
+@property (nonatomic, readonly, copy) NSString *source;
+
+@property (nonatomic, readonly, copy) WK_ARRAY(NSString *) *whitelistedURLPatterns;
+@property (nonatomic, readonly, copy) WK_ARRAY(NSString *) *blacklistedURLPatterns;
+
+@property (nonatomic, readonly, getter=isForMainFrameOnly) BOOL forMainFrameOnly;
+
+- (instancetype)initWithSource:(NSString *)source whitelistedURLPatterns:(WK_ARRAY(NSString *) *)whitelistedURLPatterns blacklistedURLPatterns:(WK_ARRAY(NSString *) *)blacklistedURLPatterns forMainFrameOnly:(BOOL)forMainFrameOnly;
+
+@end
+
+WK_ASSUME_NONNULL_END
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.mm (0 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.mm	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheet.mm	2015-10-25 05:59:16 UTC (rev 191545)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2014 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 "_WKUserStyleSheetInternal.h"
+
+#import "APIArray.h"
+#import "WKNSArray.h"
+#import "WebKit2Initialize.h"
+
+#if WK_API_ENABLED
+
+@implementation _WKUserStyleSheet
+
+static Vector<String> toWTFStrings(NSArray *strings)
+{
+    Vector<String> result;
+    result.reserveInitialCapacity(strings.count);
+
+    for (NSString *string in strings)
+        result.uncheckedAppend(string);
+
+    return result;
+}
+
+- (instancetype)initWithSource:(NSString *)source whitelistedURLPatterns:(NSArray *)whitelistedURLPatterns blacklistedURLPatterns:(NSArray *)blacklistedURLPatterns forMainFrameOnly:(BOOL)forMainFrameOnly
+{
+    if (!(self = [super init]))
+        return nil;
+
+    // FIXME: In the API test, we can use generateUniqueURL below before the API::Object constructor has done this... where should this really be?
+    WebKit::InitializeWebKit2();
+
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { WTF::String(source), API::UserStyleSheet::generateUniqueURL(), toWTFStrings(whitelistedURLPatterns), toWTFStrings(blacklistedURLPatterns), forMainFrameOnly ? WebCore::InjectInTopFrameOnly : WebCore::InjectInAllFrames, WebCore::UserStyleUserLevel });
+
+    return self;
+}
+
+- (NSString *)source
+{
+    return _userStyleSheet->userStyleSheet().source();
+}
+
+- (NSArray *)whitelistedURLPatterns
+{
+    return wrapper(API::Array::createStringArray(_userStyleSheet->userStyleSheet().whitelist()));
+}
+
+- (NSArray *)blacklistedURLPatterns
+{
+    return wrapper(API::Array::createStringArray(_userStyleSheet->userStyleSheet().blacklist()));
+}
+
+- (BOOL)isForMainFrameOnly
+{
+    return _userStyleSheet->userStyleSheet().injectedFrames() == WebCore::InjectInTopFrameOnly;
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+#pragma mark WKObject protocol implementation
+
+- (API::Object&)_apiObject
+{
+    return *_userStyleSheet;
+}
+
+@end
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheetInternal.h (0 => 191545)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheetInternal.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKUserStyleSheetInternal.h	2015-10-25 05:59:16 UTC (rev 191545)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 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 "_WKUserStyleSheet.h"
+
+#if WK_API_ENABLED
+
+#import "APIUserStyleSheet.h"
+#import <wtf/RetainPtr.h>
+
+namespace API {
+
+inline _WKUserStyleSheet *wrapper(UserStyleSheet& userStyleSheet)
+{
+    ASSERT([userStyleSheet.wrapper() isKindOfClass:[_WKUserStyleSheet class]]);
+    return (_WKUserStyleSheet *)userStyleSheet.wrapper();
+}
+
+}
+
+@interface _WKUserStyleSheet () <WKObject> {
+@package
+    API::ObjectStorage<API::UserStyleSheet> _userStyleSheet;
+}
+@end
+
+#endif

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (191544 => 191545)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-10-25 05:59:16 UTC (rev 191545)
@@ -641,6 +641,11 @@
 		2D870D1016234FFE000A3F20 /* PDFPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D870D0E1622B7F9000A3F20 /* PDFPlugin.mm */; };
 		2D8710161828415D0018FA01 /* PlatformCALayerRemoteCustom.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D8710141828415D0018FA01 /* PlatformCALayerRemoteCustom.mm */; };
 		2D8710171828415D0018FA01 /* PlatformCALayerRemoteCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8710151828415D0018FA01 /* PlatformCALayerRemoteCustom.h */; };
+		2D87861D1BDB54BF00D02ABB /* _WKUserStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D87861B1BDB54BF00D02ABB /* _WKUserStyleSheet.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		2D87861E1BDB54BF00D02ABB /* _WKUserStyleSheet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D87861C1BDB54BF00D02ABB /* _WKUserStyleSheet.mm */; settings = {ASSET_TAGS = (); }; };
+		2D8786201BDB57F500D02ABB /* _WKUserStyleSheetInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D87861F1BDB57F500D02ABB /* _WKUserStyleSheetInternal.h */; settings = {ASSET_TAGS = (); }; };
+		2D8786231BDB58FF00D02ABB /* APIUserStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8786211BDB58FF00D02ABB /* APIUserStyleSheet.cpp */; settings = {ASSET_TAGS = (); }; };
+		2D8786241BDB58FF00D02ABB /* APIUserStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8786221BDB58FF00D02ABB /* APIUserStyleSheet.h */; settings = {ASSET_TAGS = (); }; };
 		2D8949F0182044F600E898AA /* PlatformCALayerRemoteTiledBacking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8949EE182044F600E898AA /* PlatformCALayerRemoteTiledBacking.cpp */; };
 		2D8949F1182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8949EF182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h */; };
 		2D9EA30D1A96CB59002D2807 /* WKPageInjectedBundleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9EA30C1A96CB59002D2807 /* WKPageInjectedBundleClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2805,6 +2810,11 @@
 		2D870D0E1622B7F9000A3F20 /* PDFPlugin.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PDFPlugin.mm; path = PDF/PDFPlugin.mm; sourceTree = "<group>"; };
 		2D8710141828415D0018FA01 /* PlatformCALayerRemoteCustom.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformCALayerRemoteCustom.mm; sourceTree = "<group>"; };
 		2D8710151828415D0018FA01 /* PlatformCALayerRemoteCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCALayerRemoteCustom.h; sourceTree = "<group>"; };
+		2D87861B1BDB54BF00D02ABB /* _WKUserStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKUserStyleSheet.h; sourceTree = "<group>"; };
+		2D87861C1BDB54BF00D02ABB /* _WKUserStyleSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKUserStyleSheet.mm; sourceTree = "<group>"; };
+		2D87861F1BDB57F500D02ABB /* _WKUserStyleSheetInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKUserStyleSheetInternal.h; sourceTree = "<group>"; };
+		2D8786211BDB58FF00D02ABB /* APIUserStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIUserStyleSheet.cpp; sourceTree = "<group>"; };
+		2D8786221BDB58FF00D02ABB /* APIUserStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUserStyleSheet.h; sourceTree = "<group>"; };
 		2D8949EE182044F600E898AA /* PlatformCALayerRemoteTiledBacking.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformCALayerRemoteTiledBacking.cpp; sourceTree = "<group>"; };
 		2D8949EF182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCALayerRemoteTiledBacking.h; sourceTree = "<group>"; };
 		2D9EA30C1A96CB59002D2807 /* WKPageInjectedBundleClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageInjectedBundleClient.h; sourceTree = "<group>"; };
@@ -5361,6 +5371,9 @@
 				7C89D2B81A6B0F2C003A5FDE /* _WKUserContentFilter.h */,
 				7C89D2B71A6B0F2C003A5FDE /* _WKUserContentFilter.mm */,
 				7C89D2BB1A6B0F5B003A5FDE /* _WKUserContentFilterInternal.h */,
+				2D87861B1BDB54BF00D02ABB /* _WKUserStyleSheet.h */,
+				2D87861C1BDB54BF00D02ABB /* _WKUserStyleSheet.mm */,
+				2D87861F1BDB57F500D02ABB /* _WKUserStyleSheetInternal.h */,
 				1A81B37F18BD66AD0007FDAC /* _WKVisitedLinkStore.h */,
 				1A81B37E18BD66AD0007FDAC /* _WKVisitedLinkStore.mm */,
 				1A81B38418BD673A0007FDAC /* _WKVisitedLinkStoreInternal.h */,
@@ -6302,6 +6315,8 @@
 				7C3A06A61AAB903E009D74BA /* APIUserContentExtensionStore.h */,
 				7C89D2A51A6789EA003A5FDE /* APIUserScript.cpp */,
 				7C89D2921A67122F003A5FDE /* APIUserScript.h */,
+				2D8786211BDB58FF00D02ABB /* APIUserStyleSheet.cpp */,
+				2D8786221BDB58FF00D02ABB /* APIUserStyleSheet.h */,
 				1A4832C51A9BC13C008B4DFE /* APIWebsiteDataRecord.cpp */,
 				1A4832C61A9BC13C008B4DFE /* APIWebsiteDataRecord.h */,
 				1A3635A71A3144A300ED6197 /* APIWebsiteDataStore.cpp */,
@@ -8071,6 +8086,7 @@
 				93A88B461BC8829300ABA5C2 /* APIHitTestResult.h in Headers */,
 				29D55DF2161BF9F10031A2E3 /* WebPageGroupProxyMessages.h in Headers */,
 				2D9EA30F1A96CBFF002D2807 /* WebPageInjectedBundleClient.h in Headers */,
+				2D8786201BDB57F500D02ABB /* _WKUserStyleSheetInternal.h in Headers */,
 				C0CE72A11247E71D00BC0EC4 /* WebPageMessages.h in Headers */,
 				2D5C9D0619C81D8F00B3C5C1 /* WebPageOverlay.h in Headers */,
 				BC032DD110F4389F0058C15A /* WebPageProxy.h in Headers */,
@@ -8107,6 +8123,7 @@
 				3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */,
 				510AFFBA16542048001BA05E /* WebResourceLoader.h in Headers */,
 				51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */,
+				2D87861D1BDB54BF00D02ABB /* _WKUserStyleSheet.h in Headers */,
 				7C361D731927FA360036A59D /* WebScriptMessageHandler.h in Headers */,
 				D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */,
 				1A4832D71A9CDF96008B4DFE /* WebsiteData.h in Headers */,
@@ -8321,6 +8338,7 @@
 				1AB8A1EC1840080900E9AE69 /* WKPageLoaderClient.h in Headers */,
 				93E6A4EE1BC5DD3900F8A0E7 /* _WKHitTestResult.h in Headers */,
 				BC2D021912AC426C00E732A3 /* WKPageLoadTypes.h in Headers */,
+				2D8786241BDB58FF00D02ABB /* APIUserStyleSheet.h in Headers */,
 				93BDEB01171DD7AF00BFEE1B /* WKPageLoadTypesPrivate.h in Headers */,
 				2D7303791A7C2B7500F8F487 /* WKPageNavigationClient.h in Headers */,
 				1AB8A1EE18400ACB00E9AE69 /* WKPagePolicyClient.h in Headers */,
@@ -9996,6 +10014,7 @@
 				29232DF818B2A9AE00D0596F /* WKAccessibilityWebPageObjectIOS.mm in Sources */,
 				29232DF918B2AB3A00D0596F /* WKAccessibilityWebPageObjectMac.mm in Sources */,
 				0FCB4E4918BBE044000FCFC9 /* WKActionSheet.mm in Sources */,
+				2D8786231BDB58FF00D02ABB /* APIUserStyleSheet.cpp in Sources */,
 				0FCB4E4B18BBE044000FCFC9 /* WKActionSheetAssistant.mm in Sources */,
 				C5FA1ED418E1062200B3F402 /* WKAirPlayRoutePicker.mm in Sources */,
 				512E34E4130B4D0500ABD19A /* WKApplicationCacheManager.cpp in Sources */,
@@ -10080,6 +10099,7 @@
 				BCCF6AC212C91F34008F9C35 /* WKImage.cpp in Sources */,
 				BCCF6AC912C91F59008F9C35 /* WKImageCG.cpp in Sources */,
 				933DF8301B3BC0B400AEA9E3 /* WKImagePreviewViewController.mm in Sources */,
+				2D87861E1BDB54BF00D02ABB /* _WKUserStyleSheet.mm in Sources */,
 				9321D5881A38EE74008052BE /* WKImmediateActionController.mm in Sources */,
 				1C8E293A12761E5B00BC7BD0 /* WKInspector.cpp in Sources */,
 				0F3C725C196F605200AEDD0C /* WKInspectorHighlightView.mm in Sources */,

Modified: trunk/Tools/ChangeLog (191544 => 191545)


--- trunk/Tools/ChangeLog	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Tools/ChangeLog	2015-10-25 05:59:16 UTC (rev 191545)
@@ -1,5 +1,16 @@
 2015-10-24  Tim Horton  <[email protected]>
 
+        Add a way to add user style sheets to WKUserContentController
+        https://bugs.webkit.org/show_bug.cgi?id=150531
+        <rdar://problem/23191691>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm:
+        (TEST):
+
+2015-10-24  Tim Horton  <[email protected]>
+
         Expose more information about the exception in WKErrorJavaScriptExceptionOccurred errors
         https://bugs.webkit.org/show_bug.cgi?id=150525
 

Modified: trunk/Tools/TestWebKitAPI/PlatformUtilities.cpp (191544 => 191545)


--- trunk/Tools/TestWebKitAPI/PlatformUtilities.cpp	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Tools/TestWebKitAPI/PlatformUtilities.cpp	2015-10-25 05:59:16 UTC (rev 191545)
@@ -25,8 +25,6 @@
 
 #include "config.h"
 
-#if WK_HAVE_C_SPI
-
 #include "PlatformUtilities.h"
 
 #include <wtf/StdLibExtras.h>
@@ -34,6 +32,8 @@
 namespace TestWebKitAPI {
 namespace Util {
 
+#if WK_HAVE_C_SPI
+
 WKContextRef createContextWithInjectedBundle()
 {
     WKRetainPtr<WKStringRef> injectedBundlePath(AdoptWK, createInjectedBundlePath());
@@ -79,17 +79,17 @@
     return toSTD(string.get());
 }
 
-std::string toSTD(const char* string)
+WKRetainPtr<WKStringRef> toWK(const char* utf8String)
 {
-    return std::string(string);
+    return WKRetainPtr<WKStringRef>(AdoptWK, WKStringCreateWithUTF8CString(utf8String));
 }
 
-WKRetainPtr<WKStringRef> toWK(const char* utf8String)
+#endif // WK_HAVE_C_SPI
+
+std::string toSTD(const char* string)
 {
-    return WKRetainPtr<WKStringRef>(AdoptWK, WKStringCreateWithUTF8CString(utf8String));
+    return std::string(string);
 }
 
 } // namespace Util
 } // namespace TestWebKitAPI
-
-#endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm (191544 => 191545)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm	2015-10-25 05:41:47 UTC (rev 191544)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm	2015-10-25 05:59:16 UTC (rev 191545)
@@ -28,6 +28,8 @@
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import <WebKit/WebKit.h>
+#import <WebKit/WKUserContentControllerPrivate.h>
+#import <WebKit/_WKUserStyleSheet.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED
@@ -212,4 +214,154 @@
 }
 #endif
 
+static NSString *styleSheetSource = @"body { background-color: green !important; }";
+static NSString *backgroundColorScript = @"window.getComputedStyle(document.body, null).getPropertyValue('background-color')";
+static NSString *frameBackgroundColorScript = @"window.getComputedStyle(document.getElementsByTagName('iframe')[0].contentDocument.body, null).getPropertyValue('background-color')";
+static const char* greenInRGB = "rgb(0, 128, 0)";
+static const char* redInRGB = "rgb(255, 0, 0)";
+static const char* whiteInRGB = "rgba(0, 0, 0, 0)";
+
+static void expectScriptEvaluatesToColor(WKWebView *webView, NSString *script, const char* color)
+{
+    static bool didCheckBackgroundColor;
+
+    [webView evaluateJavaScript:script completionHandler:^ (id value, NSError * error) {
+        EXPECT_TRUE([value isKindOfClass:[NSString class]]);
+        EXPECT_WK_STREQ(color, value);
+        didCheckBackgroundColor = true;
+    }];
+
+    TestWebKitAPI::Util::run(&didCheckBackgroundColor);
+    didCheckBackgroundColor = false;
+}
+
+TEST(WKUserContentController, AddUserStyleSheetBeforeCreatingView)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    RetainPtr<_WKUserStyleSheet> styleSheet = adoptNS([[_WKUserStyleSheet alloc] initWithSource:styleSheetSource whitelistedURLPatterns:@[ ] blacklistedURLPatterns:@[ ] forMainFrameOnly:YES]);
+    [[configuration userContentController] _addUserStyleSheet:styleSheet.get()];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+}
+
+TEST(WKUserContentController, AddUserStyleSheetAfterCreatingView)
+{
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
+
+    RetainPtr<_WKUserStyleSheet> styleSheet = adoptNS([[_WKUserStyleSheet alloc] initWithSource:styleSheetSource whitelistedURLPatterns:@[ ] blacklistedURLPatterns:@[ ] forMainFrameOnly:YES]);
+    [[webView configuration].userContentController _addUserStyleSheet:styleSheet.get()];
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+}
+
+TEST(WKUserContentController, UserStyleSheetWhiteAndBlackList)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    RetainPtr<_WKUserStyleSheet> styleSheet = adoptNS([[_WKUserStyleSheet alloc] initWithSource:styleSheetSource whitelistedURLPatterns:@[ @"http://happy.example.com/", @"http://*.example2.com/" ] blacklistedURLPatterns:@[ @"http://sad.example.com/" ] forMainFrameOnly:YES]);
+    [[configuration userContentController] _addUserStyleSheet:styleSheet.get()];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    // Try something on the whitelist:
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:[NSURL URLWithString:@"http://happy.example.com/"]];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+
+    // Try something on the blacklist:
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:[NSURL URLWithString:@"http://sad.example.com/"]];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
+
+    // Try something on neither list:
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:[NSURL URLWithString:@"http://mediocre.example.com/"]];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
+
+    // Try something that matches the globbing pattern in the whitelist:
+
+    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:[NSURL URLWithString:@"http://anything.example2.com/"]];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+}
+
+TEST(WKUserContentController, UserStyleSheetAffectingOnlyMainFrame)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    RetainPtr<_WKUserStyleSheet> styleSheet = adoptNS([[_WKUserStyleSheet alloc] initWithSource:styleSheetSource whitelistedURLPatterns:@[ ] blacklistedURLPatterns:@[ ] forMainFrameOnly:YES]);
+    [[configuration userContentController] _addUserStyleSheet:styleSheet.get()];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    // The main frame should be affected.
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+
+    // The subframe shouldn't be affected.
+    expectScriptEvaluatesToColor(webView.get(), frameBackgroundColorScript, whiteInRGB);
+}
+
+TEST(WKUserContentController, UserStyleSheetAffectingAllFrames)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    RetainPtr<_WKUserStyleSheet> styleSheet = adoptNS([[_WKUserStyleSheet alloc] initWithSource:styleSheetSource whitelistedURLPatterns:@[ ] blacklistedURLPatterns:@[ ] forMainFrameOnly:NO]);
+    [[configuration userContentController] _addUserStyleSheet:styleSheet.get()];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    isDoneWithNavigation = false;
+
+    // The main frame should be affected.
+    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
+
+    // The subframe should also be affected.
+    expectScriptEvaluatesToColor(webView.get(), frameBackgroundColorScript, greenInRGB);
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to