OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin_placeholder.h" | 5 #include "chrome/renderer/plugins/plugin_placeholder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/jstemplate_builder.h" | 14 #include "chrome/common/jstemplate_builder.h" |
15 #include "chrome/common/prerender_messages.h" | 15 #include "chrome/common/prerender_messages.h" |
16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
17 #include "chrome/renderer/chrome_content_renderer_client.h" | 17 #include "chrome/renderer/chrome_content_renderer_client.h" |
18 #include "chrome/renderer/custom_menu_commands.h" | 18 #include "chrome/renderer/custom_menu_commands.h" |
19 #include "chrome/renderer/plugins/plugin_uma.h" | 19 #include "chrome/renderer/plugins/plugin_uma.h" |
| 20 #include "content/public/common/context_menu_params.h" |
20 #include "content/public/renderer/render_thread.h" | 21 #include "content/public/renderer/render_thread.h" |
21 #include "content/public/renderer/render_view.h" | 22 #include "content/public/renderer/render_view.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "grit/renderer_resources.h" | 24 #include "grit/renderer_resources.h" |
24 #include "grit/webkit_strings.h" | 25 #include "grit/webkit_strings.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 GURL(kPluginPlaceholderDataURL))), | 222 GURL(kPluginPlaceholderDataURL))), |
222 title_(title), | 223 title_(title), |
223 status_(new ChromeViewHostMsg_GetPluginInfo_Status), | 224 status_(new ChromeViewHostMsg_GetPluginInfo_Status), |
224 is_blocked_for_prerendering_(false), | 225 is_blocked_for_prerendering_(false), |
225 allow_loading_(false), | 226 allow_loading_(false), |
226 #if defined(ENABLE_PLUGIN_INSTALLATION) | 227 #if defined(ENABLE_PLUGIN_INSTALLATION) |
227 placeholder_routing_id_(MSG_ROUTING_NONE), | 228 placeholder_routing_id_(MSG_ROUTING_NONE), |
228 #endif | 229 #endif |
229 hidden_(false), | 230 hidden_(false), |
230 has_host_(false), | 231 has_host_(false), |
231 finished_loading_(false) { | 232 finished_loading_(false), |
| 233 context_menu_request_id_(0) { |
232 RenderThread::Get()->AddObserver(this); | 234 RenderThread::Get()->AddObserver(this); |
233 } | 235 } |
234 | 236 |
235 PluginPlaceholder::~PluginPlaceholder() { | 237 PluginPlaceholder::~PluginPlaceholder() { |
236 RenderThread::Get()->RemoveObserver(this); | 238 RenderThread::Get()->RemoveObserver(this); |
237 #if defined(ENABLE_PLUGIN_INSTALLATION) | 239 #if defined(ENABLE_PLUGIN_INSTALLATION) |
238 if (placeholder_routing_id_ == MSG_ROUTING_NONE) | 240 if (placeholder_routing_id_ == MSG_ROUTING_NONE) |
239 return; | 241 return; |
240 RenderThread::Get()->RemoveRoute(placeholder_routing_id_); | 242 RenderThread::Get()->RemoveRoute(placeholder_routing_id_); |
241 if (has_host_) { | 243 if (has_host_) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (output.status.value == status_->value) | 447 if (output.status.value == status_->value) |
446 return; | 448 return; |
447 chrome::ChromeContentRendererClient* client = | 449 chrome::ChromeContentRendererClient* client = |
448 static_cast<chrome::ChromeContentRendererClient*>( | 450 static_cast<chrome::ChromeContentRendererClient*>( |
449 content::GetContentClient()->renderer()); | 451 content::GetContentClient()->renderer()); |
450 WebPlugin* new_plugin = | 452 WebPlugin* new_plugin = |
451 client->CreatePlugin(render_view(), frame_, plugin_params_, output); | 453 client->CreatePlugin(render_view(), frame_, plugin_params_, output); |
452 ReplacePlugin(new_plugin); | 454 ReplacePlugin(new_plugin); |
453 } | 455 } |
454 | 456 |
455 void PluginPlaceholder::SetMessage(const string16& message) { | 457 void PluginPlaceholder::OnMenuAction(int request_id, unsigned action) { |
456 message_ = message; | |
457 if (finished_loading_) | |
458 UpdateMessage(); | |
459 } | |
460 | |
461 void PluginPlaceholder::UpdateMessage() { | |
462 std::string script = "window.setMessage(" + | |
463 base::GetDoubleQuotedJson(message_) + ")"; | |
464 plugin_->web_view()->mainFrame()->executeScript( | |
465 WebScriptSource(ASCIIToUTF16(script))); | |
466 } | |
467 | |
468 void PluginPlaceholder::ContextMenuAction(unsigned id) { | |
469 if (g_last_active_menu != this) | 458 if (g_last_active_menu != this) |
470 return; | 459 return; |
471 switch (id) { | 460 switch (action) { |
472 case chrome::MENU_COMMAND_PLUGIN_RUN: { | 461 case chrome::MENU_COMMAND_PLUGIN_RUN: { |
473 RenderThread::Get()->RecordUserMetrics("Plugin_Load_Menu"); | 462 RenderThread::Get()->RecordUserMetrics("Plugin_Load_Menu"); |
474 LoadPlugin(); | 463 LoadPlugin(); |
475 break; | 464 break; |
476 } | 465 } |
477 case chrome::MENU_COMMAND_PLUGIN_HIDE: { | 466 case chrome::MENU_COMMAND_PLUGIN_HIDE: { |
478 RenderThread::Get()->RecordUserMetrics("Plugin_Hide_Menu"); | 467 RenderThread::Get()->RecordUserMetrics("Plugin_Hide_Menu"); |
479 HidePlugin(); | 468 HidePlugin(); |
480 break; | 469 break; |
481 } | 470 } |
482 default: | 471 default: |
483 NOTREACHED(); | 472 NOTREACHED(); |
484 } | 473 } |
485 } | 474 } |
486 | 475 |
| 476 void PluginPlaceholder::OnMenuClosed(int request_id) { |
| 477 DCHECK(request_id == context_menu_request_id_); |
| 478 context_menu_request_id_ = 0; |
| 479 } |
| 480 |
| 481 void PluginPlaceholder::SetMessage(const string16& message) { |
| 482 message_ = message; |
| 483 if (finished_loading_) |
| 484 UpdateMessage(); |
| 485 } |
| 486 |
| 487 void PluginPlaceholder::UpdateMessage() { |
| 488 std::string script = "window.setMessage(" + |
| 489 base::GetDoubleQuotedJson(message_) + ")"; |
| 490 plugin_->web_view()->mainFrame()->executeScript( |
| 491 WebScriptSource(ASCIIToUTF16(script))); |
| 492 } |
| 493 |
487 void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { | 494 void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { |
488 WebContextMenuData menu_data; | 495 if (context_menu_request_id_) |
| 496 return; // Don't allow nested context menu requests. |
489 | 497 |
490 size_t num_items = 3u; | 498 content::ContextMenuParams params; |
491 if (!plugin_info_.path.value().empty()) | |
492 num_items++; | |
493 | 499 |
494 WebVector<WebMenuItemInfo> custom_items(num_items); | |
495 | |
496 size_t i = 0; | |
497 WebMenuItemInfo name_item; | 500 WebMenuItemInfo name_item; |
498 name_item.label = title_; | 501 name_item.label = title_; |
499 name_item.hasTextDirectionOverride = false; | 502 name_item.hasTextDirectionOverride = false; |
500 name_item.textDirection = WebKit::WebTextDirectionDefault; | 503 name_item.textDirection = WebKit::WebTextDirectionDefault; |
501 custom_items[i++] = name_item; | 504 params.custom_items.push_back(WebMenuItem(name_item)); |
502 | 505 |
503 WebMenuItemInfo separator_item; | 506 WebMenuItemInfo separator_item; |
504 separator_item.type = WebMenuItemInfo::Separator; | 507 separator_item.type = WebMenuItemInfo::Separator; |
505 custom_items[i++] = separator_item; | 508 params.custom_items.push_back(WebMenuItem(separator_item)); |
506 | 509 |
507 if (!plugin_info_.path.value().empty()) { | 510 if (!plugin_info_.path.value().empty()) { |
508 WebMenuItemInfo run_item; | 511 WebMenuItemInfo run_item; |
509 run_item.action = chrome::MENU_COMMAND_PLUGIN_RUN; | 512 run_item.action = chrome::MENU_COMMAND_PLUGIN_RUN; |
510 // Disable this menu item if the plugin is blocked by policy. | 513 // Disable this menu item if the plugin is blocked by policy. |
511 run_item.enabled = allow_loading_; | 514 run_item.enabled = allow_loading_; |
512 run_item.label = WebString::fromUTF8( | 515 run_item.label = WebString::fromUTF8( |
513 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str()); | 516 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str()); |
514 run_item.hasTextDirectionOverride = false; | 517 run_item.hasTextDirectionOverride = false; |
515 run_item.textDirection = WebKit::WebTextDirectionDefault; | 518 run_item.textDirection = WebKit::WebTextDirectionDefault; |
516 custom_items[i++] = run_item; | 519 params.custom_items.push_back(WebMenuItem(run_item)); |
517 } | 520 } |
518 | 521 |
519 WebMenuItemInfo hide_item; | 522 WebMenuItemInfo hide_item; |
520 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; | 523 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; |
521 hide_item.enabled = true; | 524 hide_item.enabled = true; |
522 hide_item.label = WebString::fromUTF8( | 525 hide_item.label = WebString::fromUTF8( |
523 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); | 526 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); |
524 hide_item.hasTextDirectionOverride = false; | 527 hide_item.hasTextDirectionOverride = false; |
525 hide_item.textDirection = WebKit::WebTextDirectionDefault; | 528 hide_item.textDirection = WebKit::WebTextDirectionDefault; |
526 custom_items[i++] = hide_item; | 529 params.custom_items.push_back(WebMenuItem(hide_item)); |
527 | 530 |
528 menu_data.customItems.swap(custom_items); | 531 params.x = event.windowX; |
529 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); | 532 params.y = event.windowY; |
530 render_view()->ShowContextMenu(NULL, menu_data); | 533 |
| 534 context_menu_request_id_ = render_view()->ShowContextMenu(this, params); |
531 g_last_active_menu = this; | 535 g_last_active_menu = this; |
532 } | 536 } |
533 | 537 |
534 void PluginPlaceholder::OnLoadBlockedPlugins(const std::string& identifier) { | 538 void PluginPlaceholder::OnLoadBlockedPlugins(const std::string& identifier) { |
535 if (!identifier.empty() && identifier != identifier_) | 539 if (!identifier.empty() && identifier != identifier_) |
536 return; | 540 return; |
537 | 541 |
538 RenderThread::Get()->RecordUserMetrics("Plugin_Load_UI"); | 542 RenderThread::Get()->RecordUserMetrics("Plugin_Load_UI"); |
539 LoadPlugin(); | 543 LoadPlugin(); |
540 } | 544 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 bool PluginPlaceholder::IsYouTubeURL(const GURL& url, | 634 bool PluginPlaceholder::IsYouTubeURL(const GURL& url, |
631 const std::string& mime_type) { | 635 const std::string& mime_type) { |
632 std::string host = url.host(); | 636 std::string host = url.host(); |
633 bool is_youtube = EndsWith(host, "youtube.com", true) || | 637 bool is_youtube = EndsWith(host, "youtube.com", true) || |
634 EndsWith(host, "youtube-nocookie.com", true); | 638 EndsWith(host, "youtube-nocookie.com", true); |
635 | 639 |
636 return is_youtube && IsValidYouTubeVideo(url.path()) && | 640 return is_youtube && IsValidYouTubeVideo(url.path()) && |
637 LowerCaseEqualsASCII(mime_type, kFlashPluginSwfMimeType); | 641 LowerCaseEqualsASCII(mime_type, kFlashPluginSwfMimeType); |
638 } | 642 } |
639 #endif | 643 #endif |
OLD | NEW |