| 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/notification_service.h" | 12 #include "chrome/common/notification_service.h" | 
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" | 
| 14 #include "chrome/renderer/render_view.h" | 14 #include "chrome/renderer/render_view.h" | 
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" | 
| 16 #include "grit/renderer_resources.h" | 16 #include "grit/renderer_resources.h" | 
|  | 17 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | 
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 
|  | 20 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" | 
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 
|  | 22 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 
|  | 23 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 
| 21 #include "webkit/glue/plugins/plugin_group.h" | 25 #include "webkit/glue/plugins/plugin_group.h" | 
| 22 #include "webkit/glue/plugins/webview_plugin.h" | 26 #include "webkit/glue/plugins/webview_plugin.h" | 
| 23 #include "webkit/glue/webpreferences.h" | 27 #include "webkit/glue/webpreferences.h" | 
| 24 | 28 | 
|  | 29 using WebKit::WebContextMenuData; | 
| 25 using WebKit::WebFrame; | 30 using WebKit::WebFrame; | 
|  | 31 using WebKit::WebMenuItemInfo; | 
| 26 using WebKit::WebPlugin; | 32 using WebKit::WebPlugin; | 
| 27 using WebKit::WebPluginContainer; | 33 using WebKit::WebPluginContainer; | 
| 28 using WebKit::WebPluginParams; | 34 using WebKit::WebPluginParams; | 
|  | 35 using WebKit::WebPoint; | 
|  | 36 using WebKit::WebString; | 
|  | 37 using WebKit::WebVector; | 
| 29 | 38 | 
| 30 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; | 39 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; | 
|  | 40 static const unsigned kMenuActionLoad = 1; | 
|  | 41 static const unsigned kMenuActionRemove = 2; | 
| 31 | 42 | 
| 32 BlockedPlugin::BlockedPlugin(RenderView* render_view, | 43 BlockedPlugin::BlockedPlugin(RenderView* render_view, | 
| 33                              WebFrame* frame, | 44                              WebFrame* frame, | 
| 34                              const PluginGroup& info, | 45                              const PluginGroup& info, | 
| 35                              const WebPluginParams& params, | 46                              const WebPluginParams& params, | 
| 36                              const WebPreferences& preferences, | 47                              const WebPreferences& preferences, | 
| 37                              int template_id, | 48                              int template_id, | 
| 38                              const string16& message) | 49                              const string16& message) | 
| 39     : render_view_(render_view), | 50     : render_view_(render_view), | 
| 40       frame_(frame), | 51       frame_(frame), | 
| 41       plugin_params_(params) { | 52       plugin_params_(params) { | 
| 42   const base::StringPiece template_html( | 53   const base::StringPiece template_html( | 
| 43       ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 54       ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); | 
| 44 | 55 | 
| 45   DCHECK(!template_html.empty()) << "unable to load template. ID: " | 56   DCHECK(!template_html.empty()) << "unable to load template. ID: " | 
| 46                                  << template_id; | 57                                  << template_id; | 
| 47 | 58 | 
| 48   DictionaryValue values; | 59   DictionaryValue values; | 
| 49   values.SetString("message", message); | 60   values.SetString("message", message); | 
| 50   values.SetString("name", info.GetGroupName()); | 61   name_ = info.GetGroupName(); | 
|  | 62   values.SetString("name", name_); | 
| 51 | 63 | 
| 52   // "t" is the id of the templates root node. | 64   // "t" is the id of the templates root node. | 
| 53   std::string html_data = jstemplate_builder::GetTemplatesHtml( | 65   std::string html_data = jstemplate_builder::GetTemplatesHtml( | 
| 54       template_html, &values, "t"); | 66       template_html, &values, "t"); | 
| 55 | 67 | 
| 56   plugin_ = WebViewPlugin::Create(this, | 68   plugin_ = WebViewPlugin::Create(this, | 
| 57                                   preferences, | 69                                   preferences, | 
| 58                                   html_data, | 70                                   html_data, | 
| 59                                   GURL(kBlockedPluginDataURL)); | 71                                   GURL(kBlockedPluginDataURL)); | 
| 60 | 72 | 
| 61   registrar_.Add(this, | 73   registrar_.Add(this, | 
| 62                  NotificationType::SHOULD_LOAD_PLUGINS, | 74                  NotificationType::SHOULD_LOAD_PLUGINS, | 
| 63                  NotificationService::AllSources()); | 75                  NotificationService::AllSources()); | 
| 64 } | 76 } | 
| 65 | 77 | 
| 66 BlockedPlugin::~BlockedPlugin() {} | 78 BlockedPlugin::~BlockedPlugin() { | 
|  | 79   render_view_->CustomMenuListenerDestroyed(this); | 
|  | 80 } | 
| 67 | 81 | 
| 68 void BlockedPlugin::BindWebFrame(WebFrame* frame) { | 82 void BlockedPlugin::BindWebFrame(WebFrame* frame) { | 
| 69   BindToJavascript(frame, L"plugin"); | 83   BindToJavascript(frame, L"plugin"); | 
| 70   BindMethod("load", &BlockedPlugin::Load); | 84   BindMethod("load", &BlockedPlugin::Load); | 
| 71 } | 85 } | 
| 72 | 86 | 
| 73 void BlockedPlugin::WillDestroyPlugin() { | 87 void BlockedPlugin::WillDestroyPlugin() { | 
| 74   delete this; | 88   delete this; | 
| 75 } | 89 } | 
| 76 | 90 | 
|  | 91 void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { | 
|  | 92   WebContextMenuData menu_data; | 
|  | 93   WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(4)); | 
|  | 94 | 
|  | 95   WebMenuItemInfo name_item; | 
|  | 96   name_item.label = name_; | 
|  | 97   custom_items[0] = name_item; | 
|  | 98 | 
|  | 99   WebMenuItemInfo separator_item; | 
|  | 100   separator_item.type = WebMenuItemInfo::Separator; | 
|  | 101   custom_items[1] = separator_item; | 
|  | 102 | 
|  | 103   WebMenuItemInfo run_item; | 
|  | 104   run_item.action = kMenuActionLoad; | 
|  | 105   run_item.enabled = true; | 
|  | 106   run_item.label = WebString::fromUTF8( | 
|  | 107       l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str()); | 
|  | 108   custom_items[2] = run_item; | 
|  | 109 | 
|  | 110   WebMenuItemInfo hide_item; | 
|  | 111   hide_item.action = kMenuActionRemove; | 
|  | 112   hide_item.enabled = true; | 
|  | 113   hide_item.label = WebString::fromUTF8( | 
|  | 114       l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); | 
|  | 115   custom_items[3] = hide_item; | 
|  | 116 | 
|  | 117   menu_data.customItems.swap(custom_items); | 
|  | 118   menu_data.mousePosition = WebPoint(event.windowX, event.windowY); | 
|  | 119   render_view_->showContextMenu(NULL, menu_data); | 
|  | 120   render_view_->CustomMenuListenerInstall(this); | 
|  | 121 } | 
|  | 122 | 
|  | 123 void BlockedPlugin::MenuItemSelected(unsigned id) { | 
|  | 124   if (id == kMenuActionLoad) { | 
|  | 125     LoadPlugin(); | 
|  | 126   } else if (id == kMenuActionRemove) { | 
|  | 127     HidePlugin(); | 
|  | 128   } else { | 
|  | 129     NOTREACHED(); | 
|  | 130   } | 
|  | 131 } | 
|  | 132 | 
| 77 void BlockedPlugin::Observe(NotificationType type, | 133 void BlockedPlugin::Observe(NotificationType type, | 
| 78                             const NotificationSource& source, | 134                             const NotificationSource& source, | 
| 79                             const NotificationDetails& details) { | 135                             const NotificationDetails& details) { | 
| 80   if (type == NotificationType::SHOULD_LOAD_PLUGINS) { | 136   if (type == NotificationType::SHOULD_LOAD_PLUGINS) { | 
| 81     LoadPlugin(); | 137     LoadPlugin(); | 
| 82   } else { | 138   } else { | 
| 83     NOTREACHED(); | 139     NOTREACHED(); | 
| 84   } | 140   } | 
| 85 } | 141 } | 
| 86 | 142 | 
| 87 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { | 143 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { | 
| 88   LoadPlugin(); | 144   LoadPlugin(); | 
| 89 } | 145 } | 
| 90 | 146 | 
| 91 void BlockedPlugin::LoadPlugin() { | 147 void BlockedPlugin::LoadPlugin() { | 
| 92   CHECK(plugin_); | 148   CHECK(plugin_); | 
| 93   WebPluginContainer* container = plugin_->container(); | 149   WebPluginContainer* container = plugin_->container(); | 
| 94   WebPlugin* new_plugin = | 150   WebPlugin* new_plugin = | 
| 95       render_view_->CreatePluginNoCheck(frame_, | 151       render_view_->CreatePluginNoCheck(frame_, | 
| 96                                         plugin_params_); | 152                                         plugin_params_); | 
| 97   if (new_plugin && new_plugin->initialize(container)) { | 153   if (new_plugin && new_plugin->initialize(container)) { | 
| 98     container->setPlugin(new_plugin); | 154     container->setPlugin(new_plugin); | 
| 99     container->invalidate(); | 155     container->invalidate(); | 
| 100     container->reportGeometry(); | 156     container->reportGeometry(); | 
| 101     plugin_->ReplayReceivedData(new_plugin); | 157     plugin_->ReplayReceivedData(new_plugin); | 
| 102     plugin_->destroy(); | 158     plugin_->destroy(); | 
| 103   } | 159   } | 
| 104 } | 160 } | 
|  | 161 | 
|  | 162 void BlockedPlugin::HidePlugin() { | 
|  | 163   CHECK(plugin_); | 
|  | 164   WebPluginContainer* container = plugin_->container(); | 
|  | 165   container->element().setAttribute("style", "display: none;"); | 
|  | 166 } | 
|  | 167 | 
| OLD | NEW | 
|---|