f2c341b655
* chore: bump chromium in DEPS to 108.0.5339.0 * chore: bump chromium in DEPS to 108.0.5341.0 * chore: sync patch to unrelated upstream code shear patches/chromium/network_service_allow_remote_certificate_verification_logic.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/printing.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/chore_add_electron_deps_to_gitignores.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3906023 * chore: refresh patches - `e patches all` * chore: remove unused parameter from WillCreateURLLoaderRequestInterceptors Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3932218 * perf: avoid unique pointer round trip Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3913938 * refactor: Simplify entropy provider management. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3901211 * fixup! perf: avoid unique pointer round trip * fixup! perf: avoid unique pointer round trip * refactor: update typeof FileSelectHelper::select_file_dialog_ Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3930092 * fixup! fixup! perf: avoid unique pointer round trip * chore: bump chromium in DEPS to 108.0.5343.0 * chore: update patches * chore: bump chromium in DEPS to 108.0.5345.0 * chore: bump chromium in DEPS to 108.0.5347.0 * chore: bump chromium in DEPS to 108.0.5349.0 * chore: bump chromium in DEPS to 108.0.5351.0 * chore: bump chromium in DEPS to 108.0.5353.0 * chore: bump chromium in DEPS to 108.0.5355.0 * chore: update patches * Refactor display::win::DisplayInfo to display::win::internal::DisplayInfo Refs https://chromium-review.googlesource.com/c/chromium/src/+/3929014 * Update proxy resolution to use NAK - Part 2 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3934016 * Disable PreconnectManager when the user disabled preloading. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3928470 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3937183 * chore: update patches * chore: update sysroot * linux: Remove breakpad integration Refs https://chromium-review.googlesource.com/c/chromium/src/+/3764621 * chore: update comments Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
102 lines
3.3 KiB
C++
102 lines
3.3 KiB
C++
// Copyright (c) 2018 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/resolve_proxy_helper.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/bind.h"
|
|
#include "content/public/browser/browser_thread.h"
|
|
#include "content/public/browser/storage_partition.h"
|
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
|
#include "net/base/network_anonymization_key.h"
|
|
#include "net/proxy_resolution/proxy_info.h"
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
|
#include "shell/browser/electron_browser_context.h"
|
|
|
|
using content::BrowserThread;
|
|
|
|
namespace electron {
|
|
|
|
ResolveProxyHelper::ResolveProxyHelper(ElectronBrowserContext* browser_context)
|
|
: browser_context_(browser_context) {}
|
|
|
|
ResolveProxyHelper::~ResolveProxyHelper() {
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
DCHECK(!owned_self_);
|
|
DCHECK(!receiver_.is_bound());
|
|
// Clear all pending requests if the ProxyService is still alive.
|
|
pending_requests_.clear();
|
|
}
|
|
|
|
void ResolveProxyHelper::ResolveProxy(const GURL& url,
|
|
ResolveProxyCallback callback) {
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
// Enqueue the pending request.
|
|
pending_requests_.emplace_back(url, std::move(callback));
|
|
|
|
// If nothing is in progress, start.
|
|
if (!receiver_.is_bound()) {
|
|
DCHECK_EQ(1u, pending_requests_.size());
|
|
StartPendingRequest();
|
|
}
|
|
}
|
|
|
|
void ResolveProxyHelper::StartPendingRequest() {
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
DCHECK(!receiver_.is_bound());
|
|
DCHECK(!pending_requests_.empty());
|
|
|
|
// Start the request.
|
|
mojo::PendingRemote<network::mojom::ProxyLookupClient> proxy_lookup_client =
|
|
receiver_.BindNewPipeAndPassRemote();
|
|
receiver_.set_disconnect_handler(
|
|
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
|
|
base::Unretained(this), net::ERR_ABORTED, absl::nullopt));
|
|
browser_context_->GetDefaultStoragePartition()
|
|
->GetNetworkContext()
|
|
->LookUpProxyForURL(pending_requests_.front().url,
|
|
net::NetworkAnonymizationKey(),
|
|
std::move(proxy_lookup_client));
|
|
}
|
|
|
|
void ResolveProxyHelper::OnProxyLookupComplete(
|
|
int32_t net_error,
|
|
const absl::optional<net::ProxyInfo>& proxy_info) {
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
DCHECK(!pending_requests_.empty());
|
|
|
|
receiver_.reset();
|
|
|
|
// Clear the current (completed) request.
|
|
PendingRequest completed_request = std::move(pending_requests_.front());
|
|
pending_requests_.pop_front();
|
|
|
|
std::string proxy;
|
|
if (proxy_info)
|
|
proxy = proxy_info->ToPacString();
|
|
|
|
if (!completed_request.callback.is_null())
|
|
std::move(completed_request.callback).Run(proxy);
|
|
|
|
// Start the next request.
|
|
if (!pending_requests_.empty())
|
|
StartPendingRequest();
|
|
}
|
|
|
|
ResolveProxyHelper::PendingRequest::PendingRequest(
|
|
const GURL& url,
|
|
ResolveProxyCallback callback)
|
|
: url(url), callback(std::move(callback)) {}
|
|
|
|
ResolveProxyHelper::PendingRequest::PendingRequest(
|
|
ResolveProxyHelper::PendingRequest&& pending_request) noexcept = default;
|
|
|
|
ResolveProxyHelper::PendingRequest::~PendingRequest() noexcept = default;
|
|
|
|
ResolveProxyHelper::PendingRequest&
|
|
ResolveProxyHelper::PendingRequest::operator=(
|
|
ResolveProxyHelper::PendingRequest&& pending_request) noexcept = default;
|
|
|
|
} // namespace electron
|