Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 13 #include "chrome/browser/extensions/api/webview/webview_api.h" | 14 #include "chrome/browser/extensions/api/webview/webview_api.h" |
| 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 15 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 15 #include "chrome/browser/extensions/extension_renderer_state.h" | 16 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 16 #include "chrome/browser/extensions/menu_manager.h" | 17 #include "chrome/browser/extensions/menu_manager.h" |
| 17 #include "chrome/browser/extensions/script_executor.h" | 18 #include "chrome/browser/extensions/script_executor.h" |
| 18 #include "chrome/browser/favicon/favicon_tab_helper.h" | 19 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 19 #include "chrome/browser/guest_view/guest_view_constants.h" | 20 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 20 #include "chrome/browser/guest_view/guest_view_manager.h" | 21 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 21 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 22 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 63 |
| 63 #if defined(ENABLE_PLUGINS) | 64 #if defined(ENABLE_PLUGINS) |
| 64 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" | 65 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" |
| 65 #endif | 66 #endif |
| 66 | 67 |
| 67 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
| 68 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 69 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 using base::UserMetricsAction; | 72 using base::UserMetricsAction; |
| 72 using content::RenderFrameHost; | |
|
Fady Samuel
2014/05/30 18:26:13
Put this back.
Xi Han
2014/05/30 19:35:30
Done.
| |
| 73 using content::WebContents; | 73 using content::WebContents; |
| 74 | 74 |
| 75 namespace { | 75 namespace { |
| 76 | 76 |
| 77 std::string WindowOpenDispositionToString( | 77 std::string WindowOpenDispositionToString( |
| 78 WindowOpenDisposition window_open_disposition) { | 78 WindowOpenDisposition window_open_disposition) { |
| 79 switch (window_open_disposition) { | 79 switch (window_open_disposition) { |
| 80 case IGNORE_ACTION: | 80 case IGNORE_ACTION: |
| 81 return "ignore"; | 81 return "ignore"; |
| 82 case SAVE_TO_DISK: | 82 case SAVE_TO_DISK: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 break; | 115 break; |
| 116 } | 116 } |
| 117 NOTREACHED() << "Unknown Termination Status."; | 117 NOTREACHED() << "Unknown Termination Status."; |
| 118 return "unknown"; | 118 return "unknown"; |
| 119 } | 119 } |
| 120 | 120 |
| 121 static std::string PermissionTypeToString(WebViewPermissionType type) { | 121 static std::string PermissionTypeToString(WebViewPermissionType type) { |
| 122 switch (type) { | 122 switch (type) { |
| 123 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 123 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| 124 return webview::kPermissionTypeDownload; | 124 return webview::kPermissionTypeDownload; |
| 125 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 126 return webview::kPermissionTypeFileSystem; | |
| 125 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 127 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 126 return webview::kPermissionTypeGeolocation; | 128 return webview::kPermissionTypeGeolocation; |
| 127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 129 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 128 return webview::kPermissionTypeDialog; | 130 return webview::kPermissionTypeDialog; |
| 129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 131 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 130 return webview::kPermissionTypeLoadPlugin; | 132 return webview::kPermissionTypeLoadPlugin; |
| 131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | 133 case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
| 132 return webview::kPermissionTypeMedia; | 134 return webview::kPermissionTypeMedia; |
| 133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 135 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| 134 return webview::kPermissionTypeNewWindow; | 136 return webview::kPermissionTypeNewWindow; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 if (allow) { | 229 if (allow) { |
| 228 // Note that |allow| == true means the embedder explicitly allowed the | 230 // Note that |allow| == true means the embedder explicitly allowed the |
| 229 // request. For some requests they might still fail. An example of such | 231 // request. For some requests they might still fail. An example of such |
| 230 // scenario would be: an embedder allows geolocation request but doesn't | 232 // scenario would be: an embedder allows geolocation request but doesn't |
| 231 // have geolocation access on its own. | 233 // have geolocation access on its own. |
| 232 switch (info.permission_type) { | 234 switch (info.permission_type) { |
| 233 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 235 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| 234 content::RecordAction( | 236 content::RecordAction( |
| 235 UserMetricsAction("WebView.PermissionAllow.Download")); | 237 UserMetricsAction("WebView.PermissionAllow.Download")); |
| 236 break; | 238 break; |
| 239 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 240 content::RecordAction( | |
| 241 UserMetricsAction("WebView.PermissionAllow.FileSystem")); | |
| 242 break; | |
| 237 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 243 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 238 content::RecordAction( | 244 content::RecordAction( |
| 239 UserMetricsAction("WebView.PermissionAllow.Geolocation")); | 245 UserMetricsAction("WebView.PermissionAllow.Geolocation")); |
| 240 break; | 246 break; |
| 241 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 247 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 242 content::RecordAction( | 248 content::RecordAction( |
| 243 UserMetricsAction("WebView.PermissionAllow.JSDialog")); | 249 UserMetricsAction("WebView.PermissionAllow.JSDialog")); |
| 244 break; | 250 break; |
| 245 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 251 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 246 content::RecordAction( | 252 content::RecordAction( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 259 break; | 265 break; |
| 260 default: | 266 default: |
| 261 break; | 267 break; |
| 262 } | 268 } |
| 263 } else { | 269 } else { |
| 264 switch (info.permission_type) { | 270 switch (info.permission_type) { |
| 265 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 271 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| 266 content::RecordAction( | 272 content::RecordAction( |
| 267 UserMetricsAction("WebView.PermissionDeny.Download")); | 273 UserMetricsAction("WebView.PermissionDeny.Download")); |
| 268 break; | 274 break; |
| 275 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 276 content::RecordAction( | |
| 277 UserMetricsAction("WebView.PermissionDeny.FileSystem")); | |
| 278 break; | |
| 269 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 279 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| 270 content::RecordAction( | 280 content::RecordAction( |
| 271 UserMetricsAction("WebView.PermissionDeny.Geolocation")); | 281 UserMetricsAction("WebView.PermissionDeny.Geolocation")); |
| 272 break; | 282 break; |
| 273 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 283 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 274 content::RecordAction( | 284 content::RecordAction( |
| 275 UserMetricsAction("WebView.PermissionDeny.JSDialog")); | 285 UserMetricsAction("WebView.PermissionDeny.JSDialog")); |
| 276 break; | 286 break; |
| 277 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 287 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 278 content::RecordAction( | 288 content::RecordAction( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 guest_web_contents()->GetController().GoToOffset(relative_index); | 619 guest_web_contents()->GetController().GoToOffset(relative_index); |
| 610 } | 620 } |
| 611 | 621 |
| 612 void WebViewGuest::Reload() { | 622 void WebViewGuest::Reload() { |
| 613 // TODO(fsamuel): Don't check for repost because we don't want to show | 623 // TODO(fsamuel): Don't check for repost because we don't want to show |
| 614 // Chromium's repost warning. We might want to implement a separate API | 624 // Chromium's repost warning. We might want to implement a separate API |
| 615 // for registering a callback if a repost is about to happen. | 625 // for registering a callback if a repost is about to happen. |
| 616 guest_web_contents()->GetController().Reload(false); | 626 guest_web_contents()->GetController().Reload(false); |
| 617 } | 627 } |
| 618 | 628 |
| 629 void WebViewGuest::RequestFileSystemPermission( | |
| 630 const GURL& url, | |
| 631 bool allowed_by_default, | |
| 632 const base::Callback<void(bool)>& callback) { | |
| 633 base::DictionaryValue request_info; | |
| 634 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); | |
| 635 RequestPermission( | |
| 636 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, | |
| 637 request_info, | |
| 638 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, | |
| 639 base::Unretained(this), | |
| 640 callback), | |
| 641 allowed_by_default); | |
| 642 } | |
| 643 | |
| 644 void WebViewGuest::OnWebViewFileSystemPermissionResponse( | |
| 645 const base::Callback<void(bool)>& callback, | |
| 646 bool allow, | |
| 647 const std::string& user_input) { | |
| 648 callback.Run(allow && attached()); | |
| 649 } | |
| 650 | |
| 619 void WebViewGuest::RequestGeolocationPermission( | 651 void WebViewGuest::RequestGeolocationPermission( |
| 620 int bridge_id, | 652 int bridge_id, |
| 621 const GURL& requesting_frame, | 653 const GURL& requesting_frame, |
| 622 bool user_gesture, | 654 bool user_gesture, |
| 623 const base::Callback<void(bool)>& callback) { | 655 const base::Callback<void(bool)>& callback) { |
| 624 base::DictionaryValue request_info; | 656 base::DictionaryValue request_info; |
| 625 request_info.Set(guestview::kUrl, | 657 request_info.Set(guestview::kUrl, |
| 626 base::Value::CreateStringValue(requesting_frame.spec())); | 658 base::Value::CreateStringValue(requesting_frame.spec())); |
| 627 request_info.Set(guestview::kUserGesture, | 659 request_info.Set(guestview::kUserGesture, |
| 628 base::Value::CreateBooleanValue(user_gesture)); | 660 base::Value::CreateBooleanValue(user_gesture)); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 removal_mask, | 812 removal_mask, |
| 781 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 813 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 782 GURL(), | 814 GURL(), |
| 783 content::StoragePartition::OriginMatcherFunction(), | 815 content::StoragePartition::OriginMatcherFunction(), |
| 784 remove_since, | 816 remove_since, |
| 785 base::Time::Now(), | 817 base::Time::Now(), |
| 786 callback); | 818 callback); |
| 787 return true; | 819 return true; |
| 788 } | 820 } |
| 789 | 821 |
| 822 // static | |
| 823 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, | |
| 824 int render_frame_id, | |
| 825 int request_id, | |
| 826 const GURL& url, | |
| 827 bool blocked_by_policy) { | |
| 828 WebViewGuest* guest = | |
| 829 WebViewGuest::FromFrame(render_process_id, render_frame_id); | |
| 830 DCHECK(guest); | |
| 831 guest->RequestFileSystemPermission( | |
| 832 url, | |
| 833 !blocked_by_policy, | |
| 834 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, | |
| 835 render_process_id, | |
| 836 render_frame_id, | |
| 837 request_id, | |
| 838 url)); | |
| 839 } | |
| 840 | |
| 841 // static | |
| 842 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id, | |
| 843 int render_frame_id, | |
| 844 int request_id, | |
| 845 const GURL& url, | |
| 846 bool allowed) { | |
| 847 TabSpecificContentSettings::FileSystemAccessed( | |
| 848 render_process_id, render_frame_id, url, !allowed); | |
| 849 content::RenderFrameHost* render_frame_host = | |
| 850 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
|
Fady Samuel
2014/05/30 18:26:13
It is possible for the frame to go away between th
Xi Han
2014/05/30 19:35:30
Done.
| |
| 851 render_frame_host->Send( | |
| 852 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( | |
| 853 render_frame_id, request_id, allowed)); | |
| 854 } | |
| 855 | |
| 856 // static | |
| 857 void WebViewGuest::FileSystemAccessedSync(int render_process_id, | |
| 858 int render_frame_id, | |
| 859 const GURL& url, | |
| 860 IPC::Message* reply_msg, | |
| 861 bool blocked_by_policy) { | |
| 862 WebViewGuest* guest = | |
| 863 WebViewGuest::FromFrame(render_process_id, render_frame_id); | |
| 864 DCHECK(guest); | |
| 865 guest->RequestFileSystemPermission( | |
| 866 url, | |
| 867 !blocked_by_policy, | |
| 868 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, | |
| 869 render_process_id, | |
| 870 render_frame_id, | |
| 871 url, | |
| 872 reply_msg)); | |
| 873 } | |
| 874 | |
| 875 // static | |
| 876 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id, | |
| 877 int render_frame_id, | |
| 878 const GURL& url, | |
| 879 IPC::Message* reply_msg, | |
| 880 bool allowed) { | |
| 881 TabSpecificContentSettings::FileSystemAccessed( | |
| 882 render_process_id, render_frame_id, url, !allowed); | |
| 883 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, | |
| 884 allowed); | |
| 885 content::RenderFrameHost* render_frame_host = | |
| 886 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
|
Fady Samuel
2014/05/30 18:26:13
if (!render_frame_host)
return;
Xi Han
2014/05/30 19:35:30
Done.
| |
| 887 render_frame_host->Send(reply_msg); | |
| 888 } | |
| 889 | |
| 790 WebViewGuest::~WebViewGuest() { | 890 WebViewGuest::~WebViewGuest() { |
| 791 } | 891 } |
| 792 | 892 |
| 793 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 893 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 794 int64 frame_id, | 894 int64 frame_id, |
| 795 const base::string16& frame_unique_name, | 895 const base::string16& frame_unique_name, |
| 796 bool is_main_frame, | 896 bool is_main_frame, |
| 797 const GURL& url, | 897 const GURL& url, |
| 798 content::PageTransition transition_type, | 898 content::PageTransition transition_type, |
| 799 content::RenderViewHost* render_view_host) { | 899 content::RenderViewHost* render_view_host) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 content::RenderViewHost* render_view_host) { | 955 content::RenderViewHost* render_view_host) { |
| 856 if (frame_id == main_frame_id_) | 956 if (frame_id == main_frame_id_) |
| 857 InjectChromeVoxIfNeeded(render_view_host); | 957 InjectChromeVoxIfNeeded(render_view_host); |
| 858 } | 958 } |
| 859 | 959 |
| 860 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 960 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 861 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 961 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 862 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 962 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 863 } | 963 } |
| 864 | 964 |
| 865 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, | 965 bool WebViewGuest::OnMessageReceived( |
|
Fady Samuel
2014/05/30 18:26:13
Restore this.
Xi Han
2014/05/30 19:35:30
Done.
| |
| 866 RenderFrameHost* render_frame_host) { | 966 const IPC::Message& message, |
| 967 content::RenderFrameHost* render_frame_host) { | |
| 867 bool handled = true; | 968 bool handled = true; |
| 868 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) | 969 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) |
| 869 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 970 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 870 IPC_MESSAGE_UNHANDLED(handled = false) | 971 IPC_MESSAGE_UNHANDLED(handled = false) |
| 871 IPC_END_MESSAGE_MAP() | 972 IPC_END_MESSAGE_MAP() |
| 872 return handled; | 973 return handled; |
| 873 } | 974 } |
| 874 | 975 |
| 875 void WebViewGuest::WebContentsDestroyed() { | 976 void WebViewGuest::WebContentsDestroyed() { |
| 876 // Clean up custom context menu items for this guest. | 977 // Clean up custom context menu items for this guest. |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1404 bool allow, | 1505 bool allow, |
| 1405 const std::string& user_input) { | 1506 const std::string& user_input) { |
| 1406 WebViewGuest* guest = | 1507 WebViewGuest* guest = |
| 1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1508 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1408 if (!guest) | 1509 if (!guest) |
| 1409 return; | 1510 return; |
| 1410 | 1511 |
| 1411 if (!allow) | 1512 if (!allow) |
| 1412 guest->Destroy(); | 1513 guest->Destroy(); |
| 1413 } | 1514 } |
| OLD | NEW |