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

Side by Side Diff: Source/devtools/front_end/SASSSourceMapping.js

Issue 13845021: DevTools: Bring Sass support from behind the experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Separate settings for CSS and JS source maps Created 7 years, 5 months 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 26 matching lines...) Expand all
37 */ 37 */
38 WebInspector.SASSSourceMapping = function(cssModel, workspace, networkWorkspaceP rovider) 38 WebInspector.SASSSourceMapping = function(cssModel, workspace, networkWorkspaceP rovider)
39 { 39 {
40 this.pollPeriodMs = 5000; 40 this.pollPeriodMs = 5000;
41 this.pollIntervalMs = 200; 41 this.pollIntervalMs = 200;
42 42
43 this._cssModel = cssModel; 43 this._cssModel = cssModel;
44 this._workspace = workspace; 44 this._workspace = workspace;
45 this._networkWorkspaceProvider = networkWorkspaceProvider; 45 this._networkWorkspaceProvider = networkWorkspaceProvider;
46 this._addingRevisionCounter = 0; 46 this._addingRevisionCounter = 0;
47 this._mappingsEnabled = WebInspector.settings.cssSourceMapsEnabled.get();
vsevik 2013/07/12 13:07:08 not needed
47 this._reset(); 48 this._reset();
48 WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventType s.SavedURL, this._fileSaveFinished, this); 49 WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventType s.SavedURL, this._fileSaveFinished, this);
50 WebInspector.settings.cssSourceMapsEnabled.addChangeListener(this._toggleSou rceMapSupport, this)
49 this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheet Changed, this._styleSheetChanged, this); 51 this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheet Changed, this._styleSheetChanged, this);
50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this); 52 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this);
51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeC ontentCommitted, this._uiSourceCodeContentCommitted, this); 53 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeC ontentCommitted, this._uiSourceCodeContentCommitted, this);
52 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._reset, this); 54 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._reset, this);
53 } 55 }
54 56
55 WebInspector.SASSSourceMapping.prototype = { 57 WebInspector.SASSSourceMapping.prototype = {
56 /** 58 /**
57 * @param {WebInspector.Event} event 59 * @param {WebInspector.Event} event
58 */ 60 */
59 _styleSheetChanged: function(event) 61 _styleSheetChanged: function(event)
60 { 62 {
61 var id = /** @type {!CSSAgent.StyleSheetId} */ (event.data.styleSheetId) ; 63 var id = /** @type {!CSSAgent.StyleSheetId} */ (event.data.styleSheetId) ;
62 if (this._addingRevisionCounter) { 64 if (this._addingRevisionCounter) {
63 --this._addingRevisionCounter; 65 --this._addingRevisionCounter;
64 return; 66 return;
65 } 67 }
66 var header = this._cssModel.styleSheetHeaderForId(id); 68 var header = this._cssModel.styleSheetHeaderForId(id);
67 if (!header || !WebInspector.experimentsSettings.sass.isEnabled()) 69 if (!header)
68 return; 70 return;
69 71
70 var wasHeaderKnown = header.sourceURL && !!this._completeSourceMapURLFor CSSURL[header.sourceURL];
71 this.removeHeader(header); 72 this.removeHeader(header);
72 if (wasHeaderKnown)
73 header.updateLocations();
74 }, 73 },
75 74
76 /** 75 /**
76 * @param {WebInspector.Event} event
77 */
78 _toggleSourceMapSupport: function(event)
79 {
80 var enabled = /** @type {boolean} */ (event.data);
81 if (enabled === this._mappingsEnabled)
82 return;
83 this._mappingsEnabled = enabled;
84 var headers = this._cssModel.styleSheetHeaders();
85 for (var i = 0; i < headers.length; ++i) {
86 if (enabled)
87 this.addHeader(headers[i]);
88 else
89 this.removeHeader(headers[i]);
90 }
91 },
92
93 /**
77 * @param {WebInspector.Event} event 94 * @param {WebInspector.Event} event
78 */ 95 */
79 _fileSaveFinished: function(event) 96 _fileSaveFinished: function(event)
80 { 97 {
81 var sassURL = /** @type {string} */ (event.data); 98 var sassURL = /** @type {string} */ (event.data);
82 this._sassFileSaved(sassURL, false); 99 this._sassFileSaved(sassURL, false);
83 }, 100 },
84 101
85 /** 102 /**
86 * @param {string} headerName 103 * @param {string} headerName
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 for (var i = 0; i < ids.length; ++i) 379 for (var i = 0; i < ids.length; ++i)
363 this._loadSourceMapAndBindUISourceCode(headers, true, completeSource MapURL); 380 this._loadSourceMapAndBindUISourceCode(headers, true, completeSource MapURL);
364 callback(cssURL, sassURL, true); 381 callback(cssURL, sassURL, true);
365 }, 382 },
366 383
367 /** 384 /**
368 * @param {WebInspector.CSSStyleSheetHeader} header 385 * @param {WebInspector.CSSStyleSheetHeader} header
369 */ 386 */
370 addHeader: function(header) 387 addHeader: function(header)
371 { 388 {
372 if (!header.sourceMapURL || !header.sourceURL || header.isInline || !Web Inspector.experimentsSettings.sass.isEnabled()) 389 if (!header.sourceMapURL || !header.sourceURL || header.isInline || !Web Inspector.settings.cssSourceMapsEnabled.get())
373 return; 390 return;
374 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(header.sou rceURL, header.sourceMapURL); 391 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(header.sou rceURL, header.sourceMapURL);
375 if (!completeSourceMapURL) 392 if (!completeSourceMapURL)
376 return; 393 return;
377 this._completeSourceMapURLForCSSURL[header.sourceURL] = completeSourceMa pURL; 394 this._completeSourceMapURLForCSSURL[header.sourceURL] = completeSourceMa pURL;
378 this._loadSourceMapAndBindUISourceCode([header], false, completeSourceMa pURL); 395 this._loadSourceMapAndBindUISourceCode([header], false, completeSourceMa pURL);
379 }, 396 },
380 397
381 /** 398 /**
382 * @param {WebInspector.CSSStyleSheetHeader} header 399 * @param {WebInspector.CSSStyleSheetHeader} header
383 */ 400 */
384 removeHeader: function(header) 401 removeHeader: function(header)
385 { 402 {
386 var sourceURL = header.sourceURL; 403 var sourceURL = header.sourceURL;
387 if (!sourceURL || !header.sourceMapURL || header.isInline || !this._comp leteSourceMapURLForCSSURL[sourceURL]) 404 if (!sourceURL || !header.sourceMapURL || header.isInline || !this._comp leteSourceMapURLForCSSURL[sourceURL])
388 return; 405 return;
389 delete this._sourceMapByStyleSheetURL[sourceURL]; 406 delete this._sourceMapByStyleSheetURL[sourceURL];
390 delete this._completeSourceMapURLForCSSURL[sourceURL]; 407 delete this._completeSourceMapURLForCSSURL[sourceURL];
391 for (var sassURL in this._cssURLsForSASSURL) { 408 for (var sassURL in this._cssURLsForSASSURL) {
392 var urls = this._cssURLsForSASSURL[sassURL]; 409 var urls = this._cssURLsForSASSURL[sassURL];
393 urls.remove(sourceURL); 410 urls.remove(sourceURL);
394 if (!urls.length) 411 if (!urls.length)
395 delete this._cssURLsForSASSURL[sassURL]; 412 delete this._cssURLsForSASSURL[sassURL];
396 } 413 }
397 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(sourceURL, header.sourceMapURL); 414 var completeSourceMapURL = WebInspector.ParsedURL.completeURL(sourceURL, header.sourceMapURL);
398 if (completeSourceMapURL) 415 if (completeSourceMapURL)
399 delete this._sourceMapByURL[completeSourceMapURL]; 416 delete this._sourceMapByURL[completeSourceMapURL];
417 header.updateLocations();
400 }, 418 },
401 419
402 /** 420 /**
403 * @param {Array.<WebInspector.CSSStyleSheetHeader>} headersWithSameSourceUR L 421 * @param {Array.<WebInspector.CSSStyleSheetHeader>} headersWithSameSourceUR L
404 * @param {boolean} forceRebind 422 * @param {boolean} forceRebind
405 * @param {string} completeSourceMapURL 423 * @param {string} completeSourceMapURL
406 */ 424 */
407 _loadSourceMapAndBindUISourceCode: function(headersWithSameSourceURL, forceR ebind, completeSourceMapURL) 425 _loadSourceMapAndBindUISourceCode: function(headersWithSameSourceURL, forceR ebind, completeSourceMapURL)
408 { 426 {
409 console.assert(headersWithSameSourceURL.length); 427 console.assert(headersWithSameSourceURL.length);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 this._cssURLsForSASSURL = {}; 603 this._cssURLsForSASSURL = {};
586 /** @type {Object.<string, Array.<function(?WebInspector.SourceMap)>>} * / 604 /** @type {Object.<string, Array.<function(?WebInspector.SourceMap)>>} * /
587 this._pendingSourceMapLoadingCallbacks = {}; 605 this._pendingSourceMapLoadingCallbacks = {};
588 /** @type {Object.<string, {deadlineMs: number, dataByURL: Object.<strin g, {timer: number, previousPoll: number}>}>} */ 606 /** @type {Object.<string, {deadlineMs: number, dataByURL: Object.<strin g, {timer: number, previousPoll: number}>}>} */
589 this._pollDataForSASSURL = {}; 607 this._pollDataForSASSURL = {};
590 /** @type {Object.<string, WebInspector.SourceMap>} */ 608 /** @type {Object.<string, WebInspector.SourceMap>} */
591 this._sourceMapByURL = {}; 609 this._sourceMapByURL = {};
592 this._sourceMapByStyleSheetURL = {}; 610 this._sourceMapByStyleSheetURL = {};
593 } 611 }
594 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698