| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" | 5 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const blink::WebPluginParams& params, | 58 const blink::WebPluginParams& params, |
| 59 const std::string& html_data, | 59 const std::string& html_data, |
| 60 const base::string16& title) | 60 const base::string16& title) |
| 61 : plugins::LoadablePluginPlaceholder(render_frame, | 61 : plugins::LoadablePluginPlaceholder(render_frame, |
| 62 frame, | 62 frame, |
| 63 params, | 63 params, |
| 64 html_data), | 64 html_data), |
| 65 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed), | 65 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed), |
| 66 title_(title), | 66 title_(title), |
| 67 context_menu_request_id_(0), | 67 context_menu_request_id_(0), |
| 68 ignore_updates_(false) { | 68 did_send_blocked_content_notification_(false) { |
| 69 RenderThread::Get()->AddObserver(this); | 69 RenderThread::Get()->AddObserver(this); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ChromePluginPlaceholder::~ChromePluginPlaceholder() { | 72 ChromePluginPlaceholder::~ChromePluginPlaceholder() { |
| 73 RenderThread::Get()->RemoveObserver(this); | 73 RenderThread::Get()->RemoveObserver(this); |
| 74 if (context_menu_request_id_ && render_frame()) | 74 if (context_menu_request_id_ && render_frame()) |
| 75 render_frame()->CancelContextMenu(context_menu_request_id_); | 75 render_frame()->CancelContextMenu(context_menu_request_id_); |
| 76 | 76 |
| 77 #if defined(ENABLE_PLUGIN_INSTALLATION) | 77 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 78 if (placeholder_routing_id_ == MSG_ROUTING_NONE) | 78 if (placeholder_routing_id_ == MSG_ROUTING_NONE) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 blocked_plugin->SetPluginInfo(info); | 163 blocked_plugin->SetPluginInfo(info); |
| 164 blocked_plugin->SetIdentifier(identifier); | 164 blocked_plugin->SetIdentifier(identifier); |
| 165 | 165 |
| 166 blocked_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled); | 166 blocked_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled); |
| 167 blocked_plugin->set_blocked_for_background_tab( | 167 blocked_plugin->set_blocked_for_background_tab( |
| 168 power_saver_info.blocked_for_background_tab); | 168 power_saver_info.blocked_for_background_tab); |
| 169 | 169 |
| 170 return blocked_plugin; | 170 return blocked_plugin; |
| 171 } | 171 } |
| 172 | 172 |
| 173 // static | |
| 174 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateDelayedPlugin( | |
| 175 content::RenderFrame* render_frame, | |
| 176 blink::WebLocalFrame* frame, | |
| 177 const blink::WebPluginParams& params, | |
| 178 const content::WebPluginInfo& info, | |
| 179 const std::string& identifier, | |
| 180 const base::string16& name, | |
| 181 const PowerSaverInfo& power_saver_info) { | |
| 182 // Can never be called with an actual poster. | |
| 183 DCHECK(power_saver_info.poster_attribute.empty()); | |
| 184 | |
| 185 // Can never be called when blocked for background tab. | |
| 186 DCHECK(!power_saver_info.blocked_for_background_tab); | |
| 187 | |
| 188 const base::StringPiece template_html( | |
| 189 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 190 IDR_PLUGIN_DELAY_HTML)); | |
| 191 base::DictionaryValue values; | |
| 192 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); | |
| 193 | |
| 194 // |delay_plugin| will destroy itself when its WebViewPlugin is going away. | |
| 195 ChromePluginPlaceholder* delay_plugin = | |
| 196 new ChromePluginPlaceholder(render_frame, frame, params, html_data, name); | |
| 197 | |
| 198 delay_plugin->set_delayed(true); | |
| 199 delay_plugin->SetPluginInfo(info); | |
| 200 delay_plugin->SetIdentifier(identifier); | |
| 201 delay_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled); | |
| 202 | |
| 203 return delay_plugin; | |
| 204 } | |
| 205 | |
| 206 void ChromePluginPlaceholder::SetStatus( | 173 void ChromePluginPlaceholder::SetStatus( |
| 207 ChromeViewHostMsg_GetPluginInfo_Status status) { | 174 ChromeViewHostMsg_GetPluginInfo_Status status) { |
| 208 status_ = status; | 175 status_ = status; |
| 209 } | 176 } |
| 210 | 177 |
| 211 #if defined(ENABLE_PLUGIN_INSTALLATION) | 178 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 212 int32_t ChromePluginPlaceholder::CreateRoutingId() { | 179 int32_t ChromePluginPlaceholder::CreateRoutingId() { |
| 213 placeholder_routing_id_ = RenderThread::Get()->GenerateRoutingID(); | 180 placeholder_routing_id_ = RenderThread::Get()->GenerateRoutingID(); |
| 214 RenderThread::Get()->AddRoute(placeholder_routing_id_, this); | 181 RenderThread::Get()->AddRoute(placeholder_routing_id_, this); |
| 215 return placeholder_routing_id_; | 182 return placeholder_routing_id_; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // PluginPreroller manages its own lifetime. | 368 // PluginPreroller manages its own lifetime. |
| 402 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(), | 369 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(), |
| 403 GetPluginInfo(), GetIdentifier(), title_, | 370 GetPluginInfo(), GetIdentifier(), title_, |
| 404 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_), | 371 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_), |
| 405 throttler.get()); | 372 throttler.get()); |
| 406 } | 373 } |
| 407 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(), | 374 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(), |
| 408 GetPluginParams(), std::move(throttler)); | 375 GetPluginParams(), std::move(throttler)); |
| 409 } | 376 } |
| 410 | 377 |
| 411 void ChromePluginPlaceholder::OnLoadedRectUpdate( | 378 void ChromePluginPlaceholder::OnBlockedTinyContent() { |
| 412 const gfx::Rect& unobscured_rect, | 379 if (did_send_blocked_content_notification_) |
| 413 content::RenderFrame::PeripheralContentStatus status) { | |
| 414 // If the placeholder is in the blocked state, do nothing. | |
| 415 if (ignore_updates_) | |
| 416 return; | 380 return; |
| 417 | 381 |
| 418 // This should only be called once. | 382 did_send_blocked_content_notification_ = true; |
| 419 set_delayed(false); | 383 ContentSettingsObserver::Get(render_frame()) |
| 420 | 384 ->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_); |
| 421 // block tiny cross-origin - simply by not continuing the load chain. | |
| 422 if (status == | |
| 423 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY) { | |
| 424 ContentSettingsObserver* observer = | |
| 425 ContentSettingsObserver::Get(render_frame()); | |
| 426 observer->DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, title_); | |
| 427 AllowLoading(); | |
| 428 ignore_updates_ = true; | |
| 429 return; | |
| 430 } | |
| 431 | |
| 432 // For essential content, powersaver can be turned off. | |
| 433 if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) | |
| 434 set_power_saver_enabled(false); | |
| 435 | |
| 436 AllowLoading(); | |
| 437 LoadPlugin(); | |
| 438 } | 385 } |
| 439 | 386 |
| 440 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( | 387 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( |
| 441 v8::Isolate* isolate) { | 388 v8::Isolate* isolate) { |
| 442 gin::ObjectTemplateBuilder builder = | 389 gin::ObjectTemplateBuilder builder = |
| 443 gin::Wrappable<ChromePluginPlaceholder>::GetObjectTemplateBuilder(isolate) | 390 gin::Wrappable<ChromePluginPlaceholder>::GetObjectTemplateBuilder(isolate) |
| 444 .SetMethod<void (ChromePluginPlaceholder::*)()>( | 391 .SetMethod<void (ChromePluginPlaceholder::*)()>( |
| 445 "hide", &ChromePluginPlaceholder::HideCallback) | 392 "hide", &ChromePluginPlaceholder::HideCallback) |
| 446 .SetMethod<void (ChromePluginPlaceholder::*)()>( | 393 .SetMethod<void (ChromePluginPlaceholder::*)()>( |
| 447 "load", &ChromePluginPlaceholder::LoadCallback) | 394 "load", &ChromePluginPlaceholder::LoadCallback) |
| 448 .SetMethod<void (ChromePluginPlaceholder::*)()>( | 395 .SetMethod<void (ChromePluginPlaceholder::*)()>( |
| 449 "didFinishLoading", | 396 "didFinishLoading", |
| 450 &ChromePluginPlaceholder::DidFinishLoadingCallback) | 397 &ChromePluginPlaceholder::DidFinishLoadingCallback) |
| 451 .SetMethod("openAboutPlugins", | 398 .SetMethod("openAboutPlugins", |
| 452 &ChromePluginPlaceholder::OpenAboutPluginsCallback); | 399 &ChromePluginPlaceholder::OpenAboutPluginsCallback); |
| 453 | 400 |
| 454 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 401 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 455 switches::kEnablePluginPlaceholderTesting)) { | 402 switches::kEnablePluginPlaceholderTesting)) { |
| 456 builder.SetMethod<void (ChromePluginPlaceholder::*)()>( | 403 builder.SetMethod<void (ChromePluginPlaceholder::*)()>( |
| 457 "didFinishIconRepositionForTesting", | 404 "didFinishIconRepositionForTesting", |
| 458 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback); | 405 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback); |
| 459 } | 406 } |
| 460 | 407 |
| 461 return builder; | 408 return builder; |
| 462 } | 409 } |
| OLD | NEW |