Chromium Code Reviews| 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/strings/string_number_conversions.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "chrome/common/prerender_messages.h" | 10 #include "chrome/common/prerender_messages.h" |
| 10 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "chrome/grit/renderer_resources.h" | 13 #include "chrome/grit/renderer_resources.h" |
| 13 #include "chrome/renderer/chrome_content_renderer_client.h" | 14 #include "chrome/renderer/chrome_content_renderer_client.h" |
| 14 #include "chrome/renderer/custom_menu_commands.h" | 15 #include "chrome/renderer/custom_menu_commands.h" |
| 15 #include "chrome/renderer/plugins/plugin_uma.h" | 16 #include "chrome/renderer/plugins/plugin_uma.h" |
| 16 #include "content/app/strings/grit/content_strings.h" | 17 #include "content/app/strings/grit/content_strings.h" |
| 17 #include "content/public/common/context_menu_params.h" | 18 #include "content/public/common/context_menu_params.h" |
| 18 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
| 19 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
| 20 #include "gin/handle.h" | 21 #include "gin/handle.h" |
| 21 #include "gin/object_template_builder.h" | 22 #include "gin/object_template_builder.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebInputEvent.h" | 24 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 24 #include "third_party/WebKit/public/web/WebKit.h" | 25 #include "third_party/WebKit/public/web/WebKit.h" |
| 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 26 #include "third_party/WebKit/public/web/WebScriptSource.h" | 27 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/base/webui/jstemplate_builder.h" | 30 #include "ui/base/webui/jstemplate_builder.h" |
| 31 #include "ui/gfx/geometry/size.h" | |
| 30 #include "url/url_util.h" | 32 #include "url/url_util.h" |
| 31 | 33 |
| 32 using base::UserMetricsAction; | 34 using base::UserMetricsAction; |
| 33 using blink::WebDocument; | 35 using blink::WebDocument; |
| 34 using blink::WebElement; | 36 using blink::WebElement; |
| 35 using blink::WebFrame; | 37 using blink::WebFrame; |
| 36 using blink::WebLocalFrame; | 38 using blink::WebLocalFrame; |
| 37 using blink::WebMouseEvent; | 39 using blink::WebMouseEvent; |
| 38 using blink::WebNode; | 40 using blink::WebNode; |
| 39 using blink::WebPlugin; | 41 using blink::WebPlugin; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 // static | 138 // static |
| 137 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( | 139 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( |
| 138 content::RenderFrame* render_frame, | 140 content::RenderFrame* render_frame, |
| 139 WebLocalFrame* frame, | 141 WebLocalFrame* frame, |
| 140 const WebPluginParams& params, | 142 const WebPluginParams& params, |
| 141 const content::WebPluginInfo& info, | 143 const content::WebPluginInfo& info, |
| 142 const std::string& identifier, | 144 const std::string& identifier, |
| 143 const base::string16& name, | 145 const base::string16& name, |
| 144 int template_id, | 146 int template_id, |
| 145 const base::string16& message, | 147 const base::string16& message, |
| 146 const std::string& poster_attribute, | 148 const PlaceholderPosterInfo& poster_info) { |
| 147 const GURL& base_url) { | |
| 148 base::DictionaryValue values; | 149 base::DictionaryValue values; |
| 149 values.SetString("message", message); | 150 values.SetString("message", message); |
| 150 values.SetString("name", name); | 151 values.SetString("name", name); |
| 151 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); | 152 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); |
| 152 | 153 |
| 153 if (!poster_attribute.empty()) { | 154 if (!poster_info.poster_attribute.empty()) { |
| 154 values.SetString("poster", poster_attribute); | 155 values.SetString("poster", poster_info.poster_attribute); |
| 155 values.SetString("baseurl", base_url.spec()); | 156 values.SetString("baseurl", poster_info.base_url.spec()); |
| 157 | |
| 158 if (!poster_info.custom_poster_size.IsEmpty()) { | |
| 159 values.SetString( | |
| 160 "visibleWidth", | |
| 161 base::Int64ToString(poster_info.custom_poster_size.width()) + "px"); | |
|
Lei Zhang
2015/04/01 19:18:35
Why not just base::IntToString()?
tommycli
2015/04/01 19:33:20
Done.
| |
| 162 values.SetString( | |
| 163 "visibleHeight", | |
| 164 base::Int64ToString(poster_info.custom_poster_size.height()) + "px"); | |
| 165 } | |
| 156 } | 166 } |
| 157 | 167 |
| 158 const base::StringPiece template_html( | 168 const base::StringPiece template_html( |
| 159 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 169 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); |
| 160 | 170 |
| 161 DCHECK(!template_html.empty()) << "unable to load template. ID: " | 171 DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 162 << template_id; | 172 << template_id; |
| 163 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); | 173 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); |
| 164 | 174 |
| 165 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. | 175 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. |
| 166 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( | 176 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( |
| 167 render_frame, frame, params, html_data, name); | 177 render_frame, frame, params, html_data, name); |
| 168 | 178 |
| 169 #if defined(ENABLE_PLUGINS) | 179 #if defined(ENABLE_PLUGINS) |
| 170 if (!poster_attribute.empty()) | 180 if (!poster_info.poster_attribute.empty()) |
| 171 blocked_plugin->BlockForPowerSaverPoster(); | 181 blocked_plugin->BlockForPowerSaverPoster(); |
| 172 #endif | 182 #endif |
| 173 blocked_plugin->SetPluginInfo(info); | 183 blocked_plugin->SetPluginInfo(info); |
| 174 blocked_plugin->SetIdentifier(identifier); | 184 blocked_plugin->SetIdentifier(identifier); |
| 175 return blocked_plugin; | 185 return blocked_plugin; |
| 176 } | 186 } |
| 177 | 187 |
| 178 void ChromePluginPlaceholder::SetStatus( | 188 void ChromePluginPlaceholder::SetStatus( |
| 179 const ChromeViewHostMsg_GetPluginInfo_Status& status) { | 189 const ChromeViewHostMsg_GetPluginInfo_Status& status) { |
| 180 status_->value = status.value; | 190 status_->value = status.value; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 v8::Handle<v8::Object> global = context->Global(); | 377 v8::Handle<v8::Object> global = context->Global(); |
| 368 global->Set(gin::StringToV8(isolate, "plugin"), | 378 global->Set(gin::StringToV8(isolate, "plugin"), |
| 369 gin::CreateHandle(isolate, this).ToV8()); | 379 gin::CreateHandle(isolate, this).ToV8()); |
| 370 } | 380 } |
| 371 | 381 |
| 372 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( | 382 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( |
| 373 v8::Isolate* isolate) { | 383 v8::Isolate* isolate) { |
| 374 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( | 384 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( |
| 375 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); | 385 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); |
| 376 } | 386 } |
| OLD | NEW |