Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Side by Side Diff: chrome/renderer/blocked_plugin.cc

Issue 2967007: Disable outdated plugins, block non-sandboxed plugins. (Closed)
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/blocked_plugin.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_path.h"
9 #include "base/string_piece.h" 10 #include "base/string_piece.h"
10 #include "chrome/common/jstemplate_builder.h" 11 #include "chrome/common/jstemplate_builder.h"
12 #include "chrome/common/notification_service.h"
13 #include "chrome/common/plugin_group.h"
14 #include "chrome/common/render_messages.h"
11 #include "chrome/renderer/render_view.h" 15 #include "chrome/renderer/render_view.h"
12 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
13 #include "grit/renderer_resources.h" 17 #include "grit/renderer_resources.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" 18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 20 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
18 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 22 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
19 #include "webkit/glue/plugins/webview_plugin.h" 23 #include "webkit/glue/plugins/webview_plugin.h"
20 24
21 using WebKit::WebCursorInfo; 25 using WebKit::WebCursorInfo;
22 using WebKit::WebFrame; 26 using WebKit::WebFrame;
23 using WebKit::WebPlugin; 27 using WebKit::WebPlugin;
24 using WebKit::WebPluginContainer; 28 using WebKit::WebPluginContainer;
25 using WebKit::WebPluginParams; 29 using WebKit::WebPluginParams;
26 using WebKit::WebURL; 30 using WebKit::WebURL;
27 using WebKit::WebView; 31 using WebKit::WebView;
28 32
29 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; 33 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/";
30 34
31 BlockedPlugin::BlockedPlugin(RenderView* render_view, 35 BlockedPlugin::BlockedPlugin(RenderView* render_view,
32 WebFrame* frame, 36 WebFrame* frame,
33 const WebPluginParams& params) 37 const WebPluginParams& params,
38 PluginGroup* group)
34 : render_view_(render_view), 39 : render_view_(render_view),
35 frame_(frame), 40 frame_(frame),
36 plugin_params_(params) { 41 plugin_params_(params) {
37 plugin_ = new WebViewPlugin(this); 42 plugin_ = new WebViewPlugin(this);
38 43
39 WebView* web_view = plugin_->web_view(); 44 WebView* web_view = plugin_->web_view();
40 web_view->mainFrame()->setCanHaveScrollbars(false); 45 web_view->mainFrame()->setCanHaveScrollbars(false);
41 46
42 int resource_id = IDR_BLOCKED_PLUGIN_HTML; 47 int resource_id = IDR_BLOCKED_PLUGIN_HTML;
43 const base::StringPiece template_html( 48 const base::StringPiece template_html(
44 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); 49 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id));
45 50
46 DCHECK(!template_html.empty()) << "unable to load template. ID: " 51 DCHECK(!template_html.empty()) << "unable to load template. ID: "
47 << resource_id; 52 << resource_id;
48 53
49 DictionaryValue localized_strings; 54 DictionaryValue values;
50 localized_strings.SetString(L"loadPlugin", 55 values.SetString(L"loadPlugin", l10n_util::GetString(IDS_PLUGIN_LOAD));
51 l10n_util::GetString(IDS_PLUGIN_LOAD)); 56 values.SetString(L"updatePlugin", l10n_util::GetString(IDS_PLUGIN_UPDATE));
57 if (group)
58 values.Set(L"pluginGroup", group->GetDataForUI());
52 59
53 // "t" is the id of the templates root node. 60 // "t" is the id of the templates root node.
54 std::string htmlData = jstemplate_builder::GetTemplatesHtml( 61 std::string htmlData = jstemplate_builder::GetTemplatesHtml(
55 template_html, &localized_strings, "t"); 62 template_html, &values, "t");
56 63
57 web_view->mainFrame()->loadHTMLString(htmlData, 64 web_view->mainFrame()->loadHTMLString(htmlData,
58 GURL(kBlockedPluginDataURL)); 65 GURL(kBlockedPluginDataURL));
66
67 registrar_.Add(this,
68 NotificationType::SHOULD_LOAD_PLUGINS,
69 NotificationService::AllSources());
59 } 70 }
60 71
61 void BlockedPlugin::BindWebFrame(WebFrame* frame) { 72 void BlockedPlugin::BindWebFrame(WebFrame* frame) {
62 BindToJavascript(frame, L"plugin"); 73 BindToJavascript(frame, L"plugin");
63 BindMethod("load", &BlockedPlugin::Load); 74 BindMethod("load", &BlockedPlugin::Load);
75 BindMethod("update", &BlockedPlugin::Update);
64 } 76 }
65 77
66 void BlockedPlugin::WillDestroyPlugin() { 78 void BlockedPlugin::WillDestroyPlugin() {
67 delete this; 79 delete this;
68 } 80 }
69 81
82 void BlockedPlugin::Observe(NotificationType type,
83 const NotificationSource& source,
84 const NotificationDetails& details) {
85 if (type == NotificationType::SHOULD_LOAD_PLUGINS) {
86 LoadPlugin();
87 } else {
88 NOTREACHED();
89 }
90 }
91
70 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { 92 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) {
71 LoadPlugin(); 93 LoadPlugin();
72 } 94 }
73 95
96 void BlockedPlugin::Update(const CppArgumentList& args, CppVariant* result) {
97 if (args.size() > 0) {
98 CppVariant arg(args[0]);
99 if (arg.isString()) {
100 GURL url(arg.ToString());
101 OpenURL(url);
102 }
103 }
104 }
105
106 void BlockedPlugin::OpenURL(GURL& url) {
107 render_view_->Send(new ViewHostMsg_OpenURL(render_view_->routing_id(),
108 url,
109 GURL(),
110 CURRENT_TAB));
111 }
112
74 void BlockedPlugin::LoadPlugin() { 113 void BlockedPlugin::LoadPlugin() {
75 CHECK(plugin_); 114 CHECK(plugin_);
76 WebPluginContainer* container = plugin_->container(); 115 WebPluginContainer* container = plugin_->container();
77 WebPlugin* new_plugin = 116 WebPlugin* new_plugin =
78 render_view_->CreatePluginInternal(frame_, plugin_params_); 117 render_view_->CreateNPAPIPlugin(frame_,
118 plugin_params_,
119 NULL,
120 std::string());
79 if (new_plugin && new_plugin->initialize(container)) { 121 if (new_plugin && new_plugin->initialize(container)) {
80 container->setPlugin(new_plugin); 122 container->setPlugin(new_plugin);
81 container->invalidate(); 123 container->invalidate();
82 container->reportGeometry(); 124 container->reportGeometry();
83 plugin_->destroy(); 125 plugin_->destroy();
126 render_view_->Send(
127 new ViewHostMsg_BlockedPluginLoaded(render_view_->routing_id()));
84 } 128 }
85 } 129 }
OLDNEW
« no previous file with comments | « chrome/renderer/blocked_plugin.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698