| OLD | NEW |
| 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using WebKit::WebNode; | 34 using WebKit::WebNode; |
| 35 using WebKit::WebPlugin; | 35 using WebKit::WebPlugin; |
| 36 using WebKit::WebPluginContainer; | 36 using WebKit::WebPluginContainer; |
| 37 using WebKit::WebPluginParams; | 37 using WebKit::WebPluginParams; |
| 38 using WebKit::WebPoint; | 38 using WebKit::WebPoint; |
| 39 using WebKit::WebRegularExpression; | 39 using WebKit::WebRegularExpression; |
| 40 using WebKit::WebString; | 40 using WebKit::WebString; |
| 41 using WebKit::WebVector; | 41 using WebKit::WebVector; |
| 42 | 42 |
| 43 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; | 43 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; |
| 44 // TODO(cevans) - move these to a shared header file so that there are no |
| 45 // collisions in the longer term. Currently, blocked_plugin.cc is the only |
| 46 // user of custom menu commands (extension menu items have their own range). |
| 44 static const unsigned kMenuActionLoad = 1; | 47 static const unsigned kMenuActionLoad = 1; |
| 45 static const unsigned kMenuActionRemove = 2; | 48 static const unsigned kMenuActionRemove = 2; |
| 46 | 49 |
| 47 BlockedPlugin::BlockedPlugin(RenderView* render_view, | 50 BlockedPlugin::BlockedPlugin(RenderView* render_view, |
| 48 WebFrame* frame, | 51 WebFrame* frame, |
| 49 const webkit::npapi::PluginGroup& info, | 52 const webkit::npapi::PluginGroup& info, |
| 50 const WebPluginParams& params, | 53 const WebPluginParams& params, |
| 51 const WebPreferences& preferences, | 54 const WebPreferences& preferences, |
| 52 int template_id, | 55 int template_id, |
| 53 const string16& message) | 56 const string16& message) |
| 54 : RenderViewObserver(render_view), | 57 : RenderViewObserver(render_view), |
| 55 frame_(frame), | 58 frame_(frame), |
| 56 plugin_params_(params), | 59 plugin_params_(params) { |
| 57 custom_menu_showing_(false) { | |
| 58 const base::StringPiece template_html( | 60 const base::StringPiece template_html( |
| 59 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 61 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); |
| 60 | 62 |
| 61 DCHECK(!template_html.empty()) << "unable to load template. ID: " | 63 DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 62 << template_id; | 64 << template_id; |
| 63 | 65 |
| 64 DictionaryValue values; | 66 DictionaryValue values; |
| 65 values.SetString("message", message); | 67 values.SetString("message", message); |
| 66 name_ = info.GetGroupName(); | 68 name_ = info.GetGroupName(); |
| 67 values.SetString("name", name_); | 69 values.SetString("name", name_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 WebMenuItemInfo hide_item; | 113 WebMenuItemInfo hide_item; |
| 112 hide_item.action = kMenuActionRemove; | 114 hide_item.action = kMenuActionRemove; |
| 113 hide_item.enabled = true; | 115 hide_item.enabled = true; |
| 114 hide_item.label = WebString::fromUTF8( | 116 hide_item.label = WebString::fromUTF8( |
| 115 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); | 117 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); |
| 116 custom_items[3] = hide_item; | 118 custom_items[3] = hide_item; |
| 117 | 119 |
| 118 menu_data.customItems.swap(custom_items); | 120 menu_data.customItems.swap(custom_items); |
| 119 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); | 121 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); |
| 120 render_view()->showContextMenu(NULL, menu_data); | 122 render_view()->showContextMenu(NULL, menu_data); |
| 121 custom_menu_showing_ = true; | |
| 122 } | 123 } |
| 123 | 124 |
| 124 bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) { | 125 bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) { |
| 125 if (custom_menu_showing_ && | 126 // We don't swallow ViewMsg_CustomContextMenuAction because we listen for all |
| 126 message.type() == ViewMsg_CustomContextMenuAction::ID) { | 127 // custom menu IDs, and not just our own. We don't swallow |
| 128 // ViewMsg_LoadBlockedPlugins because multiple blocked plugins have an |
| 129 // interest in it. |
| 130 if (message.type() == ViewMsg_CustomContextMenuAction::ID) { |
| 127 ViewMsg_CustomContextMenuAction::Dispatch( | 131 ViewMsg_CustomContextMenuAction::Dispatch( |
| 128 &message, this, this, &BlockedPlugin::OnMenuItemSelected); | 132 &message, this, this, &BlockedPlugin::OnMenuItemSelected); |
| 129 return true; | 133 } else if (message.type() == ViewMsg_LoadBlockedPlugins::ID) { |
| 130 } | |
| 131 | |
| 132 // Don't want to swallow these messages. | |
| 133 if (message.type() == ViewMsg_LoadBlockedPlugins::ID) { | |
| 134 LoadPlugin(); | 134 LoadPlugin(); |
| 135 } else if (message.type() == ViewMsg_ContextMenuClosed::ID) { | |
| 136 custom_menu_showing_ = false; | |
| 137 } | 135 } |
| 138 | 136 |
| 139 return false; | 137 return false; |
| 140 } | 138 } |
| 141 | 139 |
| 142 void BlockedPlugin::OnMenuItemSelected(unsigned id) { | 140 void BlockedPlugin::OnMenuItemSelected(unsigned id) { |
| 143 if (id == kMenuActionLoad) { | 141 if (id == kMenuActionLoad) { |
| 144 LoadPlugin(); | 142 LoadPlugin(); |
| 145 } else if (id == kMenuActionRemove) { | 143 } else if (id == kMenuActionRemove) { |
| 146 HidePlugin(); | 144 HidePlugin(); |
| 147 } else { | |
| 148 NOTREACHED(); | |
| 149 } | 145 } |
| 150 } | 146 } |
| 151 | 147 |
| 152 void BlockedPlugin::LoadPlugin() { | 148 void BlockedPlugin::LoadPlugin() { |
| 153 CHECK(plugin_); | 149 CHECK(plugin_); |
| 154 WebPluginContainer* container = plugin_->container(); | 150 WebPluginContainer* container = plugin_->container(); |
| 155 WebPlugin* new_plugin = | 151 WebPlugin* new_plugin = |
| 156 render_view()->CreatePluginNoCheck(frame_, plugin_params_); | 152 render_view()->CreatePluginNoCheck(frame_, plugin_params_); |
| 157 if (new_plugin && new_plugin->initialize(container)) { | 153 if (new_plugin && new_plugin->initialize(container)) { |
| 158 container->setPlugin(new_plugin); | 154 container->setPlugin(new_plugin); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 if (element.hasAttribute("style")) { | 210 if (element.hasAttribute("style")) { |
| 215 WebString style_str = element.getAttribute("style"); | 211 WebString style_str = element.getAttribute("style"); |
| 216 if (width_regex.match(style_str) >= 0 && | 212 if (width_regex.match(style_str) >= 0 && |
| 217 height_regex.match(style_str) >= 0) | 213 height_regex.match(style_str) >= 0) |
| 218 element.setAttribute("style", "display: none;"); | 214 element.setAttribute("style", "display: none;"); |
| 219 } | 215 } |
| 220 } | 216 } |
| 221 } | 217 } |
| 222 } | 218 } |
| 223 | 219 |
| OLD | NEW |