2015-09-23 15:04:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
|
|
|
|
* (C) 1999 Antti Koivisto (koivisto@kde.org)
|
|
|
|
* (C) 2001 Dirk Mueller (mueller@kde.org)
|
|
|
|
* (C) 2006 Alexey Proskuryakov (ap@webkit.org)
|
|
|
|
* Copyright (C) 2004-2009, 2011-2012, 2015 Apple Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
|
|
|
|
* Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
|
|
|
|
* Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "ExtensionStyleSheets.h"
|
|
|
|
|
|
|
|
#include "CSSStyleSheet.h"
|
|
|
|
#include "Element.h"
|
|
|
|
#include "HTMLLinkElement.h"
|
|
|
|
#include "HTMLStyleElement.h"
|
|
|
|
#include "Page.h"
|
|
|
|
#include "ProcessingInstruction.h"
|
|
|
|
#include "SVGStyleElement.h"
|
|
|
|
#include "Settings.h"
|
2017-05-03 14:04:21 +00:00
|
|
|
#include "StyleInvalidator.h"
|
2015-09-23 15:04:16 +00:00
|
|
|
#include "StyleResolver.h"
|
2016-10-07 16:55:11 +00:00
|
|
|
#include "StyleScope.h"
|
2015-09-23 15:04:16 +00:00
|
|
|
#include "StyleSheetContents.h"
|
|
|
|
#include "StyleSheetList.h"
|
|
|
|
#include "UserContentController.h"
|
|
|
|
#include "UserContentURLPattern.h"
|
|
|
|
#include "UserStyleSheet.h"
|
|
|
|
|
|
|
|
namespace WebCore {
|
|
|
|
|
2019-04-26 17:03:15 +00:00
|
|
|
#if ENABLE(CONTENT_EXTENSIONS)
|
2015-09-23 15:04:16 +00:00
|
|
|
using namespace ContentExtensions;
|
2019-04-26 17:03:15 +00:00
|
|
|
#endif
|
2015-09-23 15:04:16 +00:00
|
|
|
using namespace HTMLNames;
|
|
|
|
|
|
|
|
ExtensionStyleSheets::ExtensionStyleSheets(Document& document)
|
|
|
|
: m_document(document)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:39:04 +00:00
|
|
|
static Ref<CSSStyleSheet> createExtensionsStyleSheet(Document& document, URL url, const String& text, UserStyleLevel level)
|
|
|
|
{
|
2020-04-25 21:28:45 +00:00
|
|
|
auto contents = StyleSheetContents::create(url.string(), CSSParserContext(document, url));
|
2016-10-14 15:39:04 +00:00
|
|
|
auto styleSheet = CSSStyleSheet::create(contents.get(), document, true);
|
|
|
|
|
|
|
|
contents->setIsUserStyleSheet(level == UserStyleUserLevel);
|
|
|
|
contents->parseString(text);
|
|
|
|
|
|
|
|
return styleSheet;
|
|
|
|
}
|
|
|
|
|
2015-09-23 15:04:16 +00:00
|
|
|
CSSStyleSheet* ExtensionStyleSheets::pageUserSheet()
|
|
|
|
{
|
|
|
|
if (m_pageUserSheet)
|
|
|
|
return m_pageUserSheet.get();
|
|
|
|
|
|
|
|
Page* owningPage = m_document.page();
|
|
|
|
if (!owningPage)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
String userSheetText = owningPage->userStyleSheet();
|
|
|
|
if (userSheetText.isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
2017-02-09 17:47:33 +00:00
|
|
|
m_pageUserSheet = createExtensionsStyleSheet(m_document, m_document.settings().userStyleSheetLocation(), userSheetText, UserStyleUserLevel);
|
2016-10-14 15:39:04 +00:00
|
|
|
|
2015-09-23 15:04:16 +00:00
|
|
|
return m_pageUserSheet.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::clearPageUserSheet()
|
|
|
|
{
|
|
|
|
if (m_pageUserSheet) {
|
|
|
|
m_pageUserSheet = nullptr;
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::updatePageUserSheet()
|
|
|
|
{
|
|
|
|
clearPageUserSheet();
|
|
|
|
if (pageUserSheet())
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Vector<RefPtr<CSSStyleSheet>>& ExtensionStyleSheets::injectedUserStyleSheets() const
|
|
|
|
{
|
|
|
|
updateInjectedStyleSheetCache();
|
|
|
|
return m_injectedUserStyleSheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector<RefPtr<CSSStyleSheet>>& ExtensionStyleSheets::injectedAuthorStyleSheets() const
|
|
|
|
{
|
|
|
|
updateInjectedStyleSheetCache();
|
|
|
|
return m_injectedAuthorStyleSheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::updateInjectedStyleSheetCache() const
|
|
|
|
{
|
|
|
|
if (m_injectedStyleSheetCacheValid)
|
|
|
|
return;
|
2020-01-08 05:02:02 +00:00
|
|
|
|
2015-09-23 15:04:16 +00:00
|
|
|
m_injectedStyleSheetCacheValid = true;
|
|
|
|
m_injectedUserStyleSheets.clear();
|
|
|
|
m_injectedAuthorStyleSheets.clear();
|
2020-01-08 05:02:02 +00:00
|
|
|
m_injectedStyleSheetToSource.clear();
|
2015-09-23 15:04:16 +00:00
|
|
|
|
|
|
|
Page* owningPage = m_document.page();
|
|
|
|
if (!owningPage)
|
|
|
|
return;
|
|
|
|
|
2020-05-15 00:33:37 +00:00
|
|
|
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));
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
else
|
2020-05-15 00:33:37 +00:00
|
|
|
m_injectedAuthorStyleSheets.append(WTFMove(sheet));
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& userStyleSheet : m_pageSpecificStyleSheets)
|
|
|
|
addStyleSheet(userStyleSheet);
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
|
Add a baseURL parameter to _WKUserStyleSheet
https://bugs.webkit.org/show_bug.cgi?id=155219
Reviewed by Tim Horton.
Source/WebCore:
- Moves to a model for user content where instead of each page having a WebCore::UserContentController
object, we have an abstract WebCore::UserContentProvider interface that can be implemented at the WebKit
level. For now, legacy WebKit continues to use the old UserContentController, which implements
WebCore::UserContentProvider, and WebKit2 implements its own implementation so it can store additional
state.
* WebCore.xcodeproj/project.pbxproj:
Add new files.
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
Switch to using forEachUserStyleSheet on the UserContentProvider.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::loadResource):
Remove null check now that we always have a UserContentProvider.
* loader/EmptyClients.cpp:
(WebCore::fillWithEmptyClients):
* loader/EmptyClients.h:
Add new EmptyClients.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
Remove null check now that we always have a UserContentProvider.
* loader/PingLoader.cpp:
(WebCore::processContentExtensionRulesForLoad):
Remove null check now that we always have a UserContentProvider.
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal):
Remove null check now that we always have a UserContentProvider.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Remove null check now that we always have a UserContentProvider.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
Remove null checks now that we always have a UserContentProvider, and userMessageHandlerDescriptors
returns a reference.
(WebCore::DOMWindow::open):
Remove null check now that we always have a UserContentProvider.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
Simplify by lifting document check out of the main loop and using forEachUserScript.
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::userContentProvider):
(WebCore::Page::setUserContentProvider):
(WebCore::Page::setUserContentController): Deleted.
* page/Page.h:
(WebCore::Page::userContentController): Deleted.
* page/PageConfiguration.h:
Store the UserContentProvider in a Ref, and require PageConfigurations to provide one. This
removes a bunch of null checks and simplifies the code.
* page/UserContentController.cpp:
(WebCore::UserContentController::~UserContentController):
(WebCore::UserContentController::forEachUserScript):
(WebCore::UserContentController::forEachUserStyleSheet):
(WebCore::UserContentController::addUserScript):
(WebCore::UserContentController::removeUserScript):
(WebCore::UserContentController::removeUserScripts):
(WebCore::UserContentController::addUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheets):
(WebCore::UserContentController::addUserMessageHandlerDescriptor):
(WebCore::UserContentController::removeUserMessageHandlerDescriptor):
(WebCore::UserContentController::addUserContentExtension):
(WebCore::UserContentController::removeUserContentExtension):
(WebCore::UserContentController::removeAllUserContentExtensions):
(WebCore::UserContentController::removeAllUserContent):
(WebCore::UserContentController::addPage): Deleted.
(WebCore::UserContentController::removePage): Deleted.
(WebCore::contentExtensionsEnabled): Deleted.
(WebCore::UserContentController::processContentExtensionRulesForLoad): Deleted.
(WebCore::UserContentController::actionsForResourceLoad): Deleted.
* page/UserContentController.h:
(WebCore::UserContentController::userScripts): Deleted.
(WebCore::UserContentController::userStyleSheets): Deleted.
(WebCore::UserContentController::userMessageHandlerDescriptors): Deleted.
Add inheritance from UserContentProvider and simplify things by removing unique_ptrs
that were holding the member variables. There is usually only one UserContentController
so having these in unique_ptrs doesn't make much sense.
* page/UserContentProvider.cpp: Added.
(WebCore::UserContentProvider::UserContentProvider):
(WebCore::UserContentProvider::~UserContentProvider):
(WebCore::UserContentProvider::addPage):
(WebCore::UserContentProvider::removePage):
(WebCore::UserContentProvider::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
(WebCore::contentExtensionsEnabled):
(WebCore::UserContentProvider::processContentExtensionRulesForLoad):
(WebCore::UserContentProvider::actionsForResourceLoad):
* page/UserContentProvider.h: Added.
Add abstract class for providing user content and add some helpers on it.
* page/UserMessageHandlerDescriptor.h:
(WebCore::UserMessageHandlerDescriptor::create):
(WebCore::UserMessageHandlerDescriptor::client):
(WebCore::UserMessageHandlerDescriptor::invalidateClient):
* page/UserMessageHandlersNamespace.cpp:
(WebCore::UserMessageHandlersNamespace::handler):
Simplify now that userContentProvider() and userMessageHandlerDescriptors() are references.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
(-[WebView setGroupName:]):
Update to account for the name change from UserContentController -> UserContentProvider.
Source/WebKit2:
- Moves to a model for user content where instead of using a WebCore::UserContentController
object, we implement the new WebCore::UserContentProvider interface (on the existing
WebUserContentController object).
- Uses this to maintain maps of UserStylesSheets and UserScripts along with their identifiers,
freeing up the URL, which had been acting as the identifier, to be used as the baseURL which
was what it was intended for.
- Adds a baseURL property to _WKUserStyleSheet.
* WebKit2.xcodeproj/project.pbxproj:
Add new files.
* Scripts/webkit/messages.py:
(headers_for_type):
Add support for sending WebUserContentControllerDataTypes.
* Shared/WebUserContentControllerDataTypes.cpp: Added.
(WebKit::WebUserScriptData::encode):
(WebKit::WebUserScriptData::decode):
(WebKit::WebUserStyleSheetData::encode):
(WebKit::WebUserStyleSheetData::decode):
* Shared/WebUserContentControllerDataTypes.h: Added.
Add helper types for sending user content over IPC.
* UIProcess/API/APIUserScript.cpp:
(API::UserScript::generateUniqueURL):
(API::UserScript::UserScript):
* UIProcess/API/APIUserScript.h:
* UIProcess/API/APIUserStyleSheet.cpp:
(API::UserStyleSheet::generateUniqueURL):
(API::UserStyleSheet::UserStyleSheet):
* UIProcess/API/APIUserStyleSheet.h:
Add identifiers for tracking across processes.
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]):
(-[_WKUserStyleSheet baseURL]):
Add new initializer which takes a baseURL as well as an accessor for the baseURL.
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserScript):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
Pass identifiers as well as user content.
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::addUserScript):
(WebKit::InjectedBundle::addUserStyleSheet):
Move user content in via move semantics rather than using a unique_ptr.
(WebKit::InjectedBundle::removeUserScript):
(WebKit::InjectedBundle::removeUserStyleSheet):
(WebKit::InjectedBundle::removeUserScripts):
(WebKit::InjectedBundle::removeUserStyleSheets):
(WebKit::InjectedBundle::removeAllUserContent):
Update for new function signatures.
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::WebUserContentController):
(WebKit::WebUserContentController::~WebUserContentController):
(WebKit::WebUserContentController::addUserContentWorlds):
(WebKit::WebUserContentController::removeUserContentWorlds):
(WebKit::WebUserContentController::addUserScripts):
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeAllUserScripts):
(WebKit::WebUserContentController::addUserStyleSheets):
(WebKit::WebUserContentController::removeUserStyleSheet):
(WebKit::WebUserContentController::removeAllUserStyleSheets):
(WebKit::WebUserContentController::addUserScriptMessageHandlers):
(WebKit::WebUserContentController::removeUserScriptMessageHandler):
(WebKit::WebUserContentController::addUserContentExtensions):
(WebKit::WebUserContentController::removeUserContentExtension):
(WebKit::WebUserContentController::removeAllUserContentExtensions):
(WebKit::WebUserContentController::addUserScriptInternal):
(WebKit::WebUserContentController::addUserScript):
(WebKit::WebUserContentController::removeUserScriptWithURL):
(WebKit::WebUserContentController::removeUserScriptInternal):
(WebKit::WebUserContentController::removeUserScripts):
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::addUserStyleSheet):
(WebKit::WebUserContentController::removeUserStyleSheetWithURL):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheets):
(WebKit::WebUserContentController::removeAllUserContent):
(WebKit::WebUserContentController::forEachUserScript):
(WebKit::WebUserContentController::forEachUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:
Convert to inheriting from UserContentProvider, rather than containing a UserContentController.
This means adding the storage for the user content, which has been simplified to avoid using
unique_ptrs.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addUserScript):
(WebKit::WebPage::addUserStyleSheet):
(WebKit::WebPage::removeAllUserContent):
Update to call the WebUserContentController, rather than going to the UserContentController, which
no longer exists.
* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::userContentController):
* WebProcess/WebPage/WebPageGroupProxy.h:
Return the WebUserContentController rather than old UserContentController.
Canonical link: https://commits.webkit.org/173593@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-15 00:48:40 +00:00
|
|
|
owningPage->userContentProvider().forEachUserStyleSheet([&](const UserStyleSheet& userStyleSheet) {
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
if (userStyleSheet.pageID())
|
|
|
|
return;
|
|
|
|
|
2020-04-04 00:44:31 +00:00
|
|
|
if (userStyleSheet.injectedFrames() == UserContentInjectedFrames::InjectInTopFrameOnly && m_document.ownerElement())
|
Add a baseURL parameter to _WKUserStyleSheet
https://bugs.webkit.org/show_bug.cgi?id=155219
Reviewed by Tim Horton.
Source/WebCore:
- Moves to a model for user content where instead of each page having a WebCore::UserContentController
object, we have an abstract WebCore::UserContentProvider interface that can be implemented at the WebKit
level. For now, legacy WebKit continues to use the old UserContentController, which implements
WebCore::UserContentProvider, and WebKit2 implements its own implementation so it can store additional
state.
* WebCore.xcodeproj/project.pbxproj:
Add new files.
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
Switch to using forEachUserStyleSheet on the UserContentProvider.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::loadResource):
Remove null check now that we always have a UserContentProvider.
* loader/EmptyClients.cpp:
(WebCore::fillWithEmptyClients):
* loader/EmptyClients.h:
Add new EmptyClients.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
Remove null check now that we always have a UserContentProvider.
* loader/PingLoader.cpp:
(WebCore::processContentExtensionRulesForLoad):
Remove null check now that we always have a UserContentProvider.
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal):
Remove null check now that we always have a UserContentProvider.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Remove null check now that we always have a UserContentProvider.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
Remove null checks now that we always have a UserContentProvider, and userMessageHandlerDescriptors
returns a reference.
(WebCore::DOMWindow::open):
Remove null check now that we always have a UserContentProvider.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
Simplify by lifting document check out of the main loop and using forEachUserScript.
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::userContentProvider):
(WebCore::Page::setUserContentProvider):
(WebCore::Page::setUserContentController): Deleted.
* page/Page.h:
(WebCore::Page::userContentController): Deleted.
* page/PageConfiguration.h:
Store the UserContentProvider in a Ref, and require PageConfigurations to provide one. This
removes a bunch of null checks and simplifies the code.
* page/UserContentController.cpp:
(WebCore::UserContentController::~UserContentController):
(WebCore::UserContentController::forEachUserScript):
(WebCore::UserContentController::forEachUserStyleSheet):
(WebCore::UserContentController::addUserScript):
(WebCore::UserContentController::removeUserScript):
(WebCore::UserContentController::removeUserScripts):
(WebCore::UserContentController::addUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheets):
(WebCore::UserContentController::addUserMessageHandlerDescriptor):
(WebCore::UserContentController::removeUserMessageHandlerDescriptor):
(WebCore::UserContentController::addUserContentExtension):
(WebCore::UserContentController::removeUserContentExtension):
(WebCore::UserContentController::removeAllUserContentExtensions):
(WebCore::UserContentController::removeAllUserContent):
(WebCore::UserContentController::addPage): Deleted.
(WebCore::UserContentController::removePage): Deleted.
(WebCore::contentExtensionsEnabled): Deleted.
(WebCore::UserContentController::processContentExtensionRulesForLoad): Deleted.
(WebCore::UserContentController::actionsForResourceLoad): Deleted.
* page/UserContentController.h:
(WebCore::UserContentController::userScripts): Deleted.
(WebCore::UserContentController::userStyleSheets): Deleted.
(WebCore::UserContentController::userMessageHandlerDescriptors): Deleted.
Add inheritance from UserContentProvider and simplify things by removing unique_ptrs
that were holding the member variables. There is usually only one UserContentController
so having these in unique_ptrs doesn't make much sense.
* page/UserContentProvider.cpp: Added.
(WebCore::UserContentProvider::UserContentProvider):
(WebCore::UserContentProvider::~UserContentProvider):
(WebCore::UserContentProvider::addPage):
(WebCore::UserContentProvider::removePage):
(WebCore::UserContentProvider::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
(WebCore::contentExtensionsEnabled):
(WebCore::UserContentProvider::processContentExtensionRulesForLoad):
(WebCore::UserContentProvider::actionsForResourceLoad):
* page/UserContentProvider.h: Added.
Add abstract class for providing user content and add some helpers on it.
* page/UserMessageHandlerDescriptor.h:
(WebCore::UserMessageHandlerDescriptor::create):
(WebCore::UserMessageHandlerDescriptor::client):
(WebCore::UserMessageHandlerDescriptor::invalidateClient):
* page/UserMessageHandlersNamespace.cpp:
(WebCore::UserMessageHandlersNamespace::handler):
Simplify now that userContentProvider() and userMessageHandlerDescriptors() are references.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
(-[WebView setGroupName:]):
Update to account for the name change from UserContentController -> UserContentProvider.
Source/WebKit2:
- Moves to a model for user content where instead of using a WebCore::UserContentController
object, we implement the new WebCore::UserContentProvider interface (on the existing
WebUserContentController object).
- Uses this to maintain maps of UserStylesSheets and UserScripts along with their identifiers,
freeing up the URL, which had been acting as the identifier, to be used as the baseURL which
was what it was intended for.
- Adds a baseURL property to _WKUserStyleSheet.
* WebKit2.xcodeproj/project.pbxproj:
Add new files.
* Scripts/webkit/messages.py:
(headers_for_type):
Add support for sending WebUserContentControllerDataTypes.
* Shared/WebUserContentControllerDataTypes.cpp: Added.
(WebKit::WebUserScriptData::encode):
(WebKit::WebUserScriptData::decode):
(WebKit::WebUserStyleSheetData::encode):
(WebKit::WebUserStyleSheetData::decode):
* Shared/WebUserContentControllerDataTypes.h: Added.
Add helper types for sending user content over IPC.
* UIProcess/API/APIUserScript.cpp:
(API::UserScript::generateUniqueURL):
(API::UserScript::UserScript):
* UIProcess/API/APIUserScript.h:
* UIProcess/API/APIUserStyleSheet.cpp:
(API::UserStyleSheet::generateUniqueURL):
(API::UserStyleSheet::UserStyleSheet):
* UIProcess/API/APIUserStyleSheet.h:
Add identifiers for tracking across processes.
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]):
(-[_WKUserStyleSheet baseURL]):
Add new initializer which takes a baseURL as well as an accessor for the baseURL.
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserScript):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
Pass identifiers as well as user content.
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::addUserScript):
(WebKit::InjectedBundle::addUserStyleSheet):
Move user content in via move semantics rather than using a unique_ptr.
(WebKit::InjectedBundle::removeUserScript):
(WebKit::InjectedBundle::removeUserStyleSheet):
(WebKit::InjectedBundle::removeUserScripts):
(WebKit::InjectedBundle::removeUserStyleSheets):
(WebKit::InjectedBundle::removeAllUserContent):
Update for new function signatures.
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::WebUserContentController):
(WebKit::WebUserContentController::~WebUserContentController):
(WebKit::WebUserContentController::addUserContentWorlds):
(WebKit::WebUserContentController::removeUserContentWorlds):
(WebKit::WebUserContentController::addUserScripts):
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeAllUserScripts):
(WebKit::WebUserContentController::addUserStyleSheets):
(WebKit::WebUserContentController::removeUserStyleSheet):
(WebKit::WebUserContentController::removeAllUserStyleSheets):
(WebKit::WebUserContentController::addUserScriptMessageHandlers):
(WebKit::WebUserContentController::removeUserScriptMessageHandler):
(WebKit::WebUserContentController::addUserContentExtensions):
(WebKit::WebUserContentController::removeUserContentExtension):
(WebKit::WebUserContentController::removeAllUserContentExtensions):
(WebKit::WebUserContentController::addUserScriptInternal):
(WebKit::WebUserContentController::addUserScript):
(WebKit::WebUserContentController::removeUserScriptWithURL):
(WebKit::WebUserContentController::removeUserScriptInternal):
(WebKit::WebUserContentController::removeUserScripts):
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::addUserStyleSheet):
(WebKit::WebUserContentController::removeUserStyleSheetWithURL):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheets):
(WebKit::WebUserContentController::removeAllUserContent):
(WebKit::WebUserContentController::forEachUserScript):
(WebKit::WebUserContentController::forEachUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:
Convert to inheriting from UserContentProvider, rather than containing a UserContentController.
This means adding the storage for the user content, which has been simplified to avoid using
unique_ptrs.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addUserScript):
(WebKit::WebPage::addUserStyleSheet):
(WebKit::WebPage::removeAllUserContent):
Update to call the WebUserContentController, rather than going to the UserContentController, which
no longer exists.
* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::userContentController):
* WebProcess/WebPage/WebPageGroupProxy.h:
Return the WebUserContentController rather than old UserContentController.
Canonical link: https://commits.webkit.org/173593@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-15 00:48:40 +00:00
|
|
|
return;
|
|
|
|
|
2020-06-11 20:47:21 +00:00
|
|
|
if (!UserContentURLPattern::matchesPatterns(m_document.url(), userStyleSheet.allowlist(), userStyleSheet.blocklist()))
|
Add a baseURL parameter to _WKUserStyleSheet
https://bugs.webkit.org/show_bug.cgi?id=155219
Reviewed by Tim Horton.
Source/WebCore:
- Moves to a model for user content where instead of each page having a WebCore::UserContentController
object, we have an abstract WebCore::UserContentProvider interface that can be implemented at the WebKit
level. For now, legacy WebKit continues to use the old UserContentController, which implements
WebCore::UserContentProvider, and WebKit2 implements its own implementation so it can store additional
state.
* WebCore.xcodeproj/project.pbxproj:
Add new files.
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
Switch to using forEachUserStyleSheet on the UserContentProvider.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::loadResource):
Remove null check now that we always have a UserContentProvider.
* loader/EmptyClients.cpp:
(WebCore::fillWithEmptyClients):
* loader/EmptyClients.h:
Add new EmptyClients.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
Remove null check now that we always have a UserContentProvider.
* loader/PingLoader.cpp:
(WebCore::processContentExtensionRulesForLoad):
Remove null check now that we always have a UserContentProvider.
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal):
Remove null check now that we always have a UserContentProvider.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Remove null check now that we always have a UserContentProvider.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
Remove null checks now that we always have a UserContentProvider, and userMessageHandlerDescriptors
returns a reference.
(WebCore::DOMWindow::open):
Remove null check now that we always have a UserContentProvider.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
Simplify by lifting document check out of the main loop and using forEachUserScript.
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::userContentProvider):
(WebCore::Page::setUserContentProvider):
(WebCore::Page::setUserContentController): Deleted.
* page/Page.h:
(WebCore::Page::userContentController): Deleted.
* page/PageConfiguration.h:
Store the UserContentProvider in a Ref, and require PageConfigurations to provide one. This
removes a bunch of null checks and simplifies the code.
* page/UserContentController.cpp:
(WebCore::UserContentController::~UserContentController):
(WebCore::UserContentController::forEachUserScript):
(WebCore::UserContentController::forEachUserStyleSheet):
(WebCore::UserContentController::addUserScript):
(WebCore::UserContentController::removeUserScript):
(WebCore::UserContentController::removeUserScripts):
(WebCore::UserContentController::addUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheets):
(WebCore::UserContentController::addUserMessageHandlerDescriptor):
(WebCore::UserContentController::removeUserMessageHandlerDescriptor):
(WebCore::UserContentController::addUserContentExtension):
(WebCore::UserContentController::removeUserContentExtension):
(WebCore::UserContentController::removeAllUserContentExtensions):
(WebCore::UserContentController::removeAllUserContent):
(WebCore::UserContentController::addPage): Deleted.
(WebCore::UserContentController::removePage): Deleted.
(WebCore::contentExtensionsEnabled): Deleted.
(WebCore::UserContentController::processContentExtensionRulesForLoad): Deleted.
(WebCore::UserContentController::actionsForResourceLoad): Deleted.
* page/UserContentController.h:
(WebCore::UserContentController::userScripts): Deleted.
(WebCore::UserContentController::userStyleSheets): Deleted.
(WebCore::UserContentController::userMessageHandlerDescriptors): Deleted.
Add inheritance from UserContentProvider and simplify things by removing unique_ptrs
that were holding the member variables. There is usually only one UserContentController
so having these in unique_ptrs doesn't make much sense.
* page/UserContentProvider.cpp: Added.
(WebCore::UserContentProvider::UserContentProvider):
(WebCore::UserContentProvider::~UserContentProvider):
(WebCore::UserContentProvider::addPage):
(WebCore::UserContentProvider::removePage):
(WebCore::UserContentProvider::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
(WebCore::contentExtensionsEnabled):
(WebCore::UserContentProvider::processContentExtensionRulesForLoad):
(WebCore::UserContentProvider::actionsForResourceLoad):
* page/UserContentProvider.h: Added.
Add abstract class for providing user content and add some helpers on it.
* page/UserMessageHandlerDescriptor.h:
(WebCore::UserMessageHandlerDescriptor::create):
(WebCore::UserMessageHandlerDescriptor::client):
(WebCore::UserMessageHandlerDescriptor::invalidateClient):
* page/UserMessageHandlersNamespace.cpp:
(WebCore::UserMessageHandlersNamespace::handler):
Simplify now that userContentProvider() and userMessageHandlerDescriptors() are references.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
(-[WebView setGroupName:]):
Update to account for the name change from UserContentController -> UserContentProvider.
Source/WebKit2:
- Moves to a model for user content where instead of using a WebCore::UserContentController
object, we implement the new WebCore::UserContentProvider interface (on the existing
WebUserContentController object).
- Uses this to maintain maps of UserStylesSheets and UserScripts along with their identifiers,
freeing up the URL, which had been acting as the identifier, to be used as the baseURL which
was what it was intended for.
- Adds a baseURL property to _WKUserStyleSheet.
* WebKit2.xcodeproj/project.pbxproj:
Add new files.
* Scripts/webkit/messages.py:
(headers_for_type):
Add support for sending WebUserContentControllerDataTypes.
* Shared/WebUserContentControllerDataTypes.cpp: Added.
(WebKit::WebUserScriptData::encode):
(WebKit::WebUserScriptData::decode):
(WebKit::WebUserStyleSheetData::encode):
(WebKit::WebUserStyleSheetData::decode):
* Shared/WebUserContentControllerDataTypes.h: Added.
Add helper types for sending user content over IPC.
* UIProcess/API/APIUserScript.cpp:
(API::UserScript::generateUniqueURL):
(API::UserScript::UserScript):
* UIProcess/API/APIUserScript.h:
* UIProcess/API/APIUserStyleSheet.cpp:
(API::UserStyleSheet::generateUniqueURL):
(API::UserStyleSheet::UserStyleSheet):
* UIProcess/API/APIUserStyleSheet.h:
Add identifiers for tracking across processes.
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]):
(-[_WKUserStyleSheet baseURL]):
Add new initializer which takes a baseURL as well as an accessor for the baseURL.
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserScript):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
Pass identifiers as well as user content.
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::addUserScript):
(WebKit::InjectedBundle::addUserStyleSheet):
Move user content in via move semantics rather than using a unique_ptr.
(WebKit::InjectedBundle::removeUserScript):
(WebKit::InjectedBundle::removeUserStyleSheet):
(WebKit::InjectedBundle::removeUserScripts):
(WebKit::InjectedBundle::removeUserStyleSheets):
(WebKit::InjectedBundle::removeAllUserContent):
Update for new function signatures.
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::WebUserContentController):
(WebKit::WebUserContentController::~WebUserContentController):
(WebKit::WebUserContentController::addUserContentWorlds):
(WebKit::WebUserContentController::removeUserContentWorlds):
(WebKit::WebUserContentController::addUserScripts):
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeAllUserScripts):
(WebKit::WebUserContentController::addUserStyleSheets):
(WebKit::WebUserContentController::removeUserStyleSheet):
(WebKit::WebUserContentController::removeAllUserStyleSheets):
(WebKit::WebUserContentController::addUserScriptMessageHandlers):
(WebKit::WebUserContentController::removeUserScriptMessageHandler):
(WebKit::WebUserContentController::addUserContentExtensions):
(WebKit::WebUserContentController::removeUserContentExtension):
(WebKit::WebUserContentController::removeAllUserContentExtensions):
(WebKit::WebUserContentController::addUserScriptInternal):
(WebKit::WebUserContentController::addUserScript):
(WebKit::WebUserContentController::removeUserScriptWithURL):
(WebKit::WebUserContentController::removeUserScriptInternal):
(WebKit::WebUserContentController::removeUserScripts):
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::addUserStyleSheet):
(WebKit::WebUserContentController::removeUserStyleSheetWithURL):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheets):
(WebKit::WebUserContentController::removeAllUserContent):
(WebKit::WebUserContentController::forEachUserScript):
(WebKit::WebUserContentController::forEachUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:
Convert to inheriting from UserContentProvider, rather than containing a UserContentController.
This means adding the storage for the user content, which has been simplified to avoid using
unique_ptrs.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addUserScript):
(WebKit::WebPage::addUserStyleSheet):
(WebKit::WebPage::removeAllUserContent):
Update to call the WebUserContentController, rather than going to the UserContentController, which
no longer exists.
* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::userContentController):
* WebProcess/WebPage/WebPageGroupProxy.h:
Return the WebUserContentController rather than old UserContentController.
Canonical link: https://commits.webkit.org/173593@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-15 00:48:40 +00:00
|
|
|
return;
|
|
|
|
|
2020-05-15 00:33:37 +00:00
|
|
|
addStyleSheet(userStyleSheet);
|
Add a baseURL parameter to _WKUserStyleSheet
https://bugs.webkit.org/show_bug.cgi?id=155219
Reviewed by Tim Horton.
Source/WebCore:
- Moves to a model for user content where instead of each page having a WebCore::UserContentController
object, we have an abstract WebCore::UserContentProvider interface that can be implemented at the WebKit
level. For now, legacy WebKit continues to use the old UserContentController, which implements
WebCore::UserContentProvider, and WebKit2 implements its own implementation so it can store additional
state.
* WebCore.xcodeproj/project.pbxproj:
Add new files.
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
Switch to using forEachUserStyleSheet on the UserContentProvider.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::loadResource):
Remove null check now that we always have a UserContentProvider.
* loader/EmptyClients.cpp:
(WebCore::fillWithEmptyClients):
* loader/EmptyClients.h:
Add new EmptyClients.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadResourceSynchronously):
Remove null check now that we always have a UserContentProvider.
* loader/PingLoader.cpp:
(WebCore::processContentExtensionRulesForLoad):
Remove null check now that we always have a UserContentProvider.
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal):
Remove null check now that we always have a UserContentProvider.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Remove null check now that we always have a UserContentProvider.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
Remove null checks now that we always have a UserContentProvider, and userMessageHandlerDescriptors
returns a reference.
(WebCore::DOMWindow::open):
Remove null check now that we always have a UserContentProvider.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
Simplify by lifting document check out of the main loop and using forEachUserScript.
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::userContentProvider):
(WebCore::Page::setUserContentProvider):
(WebCore::Page::setUserContentController): Deleted.
* page/Page.h:
(WebCore::Page::userContentController): Deleted.
* page/PageConfiguration.h:
Store the UserContentProvider in a Ref, and require PageConfigurations to provide one. This
removes a bunch of null checks and simplifies the code.
* page/UserContentController.cpp:
(WebCore::UserContentController::~UserContentController):
(WebCore::UserContentController::forEachUserScript):
(WebCore::UserContentController::forEachUserStyleSheet):
(WebCore::UserContentController::addUserScript):
(WebCore::UserContentController::removeUserScript):
(WebCore::UserContentController::removeUserScripts):
(WebCore::UserContentController::addUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheets):
(WebCore::UserContentController::addUserMessageHandlerDescriptor):
(WebCore::UserContentController::removeUserMessageHandlerDescriptor):
(WebCore::UserContentController::addUserContentExtension):
(WebCore::UserContentController::removeUserContentExtension):
(WebCore::UserContentController::removeAllUserContentExtensions):
(WebCore::UserContentController::removeAllUserContent):
(WebCore::UserContentController::addPage): Deleted.
(WebCore::UserContentController::removePage): Deleted.
(WebCore::contentExtensionsEnabled): Deleted.
(WebCore::UserContentController::processContentExtensionRulesForLoad): Deleted.
(WebCore::UserContentController::actionsForResourceLoad): Deleted.
* page/UserContentController.h:
(WebCore::UserContentController::userScripts): Deleted.
(WebCore::UserContentController::userStyleSheets): Deleted.
(WebCore::UserContentController::userMessageHandlerDescriptors): Deleted.
Add inheritance from UserContentProvider and simplify things by removing unique_ptrs
that were holding the member variables. There is usually only one UserContentController
so having these in unique_ptrs doesn't make much sense.
* page/UserContentProvider.cpp: Added.
(WebCore::UserContentProvider::UserContentProvider):
(WebCore::UserContentProvider::~UserContentProvider):
(WebCore::UserContentProvider::addPage):
(WebCore::UserContentProvider::removePage):
(WebCore::UserContentProvider::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
(WebCore::contentExtensionsEnabled):
(WebCore::UserContentProvider::processContentExtensionRulesForLoad):
(WebCore::UserContentProvider::actionsForResourceLoad):
* page/UserContentProvider.h: Added.
Add abstract class for providing user content and add some helpers on it.
* page/UserMessageHandlerDescriptor.h:
(WebCore::UserMessageHandlerDescriptor::create):
(WebCore::UserMessageHandlerDescriptor::client):
(WebCore::UserMessageHandlerDescriptor::invalidateClient):
* page/UserMessageHandlersNamespace.cpp:
(WebCore::UserMessageHandlersNamespace::handler):
Simplify now that userContentProvider() and userMessageHandlerDescriptors() are references.
Source/WebKit/mac:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
(-[WebView setGroupName:]):
Update to account for the name change from UserContentController -> UserContentProvider.
Source/WebKit2:
- Moves to a model for user content where instead of using a WebCore::UserContentController
object, we implement the new WebCore::UserContentProvider interface (on the existing
WebUserContentController object).
- Uses this to maintain maps of UserStylesSheets and UserScripts along with their identifiers,
freeing up the URL, which had been acting as the identifier, to be used as the baseURL which
was what it was intended for.
- Adds a baseURL property to _WKUserStyleSheet.
* WebKit2.xcodeproj/project.pbxproj:
Add new files.
* Scripts/webkit/messages.py:
(headers_for_type):
Add support for sending WebUserContentControllerDataTypes.
* Shared/WebUserContentControllerDataTypes.cpp: Added.
(WebKit::WebUserScriptData::encode):
(WebKit::WebUserScriptData::decode):
(WebKit::WebUserStyleSheetData::encode):
(WebKit::WebUserStyleSheetData::decode):
* Shared/WebUserContentControllerDataTypes.h: Added.
Add helper types for sending user content over IPC.
* UIProcess/API/APIUserScript.cpp:
(API::UserScript::generateUniqueURL):
(API::UserScript::UserScript):
* UIProcess/API/APIUserScript.h:
* UIProcess/API/APIUserStyleSheet.cpp:
(API::UserStyleSheet::generateUniqueURL):
(API::UserStyleSheet::UserStyleSheet):
* UIProcess/API/APIUserStyleSheet.h:
Add identifiers for tracking across processes.
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forMainFrameOnly:legacyWhitelist:legacyBlacklist:baseURL:userContentWorld:]):
(-[_WKUserStyleSheet baseURL]):
Add new initializer which takes a baseURL as well as an accessor for the baseURL.
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserScript):
(WebKit::WebUserContentControllerProxy::removeUserScript):
(WebKit::WebUserContentControllerProxy::addUserStyleSheet):
(WebKit::WebUserContentControllerProxy::removeUserStyleSheet):
Pass identifiers as well as user content.
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::addUserScript):
(WebKit::InjectedBundle::addUserStyleSheet):
Move user content in via move semantics rather than using a unique_ptr.
(WebKit::InjectedBundle::removeUserScript):
(WebKit::InjectedBundle::removeUserStyleSheet):
(WebKit::InjectedBundle::removeUserScripts):
(WebKit::InjectedBundle::removeUserStyleSheets):
(WebKit::InjectedBundle::removeAllUserContent):
Update for new function signatures.
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::WebUserContentController):
(WebKit::WebUserContentController::~WebUserContentController):
(WebKit::WebUserContentController::addUserContentWorlds):
(WebKit::WebUserContentController::removeUserContentWorlds):
(WebKit::WebUserContentController::addUserScripts):
(WebKit::WebUserContentController::removeUserScript):
(WebKit::WebUserContentController::removeAllUserScripts):
(WebKit::WebUserContentController::addUserStyleSheets):
(WebKit::WebUserContentController::removeUserStyleSheet):
(WebKit::WebUserContentController::removeAllUserStyleSheets):
(WebKit::WebUserContentController::addUserScriptMessageHandlers):
(WebKit::WebUserContentController::removeUserScriptMessageHandler):
(WebKit::WebUserContentController::addUserContentExtensions):
(WebKit::WebUserContentController::removeUserContentExtension):
(WebKit::WebUserContentController::removeAllUserContentExtensions):
(WebKit::WebUserContentController::addUserScriptInternal):
(WebKit::WebUserContentController::addUserScript):
(WebKit::WebUserContentController::removeUserScriptWithURL):
(WebKit::WebUserContentController::removeUserScriptInternal):
(WebKit::WebUserContentController::removeUserScripts):
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::addUserStyleSheet):
(WebKit::WebUserContentController::removeUserStyleSheetWithURL):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheets):
(WebKit::WebUserContentController::removeAllUserContent):
(WebKit::WebUserContentController::forEachUserScript):
(WebKit::WebUserContentController::forEachUserStyleSheet):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:
Convert to inheriting from UserContentProvider, rather than containing a UserContentController.
This means adding the storage for the user content, which has been simplified to avoid using
unique_ptrs.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addUserScript):
(WebKit::WebPage::addUserStyleSheet):
(WebKit::WebPage::removeAllUserContent):
Update to call the WebUserContentController, rather than going to the UserContentController, which
no longer exists.
* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::userContentController):
* WebProcess/WebPage/WebPageGroupProxy.h:
Return the WebUserContentController rather than old UserContentController.
Canonical link: https://commits.webkit.org/173593@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-15 00:48:40 +00:00
|
|
|
});
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
void ExtensionStyleSheets::injectPageSpecificUserStyleSheet(const UserStyleSheet& userStyleSheet)
|
|
|
|
{
|
2020-05-15 00:33:37 +00:00
|
|
|
m_pageSpecificStyleSheets.append(userStyleSheet);
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
invalidateInjectedStyleSheetCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::removePageSpecificUserStyleSheet(const UserStyleSheet& userStyleSheet)
|
|
|
|
{
|
2020-05-15 00:33:37 +00:00
|
|
|
bool removedStyleSheet = m_pageSpecificStyleSheets.removeFirstMatching([&](const auto& styleSheet) {
|
|
|
|
return styleSheet.url() == userStyleSheet.url();
|
Add an SPI to allow UserStyleSheet injection to target a specific WKWebView
https://bugs.webkit.org/show_bug.cgi?id=208575
<rdar://problem/59773690>
Reviewed by Brady Eidson.
Source/WebCore:
Add a new Optional<PageIdentifier> member to UserStyleSheet which indicates whether the UserStyleSheet is supposed
to be injected for all WKWebViews, or only a specific top-level WKWebView associated with a Page with the give ID.
In ExtensionStyleSheets::updateInjectedStyleSheetCache(), UserStyleSheets with a specified pageID are ignored. Instead,
we now also consider CSSStyleSheets listed in the new m_pageSpecificStyleSheets which contains page-specific stylesheets
to be injected for the associated Document.
The new Page::injectUserStyleSheet() method allows the addition of a UserStyleSheet on its documents' ExtensionStyleSheets,
and will call this method either for the main frame's Document, or all Documents, depending on the UserStyleSheet's configuration.
Finally, these new targeted UserStyleSheets can be removed via Page::removeInjectedUserStyleSheet() and
ExtensionStyleSheets::removePageSpecificUserStyleSheet().
* dom/ExtensionStyleSheets.cpp:
(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache const):
(WebCore::ExtensionStyleSheets::injectPageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::removePageSpecificUserStyleSheet):
(WebCore::ExtensionStyleSheets::detachFromDocument):
* dom/ExtensionStyleSheets.h:
* page/Page.cpp:
(WebCore::Page::injectUserStyleSheet):
(WebCore::Page::removeInjectedUserStyleSheet):
* page/Page.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::pageID const):
Source/WebKit:
Since WebCore adds a new Optional<PageIdentifier> member to UserStyleSheet, we now encode that member to be preserved
across UI and Web processes.
Using this new member, WebUserContentController now determines that a UserStyleSheet meant to target a specific page
was added in addUserStyleSheetInternal(), finds the matching WebPage, and calls injectUserStyleSheet() on its backing Page
object. Conversely, WebUserContentController::removeUserStyleSheetInternal() will call into Page::removeInjectedUserStyleSheet().
Finally, we offer a new initializer on _WKUserStyleSheet to target a specific WKWebView, and its page's ID will be set on the
backing UserStyleSheet.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<UserStyleSheet>::encode):
(IPC::ArgumentCoder<UserStyleSheet>::decode):
* UIProcess/API/Cocoa/_WKUserStyleSheet.h:
* UIProcess/API/Cocoa/_WKUserStyleSheet.mm:
(-[_WKUserStyleSheet initWithSource:forWKWebView:forMainFrameOnly:userContentWorld:]):
* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::addUserStyleSheetInternal):
(WebKit::WebUserContentController::removeUserStyleSheetInternal):
Tools:
Add new tests for the new SPI which check:
1. that specifying forWKWebView: when initializing a _WKUserStyleSheet will inject the provided CSS source in the
specified WKWebView alone,
2. that the same test works with two WKWebViews with a shared WKWebKitConfiguration,
3. that a WKWebView-specific _WKUserStyleSheet can be removed,
4. that a WKWebView-specific _WKUserStyleSheet can be added twice and removed once and be removed as expected,
5. and that a WKWebView-specific _WKUserStyleSheet is automatically removed when navigating to a new page,
6. and that the same test also works with PSON enabled.
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
Canonical link: https://commits.webkit.org/221509@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-04 20:05:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (removedStyleSheet)
|
|
|
|
invalidateInjectedStyleSheetCache();
|
|
|
|
}
|
|
|
|
|
2015-09-23 15:04:16 +00:00
|
|
|
void ExtensionStyleSheets::invalidateInjectedStyleSheetCache()
|
|
|
|
{
|
|
|
|
m_injectedStyleSheetCacheValid = false;
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::addUserStyleSheet(Ref<StyleSheetContents>&& userSheet)
|
|
|
|
{
|
|
|
|
ASSERT(userSheet.get().isUserStyleSheet());
|
2016-09-05 16:58:48 +00:00
|
|
|
m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), m_document));
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::addAuthorStyleSheetForTesting(Ref<StyleSheetContents>&& authorSheet)
|
|
|
|
{
|
|
|
|
ASSERT(!authorSheet.get().isUserStyleSheet());
|
2016-09-05 16:58:48 +00:00
|
|
|
m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), m_document));
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE(CONTENT_EXTENSIONS)
|
|
|
|
void ExtensionStyleSheets::addDisplayNoneSelector(const String& identifier, const String& selector, uint32_t selectorID)
|
|
|
|
{
|
|
|
|
auto result = m_contentExtensionSelectorSheets.add(identifier, nullptr);
|
|
|
|
if (result.isNewEntry) {
|
|
|
|
result.iterator->value = ContentExtensionStyleSheet::create(m_document);
|
|
|
|
m_userStyleSheets.append(&result.iterator->value->styleSheet());
|
|
|
|
}
|
|
|
|
|
2016-01-15 03:31:52 +00:00
|
|
|
if (result.iterator->value->addDisplayNoneSelector(selector, selectorID))
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionStyleSheets::maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
|
|
|
|
{
|
|
|
|
ASSERT(sheet.isUserStyleSheet());
|
|
|
|
|
|
|
|
if (m_contentExtensionSheets.contains(identifier))
|
|
|
|
return;
|
|
|
|
|
2016-09-05 16:58:48 +00:00
|
|
|
Ref<CSSStyleSheet> cssSheet = CSSStyleSheet::create(sheet, m_document);
|
2015-09-23 15:04:16 +00:00
|
|
|
m_contentExtensionSheets.set(identifier, &cssSheet.get());
|
|
|
|
m_userStyleSheets.append(adoptRef(cssSheet.leakRef()));
|
2016-10-21 13:36:45 +00:00
|
|
|
m_document.styleScope().didChangeStyleSheetEnvironment();
|
2015-09-23 15:04:16 +00:00
|
|
|
|
|
|
|
}
|
2016-10-21 13:36:45 +00:00
|
|
|
#endif // ENABLE(CONTENT_EXTENSIONS)
|
2015-09-23 15:04:16 +00:00
|
|
|
|
2020-01-08 05:02:02 +00:00
|
|
|
String ExtensionStyleSheets::contentForInjectedStyleSheet(const RefPtr<CSSStyleSheet>& styleSheet) const
|
|
|
|
{
|
|
|
|
return m_injectedStyleSheetToSource.get(styleSheet);
|
|
|
|
}
|
|
|
|
|
2015-09-23 15:04:16 +00:00
|
|
|
void ExtensionStyleSheets::detachFromDocument()
|
|
|
|
{
|
|
|
|
if (m_pageUserSheet)
|
|
|
|
m_pageUserSheet->detachFromDocument();
|
|
|
|
for (auto& sheet : m_injectedUserStyleSheets)
|
|
|
|
sheet->detachFromDocument();
|
|
|
|
for (auto& sheet : m_injectedAuthorStyleSheets)
|
|
|
|
sheet->detachFromDocument();
|
|
|
|
for (auto& sheet : m_userStyleSheets)
|
|
|
|
sheet->detachFromDocument();
|
|
|
|
for (auto& sheet : m_authorStyleSheetsForTesting)
|
|
|
|
sheet->detachFromDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|