| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/blocked_plugin.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "base/string_piece.h" |
| 10 #include "chrome/common/jstemplate_builder.h" |
| 11 #include "chrome/renderer/render_view.h" |
| 12 #include "grit/generated_resources.h" |
| 13 #include "grit/renderer_resources.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
| 19 #include "webkit/glue/plugins/webview_plugin.h" |
| 20 |
| 21 using WebKit::WebCursorInfo; |
| 22 using WebKit::WebFrame; |
| 23 using WebKit::WebPlugin; |
| 24 using WebKit::WebPluginContainer; |
| 25 using WebKit::WebPluginParams; |
| 26 using WebKit::WebURL; |
| 27 using WebKit::WebView; |
| 28 |
| 29 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; |
| 30 |
| 31 BlockedPlugin::BlockedPlugin(RenderView* render_view, |
| 32 WebFrame* frame, |
| 33 const WebPluginParams& params) |
| 34 : render_view_(render_view), |
| 35 frame_(frame), |
| 36 plugin_params_(params) { |
| 37 plugin_ = new WebViewPlugin(this); |
| 38 |
| 39 WebView* web_view = plugin_->web_view(); |
| 40 web_view->mainFrame()->setCanHaveScrollbars(false); |
| 41 |
| 42 int resource_id = IDR_BLOCKED_PLUGIN_HTML; |
| 43 const base::StringPiece template_html( |
| 44 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 45 |
| 46 DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 47 << resource_id; |
| 48 |
| 49 DictionaryValue localized_strings; |
| 50 localized_strings.SetString(L"loadPlugin", |
| 51 l10n_util::GetString(IDS_PLUGIN_LOAD)); |
| 52 |
| 53 // "t" is the id of the templates root node. |
| 54 std::string htmlData = jstemplate_builder::GetTemplatesHtml( |
| 55 template_html, &localized_strings, "t"); |
| 56 |
| 57 web_view->mainFrame()->loadHTMLString(htmlData, |
| 58 GURL(kBlockedPluginDataURL)); |
| 59 } |
| 60 |
| 61 void BlockedPlugin::BindWebFrame(WebFrame* frame) { |
| 62 BindToJavascript(frame, L"plugin"); |
| 63 BindMethod("load", &BlockedPlugin::Load); |
| 64 } |
| 65 |
| 66 void BlockedPlugin::WillDestroyPlugin() { |
| 67 delete this; |
| 68 } |
| 69 |
| 70 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { |
| 71 LoadPlugin(); |
| 72 } |
| 73 |
| 74 void BlockedPlugin::LoadPlugin() { |
| 75 CHECK(plugin_); |
| 76 WebPluginContainer* container = plugin_->container(); |
| 77 WebPlugin* new_plugin = |
| 78 render_view_->CreatePluginInternal(frame_, plugin_params_); |
| 79 if (new_plugin && new_plugin->initialize(container)) { |
| 80 container->setPlugin(new_plugin); |
| 81 container->invalidate(); |
| 82 container->reportGeometry(); |
| 83 plugin_->destroy(); |
| 84 } |
| 85 } |
| OLD | NEW |