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

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: 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 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 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 * @param {number} columnNumberInStyleSheet 1509 * @param {number} columnNumberInStyleSheet
1507 * @return {number|undefined} 1510 * @return {number|undefined}
1508 */ 1511 */
1509 columnNumberInSource: function(lineNumberInStyleSheet, columnNumberInStyleSh eet) 1512 columnNumberInSource: function(lineNumberInStyleSheet, columnNumberInStyleSh eet)
1510 { 1513 {
1511 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInS tyleSheet; 1514 return (lineNumberInStyleSheet ? 0 : this.startColumn) + columnNumberInS tyleSheet;
1512 }, 1515 },
1513 1516
1514 /** 1517 /**
1515 * @override 1518 * @override
1519 * @return {string}
1516 */ 1520 */
1517 contentURL: function() 1521 contentURL: function()
1518 { 1522 {
1519 return this.resourceURL(); 1523 return this.resourceURL();
1520 }, 1524 },
1521 1525
1522 /** 1526 /**
1523 * @override 1527 * @override
1528 * @return {!WebInspector.ResourceType}
1524 */ 1529 */
1525 contentType: function() 1530 contentType: function()
1526 { 1531 {
1527 return WebInspector.resourceTypes.Stylesheet; 1532 return WebInspector.resourceTypes.Stylesheet;
1528 }, 1533 },
1529 1534
1530 /** 1535 /**
1536 * @param {string} text
1537 * @return {string}
1538 */
1539 _trimSourceURL: function(text)
1540 {
1541 var sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]sourceURL=[\040\t]*([^\ s]*)[\040\t]*\*\/[\040\t]*$/mg;
1542 return text.replace(sourceURLRegex, "");
1543 },
1544
1545 /**
1531 * @override 1546 * @override
1547 * @param {function(?string)} callback
1532 */ 1548 */
1533 requestContent: function(callback) 1549 requestContent: function(callback)
1534 { 1550 {
1535 CSSAgent.getStyleSheetText(this.id, textCallback.bind(this)); 1551 CSSAgent.getStyleSheetText(this.id, textCallback.bind(this));
1536 1552
1537 /** 1553 /**
1538 * @this {WebInspector.CSSStyleSheetHeader} 1554 * @this {WebInspector.CSSStyleSheetHeader}
1539 */ 1555 */
1540 function textCallback(error, text) 1556 function textCallback(error, text)
1541 { 1557 {
1542 if (error) { 1558 if (error) {
1543 WebInspector.log("Failed to get text for stylesheet " + this.id + ": " + error); 1559 WebInspector.log("Failed to get text for stylesheet " + this.id + ": " + error);
1544 text = ""; 1560 text = "";
1545 // Fall through. 1561 // Fall through.
1546 } 1562 }
1563 text = this._trimSourceURL(text);
1547 callback(text); 1564 callback(text);
1548 } 1565 }
1549 }, 1566 },
1550 1567
1551 /** 1568 /**
1552 * @override 1569 * @override
1553 */ 1570 */
1554 searchInContent: function(query, caseSensitive, isRegex, callback) 1571 searchInContent: function(query, caseSensitive, isRegex, callback)
1555 { 1572 {
1556 function performSearch(content) 1573 function performSearch(content)
1557 { 1574 {
1558 callback(WebInspector.ContentProvider.performSearchInContent(content , query, caseSensitive, isRegex)); 1575 callback(WebInspector.ContentProvider.performSearchInContent(content , query, caseSensitive, isRegex));
1559 } 1576 }
1560 1577
1561 // searchInContent should call back later. 1578 // searchInContent should call back later.
1562 this.requestContent(performSearch); 1579 this.requestContent(performSearch);
1563 } 1580 },
1581
1582 /**
1583 * @param {!CSSAgent.StyleSheetId} styleSheetId
1584 * @param {string} newText
1585 * @param {function(?Protocol.Error)} callback
1586 */
1587 setContent: function(styleSheetId, newText, callback)
1588 {
1589 newText = this._trimSourceURL(newText);
1590 if (this.hasSourceURL)
1591 newText += "\n/*# sourceURL=" + this.sourceURL + " */";
1592 CSSAgent.setStyleSheetText(styleSheetId, newText, callback);
1593 },
1564 } 1594 }
1565 1595
1566 /** 1596 /**
1567 * @constructor 1597 * @constructor
1568 * @param {!CSSAgent.StyleSheetId} styleSheetId 1598 * @param {!CSSAgent.StyleSheetId} styleSheetId
1569 * @param {!Array.<!CSSAgent.CSSRule>} payload 1599 * @param {!Array.<!CSSAgent.CSSRule>} payload
1570 */ 1600 */
1571 WebInspector.CSSStyleSheet = function(styleSheetId, payload) 1601 WebInspector.CSSStyleSheet = function(styleSheetId, payload)
1572 { 1602 {
1573 this.id = styleSheetId; 1603 this.id = styleSheetId;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 for (var i = 0; i < callbacks.length; ++i) 1829 for (var i = 0; i < callbacks.length; ++i)
1800 callbacks[i](computedStyle); 1830 callbacks[i](computedStyle);
1801 } 1831 }
1802 } 1832 }
1803 } 1833 }
1804 1834
1805 /** 1835 /**
1806 * @type {!WebInspector.CSSStyleModel} 1836 * @type {!WebInspector.CSSStyleModel}
1807 */ 1837 */
1808 WebInspector.cssModel; 1838 WebInspector.cssModel;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698