| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "url/url_util.h" | 34 #include "url/url_util.h" |
| 35 | 35 |
| 36 using base::UserMetricsAction; | 36 using base::UserMetricsAction; |
| 37 using content::RenderThread; | 37 using content::RenderThread; |
| 38 using content::RenderView; | 38 using content::RenderView; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 const ChromePluginPlaceholder* g_last_active_menu = NULL; | 41 const ChromePluginPlaceholder* g_last_active_menu = NULL; |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 PowerSaverInfo::PowerSaverInfo() |
| 45 : power_saver_enabled(false), blocked_for_background_tab(false) {} |
| 46 |
| 44 gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = { | 47 gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = { |
| 45 gin::kEmbedderNativeGin}; | 48 gin::kEmbedderNativeGin}; |
| 46 | 49 |
| 47 ChromePluginPlaceholder::ChromePluginPlaceholder( | 50 ChromePluginPlaceholder::ChromePluginPlaceholder( |
| 48 content::RenderFrame* render_frame, | 51 content::RenderFrame* render_frame, |
| 49 blink::WebLocalFrame* frame, | 52 blink::WebLocalFrame* frame, |
| 50 const blink::WebPluginParams& params, | 53 const blink::WebPluginParams& params, |
| 51 const std::string& html_data, | 54 const std::string& html_data, |
| 52 const base::string16& title) | 55 const base::string16& title) |
| 53 : plugins::LoadablePluginPlaceholder(render_frame, | 56 : plugins::LoadablePluginPlaceholder(render_frame, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // static | 106 // static |
| 104 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( | 107 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( |
| 105 content::RenderFrame* render_frame, | 108 content::RenderFrame* render_frame, |
| 106 blink::WebLocalFrame* frame, | 109 blink::WebLocalFrame* frame, |
| 107 const blink::WebPluginParams& params, | 110 const blink::WebPluginParams& params, |
| 108 const content::WebPluginInfo& info, | 111 const content::WebPluginInfo& info, |
| 109 const std::string& identifier, | 112 const std::string& identifier, |
| 110 const base::string16& name, | 113 const base::string16& name, |
| 111 int template_id, | 114 int template_id, |
| 112 const base::string16& message, | 115 const base::string16& message, |
| 113 const PlaceholderPosterInfo& poster_info) { | 116 const PowerSaverInfo& power_saver_info) { |
| 114 base::DictionaryValue values; | 117 base::DictionaryValue values; |
| 115 values.SetString("message", message); | 118 values.SetString("message", message); |
| 116 values.SetString("name", name); | 119 values.SetString("name", name); |
| 117 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); | 120 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); |
| 118 values.SetString("pluginType", | 121 values.SetString("pluginType", |
| 119 frame->view()->mainFrame()->isWebLocalFrame() && | 122 frame->view()->mainFrame()->isWebLocalFrame() && |
| 120 frame->view()->mainFrame()->document().isPluginDocument() | 123 frame->view()->mainFrame()->document().isPluginDocument() |
| 121 ? "document" | 124 ? "document" |
| 122 : "embedded"); | 125 : "embedded"); |
| 123 | 126 |
| 124 if (!poster_info.poster_attribute.empty()) { | 127 if (!power_saver_info.poster_attribute.empty()) { |
| 125 values.SetString("poster", poster_info.poster_attribute); | 128 values.SetString("poster", power_saver_info.poster_attribute); |
| 126 values.SetString("baseurl", poster_info.base_url.spec()); | 129 values.SetString("baseurl", power_saver_info.base_url.spec()); |
| 127 | 130 |
| 128 if (!poster_info.custom_poster_size.IsEmpty()) { | 131 if (!power_saver_info.custom_poster_size.IsEmpty()) { |
| 129 float zoom_factor = | 132 float zoom_factor = |
| 130 blink::WebView::zoomLevelToZoomFactor(frame->view()->zoomLevel()); | 133 blink::WebView::zoomLevelToZoomFactor(frame->view()->zoomLevel()); |
| 131 int width = roundf(poster_info.custom_poster_size.width() / zoom_factor); | 134 int width = |
| 135 roundf(power_saver_info.custom_poster_size.width() / zoom_factor); |
| 132 int height = | 136 int height = |
| 133 roundf(poster_info.custom_poster_size.height() / zoom_factor); | 137 roundf(power_saver_info.custom_poster_size.height() / zoom_factor); |
| 134 values.SetString("visibleWidth", base::IntToString(width) + "px"); | 138 values.SetString("visibleWidth", base::IntToString(width) + "px"); |
| 135 values.SetString("visibleHeight", base::IntToString(height) + "px"); | 139 values.SetString("visibleHeight", base::IntToString(height) + "px"); |
| 136 } | 140 } |
| 137 } | 141 } |
| 138 | 142 |
| 139 const base::StringPiece template_html( | 143 const base::StringPiece template_html( |
| 140 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 144 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); |
| 141 | 145 |
| 142 DCHECK(!template_html.empty()) << "unable to load template. ID: " | 146 DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 143 << template_id; | 147 << template_id; |
| 144 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); | 148 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); |
| 145 | 149 |
| 146 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. | 150 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. |
| 147 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( | 151 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( |
| 148 render_frame, frame, params, html_data, name); | 152 render_frame, frame, params, html_data, name); |
| 149 | 153 |
| 150 if (!poster_info.poster_attribute.empty()) | 154 if (!power_saver_info.poster_attribute.empty()) |
| 151 blocked_plugin->BlockForPowerSaverPoster(); | 155 blocked_plugin->BlockForPowerSaverPoster(); |
| 152 blocked_plugin->SetPluginInfo(info); | 156 blocked_plugin->SetPluginInfo(info); |
| 153 blocked_plugin->SetIdentifier(identifier); | 157 blocked_plugin->SetIdentifier(identifier); |
| 158 |
| 159 blocked_plugin->set_power_saver_enabled(power_saver_info.power_saver_enabled); |
| 160 blocked_plugin->set_blocked_for_background_tab( |
| 161 power_saver_info.blocked_for_background_tab); |
| 162 |
| 154 return blocked_plugin; | 163 return blocked_plugin; |
| 155 } | 164 } |
| 156 | 165 |
| 157 void ChromePluginPlaceholder::SetStatus( | 166 void ChromePluginPlaceholder::SetStatus( |
| 158 ChromeViewHostMsg_GetPluginInfo_Status status) { | 167 ChromeViewHostMsg_GetPluginInfo_Status status) { |
| 159 status_ = status; | 168 status_ = status; |
| 160 } | 169 } |
| 161 | 170 |
| 162 #if defined(ENABLE_PLUGIN_INSTALLATION) | 171 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 163 int32 ChromePluginPlaceholder::CreateRoutingId() { | 172 int32 ChromePluginPlaceholder::CreateRoutingId() { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 383 |
| 375 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 384 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 376 switches::kEnablePluginPlaceholderTesting)) { | 385 switches::kEnablePluginPlaceholderTesting)) { |
| 377 builder.SetMethod<void (ChromePluginPlaceholder::*)()>( | 386 builder.SetMethod<void (ChromePluginPlaceholder::*)()>( |
| 378 "didFinishIconRepositionForTesting", | 387 "didFinishIconRepositionForTesting", |
| 379 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback); | 388 &ChromePluginPlaceholder::DidFinishIconRepositionForTestingCallback); |
| 380 } | 389 } |
| 381 | 390 |
| 382 return builder; | 391 return builder; |
| 383 } | 392 } |
| OLD | NEW |