Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
04b015e
use styleSheetAdded and styleSheetRemoved to replace deleted getAllSt…
jasonsanjose Feb 26, 2014
e2ef6eb
fix related doc ref count errors
jasonsanjose Feb 26, 2014
0905ca4
fallback to getAllStyleSheets if available
jasonsanjose Feb 26, 2014
02e2b10
add error handling when getAllStyleSheets is not found in inspector p…
jasonsanjose Feb 26, 2014
ab40ce0
do not change live dev status for inspector errors
jasonsanjose Feb 26, 2014
d2a8a82
account for styleSheetId changes after a CSSDocument reloads
jasonsanjose Feb 27, 2014
87bb739
remove styleSheetRemoved handler. handle weird chrome behavior where …
jasonsanjose Feb 27, 2014
24d3cf2
fix jslint error. Fix getSourceFromBrowser response. Remove debounce …
jasonsanjose Feb 28, 2014
8af9aee
fix failing unit tests. restore CSSDocument initial call to _updateBr…
jasonsanjose Feb 28, 2014
24a3969
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
jasonsanjose Feb 28, 2014
cbe4b09
remove extraneous reject for _openDeferred
jasonsanjose Feb 28, 2014
190f437
Ignore LiveDevelopment.close() if not active
jasonsanjose Feb 28, 2014
d2b33f5
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
redmunds Feb 28, 2014
4ac3e07
Merge branch 'jasonsanjose/issue-6830' of https://github.com/adobe/br…
redmunds Feb 28, 2014
00dde93
code review comments
jasonsanjose Mar 4, 2014
85b5d8c
Merge branch 'jasonsanjose/issue-6830' of https://github.com/adobe/br…
jasonsanjose Mar 4, 2014
d1a6752
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
jasonsanjose Mar 4, 2014
3cee9fe
fix async call to getLiveDocForPath
jasonsanjose Mar 4, 2014
ac80eca
update unit test spy for API change
jasonsanjose Mar 5, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 70 additions & 23 deletions src/LiveDevelopment/Agents/CSSAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
/**
* CSSAgent keeps track of loaded style sheets and allows reloading them
* from a {Document}.
*
* CSSAgent dispatches styleSheetAdded and styleSheetRemoved events, passing
* the URL for the added/removed style sheet.
*/

define(function CSSAgent(require, exports, module) {
"use strict";

Expand All @@ -38,7 +40,12 @@ define(function CSSAgent(require, exports, module) {
var Inspector = require("LiveDevelopment/Inspector/Inspector");

var _load; // {$.Deferred} load promise
var _urlToStyle; // {url -> loaded} style definition

/** @type {Object.<string, CSS.CSSStyleSheetHeader>} */
var _urlToStyle;

/** @type {Object.<string, string>} */
var _styleSheetIdToUrl;

/**
* Create a canonicalized version of the given URL, stripping off query strings and hashes.
Expand All @@ -49,34 +56,29 @@ define(function CSSAgent(require, exports, module) {
return PathUtils.parseUrl(url).hrefNoSearch;
}

// WebInspector Event: Page.loadEventFired
function _onLoadEventFired(event, res) {
// res = {timestamp}
/**
* @private
* WebInspector Event: Page.frameNavigated
* @param {jQuery.Event} event
* @param {frame: Frame} res
*/
function _onFrameNavigated(event, res) {
// Clear maps when navigating to a new page
_urlToStyle = {};
Inspector.CSS.enable().done(function () {
Inspector.CSS.getAllStyleSheets(function onGetAllStyleSheets(res) {
var i, header;
for (i in res.headers) {
header = res.headers[i];
_urlToStyle[_canonicalize(header.sourceURL)] = header;
}
_load.resolve();
});
});
_styleSheetIdToUrl = {};
}

/** Get a style sheet for a url
* @param {string} url
*/
function styleForURL(url) {
if (_urlToStyle) {
return _urlToStyle[_canonicalize(url)];
}

return null;
return _urlToStyle[_canonicalize(url)];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since code no longer checks if (_urlToStyle) then _urlToStyle should be initialized to _urlToStyle = {} on line 43 to be safe. Same for _styleSheetIdToUrl.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

/** Get a list of all loaded stylesheet files by URL */
/**
* @deprecated Use styleSheetAdded and styleSheetRemoved events
* Get a list of all loaded stylesheet files by URL
*/
function getStylesheetURLs() {
var urls = [], url;
for (url in _urlToStyle) {
Expand Down Expand Up @@ -104,17 +106,62 @@ define(function CSSAgent(require, exports, module) {
console.assert(style, "Style Sheet for document not loaded: " + doc.url);
Inspector.CSS.setStyleSheetText(style.styleSheetId, "");
}

/**
* @private
* @param {jQuery.Event} event
* @param {header: CSSStyleSheetHeader}
*/
function _styleSheetAdded(event, res) {
if (!_urlToStyle) {
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the initialization: _urlToStyle = {} is done as mentioned in this comment, then no need to check if (!_urlToStyle) here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


var url = _canonicalize(res.header.sourceURL);

_urlToStyle[url] = res.header;
_styleSheetIdToUrl[res.header.styleSheetId] = url;

$(exports).triggerHandler("styleSheetAdded", [url]);
}

/**
* @private
* @param {jQuery.Event} event
* @param {styleSheetId: StyleSheetId}
*/
function _styleSheetRemoved(event, res) {
if (!_urlToStyle) {
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer necessary to check for existence of _urlToStyle object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


var url = _styleSheetIdToUrl[res.styleSheetId];

if (url) {
delete _urlToStyle[url];
}

delete _styleSheetIdToUrl[res.styleSheetId];

$(exports).triggerHandler("styleSheetRemoved", [url]);
}

/** Initialize the agent */
function load() {
_load = new $.Deferred();
$(Inspector.Page).on("loadEventFired.CSSAgent", _onLoadEventFired);
// "loading" is done when the domain is enabled
_load = Inspector.CSS.enable();

$(Inspector.Page).on("frameNavigated.CSSAgent", _onFrameNavigated);
$(Inspector.CSS).on("styleSheetAdded.CSSAgent", _styleSheetAdded);
$(Inspector.CSS).on("styleSheetRemoved.CSSAgent", _styleSheetRemoved);

return _load.promise();
}

/** Clean up */
function unload() {
$(Inspector.Page).off(".CSSAgent");
$(Inspector.CSS).off(".CSSAgent");
}

// Export public functions
Expand Down
Loading