mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-02 20:26:59 +01:00
d9efaee9b9
When navigating cross-origin a speculative RenderFrameHost (RFH) and CefFrameHostImpl is created in the browser process for the new frame object created in a new renderer process. The FrameAttached message then arrives for the speculative RFH, and as a consequence interfaces are bound between the new CefFrameHostImpl and the speculative RFH. If the pending navigation commits then the existing RFH will be replaced with the previously speculative RFH. Since interfaces are already bound we must keep the new CefFrameHostImpl. This means that frame objects (including for the main frame) will now always change after cross-origin navigation, and the old frame object will be invalidated.
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
// Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "libcef/browser/browser_frame.h"
|
|
|
|
#include "libcef/browser/browser_host_base.h"
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "content/public/browser/web_contents.h"
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
|
|
|
CefBrowserFrame::CefBrowserFrame(
|
|
content::RenderFrameHost* render_frame_host,
|
|
mojo::PendingReceiver<cef::mojom::BrowserFrame> receiver)
|
|
: FrameServiceBase(render_frame_host, std::move(receiver)) {}
|
|
|
|
CefBrowserFrame::~CefBrowserFrame() = default;
|
|
|
|
// static
|
|
void CefBrowserFrame::RegisterBrowserInterfaceBindersForFrame(
|
|
content::RenderFrameHost* render_frame_host,
|
|
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {
|
|
map->Add<cef::mojom::BrowserFrame>(base::BindRepeating(
|
|
[](content::RenderFrameHost* frame_host,
|
|
mojo::PendingReceiver<cef::mojom::BrowserFrame> receiver) {
|
|
// This object is bound to the lifetime of |frame_host| and the mojo
|
|
// connection. See FrameServiceBase for details.
|
|
new CefBrowserFrame(frame_host, std::move(receiver));
|
|
}));
|
|
}
|
|
|
|
void CefBrowserFrame::SendMessage(const std::string& name,
|
|
base::Value arguments) {
|
|
if (auto host = GetFrameHost()) {
|
|
host->SendMessage(name, std::move(arguments));
|
|
}
|
|
}
|
|
|
|
void CefBrowserFrame::FrameAttached() {
|
|
// Always send to the newly created RFH, which may be speculative when
|
|
// navigating cross-origin.
|
|
if (auto host = GetFrameHost(/*prefer_speculative=*/true)) {
|
|
host->FrameAttached();
|
|
}
|
|
}
|
|
|
|
void CefBrowserFrame::DidFinishFrameLoad(const GURL& validated_url,
|
|
int http_status_code) {
|
|
if (auto host = GetFrameHost()) {
|
|
host->DidFinishFrameLoad(validated_url, http_status_code);
|
|
}
|
|
}
|
|
|
|
void CefBrowserFrame::UpdateDraggableRegions(
|
|
base::Optional<std::vector<cef::mojom::DraggableRegionEntryPtr>> regions) {
|
|
if (auto host = GetFrameHost()) {
|
|
host->UpdateDraggableRegions(std::move(regions));
|
|
}
|
|
}
|
|
|
|
CefRefPtr<CefFrameHostImpl> CefBrowserFrame::GetFrameHost(
|
|
bool prefer_speculative) const {
|
|
CEF_REQUIRE_UIT();
|
|
auto rfh = render_frame_host();
|
|
if (auto browser = CefBrowserHostBase::GetBrowserForHost(rfh)) {
|
|
return browser->browser_info()->GetFrameForHost(rfh, nullptr,
|
|
prefer_speculative);
|
|
}
|
|
NOTREACHED();
|
|
return nullptr;
|
|
}
|