| 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/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 Loading... |
| 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 Loading... |
| 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); |
| 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); |
| 128 return true; |
| 129 } |
| 130 |
| 131 // Don't want to swallow these messages. |
| 132 if (message.type() == ViewMsg_LoadBlockedPlugins::ID) { |
| 133 LoadPlugin(); |
| 134 } else if (message.type() == ViewMsg_ContextMenuClosed::ID) { |
| 135 custom_menu_showing_ = false; |
| 136 } |
| 137 |
| 138 return false; |
| 139 } |
| 140 |
| 141 void BlockedPlugin::OnMenuItemSelected(unsigned id) { |
| 126 if (id == kMenuActionLoad) { | 142 if (id == kMenuActionLoad) { |
| 127 LoadPlugin(); | 143 LoadPlugin(); |
| 128 } else if (id == kMenuActionRemove) { | 144 } else if (id == kMenuActionRemove) { |
| 129 HidePlugin(); | 145 HidePlugin(); |
| 130 } else { | 146 } else { |
| 131 NOTREACHED(); | 147 NOTREACHED(); |
| 132 } | 148 } |
| 133 } | 149 } |
| 134 | 150 |
| 135 void BlockedPlugin::LoadPlugin() { | 151 void BlockedPlugin::LoadPlugin() { |
| 136 CHECK(plugin_); | 152 CHECK(plugin_); |
| 137 WebPluginContainer* container = plugin_->container(); | 153 WebPluginContainer* container = plugin_->container(); |
| 138 WebPlugin* new_plugin = | 154 WebPlugin* new_plugin = |
| 139 render_view_->CreatePluginNoCheck(frame_, | 155 render_view()->CreatePluginNoCheck(frame_, plugin_params_); |
| 140 plugin_params_); | |
| 141 if (new_plugin && new_plugin->initialize(container)) { | 156 if (new_plugin && new_plugin->initialize(container)) { |
| 142 container->setPlugin(new_plugin); | 157 container->setPlugin(new_plugin); |
| 143 container->invalidate(); | 158 container->invalidate(); |
| 144 container->reportGeometry(); | 159 container->reportGeometry(); |
| 145 plugin_->ReplayReceivedData(new_plugin); | 160 plugin_->ReplayReceivedData(new_plugin); |
| 146 plugin_->destroy(); | 161 plugin_->destroy(); |
| 147 } | 162 } |
| 148 } | 163 } |
| 149 | 164 |
| 150 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { | 165 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 if (element.hasAttribute("style")) { | 205 if (element.hasAttribute("style")) { |
| 191 WebString style_str = element.getAttribute("style"); | 206 WebString style_str = element.getAttribute("style"); |
| 192 if (width_regex.match(style_str) >= 0 && | 207 if (width_regex.match(style_str) >= 0 && |
| 193 height_regex.match(style_str) >= 0) | 208 height_regex.match(style_str) >= 0) |
| 194 element.setAttribute("style", "display: none;"); | 209 element.setAttribute("style", "display: none;"); |
| 195 } | 210 } |
| 196 } | 211 } |
| 197 } | 212 } |
| 198 } | 213 } |
| 199 | 214 |
| OLD | NEW |