diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/WebPageGroup.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/WebPageGroup.cpp | 101 |
1 files changed, 34 insertions, 67 deletions
diff --git a/Source/WebKit2/UIProcess/WebPageGroup.cpp b/Source/WebKit2/UIProcess/WebPageGroup.cpp index 59cc1ff5d..a04e0370a 100644 --- a/Source/WebKit2/UIProcess/WebPageGroup.cpp +++ b/Source/WebKit2/UIProcess/WebPageGroup.cpp @@ -27,9 +27,13 @@ #include "WebPageGroup.h" #include "APIArray.h" -#include "WebPageGroupProxyMessages.h" +#include "APIUserContentExtension.h" +#include "APIUserScript.h" +#include "APIUserStyleSheet.h" +#include "WebCompiledContentExtension.h" #include "WebPageProxy.h" #include "WebPreferences.h" +#include "WebUserContentControllerProxy.h" #include <wtf/HashMap.h> #include <wtf/NeverDestroyed.h> #include <wtf/text/StringConcatenate.h> @@ -55,7 +59,7 @@ PassRefPtr<WebPageGroup> WebPageGroup::create(const String& identifier, bool vis return adoptRef(new WebPageGroup(identifier, visibleToInjectedBundle, visibleToHistoryClient)); } -PassRef<WebPageGroup> WebPageGroup::createNonNull(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) +Ref<WebPageGroup> WebPageGroup::createNonNull(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) { return adoptRef(*new WebPageGroup(identifier, visibleToInjectedBundle, visibleToHistoryClient)); } @@ -65,25 +69,37 @@ WebPageGroup* WebPageGroup::get(uint64_t pageGroupID) return webPageGroupMap().get(pageGroupID); } -WebPageGroup::WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) +static WebPageGroupData pageGroupData(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) { - m_data.pageGroupID = generatePageGroupID(); + WebPageGroupData data; + + data.pageGroupID = generatePageGroupID(); if (!identifier.isEmpty()) - m_data.identifer = identifier; + data.identifier = identifier; else - m_data.identifer = m_data.identifer = makeString("__uniquePageGroupID-", String::number(m_data.pageGroupID)); + data.identifier = makeString("__uniquePageGroupID-", String::number(data.pageGroupID)); + + data.visibleToInjectedBundle = visibleToInjectedBundle; + data.visibleToHistoryClient = visibleToHistoryClient; + + return data; +} + +// FIXME: Why does the WebPreferences object here use ".WebKit2" instead of "WebKit2." which all the other constructors use. +// If it turns out that it's wrong, we can change it to to "WebKit2." and get rid of the globalDebugKeyPrefix from WebPreferences. +WebPageGroup::WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient) + : m_data(pageGroupData(identifier, visibleToInjectedBundle, visibleToHistoryClient)) + , m_preferences(WebPreferences::createWithLegacyDefaults(m_data.identifier, ".WebKit2", "WebKit2.")) + , m_userContentController(WebUserContentControllerProxy::create()) +{ + m_data.userContentControllerIdentifier = m_userContentController->identifier(); - m_data.visibleToInjectedBundle = visibleToInjectedBundle; - m_data.visibleToHistoryClient = visibleToHistoryClient; - webPageGroupMap().set(m_data.pageGroupID, this); } WebPageGroup::~WebPageGroup() { - if (m_preferences) - m_preferences->removePageGroup(this); webPageGroupMap().remove(pageGroupID()); } @@ -102,28 +118,15 @@ void WebPageGroup::setPreferences(WebPreferences* preferences) if (preferences == m_preferences) return; - if (!m_preferences) { - m_preferences = preferences; - m_preferences->addPageGroup(this); - } else { - m_preferences->removePageGroup(this); - m_preferences = preferences; - m_preferences->addPageGroup(this); + m_preferences = preferences; - preferencesDidChange(); - } + for (auto& webPageProxy : m_pages) + webPageProxy->setPreferences(*m_preferences); } -WebPreferences* WebPageGroup::preferences() const +WebPreferences& WebPageGroup::preferences() const { - if (!m_preferences) { - if (!m_data.identifer.isNull()) - m_preferences = WebPreferences::create(m_data.identifer); - else - m_preferences = WebPreferences::create(); - m_preferences->addPageGroup(const_cast<WebPageGroup*>(this)); - } - return m_preferences.get(); + return *m_preferences; } void WebPageGroup::preferencesDidChange() @@ -134,45 +137,9 @@ void WebPageGroup::preferencesDidChange() } } -void WebPageGroup::addUserStyleSheet(const String& source, const String& baseURL, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames injectedFrames, WebCore::UserStyleLevel level) -{ - if (source.isEmpty()) - return; - - WebCore::UserStyleSheet userStyleSheet = WebCore::UserStyleSheet(source, (baseURL.isEmpty() ? WebCore::blankURL() : WebCore::URL(WebCore::URL(), baseURL)), whitelist ? whitelist->toStringVector() : Vector<String>(), blacklist ? blacklist->toStringVector() : Vector<String>(), injectedFrames, level); - - m_data.userStyleSheets.append(userStyleSheet); - sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserStyleSheet(userStyleSheet), m_data.pageGroupID); -} - -void WebPageGroup::addUserScript(const String& source, const String& baseURL, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames injectedFrames, WebCore::UserScriptInjectionTime injectionTime) -{ - if (source.isEmpty()) - return; - - WebCore::UserScript userScript = WebCore::UserScript(source, (baseURL.isEmpty() ? WebCore::blankURL() : WebCore::URL(WebCore::URL(), baseURL)), whitelist ? whitelist->toStringVector() : Vector<String>(), blacklist ? blacklist->toStringVector() : Vector<String>(), injectionTime, injectedFrames); - - m_data.userScripts.append(userScript); - sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserScript(userScript), m_data.pageGroupID); -} - -void WebPageGroup::removeAllUserStyleSheets() -{ - m_data.userStyleSheets.clear(); - sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserStyleSheets(), m_data.pageGroupID); -} - -void WebPageGroup::removeAllUserScripts() -{ - m_data.userScripts.clear(); - sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserScripts(), m_data.pageGroupID); -} - -void WebPageGroup::removeAllUserContent() +WebUserContentControllerProxy& WebPageGroup::userContentController() { - m_data.userStyleSheets.clear(); - m_data.userScripts.clear(); - sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserContent(), m_data.pageGroupID); + return *m_userContentController; } } // namespace WebKit |