Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/renderer/plugins/missing_plugin.cc

Issue 8461011: Clean up plug-in placeholders: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/plugins/missing_plugin.h ('k') | chrome/renderer/plugins/plugin_placeholder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 using webkit::WebViewPlugin;
35
36 namespace {
37 const MissingPlugin* g_last_active_menu = NULL;
38 }
39
40 // static
41 WebViewPlugin* MissingPlugin::Create(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 // |missing_plugin| will destroy itself when its WebViewPlugin is going away.
56 MissingPlugin* missing_plugin = new MissingPlugin(render_view, frame, params,
57 html_data);
58 return missing_plugin->plugin();
59 }
60
61 MissingPlugin::MissingPlugin(content::RenderView* render_view,
62 WebFrame* frame,
63 const WebPluginParams& params,
64 const std::string& html_data)
65 : PluginPlaceholder(render_view, frame, params, html_data),
66 mime_type_(params.mimeType) {
67 }
68
69 MissingPlugin::~MissingPlugin() {
70 }
71
72 void MissingPlugin::BindWebFrame(WebFrame* frame) {
73 PluginPlaceholder::BindWebFrame(frame);
74 BindMethod("hide", &MissingPlugin::HideCallback);
75 }
76
77 void MissingPlugin::HideCallback(const CppArgumentList& args,
78 CppVariant* result) {
79 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Click");
80 HidePluginInternal();
81 }
82
83 void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) {
84 WebContextMenuData menu_data;
85
86 WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(3));
87
88 size_t i = 0;
89 WebMenuItemInfo mime_type_item;
90 mime_type_item.label = mime_type_;
91 mime_type_item.hasTextDirectionOverride = false;
92 mime_type_item.textDirection = WebKit::WebTextDirectionDefault;
93 custom_items[i++] = mime_type_item;
94
95 WebMenuItemInfo separator_item;
96 separator_item.type = WebMenuItemInfo::Separator;
97 custom_items[i++] = separator_item;
98
99 WebMenuItemInfo hide_item;
100 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE;
101 hide_item.enabled = true;
102 hide_item.label = WebString::fromUTF8(
103 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
104 hide_item.hasTextDirectionOverride = false;
105 hide_item.textDirection = WebKit::WebTextDirectionDefault;
106 custom_items[i++] = hide_item;
107
108 menu_data.customItems.swap(custom_items);
109 menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
110 render_view()->ShowContextMenu(NULL, menu_data);
111 g_last_active_menu = this;
112 }
113
114 void MissingPlugin::ContextMenuAction(unsigned id) {
115 if (g_last_active_menu != this)
116 return;
117 if (id == chrome::MENU_COMMAND_PLUGIN_HIDE) {
118 RenderThread::Get()->RecordUserMetrics("MissingPlugin_Hide_Menu");
119 HidePluginInternal();
120 } else {
121 NOTREACHED();
122 }
123 }
124
OLDNEW
« no previous file with comments | « chrome/renderer/plugins/missing_plugin.h ('k') | chrome/renderer/plugins/plugin_placeholder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698