refactor: turn OnOffscreen message into a command-line flag (#17687)

This turns the AtomViewMsg_Offscreen message, which only called the global setter blink::WebView::SetUseExternalPopupMenus(false) to get Chrome to render popup menus in the renderer instead of externally on macOS, into a command-line renderer flag --offscreen which does the same thing, except at render thread startup time, which is where Chromium sets the flag: https://chromium.googlesource.com/chromium/src/+/refs/tags/75.0.3755.3/content/renderer/render_thread_impl.cc#728.

This was the last usage of RenderViewObserver in our codebase, so this PR also removes that class.
This commit is contained in:
Jeremy Apthorp 2019-04-19 12:55:20 -07:00 committed by Shelley Vohr
parent 1249c6ebf4
commit ab009bba26
9 changed files with 32 additions and 83 deletions

View file

@ -151,10 +151,6 @@ void OffScreenWebContentsView::RenderViewCreated(
content::RenderViewHost* host) {
if (GetView())
GetView()->InstallTransparency();
#if defined(OS_MACOSX)
host->Send(new AtomViewMsg_Offscreen(host->GetRoutingID()));
#endif
}
void OffScreenWebContentsView::RenderViewReady() {}

View file

@ -147,6 +147,23 @@ WebContentsPreferences::WebContentsPreferences(
#endif
SetDefaultBoolIfUndefined(options::kOffscreen, false);
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
// this WebContents is also offscreen-rendered.
int guest_instance_id = 0;
if (web_preferences.Get(options::kGuestInstanceID, &guest_instance_id)) {
auto* manager = WebViewManager::GetWebViewManager(web_contents);
if (manager) {
auto* embedder = manager->GetEmbedder(guest_instance_id);
if (embedder) {
auto* embedder_preferences = WebContentsPreferences::From(embedder);
if (embedder_preferences &&
embedder_preferences->IsEnabled(options::kOffscreen)) {
preference_.SetKey(options::kOffscreen, base::Value(true));
}
}
}
}
last_preference_ = preference_.Clone();
}
@ -309,6 +326,11 @@ void WebContentsPreferences::AppendCommandLineSwitches(
command_line->AppendSwitchASCII(switches::kBackgroundColor, "#fff");
}
// --offscreen
if (IsEnabled(options::kOffscreen)) {
command_line->AppendSwitch(options::kOffscreen);
}
// --guest-instance-id, which is used to identify guest WebContents.
int guest_instance_id = 0;
if (GetAsInteger(&preference_, options::kGuestInstanceID, &guest_instance_id))

View file

@ -25,8 +25,6 @@ IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion)
IPC_STRUCT_TRAITS_MEMBER(bounds)
IPC_STRUCT_TRAITS_END()
IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
IPC_MESSAGE_ROUTED3(AtomAutofillFrameHostMsg_ShowPopup,
gfx::RectF /* bounds */,
std::vector<base::string16> /* values */,

View file

@ -9,7 +9,6 @@
#include "base/memory/weak_ptr.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/blink/public/web/web_autofill_client.h"
#include "third_party/blink/public/web/web_form_control_element.h"
#include "third_party/blink/public/web/web_input_element.h"

View file

@ -1,37 +0,0 @@
// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/renderer/atom_render_view_observer.h"
#include "atom/common/api/api_messages.h"
#include "content/public/renderer/render_view.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/blink/public/web/web_view.h"
namespace atom {
AtomRenderViewObserver::AtomRenderViewObserver(content::RenderView* render_view)
: content::RenderViewObserver(render_view) {}
AtomRenderViewObserver::~AtomRenderViewObserver() {}
bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
IPC_MESSAGE_HANDLER(AtomViewMsg_Offscreen, OnOffscreen)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void AtomRenderViewObserver::OnDestruct() {
delete this;
}
void AtomRenderViewObserver::OnOffscreen() {
blink::WebView::SetUseExternalPopupMenus(false);
}
} // namespace atom

View file

@ -1,31 +0,0 @@
// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_RENDERER_ATOM_RENDER_VIEW_OBSERVER_H_
#define ATOM_RENDERER_ATOM_RENDER_VIEW_OBSERVER_H_
#include "content/public/renderer/render_view_observer.h"
namespace atom {
class AtomRenderViewObserver : public content::RenderViewObserver {
public:
explicit AtomRenderViewObserver(content::RenderView* render_view);
protected:
~AtomRenderViewObserver() override;
private:
// content::RenderViewObserver implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void OnDestruct() override;
void OnOffscreen();
DISALLOW_COPY_AND_ASSIGN(AtomRenderViewObserver);
};
} // namespace atom
#endif // ATOM_RENDERER_ATOM_RENDER_VIEW_OBSERVER_H_

View file

@ -13,13 +13,13 @@
#include "atom/common/options_switches.h"
#include "atom/renderer/atom_autofill_agent.h"
#include "atom/renderer/atom_render_frame_observer.h"
#include "atom/renderer/atom_render_view_observer.h"
#include "atom/renderer/content_settings_observer.h"
#include "atom/renderer/electron_api_service_impl.h"
#include "atom/renderer/preferences_manager.h"
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "content/common/buildflags.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
@ -142,6 +142,15 @@ void RendererClientBase::AddRenderBindings(
void RendererClientBase::RenderThreadStarted() {
auto* command_line = base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
// On macOS, popup menus are rendered by the main process by default.
// This causes problems in OSR, since when the popup is rendered separately,
// it won't be captured in the rendered image.
if (command_line->HasSwitch(options::kOffscreen)) {
blink::WebView::SetUseExternalPopupMenus(false);
}
#endif
blink::WebCustomElement::AddEmbedderCustomElementName("webview");
blink::WebCustomElement::AddEmbedderCustomElementName("browserplugin");
@ -252,10 +261,6 @@ void RendererClientBase::RenderFrameCreated(
}
}
void RendererClientBase::RenderViewCreated(content::RenderView* render_view) {
new AtomRenderViewObserver(render_view);
}
void RendererClientBase::DidClearWindowObject(
content::RenderFrame* render_frame) {
// Make sure every page will get a script context created.

View file

@ -54,7 +54,6 @@ class RendererClientBase : public content::ContentRendererClient {
// content::ContentRendererClient:
void RenderThreadStarted() override;
void RenderFrameCreated(content::RenderFrame*) override;
void RenderViewCreated(content::RenderView*) override;
std::unique_ptr<blink::WebSpeechSynthesizer> OverrideSpeechSynthesizer(
blink::WebSpeechSynthesizerClient* client) override;
bool OverrideCreatePlugin(content::RenderFrame* render_frame,

View file

@ -656,8 +656,6 @@ filenames = {
"atom/renderer/atom_autofill_agent.h",
"atom/renderer/atom_render_frame_observer.cc",
"atom/renderer/atom_render_frame_observer.h",
"atom/renderer/atom_render_view_observer.cc",
"atom/renderer/atom_render_view_observer.h",
"atom/renderer/atom_renderer_client.cc",
"atom/renderer/atom_renderer_client.h",
"atom/renderer/content_settings_observer.cc",