stop using x-devtools-emulate-network-conditions-client-id header
https://chromium-review.googlesource.com/c/chromium/src/+/1086949
This commit is contained in:
parent
f514445f20
commit
3ded109c2e
4 changed files with 23 additions and 60 deletions
|
@ -27,7 +27,6 @@
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "atom/common/native_mate_converters/net_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/guid.h"
|
#include "base/guid.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
|
@ -56,10 +55,10 @@
|
||||||
#include "net/url_request/static_http_user_agent_settings.h"
|
#include "net/url_request/static_http_user_agent_settings.h"
|
||||||
#include "net/url_request/url_request_context.h"
|
#include "net/url_request/url_request_context.h"
|
||||||
#include "net/url_request/url_request_context_getter.h"
|
#include "net/url_request/url_request_context_getter.h"
|
||||||
#include "services/network/throttling/network_conditions.h"
|
|
||||||
#include "services/network/throttling/throttling_controller.h"
|
|
||||||
#include "ui/base/l10n/l10n_util.h"
|
#include "ui/base/l10n/l10n_util.h"
|
||||||
|
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
using atom::api::Cookies;
|
using atom::api::Cookies;
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
using content::StoragePartition;
|
using content::StoragePartition;
|
||||||
|
@ -353,18 +352,6 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
|
||||||
false, std::vector<download::DownloadItem::ReceivedSlice>());
|
false, std::vector<download::DownloadItem::ReceivedSlice>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDevToolsNetworkEmulationClientIdInIO(
|
|
||||||
net::URLRequestContextGetter* url_request_context_getter,
|
|
||||||
const std::string& client_id) {
|
|
||||||
if (!url_request_context_getter)
|
|
||||||
return;
|
|
||||||
net::URLRequestContext* context =
|
|
||||||
url_request_context_getter->GetURLRequestContext();
|
|
||||||
AtomNetworkDelegate* network_delegate =
|
|
||||||
static_cast<AtomNetworkDelegate*>(context->network_delegate());
|
|
||||||
network_delegate->SetDevToolsNetworkEmulationClientId(client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DestroyGlobalHandle(v8::Isolate* isolate,
|
void DestroyGlobalHandle(v8::Isolate* isolate,
|
||||||
const v8::Global<v8::Value>& global_handle) {
|
const v8::Global<v8::Value>& global_handle) {
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
|
@ -385,7 +372,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||||
: devtools_network_emulation_client_id_(base::GenerateGUID()),
|
: network_emulation_token_(base::UnguessableToken::Create()),
|
||||||
browser_context_(browser_context) {
|
browser_context_(browser_context) {
|
||||||
// Observe DownloadManager to get download notifications.
|
// Observe DownloadManager to get download notifications.
|
||||||
content::BrowserContext::GetDownloadManager(browser_context)
|
content::BrowserContext::GetDownloadManager(browser_context)
|
||||||
|
@ -503,37 +490,29 @@ void Session::SetDownloadPath(const base::FilePath& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
||||||
std::unique_ptr<network::NetworkConditions> conditions;
|
auto conditions = network::mojom::NetworkConditions::New();
|
||||||
bool offline = false;
|
|
||||||
double latency = 0.0, download_throughput = 0.0, upload_throughput = 0.0;
|
options.Get("offline", &conditions->offline);
|
||||||
if (options.Get("offline", &offline) && offline) {
|
options.Get("downloadThroughput", &conditions->download_throughput);
|
||||||
conditions.reset(new network::NetworkConditions(offline));
|
options.Get("uploadThroughput", &conditions->upload_throughput);
|
||||||
} else {
|
double latency = 0.0;
|
||||||
options.Get("latency", &latency);
|
if (options.Get("latency", &latency) && latency) {
|
||||||
options.Get("downloadThroughput", &download_throughput);
|
conditions->latency = base::TimeDelta::FromMillisecondsD(latency);
|
||||||
options.Get("uploadThroughput", &upload_throughput);
|
|
||||||
conditions.reset(new network::NetworkConditions(
|
|
||||||
false, latency, download_throughput, upload_throughput));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network::ThrottlingController::SetConditions(
|
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
|
||||||
devtools_network_emulation_client_id_, std::move(conditions));
|
browser_context_.get())
|
||||||
BrowserThread::PostTask(
|
->GetNetworkContext();
|
||||||
BrowserThread::IO, FROM_HERE,
|
network_context->SetNetworkConditions(network_emulation_token_,
|
||||||
base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
|
std::move(conditions));
|
||||||
base::RetainedRef(browser_context_->GetRequestContext()),
|
|
||||||
devtools_network_emulation_client_id_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::DisableNetworkEmulation() {
|
void Session::DisableNetworkEmulation() {
|
||||||
auto conditions = std::make_unique<network::NetworkConditions>();
|
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
|
||||||
network::ThrottlingController::SetConditions(
|
browser_context_.get())
|
||||||
devtools_network_emulation_client_id_, std::move(conditions));
|
->GetNetworkContext();
|
||||||
BrowserThread::PostTask(
|
network_context->SetNetworkConditions(
|
||||||
BrowserThread::IO, FROM_HERE,
|
network_emulation_token_, network::mojom::NetworkConditions::New());
|
||||||
base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
|
|
||||||
base::RetainedRef(browser_context_->GetRequestContext()),
|
|
||||||
std::string()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||||
|
|
|
@ -107,8 +107,8 @@ class Session : public mate::TrackableObject<Session>,
|
||||||
v8::Global<v8::Value> web_request_;
|
v8::Global<v8::Value> web_request_;
|
||||||
v8::Global<v8::Value> net_log_;
|
v8::Global<v8::Value> net_log_;
|
||||||
|
|
||||||
// The X-DevTools-Emulate-Network-Conditions-Client-Id.
|
// The client id to enable the network throttler.
|
||||||
std::string devtools_network_emulation_client_id_;
|
base::UnguessableToken network_emulation_token_;
|
||||||
|
|
||||||
scoped_refptr<AtomBrowserContext> browser_context_;
|
scoped_refptr<AtomBrowserContext> browser_context_;
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,8 @@
|
||||||
#include "net/base/load_flags.h"
|
#include "net/base/load_flags.h"
|
||||||
#include "net/base/net_errors.h"
|
#include "net/base/net_errors.h"
|
||||||
#include "net/url_request/url_request.h"
|
#include "net/url_request/url_request.h"
|
||||||
#include "services/network/throttling/throttling_network_transaction.h"
|
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
using network::ThrottlingNetworkTransaction;
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -269,11 +267,6 @@ void AtomNetworkDelegate::SetResponseListenerInIO(ResponseEvent type,
|
||||||
response_listeners_[type] = {std::move(patterns), std::move(callback)};
|
response_listeners_[type] = {std::move(patterns), std::move(callback)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomNetworkDelegate::SetDevToolsNetworkEmulationClientId(
|
|
||||||
const std::string& client_id) {
|
|
||||||
client_id_ = client_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AtomNetworkDelegate::OnBeforeURLRequest(
|
int AtomNetworkDelegate::OnBeforeURLRequest(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::CompletionCallback& callback,
|
const net::CompletionCallback& callback,
|
||||||
|
@ -297,10 +290,6 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::CompletionCallback& callback,
|
const net::CompletionCallback& callback,
|
||||||
net::HttpRequestHeaders* headers) {
|
net::HttpRequestHeaders* headers) {
|
||||||
if (!client_id_.empty())
|
|
||||||
headers->SetHeader(network::ThrottlingNetworkTransaction::
|
|
||||||
kDevToolsEmulateNetworkConditionsClientId,
|
|
||||||
client_id_);
|
|
||||||
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||||
return net::OK;
|
return net::OK;
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,6 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
||||||
URLPatterns patterns,
|
URLPatterns patterns,
|
||||||
ResponseListener callback);
|
ResponseListener callback);
|
||||||
|
|
||||||
void SetDevToolsNetworkEmulationClientId(const std::string& client_id);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// net::NetworkDelegate:
|
// net::NetworkDelegate:
|
||||||
int OnBeforeURLRequest(net::URLRequest* request,
|
int OnBeforeURLRequest(net::URLRequest* request,
|
||||||
|
@ -172,9 +170,6 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
||||||
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
||||||
std::vector<std::string> ignore_connections_limit_domains_;
|
std::vector<std::string> ignore_connections_limit_domains_;
|
||||||
|
|
||||||
// Client id for devtools network emulation.
|
|
||||||
std::string client_id_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
|
DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue