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/net_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/guid.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/url_request_context.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 "atom/common/node_includes.h"
 | 
			
		||||
 | 
			
		||||
using atom::api::Cookies;
 | 
			
		||||
using content::BrowserThread;
 | 
			
		||||
using content::StoragePartition;
 | 
			
		||||
| 
						 | 
				
			
			@ -353,18 +352,6 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
 | 
			
		|||
      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,
 | 
			
		||||
                         const v8::Global<v8::Value>& global_handle) {
 | 
			
		||||
  v8::Locker locker(isolate);
 | 
			
		||||
| 
						 | 
				
			
			@ -385,7 +372,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
 | 
			
		|||
}  // namespace
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
  // Observe DownloadManager to get download notifications.
 | 
			
		||||
  content::BrowserContext::GetDownloadManager(browser_context)
 | 
			
		||||
| 
						 | 
				
			
			@ -503,37 +490,29 @@ void Session::SetDownloadPath(const base::FilePath& path) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
 | 
			
		||||
  std::unique_ptr<network::NetworkConditions> conditions;
 | 
			
		||||
  bool offline = false;
 | 
			
		||||
  double latency = 0.0, download_throughput = 0.0, upload_throughput = 0.0;
 | 
			
		||||
  if (options.Get("offline", &offline) && offline) {
 | 
			
		||||
    conditions.reset(new network::NetworkConditions(offline));
 | 
			
		||||
  } else {
 | 
			
		||||
    options.Get("latency", &latency);
 | 
			
		||||
    options.Get("downloadThroughput", &download_throughput);
 | 
			
		||||
    options.Get("uploadThroughput", &upload_throughput);
 | 
			
		||||
    conditions.reset(new network::NetworkConditions(
 | 
			
		||||
        false, latency, download_throughput, upload_throughput));
 | 
			
		||||
  auto conditions = network::mojom::NetworkConditions::New();
 | 
			
		||||
 | 
			
		||||
  options.Get("offline", &conditions->offline);
 | 
			
		||||
  options.Get("downloadThroughput", &conditions->download_throughput);
 | 
			
		||||
  options.Get("uploadThroughput", &conditions->upload_throughput);
 | 
			
		||||
  double latency = 0.0;
 | 
			
		||||
  if (options.Get("latency", &latency) && latency) {
 | 
			
		||||
    conditions->latency = base::TimeDelta::FromMillisecondsD(latency);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  network::ThrottlingController::SetConditions(
 | 
			
		||||
      devtools_network_emulation_client_id_, std::move(conditions));
 | 
			
		||||
  BrowserThread::PostTask(
 | 
			
		||||
      BrowserThread::IO, FROM_HERE,
 | 
			
		||||
      base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
 | 
			
		||||
                     base::RetainedRef(browser_context_->GetRequestContext()),
 | 
			
		||||
                     devtools_network_emulation_client_id_));
 | 
			
		||||
  auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
 | 
			
		||||
                              browser_context_.get())
 | 
			
		||||
                              ->GetNetworkContext();
 | 
			
		||||
  network_context->SetNetworkConditions(network_emulation_token_,
 | 
			
		||||
                                        std::move(conditions));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Session::DisableNetworkEmulation() {
 | 
			
		||||
  auto conditions = std::make_unique<network::NetworkConditions>();
 | 
			
		||||
  network::ThrottlingController::SetConditions(
 | 
			
		||||
      devtools_network_emulation_client_id_, std::move(conditions));
 | 
			
		||||
  BrowserThread::PostTask(
 | 
			
		||||
      BrowserThread::IO, FROM_HERE,
 | 
			
		||||
      base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
 | 
			
		||||
                     base::RetainedRef(browser_context_->GetRequestContext()),
 | 
			
		||||
                     std::string()));
 | 
			
		||||
  auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
 | 
			
		||||
                              browser_context_.get())
 | 
			
		||||
                              ->GetNetworkContext();
 | 
			
		||||
  network_context->SetNetworkConditions(
 | 
			
		||||
      network_emulation_token_, network::mojom::NetworkConditions::New());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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> net_log_;
 | 
			
		||||
 | 
			
		||||
  // The X-DevTools-Emulate-Network-Conditions-Client-Id.
 | 
			
		||||
  std::string devtools_network_emulation_client_id_;
 | 
			
		||||
  // The client id to enable the network throttler.
 | 
			
		||||
  base::UnguessableToken network_emulation_token_;
 | 
			
		||||
 | 
			
		||||
  scoped_refptr<AtomBrowserContext> browser_context_;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,10 +20,8 @@
 | 
			
		|||
#include "net/base/load_flags.h"
 | 
			
		||||
#include "net/base/net_errors.h"
 | 
			
		||||
#include "net/url_request/url_request.h"
 | 
			
		||||
#include "services/network/throttling/throttling_network_transaction.h"
 | 
			
		||||
 | 
			
		||||
using content::BrowserThread;
 | 
			
		||||
using network::ThrottlingNetworkTransaction;
 | 
			
		||||
 | 
			
		||||
namespace atom {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -269,11 +267,6 @@ void AtomNetworkDelegate::SetResponseListenerInIO(ResponseEvent type,
 | 
			
		|||
    response_listeners_[type] = {std::move(patterns), std::move(callback)};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AtomNetworkDelegate::SetDevToolsNetworkEmulationClientId(
 | 
			
		||||
    const std::string& client_id) {
 | 
			
		||||
  client_id_ = client_id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int AtomNetworkDelegate::OnBeforeURLRequest(
 | 
			
		||||
    net::URLRequest* request,
 | 
			
		||||
    const net::CompletionCallback& callback,
 | 
			
		||||
| 
						 | 
				
			
			@ -297,10 +290,6 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
 | 
			
		|||
    net::URLRequest* request,
 | 
			
		||||
    const net::CompletionCallback& callback,
 | 
			
		||||
    net::HttpRequestHeaders* headers) {
 | 
			
		||||
  if (!client_id_.empty())
 | 
			
		||||
    headers->SetHeader(network::ThrottlingNetworkTransaction::
 | 
			
		||||
                           kDevToolsEmulateNetworkConditionsClientId,
 | 
			
		||||
                       client_id_);
 | 
			
		||||
  if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
 | 
			
		||||
    return net::OK;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,8 +79,6 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
 | 
			
		|||
                               URLPatterns patterns,
 | 
			
		||||
                               ResponseListener callback);
 | 
			
		||||
 | 
			
		||||
  void SetDevToolsNetworkEmulationClientId(const std::string& client_id);
 | 
			
		||||
 | 
			
		||||
 protected:
 | 
			
		||||
  // net::NetworkDelegate:
 | 
			
		||||
  int OnBeforeURLRequest(net::URLRequest* request,
 | 
			
		||||
| 
						 | 
				
			
			@ -172,9 +170,6 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
 | 
			
		|||
  std::map<uint64_t, net::CompletionCallback> callbacks_;
 | 
			
		||||
  std::vector<std::string> ignore_connections_limit_domains_;
 | 
			
		||||
 | 
			
		||||
  // Client id for devtools network emulation.
 | 
			
		||||
  std::string client_id_;
 | 
			
		||||
 | 
			
		||||
  DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue