diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/UserContentController.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/page/UserContentController.cpp')
-rw-r--r-- | Source/WebCore/page/UserContentController.cpp | 109 |
1 files changed, 46 insertions, 63 deletions
diff --git a/Source/WebCore/page/UserContentController.cpp b/Source/WebCore/page/UserContentController.cpp index 95fa5fdfd..bcdac0b2c 100644 --- a/Source/WebCore/page/UserContentController.cpp +++ b/Source/WebCore/page/UserContentController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Apple Inc. All rights reserved. + * Copyright (C) 2014-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,17 +27,21 @@ #include "UserContentController.h" #include "DOMWrapperWorld.h" -#include "Document.h" -#include "MainFrame.h" -#include "Page.h" #include "UserScript.h" #include "UserStyleSheet.h" +#include <heap/HeapInlines.h> +#include <runtime/JSCellInlines.h> +#include <runtime/StructureInlines.h> + +#if ENABLE(CONTENT_EXTENSIONS) +#include "CompiledContentExtension.h" +#endif namespace WebCore { -RefPtr<UserContentController> UserContentController::create() +Ref<UserContentController> UserContentController::create() { - return adoptRef(new UserContentController); + return adoptRef(*new UserContentController); } UserContentController::UserContentController() @@ -48,36 +52,39 @@ UserContentController::~UserContentController() { } -void UserContentController::addPage(Page& page) +void UserContentController::forEachUserScript(const std::function<void(DOMWrapperWorld&, const UserScript&)>& functor) const { - ASSERT(!m_pages.contains(&page)); - m_pages.add(&page); + for (const auto& worldAndUserScriptVector : m_userScripts) { + auto& world = *worldAndUserScriptVector.key.get(); + for (const auto& userScript : *worldAndUserScriptVector.value) + functor(world, *userScript); + } } -void UserContentController::removePage(Page& page) +void UserContentController::forEachUserStyleSheet(const std::function<void(const UserStyleSheet&)>& functor) const { - ASSERT(m_pages.contains(&page)); - m_pages.remove(&page); + for (auto& styleSheetVector : m_userStyleSheets.values()) { + for (const auto& styleSheet : *styleSheetVector) + functor(*styleSheet); + } } -void UserContentController::addUserScript(DOMWrapperWorld& world, std::unique_ptr<UserScript> userScript) +#if ENABLE(USER_MESSAGE_HANDLERS) +void UserContentController::forEachUserMessageHandler(const std::function<void(const UserMessageHandlerDescriptor&)>&) const { - if (!m_userScripts) - m_userScripts = std::make_unique<UserScriptMap>(); +} +#endif - auto& scriptsInWorld = m_userScripts->add(&world, nullptr).iterator->value; - if (!scriptsInWorld) - scriptsInWorld = std::make_unique<UserScriptVector>(); - scriptsInWorld->append(std::move(userScript)); +void UserContentController::addUserScript(DOMWrapperWorld& world, std::unique_ptr<UserScript> userScript) +{ + auto& scriptsInWorld = m_userScripts.ensure(&world, [&] { return std::make_unique<UserScriptVector>(); }).iterator->value; + scriptsInWorld->append(WTFMove(userScript)); } void UserContentController::removeUserScript(DOMWrapperWorld& world, const URL& url) { - if (!m_userScripts) - return; - - auto it = m_userScripts->find(&world); - if (it == m_userScripts->end()) + auto it = m_userScripts.find(&world); + if (it == m_userScripts.end()) return; auto scripts = it->value.get(); @@ -87,38 +94,27 @@ void UserContentController::removeUserScript(DOMWrapperWorld& world, const URL& } if (scripts->isEmpty()) - m_userScripts->remove(it); + m_userScripts.remove(it); } void UserContentController::removeUserScripts(DOMWrapperWorld& world) { - if (!m_userScripts) - return; - - m_userScripts->remove(&world); + m_userScripts.remove(&world); } void UserContentController::addUserStyleSheet(DOMWrapperWorld& world, std::unique_ptr<UserStyleSheet> userStyleSheet, UserStyleInjectionTime injectionTime) { - if (!m_userStyleSheets) - m_userStyleSheets = std::make_unique<UserStyleSheetMap>(); - - auto& styleSheetsInWorld = m_userStyleSheets->add(&world, nullptr).iterator->value; - if (!styleSheetsInWorld) - styleSheetsInWorld = std::make_unique<UserStyleSheetVector>(); - styleSheetsInWorld->append(std::move(userStyleSheet)); + auto& styleSheetsInWorld = m_userStyleSheets.ensure(&world, [&] { return std::make_unique<UserStyleSheetVector>(); }).iterator->value; + styleSheetsInWorld->append(WTFMove(userStyleSheet)); if (injectionTime == InjectInExistingDocuments) - invalidateInjectedStyleSheetCacheInAllFrames(); + invalidateInjectedStyleSheetCacheInAllFramesInAllPages(); } void UserContentController::removeUserStyleSheet(DOMWrapperWorld& world, const URL& url) { - if (!m_userStyleSheets) - return; - - auto it = m_userStyleSheets->find(&world); - if (it == m_userStyleSheets->end()) + auto it = m_userStyleSheets.find(&world); + if (it == m_userStyleSheets.end()) return; auto& stylesheets = *it->value; @@ -135,39 +131,26 @@ void UserContentController::removeUserStyleSheet(DOMWrapperWorld& world, const U return; if (stylesheets.isEmpty()) - m_userStyleSheets->remove(it); + m_userStyleSheets.remove(it); - invalidateInjectedStyleSheetCacheInAllFrames(); + invalidateInjectedStyleSheetCacheInAllFramesInAllPages(); } void UserContentController::removeUserStyleSheets(DOMWrapperWorld& world) { - if (!m_userStyleSheets) - return; - - if (!m_userStyleSheets->remove(&world)) + if (!m_userStyleSheets.remove(&world)) return; - invalidateInjectedStyleSheetCacheInAllFrames(); + invalidateInjectedStyleSheetCacheInAllFramesInAllPages(); } void UserContentController::removeAllUserContent() { - m_userScripts = nullptr; + m_userScripts.clear(); - if (m_userStyleSheets) { - m_userStyleSheets = nullptr; - invalidateInjectedStyleSheetCacheInAllFrames(); - } -} - -void UserContentController::invalidateInjectedStyleSheetCacheInAllFrames() -{ - for (auto& page : m_pages) { - for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) { - frame->document()->styleSheetCollection().invalidateInjectedStyleSheetCache(); - frame->document()->styleResolverChanged(DeferRecalcStyle); - } + if (!m_userStyleSheets.isEmpty()) { + m_userStyleSheets.clear(); + invalidateInjectedStyleSheetCacheInAllFramesInAllPages(); } } |