Title: [261726] trunk/Source
Revision
261726
Author
timo...@apple.com
Date
2020-05-14 17:33:37 -0700 (Thu, 14 May 2020)

Log Message

Add baseURL version of _WKUserStyleSheet forWKWebView.
https://bugs.webkit.org/show_bug.cgi?id=211926
rdar://problem/62074675

Reviewed by Devin Rousso.

Source/WebCore:

Consolidate the paths taken for adding a UserStyleSheet. The m_injectedStyleSheetToSource
was missing for page specific style sheets since it was another loop.

* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:

Source/WebKit:

* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:baseURL:level:userContentWorld:]): Added.
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:level:userContentWorld:]): Clean up WebCore::UserStyleSheet initializer.
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:]): Ditto.
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:userContentWorld:]): Ditto.
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]): Ditto.
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:level:userContentWorld:]): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (261725 => 261726)


--- trunk/Source/WebCore/ChangeLog	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebCore/ChangeLog	2020-05-15 00:33:37 UTC (rev 261726)
@@ -1,3 +1,21 @@
+2020-05-14  Timothy Hatcher  <timo...@apple.com>
+
+        Add baseURL version of _WKUserStyleSheet forWKWebView.
+        https://bugs.webkit.org/show_bug.cgi?id=211926
+        rdar://problem/62074675
+
+        Reviewed by Devin Rousso.
+
+        Consolidate the paths taken for adding a UserStyleSheet. The m_injectedStyleSheetToSource
+        was missing for page specific style sheets since it was another loop.
+
+        * dom/ExtensionStyleSheets.cpp:
+        (WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
+        (WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
+        (WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
+        (WebCore::ExtensionStyleSheets::detachFromDocument):
+        * dom/ExtensionStyleSheets.h:
+
 2020-05-14  Jiewen Tan  <jiewen_...@apple.com>
 
         [WebAuthn] Relaxing signature length requirements for U2fRegister

Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (261725 => 261726)


--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2020-05-15 00:33:37 UTC (rev 261726)
@@ -127,13 +127,20 @@
     if (!owningPage)
         return;
 
-    for (const auto& pageSpecificStyleSheet : m_pageSpecificStyleSheets) {
-        if (pageSpecificStyleSheet->contents().isUserStyleSheet())
-            m_injectedUserStyleSheets.append(pageSpecificStyleSheet);
+    auto addStyleSheet = [&](const UserStyleSheet& userStyleSheet) {
+        auto sheet = createExtensionsStyleSheet(const_cast<Document&>(m_document), userStyleSheet.url(), userStyleSheet.source(), userStyleSheet.level());
+
+        m_injectedStyleSheetToSource.set(sheet.copyRef(), userStyleSheet.source());
+
+        if (sheet->contents().isUserStyleSheet())
+            m_injectedUserStyleSheets.append(WTFMove(sheet));
         else
-            m_injectedAuthorStyleSheets.append(pageSpecificStyleSheet);
-    }
+            m_injectedAuthorStyleSheets.append(WTFMove(sheet));
+    };
 
+    for (const auto& userStyleSheet : m_pageSpecificStyleSheets)
+        addStyleSheet(userStyleSheet);
+
     owningPage->userContentProvider().forEachUserStyleSheet([&](const UserStyleSheet& userStyleSheet) {
         if (userStyleSheet.pageID())
             return;
@@ -144,28 +151,20 @@
         if (!UserContentURLPattern::matchesPatterns(m_document.url(), userStyleSheet.whitelist(), userStyleSheet.blacklist()))
             return;
 
-        auto sheet = createExtensionsStyleSheet(const_cast<Document&>(m_document), userStyleSheet.url(), userStyleSheet.source(), userStyleSheet.level());
-
-        m_injectedStyleSheetToSource.set(sheet.copyRef(), userStyleSheet.source());
-
-        if (userStyleSheet.level() == UserStyleUserLevel)
-            m_injectedUserStyleSheets.append(WTFMove(sheet));
-        else
-            m_injectedAuthorStyleSheets.append(WTFMove(sheet));
+        addStyleSheet(userStyleSheet);
     });
 }
 
 void ExtensionStyleSheets::injectPageSpecificUserStyleSheet(const UserStyleSheet& userStyleSheet)
 {
-    auto sheet = createExtensionsStyleSheet(const_cast<Document&>(m_document), userStyleSheet.url(), userStyleSheet.source(), userStyleSheet.level());
-    m_pageSpecificStyleSheets.append(WTFMove(sheet));
+    m_pageSpecificStyleSheets.append(userStyleSheet);
     invalidateInjectedStyleSheetCache();
 }
 
 void ExtensionStyleSheets::removePageSpecificUserStyleSheet(const UserStyleSheet& userStyleSheet)
 {
-    bool removedStyleSheet = m_pageSpecificStyleSheets.removeFirstMatching([userStyleSheet](auto& cssStyleSheet) {
-        return cssStyleSheet->contents().originalURL() == userStyleSheet.url();
+    bool removedStyleSheet = m_pageSpecificStyleSheets.removeFirstMatching([&](const auto& styleSheet) {
+        return styleSheet.url() == userStyleSheet.url();
     });
 
     if (removedStyleSheet)
@@ -237,8 +236,6 @@
         sheet->detachFromDocument();
     for (auto& sheet : m_authorStyleSheetsForTesting)
         sheet->detachFromDocument();
-    for (auto& sheet : m_pageSpecificStyleSheets)
-        sheet->detachFromDocument();
 }
 
 }

Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.h (261725 => 261726)


--- trunk/Source/WebCore/dom/ExtensionStyleSheets.h	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.h	2020-05-15 00:33:37 UTC (rev 261726)
@@ -27,6 +27,7 @@
 
 #pragma once
 
+#include "UserStyleSheet.h"
 #include <memory>
 #include <wtf/FastMalloc.h>
 #include <wtf/HashMap.h>
@@ -46,7 +47,6 @@
 class StyleSheet;
 class StyleSheetContents;
 class StyleSheetList;
-class UserStyleSheet;
 
 class ExtensionStyleSheets {
     WTF_MAKE_FAST_ALLOCATED;
@@ -92,7 +92,7 @@
 
     Vector<RefPtr<CSSStyleSheet>> m_userStyleSheets;
     Vector<RefPtr<CSSStyleSheet>> m_authorStyleSheetsForTesting;
-    Vector<RefPtr<CSSStyleSheet>> m_pageSpecificStyleSheets;
+    Vector<UserStyleSheet> m_pageSpecificStyleSheets;
 
 #if ENABLE(CONTENT_EXTENSIONS)
     HashMap<String, RefPtr<CSSStyleSheet>> m_contentExtensionSheets;

Modified: trunk/Source/WebKit/ChangeLog (261725 => 261726)


--- trunk/Source/WebKit/ChangeLog	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebKit/ChangeLog	2020-05-15 00:33:37 UTC (rev 261726)
@@ -1,3 +1,20 @@
+2020-05-14  Timothy Hatcher  <timo...@apple.com>
+
+        Add baseURL version of _WKUserStyleSheet forWKWebView.
+        https://bugs.webkit.org/show_bug.cgi?id=211926
+        rdar://problem/62074675
+
+        Reviewed by Devin Rousso.
+
+        * UIProcess/API/Cocoa/_WKUserStyleSheet.h:
+        * UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
+        (-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:baseURL:level:userContentWorld:]): Added.
+        (-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:level:userContentWorld:]): Clean up WebCore::UserStyleSheet initializer.
+        (-[_WKUserStyleSheet initWithSource:forMainFrameOnly:]): Ditto.
+        (-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:userContentWorld:]): Ditto.
+        (-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]): Ditto.
+        (-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:level:userContentWorld:]): Ditto.
+
 2020-05-14  John Wilander  <wilan...@apple.com>
 
         Add quirk for cookie blocking latch mode aolmail.com redirecting to aol.com under aol.com

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.h (261725 => 261726)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.h	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.h	2020-05-15 00:33:37 UTC (rev 261726)
@@ -49,6 +49,7 @@
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 - (instancetype)initWithSource:(NSString *)source forWKWebView:(WKWebView *)webView forMainFrameOnly:(BOOL)forMainFrameOnly level:(_WKUserStyleLevel)level userContentWorld:(_WKUserContentWorld *)userContentWorld WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (instancetype)initWithSource:(NSString *)source forWKWebView:(WKWebView *)webView forMainFrameOnly:(BOOL)forMainFrameOnly baseURL:(NSURL *)baseURL level:(_WKUserStyleLevel)level userContentWorld:(_WKUserContentWorld *)userContentWorld WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (instancetype)initWithSource:(NSString *)source forMainFrameOnly:(BOOL)forMainFrameOnly legacyWhitelist:(NSArray<NSString *> *)legacyWhitelist legacyBlacklist:(NSArray<NSString *> *)legacyBlacklist userContentWorld:(_WKUserContentWorld *)userContentWorld;
 - (instancetype)initWithSource:(NSString *)source forMainFrameOnly:(BOOL)forMainFrameOnly legacyWhitelist:(NSArray<NSString *> *)legacyWhitelist legacyBlacklist:(NSArray<NSString *> *)legacyBlacklist baseURL:(NSURL *)baseURL userContentWorld:(_WKUserContentWorld *)userContentWorld;
 - (instancetype)initWithSource:(NSString *)source forMainFrameOnly:(BOOL)forMainFrameOnly legacyWhitelist:(NSArray<NSString *> *)legacyWhitelist legacyBlacklist:(NSArray<NSString *> *)legacyBlacklist baseURL:(NSURL *)baseURL level:(_WKUserStyleLevel)level userContentWorld:(_WKUserContentWorld *)userContentWorld WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.mm (261725 => 261726)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.mm	2020-05-15 00:20:26 UTC (rev 261725)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserStyleSheet.mm	2020-05-15 00:33:37 UTC (rev 261726)
@@ -45,7 +45,7 @@
     // 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(), { }, { }, forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, API::ContentWorld::pageContentWorld());
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { source, API::UserStyleSheet::generateUniqueURL(), { }, { }, forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, API::ContentWorld::pageContentWorld());
 
     return self;
 }
@@ -59,11 +59,24 @@
     // 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(), { },  { }, forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, API::toWebCoreUserStyleLevel(level), [webView _page]->webPageID() }, *userContentWorld->_contentWorld->_contentWorld);
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { source, API::UserStyleSheet::generateUniqueURL(), { }, { }, forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, API::toWebCoreUserStyleLevel(level), [webView _page]->webPageID() }, *userContentWorld->_contentWorld->_contentWorld);
 
     return self;
 }
 
+- (instancetype)initWithSource:(NSString *)source forWKWebView:(WKWebView *)webView forMainFrameOnly:(BOOL)forMainFrameOnly baseURL:(NSURL *)baseURL level:(_WKUserStyleLevel)level userContentWorld:(_WKUserContentWorld *)userContentWorld
+{
+    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 { source, baseURL, { }, { }, forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, API::toWebCoreUserStyleLevel(level), [webView _page]->webPageID() }, *userContentWorld->_contentWorld->_contentWorld);
+
+    return self;
+}
+
 - (instancetype)initWithSource:(NSString *)source forMainFrameOnly:(BOOL)forMainFrameOnly legacyWhitelist:(NSArray<NSString *> *)legacyWhitelist legacyBlacklist:(NSArray<NSString *> *)legacyBlacklist userContentWorld:(_WKUserContentWorld *)userContentWorld
 {
     if (!(self = [super init]))
@@ -72,7 +85,7 @@
     // 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(), makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, *userContentWorld->_contentWorld->_contentWorld);
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { source, API::UserStyleSheet::generateUniqueURL(), makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, *userContentWorld->_contentWorld->_contentWorld);
 
     return self;
 }
@@ -85,7 +98,7 @@
     // 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), {  URL(), WTF::String([baseURL _web_originalDataAsWTFString]) }, makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, *userContentWorld->_contentWorld->_contentWorld);
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { source, baseURL, makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, WebCore::UserStyleUserLevel }, *userContentWorld->_contentWorld->_contentWorld);
 
     return self;
 }
@@ -98,7 +111,7 @@
     // 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), {  URL(), WTF::String([baseURL _web_originalDataAsWTFString]) }, makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, API::toWebCoreUserStyleLevel(level) }, *userContentWorld->_contentWorld->_contentWorld);
+    API::Object::constructInWrapper<API::UserStyleSheet>(self, WebCore::UserStyleSheet { source, baseURL, makeVector<String>(legacyWhitelist), makeVector<String>(legacyBlacklist), forMainFrameOnly ? WebCore::UserContentInjectedFrames::InjectInTopFrameOnly : WebCore::UserContentInjectedFrames::InjectInAllFrames, API::toWebCoreUserStyleLevel(level) }, *userContentWorld->_contentWorld->_contentWorld);
 
     return self;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to