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