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

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

Issue 6354025: Add hide icon on the click-to-play UI too. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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
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 "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/jstemplate_builder.h" 10 #include "chrome/common/jstemplate_builder.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 WebFrame* frame, 53 WebFrame* frame,
54 const webkit::npapi::PluginGroup& info, 54 const webkit::npapi::PluginGroup& info,
55 const WebPluginParams& params, 55 const WebPluginParams& params,
56 const WebPreferences& preferences, 56 const WebPreferences& preferences,
57 int template_id, 57 int template_id,
58 const string16& message, 58 const string16& message,
59 bool is_blocked_for_prerendering) 59 bool is_blocked_for_prerendering)
60 : RenderViewObserver(render_view), 60 : RenderViewObserver(render_view),
61 frame_(frame), 61 frame_(frame),
62 plugin_params_(params), 62 plugin_params_(params),
63 is_blocked_for_prerendering_(is_blocked_for_prerendering) { 63 is_blocked_for_prerendering_(is_blocked_for_prerendering),
64 hidden_(false) {
64 const base::StringPiece template_html( 65 const base::StringPiece template_html(
65 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 66 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
66 67
67 DCHECK(!template_html.empty()) << "unable to load template. ID: " 68 DCHECK(!template_html.empty()) << "unable to load template. ID: "
68 << template_id; 69 << template_id;
69 70
70 DictionaryValue values; 71 DictionaryValue values;
71 values.SetString("message", message); 72 values.SetString("message", message);
72 name_ = info.GetGroupName(); 73 name_ = info.GetGroupName();
73 values.SetString("name", name_); 74 values.SetString("name", name_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void BlockedPlugin::OnMenuItemSelected(unsigned id) { 150 void BlockedPlugin::OnMenuItemSelected(unsigned id) {
150 if (id == kMenuActionLoad) { 151 if (id == kMenuActionLoad) {
151 LoadPlugin(); 152 LoadPlugin();
152 } else if (id == kMenuActionRemove) { 153 } else if (id == kMenuActionRemove) {
153 HidePlugin(); 154 HidePlugin();
154 } 155 }
155 } 156 }
156 157
157 void BlockedPlugin::LoadPlugin() { 158 void BlockedPlugin::LoadPlugin() {
158 CHECK(plugin_); 159 CHECK(plugin_);
160 // This is not strictly necessary but is an important defense in case the
161 // event propagation changes between "close" vs. "click-to-play".
162 if (hidden_)
163 return;
159 WebPluginContainer* container = plugin_->container(); 164 WebPluginContainer* container = plugin_->container();
160 WebPlugin* new_plugin = 165 WebPlugin* new_plugin =
161 render_view()->CreatePluginNoCheck(frame_, plugin_params_); 166 render_view()->CreatePluginNoCheck(frame_, plugin_params_);
162 if (new_plugin && new_plugin->initialize(container)) { 167 if (new_plugin && new_plugin->initialize(container)) {
163 container->setPlugin(new_plugin); 168 container->setPlugin(new_plugin);
164 container->invalidate(); 169 container->invalidate();
165 container->reportGeometry(); 170 container->reportGeometry();
166 plugin_->ReplayReceivedData(new_plugin); 171 plugin_->ReplayReceivedData(new_plugin);
167 plugin_->destroy(); 172 plugin_->destroy();
168 } 173 }
169 } 174 }
170 175
171 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { 176 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) {
172 LoadPlugin(); 177 LoadPlugin();
173 } 178 }
174 179
175 void BlockedPlugin::Hide(const CppArgumentList& args, CppVariant* result) { 180 void BlockedPlugin::Hide(const CppArgumentList& args, CppVariant* result) {
176 HidePlugin(); 181 HidePlugin();
177 } 182 }
178 183
179 void BlockedPlugin::HidePlugin() { 184 void BlockedPlugin::HidePlugin() {
180 CHECK(plugin_); 185 CHECK(plugin_);
186 hidden_ = true;
181 WebPluginContainer* container = plugin_->container(); 187 WebPluginContainer* container = plugin_->container();
182 WebElement element = container->element(); 188 WebElement element = container->element();
183 element.setAttribute("style", "display: none;"); 189 element.setAttribute("style", "display: none;");
184 // If we have a width and height, search for a parent (often <div>) with the 190 // If we have a width and height, search for a parent (often <div>) with the
185 // same dimensions. If we find such a parent, hide that as well. 191 // same dimensions. If we find such a parent, hide that as well.
186 // This makes much more uncovered page content usable (including clickable) 192 // This makes much more uncovered page content usable (including clickable)
187 // as opposed to merely visible. 193 // as opposed to merely visible.
188 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for 194 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for
189 // now for these reasons: 195 // now for these reasons:
190 // 1) Makes the user experience better. 196 // 1) Makes the user experience better.
(...skipping 28 matching lines...) Expand all
219 if (element.hasAttribute("style")) { 225 if (element.hasAttribute("style")) {
220 WebString style_str = element.getAttribute("style"); 226 WebString style_str = element.getAttribute("style");
221 if (width_regex.match(style_str) >= 0 && 227 if (width_regex.match(style_str) >= 0 &&
222 height_regex.match(style_str) >= 0) 228 height_regex.match(style_str) >= 0)
223 element.setAttribute("style", "display: none;"); 229 element.setAttribute("style", "display: none;");
224 } 230 }
225 } 231 }
226 } 232 }
227 } 233 }
228 234
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698