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

Side by Side Diff: chrome/browser/guestview/webview/plugin_permission_helper.cc

Issue 24576003: <webview>: Change how plugin load works inside guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/browser/guestview/webview/plugin_permission_helper.h"
6
7 #include "chrome/browser/guestview/webview/webview_guest.h"
8 #include "chrome/browser/guestview/webview/webview_permission_types.h"
9 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
10 #include "chrome/common/render_messages.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/user_metrics.h"
14
15 using content::RenderViewHost;
16 using content::WebContents;
17
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginPermissionHelper);
19
20 PluginPermissionHelper::PluginPermissionHelper(WebContents* contents)
21 : content::WebContentsObserver(contents),
22 weak_factory_(this) {
23 }
24
25 PluginPermissionHelper::~PluginPermissionHelper() {
26 }
27
28 bool PluginPermissionHelper::OnMessageReceived(const IPC::Message& message) {
29 IPC_BEGIN_MESSAGE_MAP(PluginPermissionHelper, message)
30 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin,
31 OnBlockedUnauthorizedPlugin)
32 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
33 OnCouldNotLoadPlugin)
34 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
35 OnBlockedOutdatedPlugin)
36 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_NPAPINotSupported,
37 OnNPAPINotSupported)
38 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
39 OnOpenAboutPlugins)
40 #if defined(ENABLE_PLUGIN_INSTALLATION)
41 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin,
42 OnFindMissingPlugin)
43 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
44 OnRemovePluginPlaceholderHost)
45 #endif
46 IPC_MESSAGE_UNHANDLED(return false)
47 IPC_END_MESSAGE_MAP()
48
49 return true;
50 }
51
52 void PluginPermissionHelper::OnBlockedUnauthorizedPlugin(
53 const string16& name,
54 const std::string& identifier) {
55 const char kPluginName[] = "name";
56 const char kPluginIdentifier[] = "identifier";
57
58 WebViewGuest* webview = WebViewGuest::FromWebContents(web_contents());
59 if (!webview)
60 return;
61
62 base::DictionaryValue info;
63 info.SetString(std::string(kPluginName), name);
64 info.SetString(std::string(kPluginIdentifier), identifier);
65 webview->RequestPermission(static_cast<BrowserPluginPermissionType>(
66 WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN),
67 info,
68 base::Bind(&PluginPermissionHelper::OnPermissionResponse,
69 weak_factory_.GetWeakPtr(),
70 identifier));
71 content::RecordAction(
72 content::UserMetricsAction("WebView.Guest.PluginLoadRequest"));
73 }
74
75 void PluginPermissionHelper::OnCouldNotLoadPlugin(
76 const base::FilePath& plugin_path) {
77 }
78
79 void PluginPermissionHelper::OnBlockedOutdatedPlugin(
80 int placeholder_id,
81 const std::string& identifier) {
82 }
83
84 void PluginPermissionHelper::OnNPAPINotSupported(const std::string& id) {
85 }
86
87 void PluginPermissionHelper::OnOpenAboutPlugins() {
88 }
89
90 #if defined(ENABLE_PLUGIN_INSTALLATION)
91 void PluginPermissionHelper::OnFindMissingPlugin(int placeholder_id,
92 const std::string& mime_type) {
93 }
94
95 void PluginPermissionHelper::OnRemovePluginPlaceholderHost(int placeholder_id) {
96 }
97 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
98
99 void PluginPermissionHelper::OnPermissionResponse(const std::string& identifier,
100 bool allow,
101 const std::string& input) {
102 if (allow) {
103 RenderViewHost* host = web_contents()->GetRenderViewHost();
104 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
105 host->GetProcess()->GetID());
106 host->Send(new ChromeViewMsg_LoadBlockedPlugins(
107 host->GetRoutingID(), identifier));
108 }
109
110 content::RecordAction(
111 allow ? content::UserMetricsAction("WebView.Guest.PluginLoadAllowed") :
112 content::UserMetricsAction("WebView.Guest.PluginLoadDenied"));
113 }
OLDNEW
« no previous file with comments | « chrome/browser/guestview/webview/plugin_permission_helper.h ('k') | chrome/browser/guestview/webview/webview_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698