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

Unified Diff: Source/devtools/front_end/CSSStyleModel.js

Issue 110223008: DevTools: Strip sourceURL comment from stylesheets before showing them in the editor. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Made regex global Created 7 years 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/CSSStyleModel.js
diff --git a/Source/devtools/front_end/CSSStyleModel.js b/Source/devtools/front_end/CSSStyleModel.js
index 19aa7f21b2434dc0e368746290798031b1fc5cea..ca4872ec698e8c4bf348e000ffbd1eac9d9b0f2c 100644
--- a/Source/devtools/front_end/CSSStyleModel.js
+++ b/Source/devtools/front_end/CSSStyleModel.js
@@ -557,6 +557,11 @@ WebInspector.CSSStyleModel.prototype = {
*/
setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback)
{
+ var header = this._styleSheetIdToHeader[styleSheetId];
+ console.assert(header);
+ this._pendingCommandsMajorState.push(majorChange);
+ header.setContent(styleSheetId, newText, callback.bind(this));
+
/**
* @param {?Protocol.Error} error
* @this {WebInspector.CSSStyleModel}
@@ -570,8 +575,6 @@ WebInspector.CSSStyleModel.prototype = {
if (!error && userCallback)
userCallback(error);
}
- this._pendingCommandsMajorState.push(majorChange);
- CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this));
},
_undoRedoRequested: function()
@@ -1513,6 +1516,7 @@ WebInspector.CSSStyleSheetHeader.prototype = {
/**
* @override
+ * @return {string}
*/
contentURL: function()
{
@@ -1521,6 +1525,7 @@ WebInspector.CSSStyleSheetHeader.prototype = {
/**
* @override
+ * @return {!WebInspector.ResourceType}
*/
contentType: function()
{
@@ -1528,7 +1533,18 @@ WebInspector.CSSStyleSheetHeader.prototype = {
},
/**
+ * @param {string} text
+ * @return {string}
+ */
+ _trimSourceURL: function(text)
+ {
+ var sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]sourceURL=[\040\t]*([^\s]*)[\040\t]*\*\/[\040\t]*$/mg;
+ return text.replace(sourceURLRegex, "");
+ },
+
+ /**
* @override
+ * @param {function(?string)} callback
*/
requestContent: function(callback)
{
@@ -1544,6 +1560,7 @@ WebInspector.CSSStyleSheetHeader.prototype = {
text = "";
// Fall through.
}
+ text = this._trimSourceURL(text);
callback(text);
}
},
@@ -1560,7 +1577,20 @@ WebInspector.CSSStyleSheetHeader.prototype = {
// searchInContent should call back later.
this.requestContent(performSearch);
- }
+ },
+
+ /**
+ * @param {!CSSAgent.StyleSheetId} styleSheetId
+ * @param {string} newText
+ * @param {function(?Protocol.Error)} callback
+ */
+ setContent: function(styleSheetId, newText, callback)
+ {
+ newText = this._trimSourceURL(newText);
+ if (this.hasSourceURL)
+ newText += "\n/*# sourceURL=" + this.sourceURL + " */";
+ CSSAgent.setStyleSheetText(styleSheetId, newText, callback);
+ },
}
/**

Powered by Google App Engine
This is Rietveld 408576698