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

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

Issue 239113007: <webview>: Move pointerLock permission to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_downloads_to_chrome
Patch Set: Created 6 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/guestview/webview/webview_guest.h" 5 #include "chrome/browser/guestview/webview/webview_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 break; 72 break;
73 } 73 }
74 NOTREACHED() << "Unknown Termination Status."; 74 NOTREACHED() << "Unknown Termination Status.";
75 return "unknown"; 75 return "unknown";
76 } 76 }
77 77
78 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { 78 static std::string PermissionTypeToString(BrowserPluginPermissionType type) {
79 switch (type) { 79 switch (type) {
80 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 80 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
81 return webview::kPermissionTypeNewWindow; 81 return webview::kPermissionTypeNewWindow;
82 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
83 return webview::kPermissionTypePointerLock;
84 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 82 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
85 return webview::kPermissionTypeDialog; 83 return webview::kPermissionTypeDialog;
86 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 84 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
87 NOTREACHED(); 85 NOTREACHED();
88 break; 86 break;
89 default: { 87 default: {
90 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); 88 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type);
91 switch (webview) { 89 switch (webview) {
92 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 90 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
93 return webview::kPermissionTypeDownload; 91 return webview::kPermissionTypeDownload;
94 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 92 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
95 return webview::kPermissionTypeGeolocation; 93 return webview::kPermissionTypeGeolocation;
96 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 94 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
97 return webview::kPermissionTypeLoadPlugin; 95 return webview::kPermissionTypeLoadPlugin;
98 case WEB_VIEW_PERMISSION_TYPE_MEDIA: 96 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
99 return webview::kPermissionTypeMedia; 97 return webview::kPermissionTypeMedia;
98 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
99 return webview::kPermissionTypePointerLock;
100 } 100 }
101 NOTREACHED(); 101 NOTREACHED();
102 } 102 }
103 } 103 }
104 return std::string(); 104 return std::string();
105 } 105 }
106 106
107 void RemoveWebViewEventListenersOnIOThread( 107 void RemoveWebViewEventListenersOnIOThread(
108 void* profile, 108 void* profile,
109 const std::string& extension_id, 109 const std::string& extension_id,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 // static 187 // static
188 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, 188 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info,
189 bool allow) { 189 bool allow) {
190 if (allow) { 190 if (allow) {
191 // Note that |allow| == true means the embedder explicitly allowed the 191 // Note that |allow| == true means the embedder explicitly allowed the
192 // request. For some requests they might still fail. An example of such 192 // request. For some requests they might still fail. An example of such
193 // scenario would be: an embedder allows geolocation request but doesn't 193 // scenario would be: an embedder allows geolocation request but doesn't
194 // have geolocation access on its own. 194 // have geolocation access on its own.
195 switch (info.permission_type) { 195 switch (info.permission_type) {
196 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
197 content::RecordAction(
198 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock"));
199 break;
200 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 196 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
201 content::RecordAction( 197 content::RecordAction(
202 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); 198 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow"));
203 break; 199 break;
204 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 200 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
205 content::RecordAction( 201 content::RecordAction(
206 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); 202 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog"));
207 break; 203 break;
208 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 204 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
209 break; 205 break;
210 default: { 206 default: {
211 WebViewPermissionType webview_permission_type = 207 WebViewPermissionType webview_permission_type =
212 static_cast<WebViewPermissionType>(info.permission_type); 208 static_cast<WebViewPermissionType>(info.permission_type);
213 switch (webview_permission_type) { 209 switch (webview_permission_type) {
210 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
211 content::RecordAction(
212 UserMetricsAction("WebView.PermissionAllow.Download"));
213 break;
214 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 214 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
215 content::RecordAction( 215 content::RecordAction(
216 UserMetricsAction("WebView.PermissionAllow.Geolocation")); 216 UserMetricsAction("WebView.PermissionAllow.Geolocation"));
217 break; 217 break;
218 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 218 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
219 content::RecordAction( 219 content::RecordAction(
220 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); 220 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad"));
221 case WEB_VIEW_PERMISSION_TYPE_MEDIA: 221 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
222 content::RecordAction( 222 content::RecordAction(
223 UserMetricsAction("WebView.PermissionAllow.Media")); 223 UserMetricsAction("WebView.PermissionAllow.Media"));
224 break; 224 break;
225 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 225 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
226 content::RecordAction( 226 content::RecordAction(
227 UserMetricsAction("WebView.PermissionAllow.Download")); 227 UserMetricsAction("WebView.PermissionAllow.PointerLock"));
228 break; 228 break;
229 default: 229 default:
230 break; 230 break;
231 } 231 }
232 } 232 }
233 } 233 }
234 } else { 234 } else {
235 switch (info.permission_type) { 235 switch (info.permission_type) {
236 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
237 content::RecordAction(
238 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock"));
239 break;
240 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 236 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
241 content::RecordAction( 237 content::RecordAction(
242 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); 238 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow"));
243 break; 239 break;
244 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 240 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
245 content::RecordAction( 241 content::RecordAction(
246 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); 242 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog"));
247 break; 243 break;
248 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 244 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
249 break; 245 break;
250 default: { 246 default: {
251 WebViewPermissionType webview_permission_type = 247 WebViewPermissionType webview_permission_type =
252 static_cast<WebViewPermissionType>(info.permission_type); 248 static_cast<WebViewPermissionType>(info.permission_type);
253 switch (webview_permission_type) { 249 switch (webview_permission_type) {
250 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
251 content::RecordAction(
252 UserMetricsAction("WebView.PermissionDeny.Download"));
253 break;
254 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 254 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
255 content::RecordAction( 255 content::RecordAction(
256 UserMetricsAction("WebView.PermissionDeny.Geolocation")); 256 UserMetricsAction("WebView.PermissionDeny.Geolocation"));
257 break; 257 break;
258 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 258 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
259 content::RecordAction( 259 content::RecordAction(
260 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); 260 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad"));
261 case WEB_VIEW_PERMISSION_TYPE_MEDIA: 261 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
262 content::RecordAction( 262 content::RecordAction(
263 UserMetricsAction("WebView.PermissionDeny.Media")); 263 UserMetricsAction("WebView.PermissionDeny.Media"));
264 break; 264 break;
265 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 265 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
266 content::RecordAction( 266 content::RecordAction(
267 UserMetricsAction("WebView.PermissionDeny.Download")); 267 UserMetricsAction("WebView.PermissionDeny.PointerLock"));
268 break; 268 break;
269 default: 269 default:
270 break; 270 break;
271 } 271 }
272 } 272 }
273 } 273 }
274 } 274 }
275 } 275 }
276 276
277 void WebViewGuest::Attach(WebContents* embedder_web_contents, 277 void WebViewGuest::Attach(WebContents* embedder_web_contents,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 RequestMediaAccessPermission(embedder_web_contents(), request, callback); 609 RequestMediaAccessPermission(embedder_web_contents(), request, callback);
610 } 610 }
611 611
612 void WebViewGuest::OnWebViewDownloadPermissionResponse( 612 void WebViewGuest::OnWebViewDownloadPermissionResponse(
613 const base::Callback<void(bool)>& callback, 613 const base::Callback<void(bool)>& callback,
614 bool allow, 614 bool allow,
615 const std::string& user_input) { 615 const std::string& user_input) {
616 callback.Run(allow && attached()); 616 callback.Run(allow && attached());
617 } 617 }
618 618
619 void WebViewGuest::OnWebViewPointerLockPermissionResponse(
620 const base::Callback<void(bool)>& callback,
621 bool allow,
622 const std::string& user_input) {
623 callback.Run(allow && attached());
624 }
625
619 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( 626 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission(
620 int request_id, 627 int request_id,
621 PermissionResponseAction action, 628 PermissionResponseAction action,
622 const std::string& user_input) { 629 const std::string& user_input) {
623 RequestMap::iterator request_itr = 630 RequestMap::iterator request_itr =
624 pending_permission_requests_.find(request_id); 631 pending_permission_requests_.find(request_id);
625 632
626 if (request_itr == pending_permission_requests_.end()) 633 if (request_itr == pending_permission_requests_.end())
627 return SET_PERMISSION_INVALID; 634 return SET_PERMISSION_INVALID;
628 635
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 RequestPermission( 896 RequestPermission(
890 static_cast<BrowserPluginPermissionType>( 897 static_cast<BrowserPluginPermissionType>(
891 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD), 898 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD),
892 request_info, 899 request_info,
893 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, 900 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse,
894 base::Unretained(this), 901 base::Unretained(this),
895 callback), 902 callback),
896 false /* allowed_by_default */); 903 false /* allowed_by_default */);
897 } 904 }
898 905
906 void WebViewGuest::RequestPointerLockPermission(
907 bool user_gesture,
908 bool last_unlocked_by_target,
909 const base::Callback<void(bool)>& callback) {
910 base::DictionaryValue request_info;
911 request_info.Set(guestview::kUserGesture,
912 base::Value::CreateBooleanValue(user_gesture));
913 request_info.Set(webview::kLastUnlockedBySelf,
914 base::Value::CreateBooleanValue(last_unlocked_by_target));
915 request_info.Set(guestview::kUrl,
916 base::Value::CreateStringValue(
917 guest_web_contents()->GetLastCommittedURL().spec()));
918
919 RequestPermission(
920 static_cast<BrowserPluginPermissionType>(
921 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK),
922 request_info,
923 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse,
924 base::Unretained(this),
925 callback),
926 false /* allowed_by_default */);
927 }
928
899 #if defined(OS_CHROMEOS) 929 #if defined(OS_CHROMEOS)
900 void WebViewGuest::OnAccessibilityStatusChanged( 930 void WebViewGuest::OnAccessibilityStatusChanged(
901 const chromeos::AccessibilityStatusEventDetails& details) { 931 const chromeos::AccessibilityStatusEventDetails& details) {
902 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) { 932 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) {
903 accessibility_subscription_.reset(); 933 accessibility_subscription_.reset();
904 } else if (details.notification_type == 934 } else if (details.notification_type ==
905 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { 935 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) {
906 if (details.enabled) 936 if (details.enabled)
907 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); 937 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost());
908 else 938 else
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 const PermissionResponseCallback& callback, 1023 const PermissionResponseCallback& callback,
994 BrowserPluginPermissionType permission_type, 1024 BrowserPluginPermissionType permission_type,
995 bool allowed_by_default) 1025 bool allowed_by_default)
996 : callback(callback), 1026 : callback(callback),
997 permission_type(permission_type), 1027 permission_type(permission_type),
998 allowed_by_default(allowed_by_default) { 1028 allowed_by_default(allowed_by_default) {
999 } 1029 }
1000 1030
1001 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { 1031 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
1002 } 1032 }
OLDNEW
« no previous file with comments | « chrome/browser/guestview/webview/webview_guest.h ('k') | chrome/browser/guestview/webview/webview_permission_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698