OLD | NEW |
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/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
10 #include "chrome/browser/extensions/api/webview/webview_api.h" | 11 #include "chrome/browser/extensions/api/webview/webview_api.h" |
11 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 12 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
12 #include "chrome/browser/extensions/extension_renderer_state.h" | 13 #include "chrome/browser/extensions/extension_renderer_state.h" |
13 #include "chrome/browser/extensions/menu_manager.h" | 14 #include "chrome/browser/extensions/menu_manager.h" |
14 #include "chrome/browser/extensions/script_executor.h" | 15 #include "chrome/browser/extensions/script_executor.h" |
15 #include "chrome/browser/favicon/favicon_tab_helper.h" | 16 #include "chrome/browser/favicon/favicon_tab_helper.h" |
16 #include "chrome/browser/guestview/guestview_constants.h" | 17 #include "chrome/browser/guestview/guestview_constants.h" |
17 #include "chrome/browser/guestview/webview/webview_constants.h" | 18 #include "chrome/browser/guestview/webview/webview_constants.h" |
18 #include "chrome/browser/guestview/webview/webview_permission_types.h" | 19 #include "chrome/browser/guestview/webview/webview_permission_types.h" |
19 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/geolocation_permission_context.h" |
21 #include "content/public/browser/native_web_keyboard_event.h" | 23 #include "content/public/browser/native_web_keyboard_event.h" |
22 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/resource_request_details.h" | 30 #include "content/public/browser/resource_request_details.h" |
29 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
30 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 break; | 70 break; |
69 } | 71 } |
70 NOTREACHED() << "Unknown Termination Status."; | 72 NOTREACHED() << "Unknown Termination Status."; |
71 return "unknown"; | 73 return "unknown"; |
72 } | 74 } |
73 | 75 |
74 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { | 76 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { |
75 switch (type) { | 77 switch (type) { |
76 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 78 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
77 return webview::kPermissionTypeDownload; | 79 return webview::kPermissionTypeDownload; |
78 case BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION: | |
79 return webview::kPermissionTypeGeolocation; | |
80 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | 80 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: |
81 return webview::kPermissionTypeMedia; | 81 return webview::kPermissionTypeMedia; |
82 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 82 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
83 return webview::kPermissionTypeNewWindow; | 83 return webview::kPermissionTypeNewWindow; |
84 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 84 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
85 return webview::kPermissionTypePointerLock; | 85 return webview::kPermissionTypePointerLock; |
86 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 86 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
87 return webview::kPermissionTypeDialog; | 87 return webview::kPermissionTypeDialog; |
88 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 88 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 break; | 90 break; |
91 default: { | 91 default: { |
92 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); | 92 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); |
93 switch (webview) { | 93 switch (webview) { |
| 94 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 95 return webview::kPermissionTypeGeolocation; |
94 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 96 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
95 return webview::kPermissionTypeLoadPlugin; | 97 return webview::kPermissionTypeLoadPlugin; |
96 } | 98 } |
97 NOTREACHED(); | 99 NOTREACHED(); |
98 } | 100 } |
99 } | 101 } |
100 return std::string(); | 102 return std::string(); |
101 } | 103 } |
102 | 104 |
103 void RemoveWebViewEventListenersOnIOThread( | 105 void RemoveWebViewEventListenersOnIOThread( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (allow) { | 188 if (allow) { |
187 // Note that |allow| == true means the embedder explicitly allowed the | 189 // Note that |allow| == true means the embedder explicitly allowed the |
188 // request. For some requests they might still fail. An example of such | 190 // request. For some requests they might still fail. An example of such |
189 // scenario would be: an embedder allows geolocation request but doesn't | 191 // scenario would be: an embedder allows geolocation request but doesn't |
190 // have geolocation access on its own. | 192 // have geolocation access on its own. |
191 switch (info.permission_type) { | 193 switch (info.permission_type) { |
192 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 194 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
193 content::RecordAction( | 195 content::RecordAction( |
194 UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); | 196 UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); |
195 break; | 197 break; |
196 case BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION: | |
197 content::RecordAction( | |
198 UserMetricsAction("BrowserPlugin.PermissionAllow.Geolocation")); | |
199 break; | |
200 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | 198 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: |
201 content::RecordAction( | 199 content::RecordAction( |
202 UserMetricsAction("BrowserPlugin.PermissionAllow.Media")); | 200 UserMetricsAction("BrowserPlugin.PermissionAllow.Media")); |
203 break; | 201 break; |
204 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 202 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
205 content::RecordAction( | 203 content::RecordAction( |
206 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); | 204 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); |
207 break; | 205 break; |
208 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 206 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
209 content::RecordAction( | 207 content::RecordAction( |
210 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | 208 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); |
211 break; | 209 break; |
212 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 210 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
213 content::RecordAction( | 211 content::RecordAction( |
214 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); | 212 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); |
215 break; | 213 break; |
216 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 214 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
217 break; | 215 break; |
218 default: { | 216 default: { |
219 WebViewPermissionType webview_permission_type = | 217 WebViewPermissionType webview_permission_type = |
220 static_cast<WebViewPermissionType>(info.permission_type); | 218 static_cast<WebViewPermissionType>(info.permission_type); |
221 switch (webview_permission_type) { | 219 switch (webview_permission_type) { |
| 220 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 221 content::RecordAction( |
| 222 UserMetricsAction("WebView.PermissionAllow.Geolocation")); |
| 223 break; |
222 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 224 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
223 content::RecordAction( | 225 content::RecordAction( |
224 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); | 226 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); |
225 break; | 227 break; |
226 default: | 228 default: |
227 break; | 229 break; |
228 } | 230 } |
229 } | 231 } |
230 } | 232 } |
231 } else { | 233 } else { |
232 switch (info.permission_type) { | 234 switch (info.permission_type) { |
233 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 235 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
234 content::RecordAction( | 236 content::RecordAction( |
235 UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); | 237 UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); |
236 break; | 238 break; |
237 case BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION: | |
238 content::RecordAction( | |
239 UserMetricsAction("BrowserPlugin.PermissionDeny.Geolocation")); | |
240 break; | |
241 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | 239 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: |
242 content::RecordAction( | 240 content::RecordAction( |
243 UserMetricsAction("BrowserPlugin.PermissionDeny.Media")); | 241 UserMetricsAction("BrowserPlugin.PermissionDeny.Media")); |
244 break; | 242 break; |
245 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 243 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
246 content::RecordAction( | 244 content::RecordAction( |
247 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); | 245 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); |
248 break; | 246 break; |
249 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 247 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
250 content::RecordAction( | 248 content::RecordAction( |
251 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | 249 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); |
252 break; | 250 break; |
253 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 251 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
254 content::RecordAction( | 252 content::RecordAction( |
255 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); | 253 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); |
256 break; | 254 break; |
257 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 255 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
258 break; | 256 break; |
259 default: { | 257 default: { |
260 WebViewPermissionType webview_permission_type = | 258 WebViewPermissionType webview_permission_type = |
261 static_cast<WebViewPermissionType>(info.permission_type); | 259 static_cast<WebViewPermissionType>(info.permission_type); |
262 switch (webview_permission_type) { | 260 switch (webview_permission_type) { |
| 261 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 262 content::RecordAction( |
| 263 UserMetricsAction("WebView.PermissionDeny.Geolocation")); |
| 264 break; |
263 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 265 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
264 content::RecordAction( | 266 content::RecordAction( |
265 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); | 267 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); |
266 break; | 268 break; |
267 default: | 269 default: |
268 break; | 270 break; |
269 } | 271 } |
270 } | 272 } |
271 } | 273 } |
272 } | 274 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); | 432 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); |
431 } | 433 } |
432 | 434 |
433 void WebViewGuest::RendererUnresponsive() { | 435 void WebViewGuest::RendererUnresponsive() { |
434 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 436 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
435 args->SetInteger(webview::kProcessId, | 437 args->SetInteger(webview::kProcessId, |
436 guest_web_contents()->GetRenderProcessHost()->GetID()); | 438 guest_web_contents()->GetRenderProcessHost()->GetID()); |
437 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); | 439 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); |
438 } | 440 } |
439 | 441 |
440 bool WebViewGuest::RequestPermission( | 442 void WebViewGuest::RequestPermission( |
441 BrowserPluginPermissionType permission_type, | 443 BrowserPluginPermissionType permission_type, |
442 const base::DictionaryValue& request_info, | 444 const base::DictionaryValue& request_info, |
443 const PermissionResponseCallback& callback, | 445 const PermissionResponseCallback& callback, |
444 bool allowed_by_default) { | 446 bool allowed_by_default) { |
445 // If there are too many pending permission requests then reject this request. | 447 RequestPermissionInternal(permission_type, |
446 if (pending_permission_requests_.size() >= | 448 request_info, |
447 webview::kMaxOutstandingPermissionRequests) { | 449 callback, |
448 callback.Run(false, std::string()); | 450 allowed_by_default); |
449 return true; | |
450 } | |
451 | |
452 int request_id = next_permission_request_id_++; | |
453 pending_permission_requests_[request_id] = | |
454 PermissionResponseInfo(callback, permission_type, allowed_by_default); | |
455 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); | |
456 args->SetInteger(webview::kRequestId, request_id); | |
457 switch (permission_type) { | |
458 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { | |
459 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, | |
460 args.Pass())); | |
461 break; | |
462 } | |
463 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { | |
464 DispatchEvent(new GuestView::Event(webview::kEventDialog, | |
465 args.Pass())); | |
466 break; | |
467 } | |
468 default: { | |
469 args->SetString(webview::kPermission, | |
470 PermissionTypeToString(permission_type)); | |
471 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, | |
472 args.Pass())); | |
473 break; | |
474 } | |
475 } | |
476 return true; | |
477 } | 451 } |
478 | 452 |
479 void WebViewGuest::Observe(int type, | 453 void WebViewGuest::Observe(int type, |
480 const content::NotificationSource& source, | 454 const content::NotificationSource& source, |
481 const content::NotificationDetails& details) { | 455 const content::NotificationDetails& details) { |
482 switch (type) { | 456 switch (type) { |
483 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 457 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
484 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 458 DCHECK_EQ(content::Source<WebContents>(source).ptr(), |
485 guest_web_contents()); | 459 guest_web_contents()); |
486 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) | 460 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 guest_web_contents()->GetController().GoToOffset(relative_index); | 511 guest_web_contents()->GetController().GoToOffset(relative_index); |
538 } | 512 } |
539 | 513 |
540 void WebViewGuest::Reload() { | 514 void WebViewGuest::Reload() { |
541 // TODO(fsamuel): Don't check for repost because we don't want to show | 515 // TODO(fsamuel): Don't check for repost because we don't want to show |
542 // Chromium's repost warning. We might want to implement a separate API | 516 // Chromium's repost warning. We might want to implement a separate API |
543 // for registering a callback if a repost is about to happen. | 517 // for registering a callback if a repost is about to happen. |
544 guest_web_contents()->GetController().Reload(false); | 518 guest_web_contents()->GetController().Reload(false); |
545 } | 519 } |
546 | 520 |
| 521 |
| 522 void WebViewGuest::RequestGeolocationPermission( |
| 523 int bridge_id, |
| 524 const GURL& requesting_frame, |
| 525 bool user_gesture, |
| 526 const base::Callback<void(bool)>& callback) { |
| 527 base::DictionaryValue request_info; |
| 528 request_info.Set(guestview::kUrl, |
| 529 base::Value::CreateStringValue(requesting_frame.spec())); |
| 530 request_info.Set(guestview::kUserGesture, |
| 531 base::Value::CreateBooleanValue(user_gesture)); |
| 532 |
| 533 // It is safe to hold an unretained pointer to WebViewGuest because this |
| 534 // callback is called from WebViewGuest::SetPermission. |
| 535 const PermissionResponseCallback permission_callback = |
| 536 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse, |
| 537 base::Unretained(this), |
| 538 bridge_id, |
| 539 user_gesture, |
| 540 callback); |
| 541 int request_id = RequestPermissionInternal( |
| 542 static_cast<BrowserPluginPermissionType>( |
| 543 WEB_VIEW_PERMISSION_TYPE_GEOLOCATION), |
| 544 request_info, |
| 545 permission_callback, |
| 546 false /* allowed_by_default */); |
| 547 bridge_id_to_request_id_map_[bridge_id] = request_id; |
| 548 } |
| 549 |
| 550 void WebViewGuest::OnWebViewGeolocationPermissionResponse( |
| 551 int bridge_id, |
| 552 bool user_gesture, |
| 553 const base::Callback<void(bool)>& callback, |
| 554 bool allow, |
| 555 const std::string& user_input) { |
| 556 // The <webview> embedder has allowed the permission. We now need to make sure |
| 557 // that the embedder has geolocation permission. |
| 558 RemoveBridgeID(bridge_id); |
| 559 |
| 560 if (!allow || !attached()) { |
| 561 callback.Run(false); |
| 562 return; |
| 563 } |
| 564 |
| 565 content::GeolocationPermissionContext* geolocation_context = |
| 566 browser_context()->GetGeolocationPermissionContext(); |
| 567 |
| 568 DCHECK(geolocation_context); |
| 569 geolocation_context->RequestGeolocationPermission( |
| 570 embedder_web_contents()->GetRenderProcessHost()->GetID(), |
| 571 embedder_web_contents()->GetRoutingID(), |
| 572 // The geolocation permission request here is not initiated |
| 573 // through WebGeolocationPermissionRequest. We are only interested |
| 574 // in the fact whether the embedder/app has geolocation |
| 575 // permission. Therefore we use an invalid |bridge_id|. |
| 576 -1 /* bridge_id */, |
| 577 embedder_web_contents()->GetLastCommittedURL(), |
| 578 user_gesture, |
| 579 callback); |
| 580 } |
| 581 |
| 582 void WebViewGuest::CancelGeolocationPermissionRequest(int bridge_id) { |
| 583 int request_id = RemoveBridgeID(bridge_id); |
| 584 RequestMap::iterator request_itr = |
| 585 pending_permission_requests_.find(request_id); |
| 586 |
| 587 if (request_itr == pending_permission_requests_.end()) |
| 588 return; |
| 589 |
| 590 pending_permission_requests_.erase(request_itr); |
| 591 } |
| 592 |
547 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( | 593 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( |
548 int request_id, | 594 int request_id, |
549 PermissionResponseAction action, | 595 PermissionResponseAction action, |
550 const std::string& user_input) { | 596 const std::string& user_input) { |
551 RequestMap::iterator request_itr = | 597 RequestMap::iterator request_itr = |
552 pending_permission_requests_.find(request_id); | 598 pending_permission_requests_.find(request_id); |
553 | 599 |
554 if (request_itr == pending_permission_requests_.end()) | 600 if (request_itr == pending_permission_requests_.end()) |
555 return SET_PERMISSION_INVALID; | 601 return SET_PERMISSION_INVALID; |
556 | 602 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 chromeos::AccessibilityManager* manager = | 857 chromeos::AccessibilityManager* manager = |
812 chromeos::AccessibilityManager::Get(); | 858 chromeos::AccessibilityManager::Get(); |
813 if (manager && manager->IsSpokenFeedbackEnabled()) { | 859 if (manager && manager->IsSpokenFeedbackEnabled()) { |
814 manager->InjectChromeVox(render_view_host); | 860 manager->InjectChromeVox(render_view_host); |
815 chromevox_injected_ = true; | 861 chromevox_injected_ = true; |
816 } | 862 } |
817 } | 863 } |
818 #endif | 864 #endif |
819 } | 865 } |
820 | 866 |
| 867 int WebViewGuest::RemoveBridgeID(int bridge_id) { |
| 868 std::map<int, int>::iterator bridge_itr = |
| 869 bridge_id_to_request_id_map_.find(bridge_id); |
| 870 if (bridge_itr == bridge_id_to_request_id_map_.end()) |
| 871 return webview::kInvalidPermissionRequestID; |
| 872 |
| 873 int request_id = bridge_itr->second; |
| 874 bridge_id_to_request_id_map_.erase(bridge_itr); |
| 875 return request_id; |
| 876 } |
| 877 |
| 878 int WebViewGuest::RequestPermissionInternal( |
| 879 BrowserPluginPermissionType permission_type, |
| 880 const base::DictionaryValue& request_info, |
| 881 const PermissionResponseCallback& callback, |
| 882 bool allowed_by_default) { |
| 883 // If there are too many pending permission requests then reject this request. |
| 884 if (pending_permission_requests_.size() >= |
| 885 webview::kMaxOutstandingPermissionRequests) { |
| 886 // Let the stack unwind before we deny the permission request so that |
| 887 // objects held by the permission request are not destroyed immediately |
| 888 // after creation. This is to allow those same objects to be accessed again |
| 889 // in the same scope without fear of use after freeing. |
| 890 base::MessageLoop::current()->PostTask( |
| 891 FROM_HERE, |
| 892 base::Bind(&PermissionResponseCallback::Run, |
| 893 base::Owned(new PermissionResponseCallback(callback)), |
| 894 allowed_by_default, |
| 895 std::string())); |
| 896 return webview::kInvalidPermissionRequestID; |
| 897 } |
| 898 |
| 899 int request_id = next_permission_request_id_++; |
| 900 pending_permission_requests_[request_id] = |
| 901 PermissionResponseInfo(callback, permission_type, allowed_by_default); |
| 902 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); |
| 903 args->SetInteger(webview::kRequestId, request_id); |
| 904 switch (permission_type) { |
| 905 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { |
| 906 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, |
| 907 args.Pass())); |
| 908 break; |
| 909 } |
| 910 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { |
| 911 DispatchEvent(new GuestView::Event(webview::kEventDialog, |
| 912 args.Pass())); |
| 913 break; |
| 914 } |
| 915 default: { |
| 916 args->SetString(webview::kPermission, |
| 917 PermissionTypeToString(permission_type)); |
| 918 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, |
| 919 args.Pass())); |
| 920 break; |
| 921 } |
| 922 } |
| 923 return request_id; |
| 924 } |
| 925 |
821 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() | 926 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() |
822 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), | 927 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), |
823 allowed_by_default(false) { | 928 allowed_by_default(false) { |
824 } | 929 } |
825 | 930 |
826 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( | 931 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( |
827 const PermissionResponseCallback& callback, | 932 const PermissionResponseCallback& callback, |
828 BrowserPluginPermissionType permission_type, | 933 BrowserPluginPermissionType permission_type, |
829 bool allowed_by_default) | 934 bool allowed_by_default) |
830 : callback(callback), | 935 : callback(callback), |
831 permission_type(permission_type), | 936 permission_type(permission_type), |
832 allowed_by_default(allowed_by_default) { | 937 allowed_by_default(allowed_by_default) { |
833 } | 938 } |
834 | 939 |
835 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 940 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
836 } | 941 } |
OLD | NEW |