<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[162384] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/162384">162384</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-01-20 16:08:55 -0800 (Mon, 20 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>UserContentController should keep track of user scripts
https://bugs.webkit.org/show_bug.cgi?id=127317
<rdar://problem/15861296>
Reviewed by Andreas Kling.
Move handling of user scripts from PageGroup to UserContentController.
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::removeUserScriptFromWorld):
(WebCore::PageGroup::removeUserScriptsFromWorld):
(WebCore::PageGroup::removeAllUserContent):
* page/PageGroup.h:
* page/UserContentController.cpp:
(WebCore::UserContentController::addUserScript):
(WebCore::UserContentController::removeUserScript):
(WebCore::UserContentController::removeUserScripts):
(WebCore::UserContentController::removeAllUserContent):
* page/UserContentController.h:
(WebCore::UserContentController::userScripts):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageFramecpp">trunk/Source/WebCore/page/Frame.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageGroupcpp">trunk/Source/WebCore/page/PageGroup.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageGrouph">trunk/Source/WebCore/page/PageGroup.h</a></li>
<li><a href="#trunkSourceWebCorepageUserContentControllercpp">trunk/Source/WebCore/page/UserContentController.cpp</a></li>
<li><a href="#trunkSourceWebCorepageUserContentControllerh">trunk/Source/WebCore/page/UserContentController.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/ChangeLog        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -1,7 +1,34 @@
</span><span class="cx"> 2014-01-20 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><ins>+ UserContentController should keep track of user scripts
+ https://bugs.webkit.org/show_bug.cgi?id=127317
+ <rdar://problem/15861296>
+
+ Reviewed by Andreas Kling.
+
+ Move handling of user scripts from PageGroup to UserContentController.
+
+ * page/Frame.cpp:
+ (WebCore::Frame::injectUserScripts):
+ * page/PageGroup.cpp:
+ (WebCore::PageGroup::addUserScriptToWorld):
+ (WebCore::PageGroup::removeUserScriptFromWorld):
+ (WebCore::PageGroup::removeUserScriptsFromWorld):
+ (WebCore::PageGroup::removeAllUserContent):
+ * page/PageGroup.h:
+ * page/UserContentController.cpp:
+ (WebCore::UserContentController::addUserScript):
+ (WebCore::UserContentController::removeUserScript):
+ (WebCore::UserContentController::removeUserScripts):
+ (WebCore::UserContentController::removeAllUserContent):
+ * page/UserContentController.h:
+ (WebCore::UserContentController::userScripts):
+
+2014-01-20 Anders Carlsson <andersca@apple.com>
+
</ins><span class="cx"> Give each page a UserContentController
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=127315
</span><ins>+ <rdar://problem/15861296>
</ins><span class="cx">
</span><span class="cx"> Reviewed by Andreas Kling.
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorepageFramecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Frame.cpp (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Frame.cpp        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/page/Frame.cpp        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -92,6 +92,7 @@
</span><span class="cx"> #include "TextIterator.h"
</span><span class="cx"> #include "TextNodeTraversal.h"
</span><span class="cx"> #include "TextResourceDecoder.h"
</span><ins>+#include "UserContentController.h"
</ins><span class="cx"> #include "UserContentURLPattern.h"
</span><span class="cx"> #include "UserTypingGestureIndicator.h"
</span><span class="cx"> #include "VisibleUnits.h"
</span><span class="lines">@@ -703,13 +704,17 @@
</span><span class="cx"> if (loader().stateMachine()->creatingInitialEmptyDocument() && !settings().shouldInjectUserScriptsInInitialEmptyDocument())
</span><span class="cx"> return;
</span><span class="cx">
</span><ins>+ UserContentController* userContentController = m_page->userContentController();
+ if (!userContentController)
+ return;
+
</ins><span class="cx"> // Walk the hashtable. Inject by world.
</span><del>- const UserScriptMap* userScripts = m_page->group().userScripts();
</del><ins>+ const UserScriptMap* userScripts = userContentController->userScripts();
</ins><span class="cx"> if (!userScripts)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- for (auto it = userScripts->begin(), end = userScripts->end(); it != end; ++it)
- injectUserScriptsForWorld(*it->key.get(), *it->value, injectionTime);
</del><ins>+ for (const auto& worldAndUserScript : *userScripts)
+ injectUserScriptsForWorld(*worldAndUserScript.key, *worldAndUserScript.value, injectionTime);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Frame::injectUserScriptsForWorld(DOMWrapperWorld& world, const UserScriptVector& userScripts, UserScriptInjectionTime injectionTime)
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageGroupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageGroup.cpp (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageGroup.cpp        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/page/PageGroup.cpp        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -73,6 +73,7 @@
</span><span class="cx"> PageGroup::PageGroup(Page& page)
</span><span class="cx"> : m_visitedLinksPopulated(false)
</span><span class="cx"> , m_identifier(getUniqueIdentifier())
</span><ins>+ , m_userContentController(UserContentController::create())
</ins><span class="cx"> , m_groupSettings(std::make_unique<GroupSettings>())
</span><span class="cx"> {
</span><span class="cx"> addPage(page);
</span><span class="lines">@@ -279,12 +280,7 @@
</span><span class="cx"> void PageGroup::addUserScriptToWorld(DOMWrapperWorld& world, const String& source, const URL& url, const Vector<String>& whitelist, const Vector<String>& blacklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
</span><span class="cx"> {
</span><span class="cx"> auto userScript = std::make_unique<UserScript>(source, url, whitelist, blacklist, injectionTime, injectedFrames);
</span><del>- if (!m_userScripts)
- m_userScripts = std::make_unique<UserScriptMap>();
- std::unique_ptr<UserScriptVector>& scriptsInWorld = m_userScripts->add(&world, nullptr).iterator->value;
- if (!scriptsInWorld)
- scriptsInWorld = std::make_unique<UserScriptVector>();
- scriptsInWorld->append(std::move(userScript));
</del><ins>+ m_userContentController->addUserScript(world, std::move(userScript));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld& world, const String& source, const URL& url, const Vector<String>& whitelist, const Vector<String>& blacklist, UserContentInjectedFrames injectedFrames, UserStyleLevel level, UserStyleInjectionTime injectionTime)
</span><span class="lines">@@ -303,21 +299,7 @@
</span><span class="cx">
</span><span class="cx"> void PageGroup::removeUserScriptFromWorld(DOMWrapperWorld& world, const URL& url)
</span><span class="cx"> {
</span><del>- if (!m_userScripts)
- return;
-
- auto it = m_userScripts->find(&world);
- if (it == m_userScripts->end())
- return;
-
- auto scripts = it->value.get();
- for (int i = scripts->size() - 1; i >= 0; --i) {
- if (scripts->at(i)->url() == url)
- scripts->remove(i);
- }
-
- if (scripts->isEmpty())
- m_userScripts->remove(it);
</del><ins>+ m_userContentController->removeUserScript(world, url);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PageGroup::removeUserStyleSheetFromWorld(DOMWrapperWorld& world, const URL& url)
</span><span class="lines">@@ -349,10 +331,7 @@
</span><span class="cx">
</span><span class="cx"> void PageGroup::removeUserScriptsFromWorld(DOMWrapperWorld& world)
</span><span class="cx"> {
</span><del>- if (!m_userScripts)
- return;
-
- m_userScripts->remove(&world);
</del><ins>+ m_userContentController->removeUserScripts(world);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PageGroup::removeUserStyleSheetsFromWorld(DOMWrapperWorld& world)
</span><span class="lines">@@ -368,7 +347,7 @@
</span><span class="cx">
</span><span class="cx"> void PageGroup::removeAllUserContent()
</span><span class="cx"> {
</span><del>- m_userScripts = nullptr;
</del><ins>+ m_userContentController->removeAllUserContent();
</ins><span class="cx">
</span><span class="cx"> if (m_userStyleSheets) {
</span><span class="cx"> m_userStyleSheets = nullptr;
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageGrouph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageGroup.h (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageGroup.h        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/page/PageGroup.h        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -94,13 +94,12 @@
</span><span class="cx">
</span><span class="cx"> void addUserScriptToWorld(DOMWrapperWorld&, const String& source, const URL&, const Vector<String>& whitelist, const Vector<String>& blacklist, UserScriptInjectionTime, UserContentInjectedFrames);
</span><span class="cx"> void addUserStyleSheetToWorld(DOMWrapperWorld&, const String& source, const URL&, const Vector<String>& whitelist, const Vector<String>& blacklist, UserContentInjectedFrames, UserStyleLevel = UserStyleUserLevel, UserStyleInjectionTime = InjectInExistingDocuments);
</span><del>- void removeUserScriptFromWorld(DOMWrapperWorld&, const URL&);
</del><span class="cx"> void removeUserStyleSheetFromWorld(DOMWrapperWorld&, const URL&);
</span><ins>+ void removeUserScriptFromWorld(DOMWrapperWorld&, const URL&);
</ins><span class="cx"> void removeUserScriptsFromWorld(DOMWrapperWorld&);
</span><span class="cx"> void removeUserStyleSheetsFromWorld(DOMWrapperWorld&);
</span><span class="cx"> void removeAllUserContent();
</span><span class="cx">
</span><del>- const UserScriptMap* userScripts() const { return m_userScripts.get(); }
</del><span class="cx"> const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
</span><span class="cx">
</span><span class="cx"> GroupSettings& groupSettings() const { return *m_groupSettings; }
</span><span class="lines">@@ -125,7 +124,6 @@
</span><span class="cx"> HashMap<RefPtr<SecurityOrigin>, RefPtr<StorageNamespace>> m_transientLocalStorageMap;
</span><span class="cx">
</span><span class="cx"> RefPtr<UserContentController> m_userContentController;
</span><del>- std::unique_ptr<UserScriptMap> m_userScripts;
</del><span class="cx"> std::unique_ptr<UserStyleSheetMap> m_userStyleSheets;
</span><span class="cx">
</span><span class="cx"> const std::unique_ptr<GroupSettings> m_groupSettings;
</span></span></pre></div>
<a id="trunkSourceWebCorepageUserContentControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/UserContentController.cpp (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/UserContentController.cpp        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/page/UserContentController.cpp        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -56,4 +56,47 @@
</span><span class="cx"> m_pages.remove(&page);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void UserContentController::addUserScript(DOMWrapperWorld& world, std::unique_ptr<UserScript> userScript)
+{
+ if (!m_userScripts)
+ m_userScripts = std::make_unique<UserScriptMap>();
+
+ auto& scriptsInWorld = m_userScripts->add(&world, nullptr).iterator->value;
+ if (!scriptsInWorld)
+ scriptsInWorld = std::make_unique<UserScriptVector>();
+ scriptsInWorld->append(std::move(userScript));
+}
+
+void UserContentController::removeUserScript(DOMWrapperWorld& world, const URL& url)
+{
+ if (!m_userScripts)
+ return;
+
+ auto it = m_userScripts->find(&world);
+ if (it == m_userScripts->end())
+ return;
+
+ auto scripts = it->value.get();
+ for (int i = scripts->size() - 1; i >= 0; --i) {
+ if (scripts->at(i)->url() == url)
+ scripts->remove(i);
+ }
+
+ if (scripts->isEmpty())
+ m_userScripts->remove(it);
+}
+
+void UserContentController::removeUserScripts(DOMWrapperWorld& world)
+{
+ if (!m_userScripts)
+ return;
+
+ m_userScripts->remove(&world);
+}
+
+void UserContentController::removeAllUserContent()
+{
+ m_userScripts = nullptr;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepageUserContentControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/UserContentController.h (162383 => 162384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/UserContentController.h        2014-01-20 23:42:23 UTC (rev 162383)
+++ trunk/Source/WebCore/page/UserContentController.h        2014-01-21 00:08:55 UTC (rev 162384)
</span><span class="lines">@@ -26,11 +26,10 @@
</span><span class="cx"> #ifndef UserContentController_h
</span><span class="cx"> #define UserContentController_h
</span><span class="cx">
</span><del>-#include <wtf/HashMap.h>
</del><ins>+#include "UserScriptTypes.h"
</ins><span class="cx"> #include <wtf/HashSet.h>
</span><span class="cx"> #include <wtf/RefCounted.h>
</span><span class="cx"> #include <wtf/RefPtr.h>
</span><del>-#include <wtf/Vector.h>
</del><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="lines">@@ -47,10 +46,20 @@
</span><span class="cx"> void addPage(Page&);
</span><span class="cx"> void removePage(Page&);
</span><span class="cx">
</span><ins>+ const UserScriptMap* userScripts() const { return m_userScripts.get(); }
+
+ void addUserScript(DOMWrapperWorld&, std::unique_ptr<UserScript>);
+ void removeUserScript(DOMWrapperWorld&, const URL&);
+ void removeUserScripts(DOMWrapperWorld&);
+
+ void removeAllUserContent();
+
</ins><span class="cx"> private:
</span><span class="cx"> UserContentController();
</span><span class="cx">
</span><span class="cx"> HashSet<Page*> m_pages;
</span><ins>+
+ std::unique_ptr<UserScriptMap> m_userScripts;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>
</body>
</html>