<!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>[193444] branches/safari-601.1.46-branch</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/193444">193444</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2015-12-04 12:52:32 -0800 (Fri, 04 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/189104">r189104</a>. rdar://problem/23581597</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601146branchLayoutTestsChangeLog">branches/safari-601.1.46-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcssstylesheeteventsinspectorstylesheetexpectedtxt">branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet-expected.txt</a></li>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcssstylesheeteventsinspectorstylesheethtml">branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet.html</a></li>
<li><a href="#branchessafari601146branchSourceJavaScriptCoreChangeLog">branches/safari-601.1.46-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceJavaScriptCoreinspectorprotocolCSSjson">branches/safari-601.1.46-branch/Source/JavaScriptCore/inspector/protocol/CSS.json</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreChangeLog">branches/safari-601.1.46-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreinspectorInspectorCSSAgentcpp">branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreinspectorInspectorCSSAgenth">branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreinspectorInspectorStyleSheetcpp">branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIChangeLog">branches/safari-601.1.46-branch/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIUserInterfaceBaseObjectjs">branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Base/Object.js</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs">branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsCSSStyleSheetjs">branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsDOMNodejs">branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNode.js</a></li>
<li><a href="#branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs">branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcsscreateStyleSheetexpectedtxt">branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet-expected.txt</a></li>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcsscreateStyleSheethtml">branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet.html</a></li>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcssmanagerpreferredInspectorStyleSheetForFrameexpectedtxt">branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame-expected.txt</a></li>
<li><a href="#branchessafari601146branchLayoutTestsinspectorcssmanagerpreferredInspectorStyleSheetForFramehtml">branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601146branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/LayoutTests/ChangeLog (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/ChangeLog        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/LayoutTests/ChangeLog        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r189104. rdar://problem/23581597
+
+    2015-08-28  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+            Web Inspector: Separate creating a style sheet from adding a new rule in the protocol
+            https://bugs.webkit.org/show_bug.cgi?id=148502
+
+            Reviewed by Timothy Hatcher.
+
+            * inspector/css/createStyleSheet-expected.txt: Added.
+            * inspector/css/createStyleSheet.html: Added.
+            * inspector/css/manager-preferredInspectorStyleSheetForFrame-expected.txt: Added.
+            * inspector/css/manager-preferredInspectorStyleSheetForFrame.html: Added.
+            * inspector/css/stylesheet-events-inspector-stylesheet-expected.txt:
+            * inspector/css/stylesheet-events-inspector-stylesheet.html:
+
+2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r189002. rdar://problem/23581597
</span><span class="cx"> 
</span><span class="cx">     2015-08-26  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcsscreateStyleSheetexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet-expected.txt (0 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet-expected.txt                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet-expected.txt        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+Test CSS.createStyleSheet.
+
+
+== Running test suite: CSS.createStyleSheet
+-- Running test case: CheckNoStyleSheets
+PASS: Should be no stylesheets.
+
+-- Running test case: CreateInspectorStyleSheetCall1
+PASS: Should increase the list of stylesheets.
+PASS: Added StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+PASS: Added StyleSheet frame should be the main frame.
+
+-- Running test case: CreateInspectorStyleSheetCall2
+PASS: Should increase the list of stylesheets.
+PASS: Added StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+PASS: Added StyleSheet frame should be the main frame.
+PASS: Added StyleSheet should be different from the last added stylesheet.
+
+-- Running test case: CreateInspectorStyleSheetCall3
+PASS: Should increase the list of stylesheets.
+PASS: Added StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+PASS: Added StyleSheet frame should be the main frame.
+PASS: Added StyleSheet should be different from the last added stylesheet.
+
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcsscreateStyleSheethtml"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet.html (0 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet.html                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/createStyleSheet.html        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -0,0 +1,53 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/inspector-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function test()
+{
+    let addedStyleSheet;
+    let mainFrame = WebInspector.frameResourceManager.mainFrame;
+
+    let suite = InspectorTest.createAsyncSuite(&quot;CSS.createStyleSheet&quot;);
+
+    suite.addTestCase({
+        name: &quot;CheckNoStyleSheets&quot;,
+        description: &quot;Ensure there are no stylesheets.&quot;,
+        test: (resolve, reject) =&gt; {
+            InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 0, &quot;Should be no stylesheets.&quot;);
+            resolve();
+        }
+    });
+
+    for (let i = 1; i &lt;= 3; ++i) {
+        suite.addTestCase({
+            name: &quot;CreateInspectorStyleSheetCall&quot; + i,
+            description: &quot;Should create a new inspector stylesheet.&quot;,
+            test: (resolve, reject) =&gt; {
+                CSSAgent.createStyleSheet(mainFrame.id);
+                WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
+                    InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === i, &quot;Should increase the list of stylesheets.&quot;);
+                    InspectorTest.expectThat(event.data.styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;Added StyleSheet origin should be 'inspector'.&quot;);
+                    InspectorTest.expectThat(event.data.styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                    InspectorTest.expectThat(event.data.styleSheet.parentFrame === mainFrame, &quot;Added StyleSheet frame should be the main frame.&quot;);
+                    if (addedStyleSheet)
+                        InspectorTest.expectThat(event.data.styleSheet !== addedStyleSheet, &quot;Added StyleSheet should be different from the last added stylesheet.&quot;);
+                    addedStyleSheet = event.data.styleSheet;
+                    resolve();
+                });
+            }
+        });
+    }
+
+    WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetRemoved, function(event) {
+        InspectorTest.assert(false, &quot;Should not be removing any StyleSheets in this test.&quot;);
+    });
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;p&gt;Test CSS.createStyleSheet.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcssmanagerpreferredInspectorStyleSheetForFrameexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame-expected.txt (0 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame-expected.txt                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame-expected.txt        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+Test CSSManager.preferredInspectorStyleSheetForFrame.
+
+
+
+== Running test suite: CSSManager.preferredInspectorStyleSheetForFrame
+-- Running test case: CheckNoStyleSheets
+PASS: Should be no stylesheets.
+
+-- Running test case: CreateMainFrameInspectorStyleSheet
+PASS: Added StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+PASS: Added StyleSheet frame should be the main frame.
+PASS: Should be one stylesheet.
+PASS: StyleSheet origin is inspector.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+
+-- Running test case: AnotherMainFrameRequestDoesNothing
+PASS: Should still be one stylesheet.
+PASS: StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+
+-- Running test case: CreateSubFrameInspectorStyleSheet
+PASS: Added StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+PASS: Added StyleSheet frame should be a child frame.
+PASS: Should be two stylesheets.
+PASS: StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+
+-- Running test case: AnotherSubFrameRequestDoesNothing
+PASS: Should be two stylesheets.
+PASS: StyleSheet origin should be 'inspector'.
+PASS: StyleSheet.isInspectorStyleSheet() should be true.
+
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcssmanagerpreferredInspectorStyleSheetForFramehtml"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame.html (0 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame.html                                (rev 0)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/manager-preferredInspectorStyleSheetForFrame.html        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/inspector-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function test()
+{
+    let mainFrame = WebInspector.frameResourceManager.mainFrame;
+    let childFrame = mainFrame.childFrames[0];
+
+    let suite = InspectorTest.createAsyncSuite(&quot;CSSManager.preferredInspectorStyleSheetForFrame&quot;);
+
+    suite.addTestCase({
+        name: &quot;CheckNoStyleSheets&quot;,
+        description: &quot;Ensure there are no stylesheets.&quot;,
+        test: (resolve, reject) =&gt; {
+            InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 0, &quot;Should be no stylesheets.&quot;);
+            resolve();
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;CreateMainFrameInspectorStyleSheet&quot;,
+        description: &quot;First request for main frame should create inspector stylesheet.&quot;,
+        test: (resolve, reject) =&gt; {
+            WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
+                InspectorTest.expectThat(event.data.styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;Added StyleSheet origin should be 'inspector'.&quot;);
+                InspectorTest.expectThat(event.data.styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                InspectorTest.expectThat(event.data.styleSheet.parentFrame === mainFrame, &quot;Added StyleSheet frame should be the main frame.&quot;);
+            });
+            WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(mainFrame, function(styleSheet) {
+                InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 1, &quot;Should be one stylesheet.&quot;);
+                InspectorTest.expectThat(styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin is inspector.&quot;);
+                InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;AnotherMainFrameRequestDoesNothing&quot;,
+        description: &quot;Second request for main frame should not create a new stylesheet.&quot;,
+        test: (resolve, reject) =&gt; {
+            let listener = WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
+                InspectorTest.assert(false, &quot;Should not create a new StyleSheet, should reuse the existing one&quot;);
+            });
+            WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(mainFrame, function(styleSheet) {
+                InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 1, &quot;Should still be one stylesheet.&quot;);
+                InspectorTest.expectThat(styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin should be 'inspector'.&quot;);
+                InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                WebInspector.cssStyleManager.removeEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, listener, null);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;CreateSubFrameInspectorStyleSheet&quot;,
+        description: &quot;First request for subframe should create inspector stylesheet.&quot;,
+        test: (resolve, reject) =&gt; {
+            WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
+                InspectorTest.expectThat(event.data.styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;Added StyleSheet origin should be 'inspector'.&quot;);
+                InspectorTest.expectThat(event.data.styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                InspectorTest.expectThat(event.data.styleSheet.parentFrame === childFrame, &quot;Added StyleSheet frame should be a child frame.&quot;);
+            });
+            WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(childFrame, function(styleSheet) {
+                InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 2, &quot;Should be two stylesheets.&quot;);
+                InspectorTest.expectThat(styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin should be 'inspector'.&quot;);
+                InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;AnotherSubFrameRequestDoesNothing&quot;,
+        description: &quot;Second request for main frame should not create a new stylesheet.&quot;,
+        test: (resolve, reject) =&gt; {
+            let listener = WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
+                InspectorTest.assert(false, &quot;Should not create a new StyleSheet, should reuse the existing one&quot;);
+            });
+            WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(childFrame, function(styleSheet) {
+                InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 2, &quot;Should be two stylesheets.&quot;);
+                InspectorTest.expectThat(styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin should be 'inspector'.&quot;);
+                InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), &quot;StyleSheet.isInspectorStyleSheet() should be true.&quot;);
+                WebInspector.cssStyleManager.removeEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, listener, null);
+                resolve();
+            });
+        }
+    });
+
+    WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetRemoved, function(event) {
+        InspectorTest.assert(false, &quot;Should not be removing any StyleSheets in this test.&quot;);
+    });
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    &lt;p&gt;Test CSSManager.preferredInspectorStyleSheetForFrame.&lt;/p&gt;
+    &lt;iframe src=&quot;about:blank&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcssstylesheeteventsinspectorstylesheetexpectedtxt"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet-expected.txt (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet-expected.txt        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet-expected.txt        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -7,5 +7,5 @@
</span><span class="cx"> 
</span><span class="cx"> -- Running test case: CreateInspectorStyleSheet
</span><span class="cx"> PASS: Should be one stylesheet.
</span><del>-PASS: StyleSheet origin is inspector.
</del><ins>+PASS: StyleSheet origin should be 'inspector'.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari601146branchLayoutTestsinspectorcssstylesheeteventsinspectorstylesheethtml"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet.html (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet.html        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/LayoutTests/inspector/css/stylesheet-events-inspector-stylesheet.html        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -7,8 +7,6 @@
</span><span class="cx"> {
</span><span class="cx">     let suite = InspectorTest.createAsyncSuite(&quot;CSS.StyleSheetEvents.InspectorStyleSheet&quot;);
</span><span class="cx"> 
</span><del>-    let bodyNodeId;
-
</del><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;CheckNoStyleSheets&quot;,
</span><span class="cx">         description: &quot;Ensure there are currently no stylesheets.&quot;,
</span><span class="lines">@@ -22,24 +20,17 @@
</span><span class="cx">         name: &quot;CreateInspectorStyleSheet&quot;,
</span><span class="cx">         description: &quot;Creating an inspector stylesheet adds a stylesheet.&quot;,
</span><span class="cx">         test: (resolve, reject) =&gt; {
</span><ins>+            CSSAgent.createStyleSheet(WebInspector.frameResourceManager.mainFrame.id);
</ins><span class="cx">             WebInspector.cssStyleManager.singleFireEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, function(event) {
</span><span class="cx">                 InspectorTest.expectThat(WebInspector.cssStyleManager.styleSheets.length === 1, &quot;Should be one stylesheet.&quot;);
</span><span class="cx">                 InspectorTest.assert(event.data.styleSheet instanceof WebInspector.CSSStyleSheet, &quot;Event data should be a CSSStyleSheet&quot;);
</span><del>-                InspectorTest.expectThat(event.data.styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin is inspector.&quot;);
</del><ins>+                InspectorTest.expectThat(event.data.styleSheet.origin === WebInspector.CSSStyleSheet.Type.Inspector, &quot;StyleSheet origin should be 'inspector'.&quot;);
</ins><span class="cx">                 resolve();
</span><span class="cx">             });
</span><del>-
-            // FIXME: Currently the only way to create an inspector stylesheet is through `CSS.addRule`.
-            CSSAgent.addRule(bodyNodeId, &quot;body&quot;);
</del><span class="cx">         }
</span><span class="cx">     });
</span><span class="cx"> 
</span><del>-    WebInspector.domTreeManager.requestDocument(function(documentNode) {
-        WebInspector.domTreeManager.querySelector(documentNode.id, &quot;body&quot;, function(contentNodeId) {
-            bodyNodeId = contentNodeId;
-            suite.runTestCasesAndFinish();
-        });
-    });
</del><ins>+    suite.runTestCasesAndFinish();
</ins><span class="cx"> }
</span><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;/head&gt;
</span></span></pre></div>
<a id="branchessafari601146branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/JavaScriptCore/ChangeLog (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/JavaScriptCore/ChangeLog        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/JavaScriptCore/ChangeLog        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -1,5 +1,19 @@
</span><span class="cx"> 2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r189104. rdar://problem/23581597
+
+    2015-08-28  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+            Web Inspector: Separate creating a style sheet from adding a new rule in the protocol
+            https://bugs.webkit.org/show_bug.cgi?id=148502
+
+            Reviewed by Timothy Hatcher.
+
+            * inspector/protocol/CSS.json:
+            Add CSS.createStyleSheet. Modify CSS.addRule.
+
+2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r189002. rdar://problem/23581597
</span><span class="cx"> 
</span><span class="cx">     2015-08-26  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchSourceJavaScriptCoreinspectorprotocolCSSjson"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/JavaScriptCore/inspector/protocol/CSS.json (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/JavaScriptCore/inspector/protocol/CSS.json        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/JavaScriptCore/inspector/protocol/CSS.json        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -333,15 +333,25 @@
</span><span class="cx">             &quot;description&quot;: &quot;Modifies the rule selector.&quot;
</span><span class="cx">         },
</span><span class="cx">         {
</span><ins>+            &quot;name&quot;: &quot;createStyleSheet&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;frameId&quot;, &quot;$ref&quot;: &quot;Network.FrameId&quot;, &quot;description&quot;: &quot;Identifier of the frame where the new \&quot;inspector\&quot; stylesheet should be created.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;styleSheetId&quot;, &quot;$ref&quot;: &quot;StyleSheetId&quot;, &quot;description&quot;: &quot;Identifier of the created \&quot;inspector\&quot; stylesheet.&quot; }
+            ],
+            &quot;description&quot;: &quot;Creates a new special \&quot;inspector\&quot; stylesheet in the frame with given &lt;code&gt;frameId&lt;/code&gt;.&quot;
+        },
+        {
</ins><span class="cx">             &quot;name&quot;: &quot;addRule&quot;,
</span><span class="cx">             &quot;parameters&quot;: [
</span><del>-                { &quot;name&quot;: &quot;contextNodeId&quot;, &quot;$ref&quot;: &quot;DOM.NodeId&quot; },
</del><ins>+                { &quot;name&quot;: &quot;styleSheetId&quot;, &quot;$ref&quot;: &quot;StyleSheetId&quot; },
</ins><span class="cx">                 { &quot;name&quot;: &quot;selector&quot;, &quot;type&quot;: &quot;string&quot; }
</span><span class="cx">             ],
</span><span class="cx">             &quot;returns&quot;: [
</span><span class="cx">                 { &quot;name&quot;: &quot;rule&quot;, &quot;$ref&quot;: &quot;CSSRule&quot;, &quot;description&quot;: &quot;The newly created rule.&quot; }
</span><span class="cx">             ],
</span><del>-            &quot;description&quot;: &quot;Creates a new empty rule with the given &lt;code&gt;selector&lt;/code&gt; in a special \&quot;inspector\&quot; stylesheet in the owner document of the context node.&quot;
</del><ins>+            &quot;description&quot;: &quot;Creates a new empty rule with the given &lt;code&gt;selector&lt;/code&gt; in a stylesheet with given &lt;code&gt;styleSheetId&lt;/code&gt;.&quot;
</ins><span class="cx">         },
</span><span class="cx">         {
</span><span class="cx">             &quot;name&quot;: &quot;getSupportedCSSProperties&quot;,
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -1,5 +1,39 @@
</span><span class="cx"> 2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r189104. rdar://problem/23581597
+
+    2015-08-28  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+            Web Inspector: Separate creating a style sheet from adding a new rule in the protocol
+            https://bugs.webkit.org/show_bug.cgi?id=148502
+
+            Reviewed by Timothy Hatcher.
+
+            Tests: inspector/css/createStyleSheet.html
+                   inspector/css/manager-preferredInspectorStyleSheetForFrame.html
+
+            * inspector/InspectorCSSAgent.h:
+            Allow for multiple inspector style sheets per document.
+
+            * inspector/InspectorCSSAgent.cpp:
+            (WebCore::InspectorCSSAgent::createStyleSheet):
+            (WebCore::InspectorCSSAgent::createInspectorStyleSheetForDocument): Added.
+            (WebCore::InspectorCSSAgent::viaInspectorStyleSheet): Deleted.
+            Extract and generalize creating a via-inspector stylesheet here.
+
+            (WebCore::InspectorCSSAgent::addRule):
+            Lookup stylesheet to add a rule to via the provided stylesheet id.
+
+            (WebCore::InspectorCSSAgent::bindStyleSheet):
+            (WebCore::InspectorCSSAgent::detectOrigin):
+            Update to account for a list of stylesheets per document instead of one.
+
+            * inspector/InspectorStyleSheet.cpp:
+            (WebCore::InspectorStyleSheet::addRule):
+            (WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
+
+2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r189002. rdar://problem/23581597
</span><span class="cx"> 
</span><span class="cx">     2015-08-26  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreinspectorInspectorCSSAgentcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.cpp (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.cpp        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.cpp        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> #include &quot;HTMLStyleElement.h&quot;
</span><span class="cx"> #include &quot;InspectorDOMAgent.h&quot;
</span><span class="cx"> #include &quot;InspectorHistory.h&quot;
</span><ins>+#include &quot;InspectorPageAgent.h&quot;
</ins><span class="cx"> #include &quot;InstrumentingAgents.h&quot;
</span><span class="cx"> #include &quot;NamedFlowCollection.h&quot;
</span><span class="cx"> #include &quot;Node.h&quot;
</span><span class="lines">@@ -747,14 +748,79 @@
</span><span class="cx">     errorString = InspectorDOMAgent::toErrorString(ec);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InspectorCSSAgent::addRule(ErrorString&amp; errorString, const int contextNodeId, const String&amp; selector, RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt;&amp; result)
</del><ins>+void InspectorCSSAgent::createStyleSheet(ErrorString&amp; errorString, const String&amp; frameId, String* styleSheetId)
</ins><span class="cx"> {
</span><del>-    Node* node = m_domAgent-&gt;assertNode(errorString, contextNodeId);
-    if (!node)
</del><ins>+    Frame* frame = m_domAgent-&gt;pageAgent()-&gt;frameForId(frameId);
+    if (!frame) {
+        errorString = ASCIILiteral(&quot;No frame for given id found&quot;);
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><del>-    InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(&amp;node-&gt;document(), true);
</del><ins>+    Document* document = frame-&gt;document();
+    if (!document) {
+        errorString = ASCIILiteral(&quot;No document for frame&quot;);
+        return;
+    }
+
+    InspectorStyleSheet* inspectorStyleSheet = createInspectorStyleSheetForDocument(*document);
</ins><span class="cx">     if (!inspectorStyleSheet) {
</span><ins>+        errorString = ASCIILiteral(&quot;Could not create stylesheet for the frame.&quot;);
+        return;
+    }
+
+    *styleSheetId = inspectorStyleSheet-&gt;id();
+}
+
+InspectorStyleSheet* InspectorCSSAgent::createInspectorStyleSheetForDocument(Document&amp; document)
+{
+    if (!document.isHTMLDocument() &amp;&amp; !document.isSVGDocument())
+        return nullptr;
+
+    ExceptionCode ec = 0;
+    RefPtr&lt;Element&gt; styleElement = document.createElement(&quot;style&quot;, ec);
+    if (ec)
+        return nullptr;
+
+    styleElement-&gt;setAttribute(&quot;type&quot;, &quot;text/css&quot;, ec);
+    if (ec)
+        return nullptr;
+
+    ContainerNode* targetNode;
+    // HEAD is absent in ImageDocuments, for example.
+    if (auto* head = document.head())
+        targetNode = head;
+    else if (auto* body = document.bodyOrFrameset())
+        targetNode = body;
+    else
+        return nullptr;
+
+    // Inserting this &lt;style&gt; into the document will trigger activeStyleSheetsUpdated
+    // and we will create an InspectorStyleSheet for this &lt;style&gt;'s CSSStyleSheet.
+    // Set this flag, so when we create it, we put it into the via inspector map.
+    m_creatingViaInspectorStyleSheet = true;
+    InlineStyleOverrideScope overrideScope(document);
+    targetNode-&gt;appendChild(styleElement, ec);
+    m_creatingViaInspectorStyleSheet = false;
+    if (ec)
+        return nullptr;
+
+    auto iterator = m_documentToInspectorStyleSheet.find(&amp;document);
+    ASSERT(iterator != m_documentToInspectorStyleSheet.end());
+    if (iterator == m_documentToInspectorStyleSheet.end())
+        return nullptr;
+
+    auto&amp; inspectorStyleSheetsForDocument = iterator-&gt;value;
+    ASSERT(!inspectorStyleSheetsForDocument.isEmpty());
+    if (inspectorStyleSheetsForDocument.isEmpty())
+        return nullptr;
+
+    return inspectorStyleSheetsForDocument.last().get();
+}
+
+void InspectorCSSAgent::addRule(ErrorString&amp; errorString, const String&amp; styleSheetId, const String&amp; selector, RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt;&amp; result)
+{
+    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
+    if (!inspectorStyleSheet) {
</ins><span class="cx">         errorString = ASCIILiteral(&quot;No target stylesheet found&quot;);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -905,59 +971,19 @@
</span><span class="cx">         inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent-&gt;pageAgent(), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document), this);
</span><span class="cx">         m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
</span><span class="cx">         m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet);
</span><del>-        if (m_creatingViaInspectorStyleSheet)
-            m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet);
</del><ins>+        if (m_creatingViaInspectorStyleSheet) {
+            auto&amp; inspectorStyleSheetsForDocument = m_documentToInspectorStyleSheet.add(document, Vector&lt;RefPtr&lt;InspectorStyleSheet&gt;&gt;()).iterator-&gt;value;
+            inspectorStyleSheetsForDocument.append(inspectorStyleSheet);
+        }
</ins><span class="cx">     }
</span><span class="cx">     return inspectorStyleSheet.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent)
-{
-    if (!document) {
-        ASSERT(!createIfAbsent);
-        return nullptr;
-    }
-
-    if (!document-&gt;isHTMLDocument() &amp;&amp; !document-&gt;isSVGDocument())
-        return nullptr;
-
-    RefPtr&lt;InspectorStyleSheet&gt; inspectorStyleSheet = m_documentToInspectorStyleSheet.get(document);
-    if (inspectorStyleSheet || !createIfAbsent)
-        return inspectorStyleSheet.get();
-
-    ExceptionCode ec = 0;
-    RefPtr&lt;Element&gt; styleElement = document-&gt;createElement(&quot;style&quot;, ec);
-    if (!ec)
-        styleElement-&gt;setAttribute(&quot;type&quot;, &quot;text/css&quot;, ec);
-    if (!ec) {
-        ContainerNode* targetNode;
-        // HEAD is absent in ImageDocuments, for example.
-        if (auto* head = document-&gt;head())
-            targetNode = head;
-        else if (auto* body = document-&gt;bodyOrFrameset())
-            targetNode = body;
-        else
-            return nullptr;
-
-        // Inserting this &lt;style&gt; into the document will trigger activeStyleSheetsUpdated
-        // and we will create an InspectorStyleSheet for this &lt;style&gt;'s CSSStyleSheet.
-        // Set this flag, so when we create it, we put it into the via inspector hash map.
-        m_creatingViaInspectorStyleSheet = true;
-        InlineStyleOverrideScope overrideScope(document);
-        targetNode-&gt;appendChild(styleElement, ec);
-        m_creatingViaInspectorStyleSheet = false;
-    }
-    if (ec)
-        return nullptr;
-
-    return m_documentToInspectorStyleSheet.get(document);
-}
-
</del><span class="cx"> InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString&amp; errorString, const String&amp; styleSheetId)
</span><span class="cx"> {
</span><span class="cx">     IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleSheetId);
</span><span class="cx">     if (it == m_idToInspectorStyleSheet.end()) {
</span><del>-        errorString = ASCIILiteral(&quot;No style sheet with given id found&quot;);
</del><ins>+        errorString = ASCIILiteral(&quot;No stylesheet with given id found&quot;);
</ins><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx">     return it-&gt;value.get();
</span><span class="lines">@@ -970,13 +996,17 @@
</span><span class="cx"> 
</span><span class="cx">     if (pageStyleSheet &amp;&amp; !pageStyleSheet-&gt;ownerNode() &amp;&amp; pageStyleSheet-&gt;href().isEmpty())
</span><span class="cx">         return Inspector::Protocol::CSS::StyleSheetOrigin::UserAgent;
</span><del>-    
</del><ins>+
</ins><span class="cx">     if (pageStyleSheet &amp;&amp; pageStyleSheet-&gt;ownerNode() &amp;&amp; pageStyleSheet-&gt;ownerNode()-&gt;nodeName() == &quot;#document&quot;)
</span><span class="cx">         return Inspector::Protocol::CSS::StyleSheetOrigin::User;
</span><span class="cx"> 
</span><del>-    InspectorStyleSheet* viaInspectorStyleSheetForOwner = viaInspectorStyleSheet(ownerDocument, false);
-    if (viaInspectorStyleSheetForOwner &amp;&amp; pageStyleSheet == viaInspectorStyleSheetForOwner-&gt;pageStyleSheet())
-        return Inspector::Protocol::CSS::StyleSheetOrigin::Inspector;
</del><ins>+    auto iterator = m_documentToInspectorStyleSheet.find(ownerDocument);
+    if (iterator != m_documentToInspectorStyleSheet.end()) {
+        for (auto&amp; inspectorStyleSheet : iterator-&gt;value) {
+            if (pageStyleSheet == inspectorStyleSheet-&gt;pageStyleSheet())
+                return Inspector::Protocol::CSS::StyleSheetOrigin::Inspector;
+        }
+    }
</ins><span class="cx"> 
</span><span class="cx">     return Inspector::Protocol::CSS::StyleSheetOrigin::Regular;
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreinspectorInspectorCSSAgenth"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.h (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.h        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorCSSAgent.h        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -45,21 +45,16 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class CSSRule;
</span><del>-class CSSRuleList;
-class CSSStyleDeclaration;
</del><span class="cx"> class CSSStyleRule;
</span><span class="cx"> class CSSStyleSheet;
</span><ins>+class ChangeRegionOversetTask;
</ins><span class="cx"> class Document;
</span><del>-class DocumentStyleSheetCollection;
</del><span class="cx"> class Element;
</span><del>-class InspectorCSSOMWrappers;
</del><span class="cx"> class InstrumentingAgents;
</span><del>-class NameNodeMap;
</del><span class="cx"> class Node;
</span><span class="cx"> class NodeList;
</span><span class="cx"> class StyleResolver;
</span><span class="cx"> class StyleRule;
</span><del>-class ChangeRegionOversetTask;
</del><span class="cx"> 
</span><span class="cx"> class InspectorCSSAgent final
</span><span class="cx">     : public InspectorAgentBase
</span><span class="lines">@@ -71,8 +66,8 @@
</span><span class="cx"> public:
</span><span class="cx">     class InlineStyleOverrideScope {
</span><span class="cx">     public:
</span><del>-        InlineStyleOverrideScope(SecurityContext* context)
-            : m_contentSecurityPolicy(context-&gt;contentSecurityPolicy())
</del><ins>+        InlineStyleOverrideScope(SecurityContext&amp; context)
+            : m_contentSecurityPolicy(context.contentSecurityPolicy())
</ins><span class="cx">         {
</span><span class="cx">             m_contentSecurityPolicy-&gt;setOverrideAllowInlineStyle(true);
</span><span class="cx">         }
</span><span class="lines">@@ -119,7 +114,8 @@
</span><span class="cx">     virtual void setStyleSheetText(ErrorString&amp;, const String&amp; styleSheetId, const String&amp; text) override;
</span><span class="cx">     virtual void setStyleText(ErrorString&amp;, const Inspector::InspectorObject&amp; styleId, const String&amp; text, RefPtr&lt;Inspector::Protocol::CSS::CSSStyle&gt;&amp; result) override;
</span><span class="cx">     virtual void setRuleSelector(ErrorString&amp;, const Inspector::InspectorObject&amp; ruleId, const String&amp; selector, RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt;&amp; result) override;
</span><del>-    virtual void addRule(ErrorString&amp;, int contextNodeId, const String&amp; selector, RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt;&amp; result) override;
</del><ins>+    virtual void createStyleSheet(ErrorString&amp;, const String&amp; frameId, String* styleSheetId) override;
+    virtual void addRule(ErrorString&amp;, const String&amp; styleSheetId, const String&amp; selector, RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt;&amp; result) override;
</ins><span class="cx">     virtual void getSupportedCSSProperties(ErrorString&amp;, RefPtr&lt;Inspector::Protocol::Array&lt;Inspector::Protocol::CSS::CSSPropertyInfo&gt;&gt;&amp; result) override;
</span><span class="cx">     virtual void getSupportedSystemFontFamilyNames(ErrorString&amp;, RefPtr&lt;Inspector::Protocol::Array&lt;String&gt;&gt;&amp; result) override;
</span><span class="cx">     virtual void forcePseudoState(ErrorString&amp;, int nodeId, const Inspector::InspectorArray&amp; forcedPseudoClasses) override;
</span><span class="lines">@@ -135,7 +131,7 @@
</span><span class="cx">     typedef HashMap&lt;String, RefPtr&lt;InspectorStyleSheet&gt;&gt; IdToInspectorStyleSheet;
</span><span class="cx">     typedef HashMap&lt;CSSStyleSheet*, RefPtr&lt;InspectorStyleSheet&gt;&gt; CSSStyleSheetToInspectorStyleSheet;
</span><span class="cx">     typedef HashMap&lt;Node*, RefPtr&lt;InspectorStyleSheetForInlineStyle&gt;&gt; NodeToInspectorStyleSheet; // bogus &quot;stylesheets&quot; with elements' inline styles
</span><del>-    typedef HashMap&lt;RefPtr&lt;Document&gt;, RefPtr&lt;InspectorStyleSheet&gt;&gt; DocumentToViaInspectorStyleSheet; // &quot;via inspector&quot; stylesheets
</del><ins>+    typedef HashMap&lt;RefPtr&lt;Document&gt;, Vector&lt;RefPtr&lt;InspectorStyleSheet&gt;&gt;&gt; DocumentToViaInspectorStyleSheet; // &quot;via inspector&quot; stylesheets
</ins><span class="cx">     typedef HashMap&lt;int, unsigned&gt; NodeIdToForcedPseudoState;
</span><span class="cx"> 
</span><span class="cx">     void resetNonPersistentData();
</span><span class="lines">@@ -150,8 +146,8 @@
</span><span class="cx"> 
</span><span class="cx">     String unbindStyleSheet(InspectorStyleSheet*);
</span><span class="cx">     InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*);
</span><del>-    InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent);
</del><span class="cx">     InspectorStyleSheet* assertStyleSheetForId(ErrorString&amp;, const String&amp;);
</span><ins>+    InspectorStyleSheet* createInspectorStyleSheetForDocument(Document&amp;);
</ins><span class="cx">     Inspector::Protocol::CSS::StyleSheetOrigin detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;Inspector::Protocol::CSS::CSSRule&gt; buildObjectForRule(StyleRule*, StyleResolver&amp;, Element*);
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreinspectorInspectorStyleSheetcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebCore/inspector/InspectorStyleSheet.cpp        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -718,7 +718,7 @@
</span><span class="cx"> 
</span><span class="cx">     styleSheetText.append(selector);
</span><span class="cx">     styleSheetText.appendLiteral(&quot; {}&quot;);
</span><del>-    // Using setText() as this operation changes the style sheet rule set.
</del><ins>+    // Using setText() as this operation changes the stylesheet rule set.
</ins><span class="cx">     setText(styleSheetText.toString(), ASSERT_NO_EXCEPTION);
</span><span class="cx"> 
</span><span class="cx">     fireStyleSheetChanged();
</span><span class="lines">@@ -1287,7 +1287,7 @@
</span><span class="cx">     ASSERT_UNUSED(style, style == inlineStyle());
</span><span class="cx"> 
</span><span class="cx">     {
</span><del>-        InspectorCSSAgent::InlineStyleOverrideScope overrideScope(&amp;m_element-&gt;document());
</del><ins>+        InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element-&gt;document());
</ins><span class="cx">         m_element-&gt;setAttribute(&quot;style&quot;, text, ec);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/ChangeLog (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/ChangeLog        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/ChangeLog        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r189104. rdar://problem/23581597
+
+    2015-08-28  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+            Web Inspector: Separate creating a style sheet from adding a new rule in the protocol
+            https://bugs.webkit.org/show_bug.cgi?id=148502
+
+            Reviewed by Timothy Hatcher.
+
+            The backend allows creating multiple stylesheets. This patch makes
+            the frontend have a preferred InspectorStyleSheet per-frame.
+
+            * UserInterface/Base/Object.js:
+            (WebInspector.Object.singleFireEventListener):
+            Return the wrapped listener so it can be removed if needed.
+
+            * UserInterface/Models/CSSStyleSheet.js:
+            (WebInspector.CSSStyleSheet.prototype.isInspectorStyleSheet):
+            Helper to check if the current stylesheet is an inspector created stylesheet.
+
+            * UserInterface/Controllers/CSSStyleManager.js:
+            (WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame):
+            (WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame.documentNodeAvailable):
+            (WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame.bodyNodeAvailable):
+            (WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame.cssRuleAvailable):
+            (WebInspector.CSSStyleManager.prototype._inspectorStyleSheetsForFrame):
+            Lookup the inspector stylesheet for a particular frame. If one doesn't exist create it.
+            For legacy backends, exploit &quot;addRule&quot; to create the inspector stylesheet.
+
+            * UserInterface/Models/DOMNode.js:
+            * UserInterface/Models/DOMNodeStyles.js:
+            (WebInspector.DOMNodeStyles.prototype.addEmptyRule.inspectorStyleSheetAvailable):
+            (WebInspector.DOMNodeStyles.prototype.addEmptyRule):
+            Currently add all new rules to the inspector stylesheet.
+
+2015-12-04  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r189002. rdar://problem/23581597
</span><span class="cx"> 
</span><span class="cx">     2015-08-26  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIUserInterfaceBaseObjectjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Base/Object.js (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Base/Object.js        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Base/Object.js        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -55,6 +55,17 @@
</span><span class="cx">         listeners.push({thisObject, listener});
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    static singleFireEventListener(eventType, listener, thisObject)
+    {
+        let wrappedCallback = function() {
+            this.removeEventListener(eventType, wrappedCallback, null);
+            listener.apply(thisObject, arguments);
+        }.bind(this);
+
+        this.addEventListener(eventType, wrappedCallback, null);
+        return wrappedCallback;
+    }
+
</ins><span class="cx">     static removeEventListener(eventType, listener, thisObject)
</span><span class="cx">     {
</span><span class="cx">         eventType = eventType || null;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -150,6 +150,92 @@
</span><span class="cx">         return styles;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    preferredInspectorStyleSheetForFrame(frame, callback)
+    {
+        var inspectorStyleSheets = this._inspectorStyleSheetsForFrame(frame);
+        for (let styleSheet of inspectorStyleSheets) {
+            if (styleSheet[WebInspector.CSSStyleManager.PreferredInspectorStyleSheetSymbol]) {
+                callback(styleSheet);
+                return;
+            }
+        }
+
+        if (CSSAgent.createStyleSheet) {
+            CSSAgent.createStyleSheet(frame.id, function(error, styleSheetId) {
+                let styleSheet = WebInspector.cssStyleManager.styleSheetForIdentifier(styleSheetId);
+                styleSheet[WebInspector.CSSStyleManager.PreferredInspectorStyleSheetSymbol] = true;
+                callback(styleSheet);
+            });
+            return;
+        }
+
+        // COMPATIBILITY (iOS 9): CSS.createStyleSheet did not exist.
+        // Legacy backends can only create the Inspector StyleSheet through CSS.addRule.
+        // Exploit that to create the Inspector StyleSheet for the document.body node in
+        // this frame, then get the StyleSheet for the new rule.
+
+        let expression = appendWebInspectorSourceURL(&quot;document&quot;);
+        let contextId = frame.pageExecutionContext.id;
+        RuntimeAgent.evaluate.invoke({expression, objectGroup: &quot;&quot;, includeCommandLineAPI: false, doNotPauseOnExceptionsAndMuteConsole: true, contextId, returnByValue: false, generatePreview: false}, documentAvailable);
+
+        function documentAvailable(error, documentRemoteObjectPayload)
+        {
+            if (error) {
+                callback(null);
+                return;
+            }
+
+            let remoteObject = WebInspector.RemoteObject.fromPayload(documentRemoteObjectPayload);
+            remoteObject.pushNodeToFrontend(documentNodeAvailable.bind(null, remoteObject));
+        }
+
+        function documentNodeAvailable(remoteObject, documentNodeId)
+        {
+            remoteObject.release();
+
+            if (!documentNodeId) {
+                callback(null);
+                return;
+            }
+
+            DOMAgent.querySelector(documentNodeId, &quot;body&quot;, bodyNodeAvailable);
+        }
+
+        function bodyNodeAvailable(error, bodyNodeId)
+        {
+            if (error) {
+                console.error(error);
+                callback(null);
+                return;
+            }
+
+            let selector = &quot;&quot;; // Intentionally empty.
+            CSSAgent.addRule(bodyNodeId, selector, cssRuleAvailable);
+        }
+
+        function cssRuleAvailable(error, payload)
+        {
+            if (error || !payload.ruleId) {
+                callback(null);
+                return;
+            }
+
+            let styleSheetId = payload.ruleId.styleSheetId;
+            let styleSheet = WebInspector.cssStyleManager.styleSheetForIdentifier(styleSheetId);
+            if (!styleSheet) {
+                callback(null);
+                return;
+            }
+
+            styleSheet[WebInspector.CSSStyleManager.PreferredInspectorStyleSheetSymbol] = true;
+
+            console.assert(styleSheet.isInspectorStyleSheet());
+            console.assert(styleSheet.parentFrame === frame);
+
+            callback(styleSheet);
+        }
+    }
+
</ins><span class="cx">     // Protected
</span><span class="cx"> 
</span><span class="cx">     mediaQueryResultChanged()
</span><span class="lines">@@ -199,6 +285,18 @@
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="cx"> 
</span><ins>+    _inspectorStyleSheetsForFrame(frame)
+    {
+        let styleSheets = [];
+
+        for (let styleSheet of this.styleSheets) {
+            if (styleSheet.isInspectorStyleSheet() &amp;&amp; styleSheet.parentFrame === frame)
+                styleSheets.push(styleSheet);
+        }
+
+        return styleSheets;
+    }
+
</ins><span class="cx">     _nodePseudoClassesDidChange(event)
</span><span class="cx">     {
</span><span class="cx">         var node = event.target;
</span><span class="lines">@@ -436,3 +534,4 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.CSSStyleManager.ForceablePseudoClasses = [&quot;active&quot;, &quot;focus&quot;, &quot;hover&quot;, &quot;visited&quot;];
</span><ins>+WebInspector.CSSStyleManager.PreferredInspectorStyleSheetSymbol = Symbol(&quot;css-style-manager-preferred-inspector-stylesheet&quot;);
</ins></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsCSSStyleSheetjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -112,6 +112,11 @@
</span><span class="cx">         return this._hasInfo;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    isInspectorStyleSheet()
+    {
+        return this._origin === WebInspector.CSSStyleSheet.Type.Inspector;
+    }
+
</ins><span class="cx">     isInlineStyleTag()
</span><span class="cx">     {
</span><span class="cx">         return this._inlineStyleTag;
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsDOMNodejs"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNode.js (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNode.js        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNode.js        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -125,6 +125,18 @@
</span><span class="cx"> 
</span><span class="cx">     // Public
</span><span class="cx"> 
</span><ins>+    get frameIdentifier()
+    {
+        return this._frameIdentifier || this.ownerDocument.frameIdentifier;
+    }
+
+    get frame()
+    {
+        if (!this._frame)
+            this._frame = WebInspector.frameResourceManager.frameForIdentifier(this.frameIdentifier);
+        return this._frame;
+    }
+
</ins><span class="cx">     get children()
</span><span class="cx">     {
</span><span class="cx">         if (!this._children)
</span><span class="lines">@@ -634,11 +646,6 @@
</span><span class="cx">                 callback.apply(null, arguments);
</span><span class="cx">         };
</span><span class="cx">     }
</span><del>-
-    get frameIdentifier()
-    {
-        return this._frameIdentifier;
-    }
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.DOMNode.Event = {
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (193443 => 193444)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2015-12-04 20:52:19 UTC (rev 193443)
+++ branches/safari-601.1.46-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2015-12-04 20:52:32 UTC (rev 193444)
</span><span class="lines">@@ -255,9 +255,20 @@
</span><span class="cx">             this.refresh();
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var selector = this._node.appropriateSelectorFor(true);
</del><ins>+        let selector = this._node.appropriateSelectorFor(true);
</ins><span class="cx"> 
</span><del>-        CSSAgent.addRule.invoke({contextNodeId: this._node.id, selector}, addedRule.bind(this));
</del><ins>+        // COMPATIBILITY (iOS 9): Before CSS.createStyleSheet, CSS.addRule could be called with a contextNode.
+        if (!CSSAgent.createStyleSheet) {
+            CSSAgent.addRule.invoke({contextNodeId: this._node.id , selector}, addedRule.bind(this));
+            return;
+        }
+
+        function inspectorStyleSheetAvailable(styleSheet)
+        {
+            CSSAgent.addRule(styleSheet.id, selector, addedRule.bind(this));
+        }
+
+        WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(this._node.frame, inspectorStyleSheetAvailable.bind(this));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     get matchedRules()
</span></span></pre>
</div>
</div>

</body>
</html>