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..8a047731563c2e7678b80bc2b6d4f76a3612e1cf 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>} */ |
| + this._blockedURLs = new Set(); |
|
pfeldman
2017/02/21 23:59:01
Why duping the data, just keep the setting array.
|
| + 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); |
| @@ -837,15 +837,12 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| } |
| _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(this._blockedSetting.get()); |
|
pfeldman
2017/02/21 23:59:01
this would become a local variable.
|
| + var urls = /** @type {!Array<string>} */ ([]); |
| + if (this._isRequestBlockingEnabled) |
| + urls = this._blockedURLs.valuesArray(); |
| + for (var agent of this._agents) |
| + agent.setBlockedURLs(urls); |
| } |
| /** |
| @@ -853,10 +850,7 @@ SDK.MultitargetNetworkManager = class extends Common.Object { |
| */ |
| _addBlockedURL(url) { |
| this._blockedURLs.add(url); |
| - if (!this._isRequestBlockingEnabled) |
| - return; |
| - for (var agent of this._agents) |
| - agent.addBlockedURL(url); |
| + this._blockedSetting.set(this._blockedURLs.valuesArray()); |
| } |
| /** |
| @@ -864,10 +858,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._blockedSetting.set(this._blockedURLs.valuesArray()); |
| } |
| /** |
| @@ -877,13 +868,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._updateBlockedURLs(); |
| this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent()); |
| } |