Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1267)

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 306473012: Plumb file system permission into WebviewGuest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small changes are made. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 break; 118 break;
118 } 119 }
119 NOTREACHED() << "Unknown Termination Status."; 120 NOTREACHED() << "Unknown Termination Status.";
120 return "unknown"; 121 return "unknown";
121 } 122 }
122 123
123 static std::string PermissionTypeToString(WebViewPermissionType type) { 124 static std::string PermissionTypeToString(WebViewPermissionType type) {
124 switch (type) { 125 switch (type) {
125 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 126 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
126 return webview::kPermissionTypeDownload; 127 return webview::kPermissionTypeDownload;
128 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
129 return webview::kPermissionTypeFileSystem;
127 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 130 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
128 return webview::kPermissionTypeGeolocation; 131 return webview::kPermissionTypeGeolocation;
129 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 132 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
130 return webview::kPermissionTypeDialog; 133 return webview::kPermissionTypeDialog;
131 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 134 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
132 return webview::kPermissionTypeLoadPlugin; 135 return webview::kPermissionTypeLoadPlugin;
133 case WEB_VIEW_PERMISSION_TYPE_MEDIA: 136 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
134 return webview::kPermissionTypeMedia; 137 return webview::kPermissionTypeMedia;
135 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: 138 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
136 return webview::kPermissionTypeNewWindow; 139 return webview::kPermissionTypeNewWindow;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (allow) { 291 if (allow) {
289 // Note that |allow| == true means the embedder explicitly allowed the 292 // Note that |allow| == true means the embedder explicitly allowed the
290 // request. For some requests they might still fail. An example of such 293 // request. For some requests they might still fail. An example of such
291 // scenario would be: an embedder allows geolocation request but doesn't 294 // scenario would be: an embedder allows geolocation request but doesn't
292 // have geolocation access on its own. 295 // have geolocation access on its own.
293 switch (info.permission_type) { 296 switch (info.permission_type) {
294 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 297 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
295 content::RecordAction( 298 content::RecordAction(
296 UserMetricsAction("WebView.PermissionAllow.Download")); 299 UserMetricsAction("WebView.PermissionAllow.Download"));
297 break; 300 break;
301 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
302 content::RecordAction(
303 UserMetricsAction("WebView.PermissionAllow.FileSystem"));
304 break;
298 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 305 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
299 content::RecordAction( 306 content::RecordAction(
300 UserMetricsAction("WebView.PermissionAllow.Geolocation")); 307 UserMetricsAction("WebView.PermissionAllow.Geolocation"));
301 break; 308 break;
302 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 309 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
303 content::RecordAction( 310 content::RecordAction(
304 UserMetricsAction("WebView.PermissionAllow.JSDialog")); 311 UserMetricsAction("WebView.PermissionAllow.JSDialog"));
305 break; 312 break;
306 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 313 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
307 content::RecordAction( 314 content::RecordAction(
(...skipping 12 matching lines...) Expand all
320 break; 327 break;
321 default: 328 default:
322 break; 329 break;
323 } 330 }
324 } else { 331 } else {
325 switch (info.permission_type) { 332 switch (info.permission_type) {
326 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: 333 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
327 content::RecordAction( 334 content::RecordAction(
328 UserMetricsAction("WebView.PermissionDeny.Download")); 335 UserMetricsAction("WebView.PermissionDeny.Download"));
329 break; 336 break;
337 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
338 content::RecordAction(
339 UserMetricsAction("WebView.PermissionDeny.FileSystem"));
340 break;
330 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 341 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
331 content::RecordAction( 342 content::RecordAction(
332 UserMetricsAction("WebView.PermissionDeny.Geolocation")); 343 UserMetricsAction("WebView.PermissionDeny.Geolocation"));
333 break; 344 break;
334 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 345 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
335 content::RecordAction( 346 content::RecordAction(
336 UserMetricsAction("WebView.PermissionDeny.JSDialog")); 347 UserMetricsAction("WebView.PermissionDeny.JSDialog"));
337 break; 348 break;
338 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 349 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
339 content::RecordAction( 350 content::RecordAction(
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 guest_web_contents()->GetController().GoToOffset(relative_index); 685 guest_web_contents()->GetController().GoToOffset(relative_index);
675 } 686 }
676 687
677 void WebViewGuest::Reload() { 688 void WebViewGuest::Reload() {
678 // TODO(fsamuel): Don't check for repost because we don't want to show 689 // TODO(fsamuel): Don't check for repost because we don't want to show
679 // Chromium's repost warning. We might want to implement a separate API 690 // Chromium's repost warning. We might want to implement a separate API
680 // for registering a callback if a repost is about to happen. 691 // for registering a callback if a repost is about to happen.
681 guest_web_contents()->GetController().Reload(false); 692 guest_web_contents()->GetController().Reload(false);
682 } 693 }
683 694
695 void WebViewGuest::RequestFileSystemPermission(
696 const GURL& url,
697 bool allowed_by_default,
698 const base::Callback<void(bool)>& callback) {
699 base::DictionaryValue request_info;
700 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec()));
701 RequestPermission(
702 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM,
703 request_info,
704 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse,
705 base::Unretained(this),
706 callback),
707 allowed_by_default);
708 }
709
710 void WebViewGuest::OnWebViewFileSystemPermissionResponse(
711 const base::Callback<void(bool)>& callback,
712 bool allow,
713 const std::string& user_input) {
714 callback.Run(allow && attached());
715 }
716
684 void WebViewGuest::RequestGeolocationPermission( 717 void WebViewGuest::RequestGeolocationPermission(
685 int bridge_id, 718 int bridge_id,
686 const GURL& requesting_frame, 719 const GURL& requesting_frame,
687 bool user_gesture, 720 bool user_gesture,
688 const base::Callback<void(bool)>& callback) { 721 const base::Callback<void(bool)>& callback) {
689 base::DictionaryValue request_info; 722 base::DictionaryValue request_info;
690 request_info.Set(guestview::kUrl, 723 request_info.Set(guestview::kUrl,
691 base::Value::CreateStringValue(requesting_frame.spec())); 724 base::Value::CreateStringValue(requesting_frame.spec()));
692 request_info.Set(guestview::kUserGesture, 725 request_info.Set(guestview::kUserGesture,
693 base::Value::CreateBooleanValue(user_gesture)); 726 base::Value::CreateBooleanValue(user_gesture));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 removal_mask, 878 removal_mask,
846 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 879 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
847 GURL(), 880 GURL(),
848 content::StoragePartition::OriginMatcherFunction(), 881 content::StoragePartition::OriginMatcherFunction(),
849 remove_since, 882 remove_since,
850 base::Time::Now(), 883 base::Time::Now(),
851 callback); 884 callback);
852 return true; 885 return true;
853 } 886 }
854 887
888 // static
889 void WebViewGuest::FileSystemAccessedAsync(int render_process_id,
890 int render_frame_id,
891 int request_id,
892 const GURL& url,
893 bool blocked_by_policy) {
894 WebViewGuest* guest =
895 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
896 DCHECK(guest);
897 guest->RequestFileSystemPermission(
898 url,
899 !blocked_by_policy,
900 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse,
901 render_process_id,
902 render_frame_id,
903 request_id,
904 url));
905 }
906
907 // static
908 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id,
909 int render_frame_id,
910 int request_id,
911 const GURL& url,
912 bool allowed) {
913 TabSpecificContentSettings::FileSystemAccessed(
914 render_process_id, render_frame_id, url, !allowed);
915 content::RenderFrameHost* render_frame_host =
916 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
917 if (!render_frame_host)
918 return;
919 render_frame_host->Send(
920 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse(
921 render_frame_id, request_id, allowed));
922 }
923
924 // static
925 void WebViewGuest::FileSystemAccessedSync(int render_process_id,
926 int render_frame_id,
927 const GURL& url,
928 bool blocked_by_policy,
929 IPC::Message* reply_msg) {
930 WebViewGuest* guest =
931 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
932 DCHECK(guest);
933 guest->RequestFileSystemPermission(
934 url,
935 !blocked_by_policy,
936 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse,
937 render_process_id,
938 render_frame_id,
939 url,
940 reply_msg));
941 }
942
943 // static
944 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id,
945 int render_frame_id,
946 const GURL& url,
947 IPC::Message* reply_msg,
948 bool allowed) {
949 TabSpecificContentSettings::FileSystemAccessed(
950 render_process_id, render_frame_id, url, !allowed);
951 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg,
952 allowed);
953 content::RenderFrameHost* render_frame_host =
954 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
955 if (!render_frame_id)
956 return;
957 render_frame_host->Send(reply_msg);
958 }
959
855 WebViewGuest::~WebViewGuest() { 960 WebViewGuest::~WebViewGuest() {
856 } 961 }
857 962
858 void WebViewGuest::DidCommitProvisionalLoadForFrame( 963 void WebViewGuest::DidCommitProvisionalLoadForFrame(
859 int64 frame_id, 964 int64 frame_id,
860 const base::string16& frame_unique_name, 965 const base::string16& frame_unique_name,
861 bool is_main_frame, 966 bool is_main_frame,
862 const GURL& url, 967 const GURL& url,
863 content::PageTransition transition_type, 968 content::PageTransition transition_type,
864 content::RenderViewHost* render_view_host) { 969 content::RenderViewHost* render_view_host) {
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 bool allow, 1589 bool allow,
1485 const std::string& user_input) { 1590 const std::string& user_input) {
1486 WebViewGuest* guest = 1591 WebViewGuest* guest =
1487 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1592 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1488 if (!guest) 1593 if (!guest)
1489 return; 1594 return;
1490 1595
1491 if (!allow) 1596 if (!allow)
1492 guest->Destroy(); 1597 guest->Destroy();
1493 } 1598 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | chrome/browser/guest_view/web_view/web_view_permission_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698