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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 }, 550 },
551 551
552 /** 552 /**
553 * @param {!CSSAgent.StyleSheetId} styleSheetId 553 * @param {!CSSAgent.StyleSheetId} styleSheetId
554 * @param {string} newText 554 * @param {string} newText
555 * @param {boolean} majorChange 555 * @param {boolean} majorChange
556 * @param {function(?Protocol.Error)} userCallback 556 * @param {function(?Protocol.Error)} userCallback
557 */ 557 */
558 setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback ) 558 setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback )
559 { 559 {
560 var header = this._styleSheetIdToHeader[styleSheetId];
561 console.assert(header);
562 this._pendingCommandsMajorState.push(majorChange);
563 header.setContent(styleSheetId, newText, callback.bind(this));
564
560 /** 565 /**
561 * @param {?Protocol.Error} error 566 * @param {?Protocol.Error} error
562 * @this {WebInspector.CSSStyleModel} 567 * @this {WebInspector.CSSStyleModel}
563 */ 568 */
564 function callback(error) 569 function callback(error)
565 { 570 {
566 this._pendingCommandsMajorState.pop(); 571 this._pendingCommandsMajorState.pop();
567 if (!error && majorChange) 572 if (!error && majorChange)
568 WebInspector.domAgent.markUndoableState(); 573 WebInspector.domAgent.markUndoableState();
569 574
570 if (!error && userCallback) 575 if (!error && userCallback)
571 userCallback(error); 576 userCallback(error);
572 } 577 }
573 this._pendingCommandsMajorState.push(majorChange);
574 CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this));
575 }, 578 },
576 579
577 _undoRedoRequested: function() 580 _undoRedoRequested: function()
578 { 581 {
579 this._pendingCommandsMajorState.push(true); 582 this._pendingCommandsMajorState.push(true);
580 }, 583 },
581 584
582 _undoRedoCompleted: function() 585 _undoRedoCompleted: function()
583 { 586 {
584 this._pendingCommandsMajorState.pop(); 587 this._pendingCommandsMajorState.pop();
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 this.disabled = payload.disabled; 1409 this.disabled = payload.disabled;
1407 this.isInline = payload.isInline; 1410 this.isInline = payload.isInline;
1408 this.startLine = payload.startLine; 1411 this.startLine = payload.startLine;
1409 this.startColumn = payload.startColumn; 1412 this.startColumn = payload.startColumn;
1410 /** @type {!Set.<!WebInspector.CSSStyleModel.LiveLocation>} */ 1413 /** @type {!Set.<!WebInspector.CSSStyleModel.LiveLocation>} */
1411 this._locations = new Set(); 1414 this._locations = new Set();
1412 /** @type {!Array.<!WebInspector.SourceMapping>} */ 1415 /** @type {!Array.<!WebInspector.SourceMapping>} */
1413 this._sourceMappings = []; 1416 this._sourceMappings = [];
1414 } 1417 }
1415 1418
1419 WebInspector.CSSStyleSheetHeader.sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]so urceURL=[\040\t]*([^\s]*)[\040\t]*\*\/[\040\t]*$/m;
apavlov 2013/12/20 10:06:25 Perhaps, \n -> ^ in the multiline mode? (this may
1420
1416 WebInspector.CSSStyleSheetHeader.prototype = { 1421 WebInspector.CSSStyleSheetHeader.prototype = {
1417 /** 1422 /**
1418 * @return {string} 1423 * @return {string}
1419 */ 1424 */
1420 resourceURL: function() 1425 resourceURL: function()
1421 { 1426 {
1422 return this.origin === "inspector" ? this._viaInspectorResourceURL() : t his.sourceURL; 1427 return this.origin === "inspector" ? this._viaInspectorResourceURL() : t his.sourceURL;
1423 }, 1428 },
1424 1429
1425 /** 1430 /**
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 * @param {number} columnNumberInStyleSheet 1511 * @param {number} columnNumberInStyleSheet
1507 * @return {number|undefined} 1512 * @return {number|undefined}
1508 */ 1513 */
1509 columnNumberInSource: function(lineNumberInStyleSheet, columnNumberInStyleSh eet) 1514 columnNumberInSource: function(lineNumberInStyleSheet, columnNumberInStyleSh eet)
1510 { 1515 {
1511 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInS tyleSheet; 1516 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInS tyleSheet;
1512 }, 1517 },
1513 1518
1514 /** 1519 /**
1515 * @override 1520 * @override
1521 * @return {string}
1516 */ 1522 */
1517 contentURL: function() 1523 contentURL: function()
1518 { 1524 {
1519 return this.resourceURL(); 1525 return this.resourceURL();
1520 }, 1526 },
1521 1527
1522 /** 1528 /**
1523 * @override 1529 * @override
1530 * @return {!WebInspector.ResourceType}
1524 */ 1531 */
1525 contentType: function() 1532 contentType: function()
1526 { 1533 {
1527 return WebInspector.resourceTypes.Stylesheet; 1534 return WebInspector.resourceTypes.Stylesheet;
1528 }, 1535 },
1529 1536
1530 /** 1537 /**
1531 * @override 1538 * @override
1539 * @param {function(?string)} callback
1532 */ 1540 */
1533 requestContent: function(callback) 1541 requestContent: function(callback)
1534 { 1542 {
1535 CSSAgent.getStyleSheetText(this.id, textCallback.bind(this)); 1543 CSSAgent.getStyleSheetText(this.id, textCallback.bind(this));
1536 1544
1537 /** 1545 /**
1538 * @this {WebInspector.CSSStyleSheetHeader} 1546 * @this {WebInspector.CSSStyleSheetHeader}
1539 */ 1547 */
1540 function textCallback(error, text) 1548 function textCallback(error, text)
1541 { 1549 {
1542 if (error) { 1550 if (error) {
1543 WebInspector.log("Failed to get text for stylesheet " + this.id + ": " + error); 1551 WebInspector.log("Failed to get text for stylesheet " + this.id + ": " + error);
1544 text = ""; 1552 text = "";
1545 // Fall through. 1553 // Fall through.
1546 } 1554 }
1555 text = text.replace(WebInspector.CSSStyleSheetHeader.sourceURLRegex, "");
1547 callback(text); 1556 callback(text);
1548 } 1557 }
1549 }, 1558 },
1550 1559
1551 /** 1560 /**
1552 * @override 1561 * @override
1553 */ 1562 */
1554 searchInContent: function(query, caseSensitive, isRegex, callback) 1563 searchInContent: function(query, caseSensitive, isRegex, callback)
1555 { 1564 {
1556 function performSearch(content) 1565 function performSearch(content)
1557 { 1566 {
1558 callback(WebInspector.ContentProvider.performSearchInContent(content , query, caseSensitive, isRegex)); 1567 callback(WebInspector.ContentProvider.performSearchInContent(content , query, caseSensitive, isRegex));
1559 } 1568 }
1560 1569
1561 // searchInContent should call back later. 1570 // searchInContent should call back later.
1562 this.requestContent(performSearch); 1571 this.requestContent(performSearch);
1563 } 1572 },
1573
1574 /**
1575 * @param {!CSSAgent.StyleSheetId} styleSheetId
1576 * @param {string} newText
1577 * @param {function(?Protocol.Error)} callback
1578 */
1579 setContent: function(styleSheetId, newText, callback)
1580 {
1581 var regex = WebInspector.CSSStyleSheetHeader.sourceURLRegex;
apavlov 2013/12/20 10:06:25 This can be inlined, since regex is used only once
1582 if (this.hasSourceURL && !regex.exec(newText))
apavlov 2013/12/20 10:06:25 exec->test
1583 newText += "\n/*# sourceURL=" + this.sourceURL + " */";
1584 CSSAgent.setStyleSheetText(styleSheetId, newText, callback);
1585 },
1564 } 1586 }
1565 1587
1566 /** 1588 /**
1567 * @constructor 1589 * @constructor
1568 * @param {!CSSAgent.StyleSheetId} styleSheetId 1590 * @param {!CSSAgent.StyleSheetId} styleSheetId
1569 * @param {!Array.<!CSSAgent.CSSRule>} payload 1591 * @param {!Array.<!CSSAgent.CSSRule>} payload
1570 */ 1592 */
1571 WebInspector.CSSStyleSheet = function(styleSheetId, payload) 1593 WebInspector.CSSStyleSheet = function(styleSheetId, payload)
1572 { 1594 {
1573 this.id = styleSheetId; 1595 this.id = styleSheetId;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 for (var i = 0; i < callbacks.length; ++i) 1821 for (var i = 0; i < callbacks.length; ++i)
1800 callbacks[i](computedStyle); 1822 callbacks[i](computedStyle);
1801 } 1823 }
1802 } 1824 }
1803 } 1825 }
1804 1826
1805 /** 1827 /**
1806 * @type {!WebInspector.CSSStyleModel} 1828 * @type {!WebInspector.CSSStyleModel}
1807 */ 1829 */
1808 WebInspector.cssModel; 1830 WebInspector.cssModel;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698