| 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" | |
| 13 #include "chrome/common/render_messages.h" | |
| 14 #include "chrome/renderer/render_view.h" | 12 #include "chrome/renderer/render_view.h" |
| 15 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 16 #include "grit/renderer_resources.h" | |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 19 #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/WebVector.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
| 25 #include "webkit/glue/webpreferences.h" | 22 #include "webkit/glue/webpreferences.h" |
| 26 #include "webkit/plugins/npapi/plugin_group.h" | 23 #include "webkit/plugins/npapi/plugin_group.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 60 |
| 64 // "t" is the id of the templates root node. | 61 // "t" is the id of the templates root node. |
| 65 std::string html_data = jstemplate_builder::GetTemplatesHtml( | 62 std::string html_data = jstemplate_builder::GetTemplatesHtml( |
| 66 template_html, &values, "t"); | 63 template_html, &values, "t"); |
| 67 | 64 |
| 68 plugin_ = webkit::npapi::WebViewPlugin::Create(this, | 65 plugin_ = webkit::npapi::WebViewPlugin::Create(this, |
| 69 preferences, | 66 preferences, |
| 70 html_data, | 67 html_data, |
| 71 GURL(kBlockedPluginDataURL)); | 68 GURL(kBlockedPluginDataURL)); |
| 72 | 69 |
| 73 registrar_.Add(this, | 70 render_view_->RegisterBlockedPlugin(this); |
| 74 NotificationType::SHOULD_LOAD_PLUGINS, | |
| 75 NotificationService::AllSources()); | |
| 76 } | 71 } |
| 77 | 72 |
| 78 BlockedPlugin::~BlockedPlugin() { | 73 BlockedPlugin::~BlockedPlugin() { |
| 79 render_view_->CustomMenuListenerDestroyed(this); | 74 render_view_->CustomMenuListenerDestroyed(this); |
| 75 render_view_->UnregisterBlockedPlugin(this); |
| 80 } | 76 } |
| 81 | 77 |
| 82 void BlockedPlugin::BindWebFrame(WebFrame* frame) { | 78 void BlockedPlugin::BindWebFrame(WebFrame* frame) { |
| 83 BindToJavascript(frame, "plugin"); | 79 BindToJavascript(frame, "plugin"); |
| 84 BindMethod("load", &BlockedPlugin::Load); | 80 BindMethod("load", &BlockedPlugin::Load); |
| 85 } | 81 } |
| 86 | 82 |
| 87 void BlockedPlugin::WillDestroyPlugin() { | 83 void BlockedPlugin::WillDestroyPlugin() { |
| 88 delete this; | 84 delete this; |
| 89 } | 85 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void BlockedPlugin::MenuItemSelected(unsigned id) { | 119 void BlockedPlugin::MenuItemSelected(unsigned id) { |
| 124 if (id == kMenuActionLoad) { | 120 if (id == kMenuActionLoad) { |
| 125 LoadPlugin(); | 121 LoadPlugin(); |
| 126 } else if (id == kMenuActionRemove) { | 122 } else if (id == kMenuActionRemove) { |
| 127 HidePlugin(); | 123 HidePlugin(); |
| 128 } else { | 124 } else { |
| 129 NOTREACHED(); | 125 NOTREACHED(); |
| 130 } | 126 } |
| 131 } | 127 } |
| 132 | 128 |
| 133 void BlockedPlugin::Observe(NotificationType type, | |
| 134 const NotificationSource& source, | |
| 135 const NotificationDetails& details) { | |
| 136 if (type == NotificationType::SHOULD_LOAD_PLUGINS) { | |
| 137 LoadPlugin(); | |
| 138 } else { | |
| 139 NOTREACHED(); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { | |
| 144 LoadPlugin(); | |
| 145 } | |
| 146 | |
| 147 void BlockedPlugin::LoadPlugin() { | 129 void BlockedPlugin::LoadPlugin() { |
| 148 CHECK(plugin_); | 130 CHECK(plugin_); |
| 149 WebPluginContainer* container = plugin_->container(); | 131 WebPluginContainer* container = plugin_->container(); |
| 150 WebPlugin* new_plugin = | 132 WebPlugin* new_plugin = |
| 151 render_view_->CreatePluginNoCheck(frame_, | 133 render_view_->CreatePluginNoCheck(frame_, |
| 152 plugin_params_); | 134 plugin_params_); |
| 153 if (new_plugin && new_plugin->initialize(container)) { | 135 if (new_plugin && new_plugin->initialize(container)) { |
| 154 container->setPlugin(new_plugin); | 136 container->setPlugin(new_plugin); |
| 155 container->invalidate(); | 137 container->invalidate(); |
| 156 container->reportGeometry(); | 138 container->reportGeometry(); |
| 157 plugin_->ReplayReceivedData(new_plugin); | 139 plugin_->ReplayReceivedData(new_plugin); |
| 158 plugin_->destroy(); | 140 plugin_->destroy(); |
| 159 } | 141 } |
| 160 } | 142 } |
| 161 | 143 |
| 144 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { |
| 145 LoadPlugin(); |
| 146 } |
| 147 |
| 162 void BlockedPlugin::HidePlugin() { | 148 void BlockedPlugin::HidePlugin() { |
| 163 CHECK(plugin_); | 149 CHECK(plugin_); |
| 164 WebPluginContainer* container = plugin_->container(); | 150 WebPluginContainer* container = plugin_->container(); |
| 165 container->element().setAttribute("style", "display: none;"); | 151 container->element().setAttribute("style", "display: none;"); |
| 166 } | 152 } |
| 167 | 153 |
| OLD | NEW |