This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Use styleSheetAdded and styleSheetRemoved, replaces getAllStylesheets #7008
Merged
Merged
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 e2ef6eb
fix related doc ref count errors
jasonsanjose 0905ca4
fallback to getAllStyleSheets if available
jasonsanjose 02e2b10
add error handling when getAllStyleSheets is not found in inspector p…
jasonsanjose ab40ce0
do not change live dev status for inspector errors
jasonsanjose d2a8a82
account for styleSheetId changes after a CSSDocument reloads
jasonsanjose 87bb739
remove styleSheetRemoved handler. handle weird chrome behavior where …
jasonsanjose 24d3cf2
fix jslint error. Fix getSourceFromBrowser response. Remove debounce …
jasonsanjose 8af9aee
fix failing unit tests. restore CSSDocument initial call to _updateBr…
jasonsanjose 24a3969
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
jasonsanjose cbe4b09
remove extraneous reject for _openDeferred
jasonsanjose 190f437
Ignore LiveDevelopment.close() if not active
jasonsanjose d2b33f5
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
redmunds 4ac3e07
Merge branch 'jasonsanjose/issue-6830' of https://github.com/adobe/br…
redmunds 00dde93
code review comments
jasonsanjose 85b5d8c
Merge branch 'jasonsanjose/issue-6830' of https://github.com/adobe/br…
jasonsanjose d1a6752
Merge remote-tracking branch 'origin/master' into jasonsanjose/issue-…
jasonsanjose 3cee9fe
fix async call to getLiveDocForPath
jasonsanjose ac80eca
update unit test spy for API change
jasonsanjose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
||
|
|
@@ -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. | ||
|
|
@@ -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)]; | ||
| } | ||
|
|
||
| /** 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) { | ||
|
|
@@ -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; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the initialization:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer necessary to check for existence of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_urlToStyleshould be initialized to_urlToStyle = {}on line 43 to be safe. Same for_styleSheetIdToUrl.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed