Skip to content

Commit

Permalink
[HBD] Add console message when plugin throttled or blocked.
Browse files Browse the repository at this point in the history
Also includes some simplifying refactors to LoadablePluginPlaceholder.

Bug: 748257
Change-Id: I1830c47054e4e1c9255ec3939afdec9e36707b66
Reviewed-on: https://chromium-review.googlesource.com/609470
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: Bernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#495595}
  • Loading branch information
Tommy C. Li authored and Commit Bot committed Aug 18, 2017
1 parent b9d5f69 commit 5ba5644
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
33 changes: 22 additions & 11 deletions chrome/renderer/plugins/chrome_plugin_placeholder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/chrome_features.h"
Expand Down Expand Up @@ -60,13 +61,10 @@ ChromePluginPlaceholder::ChromePluginPlaceholder(
const blink::WebPluginParams& params,
const std::string& html_data,
const base::string16& title)
: plugins::LoadablePluginPlaceholder(render_frame,
params,
html_data),
: plugins::LoadablePluginPlaceholder(render_frame, params, html_data),
status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed),
title_(title),
context_menu_request_id_(0),
did_send_blocked_content_notification_(false) {
context_menu_request_id_(0) {
RenderThread::Get()->AddObserver(this);
}

Expand Down Expand Up @@ -359,14 +357,27 @@ blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() {
std::move(throttler));
}

void ChromePluginPlaceholder::OnBlockedTinyContent() {
void ChromePluginPlaceholder::OnBlockedContent(
content::RenderFrame::PeripheralContentStatus status,
bool is_same_origin) {
DCHECK(render_frame());
if (did_send_blocked_content_notification_)
return;

did_send_blocked_content_notification_ = true;
ContentSettingsObserver::Get(render_frame())
->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_);
if (status ==
content::RenderFrame::PeripheralContentStatus::CONTENT_STATUS_TINY) {
ContentSettingsObserver::Get(render_frame())
->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_);
}

std::string message = base::StringPrintf(
is_same_origin ? "Same-origin plugin content from %s must have a visible "
"size larger than 6 x 6 pixels, or it will be blocked. "
"Invisible content is always blocked."
: "Cross-origin plugin content from %s must have a "
"visible size larger than 400 x 300 pixels, or it will "
"be blocked. Invisible content is always blocked.",
GetPluginParams().url.GetString().Utf8().c_str());
render_frame()->AddMessageToConsole(content::CONSOLE_MESSAGE_LEVEL_INFO,
message);
}

gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder(
Expand Down
5 changes: 2 additions & 3 deletions chrome/renderer/plugins/chrome_plugin_placeholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ChromePluginPlaceholder final

// content::LoadablePluginPlaceholder overrides.
blink::WebPlugin* CreatePlugin() override;
void OnBlockedTinyContent() override;
void OnBlockedContent(content::RenderFrame::PeripheralContentStatus status,
bool is_same_origin) override;

// gin::Wrappable (via PluginPlaceholder) method
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
Expand Down Expand Up @@ -95,8 +96,6 @@ class ChromePluginPlaceholder final
int context_menu_request_id_; // Nonzero when request pending.
base::string16 plugin_name_;

bool did_send_blocked_content_notification_;

DISALLOW_COPY_AND_ASSIGN(ChromePluginPlaceholder);
};

Expand Down
31 changes: 15 additions & 16 deletions components/plugins/renderer/loadable_plugin_placeholder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,17 @@ void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
int y = roundf(unobscured_rect_.y() / zoom_factor);

// On a size update check if we now qualify as a essential plugin.
url::Origin main_frame_origin =
render_frame()->GetWebFrame()->Top()->GetSecurityOrigin();
url::Origin content_origin = url::Origin(GetPluginParams().url);
RenderFrame::PeripheralContentStatus status =
render_frame()->GetPeripheralContentStatus(
render_frame()->GetWebFrame()->Top()->GetSecurityOrigin(),
content_origin, gfx::Size(width, height),
main_frame_origin, content_origin, gfx::Size(width, height),
heuristic_run_before_ ? RenderFrame::DONT_RECORD_DECISION
: RenderFrame::RECORD_DECISION);

bool plugin_is_tiny_and_blocked =
is_blocked_for_tinyness_ && status == RenderFrame::CONTENT_STATUS_TINY;

// Early exit for plugins that we've discovered to be essential.
if (!plugin_is_tiny_and_blocked &&
status != RenderFrame::CONTENT_STATUS_PERIPHERAL &&
if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL &&
status != RenderFrame::CONTENT_STATUS_TINY) {
MarkPluginEssential(
heuristic_run_before_
Expand All @@ -233,16 +230,16 @@ void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(

return;
}
heuristic_run_before_ = true;

if (is_blocked_for_tinyness_) {
if (plugin_is_tiny_and_blocked) {
OnBlockedTinyContent();
} else {
is_blocked_for_tinyness_ = false;
if (!LoadingBlocked()) {
LoadPlugin();
}
if (!heuristic_run_before_) {
OnBlockedContent(status,
main_frame_origin.IsSameOriginWith(content_origin));
}

if (is_blocked_for_tinyness_ && status != RenderFrame::CONTENT_STATUS_TINY) {
is_blocked_for_tinyness_ = false;
if (!LoadingBlocked()) {
LoadPlugin();
}
}

Expand All @@ -255,6 +252,8 @@ void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
plugin()->main_frame()->ExecuteScript(
blink::WebScriptSource(blink::WebString::FromUTF8(script)));
}

heuristic_run_before_ = true;
}

void LoadablePluginPlaceholder::WasShown() {
Expand Down
6 changes: 4 additions & 2 deletions components/plugins/renderer/loadable_plugin_placeholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase {
// Plugin creation is embedder-specific.
virtual blink::WebPlugin* CreatePlugin() = 0;

// Embedder-specific behavior.
virtual void OnBlockedTinyContent() = 0;
// Embedder-specific behavior. This will only be called once per placeholder.
virtual void OnBlockedContent(
content::RenderFrame::PeripheralContentStatus status,
bool is_same_origin) = 0;

content::WebPluginInfo plugin_info_;

Expand Down

0 comments on commit 5ba5644

Please sign in to comment.