Chromium Code Reviews| Index: content/renderer/pepper/pepper_plugin_instance_impl.cc |
| diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| index e22101ba7c5f8660dd9d5d8a401b6c1139100266..52795cc422dcabf53b83e18fca6a3771f01ab671 100644 |
| --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| @@ -21,6 +21,7 @@ |
| #include "cc/layers/texture_layer.h" |
| #include "cc/trees/layer_tree_host.h" |
| #include "content/common/content_constants_internal.h" |
| +#include "content/common/frame_messages.h" |
| #include "content/common/input/web_input_event_traits.h" |
| #include "content/public/common/content_constants.h" |
| #include "content/public/common/content_switches.h" |
| @@ -225,6 +226,11 @@ const char kHeight[] = "height"; |
| const char kBorder[] = "border"; // According to w3c, deprecated. |
| const char kStyle[] = "style"; |
| +// Maximum dimensions plug-in content may have while still being considered |
|
Lei Zhang
2014/10/28 02:16:23
Mention these match Safari's sizes.
tommycli
2014/10/28 22:18:07
Done.
|
| +// peripheral content. |
| +const int kPeripheralContentMaxWidth = 400; |
| +const int kPeripheralContentMaxHeight = 300; |
| + |
| COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_MOUSECURSOR_TYPE_POINTER); |
| COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_MOUSECURSOR_TYPE_CROSS); |
| COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_MOUSECURSOR_TYPE_HAND); |
| @@ -2052,6 +2058,18 @@ bool PepperPluginInstanceImpl::PrepareTextureMailbox( |
| void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } |
| +bool PepperPluginInstanceImpl::OnMessageReceived(const IPC::Message& message) { |
| + // We set "handled" to false here, because we want this broadcast message to |
|
Lei Zhang
2014/10/28 02:16:23
Do you want to coordinate this at the PluginModule
tommycli
2014/10/28 22:18:07
Done. I made a PluginPowerSaverHelper class to con
|
| + // be processed by every PepperPluginInstanceImpl, and not swallowed. |
| + bool handled = false; |
|
tommycli
2014/10/27 23:35:53
I set (handled = false) to make sure every instanc
groby-ooo-7-16
2014/10/28 00:39:12
You don't need this - as is, the code will _always
|
| + IPC_BEGIN_MESSAGE_MAP(PepperPluginInstanceImpl, message) |
| + IPC_MESSAGE_HANDLER(FrameMsg_PluginContentOriginWhitelisted, |
| + OnPluginContentOriginWhitelisted) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| void PepperPluginInstanceImpl::AddLatencyInfo( |
| const std::vector<ui::LatencyInfo>& latency_info) { |
| if (render_frame_ && render_frame_->GetRenderWidget()) { |
| @@ -3295,15 +3313,15 @@ void PepperPluginInstanceImpl::DidDataFromWebURLResponse( |
| } |
| } |
| -bool PepperPluginInstanceImpl::IsPeripheralContent() const { |
| +bool PepperPluginInstanceImpl::IsPeripheralContent() { |
| if (module_->name() != kFlashPluginName) |
| return false; |
| - // Peripheral plugin content is defined to be peripheral when the plugin |
| - // content's origin differs from the top level frame's origin. For example: |
| - // - Peripheral: a.com -> b.com/plugin.swf |
| - // - Peripheral: a.com -> b.com/iframe.html -> b.com/plugin.swf |
| - // - NOT peripheral: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf |
| + // Plugin content is defined to be cross-origin when the plugin source's |
| + // origin differs from the top level frame's origin. For example: |
| + // - Cross-origin: a.com -> b.com/plugin.swf |
| + // - Cross-origin: a.com -> b.com/iframe.html -> b.com/plugin.swf |
| + // - Same-origin: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf |
| // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 |
| // is fixed. For now, case 3 in the comment above doesn't work in |
| @@ -3312,8 +3330,31 @@ bool PepperPluginInstanceImpl::IsPeripheralContent() const { |
| if (main_frame->isWebRemoteFrame()) |
| return true; |
| + // All same-origin plugin content is essential. |
| GURL main_frame_url = main_frame->document().url(); |
|
Lei Zhang
2014/10/28 02:16:23
nit: replace |main_frame_url| with |main_frame_ori
tommycli
2014/10/28 22:18:07
Done.
|
| - return plugin_url_.GetOrigin() != main_frame_url.GetOrigin(); |
| + GURL plugin_origin = plugin_url_.GetOrigin(); |
| + if (plugin_origin == main_frame_url.GetOrigin()) |
| + return false; |
| + |
| + // Cross-origin plugin content is peripheral if smaller than a maximum size. |
| + blink::WebRect bounds = container()->element().boundsInViewportSpace(); |
| + bool content_is_large = bounds.width < kPeripheralContentMaxWidth || |
|
Lei Zhang
2014/10/28 02:16:23
Shouldn't the variable be named "content_is_small"
tommycli
2014/10/28 22:18:07
Done.
|
| + bounds.height < kPeripheralContentMaxHeight; |
| + |
| + if (content_is_large) { |
| + // Large cross-origin plugin content should temporarily whitelist all |
| + // content from that origin for that top level frame. This whitelist is |
| + // cleared when this render frame is destroyed. |
| + Send(new FrameHostMsg_PluginContentOriginAllowed( |
|
Lei Zhang
2014/10/28 02:16:23
It's weird that an IsFoo() method has side effects
tommycli
2014/10/28 22:18:07
Done.
|
| + render_frame()->GetRoutingID(), |
| + plugin_origin)); |
| + } else { |
| + Send(new FrameHostMsg_PluginContentMarkedPeripheral( |
| + render_frame()->GetRoutingID(), |
| + plugin_origin)); |
| + } |
| + |
| + return content_is_large; |
| } |
| void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
| @@ -3325,4 +3366,12 @@ void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
| SendDidChangeView(); |
| } |
| +void PepperPluginInstanceImpl::OnPluginContentOriginWhitelisted( |
| + const GURL& content_origin) { |
| + if (content_origin == plugin_url_.GetOrigin()) { |
| + power_saver_enabled_ = false; |
| + SetPluginThrottled(false); |
|
groby-ooo-7-16
2014/10/28 00:39:12
Why not just SetPluginThrottled(false)?
tommycli
2014/10/28 22:18:07
power_saver_enabled_ needs to be set to false, so
|
| + } |
| +} |
| + |
| } // namespace content |