* chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
		
			
				
	
	
		
			545 lines
		
	
	
	
		
			18 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			545 lines
		
	
	
	
		
			18 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
// Copyright (c) 2015 GitHub, Inc.
 | 
						|
// Use of this source code is governed by the MIT license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
#include "shell/browser/net/atom_network_delegate.h"
 | 
						|
 | 
						|
#include <memory>
 | 
						|
#include <utility>
 | 
						|
 | 
						|
#include "base/command_line.h"
 | 
						|
#include "base/stl_util.h"
 | 
						|
#include "base/strings/string_util.h"
 | 
						|
#include "base/task/post_task.h"
 | 
						|
#include "content/public/browser/browser_task_traits.h"
 | 
						|
#include "content/public/browser/browser_thread.h"
 | 
						|
#include "content/public/browser/render_frame_host.h"
 | 
						|
#include "content/public/browser/resource_request_info.h"
 | 
						|
#include "net/base/load_flags.h"
 | 
						|
#include "net/base/net_errors.h"
 | 
						|
#include "net/url_request/url_request.h"
 | 
						|
#include "shell/browser/api/atom_api_web_contents.h"
 | 
						|
#include "shell/browser/login_handler.h"
 | 
						|
#include "shell/common/native_mate_converters/net_converter.h"
 | 
						|
#include "shell/common/options_switches.h"
 | 
						|
 | 
						|
using content::BrowserThread;
 | 
						|
 | 
						|
namespace electron {
 | 
						|
 | 
						|
const char* ResourceTypeToString(content::ResourceType type) {
 | 
						|
  switch (type) {
 | 
						|
    case content::ResourceType::kMainFrame:
 | 
						|
      return "mainFrame";
 | 
						|
    case content::ResourceType::kSubFrame:
 | 
						|
      return "subFrame";
 | 
						|
    case content::ResourceType::kStylesheet:
 | 
						|
      return "stylesheet";
 | 
						|
    case content::ResourceType::kScript:
 | 
						|
      return "script";
 | 
						|
    case content::ResourceType::kImage:
 | 
						|
      return "image";
 | 
						|
    case content::ResourceType::kObject:
 | 
						|
      return "object";
 | 
						|
    case content::ResourceType::kXhr:
 | 
						|
      return "xhr";
 | 
						|
    default:
 | 
						|
      return "other";
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int32_t GetWebContentsID(int process_id, int frame_id) {
 | 
						|
  auto* webContents = content::WebContents::FromRenderFrameHost(
 | 
						|
      content::RenderFrameHost::FromID(process_id, frame_id));
 | 
						|
  return electron::api::WebContents::GetIDFromWrappedClass(webContents);
 | 
						|
}
 | 
						|
 | 
						|
namespace {
 | 
						|
 | 
						|
using ResponseHeadersContainer =
 | 
						|
    std::pair<scoped_refptr<net::HttpResponseHeaders>*, const std::string&>;
 | 
						|
 | 
						|
void RunSimpleListener(const AtomNetworkDelegate::SimpleListener& listener,
 | 
						|
                       std::unique_ptr<base::DictionaryValue> details,
 | 
						|
                       int render_process_id,
 | 
						|
                       int render_frame_id) {
 | 
						|
  int32_t id = GetWebContentsID(render_process_id, render_frame_id);
 | 
						|
  // id must be greater than zero
 | 
						|
  if (id)
 | 
						|
    details->SetInteger("webContentsId", id);
 | 
						|
  return listener.Run(*(details.get()));
 | 
						|
}
 | 
						|
 | 
						|
void RunResponseListener(const AtomNetworkDelegate::ResponseListener& listener,
 | 
						|
                         std::unique_ptr<base::DictionaryValue> details,
 | 
						|
                         int render_process_id,
 | 
						|
                         int render_frame_id,
 | 
						|
                         AtomNetworkDelegate::ResponseCallback callback) {
 | 
						|
  int32_t id = GetWebContentsID(render_process_id, render_frame_id);
 | 
						|
  // id must be greater than zero
 | 
						|
  if (id)
 | 
						|
    details->SetInteger("webContentsId", id);
 | 
						|
  return listener.Run(*(details.get()), std::move(callback));
 | 
						|
}
 | 
						|
 | 
						|
// Test whether the URL of |request| matches |patterns|.
 | 
						|
bool MatchesFilterCondition(net::URLRequest* request,
 | 
						|
                            const URLPatterns& patterns) {
 | 
						|
  if (patterns.empty())
 | 
						|
    return true;
 | 
						|
 | 
						|
  for (const auto& pattern : patterns) {
 | 
						|
    if (pattern.MatchesURL(request->url()))
 | 
						|
      return true;
 | 
						|
  }
 | 
						|
  return false;
 | 
						|
}
 | 
						|
 | 
						|
// Overloaded by multiple types to fill the |details| object.
 | 
						|
void ToDictionary(base::DictionaryValue* details, net::URLRequest* request) {
 | 
						|
  FillRequestDetails(details, request);
 | 
						|
  details->SetInteger("id", request->identifier());
 | 
						|
  details->SetDouble("timestamp", base::Time::Now().ToDoubleT() * 1000);
 | 
						|
  auto* info = content::ResourceRequestInfo::ForRequest(request);
 | 
						|
  if (info) {
 | 
						|
    details->SetString("resourceType",
 | 
						|
                       ResourceTypeToString(info->GetResourceType()));
 | 
						|
  } else {
 | 
						|
    details->SetString("resourceType", "other");
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details,
 | 
						|
                  const net::HttpRequestHeaders& headers) {
 | 
						|
  auto dict = std::make_unique<base::DictionaryValue>();
 | 
						|
  net::HttpRequestHeaders::Iterator it(headers);
 | 
						|
  while (it.GetNext())
 | 
						|
    dict->SetKey(it.name(), base::Value(it.value()));
 | 
						|
  details->Set("requestHeaders", std::move(dict));
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details,
 | 
						|
                  const net::HttpResponseHeaders* headers) {
 | 
						|
  if (!headers)
 | 
						|
    return;
 | 
						|
 | 
						|
  auto dict = std::make_unique<base::DictionaryValue>();
 | 
						|
  size_t iter = 0;
 | 
						|
  std::string key;
 | 
						|
  std::string value;
 | 
						|
  while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
 | 
						|
    if (dict->FindKey(key)) {
 | 
						|
      base::ListValue* values = nullptr;
 | 
						|
      if (dict->GetList(key, &values))
 | 
						|
        values->AppendString(value);
 | 
						|
    } else {
 | 
						|
      auto values = std::make_unique<base::ListValue>();
 | 
						|
      values->AppendString(value);
 | 
						|
      dict->Set(key, std::move(values));
 | 
						|
    }
 | 
						|
  }
 | 
						|
  details->Set("responseHeaders", std::move(dict));
 | 
						|
  details->SetString("statusLine", headers->GetStatusLine());
 | 
						|
  details->SetInteger("statusCode", headers->response_code());
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details, const GURL& location) {
 | 
						|
  details->SetString("redirectURL", location.spec());
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details,
 | 
						|
                  const net::IPEndPoint& remote_endpoint) {
 | 
						|
  details->SetString("ip", remote_endpoint.ToStringWithoutPort());
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details, bool from_cache) {
 | 
						|
  details->SetBoolean("fromCache", from_cache);
 | 
						|
}
 | 
						|
 | 
						|
void ToDictionary(base::DictionaryValue* details,
 | 
						|
                  const net::URLRequestStatus& status) {
 | 
						|
  details->SetString("error", net::ErrorToString(status.error()));
 | 
						|
}
 | 
						|
 | 
						|
// Helper function to fill |details| with arbitrary |args|.
 | 
						|
template <typename Arg>
 | 
						|
void FillDetailsObject(base::DictionaryValue* details, Arg arg) {
 | 
						|
  ToDictionary(details, arg);
 | 
						|
}
 | 
						|
 | 
						|
template <typename Arg, typename... Args>
 | 
						|
void FillDetailsObject(base::DictionaryValue* details, Arg arg, Args... args) {
 | 
						|
  ToDictionary(details, arg);
 | 
						|
  FillDetailsObject(details, args...);
 | 
						|
}
 | 
						|
 | 
						|
// Fill the native types with the result from the response object.
 | 
						|
void ReadFromResponseObject(const base::DictionaryValue& response,
 | 
						|
                            GURL* new_location) {
 | 
						|
  std::string url;
 | 
						|
  if (response.GetString("redirectURL", &url))
 | 
						|
    *new_location = GURL(url);
 | 
						|
}
 | 
						|
 | 
						|
void ReadFromResponseObject(const base::DictionaryValue& response,
 | 
						|
                            net::HttpRequestHeaders* headers) {
 | 
						|
  const base::DictionaryValue* dict;
 | 
						|
  if (response.GetDictionary("requestHeaders", &dict)) {
 | 
						|
    headers->Clear();
 | 
						|
    for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
 | 
						|
         it.Advance()) {
 | 
						|
      if (it.value().is_string()) {
 | 
						|
        std::string value = it.value().GetString();
 | 
						|
        headers->SetHeader(it.key(), value);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void ReadFromResponseObject(const base::DictionaryValue& response,
 | 
						|
                            const ResponseHeadersContainer& container) {
 | 
						|
  const base::DictionaryValue* dict;
 | 
						|
  std::string status_line;
 | 
						|
  if (!response.GetString("statusLine", &status_line))
 | 
						|
    status_line = container.second;
 | 
						|
  if (response.GetDictionary("responseHeaders", &dict)) {
 | 
						|
    auto* headers = container.first;
 | 
						|
    *headers = new net::HttpResponseHeaders("");
 | 
						|
    (*headers)->ReplaceStatusLine(status_line);
 | 
						|
    for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
 | 
						|
         it.Advance()) {
 | 
						|
      const base::ListValue* list;
 | 
						|
      if (it.value().GetAsList(&list)) {
 | 
						|
        (*headers)->RemoveHeader(it.key());
 | 
						|
        for (size_t i = 0; i < list->GetSize(); ++i) {
 | 
						|
          std::string value;
 | 
						|
          if (list->GetString(i, &value))
 | 
						|
            (*headers)->AddHeader(it.key() + " : " + value);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace
 | 
						|
 | 
						|
AtomNetworkDelegate::SimpleListenerInfo::SimpleListenerInfo(
 | 
						|
    URLPatterns patterns_,
 | 
						|
    SimpleListener listener_)
 | 
						|
    : url_patterns(patterns_), listener(listener_) {}
 | 
						|
AtomNetworkDelegate::SimpleListenerInfo::SimpleListenerInfo() = default;
 | 
						|
AtomNetworkDelegate::SimpleListenerInfo::~SimpleListenerInfo() = default;
 | 
						|
 | 
						|
AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo(
 | 
						|
    URLPatterns patterns_,
 | 
						|
    ResponseListener listener_)
 | 
						|
    : url_patterns(patterns_), listener(listener_) {}
 | 
						|
AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo() = default;
 | 
						|
AtomNetworkDelegate::ResponseListenerInfo::~ResponseListenerInfo() = default;
 | 
						|
 | 
						|
AtomNetworkDelegate::AtomNetworkDelegate() {
 | 
						|
  auto* command_line = base::CommandLine::ForCurrentProcess();
 | 
						|
  if (command_line->HasSwitch(switches::kIgnoreConnectionsLimit)) {
 | 
						|
    std::string value =
 | 
						|
        command_line->GetSwitchValueASCII(switches::kIgnoreConnectionsLimit);
 | 
						|
    ignore_connections_limit_domains_ = base::SplitString(
 | 
						|
        value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
AtomNetworkDelegate::~AtomNetworkDelegate() {}
 | 
						|
 | 
						|
void AtomNetworkDelegate::SetSimpleListenerInIO(SimpleEvent type,
 | 
						|
                                                URLPatterns patterns,
 | 
						|
                                                SimpleListener callback) {
 | 
						|
  if (callback.is_null())
 | 
						|
    simple_listeners_.erase(type);
 | 
						|
  else
 | 
						|
    simple_listeners_[type] = {std::move(patterns), std::move(callback)};
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::SetResponseListenerInIO(ResponseEvent type,
 | 
						|
                                                  URLPatterns patterns,
 | 
						|
                                                  ResponseListener callback) {
 | 
						|
  if (callback.is_null())
 | 
						|
    response_listeners_.erase(type);
 | 
						|
  else
 | 
						|
    response_listeners_[type] = {std::move(patterns), std::move(callback)};
 | 
						|
}
 | 
						|
 | 
						|
int AtomNetworkDelegate::OnBeforeURLRequest(
 | 
						|
    net::URLRequest* request,
 | 
						|
    net::CompletionOnceCallback callback,
 | 
						|
    GURL* new_url) {
 | 
						|
  if (!base::Contains(response_listeners_, kOnBeforeRequest)) {
 | 
						|
    for (const auto& domain : ignore_connections_limit_domains_) {
 | 
						|
      if (request->url().DomainIs(domain)) {
 | 
						|
        // Allow unlimited concurrent connections.
 | 
						|
        request->SetPriority(net::MAXIMUM_PRIORITY);
 | 
						|
        request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS);
 | 
						|
        break;
 | 
						|
      }
 | 
						|
    }
 | 
						|
    return net::OK;
 | 
						|
  }
 | 
						|
 | 
						|
  return HandleResponseEvent(kOnBeforeRequest, request, std::move(callback),
 | 
						|
                             new_url);
 | 
						|
}
 | 
						|
 | 
						|
int AtomNetworkDelegate::OnBeforeStartTransaction(
 | 
						|
    net::URLRequest* request,
 | 
						|
    net::CompletionOnceCallback callback,
 | 
						|
    net::HttpRequestHeaders* headers) {
 | 
						|
  if (!base::Contains(response_listeners_, kOnBeforeSendHeaders))
 | 
						|
    return net::OK;
 | 
						|
 | 
						|
  return HandleResponseEvent(kOnBeforeSendHeaders, request, std::move(callback),
 | 
						|
                             headers, *headers);
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnStartTransaction(
 | 
						|
    net::URLRequest* request,
 | 
						|
    const net::HttpRequestHeaders& headers) {
 | 
						|
  if (!base::Contains(simple_listeners_, kOnSendHeaders))
 | 
						|
    return;
 | 
						|
 | 
						|
  HandleSimpleEvent(kOnSendHeaders, request, headers);
 | 
						|
}
 | 
						|
 | 
						|
int AtomNetworkDelegate::OnHeadersReceived(
 | 
						|
    net::URLRequest* request,
 | 
						|
    net::CompletionOnceCallback callback,
 | 
						|
    const net::HttpResponseHeaders* original,
 | 
						|
    scoped_refptr<net::HttpResponseHeaders>* override,
 | 
						|
    GURL* allowed) {
 | 
						|
  if (!base::Contains(response_listeners_, kOnHeadersReceived))
 | 
						|
    return net::OK;
 | 
						|
 | 
						|
  return HandleResponseEvent(
 | 
						|
      kOnHeadersReceived, request, std::move(callback),
 | 
						|
      std::make_pair(override, original->GetStatusLine()), original);
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
 | 
						|
                                           const GURL& new_location) {
 | 
						|
  if (!base::Contains(simple_listeners_, kOnBeforeRedirect))
 | 
						|
    return;
 | 
						|
 | 
						|
  HandleSimpleEvent(
 | 
						|
      kOnBeforeRedirect, request, new_location, request->response_headers(),
 | 
						|
      request->GetResponseRemoteEndpoint(), request->was_cached());
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnResponseStarted(net::URLRequest* request,
 | 
						|
                                            int net_error) {
 | 
						|
  if (!base::Contains(simple_listeners_, kOnResponseStarted))
 | 
						|
    return;
 | 
						|
 | 
						|
  if (request->status().status() != net::URLRequestStatus::SUCCESS)
 | 
						|
    return;
 | 
						|
 | 
						|
  HandleSimpleEvent(kOnResponseStarted, request, request->response_headers(),
 | 
						|
                    request->was_cached());
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnCompleted(net::URLRequest* request,
 | 
						|
                                      bool started,
 | 
						|
                                      int net_error) {
 | 
						|
  // OnCompleted may happen before other events.
 | 
						|
  callbacks_.erase(request->identifier());
 | 
						|
 | 
						|
  if (request->status().status() == net::URLRequestStatus::FAILED ||
 | 
						|
      request->status().status() == net::URLRequestStatus::CANCELED) {
 | 
						|
    // Error event.
 | 
						|
    OnErrorOccurred(request, started, net_error);
 | 
						|
    return;
 | 
						|
  }
 | 
						|
 | 
						|
  if (request->response_headers() &&
 | 
						|
      net::HttpResponseHeaders::IsRedirectResponseCode(
 | 
						|
          request->response_headers()->response_code())) {
 | 
						|
    // Redirect event.
 | 
						|
    return;
 | 
						|
  }
 | 
						|
 | 
						|
  if (!base::Contains(simple_listeners_, kOnCompleted))
 | 
						|
    return;
 | 
						|
 | 
						|
  HandleSimpleEvent(kOnCompleted, request, request->response_headers(),
 | 
						|
                    request->was_cached());
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
 | 
						|
  const auto& it = login_handler_map_.find(request->identifier());
 | 
						|
  if (it != login_handler_map_.end()) {
 | 
						|
    it->second->NotifyRequestDestroyed();
 | 
						|
    it->second = nullptr;
 | 
						|
    login_handler_map_.erase(it);
 | 
						|
  }
 | 
						|
  callbacks_.erase(request->identifier());
 | 
						|
}
 | 
						|
 | 
						|
net::NetworkDelegate::AuthRequiredResponse AtomNetworkDelegate::OnAuthRequired(
 | 
						|
    net::URLRequest* request,
 | 
						|
    const net::AuthChallengeInfo& auth_info,
 | 
						|
    AuthCallback callback,
 | 
						|
    net::AuthCredentials* credentials) {
 | 
						|
  auto* resource_request_info =
 | 
						|
      content::ResourceRequestInfo::ForRequest(request);
 | 
						|
  if (!resource_request_info)
 | 
						|
    return AUTH_REQUIRED_RESPONSE_NO_ACTION;
 | 
						|
  login_handler_map_.emplace(
 | 
						|
      request->identifier(),
 | 
						|
      new LoginHandler(request, auth_info, std::move(callback), credentials,
 | 
						|
                       resource_request_info));
 | 
						|
  return AUTH_REQUIRED_RESPONSE_IO_PENDING;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
 | 
						|
                                          const net::CookieList& cookie_list,
 | 
						|
                                          bool allowed_from_caller) {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanSetCookie(
 | 
						|
    const net::URLRequest& request,
 | 
						|
    const net::CanonicalCookie& cookie_line,
 | 
						|
    net::CookieOptions* options,
 | 
						|
    bool allowed_from_caller) {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanAccessFile(
 | 
						|
    const net::URLRequest& request,
 | 
						|
    const base::FilePath& original_path,
 | 
						|
    const base::FilePath& absolute_path) const {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnForcePrivacyMode(
 | 
						|
    const GURL& url,
 | 
						|
    const GURL& first_party_for_cookies) const {
 | 
						|
  return false;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
 | 
						|
    const net::URLRequest& request,
 | 
						|
    const GURL& target_url,
 | 
						|
    const GURL& referrer_url) const {
 | 
						|
  return false;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanQueueReportingReport(
 | 
						|
    const url::Origin& origin) const {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnCanSendReportingReports(
 | 
						|
    std::set<url::Origin> origins,
 | 
						|
    base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {
 | 
						|
  std::move(result_callback).Run(std::move(origins));
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
 | 
						|
                                                  const GURL& endpoint) const {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool AtomNetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
 | 
						|
                                                  const GURL& endpoint) const {
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void AtomNetworkDelegate::OnErrorOccurred(net::URLRequest* request,
 | 
						|
                                          bool started,
 | 
						|
                                          int net_error) {
 | 
						|
  if (!base::Contains(simple_listeners_, kOnErrorOccurred))
 | 
						|
    return;
 | 
						|
 | 
						|
  HandleSimpleEvent(kOnErrorOccurred, request, request->was_cached(),
 | 
						|
                    request->status());
 | 
						|
}
 | 
						|
 | 
						|
template <typename Out, typename... Args>
 | 
						|
int AtomNetworkDelegate::HandleResponseEvent(
 | 
						|
    ResponseEvent type,
 | 
						|
    net::URLRequest* request,
 | 
						|
    net::CompletionOnceCallback callback,
 | 
						|
    Out out,
 | 
						|
    Args... args) {
 | 
						|
  const auto& info = response_listeners_[type];
 | 
						|
  if (!MatchesFilterCondition(request, info.url_patterns))
 | 
						|
    return net::OK;
 | 
						|
 | 
						|
  auto details = std::make_unique<base::DictionaryValue>();
 | 
						|
  FillDetailsObject(details.get(), request, args...);
 | 
						|
 | 
						|
  int render_process_id, render_frame_id;
 | 
						|
  content::ResourceRequestInfo::GetRenderFrameForRequest(
 | 
						|
      request, &render_process_id, &render_frame_id);
 | 
						|
 | 
						|
  // The |request| could be destroyed before the |callback| is called.
 | 
						|
  callbacks_[request->identifier()] = std::move(callback);
 | 
						|
 | 
						|
  ResponseCallback response =
 | 
						|
      base::BindOnce(&AtomNetworkDelegate::OnListenerResultInUI<Out>,
 | 
						|
                     base::Unretained(this), request->identifier(), out);
 | 
						|
  base::PostTaskWithTraits(
 | 
						|
      FROM_HERE, {BrowserThread::UI},
 | 
						|
      base::BindOnce(RunResponseListener, info.listener, std::move(details),
 | 
						|
                     render_process_id, render_frame_id, std::move(response)));
 | 
						|
  return net::ERR_IO_PENDING;
 | 
						|
}
 | 
						|
 | 
						|
template <typename... Args>
 | 
						|
void AtomNetworkDelegate::HandleSimpleEvent(SimpleEvent type,
 | 
						|
                                            net::URLRequest* request,
 | 
						|
                                            Args... args) {
 | 
						|
  const auto& info = simple_listeners_[type];
 | 
						|
  if (!MatchesFilterCondition(request, info.url_patterns))
 | 
						|
    return;
 | 
						|
 | 
						|
  auto details = std::make_unique<base::DictionaryValue>();
 | 
						|
  FillDetailsObject(details.get(), request, args...);
 | 
						|
 | 
						|
  int render_process_id, render_frame_id;
 | 
						|
  content::ResourceRequestInfo::GetRenderFrameForRequest(
 | 
						|
      request, &render_process_id, &render_frame_id);
 | 
						|
 | 
						|
  base::PostTaskWithTraits(
 | 
						|
      FROM_HERE, {BrowserThread::UI},
 | 
						|
      base::BindOnce(RunSimpleListener, info.listener, std::move(details),
 | 
						|
                     render_process_id, render_frame_id));
 | 
						|
}
 | 
						|
 | 
						|
template <typename T>
 | 
						|
void AtomNetworkDelegate::OnListenerResultInIO(
 | 
						|
    uint64_t id,
 | 
						|
    T out,
 | 
						|
    std::unique_ptr<base::DictionaryValue> response) {
 | 
						|
  // The request has been destroyed.
 | 
						|
  if (!base::Contains(callbacks_, id))
 | 
						|
    return;
 | 
						|
 | 
						|
  ReadFromResponseObject(*response, out);
 | 
						|
 | 
						|
  bool cancel = false;
 | 
						|
  response->GetBoolean("cancel", &cancel);
 | 
						|
  std::move(callbacks_[id]).Run(cancel ? net::ERR_BLOCKED_BY_CLIENT : net::OK);
 | 
						|
}
 | 
						|
 | 
						|
template <typename T>
 | 
						|
void AtomNetworkDelegate::OnListenerResultInUI(
 | 
						|
    uint64_t id,
 | 
						|
    T out,
 | 
						|
    const base::DictionaryValue& response) {
 | 
						|
  auto copy = base::DictionaryValue::From(
 | 
						|
      base::Value::ToUniquePtrValue(response.Clone()));
 | 
						|
  base::PostTaskWithTraits(
 | 
						|
      FROM_HERE, {BrowserThread::IO},
 | 
						|
      base::BindOnce(&AtomNetworkDelegate::OnListenerResultInIO<T>,
 | 
						|
                     base::Unretained(this), id, out, std::move(copy)));
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace electron
 |