Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Unified Diff: Source/devtools/front_end/sdk/CSSParser.js

Issue 685203003: DevTools: Get rid of synchronous XHRs in the frontend code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/sdk/CSSParser.js
diff --git a/Source/devtools/front_end/sdk/CSSParser.js b/Source/devtools/front_end/sdk/CSSParser.js
index 305dd957f71bb54bb843abaf7539aaf733a1c1b4..aa0c14255a7b30d83ee5a22b1faddadd657c8743 100644
--- a/Source/devtools/front_end/sdk/CSSParser.js
+++ b/Source/devtools/front_end/sdk/CSSParser.js
@@ -10,9 +10,8 @@
*/
WebInspector.CSSParser = function()
{
- this._worker = Runtime.startWorker("script_formatter_worker");
- this._worker.onmessage = this._onRuleChunk.bind(this);
this._rules = [];
+ Runtime.startWorker("script_formatter_worker").then(this._init.bind(this));
}
WebInspector.CSSParser.Events = {
@@ -20,6 +19,17 @@ WebInspector.CSSParser.Events = {
}
WebInspector.CSSParser.prototype = {
+ _init: function(worker)
pfeldman 2014/11/07 14:51:17 Here and in other _inits, please annotate worker.
apavlov 2014/11/10 07:44:11 Done.
+ {
+ this._worker = worker;
+ if (this._disposed) {
+ this.dispose();
+ return;
+ }
+ this._worker.onmessage = this._onRuleChunk.bind(this);
+ this._parseStoredText();
+ },
+
/**
* @param {!WebInspector.CSSStyleSheetHeader} styleSheetHeader
* @param {function(!Array.<!WebInspector.CSSParser.Rule>)=} callback
@@ -47,6 +57,8 @@ WebInspector.CSSParser.prototype = {
if (this._worker) {
this._worker.terminate();
delete this._worker;
+ } else {
+ this._disposed = true;
}
},
@@ -74,8 +86,18 @@ WebInspector.CSSParser.prototype = {
*/
_innerParse: function(text)
{
+ this._text = text;
+ if (this._worker)
+ this._parseStoredText();
+ },
+
+ _parseStoredText: function()
+ {
+ if (this._text === undefined)
+ return;
this._rules = [];
- this._worker.postMessage({ method: "parseCSS", params: { content: text } });
+ this._worker.postMessage({ method: "parseCSS", params: { content: this._text } });
+ delete this._text;
},
/**

Powered by Google App Engine
This is Rietveld 408576698