| 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 26 matching lines...) Expand all Loading... |
| 37 { | 37 { |
| 38 WebInspector.SDKModel.call(this, WebInspector.NetworkManager, target); | 38 WebInspector.SDKModel.call(this, WebInspector.NetworkManager, target); |
| 39 this._dispatcher = new WebInspector.NetworkDispatcher(this); | 39 this._dispatcher = new WebInspector.NetworkDispatcher(this); |
| 40 this._target = target; | 40 this._target = target; |
| 41 this._networkAgent = target.networkAgent(); | 41 this._networkAgent = target.networkAgent(); |
| 42 target.registerNetworkDispatcher(this._dispatcher); | 42 target.registerNetworkDispatcher(this._dispatcher); |
| 43 if (WebInspector.moduleSetting("cacheDisabled").get()) | 43 if (WebInspector.moduleSetting("cacheDisabled").get()) |
| 44 this._networkAgent.setCacheDisabled(true); | 44 this._networkAgent.setCacheDisabled(true); |
| 45 if (WebInspector.moduleSetting("monitoringXHREnabled").get()) | 45 if (WebInspector.moduleSetting("monitoringXHREnabled").get()) |
| 46 this._networkAgent.setMonitoringXHREnabled(true); | 46 this._networkAgent.setMonitoringXHREnabled(true); |
| 47 this._initNetworkConditions(); |
| 47 this._networkAgent.enable(); | 48 this._networkAgent.enable(); |
| 48 | 49 |
| 49 WebInspector.moduleSetting("cacheDisabled").addChangeListener(this._cacheDis
abledSettingChanged, this); | 50 WebInspector.moduleSetting("cacheDisabled").addChangeListener(this._cacheDis
abledSettingChanged, this); |
| 50 } | 51 } |
| 51 | 52 |
| 52 WebInspector.NetworkManager.EventTypes = { | 53 WebInspector.NetworkManager.EventTypes = { |
| 53 RequestStarted: "RequestStarted", | 54 RequestStarted: "RequestStarted", |
| 54 RequestUpdated: "RequestUpdated", | 55 RequestUpdated: "RequestUpdated", |
| 55 RequestFinished: "RequestFinished", | 56 RequestFinished: "RequestFinished", |
| 56 RequestUpdateDropped: "RequestUpdateDropped" | 57 RequestUpdateDropped: "RequestUpdateDropped" |
| 57 } | 58 } |
| 58 | 59 |
| 59 WebInspector.NetworkManager._MIMETypes = { | 60 WebInspector.NetworkManager._MIMETypes = { |
| 60 "text/html": {"document": true}, | 61 "text/html": {"document": true}, |
| 61 "text/xml": {"document": true}, | 62 "text/xml": {"document": true}, |
| 62 "text/plain": {"document": true}, | 63 "text/plain": {"document": true}, |
| 63 "application/xhtml+xml": {"document": true}, | 64 "application/xhtml+xml": {"document": true}, |
| 64 "image/svg+xml": {"document": true}, | 65 "image/svg+xml": {"document": true}, |
| 65 "text/css": {"stylesheet": true}, | 66 "text/css": {"stylesheet": true}, |
| 66 "text/xsl": {"stylesheet": true}, | 67 "text/xsl": {"stylesheet": true}, |
| 67 "text/vtt": {"texttrack": true}, | 68 "text/vtt": {"texttrack": true}, |
| 68 } | 69 } |
| 69 | 70 |
| 71 /** @typedef {{throughput: number, latency: number}} */ |
| 72 WebInspector.NetworkManager.Conditions; |
| 73 |
| 70 WebInspector.NetworkManager.prototype = { | 74 WebInspector.NetworkManager.prototype = { |
| 71 /** | 75 /** |
| 72 * @param {string} url | 76 * @param {string} url |
| 73 * @return {!WebInspector.NetworkRequest} | 77 * @return {!WebInspector.NetworkRequest} |
| 74 */ | 78 */ |
| 75 inflightRequestForURL: function(url) | 79 inflightRequestForURL: function(url) |
| 76 { | 80 { |
| 77 return this._dispatcher._inflightRequestsByURL[url]; | 81 return this._dispatcher._inflightRequestsByURL[url]; |
| 78 }, | 82 }, |
| 79 | 83 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 94 clearBrowserCache: function() | 98 clearBrowserCache: function() |
| 95 { | 99 { |
| 96 this._networkAgent.clearBrowserCache(); | 100 this._networkAgent.clearBrowserCache(); |
| 97 }, | 101 }, |
| 98 | 102 |
| 99 clearBrowserCookies: function() | 103 clearBrowserCookies: function() |
| 100 { | 104 { |
| 101 this._networkAgent.clearBrowserCookies(); | 105 this._networkAgent.clearBrowserCookies(); |
| 102 }, | 106 }, |
| 103 | 107 |
| 108 _initNetworkConditions: function() |
| 109 { |
| 110 this._networkAgent.canEmulateNetworkConditions(callback.bind(this)); |
| 111 |
| 112 /** |
| 113 * @this {WebInspector.NetworkManager} |
| 114 */ |
| 115 function callback(error, canEmulate) |
| 116 { |
| 117 if (error || !canEmulate) |
| 118 return; |
| 119 WebInspector.moduleSetting("networkConditions").addChangeListener(th
is._networkConditionsSettingChanged, this); |
| 120 var conditions = WebInspector.moduleSetting("networkConditions").get
(); |
| 121 if (conditions.throughput < 0) |
| 122 return; |
| 123 this._updateNetworkConditions(conditions); |
| 124 } |
| 125 }, |
| 126 |
| 127 /** |
| 128 * @param {!WebInspector.NetworkManager.Conditions} conditions |
| 129 */ |
| 130 _updateNetworkConditions: function(conditions) |
| 131 { |
| 132 if (conditions.throughput < 0) { |
| 133 this._networkAgent.emulateNetworkConditions(false, 0, 0, 0); |
| 134 } else { |
| 135 var offline = !conditions.throughput && !conditions.latency; |
| 136 this._networkAgent.emulateNetworkConditions(!!offline, conditions.la
tency, conditions.throughput, conditions.throughput); |
| 137 } |
| 138 }, |
| 139 |
| 140 /** |
| 141 * @param {!WebInspector.Event} event |
| 142 */ |
| 143 _networkConditionsSettingChanged: function(event) |
| 144 { |
| 145 this._updateNetworkConditions(/** @type {!WebInspector.NetworkManager.Co
nditions} */ (event.data)); |
| 146 }, |
| 147 |
| 104 __proto__: WebInspector.SDKModel.prototype | 148 __proto__: WebInspector.SDKModel.prototype |
| 105 } | 149 } |
| 106 | 150 |
| 107 /** | 151 /** |
| 108 * @constructor | 152 * @constructor |
| 109 * @implements {NetworkAgent.Dispatcher} | 153 * @implements {NetworkAgent.Dispatcher} |
| 110 */ | 154 */ |
| 111 WebInspector.NetworkDispatcher = function(manager) | 155 WebInspector.NetworkDispatcher = function(manager) |
| 112 { | 156 { |
| 113 this._manager = manager; | 157 this._manager = manager; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 * @override | 633 * @override |
| 590 * @param {!WebInspector.Target} target | 634 * @param {!WebInspector.Target} target |
| 591 */ | 635 */ |
| 592 targetAdded: function(target) | 636 targetAdded: function(target) |
| 593 { | 637 { |
| 594 var networkAgent = target.networkAgent(); | 638 var networkAgent = target.networkAgent(); |
| 595 if (this._extraHeaders) | 639 if (this._extraHeaders) |
| 596 networkAgent.setExtraHTTPHeaders(this._extraHeaders); | 640 networkAgent.setExtraHTTPHeaders(this._extraHeaders); |
| 597 if (typeof this._userAgent !== "undefined") | 641 if (typeof this._userAgent !== "undefined") |
| 598 networkAgent.setUserAgentOverride(this._userAgent); | 642 networkAgent.setUserAgentOverride(this._userAgent); |
| 599 if (this._networkConditions) { | |
| 600 networkAgent.emulateNetworkConditions(this._networkConditions.offlin
e, this._networkConditions.latency, | |
| 601 this._networkConditions.throughput, this._networkConditions.thro
ughput); | |
| 602 } | |
| 603 }, | 643 }, |
| 604 | 644 |
| 605 /** | 645 /** |
| 606 * @override | 646 * @override |
| 607 * @param {!WebInspector.Target} target | 647 * @param {!WebInspector.Target} target |
| 608 */ | 648 */ |
| 609 targetRemoved: function(target) | 649 targetRemoved: function(target) |
| 610 { | 650 { |
| 611 }, | 651 }, |
| 612 | 652 |
| 613 /** | 653 /** |
| 614 * @param {!NetworkAgent.Headers} headers | 654 * @param {!NetworkAgent.Headers} headers |
| 615 */ | 655 */ |
| 616 setExtraHTTPHeaders: function(headers) | 656 setExtraHTTPHeaders: function(headers) |
| 617 { | 657 { |
| 618 this._extraHeaders = headers; | 658 this._extraHeaders = headers; |
| 619 for (var target of WebInspector.targetManager.targets()) | 659 for (var target of WebInspector.targetManager.targets()) |
| 620 target.networkAgent().setExtraHTTPHeaders(this._extraHeaders); | 660 target.networkAgent().setExtraHTTPHeaders(this._extraHeaders); |
| 621 }, | 661 }, |
| 622 | 662 |
| 623 /** | 663 /** |
| 624 * @param {string} userAgent | 664 * @param {string} userAgent |
| 625 */ | 665 */ |
| 626 setUserAgentOverride: function(userAgent) | 666 setUserAgentOverride: function(userAgent) |
| 627 { | 667 { |
| 628 WebInspector.ResourceLoader.targetUserAgent = userAgent; | 668 WebInspector.ResourceLoader.targetUserAgent = userAgent; |
| 629 this._userAgent = userAgent; | 669 this._userAgent = userAgent; |
| 630 for (var target of WebInspector.targetManager.targets()) | 670 for (var target of WebInspector.targetManager.targets()) |
| 631 target.networkAgent().setUserAgentOverride(this._userAgent); | 671 target.networkAgent().setUserAgentOverride(this._userAgent); |
| 632 }, | |
| 633 | |
| 634 /** | |
| 635 * @param {boolean} offline | |
| 636 * @param {number} latency | |
| 637 * @param {number} throughput | |
| 638 */ | |
| 639 emulateNetworkConditions: function(offline, latency, throughput) | |
| 640 { | |
| 641 this._networkConditions = { offline: offline, latency: latency, throughp
ut: throughput }; | |
| 642 for (var target of WebInspector.targetManager.targets()) { | |
| 643 target.networkAgent().emulateNetworkConditions(this._networkConditio
ns.offline, this._networkConditions.latency, | |
| 644 this._networkConditions.throughput, this._networkConditions.thro
ughput); | |
| 645 } | |
| 646 } | 672 } |
| 647 } | 673 } |
| 648 | 674 |
| 649 /** | 675 /** |
| 650 * @type {!WebInspector.MultitargetNetworkManager} | 676 * @type {!WebInspector.MultitargetNetworkManager} |
| 651 */ | 677 */ |
| 652 WebInspector.multitargetNetworkManager; | 678 WebInspector.multitargetNetworkManager; |
| OLD | NEW |