Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 }; | 678 }; |
| 679 | 679 |
| 680 /** | 680 /** |
| 681 * @implements {SDK.TargetManager.Observer} | 681 * @implements {SDK.TargetManager.Observer} |
| 682 * @unrestricted | 682 * @unrestricted |
| 683 */ | 683 */ |
| 684 SDK.MultitargetNetworkManager = class extends Common.Object { | 684 SDK.MultitargetNetworkManager = class extends Common.Object { |
| 685 constructor() { | 685 constructor() { |
| 686 super(); | 686 super(); |
| 687 | 687 |
| 688 /** @type {!Set<string>} */ | |
| 689 this._blockedURLs = new Set(); | |
| 690 this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); | |
| 691 this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); | |
| 692 this._blockedSetting.set([]); | |
| 693 this._updateBlockedURLs(); | |
| 694 | |
| 695 this._userAgentOverride = ''; | 688 this._userAgentOverride = ''; |
| 696 this._isRequestBlockingEnabled = false; | 689 this._isRequestBlockingEnabled = false; |
| 697 /** @type {!Set<!Protocol.NetworkAgent>} */ | 690 /** @type {!Set<!Protocol.NetworkAgent>} */ |
| 698 this._agents = new Set(); | 691 this._agents = new Set(); |
| 699 /** @type {!SDK.NetworkManager.Conditions} */ | 692 /** @type {!SDK.NetworkManager.Conditions} */ |
| 700 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; | 693 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; |
| 701 | 694 |
| 695 /** @type {!Set<string>} */ | |
|
allada
2017/02/16 22:14:49
This was moved because this._agents is needed in _
| |
| 696 this._blockedURLs = new Set(); | |
| 697 this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); | |
| 698 this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); | |
| 699 this._blockedSetting.set([]); | |
| 700 this._updateBlockedURLs(); | |
| 701 | |
| 702 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); | 702 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); |
| 703 } | 703 } |
| 704 | 704 |
| 705 /** | 705 /** |
| 706 * @param {string} uaString | 706 * @param {string} uaString |
| 707 * @return {string} | 707 * @return {string} |
| 708 */ | 708 */ |
| 709 static patchUserAgentWithChromeVersion(uaString) { | 709 static patchUserAgentWithChromeVersion(uaString) { |
| 710 // Patches Chrome/CriOS version from user agent ("1.2.3.4" when user agent i s: "Chrome/1.2.3.4"). | 710 // Patches Chrome/CriOS version from user agent ("1.2.3.4" when user agent i s: "Chrome/1.2.3.4"). |
| 711 var chromeRegex = new RegExp('(?:^|\\W)Chrome/(\\S+)'); | 711 var chromeRegex = new RegExp('(?:^|\\W)Chrome/(\\S+)'); |
| 712 var chromeMatch = navigator.userAgent.match(chromeRegex); | 712 var chromeMatch = navigator.userAgent.match(chromeRegex); |
| 713 if (chromeMatch && chromeMatch.length > 1) | 713 if (chromeMatch && chromeMatch.length > 1) |
| 714 return String.sprintf(uaString, chromeMatch[1]); | 714 return String.sprintf(uaString, chromeMatch[1]); |
| 715 return uaString; | 715 return uaString; |
| 716 } | 716 } |
| 717 | 717 |
| 718 /** | 718 /** |
| 719 * @override | 719 * @override |
| 720 * @param {!SDK.Target} target | 720 * @param {!SDK.Target} target |
| 721 */ | 721 */ |
| 722 targetAdded(target) { | 722 targetAdded(target) { |
| 723 var networkAgent = target.networkAgent(); | 723 var networkAgent = target.networkAgent(); |
| 724 if (this._extraHeaders) | 724 if (this._extraHeaders) |
| 725 networkAgent.setExtraHTTPHeaders(this._extraHeaders); | 725 networkAgent.setExtraHTTPHeaders(this._extraHeaders); |
| 726 if (this._currentUserAgent()) | 726 if (this._currentUserAgent()) |
| 727 networkAgent.setUserAgentOverride(this._currentUserAgent()); | 727 networkAgent.setUserAgentOverride(this._currentUserAgent()); |
| 728 for (var url of this._blockedURLs) | 728 if (this._isRequestBlockingEnabled) |
| 729 networkAgent.addBlockedURL(url); | 729 networkAgent.setBlockedURLs(this._blockedURLs.valuesArray()); |
| 730 this._agents.add(networkAgent); | 730 this._agents.add(networkAgent); |
| 731 if (this.isThrottling()) | 731 if (this.isThrottling()) |
| 732 this._updateNetworkConditions(networkAgent); | 732 this._updateNetworkConditions(networkAgent); |
| 733 } | 733 } |
| 734 | 734 |
| 735 /** | 735 /** |
| 736 * @override | 736 * @override |
| 737 * @param {!SDK.Target} target | 737 * @param {!SDK.Target} target |
| 738 */ | 738 */ |
| 739 targetRemoved(target) { | 739 targetRemoved(target) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 } | 829 } |
| 830 | 830 |
| 831 /** | 831 /** |
| 832 * @param {string} userAgent | 832 * @param {string} userAgent |
| 833 */ | 833 */ |
| 834 setCustomUserAgentOverride(userAgent) { | 834 setCustomUserAgentOverride(userAgent) { |
| 835 this._customUserAgent = userAgent; | 835 this._customUserAgent = userAgent; |
| 836 this._updateUserAgentOverride(); | 836 this._updateUserAgentOverride(); |
| 837 } | 837 } |
| 838 | 838 |
| 839 _updateBackendBlockedURLs() { | |
| 840 var urls = /** @type {!Array<string>} */ ([]); | |
| 841 if (this._isRequestBlockingEnabled) | |
| 842 urls = this._blockedURLs.valuesArray(); | |
| 843 for (var agent of this._agents) | |
| 844 agent.setBlockedURLs(urls); | |
| 845 } | |
| 846 | |
| 839 _updateBlockedURLs() { | 847 _updateBlockedURLs() { |
| 840 var blocked = this._blockedSetting.get(); | 848 var blocked = this._blockedSetting.get(); |
| 841 for (var url of blocked) { | 849 this._blockedURLs = new Set(blocked); |
| 842 if (!this._blockedURLs.has(url)) | 850 this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
inline backend update into this method.
allada
2017/02/17 00:58:06
Done.
| |
| 843 this._addBlockedURL(url); | |
| 844 } | |
| 845 for (var url of this._blockedURLs) { | |
| 846 if (blocked.indexOf(url) === -1) | |
| 847 this._removeBlockedURL(url); | |
| 848 } | |
| 849 } | 851 } |
| 850 | 852 |
| 851 /** | 853 /** |
| 852 * @param {string} url | 854 * @param {string} url |
| 853 */ | 855 */ |
| 854 _addBlockedURL(url) { | 856 _addBlockedURL(url) { |
| 855 this._blockedURLs.add(url); | 857 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.
| |
| 856 if (!this._isRequestBlockingEnabled) | 858 this._updateBackendBlockedURLs(); |
| 857 return; | |
| 858 for (var agent of this._agents) | |
| 859 agent.addBlockedURL(url); | |
| 860 } | 859 } |
| 861 | 860 |
| 862 /** | 861 /** |
| 863 * @param {string} url | 862 * @param {string} url |
| 864 */ | 863 */ |
| 865 _removeBlockedURL(url) { | 864 _removeBlockedURL(url) { |
| 866 this._blockedURLs.delete(url); | 865 this._blockedURLs.delete(url); |
| 867 if (!this._isRequestBlockingEnabled) | 866 this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
var blockedURLs = this._blockedSetting.get();
bloc
allada
2017/02/17 00:58:06
Done.
| |
| 868 return; | |
| 869 for (var agent of this._agents) | |
| 870 agent.removeBlockedURL(url); | |
| 871 } | 867 } |
| 872 | 868 |
| 873 /** | 869 /** |
| 874 * @param {boolean} enabled | 870 * @param {boolean} enabled |
| 875 */ | 871 */ |
| 876 setRequestBlockingEnabled(enabled) { | 872 setRequestBlockingEnabled(enabled) { |
| 877 if (this._isRequestBlockingEnabled === enabled) | 873 if (this._isRequestBlockingEnabled === enabled) |
| 878 return; | 874 return; |
| 879 this._isRequestBlockingEnabled = enabled; | 875 this._isRequestBlockingEnabled = enabled; |
| 880 if (enabled) { | 876 this._updateBackendBlockedURLs(); |
|
pfeldman
2017/02/16 22:29:24
_updateBlockedURLs()
allada
2017/02/17 00:58:06
Done.
| |
| 881 for (var agent of this._agents) | |
| 882 this._blockedURLs.forEach(url => agent.addBlockedURL(url)); | |
| 883 } else { | |
| 884 for (var agent of this._agents) | |
| 885 this._blockedURLs.forEach(url => agent.removeBlockedURL(url)); | |
| 886 } | |
| 887 this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEve nt()); | 877 this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEve nt()); |
| 888 } | 878 } |
| 889 | 879 |
| 890 isRequestBlockingEnabled() { | 880 isRequestBlockingEnabled() { |
| 891 return this._isRequestBlockingEnabled; | 881 return this._isRequestBlockingEnabled; |
| 892 } | 882 } |
| 893 | 883 |
| 894 clearBrowserCache() { | 884 clearBrowserCache() { |
| 895 for (var agent of this._agents) | 885 for (var agent of this._agents) |
| 896 agent.clearBrowserCache(); | 886 agent.clearBrowserCache(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 UserAgentChanged: Symbol('UserAgentChanged') | 932 UserAgentChanged: Symbol('UserAgentChanged') |
| 943 }; | 933 }; |
| 944 | 934 |
| 945 /** @implements {Common.Emittable} */ | 935 /** @implements {Common.Emittable} */ |
| 946 SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent = class {}; | 936 SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent = class {}; |
| 947 | 937 |
| 948 /** | 938 /** |
| 949 * @type {!SDK.MultitargetNetworkManager} | 939 * @type {!SDK.MultitargetNetworkManager} |
| 950 */ | 940 */ |
| 951 SDK.multitargetNetworkManager; | 941 SDK.multitargetNetworkManager; |
| OLD | NEW |