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 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | |
6 | |
7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
8 #include "chrome/browser/geolocation/geolocation_permission_context.h" | |
9 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | |
10 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | |
11 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | |
12 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | |
13 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/common/render_messages.h" | |
16 #include "content/public/browser/render_process_host.h" | |
17 #include "content/public/browser/render_view_host.h" | |
18 #include "content/public/browser/user_metrics.h" | |
19 | |
20 using content::BrowserPluginGuestDelegate; | |
21 using content::RenderViewHost; | |
22 using content::WebContents; | |
23 | |
24 namespace { | |
25 static std::string PermissionTypeToString(WebViewPermissionType type) { | |
26 switch (type) { | |
27 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
28 return webview::kPermissionTypeDownload; | |
29 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
30 return webview::kPermissionTypeFileSystem; | |
31 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
32 return webview::kPermissionTypeGeolocation; | |
33 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
34 return webview::kPermissionTypeDialog; | |
35 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
36 return webview::kPermissionTypeLoadPlugin; | |
37 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
38 return webview::kPermissionTypeMedia; | |
39 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
40 return webview::kPermissionTypeNewWindow; | |
41 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
42 return webview::kPermissionTypePointerLock; | |
43 default: | |
44 NOTREACHED(); | |
45 return std::string(); | |
46 } | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 DEFINE_WEB_CONTENTS_USER_DATA_KEY(WebViewPermissionHelper); | |
Fady Samuel
2014/06/20 22:54:33
Don't make this WebContentsUserData. This makes li
Xi Han
2014/06/24 13:55:32
Done.
| |
52 | |
53 WebViewPermissionHelper::WebViewPermissionHelper( | |
54 content::WebContents* web_contents) | |
55 : content::WebContentsObserver(web_contents), | |
56 weak_factory_(this), | |
57 next_permission_request_id_(0), | |
58 web_view_guest_(WebViewGuest::FromWebContents(web_contents)) { | |
Fady Samuel
2014/06/20 22:54:33
Pass this in as a raw pointer from WebViewGuest.
Xi Han
2014/06/24 13:55:32
Done.
| |
59 } | |
60 | |
61 WebViewPermissionHelper::~WebViewPermissionHelper() { | |
62 } | |
63 | |
64 #if defined(ENABLE_PLUGINS) | |
65 bool WebViewPermissionHelper::OnMessageReceived( | |
66 const IPC::Message& message, | |
67 content::RenderFrameHost* render_frame_host) { | |
68 IPC_BEGIN_MESSAGE_MAP(WebViewPermissionHelper, message) | |
69 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, | |
70 OnBlockedOutdatedPlugin) | |
71 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin, | |
72 OnBlockedUnauthorizedPlugin) | |
73 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_NPAPINotSupported, | |
74 OnNPAPINotSupported) | |
75 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
76 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin, | |
77 OnFindMissingPlugin) | |
78 #endif | |
79 IPC_MESSAGE_UNHANDLED(return false) | |
80 IPC_END_MESSAGE_MAP() | |
81 | |
82 return true; | |
83 } | |
84 | |
85 bool WebViewPermissionHelper::OnMessageReceived(const IPC::Message& message) { | |
86 IPC_BEGIN_MESSAGE_MAP(WebViewPermissionHelper, message) | |
87 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, | |
88 OnCouldNotLoadPlugin) | |
89 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, | |
90 OnOpenAboutPlugins) | |
91 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
92 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, | |
93 OnRemovePluginPlaceholderHost) | |
94 #endif | |
95 IPC_MESSAGE_UNHANDLED(return false) | |
96 IPC_END_MESSAGE_MAP() | |
97 | |
98 return true; | |
99 } | |
100 | |
101 void WebViewPermissionHelper::OnBlockedUnauthorizedPlugin( | |
102 const base::string16& name, | |
103 const std::string& identifier) { | |
104 const char kPluginName[] = "name"; | |
105 const char kPluginIdentifier[] = "identifier"; | |
106 | |
107 base::DictionaryValue info; | |
108 info.SetString(std::string(kPluginName), name); | |
109 info.SetString(std::string(kPluginIdentifier), identifier); | |
110 RequestPermission( | |
111 WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN, | |
112 info, | |
113 base::Bind(&WebViewPermissionHelper::OnPermissionResponse, | |
114 weak_factory_.GetWeakPtr(), | |
115 identifier), | |
116 true /* allowed_by_default */); | |
117 content::RecordAction( | |
118 base::UserMetricsAction("WebView.Guest.PluginLoadRequest")); | |
119 } | |
120 | |
121 void WebViewPermissionHelper::OnCouldNotLoadPlugin( | |
122 const base::FilePath& plugin_path) { | |
123 } | |
124 | |
125 void WebViewPermissionHelper::OnBlockedOutdatedPlugin( | |
126 int placeholder_id, | |
127 const std::string& identifier) { | |
128 } | |
129 | |
130 void WebViewPermissionHelper::OnNPAPINotSupported(const std::string& id) { | |
131 } | |
132 | |
133 void WebViewPermissionHelper::OnOpenAboutPlugins() { | |
134 } | |
135 | |
136 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
137 void WebViewPermissionHelper::OnFindMissingPlugin( | |
138 int placeholder_id, | |
139 const std::string& mime_type) { | |
140 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); | |
141 } | |
142 | |
143 void WebViewPermissionHelper::OnRemovePluginPlaceholderHost( | |
144 int placeholder_id) { | |
145 } | |
146 #endif // defined(ENABLE_PLUGIN_INSTALLATION) | |
147 | |
148 void WebViewPermissionHelper::OnPermissionResponse( | |
149 const std::string& identifier, | |
150 bool allow, | |
151 const std::string& input) { | |
152 if (allow) { | |
153 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | |
154 web_contents(), true, identifier); | |
155 } | |
156 } | |
157 | |
158 #endif // defined(ENABLE_PLUGINS) | |
159 | |
160 // static | |
161 void WebViewPermissionHelper::RecordUserInitiatedUMA( | |
Fady Samuel
2014/06/20 22:54:33
This doesn't need to be public. You can probably p
Xi Han
2014/06/24 13:55:32
Done.
| |
162 const PermissionResponseInfo& info, | |
163 bool allow) { | |
164 if (allow) { | |
165 // Note that |allow| == true means the embedder explicitly allowed the | |
166 // request. For some requests they might still fail. An example of such | |
167 // scenario would be: an embedder allows geolocation request but doesn't | |
168 // have geolocation access on its own. | |
169 switch (info.permission_type) { | |
170 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
171 content::RecordAction( | |
172 UserMetricsAction("WebView.PermissionAllow.Download")); | |
173 break; | |
174 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
175 content::RecordAction( | |
176 UserMetricsAction("WebView.PermissionAllow.FileSystem")); | |
177 break; | |
178 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
179 content::RecordAction( | |
180 UserMetricsAction("WebView.PermissionAllow.Geolocation")); | |
181 break; | |
182 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
183 content::RecordAction( | |
184 UserMetricsAction("WebView.PermissionAllow.JSDialog")); | |
185 break; | |
186 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
187 content::RecordAction( | |
188 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); | |
189 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
190 content::RecordAction( | |
191 UserMetricsAction("WebView.PermissionAllow.Media")); | |
192 break; | |
193 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
194 content::RecordAction( | |
195 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | |
196 break; | |
197 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
198 content::RecordAction( | |
199 UserMetricsAction("WebView.PermissionAllow.PointerLock")); | |
200 break; | |
201 default: | |
202 break; | |
203 } | |
204 } else { | |
205 switch (info.permission_type) { | |
206 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
207 content::RecordAction( | |
208 UserMetricsAction("WebView.PermissionDeny.Download")); | |
209 break; | |
210 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
211 content::RecordAction( | |
212 UserMetricsAction("WebView.PermissionDeny.FileSystem")); | |
213 break; | |
214 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
215 content::RecordAction( | |
216 UserMetricsAction("WebView.PermissionDeny.Geolocation")); | |
217 break; | |
218 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
219 content::RecordAction( | |
220 UserMetricsAction("WebView.PermissionDeny.JSDialog")); | |
221 break; | |
222 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
223 content::RecordAction( | |
224 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); | |
225 break; | |
226 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
227 content::RecordAction( | |
228 UserMetricsAction("WebView.PermissionDeny.Media")); | |
229 break; | |
230 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
231 content::RecordAction( | |
232 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | |
233 break; | |
234 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
235 content::RecordAction( | |
236 UserMetricsAction("WebView.PermissionDeny.PointerLock")); | |
237 break; | |
238 default: | |
239 break; | |
240 } | |
241 } | |
242 } | |
243 | |
244 void WebViewPermissionHelper::RequestMediaAccessPermission( | |
245 content::WebContents* source, | |
246 const content::MediaStreamRequest& request, | |
247 const content::MediaResponseCallback& callback) { | |
248 base::DictionaryValue request_info; | |
249 request_info.Set( | |
250 guestview::kUrl, | |
251 base::Value::CreateStringValue(request.security_origin.spec())); | |
252 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | |
253 request_info, | |
254 base::Bind(&WebViewPermissionHelper:: | |
255 OnWebViewMediaPermissionResponse, | |
256 base::Unretained(this), | |
257 request, | |
258 callback), | |
259 false /* allowed_by_default */); | |
260 } | |
261 | |
262 void WebViewPermissionHelper::OnWebViewMediaPermissionResponse( | |
Fady Samuel
2014/06/20 22:54:33
Replace all instances of OnWebView* to On*
Xi Han
2014/06/24 13:55:32
Done.
| |
263 const content::MediaStreamRequest& request, | |
264 const content::MediaResponseCallback& callback, | |
265 bool allow, | |
266 const std::string& user_input) { | |
267 if (!allow || !web_view_guest_->attached()) { | |
268 // Deny the request. | |
269 callback.Run(content::MediaStreamDevices(), | |
270 content::MEDIA_DEVICE_INVALID_STATE, | |
271 scoped_ptr<content::MediaStreamUI>()); | |
272 return; | |
273 } | |
274 if (!web_view_guest_->embedder_web_contents()->GetDelegate()) | |
275 return; | |
276 | |
277 web_view_guest_->embedder_web_contents()->GetDelegate()-> | |
278 RequestMediaAccessPermission(web_view_guest_->embedder_web_contents(), | |
279 request, | |
280 callback); | |
281 } | |
282 | |
283 void WebViewPermissionHelper::CanDownload( | |
284 content::RenderViewHost* render_view_host, | |
285 const GURL& url, | |
286 const std::string& request_method, | |
287 const base::Callback<void(bool)>& callback) { | |
288 base::DictionaryValue request_info; | |
289 request_info.Set( | |
290 guestview::kUrl, | |
291 base::Value::CreateStringValue(url.spec())); | |
292 RequestPermission( | |
293 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | |
294 request_info, | |
295 base::Bind(&WebViewPermissionHelper::OnWebViewDownloadPermissionResponse, | |
296 base::Unretained(this), | |
297 callback), | |
298 false /* allowed_by_default */); | |
299 } | |
300 | |
301 void WebViewPermissionHelper::OnWebViewDownloadPermissionResponse( | |
302 const base::Callback<void(bool)>& callback, | |
303 bool allow, | |
304 const std::string& user_input) { | |
305 callback.Run(allow && web_view_guest_->attached()); | |
306 } | |
307 | |
308 void WebViewPermissionHelper::RequestPointerLockPermission( | |
309 bool user_gesture, | |
310 bool last_unlocked_by_target, | |
311 const base::Callback<void(bool)>& callback) { | |
312 base::DictionaryValue request_info; | |
313 request_info.Set(guestview::kUserGesture, | |
314 base::Value::CreateBooleanValue(user_gesture)); | |
315 request_info.Set(webview::kLastUnlockedBySelf, | |
316 base::Value::CreateBooleanValue(last_unlocked_by_target)); | |
317 request_info.Set(guestview::kUrl, | |
318 base::Value::CreateStringValue( | |
319 web_contents()->GetLastCommittedURL().spec())); | |
320 | |
321 RequestPermission( | |
322 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, | |
323 request_info, | |
324 base::Bind( | |
325 &WebViewPermissionHelper::OnWebViewPointerLockPermissionResponse, | |
326 base::Unretained(this), | |
327 callback), | |
328 false /* allowed_by_default */); | |
329 } | |
330 | |
331 void WebViewPermissionHelper::OnWebViewPointerLockPermissionResponse( | |
332 const base::Callback<void(bool)>& callback, | |
333 bool allow, | |
334 const std::string& user_input) { | |
335 callback.Run(allow && web_view_guest_->attached()); | |
336 } | |
337 | |
338 void WebViewPermissionHelper::RequestGeolocationPermission( | |
339 int bridge_id, | |
340 const GURL& requesting_frame, | |
341 bool user_gesture, | |
342 const base::Callback<void(bool)>& callback) { | |
343 base::DictionaryValue request_info; | |
344 request_info.Set(guestview::kUrl, | |
345 base::Value::CreateStringValue(requesting_frame.spec())); | |
346 request_info.Set(guestview::kUserGesture, | |
347 base::Value::CreateBooleanValue(user_gesture)); | |
348 | |
349 // It is safe to hold an unretained pointer to WebViewPermissionHelper because | |
350 // this callback is called from WebViewPermissionHelper::SetPermission. | |
351 const PermissionResponseCallback permission_callback = | |
352 base::Bind( | |
353 &WebViewPermissionHelper::OnWebViewGeolocationPermissionResponse, | |
354 base::Unretained(this), | |
355 bridge_id, | |
356 user_gesture, | |
357 callback); | |
358 int request_id = RequestPermission( | |
359 WEB_VIEW_PERMISSION_TYPE_GEOLOCATION, | |
360 request_info, | |
361 permission_callback, | |
362 false /* allowed_by_default */); | |
363 bridge_id_to_request_id_map_[bridge_id] = request_id; | |
364 } | |
365 | |
366 void WebViewPermissionHelper::OnWebViewGeolocationPermissionResponse( | |
367 int bridge_id, | |
368 bool user_gesture, | |
369 const base::Callback<void(bool)>& callback, | |
370 bool allow, | |
371 const std::string& user_input) { | |
372 // The <webview> embedder has allowed the permission. We now need to make sure | |
373 // that the embedder has geolocation permission. | |
374 RemoveBridgeID(bridge_id); | |
375 | |
376 if (!allow || !web_view_guest_->attached()) { | |
377 callback.Run(false); | |
378 return; | |
379 } | |
380 | |
381 Profile* profile = Profile::FromBrowserContext( | |
382 web_view_guest_->browser_context()); | |
383 GeolocationPermissionContextFactory::GetForProfile(profile)-> | |
384 RequestGeolocationPermission( | |
385 web_view_guest_->embedder_web_contents(), | |
386 // The geolocation permission request here is not initiated | |
387 // through WebGeolocationPermissionRequest. We are only interested | |
388 // in the fact whether the embedder/app has geolocation | |
389 // permission. Therefore we use an invalid |bridge_id|. | |
390 -1, | |
391 web_view_guest_->embedder_web_contents()->GetLastCommittedURL(), | |
392 user_gesture, | |
393 callback, | |
394 NULL); | |
395 } | |
396 | |
397 void WebViewPermissionHelper::CancelGeolocationPermissionRequest( | |
398 int bridge_id) { | |
399 int request_id = RemoveBridgeID(bridge_id); | |
400 RequestMap::iterator request_itr = | |
401 pending_permission_requests_.find(request_id); | |
402 | |
403 if (request_itr == pending_permission_requests_.end()) | |
404 return; | |
405 | |
406 pending_permission_requests_.erase(request_itr); | |
407 } | |
408 | |
409 int WebViewPermissionHelper::RemoveBridgeID(int bridge_id) { | |
410 std::map<int, int>::iterator bridge_itr = | |
411 bridge_id_to_request_id_map_.find(bridge_id); | |
412 if (bridge_itr == bridge_id_to_request_id_map_.end()) | |
413 return webview::kInvalidPermissionRequestID; | |
414 | |
415 int request_id = bridge_itr->second; | |
416 bridge_id_to_request_id_map_.erase(bridge_itr); | |
417 return request_id; | |
418 } | |
419 | |
420 void WebViewPermissionHelper::RequestFileSystemPermission( | |
421 const GURL& url, | |
422 bool allowed_by_default, | |
423 const base::Callback<void(bool)>& callback) { | |
424 base::DictionaryValue request_info; | |
425 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); | |
426 RequestPermission( | |
427 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, | |
428 request_info, | |
429 base::Bind( | |
430 &WebViewPermissionHelper::OnWebViewFileSystemPermissionResponse, | |
431 base::Unretained(this), | |
432 callback), | |
433 allowed_by_default); | |
434 } | |
435 | |
436 void WebViewPermissionHelper::OnWebViewFileSystemPermissionResponse( | |
437 const base::Callback<void(bool)>& callback, | |
438 bool allow, | |
439 const std::string& user_input) { | |
440 callback.Run(allow && web_view_guest_->attached()); | |
441 } | |
442 | |
443 void WebViewPermissionHelper::FileSystemAccessedAsync(int render_process_id, | |
444 int render_frame_id, | |
445 int request_id, | |
446 const GURL& url, | |
447 bool blocked_by_policy) { | |
448 RequestFileSystemPermission( | |
449 url, | |
450 !blocked_by_policy, | |
451 base::Bind(&WebViewPermissionHelper::FileSystemAccessedAsyncResponse, | |
452 base::Unretained(this), | |
453 render_process_id, | |
454 render_frame_id, | |
455 request_id, | |
456 url)); | |
457 } | |
458 | |
459 void WebViewPermissionHelper::FileSystemAccessedAsyncResponse( | |
460 int render_process_id, | |
461 int render_frame_id, | |
462 int request_id, | |
463 const GURL& url, | |
464 bool allowed) { | |
465 TabSpecificContentSettings::FileSystemAccessed( | |
466 render_process_id, render_frame_id, url, !allowed); | |
467 Send(new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( | |
468 render_frame_id, request_id, allowed)); | |
469 } | |
470 | |
471 void WebViewPermissionHelper::FileSystemAccessedSync(int render_process_id, | |
472 int render_frame_id, | |
473 const GURL& url, | |
474 bool blocked_by_policy, | |
475 IPC::Message* reply_msg) { | |
476 RequestFileSystemPermission( | |
477 url, | |
478 !blocked_by_policy, | |
479 base::Bind(&WebViewPermissionHelper::FileSystemAccessedSyncResponse, | |
480 base::Unretained(this), | |
481 render_process_id, | |
482 render_frame_id, | |
483 url, | |
484 reply_msg)); | |
485 } | |
486 | |
487 void WebViewPermissionHelper::FileSystemAccessedSyncResponse( | |
488 int render_process_id, | |
489 int render_frame_id, | |
490 const GURL& url, | |
491 IPC::Message* reply_msg, | |
492 bool allowed) { | |
493 TabSpecificContentSettings::FileSystemAccessed( | |
494 render_process_id, render_frame_id, url, !allowed); | |
495 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, | |
496 allowed); | |
497 Send(reply_msg); | |
498 } | |
499 | |
500 int WebViewPermissionHelper::RequestPermission( | |
501 WebViewPermissionType permission_type, | |
502 const base::DictionaryValue& request_info, | |
503 const PermissionResponseCallback& callback, | |
504 bool allowed_by_default) { | |
505 // If there are too many pending permission requests then reject this request. | |
506 if (pending_permission_requests_.size() >= | |
507 webview::kMaxOutstandingPermissionRequests) { | |
508 // Let the stack unwind before we deny the permission request so that | |
509 // objects held by the permission request are not destroyed immediately | |
510 // after creation. This is to allow those same objects to be accessed again | |
511 // in the same scope without fear of use after freeing. | |
512 base::MessageLoop::current()->PostTask( | |
513 FROM_HERE, | |
514 base::Bind(&PermissionResponseCallback::Run, | |
515 base::Owned(new PermissionResponseCallback(callback)), | |
516 allowed_by_default, | |
517 std::string())); | |
518 return webview::kInvalidPermissionRequestID; | |
519 } | |
520 | |
521 int request_id = next_permission_request_id_++; | |
522 pending_permission_requests_[request_id] = | |
523 PermissionResponseInfo(callback, permission_type, allowed_by_default); | |
524 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); | |
525 args->SetInteger(webview::kRequestId, request_id); | |
526 switch (permission_type) { | |
527 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: { | |
528 web_view_guest_->DispatchEvent( | |
529 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass())); | |
530 break; | |
531 } | |
532 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { | |
533 web_view_guest_->DispatchEvent( | |
534 new GuestViewBase::Event(webview::kEventDialog, args.Pass())); | |
535 break; | |
536 } | |
537 default: { | |
538 args->SetString(webview::kPermission, | |
539 PermissionTypeToString(permission_type)); | |
540 web_view_guest_->DispatchEvent(new GuestViewBase::Event( | |
541 webview::kEventPermissionRequest, | |
542 args.Pass())); | |
543 break; | |
544 } | |
545 } | |
546 return request_id; | |
547 } | |
548 | |
549 WebViewPermissionHelper::SetPermissionResult | |
550 WebViewPermissionHelper::SetPermission( | |
551 int request_id, | |
552 PermissionResponseAction action, | |
553 const std::string& user_input) { | |
554 RequestMap::iterator request_itr = | |
555 pending_permission_requests_.find(request_id); | |
556 | |
557 if (request_itr == pending_permission_requests_.end()) | |
558 return SET_PERMISSION_INVALID; | |
559 | |
560 const PermissionResponseInfo& info = request_itr->second; | |
561 bool allow = (action == ALLOW) || | |
562 ((action == DEFAULT) && info.allowed_by_default); | |
563 | |
564 info.callback.Run(allow, user_input); | |
565 | |
566 // Only record user initiated (i.e. non-default) actions. | |
567 if (action != DEFAULT) | |
568 RecordUserInitiatedUMA(info, allow); | |
569 | |
570 pending_permission_requests_.erase(request_itr); | |
571 | |
572 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; | |
573 } | |
574 | |
575 WebViewPermissionHelper::PermissionResponseInfo::PermissionResponseInfo() | |
576 : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN), | |
577 allowed_by_default(false) { | |
578 } | |
579 | |
580 WebViewPermissionHelper::PermissionResponseInfo::PermissionResponseInfo( | |
581 const PermissionResponseCallback& callback, | |
582 WebViewPermissionType permission_type, | |
583 bool allowed_by_default) | |
584 : callback(callback), | |
585 permission_type(permission_type), | |
586 allowed_by_default(allowed_by_default) { | |
587 } | |
588 | |
589 WebViewPermissionHelper::PermissionResponseInfo::~PermissionResponseInfo() { | |
590 } | |
OLD | NEW |