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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 super(); | 686 super(); |
687 | 687 |
688 /** @type {!Set<string>} */ | 688 /** @type {!Set<string>} */ |
689 this._blockedURLs = new Set(); | 689 this._blockedURLs = new Set(); |
690 this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); | 690 this._blockedSetting = Common.moduleSetting('networkBlockedURLs'); |
691 this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); | 691 this._blockedSetting.addChangeListener(this._updateBlockedURLs, this); |
692 this._blockedSetting.set([]); | 692 this._blockedSetting.set([]); |
693 this._updateBlockedURLs(); | 693 this._updateBlockedURLs(); |
694 | 694 |
695 this._userAgentOverride = ''; | 695 this._userAgentOverride = ''; |
| 696 this._isRequestBlockingEnabled = false; |
696 /** @type {!Set<!Protocol.NetworkAgent>} */ | 697 /** @type {!Set<!Protocol.NetworkAgent>} */ |
697 this._agents = new Set(); | 698 this._agents = new Set(); |
698 /** @type {!SDK.NetworkManager.Conditions} */ | 699 /** @type {!SDK.NetworkManager.Conditions} */ |
699 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; | 700 this._networkConditions = SDK.NetworkManager.NoThrottlingConditions; |
700 | 701 |
701 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); | 702 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Network); |
702 } | 703 } |
703 | 704 |
704 /** | 705 /** |
705 * @param {string} uaString | 706 * @param {string} uaString |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 if (blocked.indexOf(url) === -1) | 846 if (blocked.indexOf(url) === -1) |
846 this._removeBlockedURL(url); | 847 this._removeBlockedURL(url); |
847 } | 848 } |
848 } | 849 } |
849 | 850 |
850 /** | 851 /** |
851 * @param {string} url | 852 * @param {string} url |
852 */ | 853 */ |
853 _addBlockedURL(url) { | 854 _addBlockedURL(url) { |
854 this._blockedURLs.add(url); | 855 this._blockedURLs.add(url); |
| 856 if (!this._isRequestBlockingEnabled) |
| 857 return; |
855 for (var agent of this._agents) | 858 for (var agent of this._agents) |
856 agent.addBlockedURL(url); | 859 agent.addBlockedURL(url); |
857 } | 860 } |
858 | 861 |
859 /** | 862 /** |
860 * @param {string} url | 863 * @param {string} url |
861 */ | 864 */ |
862 _removeBlockedURL(url) { | 865 _removeBlockedURL(url) { |
863 this._blockedURLs.delete(url); | 866 this._blockedURLs.delete(url); |
| 867 if (!this._isRequestBlockingEnabled) |
| 868 return; |
864 for (var agent of this._agents) | 869 for (var agent of this._agents) |
865 agent.removeBlockedURL(url); | 870 agent.removeBlockedURL(url); |
866 } | 871 } |
867 | 872 |
| 873 /** |
| 874 * @param {boolean} enabled |
| 875 */ |
| 876 setRequestBlockingEnabled(enabled) { |
| 877 if (this._isRequestBlockingEnabled === enabled) |
| 878 return; |
| 879 this._isRequestBlockingEnabled = enabled; |
| 880 if (enabled) { |
| 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()); |
| 888 } |
| 889 |
| 890 isRequestBlockingEnabled() { |
| 891 return this._isRequestBlockingEnabled; |
| 892 } |
| 893 |
868 clearBrowserCache() { | 894 clearBrowserCache() { |
869 for (var agent of this._agents) | 895 for (var agent of this._agents) |
870 agent.clearBrowserCache(); | 896 agent.clearBrowserCache(); |
871 } | 897 } |
872 | 898 |
873 clearBrowserCookies() { | 899 clearBrowserCookies() { |
874 for (var agent of this._agents) | 900 for (var agent of this._agents) |
875 agent.clearBrowserCookies(); | 901 agent.clearBrowserCookies(); |
876 } | 902 } |
877 | 903 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 Host.ResourceLoader.load(url, headers, callback); | 935 Host.ResourceLoader.load(url, headers, callback); |
910 } | 936 } |
911 }; | 937 }; |
912 | 938 |
913 /** @enum {symbol} */ | 939 /** @enum {symbol} */ |
914 SDK.MultitargetNetworkManager.Events = { | 940 SDK.MultitargetNetworkManager.Events = { |
915 ConditionsChanged: Symbol('ConditionsChanged'), | 941 ConditionsChanged: Symbol('ConditionsChanged'), |
916 UserAgentChanged: Symbol('UserAgentChanged') | 942 UserAgentChanged: Symbol('UserAgentChanged') |
917 }; | 943 }; |
918 | 944 |
| 945 /** @implements {Common.Emittable} */ |
| 946 SDK.MultitargetNetworkManager.RequestBlockingEnabledChangedEvent = class {}; |
919 | 947 |
920 /** | 948 /** |
921 * @type {!SDK.MultitargetNetworkManager} | 949 * @type {!SDK.MultitargetNetworkManager} |
922 */ | 950 */ |
923 SDK.multitargetNetworkManager; | 951 SDK.multitargetNetworkManager; |
OLD | NEW |