Commit 8b49b032 authored by Darin Fisher's avatar Darin Fisher Committed by Commit Bot

Migrate LoadBlockedPlugins IPC to Mojo.

Bug: 993189
Change-Id: I709dd4bf32e24e712efbaff8a5431f2297d05ac1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517922
Commit-Queue: Darin Fisher <darin@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824919}
parent 9682dbed
......@@ -14,7 +14,7 @@
#include "chrome/browser/plugins/plugin_metadata.h"
#include "chrome/browser/plugins/plugin_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
......@@ -24,6 +24,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_constants.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
using content::BrowserThread;
using content::PluginService;
......@@ -61,11 +62,6 @@ class ProfileContentSettingObserver : public content_settings::Observer {
Profile* profile_;
};
void AuthorizeRenderer(content::RenderFrameHost* render_frame_host) {
ChromePluginServiceFilter::GetInstance()->AuthorizePlugin(
render_frame_host->GetProcess()->GetID(), base::FilePath());
}
} // namespace
// ChromePluginServiceFilter inner struct definitions.
......@@ -152,10 +148,24 @@ void ChromePluginServiceFilter::AuthorizeAllPlugins(
bool load_blocked,
const std::string& identifier) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
web_contents->ForEachFrame(base::BindRepeating(&AuthorizeRenderer));
web_contents->ForEachFrame(
base::BindRepeating([](content::RenderFrameHost* render_frame_host) {
ChromePluginServiceFilter::GetInstance()->AuthorizePlugin(
render_frame_host->GetProcess()->GetID(), base::FilePath());
}));
if (load_blocked) {
web_contents->SendToAllFrames(new ChromeViewMsg_LoadBlockedPlugins(
MSG_ROUTING_NONE, identifier));
web_contents->ForEachFrame(base::BindRepeating(
[](const std::string& identifier,
content::RenderFrameHost* render_frame_host) {
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame>
chrome_render_frame;
render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
&chrome_render_frame);
chrome_render_frame->LoadBlockedPlugins(identifier);
},
identifier));
}
}
......
......@@ -58,4 +58,8 @@ interface ChromeRenderFrame {
// Requests the Media Feed Url from the renderer (if the page has one).
GetMediaFeedURL() => (url.mojom.Url? url);
// Tells the render frame to load any blocked plugins matching the given
// identifier (empty string matches all).
LoadBlockedPlugins(string identifier);
};
......@@ -5,8 +5,6 @@
#ifndef CHROME_COMMON_RENDER_MESSAGES_H_
#define CHROME_COMMON_RENDER_MESSAGES_H_
#include <string>
#include "chrome/common/web_application_info_provider_param_traits.h"
#include "ipc/ipc_message_macros.h"
#include "url/gurl.h"
......@@ -21,14 +19,6 @@
#define IPC_MESSAGE_START ChromeMsgStart
//-----------------------------------------------------------------------------
// RenderView messages
// These are messages sent from the browser to the renderer process.
// Tells the render frame to load all blocked plugins with the given identifier.
IPC_MESSAGE_ROUTED1(ChromeViewMsg_LoadBlockedPlugins,
std::string /* identifier */)
//-----------------------------------------------------------------------------
// Misc messages
// These are messages sent from the renderer to the browser process.
......
......@@ -57,6 +57,11 @@ bool ChromeContentSettingsAgentDelegate::IsPluginTemporarilyAllowed(
base::Contains(temporarily_allowed_plugins_, std::string());
}
void ChromeContentSettingsAgentDelegate::AllowPluginTemporarily(
const std::string& identifier) {
temporarily_allowed_plugins_.insert(identifier);
}
bool ChromeContentSettingsAgentDelegate::IsSchemeAllowlisted(
const std::string& scheme) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
......@@ -125,16 +130,6 @@ void ChromeContentSettingsAgentDelegate::PassiveInsecureContentFound(
FilteredReportInsecureContentDisplayed(GURL(resource_url));
}
bool ChromeContentSettingsAgentDelegate::OnMessageReceived(
const IPC::Message& message) {
// Don't swallow LoadBlockedPlugins messages, as they're sent to every
// blocked plugin.
IPC_BEGIN_MESSAGE_MAP(ChromeContentSettingsAgentDelegate, message)
IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
IPC_END_MESSAGE_MAP()
return false;
}
void ChromeContentSettingsAgentDelegate::DidCommitProvisionalLoad(
ui::PageTransition transition) {
if (render_frame()->GetWebFrame()->Parent())
......@@ -145,11 +140,6 @@ void ChromeContentSettingsAgentDelegate::DidCommitProvisionalLoad(
void ChromeContentSettingsAgentDelegate::OnDestruct() {}
void ChromeContentSettingsAgentDelegate::OnLoadBlockedPlugins(
const std::string& identifier) {
temporarily_allowed_plugins_.insert(identifier);
}
bool ChromeContentSettingsAgentDelegate::IsPlatformApp() {
#if BUILDFLAG(ENABLE_EXTENSIONS)
blink::WebLocalFrame* frame = render_frame_->GetWebFrame();
......
......@@ -32,6 +32,7 @@ class ChromeContentSettingsAgentDelegate
#endif
bool IsPluginTemporarilyAllowed(const std::string& identifier);
void AllowPluginTemporarily(const std::string& identifier);
// content_settings::ContentSettingsAgentImpl::Delegate:
bool IsSchemeAllowlisted(const std::string& scheme) override;
......@@ -45,12 +46,9 @@ class ChromeContentSettingsAgentDelegate
PluginsTemporarilyAllowed);
// RenderFrameObserver:
bool OnMessageReceived(const IPC::Message& message) override;
void DidCommitProvisionalLoad(ui::PageTransition transition) override;
void OnDestruct() override;
void OnLoadBlockedPlugins(const std::string& identifier);
// Whether the observed RenderFrame is for a platform app.
bool IsPlatformApp();
......
......@@ -40,7 +40,7 @@ TEST_F(ChromeContentSettingsAgentDelegateBrowserTest,
EXPECT_FALSE(delegate->IsPluginTemporarilyAllowed(foo_plugin));
// Temporarily allow the "foo" plugin.
delegate->OnLoadBlockedPlugins(foo_plugin);
delegate->AllowPluginTemporarily(foo_plugin);
EXPECT_TRUE(delegate->IsPluginTemporarilyAllowed(foo_plugin));
EXPECT_FALSE(delegate->IsPluginTemporarilyAllowed(bar_plugin));
......@@ -55,7 +55,7 @@ TEST_F(ChromeContentSettingsAgentDelegateBrowserTest,
EXPECT_FALSE(delegate->IsPluginTemporarilyAllowed(bar_plugin));
// Temporarily allow all plugins.
delegate->OnLoadBlockedPlugins(std::string());
delegate->AllowPluginTemporarily(std::string());
EXPECT_TRUE(delegate->IsPluginTemporarilyAllowed(foo_plugin));
EXPECT_TRUE(delegate->IsPluginTemporarilyAllowed(bar_plugin));
}
......@@ -23,6 +23,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/open_search_description_document_handler.mojom.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/chrome_content_settings_agent_delegate.h"
#include "chrome/renderer/media/media_feeds.h"
#include "chrome/renderer/web_apps.h"
#include "components/crash/core/common/crash_key.h"
......@@ -69,6 +70,10 @@
#include "chrome/common/mhtml_page_notifier.mojom.h"
#endif
#if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
#endif
using blink::WebDocumentLoader;
using blink::WebElement;
using blink::WebFrameContentDumper;
......@@ -433,6 +438,24 @@ void ChromeRenderFrameObserver::GetMediaFeedURL(
std::move(callback).Run(MediaFeeds::GetMediaFeedURL(render_frame()));
}
void ChromeRenderFrameObserver::LoadBlockedPlugins(
const std::string& identifier) {
// Record that this plugin is temporarily allowed and notify all placeholders.
ChromeContentSettingsAgentDelegate::Get(render_frame())
->AllowPluginTemporarily(identifier);
#if BUILDFLAG(ENABLE_PLUGINS)
ChromePluginPlaceholder::ForEach(
render_frame(), base::BindRepeating(
[](const std::string& identifier,
ChromePluginPlaceholder* placeholder) {
placeholder->MaybeLoadBlockedPlugin(identifier);
},
identifier));
#endif // BUILDFLAG(ENABLE_PLUGINS)
}
void ChromeRenderFrameObserver::SetClientSidePhishingDetection() {
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
phishing_classifier_ = safe_browsing::PhishingClassifierDelegate::Create(
......
......@@ -91,6 +91,7 @@ class ChromeRenderFrameObserver : public content::RenderFrameObserver,
void SetCCTClientHeader(const std::string& header) override;
#endif
void GetMediaFeedURL(GetMediaFeedURLCallback callback) override;
void LoadBlockedPlugins(const std::string& identifier) override;
// Initialize a |phishing_classifier_delegate_|.
void SetClientSidePhishingDetection();
......
......@@ -5,6 +5,7 @@
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
#include <memory>
#include <set>
#include <utility>
#include "base/command_line.h"
......@@ -54,6 +55,36 @@ using content::RenderView;
namespace {
const ChromePluginPlaceholder* g_last_active_menu = nullptr;
const char kPlaceholderSetKey[] = "kPlaceholderSetKey";
class PlaceholderSet : public base::SupportsUserData::Data {
public:
~PlaceholderSet() override = default;
static PlaceholderSet* Get(content::RenderFrame* render_frame) {
DCHECK(render_frame);
return static_cast<PlaceholderSet*>(
render_frame->GetUserData(kPlaceholderSetKey));
}
static PlaceholderSet* GetOrCreate(content::RenderFrame* render_frame) {
PlaceholderSet* set = Get(render_frame);
if (!set) {
set = new PlaceholderSet();
render_frame->SetUserData(kPlaceholderSetKey, base::WrapUnique(set));
}
return set;
}
std::set<ChromePluginPlaceholder*>& placeholders() { return placeholders_; }
private:
PlaceholderSet() = default;
std::set<ChromePluginPlaceholder*> placeholders_;
};
} // namespace
gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = {
......@@ -70,18 +101,26 @@ ChromePluginPlaceholder::ChromePluginPlaceholder(
context_menu_request_id_(0) {
RenderThread::Get()->AddObserver(this);
prerender::PrerenderObserverList::AddObserverForFrame(render_frame, this);
// Keep track of all placeholders associated with |render_frame|.
PlaceholderSet::GetOrCreate(render_frame)->placeholders().insert(this);
}
ChromePluginPlaceholder::~ChromePluginPlaceholder() {
RenderThread::Get()->RemoveObserver(this);
// The render frame may already be gone.
if (render_frame()) {
PlaceholderSet* set = PlaceholderSet::Get(render_frame());
if (set)
set->placeholders().erase(this);
prerender::PrerenderObserverList::RemoveObserverForFrame(render_frame(),
this);
}
if (context_menu_request_id_ && render_frame())
render_frame()->CancelContextMenu(context_menu_request_id_);
if (context_menu_request_id_)
render_frame()->CancelContextMenu(context_menu_request_id_);
}
}
mojo::PendingRemote<chrome::mojom::PluginRenderer>
......@@ -148,18 +187,19 @@ ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin(
return blocked_plugin;
}
void ChromePluginPlaceholder::SetStatus(chrome::mojom::PluginStatus status) {
status_ = status;
// static
void ChromePluginPlaceholder::ForEach(
content::RenderFrame* render_frame,
const base::RepeatingCallback<void(ChromePluginPlaceholder*)>& callback) {
PlaceholderSet* set = PlaceholderSet::Get(render_frame);
if (set) {
for (auto* placeholder : set->placeholders())
callback.Run(placeholder);
}
}
bool ChromePluginPlaceholder::OnMessageReceived(const IPC::Message& message) {
// We don't swallow these messages because multiple blocked plugins and other
// objects have an interest in them.
IPC_BEGIN_MESSAGE_MAP(ChromePluginPlaceholder, message)
IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
IPC_END_MESSAGE_MAP()
return false;
void ChromePluginPlaceholder::SetStatus(chrome::mojom::PluginStatus status) {
status_ = status;
}
void ChromePluginPlaceholder::ShowPermissionBubbleCallback() {
......
......@@ -43,6 +43,11 @@ class ChromePluginPlaceholder final
content::RenderFrame* render_frame,
const blink::WebPluginParams& params);
// Runs |callback| over each plugin placeholder for the given RenderFrame.
static void ForEach(
content::RenderFrame* render_frame,
const base::RepeatingCallback<void(ChromePluginPlaceholder*)>& callback);
void SetStatus(chrome::mojom::PluginStatus status);
mojo::PendingRemote<chrome::mojom::PluginRenderer> BindPluginRenderer();
......@@ -63,9 +68,6 @@ class ChromePluginPlaceholder final
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) final;
// content::RenderViewObserver (via PluginPlaceholder) override:
bool OnMessageReceived(const IPC::Message& message) override;
// WebViewPlugin::Delegate (via PluginPlaceholder) methods:
v8::Local<v8::Value> GetV8Handle(v8::Isolate* isolate) override;
void ShowContextMenu(const blink::WebMouseEvent&) override;
......
......@@ -29,6 +29,15 @@ using content::RenderThread;
namespace plugins {
void LoadablePluginPlaceholder::MaybeLoadBlockedPlugin(
const std::string& identifier) {
if (!identifier.empty() && identifier != identifier_)
return;
RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_UI"));
LoadPlugin();
}
LoadablePluginPlaceholder::LoadablePluginPlaceholder(
RenderFrame* render_frame,
const blink::WebPluginParams& params,
......@@ -98,15 +107,6 @@ bool LoadablePluginPlaceholder::IsErrorPlaceholder() {
return !allow_loading_;
}
void LoadablePluginPlaceholder::OnLoadBlockedPlugins(
const std::string& identifier) {
if (!identifier.empty() && identifier != identifier_)
return;
RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_UI"));
LoadPlugin();
}
void LoadablePluginPlaceholder::OnSetIsPrerendering(bool is_prerendering) {
// Prerendering can only be enabled prior to a RenderView's first navigation,
// so no BlockedPlugin should see the notification that enables prerendering.
......
......@@ -26,13 +26,15 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase {
void AllowLoading() { allow_loading_ = true; }
// Load the blocked plugin if the identifier matches (or is empty).
void MaybeLoadBlockedPlugin(const std::string& identifier);
protected:
LoadablePluginPlaceholder(content::RenderFrame* render_frame,
const blink::WebPluginParams& params,
const std::string& html_data);
~LoadablePluginPlaceholder() override;
void OnLoadBlockedPlugins(const std::string& identifier);
void OnSetIsPrerendering(bool is_prerendering);
void SetMessage(const base::string16& message);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment