Chromium Code Reviews| 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/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 14 matching lines...) Expand all Loading... | |
| 25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/resource_request_details.h" | 30 #include "content/public/browser/resource_request_details.h" |
| 31 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
| 32 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
| 33 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/browser/web_contents_delegate.h" | |
| 36 #include "content/public/common/media_stream_request.h" | |
| 35 #include "content/public/common/page_zoom.h" | 37 #include "content/public/common/page_zoom.h" |
| 36 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
| 37 #include "content/public/common/stop_find_action.h" | 39 #include "content/public/common/stop_find_action.h" |
| 38 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
| 39 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 40 #include "third_party/WebKit/public/web/WebFindOptions.h" | 42 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 41 | 43 |
| 42 #if defined(ENABLE_PLUGINS) | 44 #if defined(ENABLE_PLUGINS) |
| 43 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" | 45 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" |
| 44 #endif | 46 #endif |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 70 break; | 72 break; |
| 71 } | 73 } |
| 72 NOTREACHED() << "Unknown Termination Status."; | 74 NOTREACHED() << "Unknown Termination Status."; |
| 73 return "unknown"; | 75 return "unknown"; |
| 74 } | 76 } |
| 75 | 77 |
| 76 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { | 78 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { |
| 77 switch (type) { | 79 switch (type) { |
| 78 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 80 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
| 79 return webview::kPermissionTypeDownload; | 81 return webview::kPermissionTypeDownload; |
| 80 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | |
| 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_LOAD_PLUGIN: | 94 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 95 return webview::kPermissionTypeLoadPlugin; | 95 return webview::kPermissionTypeLoadPlugin; |
| 96 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 96 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 97 return webview::kPermissionTypeGeolocation; | 97 return webview::kPermissionTypeGeolocation; |
| 98 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
|
lazyboy
2014/04/11 20:13:20
nit: sort the case-s, here and in other places + i
Fady Samuel
2014/04/11 21:52:31
Done.
| |
| 99 return webview::kPermissionTypeMedia; | |
| 98 } | 100 } |
| 99 NOTREACHED(); | 101 NOTREACHED(); |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 return std::string(); | 104 return std::string(); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void RemoveWebViewEventListenersOnIOThread( | 107 void RemoveWebViewEventListenersOnIOThread( |
| 106 void* profile, | 108 void* profile, |
| 107 const std::string& extension_id, | 109 const std::string& extension_id, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 if (allow) { | 190 if (allow) { |
| 189 // Note that |allow| == true means the embedder explicitly allowed the | 191 // Note that |allow| == true means the embedder explicitly allowed the |
| 190 // 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 |
| 191 // scenario would be: an embedder allows geolocation request but doesn't | 193 // scenario would be: an embedder allows geolocation request but doesn't |
| 192 // have geolocation access on its own. | 194 // have geolocation access on its own. |
| 193 switch (info.permission_type) { | 195 switch (info.permission_type) { |
| 194 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 196 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
| 195 content::RecordAction( | 197 content::RecordAction( |
| 196 UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); | 198 UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); |
| 197 break; | 199 break; |
| 198 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | |
| 199 content::RecordAction( | |
| 200 UserMetricsAction("BrowserPlugin.PermissionAllow.Media")); | |
| 201 break; | |
| 202 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 200 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
| 203 content::RecordAction( | 201 content::RecordAction( |
| 204 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); | 202 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); |
| 205 break; | 203 break; |
| 206 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 204 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
| 207 content::RecordAction( | 205 content::RecordAction( |
| 208 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | 206 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); |
| 209 break; | 207 break; |
| 210 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 208 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 211 content::RecordAction( | 209 content::RecordAction( |
| 212 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); | 210 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); |
| 213 break; | 211 break; |
| 214 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 212 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
| 215 break; | 213 break; |
| 216 default: { | 214 default: { |
| 217 WebViewPermissionType webview_permission_type = | 215 WebViewPermissionType webview_permission_type = |
| 218 static_cast<WebViewPermissionType>(info.permission_type); | 216 static_cast<WebViewPermissionType>(info.permission_type); |
| 219 switch (webview_permission_type) { | 217 switch (webview_permission_type) { |
| 220 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 218 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 221 content::RecordAction( | 219 content::RecordAction( |
| 222 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); | 220 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); |
| 223 break; | 221 break; |
| 224 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 222 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 225 content::RecordAction( | 223 content::RecordAction( |
| 226 UserMetricsAction("WebView.PermissionAllow.Geolocation")); | 224 UserMetricsAction("WebView.PermissionAllow.Geolocation")); |
| 227 break; | 225 break; |
| 226 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
| 227 content::RecordAction( | |
| 228 UserMetricsAction("WebView.PermissionAllow.Media")); | |
| 229 break; | |
| 228 default: | 230 default: |
| 229 break; | 231 break; |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 } else { | 235 } else { |
| 234 switch (info.permission_type) { | 236 switch (info.permission_type) { |
| 235 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 237 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
| 236 content::RecordAction( | 238 content::RecordAction( |
| 237 UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); | 239 UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); |
| 238 break; | 240 break; |
| 239 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | |
| 240 content::RecordAction( | |
| 241 UserMetricsAction("BrowserPlugin.PermissionDeny.Media")); | |
| 242 break; | |
| 243 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 241 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
| 244 content::RecordAction( | 242 content::RecordAction( |
| 245 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); | 243 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); |
| 246 break; | 244 break; |
| 247 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 245 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
| 248 content::RecordAction( | 246 content::RecordAction( |
| 249 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | 247 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); |
| 250 break; | 248 break; |
| 251 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 249 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 252 content::RecordAction( | 250 content::RecordAction( |
| 253 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); | 251 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); |
| 254 break; | 252 break; |
| 255 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 253 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
| 256 break; | 254 break; |
| 257 default: { | 255 default: { |
| 258 WebViewPermissionType webview_permission_type = | 256 WebViewPermissionType webview_permission_type = |
| 259 static_cast<WebViewPermissionType>(info.permission_type); | 257 static_cast<WebViewPermissionType>(info.permission_type); |
| 260 switch (webview_permission_type) { | 258 switch (webview_permission_type) { |
| 261 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 259 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 262 content::RecordAction( | 260 content::RecordAction( |
| 263 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); | 261 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); |
| 264 break; | 262 break; |
| 265 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 263 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 266 content::RecordAction( | 264 content::RecordAction( |
| 267 UserMetricsAction("WebView.PermissionDeny.Geolocation")); | 265 UserMetricsAction("WebView.PermissionDeny.Geolocation")); |
| 268 break; | 266 break; |
| 267 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
| 268 content::RecordAction( | |
| 269 UserMetricsAction("WebView.PermissionDeny.Media")); | |
| 270 break; | |
| 269 default: | 271 default: |
| 270 break; | 272 break; |
| 271 } | 273 } |
| 272 } | 274 } |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 } | 277 } |
| 276 | 278 |
| 277 void WebViewGuest::Attach(WebContents* embedder_web_contents, | 279 void WebViewGuest::Attach(WebContents* embedder_web_contents, |
| 278 const base::DictionaryValue& args) { | 280 const base::DictionaryValue& args) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 int request_id = RemoveBridgeID(bridge_id); | 617 int request_id = RemoveBridgeID(bridge_id); |
| 616 RequestMap::iterator request_itr = | 618 RequestMap::iterator request_itr = |
| 617 pending_permission_requests_.find(request_id); | 619 pending_permission_requests_.find(request_id); |
| 618 | 620 |
| 619 if (request_itr == pending_permission_requests_.end()) | 621 if (request_itr == pending_permission_requests_.end()) |
| 620 return; | 622 return; |
| 621 | 623 |
| 622 pending_permission_requests_.erase(request_itr); | 624 pending_permission_requests_.erase(request_itr); |
| 623 } | 625 } |
| 624 | 626 |
| 627 void WebViewGuest::OnWebViewMediaPermissionResponse( | |
| 628 const content::MediaStreamRequest& request, | |
| 629 const content::MediaResponseCallback& callback, | |
| 630 bool allow, | |
| 631 const std::string& user_input) { | |
| 632 if (!allow || !attached()) { | |
| 633 // Deny the request. | |
| 634 callback.Run(content::MediaStreamDevices(), | |
| 635 content::MEDIA_DEVICE_INVALID_STATE, | |
| 636 scoped_ptr<content::MediaStreamUI>()); | |
| 637 return; | |
| 638 } | |
| 639 if (!embedder_web_contents()->GetDelegate()) | |
| 640 return; | |
| 641 | |
| 642 embedder_web_contents()->GetDelegate()-> | |
| 643 RequestMediaAccessPermission(embedder_web_contents(), request, callback); | |
| 644 } | |
| 645 | |
| 625 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( | 646 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( |
| 626 int request_id, | 647 int request_id, |
| 627 PermissionResponseAction action, | 648 PermissionResponseAction action, |
| 628 const std::string& user_input) { | 649 const std::string& user_input) { |
| 629 RequestMap::iterator request_itr = | 650 RequestMap::iterator request_itr = |
| 630 pending_permission_requests_.find(request_id); | 651 pending_permission_requests_.find(request_id); |
| 631 | 652 |
| 632 if (request_itr == pending_permission_requests_.end()) | 653 if (request_itr == pending_permission_requests_.end()) |
| 633 return SET_PERMISSION_INVALID; | 654 return SET_PERMISSION_INVALID; |
| 634 | 655 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 881 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 861 const gfx::Size& new_size) { | 882 const gfx::Size& new_size) { |
| 862 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 883 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 863 args->SetInteger(webview::kOldHeight, old_size.height()); | 884 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 864 args->SetInteger(webview::kOldWidth, old_size.width()); | 885 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 865 args->SetInteger(webview::kNewHeight, new_size.height()); | 886 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 866 args->SetInteger(webview::kNewWidth, new_size.width()); | 887 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 867 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); | 888 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
| 868 } | 889 } |
| 869 | 890 |
| 891 void WebViewGuest::RequestMediaAccessPermission( | |
| 892 const content::MediaStreamRequest& request, | |
| 893 const content::MediaResponseCallback& callback) { | |
| 894 base::DictionaryValue request_info; | |
| 895 request_info.Set( | |
| 896 guestview::kUrl, | |
| 897 base::Value::CreateStringValue(request.security_origin.spec())); | |
| 898 RequestPermission(static_cast<BrowserPluginPermissionType>( | |
| 899 WEB_VIEW_PERMISSION_TYPE_MEDIA), | |
| 900 request_info, | |
| 901 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | |
| 902 base::Unretained(this), | |
|
lazyboy
2014/04/11 20:13:20
nit: indent
WebViewGuest going away before the cal
Fady Samuel
2014/04/11 21:52:31
Done.
lazyboy
2014/04/11 21:56:26
Do we not need to fix the base::Unretained() issue
| |
| 903 request, | |
| 904 callback), | |
| 905 false /* allowed_by_default */); | |
| 906 } | |
| 907 | |
| 870 #if defined(OS_CHROMEOS) | 908 #if defined(OS_CHROMEOS) |
| 871 void WebViewGuest::OnAccessibilityStatusChanged( | 909 void WebViewGuest::OnAccessibilityStatusChanged( |
| 872 const chromeos::AccessibilityStatusEventDetails& details) { | 910 const chromeos::AccessibilityStatusEventDetails& details) { |
| 873 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) { | 911 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) { |
| 874 accessibility_subscription_.reset(); | 912 accessibility_subscription_.reset(); |
| 875 } else if (details.notification_type == | 913 } else if (details.notification_type == |
| 876 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { | 914 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { |
| 877 if (details.enabled) | 915 if (details.enabled) |
| 878 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); | 916 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); |
| 879 else | 917 else |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 const PermissionResponseCallback& callback, | 955 const PermissionResponseCallback& callback, |
| 918 BrowserPluginPermissionType permission_type, | 956 BrowserPluginPermissionType permission_type, |
| 919 bool allowed_by_default) | 957 bool allowed_by_default) |
| 920 : callback(callback), | 958 : callback(callback), |
| 921 permission_type(permission_type), | 959 permission_type(permission_type), |
| 922 allowed_by_default(allowed_by_default) { | 960 allowed_by_default(allowed_by_default) { |
| 923 } | 961 } |
| 924 | 962 |
| 925 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 963 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
| 926 } | 964 } |
| OLD | NEW |