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/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/common/prerender_messages.h" | 9 #include "chrome/common/prerender_messages.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "chrome/renderer/chrome_content_renderer_client.h" | 11 #include "chrome/renderer/chrome_content_renderer_client.h" |
12 #include "chrome/renderer/custom_menu_commands.h" | 12 #include "chrome/renderer/custom_menu_commands.h" |
13 #include "chrome/renderer/plugins/plugin_uma.h" | 13 #include "chrome/renderer/plugins/plugin_uma.h" |
14 #include "content/public/common/context_menu_params.h" | 14 #include "content/public/common/context_menu_params.h" |
15 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
| 17 #include "gin/handle.h" |
| 18 #include "gin/object_template_builder.h" |
17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
18 #include "grit/renderer_resources.h" | 20 #include "grit/renderer_resources.h" |
19 #include "grit/webkit_strings.h" | 21 #include "grit/webkit_strings.h" |
20 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebInputEvent.h" | 24 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 25 #include "third_party/WebKit/public/web/WebKit.h" |
23 #include "third_party/WebKit/public/web/WebScriptSource.h" | 26 #include "third_party/WebKit/public/web/WebScriptSource.h" |
24 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/base/webui/jstemplate_builder.h" | 29 #include "ui/base/webui/jstemplate_builder.h" |
27 | 30 |
28 using content::RenderThread; | 31 using content::RenderThread; |
29 using content::RenderView; | 32 using content::RenderView; |
30 using content::UserMetricsAction; | 33 using content::UserMetricsAction; |
31 using blink::WebDocument; | 34 using blink::WebDocument; |
32 using blink::WebElement; | 35 using blink::WebElement; |
33 using blink::WebFrame; | 36 using blink::WebFrame; |
34 using blink::WebMouseEvent; | 37 using blink::WebMouseEvent; |
35 using blink::WebNode; | 38 using blink::WebNode; |
36 using blink::WebPlugin; | 39 using blink::WebPlugin; |
37 using blink::WebPluginContainer; | 40 using blink::WebPluginContainer; |
38 using blink::WebPluginParams; | 41 using blink::WebPluginParams; |
39 using webkit_glue::CppArgumentList; | |
40 using webkit_glue::CppVariant; | |
41 | 42 |
42 namespace { | 43 namespace { |
43 const plugins::PluginPlaceholder* g_last_active_menu = NULL; | 44 const plugins::PluginPlaceholder* g_last_active_menu = NULL; |
44 } // namespace | 45 } // namespace |
45 | 46 |
46 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] = | 47 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] = |
47 "chrome://pluginplaceholderdata/"; | 48 "chrome://pluginplaceholderdata/"; |
48 | 49 |
49 ChromePluginPlaceholder::ChromePluginPlaceholder( | 50 ChromePluginPlaceholder::ChromePluginPlaceholder( |
50 content::RenderFrame* render_frame, | 51 content::RenderFrame* render_frame, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 IPC_END_MESSAGE_MAP() | 212 IPC_END_MESSAGE_MAP() |
212 | 213 |
213 return false; | 214 return false; |
214 } | 215 } |
215 | 216 |
216 void ChromePluginPlaceholder::OnLoadBlockedPlugins( | 217 void ChromePluginPlaceholder::OnLoadBlockedPlugins( |
217 const std::string& identifier) { | 218 const std::string& identifier) { |
218 plugins::PluginPlaceholder::OnLoadBlockedPlugins(identifier); | 219 plugins::PluginPlaceholder::OnLoadBlockedPlugins(identifier); |
219 } | 220 } |
220 | 221 |
221 void ChromePluginPlaceholder::OpenAboutPluginsCallback( | 222 void ChromePluginPlaceholder::OpenAboutPluginsCallback() { |
222 const CppArgumentList& args, | |
223 CppVariant* result) { | |
224 RenderThread::Get()->Send( | 223 RenderThread::Get()->Send( |
225 new ChromeViewHostMsg_OpenAboutPlugins(routing_id())); | 224 new ChromeViewHostMsg_OpenAboutPlugins(routing_id())); |
226 } | 225 } |
227 | 226 |
228 void ChromePluginPlaceholder::OnSetIsPrerendering(bool is_prerendering) { | 227 void ChromePluginPlaceholder::OnSetIsPrerendering(bool is_prerendering) { |
229 plugins::PluginPlaceholder::OnSetIsPrerendering(is_prerendering); | 228 plugins::PluginPlaceholder::OnSetIsPrerendering(is_prerendering); |
230 } | 229 } |
231 | 230 |
232 #if defined(ENABLE_PLUGIN_INSTALLATION) | 231 #if defined(ENABLE_PLUGIN_INSTALLATION) |
233 void ChromePluginPlaceholder::OnDidNotFindMissingPlugin() { | 232 void ChromePluginPlaceholder::OnDidNotFindMissingPlugin() { |
(...skipping 26 matching lines...) Expand all Loading... |
260 base::UTF8ToUTF16(error))); | 259 base::UTF8ToUTF16(error))); |
261 } | 260 } |
262 | 261 |
263 void ChromePluginPlaceholder::OnCancelledDownloadingPlugin() { | 262 void ChromePluginPlaceholder::OnCancelledDownloadingPlugin() { |
264 SetMessage( | 263 SetMessage( |
265 l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED, plugin_name_)); | 264 l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED, plugin_name_)); |
266 } | 265 } |
267 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | 266 #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
268 | 267 |
269 void ChromePluginPlaceholder::PluginListChanged() { | 268 void ChromePluginPlaceholder::PluginListChanged() { |
270 if (!GetFrame()) | 269 if (!GetFrame() || !plugin()) |
271 return; | 270 return; |
272 WebDocument document = GetFrame()->top()->document(); | 271 WebDocument document = GetFrame()->top()->document(); |
273 if (document.isNull()) | 272 if (document.isNull()) |
274 return; | 273 return; |
275 | 274 |
276 ChromeViewHostMsg_GetPluginInfo_Output output; | 275 ChromeViewHostMsg_GetPluginInfo_Output output; |
277 std::string mime_type(GetPluginParams().mimeType.utf8()); | 276 std::string mime_type(GetPluginParams().mimeType.utf8()); |
278 render_frame()->Send( | 277 render_frame()->Send( |
279 new ChromeViewHostMsg_GetPluginInfo(routing_id(), | 278 new ChromeViewHostMsg_GetPluginInfo(routing_id(), |
280 GURL(GetPluginParams().url), | 279 GURL(GetPluginParams().url), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 params.custom_items.push_back(hide_item); | 346 params.custom_items.push_back(hide_item); |
348 | 347 |
349 params.x = event.windowX; | 348 params.x = event.windowX; |
350 params.y = event.windowY; | 349 params.y = event.windowY; |
351 | 350 |
352 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params); | 351 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params); |
353 g_last_active_menu = this; | 352 g_last_active_menu = this; |
354 } | 353 } |
355 | 354 |
356 void ChromePluginPlaceholder::BindWebFrame(blink::WebFrame* frame) { | 355 void ChromePluginPlaceholder::BindWebFrame(blink::WebFrame* frame) { |
357 plugins::PluginPlaceholder::BindWebFrame(frame); | 356 v8::Isolate* isolate = blink::mainThreadIsolate(); |
358 BindCallback("openAboutPlugins", | 357 v8::HandleScope handle_scope(isolate); |
359 base::Bind(&ChromePluginPlaceholder::OpenAboutPluginsCallback, | 358 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
360 base::Unretained(this))); | 359 DCHECK(!context.IsEmpty()); |
| 360 |
| 361 v8::Context::Scope context_scope(context); |
| 362 v8::Handle<v8::Object> global = context->Global(); |
| 363 global->Set(gin::StringToV8(isolate, "plugin"), |
| 364 gin::CreateHandle(isolate, this).ToV8()); |
361 } | 365 } |
| 366 |
| 367 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( |
| 368 v8::Isolate* isolate) { |
| 369 return PluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( |
| 370 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); |
| 371 } |
OLD | NEW |