Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
| index 31a9361ad76df2c9c4d11df5a99457d277fcd189..dd55baa8adbc9a0c63fbe18ea6c3cdd83362eb6a 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
| @@ -56,6 +56,7 @@ |
| #include "core/loader/FrameLoader.h" |
| #include "core/loader/MixedContentChecker.h" |
| #include "core/loader/ThreadableLoaderClient.h" |
| +#include "core/page/NetworkStateNotifier.h" |
| #include "core/page/Page.h" |
| #include "core/xmlhttprequest/XMLHttpRequest.h" |
| #include "platform/blob/BlobData.h" |
| @@ -98,9 +99,6 @@ static size_t maximumTotalBufferSize = 100 * 1000 * 1000; |
| // 10MB |
| static size_t maximumResourceBufferSize = 10 * 1000 * 1000; |
| -} |
| - |
| -namespace { |
| // Pattern may contain stars ('*') which match to any (possibly empty) string. |
| // Stars implicitly assumed at the begin/end of pattern. |
| @@ -246,6 +244,30 @@ String buildBlockedReason(ResourceRequestBlockedReason reason) |
| } |
| } |
| +WebConnectionType toWebConnectionType(ErrorString* errorString, const String& connectionType) |
| +{ |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::None) |
|
allada
2016/06/28 22:34:15
Can we use a switch/case here instead?
dgozman
2016/06/29 01:17:33
Unfortunately, it's a string.
|
| + return WebConnectionTypeNone; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Cellular2g) |
| + return WebConnectionTypeCellular2G; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Cellular3g) |
| + return WebConnectionTypeCellular3G; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Cellular4g) |
| + return WebConnectionTypeCellular4G; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Bluetooth) |
| + return WebConnectionTypeBluetooth; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Ethernet) |
| + return WebConnectionTypeEthernet; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Wifi) |
| + return WebConnectionTypeWifi; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Wimax) |
| + return WebConnectionTypeWimax; |
| + if (connectionType == protocol::Network::ConnectionTypeEnum::Other) |
| + return WebConnectionTypeOther; |
| + *errorString = "Unknown connection type"; |
| + return WebConnectionTypeUnknown; |
| +} |
| + |
| } // namespace |
| void InspectorNetworkAgent::restore() |
| @@ -1046,6 +1068,21 @@ void InspectorNetworkAgent::canClearBrowserCookies(ErrorString*, bool* result) |
| *result = true; |
| } |
| +void InspectorNetworkAgent::emulateNetworkConditions(ErrorString* errorString, bool offline, double latency, double downloadThroughput, double uploadThroughput, const Maybe<String>& connectionType) |
| +{ |
| + WebConnectionType type = WebConnectionTypeUnknown; |
| + if (connectionType.isJust()) { |
| + type = toWebConnectionType(errorString, connectionType.fromJust()); |
| + if (!errorString->isEmpty()) |
| + return; |
| + } |
| + // TODO(dgozman): networkStateNotifier is per-process. It would be nice to have per-frame override instead. |
| + if (offline || latency || downloadThroughput || uploadThroughput) |
| + networkStateNotifier().setOverride(!offline, type, downloadThroughput / (1024 * 1024 / 8)); |
| + else |
| + networkStateNotifier().clearOverride(); |
| +} |
| + |
| void InspectorNetworkAgent::setCacheDisabled(ErrorString*, bool cacheDisabled) |
| { |
| m_state->setBoolean(NetworkAgentState::cacheDisabled, cacheDisabled); |