<!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
&lt;rdar://problem/15861296&gt;

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  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        UserContentController should keep track of user scripts
+        https://bugs.webkit.org/show_bug.cgi?id=127317
+        &lt;rdar://problem/15861296&gt;
+
+        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  &lt;andersca@apple.com&gt;
+
</ins><span class="cx">         Give each page a UserContentController
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=127315
</span><ins>+        &lt;rdar://problem/15861296&gt;
</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 &quot;TextIterator.h&quot;
</span><span class="cx"> #include &quot;TextNodeTraversal.h&quot;
</span><span class="cx"> #include &quot;TextResourceDecoder.h&quot;
</span><ins>+#include &quot;UserContentController.h&quot;
</ins><span class="cx"> #include &quot;UserContentURLPattern.h&quot;
</span><span class="cx"> #include &quot;UserTypingGestureIndicator.h&quot;
</span><span class="cx"> #include &quot;VisibleUnits.h&quot;
</span><span class="lines">@@ -703,13 +704,17 @@
</span><span class="cx">     if (loader().stateMachine()-&gt;creatingInitialEmptyDocument() &amp;&amp; !settings().shouldInjectUserScriptsInInitialEmptyDocument())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    UserContentController* userContentController = m_page-&gt;userContentController();
+    if (!userContentController)
+        return;
+
</ins><span class="cx">     // Walk the hashtable. Inject by world.
</span><del>-    const UserScriptMap* userScripts = m_page-&gt;group().userScripts();
</del><ins>+    const UserScriptMap* userScripts = userContentController-&gt;userScripts();
</ins><span class="cx">     if (!userScripts)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    for (auto it = userScripts-&gt;begin(), end = userScripts-&gt;end(); it != end; ++it)
-        injectUserScriptsForWorld(*it-&gt;key.get(), *it-&gt;value, injectionTime);
</del><ins>+    for (const auto&amp; worldAndUserScript : *userScripts)
+        injectUserScriptsForWorld(*worldAndUserScript.key, *worldAndUserScript.value, injectionTime);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Frame::injectUserScriptsForWorld(DOMWrapperWorld&amp; world, const UserScriptVector&amp; 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&amp; 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&lt;GroupSettings&gt;())
</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&amp; world, const String&amp; source, const URL&amp; url, const Vector&lt;String&gt;&amp; whitelist, const Vector&lt;String&gt;&amp; blacklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
</span><span class="cx"> {
</span><span class="cx">     auto userScript = std::make_unique&lt;UserScript&gt;(source, url, whitelist, blacklist, injectionTime, injectedFrames);
</span><del>-    if (!m_userScripts)
-        m_userScripts = std::make_unique&lt;UserScriptMap&gt;();
-    std::unique_ptr&lt;UserScriptVector&gt;&amp; scriptsInWorld = m_userScripts-&gt;add(&amp;world, nullptr).iterator-&gt;value;
-    if (!scriptsInWorld)
-        scriptsInWorld = std::make_unique&lt;UserScriptVector&gt;();
-    scriptsInWorld-&gt;append(std::move(userScript));
</del><ins>+    m_userContentController-&gt;addUserScript(world, std::move(userScript));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld&amp; world, const String&amp; source, const URL&amp; url, const Vector&lt;String&gt;&amp; whitelist, const Vector&lt;String&gt;&amp; 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&amp; world, const URL&amp; url)
</span><span class="cx"> {
</span><del>-    if (!m_userScripts)
-        return;
-
-    auto it = m_userScripts-&gt;find(&amp;world);
-    if (it == m_userScripts-&gt;end())
-        return;
-    
-    auto scripts = it-&gt;value.get();
-    for (int i = scripts-&gt;size() - 1; i &gt;= 0; --i) {
-        if (scripts-&gt;at(i)-&gt;url() == url)
-            scripts-&gt;remove(i);
-    }
-    
-    if (scripts-&gt;isEmpty())
-        m_userScripts-&gt;remove(it);
</del><ins>+    m_userContentController-&gt;removeUserScript(world, url);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PageGroup::removeUserStyleSheetFromWorld(DOMWrapperWorld&amp; world, const URL&amp; url)
</span><span class="lines">@@ -349,10 +331,7 @@
</span><span class="cx"> 
</span><span class="cx"> void PageGroup::removeUserScriptsFromWorld(DOMWrapperWorld&amp; world)
</span><span class="cx"> {
</span><del>-    if (!m_userScripts)
-        return;
-
-    m_userScripts-&gt;remove(&amp;world);
</del><ins>+    m_userContentController-&gt;removeUserScripts(world);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PageGroup::removeUserStyleSheetsFromWorld(DOMWrapperWorld&amp; 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-&gt;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&amp;, const String&amp; source, const URL&amp;, const Vector&lt;String&gt;&amp; whitelist, const Vector&lt;String&gt;&amp; blacklist, UserScriptInjectionTime, UserContentInjectedFrames);
</span><span class="cx">         void addUserStyleSheetToWorld(DOMWrapperWorld&amp;, const String&amp; source, const URL&amp;, const Vector&lt;String&gt;&amp; whitelist, const Vector&lt;String&gt;&amp; blacklist, UserContentInjectedFrames, UserStyleLevel = UserStyleUserLevel, UserStyleInjectionTime = InjectInExistingDocuments);
</span><del>-        void removeUserScriptFromWorld(DOMWrapperWorld&amp;, const URL&amp;);
</del><span class="cx">         void removeUserStyleSheetFromWorld(DOMWrapperWorld&amp;, const URL&amp;);
</span><ins>+        void removeUserScriptFromWorld(DOMWrapperWorld&amp;, const URL&amp;);
</ins><span class="cx">         void removeUserScriptsFromWorld(DOMWrapperWorld&amp;);
</span><span class="cx">         void removeUserStyleSheetsFromWorld(DOMWrapperWorld&amp;);
</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&amp; groupSettings() const { return *m_groupSettings; }
</span><span class="lines">@@ -125,7 +124,6 @@
</span><span class="cx">         HashMap&lt;RefPtr&lt;SecurityOrigin&gt;, RefPtr&lt;StorageNamespace&gt;&gt; m_transientLocalStorageMap;
</span><span class="cx"> 
</span><span class="cx">         RefPtr&lt;UserContentController&gt; m_userContentController;
</span><del>-        std::unique_ptr&lt;UserScriptMap&gt; m_userScripts;
</del><span class="cx">         std::unique_ptr&lt;UserStyleSheetMap&gt; m_userStyleSheets;
</span><span class="cx"> 
</span><span class="cx">         const std::unique_ptr&lt;GroupSettings&gt; 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(&amp;page);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void UserContentController::addUserScript(DOMWrapperWorld&amp; world, std::unique_ptr&lt;UserScript&gt; userScript)
+{
+    if (!m_userScripts)
+        m_userScripts = std::make_unique&lt;UserScriptMap&gt;();
+
+    auto&amp; scriptsInWorld = m_userScripts-&gt;add(&amp;world, nullptr).iterator-&gt;value;
+    if (!scriptsInWorld)
+        scriptsInWorld = std::make_unique&lt;UserScriptVector&gt;();
+    scriptsInWorld-&gt;append(std::move(userScript));
+}
+
+void UserContentController::removeUserScript(DOMWrapperWorld&amp; world, const URL&amp; url)
+{
+    if (!m_userScripts)
+        return;
+
+    auto it = m_userScripts-&gt;find(&amp;world);
+    if (it == m_userScripts-&gt;end())
+        return;
+
+    auto scripts = it-&gt;value.get();
+    for (int i = scripts-&gt;size() - 1; i &gt;= 0; --i) {
+        if (scripts-&gt;at(i)-&gt;url() == url)
+            scripts-&gt;remove(i);
+    }
+
+    if (scripts-&gt;isEmpty())
+        m_userScripts-&gt;remove(it);
+}
+
+void UserContentController::removeUserScripts(DOMWrapperWorld&amp; world)
+{
+    if (!m_userScripts)
+        return;
+
+    m_userScripts-&gt;remove(&amp;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 &lt;wtf/HashMap.h&gt;
</del><ins>+#include &quot;UserScriptTypes.h&quot;
</ins><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><del>-#include &lt;wtf/Vector.h&gt;
</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&amp;);
</span><span class="cx">     void removePage(Page&amp;);
</span><span class="cx"> 
</span><ins>+    const UserScriptMap* userScripts() const { return m_userScripts.get(); }
+
+    void addUserScript(DOMWrapperWorld&amp;, std::unique_ptr&lt;UserScript&gt;);
+    void removeUserScript(DOMWrapperWorld&amp;, const URL&amp;);
+    void removeUserScripts(DOMWrapperWorld&amp;);
+
+    void removeAllUserContent();
+
</ins><span class="cx"> private:
</span><span class="cx">     UserContentController();
</span><span class="cx"> 
</span><span class="cx">     HashSet&lt;Page*&gt; m_pages;
</span><ins>+
+    std::unique_ptr&lt;UserScriptMap&gt; m_userScripts;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>

</body>
</html>