OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/plugins/missing_plugin.h" |
| 6 |
| 7 #include "base/string_piece.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/common/jstemplate_builder.h" |
| 11 #include "chrome/renderer/custom_menu_commands.h" |
| 12 #include "content/public/renderer/render_thread.h" |
| 13 #include "content/public/renderer/render_view.h" |
| 14 #include "grit/generated_resources.h" |
| 15 #include "grit/renderer_resources.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "webkit/plugins/npapi/plugin_group.h" |
| 24 |
| 25 using WebKit::WebContextMenuData; |
| 26 using WebKit::WebFrame; |
| 27 using WebKit::WebMenuItemInfo; |
| 28 using WebKit::WebPlugin; |
| 29 using WebKit::WebPluginParams; |
| 30 using WebKit::WebPoint; |
| 31 using WebKit::WebString; |
| 32 using WebKit::WebVector; |
| 33 using content::RenderThread; |
| 34 |
| 35 namespace { |
| 36 const MissingPlugin* g_last_active_menu = NULL; |
| 37 } |
| 38 |
| 39 // static |
| 40 webkit::npapi::WebViewPlugin* MissingPlugin::Create( |
| 41 content::RenderView* render_view, |
| 42 WebFrame* frame, |
| 43 const WebPluginParams& params) { |
| 44 const base::StringPiece template_html( |
| 45 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 46 IDR_BLOCKED_PLUGIN_HTML)); |
| 47 |
| 48 DictionaryValue values; |
| 49 values.SetString("message", l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_FOUND)); |
| 50 |
| 51 // "t" is the id of the templates root node. |
| 52 std::string html_data = |
| 53 jstemplate_builder::GetI18nTemplateHtml(template_html, &values); |
| 54 |
| 55 MissingPlugin* missing_plugin = new MissingPlugin(render_view, frame, params, |
| 56 html_data); |
| 57 return missing_plugin->plugin(); |
| 58 } |
| 59 |
| 60 MissingPlugin::MissingPlugin(content::RenderView* render_view, |
| 61 WebFrame* frame, |
| 62 const WebPluginParams& params, |
| 63 const std::string& html_data) |
| 64 : PluginPlaceholder(render_view, frame, params, html_data), |
| 65 mime_type_(params.mimeType) { |
| 66 } |
| 67 |
| 68 MissingPlugin::~MissingPlugin() { |
| 69 } |
| 70 |
| 71 void MissingPlugin::BindWebFrame(WebFrame* frame) { |
| 72 PluginPlaceholder::BindWebFrame(frame); |
| 73 BindMethod("hide", &MissingPlugin::HideCallback); |
| 74 } |
| 75 |
| 76 void MissingPlugin::HideCallback(const CppArgumentList& args, |
| 77 CppVariant* result) { |
| 78 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Click"); |
| 79 HidePlugin(); |
| 80 } |
| 81 |
| 82 void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { |
| 83 WebContextMenuData menu_data; |
| 84 |
| 85 WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(3)); |
| 86 |
| 87 size_t i = 0; |
| 88 WebMenuItemInfo mime_type_item; |
| 89 mime_type_item.label = mime_type_; |
| 90 mime_type_item.hasTextDirectionOverride = false; |
| 91 mime_type_item.textDirection = WebKit::WebTextDirectionDefault; |
| 92 custom_items[i++] = mime_type_item; |
| 93 |
| 94 WebMenuItemInfo separator_item; |
| 95 separator_item.type = WebMenuItemInfo::Separator; |
| 96 custom_items[i++] = separator_item; |
| 97 |
| 98 WebMenuItemInfo hide_item; |
| 99 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; |
| 100 hide_item.enabled = true; |
| 101 hide_item.label = WebString::fromUTF8( |
| 102 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); |
| 103 hide_item.hasTextDirectionOverride = false; |
| 104 hide_item.textDirection = WebKit::WebTextDirectionDefault; |
| 105 custom_items[i++] = hide_item; |
| 106 |
| 107 menu_data.customItems.swap(custom_items); |
| 108 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); |
| 109 render_view()->ShowContextMenu(NULL, menu_data); |
| 110 g_last_active_menu = this; |
| 111 } |
| 112 |
| 113 void MissingPlugin::ContextMenuAction(unsigned id) { |
| 114 if (g_last_active_menu != this) |
| 115 return; |
| 116 if (id == chrome::MENU_COMMAND_PLUGIN_HIDE) { |
| 117 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Menu"); |
| 118 HidePlugin(); |
| 119 } else { |
| 120 NOTREACHED(); |
| 121 } |
| 122 } |
| 123 |
OLD | NEW |