OLD | NEW |
---|---|
(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 | |
14 using content::RenderViewHost; | |
15 using content::WebContents; | |
16 | |
17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginPermissionHelper); | |
18 | |
19 PluginPermissionHelper::PluginPermissionHelper(WebContents* contents) | |
20 : content::WebContentsObserver(contents), | |
21 weak_factory_(this) { | |
22 } | |
23 | |
24 PluginPermissionHelper::~PluginPermissionHelper() { | |
25 } | |
26 | |
27 bool PluginPermissionHelper::OnMessageReceived(const IPC::Message& message) { | |
28 IPC_BEGIN_MESSAGE_MAP(PluginPermissionHelper, message) | |
29 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, | |
30 OnBlockedUnauthorizedPlugin) | |
31 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, | |
32 OnCouldNotLoadPlugin) | |
33 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | |
34 OnBlockedOutdatedPlugin) | |
35 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_NPAPINotSupported, | |
36 OnNPAPINotSupported) | |
37 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, | |
38 OnOpenAboutPlugins) | |
39 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
40 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin, | |
41 OnFindMissingPlugin) | |
42 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, | |
43 OnRemovePluginPlaceholderHost) | |
44 #endif | |
45 IPC_MESSAGE_UNHANDLED(return false) | |
46 IPC_END_MESSAGE_MAP() | |
47 | |
48 return true; | |
49 } | |
50 | |
51 void PluginPermissionHelper::OnBlockedUnauthorizedPlugin( | |
52 const string16& name, | |
53 const std::string& identifier) { | |
54 const char kPluginName[] = "name"; | |
55 const char kPluginIdentifier[] = "identifier"; | |
56 | |
57 WebViewGuest* webview = WebViewGuest::FromWebContents(web_contents()); | |
58 if (!webview) | |
59 return; | |
60 | |
61 base::DictionaryValue info; | |
Fady Samuel
2013/09/27 13:04:08
It would be nice to have an UMA count here. WebVie
sadrul
2013/09/27 14:17:39
Done.
| |
62 info.SetString(std::string(kPluginName), name); | |
63 info.SetString(std::string(kPluginIdentifier), identifier); | |
64 webview->RequestPermission(static_cast<BrowserPluginPermissionType>( | |
65 WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN), | |
66 info, | |
67 base::Bind(&PluginPermissionHelper::OnPermissionResponse, | |
68 weak_factory_.GetWeakPtr(), | |
69 identifier)); | |
70 } | |
71 | |
72 void PluginPermissionHelper::OnCouldNotLoadPlugin( | |
73 const base::FilePath& plugin_path) { | |
74 } | |
75 | |
76 void PluginPermissionHelper::OnBlockedOutdatedPlugin( | |
77 int placeholder_id, | |
78 const std::string& identifier) { | |
79 } | |
80 | |
81 void PluginPermissionHelper::OnNPAPINotSupported(const std::string& id) { | |
82 } | |
83 | |
84 void PluginPermissionHelper::OnOpenAboutPlugins() { | |
85 } | |
86 | |
87 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
88 void PluginPermissionHelper::OnFindMissingPlugin(int placeholder_id, | |
89 const std::string& mime_type) { | |
90 } | |
91 | |
92 void PluginPermissionHelper::OnRemovePluginPlaceholderHost(int placeholder_id) { | |
93 } | |
94 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | |
95 | |
96 void PluginPermissionHelper::OnPermissionResponse(const std::string& identifier, | |
97 bool allow, | |
98 const std::string& input) { | |
99 if (allow) { | |
100 RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
101 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | |
102 host->GetProcess()->GetID()); | |
103 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | |
104 host->GetRoutingID(), identifier)); | |
105 } | |
106 } | |
OLD | NEW |