9e0a3c44dd
* chore: bump chromium in DEPS to 105.0.5179.0 * chore: update patches * 3758224: Reland^2 "[flags] Enable freezing of flags" https://chromium-review.googlesource.com/c/v8/v8/+/3758224 * chore: bump chromium in DEPS to 105.0.5181.0 * chore: update patches * chore: bump chromium in DEPS to 105.0.5183.0 * chore: bump chromium in DEPS to 105.0.5185.0 * chore: bump chromium in DEPS to 105.0.5187.0 * chore: update patches * 3723298: Pass RemoteFrame mojo channels through its creation messages. https://chromium-review.googlesource.com/c/chromium/src/+/3723298 * 3737382: [Code Heath] Replace base::{ListValue,DictionaryValue} in skia et al https://chromium-review.googlesource.com/c/chromium/src/+/3737382 * Pass RemoteFrame mojo channels through its creation messages. https://chromium-review.googlesource.com/c/chromium/src/+/3723298 * Changed PrintRenderFrame.PrintWithParams mojo interface to use callback. https://chromium-review.googlesource.com/c/chromium/src/+/3761203 * 3738183: [CSP] Add support for `DisableWasmEval` https://chromium-review.googlesource.com/c/chromium/src/+/3738183 * 3740498: Move LinuxUI from //ui/views/linux_ui to //ui/linux https://chromium-review.googlesource.com/c/chromium/src/+/3740498 * 3558277: Moves subsystem and semantics to enum class https://chromium-review.googlesource.com/c/chromium/src/+/3558277 * chore: fix broken steps-electron-gn-check * 3749583: [arm64] Fix undefined symbol linker error https://chromium-review.googlesource.com/c/v8/v8/+/3749583 Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
125 lines
4.6 KiB
C++
125 lines
4.6 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/web_view_guest_delegate.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
|
|
#include "content/public/browser/navigation_handle.h"
|
|
#include "content/public/browser/render_frame_host.h"
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "content/public/browser/render_view_host.h"
|
|
#include "content/public/browser/render_widget_host.h"
|
|
#include "content/public/browser/render_widget_host_view.h"
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
#include "third_party/blink/public/common/page/page_zoom.h"
|
|
|
|
namespace electron {
|
|
|
|
WebViewGuestDelegate::WebViewGuestDelegate(content::WebContents* embedder,
|
|
api::WebContents* api_web_contents)
|
|
: embedder_web_contents_(embedder), api_web_contents_(api_web_contents) {}
|
|
|
|
WebViewGuestDelegate::~WebViewGuestDelegate() {
|
|
ResetZoomController();
|
|
}
|
|
|
|
void WebViewGuestDelegate::AttachToIframe(
|
|
content::WebContents* embedder_web_contents,
|
|
int embedder_frame_id) {
|
|
embedder_web_contents_ = embedder_web_contents;
|
|
|
|
int embedder_process_id =
|
|
embedder_web_contents_->GetPrimaryMainFrame()->GetProcess()->GetID();
|
|
auto* embedder_frame =
|
|
content::RenderFrameHost::FromID(embedder_process_id, embedder_frame_id);
|
|
DCHECK_EQ(embedder_web_contents_,
|
|
content::WebContents::FromRenderFrameHost(embedder_frame));
|
|
|
|
content::WebContents* guest_web_contents = api_web_contents_->web_contents();
|
|
|
|
// Force a refresh of the webPreferences so that OverrideWebkitPrefs runs on
|
|
// the new web contents before the renderer process initializes.
|
|
// guest_web_contents->NotifyPreferencesChanged();
|
|
|
|
// Attach this inner WebContents |guest_web_contents| to the outer
|
|
// WebContents |embedder_web_contents|. The outer WebContents's
|
|
// frame |embedder_frame| hosts the inner WebContents.
|
|
embedder_web_contents_->AttachInnerWebContents(
|
|
base::WrapUnique<content::WebContents>(guest_web_contents),
|
|
embedder_frame,
|
|
/*remote_frame=*/mojo::NullAssociatedRemote(),
|
|
/*remote_frame_host_receiver=*/mojo::NullAssociatedReceiver(),
|
|
/*is_full_page=*/false);
|
|
|
|
ResetZoomController();
|
|
|
|
embedder_zoom_controller_ =
|
|
WebContentsZoomController::FromWebContents(embedder_web_contents_);
|
|
embedder_zoom_controller_->AddObserver(this);
|
|
auto* zoom_controller = api_web_contents_->GetZoomController();
|
|
zoom_controller->SetEmbedderZoomController(embedder_zoom_controller_);
|
|
|
|
api_web_contents_->Emit("did-attach");
|
|
}
|
|
|
|
void WebViewGuestDelegate::WillDestroy() {
|
|
ResetZoomController();
|
|
}
|
|
|
|
content::WebContents* WebViewGuestDelegate::GetOwnerWebContents() {
|
|
return embedder_web_contents_;
|
|
}
|
|
|
|
void WebViewGuestDelegate::OnZoomLevelChanged(
|
|
content::WebContents* web_contents,
|
|
double level,
|
|
bool is_temporary) {
|
|
if (web_contents == GetOwnerWebContents()) {
|
|
if (is_temporary) {
|
|
api_web_contents_->GetZoomController()->SetTemporaryZoomLevel(level);
|
|
} else {
|
|
api_web_contents_->GetZoomController()->SetZoomLevel(level);
|
|
}
|
|
// Change the default zoom factor to match the embedders' new zoom level.
|
|
double zoom_factor = blink::PageZoomLevelToZoomFactor(level);
|
|
api_web_contents_->GetZoomController()->SetDefaultZoomFactor(zoom_factor);
|
|
}
|
|
}
|
|
|
|
void WebViewGuestDelegate::OnZoomControllerWebContentsDestroyed() {
|
|
ResetZoomController();
|
|
}
|
|
|
|
void WebViewGuestDelegate::ResetZoomController() {
|
|
if (embedder_zoom_controller_) {
|
|
embedder_zoom_controller_->RemoveObserver(this);
|
|
embedder_zoom_controller_ = nullptr;
|
|
}
|
|
}
|
|
|
|
content::WebContents* WebViewGuestDelegate::CreateNewGuestWindow(
|
|
const content::WebContents::CreateParams& create_params) {
|
|
// Code below mirrors what content::WebContentsImpl::CreateNewWindow
|
|
// does for non-guest sources
|
|
content::WebContents::CreateParams guest_params(create_params);
|
|
guest_params.context = embedder_web_contents_->GetNativeView();
|
|
std::unique_ptr<content::WebContents> guest_contents =
|
|
content::WebContents::Create(guest_params);
|
|
if (!create_params.opener_suppressed) {
|
|
auto* guest_contents_impl =
|
|
static_cast<content::WebContentsImpl*>(guest_contents.release());
|
|
auto* new_guest_view = guest_contents_impl->GetView();
|
|
content::RenderWidgetHostView* widget_view =
|
|
new_guest_view->CreateViewForWidget(
|
|
guest_contents_impl->GetRenderViewHost()->GetWidget());
|
|
if (!create_params.initially_hidden)
|
|
widget_view->Show();
|
|
return guest_contents_impl;
|
|
}
|
|
return guest_contents.release();
|
|
}
|
|
|
|
} // namespace electron
|