Files
electron/shell/browser/network_hints_handler_impl.cc
Samuel Attard f8335b6542 feat: identify the requesting frame and initiator on network, auth and download events (#53685)
* feat: identify the requesting frame and initiator on network, auth and download events

* webRequest listener details gain `initiator`, the origin that issued the
  request (kept from the original request across redirects, as in Chrome's
  webRequest API)
* protocol.handle() requests and ProtocolRequest gain `initiator`
* DownloadItem gains getInitiatorOrigin(); session 'will-download' gets a
  trailing `frame`
* session 'preconnect' gets a trailing `frame`
* specs for each

* docs: add API history PR reference
2026-09-07 18:31:56 +00:00

49 lines
1.8 KiB
C++

// 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_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"
#include "shell/browser/api/electron_api_session.h"
#include "shell/common/gin_converters/frame_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "v8/include/v8.h"
NetworkHintsHandlerImpl::NetworkHintsHandlerImpl(
content::RenderFrameHost* frame_host)
: network_hints::SimpleNetworkHintsHandlerImpl(frame_host->GetGlobalId()),
render_frame_host_id_(frame_host->GetGlobalId()),
browser_context_(frame_host->GetProcess()->GetBrowserContext()) {}
NetworkHintsHandlerImpl::~NetworkHintsHandlerImpl() = default;
void NetworkHintsHandlerImpl::Preconnect(const url::SchemeHostPort& url,
bool allow_credentials) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!browser_context_) {
return;
}
gin::WeakCell<electron::api::Session>* session =
electron::api::Session::FromBrowserContext(browser_context_);
if (session && session->Get()) {
session->Get()->Emit(
"preconnect", url.GetURL(), allow_credentials,
content::RenderFrameHost::FromID(render_frame_host_id_));
}
}
void NetworkHintsHandlerImpl::Create(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<network_hints::mojom::NetworkHintsHandler> receiver) {
mojo::MakeSelfOwnedReceiver(
base::WrapUnique(new NetworkHintsHandlerImpl(frame_host)),
std::move(receiver));
}