2019-11-05 23:41:20 +00:00
|
|
|
// Copyright (c) 2019 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "shell/browser/network_hints_handler_impl.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "content/public/browser/browser_context.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_session.h"
|
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2019-11-05 23:41:20 +00:00
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
NetworkHintsHandlerImpl::NetworkHintsHandlerImpl(
|
|
|
|
content::RenderFrameHost* frame_host)
|
|
|
|
: network_hints::SimpleNetworkHintsHandlerImpl(
|
2020-01-29 12:01:37 +00:00
|
|
|
frame_host->GetProcess()->GetID(),
|
|
|
|
frame_host->GetRoutingID()),
|
2020-05-01 07:37:01 +00:00
|
|
|
browser_context_(frame_host->GetProcess()->GetBrowserContext()) {}
|
2019-11-05 23:41:20 +00:00
|
|
|
|
|
|
|
NetworkHintsHandlerImpl::~NetworkHintsHandlerImpl() = default;
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
void NetworkHintsHandlerImpl::Preconnect(const GURL& url,
|
2019-11-05 23:41:20 +00:00
|
|
|
bool allow_credentials) {
|
|
|
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
|
|
2020-05-01 07:37:01 +00:00
|
|
|
if (!browser_context_) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-19 17:18:12 +00:00
|
|
|
auto* session = electron::api::Session::FromBrowserContext(browser_context_);
|
2019-11-05 23:41:20 +00:00
|
|
|
if (session) {
|
|
|
|
session->Emit("preconnect", url, allow_credentials);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkHintsHandlerImpl::Create(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::RenderFrameHost* frame_host,
|
2019-11-05 23:41:20 +00:00
|
|
|
mojo::PendingReceiver<network_hints::mojom::NetworkHintsHandler> receiver) {
|
|
|
|
mojo::MakeSelfOwnedReceiver(
|
2019-12-11 00:22:35 +00:00
|
|
|
base::WrapUnique(new NetworkHintsHandlerImpl(frame_host)),
|
2019-11-05 23:41:20 +00:00
|
|
|
std::move(receiver));
|
|
|
|
}
|