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

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_permission_helper.h

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

Powered by Google App Engine
This is Rietveld 408576698