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._updateBlockedURLs(); | |
693 | |
694 this._userAgentOverride = ''; | 688 this._userAgentOverride = ''; |
695 this._isRequestBlockingEnabled = false; | 689 this._isRequestBlockingEnabled = false; |
696 /** @type {!Set<!Protocol.NetworkAgent>} */ | 690 /** @type {!Set<!Protocol.NetworkAgent>} */ |
697 this._agents = new Set(); | 691 this._agents = new Set(); |
698 /** @type {!SDK.NetworkManager.Conditions} */ | 692 /** @type {!SDK.NetworkManager.Conditions} */ |
699 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; | 693 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; |
700 | 694 |
| 695 this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); |
| 696 this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); |
| 697 this._blockedSetting.set([]); |
| 698 this._updateBlockedURLs(); |
| 699 |
701 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); | 700 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); |
702 } | 701 } |
703 | 702 |
704 /** | 703 /** |
705 * @param {string} uaString | 704 * @param {string} uaString |
706 * @return {string} | 705 * @return {string} |
707 */ | 706 */ |
708 static patchUserAgentWithChromeVersion(uaString) { | 707 static patchUserAgentWithChromeVersion(uaString) { |
709 // Patches Chrome/CriOS version from user agent ("1.2.3.4" when user agent i
s: "Chrome/1.2.3.4"). | 708 // Patches Chrome/CriOS version from user agent ("1.2.3.4" when user agent i
s: "Chrome/1.2.3.4"). |
710 var chromeRegex = new RegExp('(?:^|\\W)Chrome/(\\S+)'); | 709 var chromeRegex = new RegExp('(?:^|\\W)Chrome/(\\S+)'); |
711 var chromeMatch = navigator.userAgent.match(chromeRegex); | 710 var chromeMatch = navigator.userAgent.match(chromeRegex); |
712 if (chromeMatch && chromeMatch.length > 1) | 711 if (chromeMatch && chromeMatch.length > 1) |
713 return String.sprintf(uaString, chromeMatch[1]); | 712 return String.sprintf(uaString, chromeMatch[1]); |
714 return uaString; | 713 return uaString; |
715 } | 714 } |
716 | 715 |
717 /** | 716 /** |
718 * @override | 717 * @override |
719 * @param {!SDK.Target} target | 718 * @param {!SDK.Target} target |
720 */ | 719 */ |
721 targetAdded(target) { | 720 targetAdded(target) { |
722 var networkAgent = target.networkAgent(); | 721 var networkAgent = target.networkAgent(); |
723 if (this._extraHeaders) | 722 if (this._extraHeaders) |
724 networkAgent.setExtraHTTPHeaders(this._extraHeaders); | 723 networkAgent.setExtraHTTPHeaders(this._extraHeaders); |
725 if (this._currentUserAgent()) | 724 if (this._currentUserAgent()) |
726 networkAgent.setUserAgentOverride(this._currentUserAgent()); | 725 networkAgent.setUserAgentOverride(this._currentUserAgent()); |
727 for (var url of this._blockedURLs) | 726 if (this._isRequestBlockingEnabled) |
728 networkAgent.addBlockedURL(url); | 727 networkAgent.setBlockedURLs(this._blockedSetting.get()); |
729 this._agents.add(networkAgent); | 728 this._agents.add(networkAgent); |
730 if (this.isThrottling()) | 729 if (this.isThrottling()) |
731 this._updateNetworkConditions(networkAgent); | 730 this._updateNetworkConditions(networkAgent); |
732 } | 731 } |
733 | 732 |
734 /** | 733 /** |
735 * @override | 734 * @override |
736 * @param {!SDK.Target} target | 735 * @param {!SDK.Target} target |
737 */ | 736 */ |
738 targetRemoved(target) { | 737 targetRemoved(target) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 828 |
830 /** | 829 /** |
831 * @param {string} userAgent | 830 * @param {string} userAgent |
832 */ | 831 */ |
833 setCustomUserAgentOverride(userAgent) { | 832 setCustomUserAgentOverride(userAgent) { |
834 this._customUserAgent = userAgent; | 833 this._customUserAgent = userAgent; |
835 this._updateUserAgentOverride(); | 834 this._updateUserAgentOverride(); |
836 } | 835 } |
837 | 836 |
838 _updateBlockedURLs() { | 837 _updateBlockedURLs() { |
839 var blocked = this._blockedSetting.get(); | 838 var urls = /** @type {!Array<string>} */ ([]); |
840 for (var url of blocked) { | 839 if (this._isRequestBlockingEnabled) |
841 if (!this._blockedURLs.has(url)) | 840 urls = this._blockedSetting.get(); |
842 this._addBlockedURL(url); | 841 for (var agent of this._agents) |
843 } | 842 agent.setBlockedURLs(urls); |
844 for (var url of this._blockedURLs) { | |
845 if (blocked.indexOf(url) === -1) | |
846 this._removeBlockedURL(url); | |
847 } | |
848 } | 843 } |
849 | 844 |
850 /** | 845 /** |
851 * @param {string} url | |
852 */ | |
853 _addBlockedURL(url) { | |
854 this._blockedURLs.add(url); | |
855 if (!this._isRequestBlockingEnabled) | |
856 return; | |
857 for (var agent of this._agents) | |
858 agent.addBlockedURL(url); | |
859 } | |
860 | |
861 /** | |
862 * @param {string} url | |
863 */ | |
864 _removeBlockedURL(url) { | |
865 this._blockedURLs.delete(url); | |
866 if (!this._isRequestBlockingEnabled) | |
867 return; | |
868 for (var agent of this._agents) | |
869 agent.removeBlockedURL(url); | |
870 } | |
871 | |
872 /** | |
873 * @param {boolean} enabled | 846 * @param {boolean} enabled |
874 */ | 847 */ |
875 setRequestBlockingEnabled(enabled) { | 848 setRequestBlockingEnabled(enabled) { |
876 if (this._isRequestBlockingEnabled === enabled) | 849 if (this._isRequestBlockingEnabled === enabled) |
877 return; | 850 return; |
878 this._isRequestBlockingEnabled = enabled; | 851 this._isRequestBlockingEnabled = enabled; |
879 if (enabled) { | 852 this._updateBlockedURLs(); |
880 for (var agent of this._agents) | |
881 this._blockedURLs.forEach(url => agent.addBlockedURL(url)); | |
882 } else { | |
883 for (var agent of this._agents) | |
884 this._blockedURLs.forEach(url => agent.removeBlockedURL(url)); | |
885 } | |
886 this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEve
nt()); | 853 this.emit(new SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEve
nt()); |
887 } | 854 } |
888 | 855 |
889 isRequestBlockingEnabled() { | 856 isRequestBlockingEnabled() { |
890 return this._isRequestBlockingEnabled; | 857 return this._isRequestBlockingEnabled; |
891 } | 858 } |
892 | 859 |
893 clearBrowserCache() { | 860 clearBrowserCache() { |
894 for (var agent of this._agents) | 861 for (var agent of this._agents) |
895 agent.clearBrowserCache(); | 862 agent.clearBrowserCache(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 UserAgentChanged: Symbol('UserAgentChanged') | 908 UserAgentChanged: Symbol('UserAgentChanged') |
942 }; | 909 }; |
943 | 910 |
944 /** @implements {Common.Emittable} */ | 911 /** @implements {Common.Emittable} */ |
945 SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent = class {}; | 912 SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent = class {}; |
946 | 913 |
947 /** | 914 /** |
948 * @type {!SDK.MultitargetNetworkManager} | 915 * @type {!SDK.MultitargetNetworkManager} |
949 */ | 916 */ |
950 SDK.multitargetNetworkManager; | 917 SDK.multitargetNetworkManager; |
OLD | NEW |