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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 break; | 116 break; |
116 } | 117 } |
117 NOTREACHED() << "Unknown Termination Status."; | 118 NOTREACHED() << "Unknown Termination Status."; |
118 return "unknown"; | 119 return "unknown"; |
119 } | 120 } |
120 | 121 |
121 static std::string PermissionTypeToString(WebViewPermissionType type) { | 122 static std::string PermissionTypeToString(WebViewPermissionType type) { |
122 switch (type) { | 123 switch (type) { |
123 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 124 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
124 return webview::kPermissionTypeDownload; | 125 return webview::kPermissionTypeDownload; |
| 126 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 127 return webview::kPermissionTypeFileSystem; |
125 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 128 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
126 return webview::kPermissionTypeGeolocation; | 129 return webview::kPermissionTypeGeolocation; |
127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 130 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
128 return webview::kPermissionTypeDialog; | 131 return webview::kPermissionTypeDialog; |
129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 132 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
130 return webview::kPermissionTypeLoadPlugin; | 133 return webview::kPermissionTypeLoadPlugin; |
131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | 134 case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
132 return webview::kPermissionTypeMedia; | 135 return webview::kPermissionTypeMedia; |
133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 136 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
134 return webview::kPermissionTypeNewWindow; | 137 return webview::kPermissionTypeNewWindow; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (allow) { | 230 if (allow) { |
228 // Note that |allow| == true means the embedder explicitly allowed the | 231 // Note that |allow| == true means the embedder explicitly allowed the |
229 // request. For some requests they might still fail. An example of such | 232 // request. For some requests they might still fail. An example of such |
230 // scenario would be: an embedder allows geolocation request but doesn't | 233 // scenario would be: an embedder allows geolocation request but doesn't |
231 // have geolocation access on its own. | 234 // have geolocation access on its own. |
232 switch (info.permission_type) { | 235 switch (info.permission_type) { |
233 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 236 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
234 content::RecordAction( | 237 content::RecordAction( |
235 UserMetricsAction("WebView.PermissionAllow.Download")); | 238 UserMetricsAction("WebView.PermissionAllow.Download")); |
236 break; | 239 break; |
| 240 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 241 content::RecordAction( |
| 242 UserMetricsAction("WebView.PermissionAllow.FileSystem")); |
| 243 break; |
237 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 244 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
238 content::RecordAction( | 245 content::RecordAction( |
239 UserMetricsAction("WebView.PermissionAllow.Geolocation")); | 246 UserMetricsAction("WebView.PermissionAllow.Geolocation")); |
240 break; | 247 break; |
241 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 248 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
242 content::RecordAction( | 249 content::RecordAction( |
243 UserMetricsAction("WebView.PermissionAllow.JSDialog")); | 250 UserMetricsAction("WebView.PermissionAllow.JSDialog")); |
244 break; | 251 break; |
245 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 252 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
246 content::RecordAction( | 253 content::RecordAction( |
(...skipping 12 matching lines...) Expand all Loading... |
259 break; | 266 break; |
260 default: | 267 default: |
261 break; | 268 break; |
262 } | 269 } |
263 } else { | 270 } else { |
264 switch (info.permission_type) { | 271 switch (info.permission_type) { |
265 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 272 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
266 content::RecordAction( | 273 content::RecordAction( |
267 UserMetricsAction("WebView.PermissionDeny.Download")); | 274 UserMetricsAction("WebView.PermissionDeny.Download")); |
268 break; | 275 break; |
| 276 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 277 content::RecordAction( |
| 278 UserMetricsAction("WebView.PermissionDeny.FileSystem")); |
| 279 break; |
269 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 280 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
270 content::RecordAction( | 281 content::RecordAction( |
271 UserMetricsAction("WebView.PermissionDeny.Geolocation")); | 282 UserMetricsAction("WebView.PermissionDeny.Geolocation")); |
272 break; | 283 break; |
273 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 284 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
274 content::RecordAction( | 285 content::RecordAction( |
275 UserMetricsAction("WebView.PermissionDeny.JSDialog")); | 286 UserMetricsAction("WebView.PermissionDeny.JSDialog")); |
276 break; | 287 break; |
277 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 288 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
278 content::RecordAction( | 289 content::RecordAction( |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 guest_web_contents()->GetController().GoToOffset(relative_index); | 620 guest_web_contents()->GetController().GoToOffset(relative_index); |
610 } | 621 } |
611 | 622 |
612 void WebViewGuest::Reload() { | 623 void WebViewGuest::Reload() { |
613 // TODO(fsamuel): Don't check for repost because we don't want to show | 624 // 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 | 625 // Chromium's repost warning. We might want to implement a separate API |
615 // for registering a callback if a repost is about to happen. | 626 // for registering a callback if a repost is about to happen. |
616 guest_web_contents()->GetController().Reload(false); | 627 guest_web_contents()->GetController().Reload(false); |
617 } | 628 } |
618 | 629 |
| 630 void WebViewGuest::RequestFileSystemPermission( |
| 631 const GURL& url, |
| 632 bool allowed_by_default, |
| 633 const base::Callback<void(bool)>& callback) { |
| 634 base::DictionaryValue request_info; |
| 635 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); |
| 636 RequestPermission( |
| 637 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, |
| 638 request_info, |
| 639 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, |
| 640 base::Unretained(this), |
| 641 callback), |
| 642 allowed_by_default); |
| 643 } |
| 644 |
| 645 void WebViewGuest::OnWebViewFileSystemPermissionResponse( |
| 646 const base::Callback<void(bool)>& callback, |
| 647 bool allow, |
| 648 const std::string& user_input) { |
| 649 callback.Run(allow && attached()); |
| 650 } |
| 651 |
619 void WebViewGuest::RequestGeolocationPermission( | 652 void WebViewGuest::RequestGeolocationPermission( |
620 int bridge_id, | 653 int bridge_id, |
621 const GURL& requesting_frame, | 654 const GURL& requesting_frame, |
622 bool user_gesture, | 655 bool user_gesture, |
623 const base::Callback<void(bool)>& callback) { | 656 const base::Callback<void(bool)>& callback) { |
624 base::DictionaryValue request_info; | 657 base::DictionaryValue request_info; |
625 request_info.Set(guestview::kUrl, | 658 request_info.Set(guestview::kUrl, |
626 base::Value::CreateStringValue(requesting_frame.spec())); | 659 base::Value::CreateStringValue(requesting_frame.spec())); |
627 request_info.Set(guestview::kUserGesture, | 660 request_info.Set(guestview::kUserGesture, |
628 base::Value::CreateBooleanValue(user_gesture)); | 661 base::Value::CreateBooleanValue(user_gesture)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 removal_mask, | 813 removal_mask, |
781 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 814 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
782 GURL(), | 815 GURL(), |
783 content::StoragePartition::OriginMatcherFunction(), | 816 content::StoragePartition::OriginMatcherFunction(), |
784 remove_since, | 817 remove_since, |
785 base::Time::Now(), | 818 base::Time::Now(), |
786 callback); | 819 callback); |
787 return true; | 820 return true; |
788 } | 821 } |
789 | 822 |
| 823 // static |
| 824 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, |
| 825 int render_frame_id, |
| 826 int request_id, |
| 827 const GURL& url, |
| 828 bool blocked_by_policy) { |
| 829 WebViewGuest* guest = |
| 830 WebViewGuest::FromFrame(render_process_id, render_frame_id); |
| 831 DCHECK(guest); |
| 832 guest->RequestFileSystemPermission( |
| 833 url, |
| 834 !blocked_by_policy, |
| 835 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, |
| 836 render_process_id, |
| 837 render_frame_id, |
| 838 request_id, |
| 839 url)); |
| 840 } |
| 841 |
| 842 // static |
| 843 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id, |
| 844 int render_frame_id, |
| 845 int request_id, |
| 846 const GURL& url, |
| 847 bool allowed) { |
| 848 TabSpecificContentSettings::FileSystemAccessed( |
| 849 render_process_id, render_frame_id, url, !allowed); |
| 850 content::RenderFrameHost* render_frame_host = |
| 851 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 852 if (!render_frame_host) |
| 853 return; |
| 854 render_frame_host->Send( |
| 855 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( |
| 856 render_frame_id, request_id, allowed)); |
| 857 } |
| 858 |
| 859 // static |
| 860 void WebViewGuest::FileSystemAccessedSync(int render_process_id, |
| 861 int render_frame_id, |
| 862 const GURL& url, |
| 863 IPC::Message* reply_msg, |
| 864 bool blocked_by_policy) { |
| 865 WebViewGuest* guest = |
| 866 WebViewGuest::FromFrame(render_process_id, render_frame_id); |
| 867 DCHECK(guest); |
| 868 guest->RequestFileSystemPermission( |
| 869 url, |
| 870 !blocked_by_policy, |
| 871 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, |
| 872 render_process_id, |
| 873 render_frame_id, |
| 874 url, |
| 875 reply_msg)); |
| 876 } |
| 877 |
| 878 // static |
| 879 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id, |
| 880 int render_frame_id, |
| 881 const GURL& url, |
| 882 IPC::Message* reply_msg, |
| 883 bool allowed) { |
| 884 TabSpecificContentSettings::FileSystemAccessed( |
| 885 render_process_id, render_frame_id, url, !allowed); |
| 886 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, |
| 887 allowed); |
| 888 content::RenderFrameHost* render_frame_host = |
| 889 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 890 if (!render_frame_id) |
| 891 return; |
| 892 render_frame_host->Send(reply_msg); |
| 893 } |
| 894 |
790 WebViewGuest::~WebViewGuest() { | 895 WebViewGuest::~WebViewGuest() { |
791 } | 896 } |
792 | 897 |
793 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 898 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
794 int64 frame_id, | 899 int64 frame_id, |
795 const base::string16& frame_unique_name, | 900 const base::string16& frame_unique_name, |
796 bool is_main_frame, | 901 bool is_main_frame, |
797 const GURL& url, | 902 const GURL& url, |
798 content::PageTransition transition_type, | 903 content::PageTransition transition_type, |
799 content::RenderViewHost* render_view_host) { | 904 content::RenderViewHost* render_view_host) { |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 bool allow, | 1509 bool allow, |
1405 const std::string& user_input) { | 1510 const std::string& user_input) { |
1406 WebViewGuest* guest = | 1511 WebViewGuest* guest = |
1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1512 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1408 if (!guest) | 1513 if (!guest) |
1409 return; | 1514 return; |
1410 | 1515 |
1411 if (!allow) | 1516 if (!allow) |
1412 guest->Destroy(); | 1517 guest->Destroy(); |
1413 } | 1518 } |
OLD | NEW |