set network emulation client id in request headers
This commit is contained in:
parent
0bf1e56156
commit
fcf04377d7
4 changed files with 24 additions and 0 deletions
|
@ -22,6 +22,8 @@
|
|||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/guid.h"
|
||||
#include "base/prefs/pref_service.h"
|
||||
|
@ -286,6 +288,12 @@ void ClearHostResolverCacheInIO(
|
|||
}
|
||||
}
|
||||
|
||||
void SetDevToolsNetworkEmulationClientId(const std::string& id) {
|
||||
auto cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
cmd_line->AppendSwitchASCII(
|
||||
switches::kDevToolsEmulateNetworkConditionsClientId, id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Session::Session(AtomBrowserContext* browser_context)
|
||||
|
@ -386,12 +394,14 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
|||
|
||||
browser_context_->network_controller_handle()->SetNetworkState(
|
||||
devtools_network_emulation_client_id_, std::move(conditions));
|
||||
SetDevToolsNetworkEmulationClientId(devtools_network_emulation_client_id_);
|
||||
}
|
||||
|
||||
void Session::DisableNetworkEmulation() {
|
||||
scoped_ptr<brightray::DevToolsNetworkConditions> conditions;
|
||||
browser_context_->network_controller_handle()->SetNetworkState(
|
||||
devtools_network_emulation_client_id_, std::move(conditions));
|
||||
SetDevToolsNetworkEmulationClientId(std::string());
|
||||
}
|
||||
|
||||
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <utility>
|
||||
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
|
@ -241,6 +243,12 @@ int AtomNetworkDelegate::OnBeforeSendHeaders(
|
|||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::HttpRequestHeaders* headers) {
|
||||
auto cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
auto client_id = cmd_line->GetSwitchValueASCII(
|
||||
switches::kDevToolsEmulateNetworkConditionsClientId);
|
||||
if (!client_id.empty())
|
||||
headers->SetHeader(
|
||||
switches::kDevToolsEmulateNetworkConditionsClientId, client_id);
|
||||
if (!ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||
return brightray::NetworkDelegate::OnBeforeSendHeaders(
|
||||
request, callback, headers);
|
||||
|
|
|
@ -156,6 +156,10 @@ const char kWidevineCdmPath[] = "widevine-cdm-path";
|
|||
// Widevine CDM version.
|
||||
const char kWidevineCdmVersion[] = "widevine-cdm-version";
|
||||
|
||||
// Client id for devtools network emulation.
|
||||
const char kDevToolsEmulateNetworkConditionsClientId[] =
|
||||
"X-DevTools-Emulate-Network-Conditions-Client-Id";
|
||||
|
||||
} // namespace switches
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -87,6 +87,8 @@ extern const char kOpenerID[];
|
|||
extern const char kWidevineCdmPath[];
|
||||
extern const char kWidevineCdmVersion[];
|
||||
|
||||
extern const char kDevToolsEmulateNetworkConditionsClientId[];
|
||||
|
||||
} // namespace switches
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Reference in a new issue