Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js b/third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js |
| index daa1d5388ceaa1437f6bf2f279a4a644fe545e8e..ca9c69f360d277171a41867412f2b065a5b41271 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js |
| @@ -685,13 +685,6 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| constructor() { |
| super(); |
| - /** @type {!Set<string>} */ |
| - this._blockedURLs = new Set(); |
| - this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); |
| - this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); |
| - this._blockedSetting.set([]); |
| - this._updateBlockedURLs(); |
| - |
| this._userAgentOverride = ''; |
| this._isRequestBlockingEnabled = false; |
| /** @type {!Set<!Protocol.NetworkAgent>} */ |
| @@ -699,6 +692,13 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| /** @type {!SDK.NetworkManager.Conditions} */ |
| this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; |
| + /** @type {!Set<string>} */ |
|
allada
2017/02/16 22:14:49
This was moved because this._agents is needed in _
|
| + this._blockedURLs = new Set(); |
| + this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); |
| + this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); |
| + this._blockedSetting.set([]); |
| + this._updateBlockedURLs(); |
| + |
| SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); |
| } |
| @@ -725,8 +725,8 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| networkAgent.setExtraHTTPHeaders(this._extraHeaders); |
| if (this._currentUserAgent()) |
| networkAgent.setUserAgentOverride(this._currentUserAgent()); |
| - for (var url of this._blockedURLs) |
| - networkAgent.addBlockedURL(url); |
| + if (this._isRequestBlockingEnabled) |
| + networkAgent.setBlockedURLs(this._blockedURLs.valuesArray()); |
| this._agents.add(networkAgent); |
| if (this.isThrottling()) |
| this._updateNetworkConditions(networkAgent); |
| @@ -836,16 +836,18 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| this._updateUserAgentOverride(); |
| } |
| + _updateBackendBlockedURLs() { |
| + var urls = /** @type {!Array<string>} */ ([]); |
| + if (this._isRequestBlockingEnabled) |
| + urls = this._blockedURLs.valuesArray(); |
| + for (var agent of this._agents) |
| + agent.setBlockedURLs(urls); |
| + } |
| + |
| _updateBlockedURLs() { |
| var blocked = this._blockedSetting.get(); |
| - for (var url of blocked) { |
| - if (!this._blockedURLs.has(url)) |
| - this._addBlockedURL(url); |
| - } |
| - for (var url of this._blockedURLs) { |
| - if (blocked.indexOf(url) === -1) |
| - this._removeBlockedURL(url); |
| - } |
| + this._blockedURLs = new Set(blocked); |
| + this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
inline backend update into this method.
allada
2017/02/17 00:58:06
Done.
|
| } |
| /** |
| @@ -853,10 +855,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| */ |
| _addBlockedURL(url) { |
| this._blockedURLs.add(url); |
|
pfeldman
2017/02/16 22:29:24
var blockedURLs = this._blockedSetting.get();
bloc
allada
2017/02/17 00:58:06
Done.
|
| - if (!this._isRequestBlockingEnabled) |
| - return; |
| - for (var agent of this._agents) |
| - agent.addBlockedURL(url); |
| + this._updateBackendBlockedURLs(); |
| } |
| /** |
| @@ -864,10 +863,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| */ |
| _removeBlockedURL(url) { |
| this._blockedURLs.delete(url); |
| - if (!this._isRequestBlockingEnabled) |
| - return; |
| - for (var agent of this._agents) |
| - agent.removeBlockedURL(url); |
| + this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
var blockedURLs = this._blockedSetting.get();
bloc
allada
2017/02/17 00:58:06
Done.
|
| } |
| /** |
| @@ -877,13 +873,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| if (this._isRequestBlockingEnabled === enabled) |
| return; |
| this._isRequestBlockingEnabled = enabled; |
| - if (enabled) { |
| - for (var agent of this._agents) |
| - this._blockedURLs.forEach(url => agent.addBlockedURL(url)); |
| - } else { |
| - for (var agent of this._agents) |
| - this._blockedURLs.forEach(url => agent.removeBlockedURL(url)); |
| - } |
| + this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
_updateBlockedURLs()
allada
2017/02/17 00:58:06
Done.
|
| this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent()); |
| } |