Unreviewed, rolling out r142975.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2013 16:01:52 +0000 (16:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2013 16:01:52 +0000 (16:01 +0000)
http://trac.webkit.org/changeset/142975
https://bugs.webkit.org/show_bug.cgi?id=110225

Introduces hard-to-reproduce crashes upon inspected page
navigation on Mac (Requested by apavlov on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2013-02-19

Source/WebCore:

* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
* inspector/Inspector.json:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::InspectorCSSAgent):
(WebCore::InspectorCSSAgent::clearFrontend):
(WebCore::InspectorCSSAgent::enable):
(WebCore::InspectorCSSAgent::getAllStyleSheets):
(WebCore::InspectorCSSAgent::collectStyleSheets):
(WebCore::InspectorCSSAgent::bindStyleSheet):
(WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
(WebCore::InspectorCSSAgent::detectOrigin):
(WebCore::InspectorCSSAgent::buildObjectForRule):
* inspector/InspectorCSSAgent.h:
(InspectorCSSAgent):
* inspector/InspectorInstrumentation.cpp:
(WebCore):
* inspector/InspectorInstrumentation.h:
(WebCore):
(InspectorInstrumentation):
* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSStyleModel.prototype.getViaInspectorResourceForRule):
(WebInspector.CSSStyleModelResourceBinding.prototype.):
(WebInspector.CSSStyleModelResourceBinding.prototype.requestStyleSheetIdForResource):
(WebInspector.CSSStyleModelResourceBinding.prototype.requestResourceURLForStyleSheetId):
(WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetIdForResource):
(WebInspector.CSSStyleModelResourceBinding.prototype._loadStyleSheetHeaders):
(WebInspector.CSSStyleModelResourceBinding.prototype.headersLoaded):
(WebInspector.CSSStyleModelResourceBinding.prototype._requestViaInspectorResource):
(WebInspector.CSSStyleModelResourceBinding.prototype._getOrCreateInspectorResource):
(WebInspector.CSSStyleModelResourceBinding.prototype._reset):
* inspector/front-end/SASSSourceMapping.js:
(WebInspector.SASSSourceMapping.prototype._styleSheetChanged.callback):
(WebInspector.SASSSourceMapping.prototype._styleSheetChanged):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertiesSection.prototype._createRuleOriginNode.callback):
(WebInspector.StylePropertiesSection.prototype._createRuleOriginNode):
* inspector/front-end/StylesSourceMapping.js:
(WebInspector.StyleContentBinding.prototype.callback):
(WebInspector.StyleContentBinding.prototype.setStyleContent):
(WebInspector.StyleContentBinding.prototype.):
(WebInspector.StyleContentBinding.prototype._innerStyleSheetChanged):

LayoutTests:

* inspector/styles/resources/stylesheet-tracking.css: Removed.
* inspector/styles/stylesheet-tracking-expected.txt: Removed.
* inspector/styles/stylesheet-tracking.html: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143333 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/styles/resources/stylesheet-tracking.css [deleted file]
LayoutTests/inspector/styles/stylesheet-tracking-expected.txt [deleted file]
LayoutTests/inspector/styles/stylesheet-tracking.html [deleted file]
Source/WebCore/ChangeLog
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/front-end/CSSStyleModel.js
Source/WebCore/inspector/front-end/SASSSourceMapping.js
Source/WebCore/inspector/front-end/StylesSidebarPane.js
Source/WebCore/inspector/front-end/StylesSourceMapping.js

index 61726dd7e02959a7865964189d89193fbb53a927..2c5960b7c35af33badf83248ef71371e949af91f 100644 (file)
@@ -1,3 +1,16 @@
+2013-02-19  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r142975.
+        http://trac.webkit.org/changeset/142975
+        https://bugs.webkit.org/show_bug.cgi?id=110225
+
+        Introduces hard-to-reproduce crashes upon inspected page
+        navigation on Mac (Requested by apavlov on #webkit).
+
+        * inspector/styles/resources/stylesheet-tracking.css: Removed.
+        * inspector/styles/stylesheet-tracking-expected.txt: Removed.
+        * inspector/styles/stylesheet-tracking.html: Removed.
+
 2013-02-19  Julien Chaffraix  <jchaffraix@webkit.org>
 
         RenderGrid::computedUsedBreadthOfGridTracks can read past m_grid's size
diff --git a/LayoutTests/inspector/styles/resources/stylesheet-tracking.css b/LayoutTests/inspector/styles/resources/stylesheet-tracking.css
deleted file mode 100644 (file)
index d1aa4cc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-body {
-    border: 1px solid green;
-}
diff --git a/LayoutTests/inspector/styles/stylesheet-tracking-expected.txt b/LayoutTests/inspector/styles/stylesheet-tracking-expected.txt
deleted file mode 100644 (file)
index 7d8a469..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. Bug 105828.
-
-Text
-2 headers known:
-0:
-    URL=.../inspector/styles/resources/stylesheet-tracking.css
-    origin=regular
-1:
-    URL=.../inspector/styles/stylesheet-tracking.html
-    origin=regular
-Adding stylesheet...
-Stylesheet added:
-    URL=.../inspector/styles/stylesheet-tracking.html
-    origin=regular
-Removing stylesheet...
-Stylesheet removed:
-    URL=.../inspector/styles/stylesheet-tracking.html
-    origin=regular
-Adding rule...
-Stylesheet added:
-    URL=.../inspector/styles/stylesheet-tracking.html
-    origin=inspector
-Rule added
-
diff --git a/LayoutTests/inspector/styles/stylesheet-tracking.html b/LayoutTests/inspector/styles/stylesheet-tracking.html
deleted file mode 100644 (file)
index 96de278..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-<html>
-<head>
-<script src="../../http/tests/inspector/inspector-test.js"></script>
-<script src="../../http/tests/inspector/elements-test.js"></script>
-<script src="../../http/tests/inspector/debugger-test.js"></script>
-<link rel="stylesheet" href="resources/stylesheet-tracking.css" />
-
-<style>
-body {
-    font-size: 12px;
-}
-</style>
-
-<script>
-
-function addStyleSheet()
-{
-    var styleElement = document.createElement("style");
-    styleElement.id = "style";
-    document.head.appendChild(styleElement);
-}
-
-function removeStyleSheet()
-{
-    document.head.removeChild(document.getElementById("style"));
-}
-
-function test()
-{
-    var inspectorResource;
-
-    WebInspector.showPanel("elements");
-    WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAdded, styleSheetAdded, null);
-    WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRemoved, styleSheetRemoved, null);
-    var headers = WebInspector.cssModel.styleSheetHeaders();
-    InspectorTest.addResult(headers.length + " headers known:");
-    for (var i = 0; i < headers.length; ++i)
-        InspectorTest.addResult(i + ":\n" + headerData(headers[i]));
-
-    step1();
-
-    function step1()
-    {
-        InspectorTest.addResult("Adding stylesheet...");
-        InspectorTest.evaluateInPage("addStyleSheet()", step2);
-    }
-
-    function step2()
-    {
-        InspectorTest.addResult("Removing stylesheet...");
-        InspectorTest.evaluateInPage("removeStyleSheet()", step3);
-    }
-
-    function step3()
-    {
-        InspectorTest.selectNodeAndWaitForStyles("inspected", step4);
-    }
-
-    function step4(node)
-    {
-        InspectorTest.addResult("Adding rule...");
-        WebInspector.cssModel.addRule(node.id, "#inspected", successCallback, failureCallback);
-
-        function successCallback()
-        {
-            InspectorTest.addResult("Rule added");
-            InspectorTest.completeTest();
-        }
-        function failureCallback()
-        {
-            InspectorTest.addResult("Failed to add rule.");
-            InspectorTest.completeTest();
-        }
-    }
-
-    function styleSheetAdded(event)
-    {
-        var header = event.data;
-        InspectorTest.addResult("Stylesheet added:\n" + headerData(header));
-    }
-
-    function styleSheetRemoved(event)
-    {
-        var header = event.data;
-        InspectorTest.addResult("Stylesheet removed:\n" + headerData(header));
-    }
-
-    function headerData(header)
-    {
-        return "    URL=" + trimURL(header.sourceURL) + "\n    origin=" + header.origin;
-    }
-
-    function trimURL(url)
-    {
-        if (!url)
-            return url;
-        var lastIndex = url.lastIndexOf("inspector/");
-        if (lastIndex < 0)
-            return url;
-        return ".../" + url.substr(lastIndex);
-    }
-}
-</script>
-</head>
-
-<body onload="runTest()">
-<p>
-Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. <a href="https://bugs.webkit.org/show_bug.cgi?id=105828">Bug 105828</a>.
-</p>
-
-<div id="inspected">Text</div>
-
-</body>
-</html>
index 0bcbda65ebc37b4d2694b8c61234eedd0c1dbaf5..2d2f940680e10d17d3717b5cdde089671b318b99 100644 (file)
@@ -1,3 +1,55 @@
+2013-02-19  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r142975.
+        http://trac.webkit.org/changeset/142975
+        https://bugs.webkit.org/show_bug.cgi?id=110225
+
+        Introduces hard-to-reproduce crashes upon inspected page
+        navigation on Mac (Requested by apavlov on #webkit).
+
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
+        * inspector/Inspector.json:
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::InspectorCSSAgent):
+        (WebCore::InspectorCSSAgent::clearFrontend):
+        (WebCore::InspectorCSSAgent::enable):
+        (WebCore::InspectorCSSAgent::getAllStyleSheets):
+        (WebCore::InspectorCSSAgent::collectStyleSheets):
+        (WebCore::InspectorCSSAgent::bindStyleSheet):
+        (WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
+        (WebCore::InspectorCSSAgent::detectOrigin):
+        (WebCore::InspectorCSSAgent::buildObjectForRule):
+        * inspector/InspectorCSSAgent.h:
+        (InspectorCSSAgent):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore):
+        (InspectorInstrumentation):
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel.prototype.getViaInspectorResourceForRule):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.requestStyleSheetIdForResource):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.requestResourceURLForStyleSheetId):
+        (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetIdForResource):
+        (WebInspector.CSSStyleModelResourceBinding.prototype._loadStyleSheetHeaders):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.headersLoaded):
+        (WebInspector.CSSStyleModelResourceBinding.prototype._requestViaInspectorResource):
+        (WebInspector.CSSStyleModelResourceBinding.prototype._getOrCreateInspectorResource):
+        (WebInspector.CSSStyleModelResourceBinding.prototype._reset):
+        * inspector/front-end/SASSSourceMapping.js:
+        (WebInspector.SASSSourceMapping.prototype._styleSheetChanged.callback):
+        (WebInspector.SASSSourceMapping.prototype._styleSheetChanged):
+        * inspector/front-end/StylesSidebarPane.js:
+        (WebInspector.StylePropertiesSection.prototype._createRuleOriginNode.callback):
+        (WebInspector.StylePropertiesSection.prototype._createRuleOriginNode):
+        * inspector/front-end/StylesSourceMapping.js:
+        (WebInspector.StyleContentBinding.prototype.callback):
+        (WebInspector.StyleContentBinding.prototype.setStyleContent):
+        (WebInspector.StyleContentBinding.prototype.):
+        (WebInspector.StyleContentBinding.prototype._innerStyleSheetChanged):
+
 2013-02-19  Julien Chaffraix  <jchaffraix@webkit.org>
 
         RenderGrid::computedUsedBreadthOfGridTracks can read past m_grid's size
index d06ff965bd7cb2260b4517865cb453e47f0a9473..3ac1f5ec4c782f366101d4f123980d099c37cc93 100644 (file)
@@ -487,7 +487,6 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag
         resetCSSFeatureFlags();
     }
     m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
-    InspectorInstrumentation::activeStyleSheetsUpdated(m_document, m_styleSheetsForStyleSheetList, activeStyleSheets);
     m_styleSheetsForStyleSheetList.swap(activeStyleSheets);
 
     m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
index c1cb98049e373fe8339ae5b96f80a1b35f10e8b1..cba1edebdbe81bfe15dc73a938b087ec76038bb0 100644 (file)
     {
         "domain": "CSS",
         "hidden": true,
-        "description": "This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) have an associated <code>id</code> used in subsequent operations on the related object. Each object type has a specific <code>id</code> structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the <code>get*ForNode()</code> calls (which accept a DOM node id). A client can also discover all the existing stylesheets with the <code>getAllStyleSheets()</code> method (or keeping track of the <code>styleSheetAdded</code>/<code>styleSheetRemoved</code> events) and subsequently load the required stylesheet contents using the <code>getStyleSheet[Text]()</code> methods.",
+        "description": "This domain exposes CSS read/write operations. All CSS objects, like stylesheets, rules, and styles, have an associated <code>id</code> used in subsequent operations on the related object. Each object type has a specific <code>id</code> structure, and those are not interchangeable between objects of different kinds. CSS objects can be loaded using the <code>get*ForNode()</code> calls (which accept a DOM node id). Alternatively, a client can discover all the existing stylesheets with the <code>getAllStyleSheets()</code> method and subsequently load the required stylesheet contents using the <code>getStyleSheet[Text]()</code> methods.",
         "types": [
             {
                 "id": "StyleSheetId",
                 ],
                 "description": "Fired whenever a stylesheet is changed as a result of the client operation."
             },
-            {
-                "name": "styleSheetAdded",
-                "parameters": [
-                    { "name": "header", "$ref": "CSSStyleSheetHeader", "description": "Added stylesheet metainfo." }
-                ],
-                "description": "Fired whenever an active document stylesheet is added."
-            },
-            {
-                "name": "styleSheetRemoved",
-                "parameters": [
-                    { "name": "styleSheetId", "$ref": "StyleSheetId", "description": "Identifier of the removed stylesheet." }
-                ],
-                "description": "Fired whenever an active document stylesheet is removed."
-            },
             {
                 "name": "namedFlowCreated",
                 "parameters": [
index 9b9fa3f502af7aea43bb97a477fc4376c33447c3..6d705ae1ededeefada9a2d0132e6aff7cef13c9f 100644 (file)
@@ -54,7 +54,6 @@
 #include "StylePropertyShorthand.h"
 #include "StyleResolver.h"
 #include "StyleRule.h"
-#include "StyleSheet.h"
 #include "StyleSheetList.h"
 #include "WebKitNamedFlow.h"
 
@@ -530,7 +529,6 @@ InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, I
     , m_frontend(0)
     , m_domAgent(domAgent)
     , m_lastStyleSheetId(1)
-    , m_creatingViaInspectorStyleSheet(false)
 {
     m_domAgent->setDOMListener(this);
 }
@@ -552,7 +550,8 @@ void InspectorCSSAgent::clearFrontend()
     ASSERT(m_frontend);
     m_frontend = 0;
     resetNonPersistentData();
-    stopSelectorProfilerImpl(0, false);
+    String errorString;
+    stopSelectorProfilerImpl(&errorString, false);
 }
 
 void InspectorCSSAgent::discardAgent()
@@ -594,12 +593,6 @@ void InspectorCSSAgent::enable(ErrorString*)
 {
     m_state->setBoolean(CSSAgentState::cssAgentEnabled, true);
     m_instrumentingAgents->setInspectorCSSAgent(this);
-
-    RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create();
-    Vector<InspectorStyleSheet*> styleSheets;
-    collectAllStyleSheets(styleSheets);
-    for (size_t i = 0; i < styleSheets.size(); ++i)
-        m_frontend->styleSheetAdded(styleSheets.at(i)->buildObjectForStyleSheetInfo());
 }
 
 void InspectorCSSAgent::disable(ErrorString*)
@@ -658,38 +651,6 @@ void InspectorCSSAgent::regionLayoutUpdated(WebKitNamedFlow* namedFlow, int docu
     m_frontend->regionLayoutUpdated(buildObjectForNamedFlow(&errorString, namedFlow, documentNodeId));
 }
 
-void InspectorCSSAgent::activeStyleSheetsUpdated(const Vector<RefPtr<StyleSheet> >& oldSheets, const Vector<RefPtr<StyleSheet> >& newSheets)
-{
-    HashSet<CSSStyleSheet*> removedSheets;
-    for (size_t i = 0, size = oldSheets.size(); i < size; ++i) {
-        StyleSheet* oldSheet = oldSheets.at(i).get();
-        if (oldSheet->isCSSStyleSheet())
-            removedSheets.add(static_cast<CSSStyleSheet*>(oldSheet));
-    }
-
-    HashSet<CSSStyleSheet*> addedSheets;
-    for (size_t i = 0, size = newSheets.size(); i < size; ++i) {
-        StyleSheet* newSheet = newSheets.at(i).get();
-        if (!newSheet->isCSSStyleSheet())
-            continue;
-        CSSStyleSheet* newCSSSheet = static_cast<CSSStyleSheet*>(newSheet);
-        if (removedSheets.contains(newCSSSheet))
-            removedSheets.remove(newCSSSheet);
-        else
-            addedSheets.add(newCSSSheet);
-    }
-
-    RefPtr<TypeBuilder::Array<TypeBuilder::CSS::StyleSheetId> > removedIds = TypeBuilder::Array<TypeBuilder::CSS::StyleSheetId>::create();
-    for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != removedSheets.end(); ++it) {
-        RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspectorStyleSheet.get(*it);
-        ASSERT(inspectorStyleSheet);
-        m_frontend->styleSheetRemoved(unbindStyleSheet(inspectorStyleSheet.get()));
-    }
-    RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > addedHeaders = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create();
-    for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != addedSheets.end(); ++it)
-        m_frontend->styleSheetAdded(bindStyleSheet(static_cast<CSSStyleSheet*>(*it))->buildObjectForStyleSheetInfo());
-}
-
 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoType pseudoType)
 {
     if (m_nodeIdToForcedPseudoState.isEmpty())
@@ -797,10 +758,15 @@ void InspectorCSSAgent::getComputedStyleForNode(ErrorString* errorString, int no
 void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos)
 {
     styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create();
-    Vector<InspectorStyleSheet*> styleSheets;
-    collectAllStyleSheets(styleSheets);
-    for (size_t i = 0; i < styleSheets.size(); ++i)
-        styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo());
+    Vector<Document*> documents = m_domAgent->documents();
+    for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
+        StyleSheetList* list = (*it)->styleSheets();
+        for (unsigned i = 0; i < list->length(); ++i) {
+            StyleSheet* styleSheet = list->item(i);
+            if (styleSheet->isCSSStyleSheet())
+                collectStyleSheets(static_cast<CSSStyleSheet*>(styleSheet), styleInfos.get());
+        }
+    }
 }
 
 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& styleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject)
@@ -1057,23 +1023,10 @@ int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document)
     return documentNodeId;
 }
 
-void InspectorCSSAgent::collectAllStyleSheets(Vector<InspectorStyleSheet*>& result)
-{
-    Vector<Document*> documents = m_domAgent->documents();
-    for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
-        StyleSheetList* list = (*it)->styleSheets();
-        for (unsigned i = 0; i < list->length(); ++i) {
-            StyleSheet* styleSheet = list->item(i);
-            if (styleSheet->isCSSStyleSheet())
-                collectStyleSheets(static_cast<CSSStyleSheet*>(styleSheet), result);
-        }
-    }
-}
-
-void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Vector<InspectorStyleSheet*>& result)
+void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>* result)
 {
     InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet));
-    result.append(inspectorStyleSheet);
+    result->addItem(inspectorStyleSheet->buildObjectForStyleSheetInfo());
     for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
         CSSRule* rule = styleSheet->item(i);
         if (rule->type() == CSSRule::IMPORT_RULE) {
@@ -1093,20 +1046,10 @@ InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet
         inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document), this);
         m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
         m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet);
-        if (m_creatingViaInspectorStyleSheet)
-            m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet);
     }
     return inspectorStyleSheet.get();
 }
 
-String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSheet)
-{
-    String id = inspectorStyleSheet->id();
-    m_idToInspectorStyleSheet.remove(id);
-    m_cssStyleSheetToInspectorStyleSheet.remove(inspectorStyleSheet->pageStyleSheet());
-    return id;
-}
-
 InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent)
 {
     if (!document) {
@@ -1133,15 +1076,21 @@ InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* documen
             return 0;
 
         InlineStyleOverrideScope overrideScope(document);
-        m_creatingViaInspectorStyleSheet = true;
         targetNode->appendChild(styleElement, ec);
-        // At this point the added stylesheet will get bound through the updateActiveStyleSheets() invocation.
-        // We just need to pick the respective InspectorStyleSheet from m_documentToInspectorStyleSheet.
-        m_creatingViaInspectorStyleSheet = false;
     }
     if (ec)
         return 0;
-    return m_documentToInspectorStyleSheet.get(document).get();
+    StyleSheetList* styleSheets = document->styleSheets();
+    StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1);
+    if (!styleSheet || !styleSheet->isCSSStyleSheet())
+        return 0;
+    CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet);
+    String id = String::number(m_lastStyleSheetId++);
+    inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), id, cssStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Inspector, InspectorDOMAgent::documentURLString(document), this);
+    m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
+    m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet);
+    m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet);
+    return inspectorStyleSheet.get();
 }
 
 InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* errorString, const String& styleSheetId)
@@ -1156,9 +1105,6 @@ InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* error
 
 TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument)
 {
-    if (m_creatingViaInspectorStyleSheet)
-        return TypeBuilder::CSS::StyleSheetOrigin::Inspector;
-
     TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleSheetOrigin::Regular;
     if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href().isEmpty())
         origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent;
@@ -1185,7 +1131,8 @@ PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSS
         if (!rule)
             return 0;
     }
-    return bindStyleSheet(rule->parentStyleSheet())->buildObjectForRule(rule);
+    InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(rule->parentStyleSheet());
+    return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(rule) : 0;
 }
 
 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::buildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver)
index d35c9bc33e447c6ab4393586db9593da01950426..143e454aa96b0168198031510ff59738af0fee17 100644 (file)
@@ -37,7 +37,6 @@
 #include <wtf/HashSet.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -106,7 +105,6 @@ public:
     void willRemoveNamedFlow(Document*, WebKitNamedFlow*);
     void didUpdateRegionLayout(Document*, WebKitNamedFlow*);
     void regionLayoutUpdated(WebKitNamedFlow*, int documentNodeId);
-    void activeStyleSheetsUpdated(const Vector<RefPtr<StyleSheet> >& oldSheets, const Vector<RefPtr<StyleSheet> >& newSheets);
 
     virtual void getComputedStyleForNode(ErrorString*, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> >&);
     virtual void getInlineStylesForNode(ErrorString*, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributes);
@@ -152,11 +150,9 @@ private:
     InspectorStyleSheetForInlineStyle* asInspectorStyleSheet(Element* element);
     Element* elementForId(ErrorString*, int nodeId);
     int documentNodeWithRequestedFlowsId(Document*);
-    void collectAllStyleSheets(Vector<InspectorStyleSheet*>&);
-    void collectStyleSheets(CSSStyleSheet*, Vector<InspectorStyleSheet*>&);
+    void collectStyleSheets(CSSStyleSheet*, TypeBuilder::Array<WebCore::TypeBuilder::CSS::CSSStyleSheetHeader>*);
 
     InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*);
-    String unbindStyleSheet(InspectorStyleSheet*);
     InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent);
     InspectorStyleSheet* assertStyleSheetForId(ErrorString*, const String&);
     TypeBuilder::CSS::StyleSheetOrigin::Enum detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
@@ -190,7 +186,6 @@ private:
     OwnPtr<UpdateRegionLayoutTask> m_updateRegionLayoutTask;
 
     int m_lastStyleSheetId;
-    bool m_creatingViaInspectorStyleSheet;
 
     OwnPtr<SelectorProfile> m_currentSelectorProfile;
 };
index 7a4463236d753342005526b7bfcf36419ae6d48c..5aaab18ac67c42a38668707d8ce54f24e1e3c55c 100644 (file)
@@ -244,12 +244,6 @@ void InspectorInstrumentation::didInvalidateStyleAttrImpl(InstrumentingAgents* i
 #endif
 }
 
-void InspectorInstrumentation::activeStyleSheetsUpdatedImpl(InstrumentingAgents* instrumentingAgents, const Vector<RefPtr<StyleSheet> >& oldSheets, const Vector<RefPtr<StyleSheet> >& newSheets)
-{
-    if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent())
-        cssAgent->activeStyleSheetsUpdated(oldSheets, newSheets);
-}
-
 void InspectorInstrumentation::frameWindowDiscardedImpl(InstrumentingAgents* instrumentingAgents, DOMWindow* window)
 {
     if (InspectorConsoleAgent* consoleAgent = instrumentingAgents->inspectorConsoleAgent())
index e6c7128ce59b7ba3d4ff37f3a365d00dabf35476..ff6300516ef10334b0022109cfedb36f3d612f3a 100644 (file)
@@ -47,7 +47,6 @@
 #include "WebSocketHandshakeResponse.h"
 #include <wtf/RefPtr.h>
 #include <wtf/UnusedParam.h>
-#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -83,7 +82,6 @@ class ShadowRoot;
 class StorageArea;
 class StyleResolver;
 class StyleRule;
-class StyleSheet;
 class ThreadableLoaderClient;
 class WorkerContext;
 class WorkerContextProxy;
@@ -124,7 +122,6 @@ public:
     static void didRemoveDOMAttr(Document*, Element*, const AtomicString& name);
     static void characterDataModified(Document*, CharacterData*);
     static void didInvalidateStyleAttr(Document*, Node*);
-    static void activeStyleSheetsUpdated(Document*, const Vector<RefPtr<StyleSheet> >&, const Vector<RefPtr<StyleSheet> >&);
     static void frameWindowDiscarded(Frame*, DOMWindow*);
     static void mediaQueryResultChanged(Document*);
     static void didPushShadowRoot(Element* host, ShadowRoot*);
@@ -328,7 +325,6 @@ private:
     static void didRemoveDOMAttrImpl(InstrumentingAgents*, Element*, const AtomicString& name);
     static void characterDataModifiedImpl(InstrumentingAgents*, CharacterData*);
     static void didInvalidateStyleAttrImpl(InstrumentingAgents*, Node*);
-    static void activeStyleSheetsUpdatedImpl(InstrumentingAgents*, const Vector<RefPtr<StyleSheet> >&, const Vector<RefPtr<StyleSheet> >&);
     static void frameWindowDiscardedImpl(InstrumentingAgents*, DOMWindow*);
     static void mediaQueryResultChangedImpl(InstrumentingAgents*);
     static void didPushShadowRootImpl(InstrumentingAgents*, Element* host, ShadowRoot*);
@@ -620,19 +616,6 @@ inline void InspectorInstrumentation::didInvalidateStyleAttr(Document* document,
 #endif
 }
 
-inline void InspectorInstrumentation::activeStyleSheetsUpdated(Document* document, const Vector<RefPtr<StyleSheet> >& oldSheets, const Vector<RefPtr<StyleSheet> >& newSheets)
-{
-#if ENABLE(INSPECTOR)
-    FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
-        activeStyleSheetsUpdatedImpl(instrumentingAgents, oldSheets, newSheets);
-#else
-    UNUSED_PARAM(document);
-    UNUSED_PARAM(oldSheets);
-    UNUSED_PARAM(newSheets);
-#endif
-}
-
 inline void InspectorInstrumentation::frameWindowDiscarded(Frame* frame, DOMWindow* domWindow)
 {
 #if ENABLE(INSPECTOR)
index a755ba5f3f31765a2e9643a7178007408f6bc007..f45b2f8d6bb0471d632cb38ae7f20250b10cdc92 100644 (file)
@@ -73,9 +73,7 @@ WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray)
 }
 
 WebInspector.CSSStyleModel.Events = {
-    StyleSheetAdded: "StyleSheetAdded",
     StyleSheetChanged: "StyleSheetChanged",
-    StyleSheetRemoved: "StyleSheetRemoved",
     MediaQueryResultChanged: "MediaQueryResultChanged",
     NamedFlowCreated: "NamedFlowCreated",
     NamedFlowRemoved: "NamedFlowRemoved",
@@ -359,14 +357,6 @@ WebInspector.CSSStyleModel.prototype = {
         this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged);
     },
 
-    /**
-     * @return {Array.<CSSAgent.CSSStyleSheetHeader>}
-     */
-    styleSheetHeaders: function()
-    {
-        return Object.values(this._resourceBinding._styleSheetIdToHeader);
-    },
-
     /**
      * @param {DOMAgent.NodeId} nodeId
      */
@@ -394,20 +384,6 @@ WebInspector.CSSStyleModel.prototype = {
         this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged, { styleSheetId: styleSheetId, majorChange: majorChange });
     },
 
-    _styleSheetAdded: function(header)
-    {
-        this._resourceBinding._setHeaderForStyleSheetId(header.styleSheetId, header);
-        this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetAdded, header);
-    },
-
-    _styleSheetRemoved: function(id)
-    {
-        var header = this._resourceBinding._styleSheetIdToHeader[id];
-        console.assert(header);
-        this._resourceBinding._setHeaderForStyleSheetId(id, null);
-        this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetRemoved, header);
-    },
-
     /**
      * @param {CSSAgent.NamedFlow} namedFlowPayload
      */
@@ -486,13 +462,15 @@ WebInspector.CSSStyleModel.prototype = {
 
     /**
      * @param {WebInspector.CSSRule} rule
-     * @return {?WebInspector.Resource}
+     * @param {function(?WebInspector.Resource)} callback
      */
-    viaInspectorResourceForRule: function(rule)
+    getViaInspectorResourceForRule: function(rule, callback)
     {
-        if (!rule.id)
-            return null;
-        return this._resourceBinding._inspectorResource(rule.id.styleSheetId);
+        if (!rule.id) {
+            callback(null);
+            return;
+        }
+        this._resourceBinding._requestViaInspectorResource(rule.id.styleSheetId, callback);
     },
 
     /**
@@ -1229,80 +1207,136 @@ WebInspector.CSSStyleModelResourceBinding = function()
 
 WebInspector.CSSStyleModelResourceBinding.prototype = {
     /**
-     * @param {CSSAgent.StyleSheetId} styleSheetId
-     * @param {CSSAgent.CSSStyleSheetHeader} header
+     * @param {WebInspector.Resource} resource
+     * @param {function(?CSSAgent.StyleSheetId)} callback
      */
-    _setHeaderForStyleSheetId: function(styleSheetId, header)
+    requestStyleSheetIdForResource: function(resource, callback)
     {
-        var oldHeader = this._styleSheetIdToHeader[styleSheetId];
-        if (oldHeader) {
-            delete this._styleSheetIdToHeader[styleSheetId];
-            delete this._frameAndURLToStyleSheetId[this._headerKey(oldHeader)];
-        }
-        if (header) {
-            this._styleSheetIdToHeader[styleSheetId] = header;
-            if (header.origin === "inspector")
-                this._createInspectorResource(header);
-            else
-                this._frameAndURLToStyleSheetId[this._headerKey(header)] = header.styleSheetId;
+        function innerCallback()
+        {
+            callback(this._styleSheetIdForResource(resource));
         }
+        
+        if (this._styleSheetIdForResource(resource))
+            innerCallback.call(this);
+        else
+            this._loadStyleSheetHeaders(innerCallback.bind(this));
     },
 
     /**
      * @param {CSSAgent.StyleSheetId} styleSheetId
-     * @return {?string}
+     * @param {function(?string)} callback
      */
-    resourceURLForStyleSheetId: function(styleSheetId)
+    requestResourceURLForStyleSheetId: function(styleSheetId, callback)
     {
-        var header = this._styleSheetIdToHeader[styleSheetId];
-        if (!header)
-            return null;
+        function innerCallback()
+        {
+            var header = this._styleSheetIdToHeader[styleSheetId];
+            if (!header) {
+                callback(null);
+                return;
+            }
 
-        var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
-        if (!frame)
-            return null;
+            var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
+            if (!frame) {
+                callback(null);
+                return;
+            }
 
-        var styleSheetURL = header.origin === "inspector" ? this._viaInspectorResourceURL(header.sourceURL) : header.sourceURL;
-        return styleSheetURL;
+            var styleSheetURL = header.origin === "inspector" ? this._viaInspectorResourceURL(header.sourceURL) : header.sourceURL;
+            callback(styleSheetURL);
+        }
+        
+        if (this._styleSheetIdToHeader[styleSheetId])
+            innerCallback.call(this);
+        else
+            this._loadStyleSheetHeaders(innerCallback.bind(this));
     },
 
     /**
      * @param {WebInspector.Resource} resource
-     * @return {CSSAgent.StyleSheetId|undefined}
+     * @return {CSSAgent.StyleSheetId}
      */
-    styleSheetIdForResource: function(resource)
+    _styleSheetIdForResource: function(resource)
     {
         return this._frameAndURLToStyleSheetId[resource.frameId + ":" + resource.url];
     },
 
     /**
-     * @param {!CSSAgent.CSSStyleSheetHeader} header
-     * @return {string}
+     * @param {function(?string)} callback
      */
-    _headerKey: function(header)
+    _loadStyleSheetHeaders: function(callback)
     {
-        return header.frameId + ":" + (header.origin === "inspector" ? this._viaInspectorResourceURL(header.sourceURL) : header.sourceURL);
+        /**
+         * @param {?string} error
+         * @param {Array.<CSSAgent.CSSStyleSheetHeader>} infos
+         */
+        function didGetAllStyleSheets(error, infos)
+        {
+            if (error) {
+                callback(error);
+                return;
+            }
+
+            for (var i = 0; i < infos.length; ++i) {
+                var info = infos[i];
+                if (info.origin === "inspector") {
+                    this._getOrCreateInspectorResource(info);
+                    continue;
+                }
+                this._frameAndURLToStyleSheetId[info.frameId + ":" + info.sourceURL] = info.styleSheetId;
+                this._styleSheetIdToHeader[info.styleSheetId] = info;
+            }
+            callback(null);
+        }
+        CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
+    },
+
+    /**
+     * @param {CSSAgent.StyleSheetId} styleSheetId
+     * @param {function(?WebInspector.Resource)} callback
+     */
+    _requestViaInspectorResource: function(styleSheetId, callback)
+    {
+        var header = this._styleSheetIdToHeader[styleSheetId];
+        if (header) {
+            callback(this._getOrCreateInspectorResource(header));
+            return;
+        }
+
+        function headersLoaded()
+        {
+            var header = this._styleSheetIdToHeader[styleSheetId];
+            if (header)
+                callback(this._getOrCreateInspectorResource(header));
+            else
+                callback(null);
+        }
+        this._loadStyleSheetHeaders(headersLoaded.bind(this));
     },
 
     /**
      * @param {CSSAgent.CSSStyleSheetHeader} header
+     * @return {?WebInspector.Resource}
      */
-    _createInspectorResource: function(header)
+    _getOrCreateInspectorResource: function(header)
     {
         var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
         if (!frame)
-            return;
+            return null;
 
         var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL);    
-        console.assert(!frame.resourceForURL(viaInspectorURL));
+        var inspectorResource = frame.resourceForURL(viaInspectorURL);
+        if (inspectorResource)
+            return inspectorResource;
 
         var resource = frame.resourceForURL(header.sourceURL);
         if (!resource)
-            return;
-
-        this._frameAndURLToStyleSheetId[this._headerKey(header)] = header.styleSheetId;
-        var inspectorResource = new WebInspector.Resource(null, viaInspectorURL, resource.documentURL, resource.frameId, resource.loaderId, WebInspector.resourceTypes.Stylesheet, "text/css", true);
+            return null;
 
+        this._frameAndURLToStyleSheetId[header.frameId + ":" + viaInspectorURL] = header.styleSheetId;
+        this._styleSheetIdToHeader[header.styleSheetId] = header;
+        inspectorResource = new WebInspector.Resource(null, viaInspectorURL, resource.documentURL, resource.frameId, resource.loaderId, WebInspector.resourceTypes.Stylesheet, "text/css", true);
         /**
          * @param {function(?string, boolean, string)} callback
          */
@@ -1316,23 +1350,7 @@ WebInspector.CSSStyleModelResourceBinding.prototype = {
         }
         inspectorResource.requestContent = overrideRequestContent;
         frame.addResource(inspectorResource);
-    },
-
-    /**
-     * @param {CSSAgent.StyleSheetId} styleSheetId
-     * @return {?WebInspector.Resource}
-     */
-    _inspectorResource: function(styleSheetId)
-    {
-        var header = this._styleSheetIdToHeader[styleSheetId];
-        if (!header)
-            return null;
-        var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
-        if (!frame)
-            return null;
-
-        var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL);
-        return frame.resourceForURL(viaInspectorURL);
+        return inspectorResource;
     },
 
     /**
@@ -1352,9 +1370,7 @@ WebInspector.CSSStyleModelResourceBinding.prototype = {
     _reset: function()
     {
         // Main frame navigation - clear history.
-        /** @type {!Object.<string, !CSSAgent.StyleSheetId>} */
         this._frameAndURLToStyleSheetId = {};
-        /** @type {!Object.<CSSAgent.StyleSheetId, !CSSAgent.CSSStyleSheetHeader>} */
         this._styleSheetIdToHeader = {};
     }
 }
@@ -1383,22 +1399,6 @@ WebInspector.CSSDispatcher.prototype = {
         this._cssModel._fireStyleSheetChanged(styleSheetId);
     },
 
-    /**
-     * @param {CSSAgent.CSSStyleSheetHeader} header
-     */
-    styleSheetAdded: function(header)
-    {
-        this._cssModel._styleSheetAdded(header);
-    },
-
-    /**
-     * @param {CSSAgent.StyleSheetId} id
-     */
-    styleSheetRemoved: function(id)
-    {
-        this._cssModel._styleSheetRemoved(id);
-    },
-
     /**
      * @param {CSSAgent.NamedFlow} namedFlowPayload
      */
index 365ac45bcd2b654f2c75a89614454173cbc8fb17..e6b10152f71858b8adfee434fd630aa035e4f466 100644 (file)
@@ -76,10 +76,14 @@ WebInspector.SASSSourceMapping.prototype = {
 
         if (isAddingRevision)
             return;
-        var url = this._cssModel.resourceBinding().resourceURLForStyleSheetId(event.data.styleSheetId);
-        if (!url)
-            return;
-        this._cssModel.setSourceMapping(url, null);
+        this._cssModel.resourceBinding().requestResourceURLForStyleSheetId(event.data.styleSheetId, callback.bind(this));
+
+        function callback(url)
+        {
+            if (!url)
+                return;
+            this._cssModel.setSourceMapping(url, null);
+        }
     },
 
     /**
index 0b3ebbd94f0959fdc07e7f67b02b33e252e2bcc7..d439d3ae88112cccf41ffbca3bce844962277736 100644 (file)
@@ -1196,11 +1196,17 @@ WebInspector.StylePropertiesSection.prototype = {
             return document.createTextNode(WebInspector.UIString("user stylesheet"));
         if (this.rule.isViaInspector) {
             var element = document.createElement("span");
-            var resource = WebInspector.cssModel.viaInspectorResourceForRule(this.rule);
-            if (resource)
-                element.appendChild(linkifyUncopyable(resource.url, this.rule.sourceLine));
-            else
-                element.textContent = WebInspector.UIString("via inspector");
+            /**
+             * @param {?WebInspector.Resource} resource
+             */
+            function callback(resource)
+            {
+                if (resource)
+                    element.appendChild(linkifyUncopyable(resource.url, this.rule.sourceLine));
+                else
+                    element.textContent = WebInspector.UIString("via inspector");
+            }
+            WebInspector.cssModel.getViaInspectorResourceForRule(this.rule, callback.bind(this));
             return element;
         }
     },
index 72640525d0b80b1887a212f58e3edf88c895ae67..c68ae5c67f4122cd2fee22d7f3f1fa799714fbfb 100644 (file)
@@ -239,13 +239,31 @@ WebInspector.StyleContentBinding.prototype = {
             userCallback("No resource found: " + uiSourceCode.url);
             return;
         }
+            
+        this._cssModel.resourceBinding().requestStyleSheetIdForResource(resource, callback.bind(this));
 
-        var styleSheetId = this._cssModel.resourceBinding().styleSheetIdForResource(resource);
-        if (!styleSheetId) {
-            userCallback("No stylesheet found: " + resource.frameId + ":" + resource.url);
-            return;
+        /**
+         * @param {?CSSAgent.StyleSheetId} styleSheetId
+         */
+        function callback(styleSheetId)
+        {
+            if (!styleSheetId) {
+                userCallback("No stylesheet found: " + resource.frameId + ":" + resource.url);
+                return;
+            }
+
+            this._innerSetContent(styleSheetId, content, majorChange, userCallback, null);
         }
+    },
 
+    /**
+     * @param {CSSAgent.StyleSheetId} styleSheetId
+     * @param {string} content
+     * @param {boolean} majorChange
+     * @param {function(?string)} userCallback
+     */
+    _innerSetContent: function(styleSheetId, content, majorChange, userCallback)
+    {
         this._isSettingContent = true;
         function callback(error)
         {
@@ -284,18 +302,25 @@ WebInspector.StyleContentBinding.prototype = {
      */
     _innerStyleSheetChanged: function(styleSheetId, content)
     {
-        var styleSheetURL = this._cssModel.resourceBinding().resourceURLForStyleSheetId(styleSheetId);
-        if (typeof styleSheetURL !== "string")
-            return;
+        /**
+         * @param {?string} styleSheetURL
+         */
+        function callback(styleSheetURL)
+        {
+            if (typeof styleSheetURL !== "string")
+                return;
 
-        var uri = WebInspector.fileMapping.uriForURL(styleSheetURL);
-        var uiSourceCode = WebInspector.workspace.uiSourceCodeForURI(uri);
-        if (!uiSourceCode)
-            return;
+            var uri = WebInspector.fileMapping.uriForURL(styleSheetURL);
+            var uiSourceCode = WebInspector.workspace.uiSourceCodeForURI(uri);
+            if (!uiSourceCode)
+                return;
 
-        if (uiSourceCode.styleFile())
-            uiSourceCode.styleFile().addRevision(content);
-    }
+            if (uiSourceCode.styleFile())
+                uiSourceCode.styleFile().addRevision(content);
+        }
+
+        this._cssModel.resourceBinding().requestResourceURLForStyleSheetId(styleSheetId, callback.bind(this));
+    },
 }
 
 /**