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

Side by Side Diff: chrome/renderer/blocked_plugin.cc

Issue 6312004: Make BlockedPlugin implement RenderViewObserver so that RenderView doesn't ha... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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/blocked_plugin.h ('k') | chrome/renderer/custom_menu_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/blocked_plugin.h" 5 #include "chrome/renderer/blocked_plugin.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/jstemplate_builder.h" 11 #include "chrome/common/jstemplate_builder.h"
12 #include "chrome/common/render_messages.h"
12 #include "chrome/renderer/render_view.h" 13 #include "chrome/renderer/render_view.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebData.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" 18 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h"
18 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 19 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
19 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" 20 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebTextCaseSensitivity.h" 22 #include "third_party/WebKit/WebKit/chromium/public/WebTextCaseSensitivity.h"
(...skipping 20 matching lines...) Expand all
42 static const unsigned kMenuActionLoad = 1; 43 static const unsigned kMenuActionLoad = 1;
43 static const unsigned kMenuActionRemove = 2; 44 static const unsigned kMenuActionRemove = 2;
44 45
45 BlockedPlugin::BlockedPlugin(RenderView* render_view, 46 BlockedPlugin::BlockedPlugin(RenderView* render_view,
46 WebFrame* frame, 47 WebFrame* frame,
47 const webkit::npapi::PluginGroup& info, 48 const webkit::npapi::PluginGroup& info,
48 const WebPluginParams& params, 49 const WebPluginParams& params,
49 const WebPreferences& preferences, 50 const WebPreferences& preferences,
50 int template_id, 51 int template_id,
51 const string16& message) 52 const string16& message)
52 : render_view_(render_view), 53 : RenderViewObserver(render_view),
53 frame_(frame), 54 frame_(frame),
54 plugin_params_(params) { 55 plugin_params_(params),
56 custom_menu_showing_(false) {
55 const base::StringPiece template_html( 57 const base::StringPiece template_html(
56 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 58 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
57 59
58 DCHECK(!template_html.empty()) << "unable to load template. ID: " 60 DCHECK(!template_html.empty()) << "unable to load template. ID: "
59 << template_id; 61 << template_id;
60 62
61 DictionaryValue values; 63 DictionaryValue values;
62 values.SetString("message", message); 64 values.SetString("message", message);
63 name_ = info.GetGroupName(); 65 name_ = info.GetGroupName();
64 values.SetString("name", name_); 66 values.SetString("name", name_);
65 67
66 // "t" is the id of the templates root node. 68 // "t" is the id of the templates root node.
67 std::string html_data = jstemplate_builder::GetTemplatesHtml( 69 std::string html_data = jstemplate_builder::GetTemplatesHtml(
68 template_html, &values, "t"); 70 template_html, &values, "t");
69 71
70 plugin_ = webkit::npapi::WebViewPlugin::Create(this, 72 plugin_ = webkit::npapi::WebViewPlugin::Create(this,
71 preferences, 73 preferences,
72 html_data, 74 html_data,
73 GURL(kBlockedPluginDataURL)); 75 GURL(kBlockedPluginDataURL));
74
75 render_view_->RegisterBlockedPlugin(this);
76 } 76 }
77 77
78 BlockedPlugin::~BlockedPlugin() { 78 BlockedPlugin::~BlockedPlugin() {
79 render_view_->CustomMenuListenerDestroyed(this);
80 render_view_->UnregisterBlockedPlugin(this);
81 } 79 }
82 80
83 void BlockedPlugin::BindWebFrame(WebFrame* frame) { 81 void BlockedPlugin::BindWebFrame(WebFrame* frame) {
84 BindToJavascript(frame, "plugin"); 82 BindToJavascript(frame, "plugin");
85 BindMethod("load", &BlockedPlugin::Load); 83 BindMethod("load", &BlockedPlugin::Load);
86 BindMethod("hide", &BlockedPlugin::Hide); 84 BindMethod("hide", &BlockedPlugin::Hide);
87 } 85 }
88 86
89 void BlockedPlugin::WillDestroyPlugin() { 87 void BlockedPlugin::WillDestroyPlugin() {
90 delete this; 88 delete this;
(...skipping 20 matching lines...) Expand all
111 109
112 WebMenuItemInfo hide_item; 110 WebMenuItemInfo hide_item;
113 hide_item.action = kMenuActionRemove; 111 hide_item.action = kMenuActionRemove;
114 hide_item.enabled = true; 112 hide_item.enabled = true;
115 hide_item.label = WebString::fromUTF8( 113 hide_item.label = WebString::fromUTF8(
116 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); 114 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
117 custom_items[3] = hide_item; 115 custom_items[3] = hide_item;
118 116
119 menu_data.customItems.swap(custom_items); 117 menu_data.customItems.swap(custom_items);
120 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); 118 menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
121 render_view_->showContextMenu(NULL, menu_data); 119 render_view()->showContextMenu(NULL, menu_data);
Chris Evans 2011/01/17 13:50:30 I don't see where this ever gets set to false? Doe
jam 2011/01/17 18:45:19 This is the same behavior as before, where CustomM
jam 2011/01/17 18:47:46 oh, wait, nm, I think I understand what you meant
122 render_view_->CustomMenuListenerInstall(this); 120 custom_menu_showing_ = true;
123 } 121 }
124 122
125 void BlockedPlugin::MenuItemSelected(unsigned id) { 123 bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) {
124 if (custom_menu_showing_ &&
125 message.type() == ViewMsg_CustomContextMenuAction::ID) {
126 ViewMsg_CustomContextMenuAction::Dispatch(
127 &message, this, this, &BlockedPlugin::OnMenuItemSelected);
Chris Evans 2011/01/17 13:50:30 Perhaps we could guarantee unique IDs for custom m
128 return true;
129 }
130
131 if (message.type() == ViewMsg_LoadBlockedPlugins::ID)
132 LoadPlugin();
133
134 return false; // Want other BlockedPlugin objects to see LoadBlockedPlugins.
135 }
136
137 void BlockedPlugin::OnMenuItemSelected(unsigned id) {
126 if (id == kMenuActionLoad) { 138 if (id == kMenuActionLoad) {
127 LoadPlugin(); 139 LoadPlugin();
128 } else if (id == kMenuActionRemove) { 140 } else if (id == kMenuActionRemove) {
129 HidePlugin(); 141 HidePlugin();
130 } else { 142 } else {
131 NOTREACHED(); 143 NOTREACHED();
132 } 144 }
133 } 145 }
134 146
135 void BlockedPlugin::LoadPlugin() { 147 void BlockedPlugin::LoadPlugin() {
136 CHECK(plugin_); 148 CHECK(plugin_);
137 WebPluginContainer* container = plugin_->container(); 149 WebPluginContainer* container = plugin_->container();
138 WebPlugin* new_plugin = 150 WebPlugin* new_plugin =
139 render_view_->CreatePluginNoCheck(frame_, 151 render_view()->CreatePluginNoCheck(frame_, plugin_params_);
140 plugin_params_);
141 if (new_plugin && new_plugin->initialize(container)) { 152 if (new_plugin && new_plugin->initialize(container)) {
142 container->setPlugin(new_plugin); 153 container->setPlugin(new_plugin);
143 container->invalidate(); 154 container->invalidate();
144 container->reportGeometry(); 155 container->reportGeometry();
145 plugin_->ReplayReceivedData(new_plugin); 156 plugin_->ReplayReceivedData(new_plugin);
146 plugin_->destroy(); 157 plugin_->destroy();
147 } 158 }
148 } 159 }
149 160
150 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { 161 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (element.hasAttribute("style")) { 201 if (element.hasAttribute("style")) {
191 WebString style_str = element.getAttribute("style"); 202 WebString style_str = element.getAttribute("style");
192 if (width_regex.match(style_str) >= 0 && 203 if (width_regex.match(style_str) >= 0 &&
193 height_regex.match(style_str) >= 0) 204 height_regex.match(style_str) >= 0)
194 element.setAttribute("style", "display: none;"); 205 element.setAttribute("style", "display: none;");
195 } 206 }
196 } 207 }
197 } 208 }
198 } 209 }
199 210
OLDNEW
« no previous file with comments | « chrome/renderer/blocked_plugin.h ('k') | chrome/renderer/custom_menu_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698