Merge pull request #5147 from deepak1556/devtools_network_controller_patch
session: set client id when enabling network emulation
This commit is contained in:
commit
8ca1a6961c
3 changed files with 30 additions and 1 deletions
|
@ -386,12 +386,16 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
|||
|
||||
browser_context_->network_controller_handle()->SetNetworkState(
|
||||
devtools_network_emulation_client_id_, std::move(conditions));
|
||||
browser_context_->network_delegate()->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));
|
||||
browser_context_->network_delegate()->SetDevToolsNetworkEmulationClientId(
|
||||
std::string());
|
||||
}
|
||||
|
||||
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||
|
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brightray/browser/net/devtools_network_transaction.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
using brightray::DevToolsNetworkTransaction;
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
@ -226,6 +227,12 @@ void AtomNetworkDelegate::SetResponseListenerInIO(
|
|||
response_listeners_[type] = { patterns, callback };
|
||||
}
|
||||
|
||||
void AtomNetworkDelegate::SetDevToolsNetworkEmulationClientId(
|
||||
const std::string& client_id) {
|
||||
base::AutoLock auto_lock(lock_);
|
||||
client_id_ = client_id;
|
||||
}
|
||||
|
||||
int AtomNetworkDelegate::OnBeforeURLRequest(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
|
@ -241,6 +248,16 @@ int AtomNetworkDelegate::OnBeforeSendHeaders(
|
|||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::HttpRequestHeaders* headers) {
|
||||
std::string client_id;
|
||||
{
|
||||
base::AutoLock auto_lock(lock_);
|
||||
client_id = client_id_;
|
||||
}
|
||||
|
||||
if (!client_id.empty())
|
||||
headers->SetHeader(
|
||||
DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId,
|
||||
client_id);
|
||||
if (!ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||
return brightray::NetworkDelegate::OnBeforeSendHeaders(
|
||||
request, callback, headers);
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "brightray/browser/network_delegate.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/values.h"
|
||||
#include "extensions/common/url_pattern.h"
|
||||
#include "net/base/net_errors.h"
|
||||
|
@ -68,6 +70,8 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
|||
const URLPatterns& patterns,
|
||||
const ResponseListener& callback);
|
||||
|
||||
void SetDevToolsNetworkEmulationClientId(const std::string& client_id);
|
||||
|
||||
protected:
|
||||
// net::NetworkDelegate:
|
||||
int OnBeforeURLRequest(net::URLRequest* request,
|
||||
|
@ -116,6 +120,10 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
|||
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
||||
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
||||
|
||||
base::Lock lock_;
|
||||
// Client id for devtools network emulation.
|
||||
std::string client_id_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue