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/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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
12 #include "chrome/browser/extensions/api/webview/webview_api.h" | 13 #include "chrome/browser/extensions/api/webview/webview_api.h" |
13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
14 #include "chrome/browser/extensions/extension_renderer_state.h" | 15 #include "chrome/browser/extensions/extension_renderer_state.h" |
15 #include "chrome/browser/extensions/menu_manager.h" | 16 #include "chrome/browser/extensions/menu_manager.h" |
16 #include "chrome/browser/extensions/script_executor.h" | 17 #include "chrome/browser/extensions/script_executor.h" |
17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
18 #include "chrome/browser/guest_view/guest_view_constants.h" | 19 #include "chrome/browser/guest_view/guest_view_constants.h" |
19 #include "chrome/browser/guest_view/guest_view_manager.h" | 20 #include "chrome/browser/guest_view/guest_view_manager.h" |
20 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 21 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 break; | 117 break; |
117 } | 118 } |
118 NOTREACHED() << "Unknown Termination Status."; | 119 NOTREACHED() << "Unknown Termination Status."; |
119 return "unknown"; | 120 return "unknown"; |
120 } | 121 } |
121 | 122 |
122 static std::string PermissionTypeToString(WebViewPermissionType type) { | 123 static std::string PermissionTypeToString(WebViewPermissionType type) { |
123 switch (type) { | 124 switch (type) { |
124 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 125 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
125 return webview::kPermissionTypeDownload; | 126 return webview::kPermissionTypeDownload; |
| 127 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 128 return webview::kPermissionTypeFileSystem; |
126 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 129 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
127 return webview::kPermissionTypeGeolocation; | 130 return webview::kPermissionTypeGeolocation; |
128 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 131 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
129 return webview::kPermissionTypeDialog; | 132 return webview::kPermissionTypeDialog; |
130 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 133 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
131 return webview::kPermissionTypeLoadPlugin; | 134 return webview::kPermissionTypeLoadPlugin; |
132 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | 135 case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
133 return webview::kPermissionTypeMedia; | 136 return webview::kPermissionTypeMedia; |
134 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 137 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
135 return webview::kPermissionTypeNewWindow; | 138 return webview::kPermissionTypeNewWindow; |
(...skipping 91 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 guest_web_contents()->GetController().GoToOffset(relative_index); | 606 guest_web_contents()->GetController().GoToOffset(relative_index); |
596 } | 607 } |
597 | 608 |
598 void WebViewGuest::Reload() { | 609 void WebViewGuest::Reload() { |
599 // TODO(fsamuel): Don't check for repost because we don't want to show | 610 // TODO(fsamuel): Don't check for repost because we don't want to show |
600 // Chromium's repost warning. We might want to implement a separate API | 611 // Chromium's repost warning. We might want to implement a separate API |
601 // for registering a callback if a repost is about to happen. | 612 // for registering a callback if a repost is about to happen. |
602 guest_web_contents()->GetController().Reload(false); | 613 guest_web_contents()->GetController().Reload(false); |
603 } | 614 } |
604 | 615 |
| 616 void WebViewGuest::RequestFileSystemPermission( |
| 617 const GURL& url, |
| 618 bool allowed_by_default, |
| 619 const base::Callback<void(bool)>& callback) { |
| 620 base::DictionaryValue request_info; |
| 621 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); |
| 622 RequestPermission( |
| 623 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, |
| 624 request_info, |
| 625 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, |
| 626 base::Unretained(this), |
| 627 callback), |
| 628 allowed_by_default); |
| 629 } |
| 630 |
| 631 void WebViewGuest::OnWebViewFileSystemPermissionResponse( |
| 632 const base::Callback<void(bool)>& callback, |
| 633 bool allow, |
| 634 const std::string& user_input) { |
| 635 callback.Run(allow && attached()); |
| 636 } |
| 637 |
605 void WebViewGuest::RequestGeolocationPermission( | 638 void WebViewGuest::RequestGeolocationPermission( |
606 int bridge_id, | 639 int bridge_id, |
607 const GURL& requesting_frame, | 640 const GURL& requesting_frame, |
608 bool user_gesture, | 641 bool user_gesture, |
609 const base::Callback<void(bool)>& callback) { | 642 const base::Callback<void(bool)>& callback) { |
610 base::DictionaryValue request_info; | 643 base::DictionaryValue request_info; |
611 request_info.Set(guestview::kUrl, | 644 request_info.Set(guestview::kUrl, |
612 base::Value::CreateStringValue(requesting_frame.spec())); | 645 base::Value::CreateStringValue(requesting_frame.spec())); |
613 request_info.Set(guestview::kUserGesture, | 646 request_info.Set(guestview::kUserGesture, |
614 base::Value::CreateBooleanValue(user_gesture)); | 647 base::Value::CreateBooleanValue(user_gesture)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 removal_mask, | 799 removal_mask, |
767 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 800 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
768 GURL(), | 801 GURL(), |
769 content::StoragePartition::OriginMatcherFunction(), | 802 content::StoragePartition::OriginMatcherFunction(), |
770 remove_since, | 803 remove_since, |
771 base::Time::Now(), | 804 base::Time::Now(), |
772 callback); | 805 callback); |
773 return true; | 806 return true; |
774 } | 807 } |
775 | 808 |
| 809 // static |
| 810 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, |
| 811 int render_frame_id, |
| 812 int request_id, |
| 813 const GURL& url, |
| 814 bool blocked_by_policy) { |
| 815 WebViewGuest* guest = |
| 816 WebViewGuest::FromFrameID(render_process_id, render_frame_id); |
| 817 DCHECK(guest); |
| 818 guest->RequestFileSystemPermission( |
| 819 url, |
| 820 !blocked_by_policy, |
| 821 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, |
| 822 render_process_id, |
| 823 render_frame_id, |
| 824 request_id, |
| 825 url)); |
| 826 } |
| 827 |
| 828 // static |
| 829 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id, |
| 830 int render_frame_id, |
| 831 int request_id, |
| 832 const GURL& url, |
| 833 bool allowed) { |
| 834 TabSpecificContentSettings::FileSystemAccessed( |
| 835 render_process_id, render_frame_id, url, !allowed); |
| 836 content::RenderFrameHost* render_frame_host = |
| 837 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 838 if (!render_frame_host) |
| 839 return; |
| 840 render_frame_host->Send( |
| 841 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( |
| 842 render_frame_id, request_id, allowed)); |
| 843 } |
| 844 |
| 845 // static |
| 846 void WebViewGuest::FileSystemAccessedSync(int render_process_id, |
| 847 int render_frame_id, |
| 848 const GURL& url, |
| 849 bool blocked_by_policy, |
| 850 IPC::Message* reply_msg) { |
| 851 WebViewGuest* guest = |
| 852 WebViewGuest::FromFrameID(render_process_id, render_frame_id); |
| 853 DCHECK(guest); |
| 854 guest->RequestFileSystemPermission( |
| 855 url, |
| 856 !blocked_by_policy, |
| 857 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, |
| 858 render_process_id, |
| 859 render_frame_id, |
| 860 url, |
| 861 reply_msg)); |
| 862 } |
| 863 |
| 864 // static |
| 865 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id, |
| 866 int render_frame_id, |
| 867 const GURL& url, |
| 868 IPC::Message* reply_msg, |
| 869 bool allowed) { |
| 870 TabSpecificContentSettings::FileSystemAccessed( |
| 871 render_process_id, render_frame_id, url, !allowed); |
| 872 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, |
| 873 allowed); |
| 874 content::RenderFrameHost* render_frame_host = |
| 875 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 876 if (!render_frame_id) |
| 877 return; |
| 878 render_frame_host->Send(reply_msg); |
| 879 } |
| 880 |
776 WebViewGuest::~WebViewGuest() { | 881 WebViewGuest::~WebViewGuest() { |
777 } | 882 } |
778 | 883 |
779 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 884 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
780 int64 frame_id, | 885 int64 frame_id, |
781 const base::string16& frame_unique_name, | 886 const base::string16& frame_unique_name, |
782 bool is_main_frame, | 887 bool is_main_frame, |
783 const GURL& url, | 888 const GURL& url, |
784 content::PageTransition transition_type, | 889 content::PageTransition transition_type, |
785 content::RenderViewHost* render_view_host) { | 890 content::RenderViewHost* render_view_host) { |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 bool allow, | 1520 bool allow, |
1416 const std::string& user_input) { | 1521 const std::string& user_input) { |
1417 WebViewGuest* guest = | 1522 WebViewGuest* guest = |
1418 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1523 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1419 if (!guest) | 1524 if (!guest) |
1420 return; | 1525 return; |
1421 | 1526 |
1422 if (!allow) | 1527 if (!allow) |
1423 guest->Destroy(); | 1528 guest->Destroy(); |
1424 } | 1529 } |
OLD | NEW |