OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | |
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "base/metrics/user_metrics_action.h" | |
10 #include "chrome/browser/guest_view/guest_view_constants.h" | |
11 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | |
12 #include "content/public/browser/web_contents_observer.h" | |
13 #include "content/public/browser/web_contents_user_data.h" | |
14 #include "content/public/common/media_stream_request.h" | |
15 | |
16 using base::UserMetricsAction; | |
17 | |
18 class WebViewGuest; | |
19 | |
20 class WebViewPermissionHelper | |
21 : public content::WebContentsUserData<WebViewPermissionHelper>, | |
22 public content::WebContentsObserver { | |
23 public: | |
24 explicit WebViewPermissionHelper(content::WebContents* web_contents); | |
25 virtual ~WebViewPermissionHelper(); | |
26 typedef base::Callback< | |
27 void(bool /* allow */, const std::string& /* user_input */)> | |
28 PermissionResponseCallback; | |
29 | |
30 // A map to store the callback for a request keyed by the request's id. | |
31 struct PermissionResponseInfo { | |
32 PermissionResponseCallback callback; | |
33 WebViewPermissionType permission_type; | |
34 bool allowed_by_default; | |
35 PermissionResponseInfo(); | |
36 PermissionResponseInfo(const PermissionResponseCallback& callback, | |
37 WebViewPermissionType permission_type, | |
38 bool allowed_by_default); | |
39 ~PermissionResponseInfo(); | |
40 }; | |
41 | |
42 typedef std::map<int, PermissionResponseInfo> RequestMap; | |
43 | |
44 int RequestPermission(WebViewPermissionType permission_type, | |
45 const base::DictionaryValue& request_info, | |
46 const PermissionResponseCallback& callback, | |
47 bool allowed_by_default); | |
48 | |
49 void RequestMediaAccessPermission( | |
50 content::WebContents* source, | |
51 const content::MediaStreamRequest& request, | |
52 const content::MediaResponseCallback& callback); | |
53 void CanDownload(content::RenderViewHost* render_view_host, | |
54 const GURL& url, | |
55 const std::string& request_method, | |
56 const base::Callback<void(bool)>& callback); | |
57 void RequestPointerLockPermission(bool user_gesture, | |
58 bool last_unlocked_by_target, | |
59 const base::Callback<void(bool)>& callback); | |
60 | |
61 // Requests Geolocation Permission from the embedder. | |
62 void RequestGeolocationPermission(int bridge_id, | |
63 const GURL& requesting_frame, | |
64 bool user_gesture, | |
65 const base::Callback<void(bool)>& callback); | |
66 void CancelGeolocationPermissionRequest(int bridge_id); | |
67 | |
68 void RequestFileSystemPermission(const GURL& url, | |
69 bool allowed_by_default, | |
70 const base::Callback<void(bool)>& callback); | |
71 | |
72 // Called when file system access is requested by the guest content using the | |
73 // asynchronous HTML5 file system API. The request is plumbed through the | |
74 // <webview> permission request API. The request will be: | |
75 // - Allowed if the embedder explicitly allowed it. | |
76 // - Denied if the embedder explicitly denied. | |
77 // - Determined by the guest's content settings if the embedder does not | |
78 // perform an explicit action. | |
79 // If access was blocked due to the page's content settings, | |
80 // |blocked_by_policy| should be true, and this function should invoke | |
81 // OnContentBlocked. | |
82 void FileSystemAccessedAsync(int render_process_id, | |
83 int render_frame_id, | |
84 int request_id, | |
85 const GURL& url, | |
86 bool blocked_by_policy); | |
87 | |
88 // Called when file system access is requested by the guest content using the | |
89 // synchronous HTML5 file system API in a worker thread or shared worker. The | |
90 // request is plumbed through the <webview> permission request API. The | |
91 // request will be: | |
92 // - Allowed if the embedder explicitly allowed it. | |
93 // - Denied if the embedder explicitly denied. | |
94 // - Determined by the guest's content settings if the embedder does not | |
95 // perform an explicit action. | |
96 // If access was blocked due to the page's content settings, | |
97 // |blocked_by_policy| should be true, and this function should invoke | |
98 // OnContentBlocked. | |
99 void FileSystemAccessedSync(int render_process_id, | |
100 int render_frame_id, | |
101 const GURL& url, | |
102 bool blocked_by_policy, | |
103 IPC::Message* reply_msg); | |
104 | |
105 enum PermissionResponseAction { DENY, ALLOW, DEFAULT }; | |
106 | |
107 enum SetPermissionResult { | |
108 SET_PERMISSION_INVALID, | |
109 SET_PERMISSION_ALLOWED, | |
110 SET_PERMISSION_DENIED | |
111 }; | |
112 | |
113 // Responds to the permission request |request_id| with |action| and | |
114 // |user_input|. Returns whether there was a pending request for the provided | |
115 // |request_id|. | |
116 SetPermissionResult SetPermission(int request_id, | |
117 PermissionResponseAction action, | |
118 const std::string& user_input); | |
119 | |
120 private: | |
121 #if defined(ENABLE_PLUGINS) | |
122 friend class content::WebContentsUserData<WebViewPermissionHelper>; | |
123 | |
124 // content::WebContentsObserver implementation. | |
125 virtual bool OnMessageReceived( | |
126 const IPC::Message& message, | |
127 content::RenderFrameHost* render_frame_host) OVERRIDE; | |
128 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
129 | |
130 // Message handlers: | |
131 void OnBlockedUnauthorizedPlugin(const base::string16& name, | |
132 const std::string& identifier); | |
133 void OnCouldNotLoadPlugin(const base::FilePath& plugin_path); | |
134 void OnBlockedOutdatedPlugin(int placeholder_id, | |
135 const std::string& identifier); | |
136 void OnNPAPINotSupported(const std::string& identifier); | |
137 void OnOpenAboutPlugins(); | |
138 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
139 void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type); | |
140 | |
141 void OnRemovePluginPlaceholderHost(int placeholder_id); | |
142 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | |
143 | |
144 void OnPermissionResponse(const std::string& identifier, | |
145 bool allow, | |
146 const std::string& user_input); | |
147 #endif // defiend(ENABLE_PLUGINS) | |
148 | |
149 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info, | |
150 bool allow); | |
Fady Samuel
2014/06/20 22:54:33
Space
Xi Han
2014/06/24 13:55:33
Done.
| |
151 void OnWebViewGeolocationPermissionResponse( | |
152 int bridge_id, | |
153 bool user_gesture, | |
154 const base::Callback<void(bool)>& callback, | |
155 bool allow, | |
156 const std::string& user_input); | |
157 | |
158 void OnWebViewFileSystemPermissionResponse( | |
159 const base::Callback<void(bool)>& callback, | |
160 bool allow, | |
161 const std::string& user_input); | |
162 | |
163 void OnWebViewMediaPermissionResponse( | |
164 const content::MediaStreamRequest& request, | |
165 const content::MediaResponseCallback& callback, | |
166 bool allow, | |
167 const std::string& user_input); | |
168 | |
169 void OnWebViewDownloadPermissionResponse( | |
170 const base::Callback<void(bool)>& callback, | |
171 bool allow, | |
172 const std::string& user_input); | |
173 | |
174 void OnWebViewPointerLockPermissionResponse( | |
175 const base::Callback<void(bool)>& callback, | |
176 bool allow, | |
177 const std::string& user_input); | |
178 | |
179 // Bridge IDs correspond to a geolocation request. This method will remove | |
180 // the bookkeeping for a particular geolocation request associated with the | |
181 // provided |bridge_id|. It returns the request ID of the geolocation request. | |
182 int RemoveBridgeID(int bridge_id); | |
183 | |
184 void FileSystemAccessedAsyncResponse(int render_process_id, | |
185 int render_frame_id, | |
186 int request_id, | |
187 const GURL& url, | |
188 bool allowed); | |
189 | |
190 void FileSystemAccessedSyncResponse(int render_process_id, | |
191 int render_frame_id, | |
192 const GURL& url, | |
193 IPC::Message* reply_msg, | |
194 bool allowed); | |
195 | |
196 base::WeakPtrFactory<WebViewPermissionHelper> weak_factory_; | |
197 | |
198 // A counter to generate a unique request id for a permission request. | |
199 // We only need the ids to be unique for a given WebViewGuest. | |
200 int next_permission_request_id_; | |
201 | |
202 WebViewPermissionHelper::RequestMap pending_permission_requests_; | |
203 | |
204 std::map<int, int> bridge_id_to_request_id_map_; | |
205 | |
206 WebViewGuest* const web_view_guest_; | |
207 | |
208 DISALLOW_COPY_AND_ASSIGN(WebViewPermissionHelper); | |
209 }; | |
210 | |
211 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_ | |
OLD | NEW |