| 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" |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // Chromium's repost warning. We might want to implement a separate API | 747 // Chromium's repost warning. We might want to implement a separate API |
| 748 // for registering a callback if a repost is about to happen. | 748 // for registering a callback if a repost is about to happen. |
| 749 guest_web_contents()->GetController().Reload(false); | 749 guest_web_contents()->GetController().Reload(false); |
| 750 } | 750 } |
| 751 | 751 |
| 752 void WebViewGuest::RequestFileSystemPermission( | 752 void WebViewGuest::RequestFileSystemPermission( |
| 753 const GURL& url, | 753 const GURL& url, |
| 754 bool allowed_by_default, | 754 bool allowed_by_default, |
| 755 const base::Callback<void(bool)>& callback) { | 755 const base::Callback<void(bool)>& callback) { |
| 756 base::DictionaryValue request_info; | 756 base::DictionaryValue request_info; |
| 757 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); | 757 request_info.Set(guestview::kUrl, new base::StringValue(url.spec())); |
| 758 RequestPermission( | 758 RequestPermission( |
| 759 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, | 759 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, |
| 760 request_info, | 760 request_info, |
| 761 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, | 761 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, |
| 762 base::Unretained(this), | 762 base::Unretained(this), |
| 763 callback), | 763 callback), |
| 764 allowed_by_default); | 764 allowed_by_default); |
| 765 } | 765 } |
| 766 | 766 |
| 767 void WebViewGuest::OnWebViewFileSystemPermissionResponse( | 767 void WebViewGuest::OnWebViewFileSystemPermissionResponse( |
| 768 const base::Callback<void(bool)>& callback, | 768 const base::Callback<void(bool)>& callback, |
| 769 bool allow, | 769 bool allow, |
| 770 const std::string& user_input) { | 770 const std::string& user_input) { |
| 771 callback.Run(allow && attached()); | 771 callback.Run(allow && attached()); |
| 772 } | 772 } |
| 773 | 773 |
| 774 void WebViewGuest::RequestGeolocationPermission( | 774 void WebViewGuest::RequestGeolocationPermission( |
| 775 int bridge_id, | 775 int bridge_id, |
| 776 const GURL& requesting_frame, | 776 const GURL& requesting_frame, |
| 777 bool user_gesture, | 777 bool user_gesture, |
| 778 const base::Callback<void(bool)>& callback) { | 778 const base::Callback<void(bool)>& callback) { |
| 779 base::DictionaryValue request_info; | 779 base::DictionaryValue request_info; |
| 780 request_info.Set(guestview::kUrl, | 780 request_info.Set(guestview::kUrl, |
| 781 base::Value::CreateStringValue(requesting_frame.spec())); | 781 new base::StringValue(requesting_frame.spec())); |
| 782 request_info.Set(guestview::kUserGesture, | 782 request_info.Set(guestview::kUserGesture, |
| 783 base::Value::CreateBooleanValue(user_gesture)); | 783 base::Value::CreateBooleanValue(user_gesture)); |
| 784 | 784 |
| 785 // It is safe to hold an unretained pointer to WebViewGuest because this | 785 // It is safe to hold an unretained pointer to WebViewGuest because this |
| 786 // callback is called from WebViewGuest::SetPermission. | 786 // callback is called from WebViewGuest::SetPermission. |
| 787 const PermissionResponseCallback permission_callback = | 787 const PermissionResponseCallback permission_callback = |
| 788 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse, | 788 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse, |
| 789 base::Unretained(this), | 789 base::Unretained(this), |
| 790 bridge_id, | 790 bridge_id, |
| 791 user_gesture, | 791 user_gesture, |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 args->SetInteger(webview::kNewWidth, new_size.width()); | 1203 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 1204 DispatchEvent( | 1204 DispatchEvent( |
| 1205 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 1205 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 void WebViewGuest::RequestMediaAccessPermission( | 1208 void WebViewGuest::RequestMediaAccessPermission( |
| 1209 content::WebContents* source, | 1209 content::WebContents* source, |
| 1210 const content::MediaStreamRequest& request, | 1210 const content::MediaStreamRequest& request, |
| 1211 const content::MediaResponseCallback& callback) { | 1211 const content::MediaResponseCallback& callback) { |
| 1212 base::DictionaryValue request_info; | 1212 base::DictionaryValue request_info; |
| 1213 request_info.Set( | 1213 request_info.Set(guestview::kUrl, |
| 1214 guestview::kUrl, | 1214 new base::StringValue(request.security_origin.spec())); |
| 1215 base::Value::CreateStringValue(request.security_origin.spec())); | |
| 1216 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | 1215 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, |
| 1217 request_info, | 1216 request_info, |
| 1218 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | 1217 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, |
| 1219 base::Unretained(this), | 1218 base::Unretained(this), |
| 1220 request, | 1219 request, |
| 1221 callback), | 1220 callback), |
| 1222 false /* allowed_by_default */); | 1221 false /* allowed_by_default */); |
| 1223 } | 1222 } |
| 1224 | 1223 |
| 1225 void WebViewGuest::CanDownload( | 1224 void WebViewGuest::CanDownload( |
| 1226 content::RenderViewHost* render_view_host, | 1225 content::RenderViewHost* render_view_host, |
| 1227 const GURL& url, | 1226 const GURL& url, |
| 1228 const std::string& request_method, | 1227 const std::string& request_method, |
| 1229 const base::Callback<void(bool)>& callback) { | 1228 const base::Callback<void(bool)>& callback) { |
| 1230 base::DictionaryValue request_info; | 1229 base::DictionaryValue request_info; |
| 1231 request_info.Set( | 1230 request_info.Set(guestview::kUrl, new base::StringValue(url.spec())); |
| 1232 guestview::kUrl, | |
| 1233 base::Value::CreateStringValue(url.spec())); | |
| 1234 RequestPermission( | 1231 RequestPermission( |
| 1235 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | 1232 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, |
| 1236 request_info, | 1233 request_info, |
| 1237 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, | 1234 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, |
| 1238 base::Unretained(this), | 1235 base::Unretained(this), |
| 1239 callback), | 1236 callback), |
| 1240 false /* allowed_by_default */); | 1237 false /* allowed_by_default */); |
| 1241 } | 1238 } |
| 1242 | 1239 |
| 1243 void WebViewGuest::RequestPointerLockPermission( | 1240 void WebViewGuest::RequestPointerLockPermission( |
| 1244 bool user_gesture, | 1241 bool user_gesture, |
| 1245 bool last_unlocked_by_target, | 1242 bool last_unlocked_by_target, |
| 1246 const base::Callback<void(bool)>& callback) { | 1243 const base::Callback<void(bool)>& callback) { |
| 1247 base::DictionaryValue request_info; | 1244 base::DictionaryValue request_info; |
| 1248 request_info.Set(guestview::kUserGesture, | 1245 request_info.Set(guestview::kUserGesture, |
| 1249 base::Value::CreateBooleanValue(user_gesture)); | 1246 base::Value::CreateBooleanValue(user_gesture)); |
| 1250 request_info.Set(webview::kLastUnlockedBySelf, | 1247 request_info.Set(webview::kLastUnlockedBySelf, |
| 1251 base::Value::CreateBooleanValue(last_unlocked_by_target)); | 1248 base::Value::CreateBooleanValue(last_unlocked_by_target)); |
| 1252 request_info.Set(guestview::kUrl, | 1249 request_info.Set(guestview::kUrl, |
| 1253 base::Value::CreateStringValue( | 1250 new base::StringValue( |
| 1254 guest_web_contents()->GetLastCommittedURL().spec())); | 1251 guest_web_contents()->GetLastCommittedURL().spec())); |
| 1255 | 1252 |
| 1256 RequestPermission( | 1253 RequestPermission( |
| 1257 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, | 1254 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, |
| 1258 request_info, | 1255 request_info, |
| 1259 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse, | 1256 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse, |
| 1260 base::Unretained(this), | 1257 base::Unretained(this), |
| 1261 callback), | 1258 callback), |
| 1262 false /* allowed_by_default */); | 1259 false /* allowed_by_default */); |
| 1263 } | 1260 } |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 // Retrieve the opener partition info if we have it. | 1596 // Retrieve the opener partition info if we have it. |
| 1600 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); | 1597 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); |
| 1601 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); | 1598 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); |
| 1602 | 1599 |
| 1603 base::DictionaryValue request_info; | 1600 base::DictionaryValue request_info; |
| 1604 request_info.Set(webview::kInitialHeight, | 1601 request_info.Set(webview::kInitialHeight, |
| 1605 base::Value::CreateIntegerValue(initial_bounds.height())); | 1602 base::Value::CreateIntegerValue(initial_bounds.height())); |
| 1606 request_info.Set(webview::kInitialWidth, | 1603 request_info.Set(webview::kInitialWidth, |
| 1607 base::Value::CreateIntegerValue(initial_bounds.width())); | 1604 base::Value::CreateIntegerValue(initial_bounds.width())); |
| 1608 request_info.Set(webview::kTargetURL, | 1605 request_info.Set(webview::kTargetURL, |
| 1609 base::Value::CreateStringValue(new_window_info.url.spec())); | 1606 new base::StringValue(new_window_info.url.spec())); |
| 1610 request_info.Set(webview::kName, | 1607 request_info.Set(webview::kName, new base::StringValue(new_window_info.name)); |
| 1611 base::Value::CreateStringValue(new_window_info.name)); | |
| 1612 request_info.Set(webview::kWindowID, | 1608 request_info.Set(webview::kWindowID, |
| 1613 base::Value::CreateIntegerValue( | 1609 base::Value::CreateIntegerValue( |
| 1614 guest->GetGuestInstanceID())); | 1610 guest->GetGuestInstanceID())); |
| 1615 // We pass in partition info so that window-s created through newwindow | 1611 // We pass in partition info so that window-s created through newwindow |
| 1616 // API can use it to set their partition attribute. | 1612 // API can use it to set their partition attribute. |
| 1617 request_info.Set(webview::kStoragePartitionId, | 1613 request_info.Set(webview::kStoragePartitionId, |
| 1618 base::Value::CreateStringValue(storage_partition_id)); | 1614 new base::StringValue(storage_partition_id)); |
| 1619 request_info.Set(webview::kWindowOpenDisposition, | 1615 request_info.Set( |
| 1620 base::Value::CreateStringValue( | 1616 webview::kWindowOpenDisposition, |
| 1621 WindowOpenDispositionToString(disposition))); | 1617 new base::StringValue(WindowOpenDispositionToString(disposition))); |
| 1622 | 1618 |
| 1623 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1619 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| 1624 request_info, | 1620 request_info, |
| 1625 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1621 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| 1626 base::Unretained(this), | 1622 base::Unretained(this), |
| 1627 guest->GetGuestInstanceID()), | 1623 guest->GetGuestInstanceID()), |
| 1628 false /* allowed_by_default */); | 1624 false /* allowed_by_default */); |
| 1629 } | 1625 } |
| 1630 | 1626 |
| 1631 void WebViewGuest::DestroyUnattachedWindows() { | 1627 void WebViewGuest::DestroyUnattachedWindows() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1660 bool allow, | 1656 bool allow, |
| 1661 const std::string& user_input) { | 1657 const std::string& user_input) { |
| 1662 WebViewGuest* guest = | 1658 WebViewGuest* guest = |
| 1663 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1659 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1664 if (!guest) | 1660 if (!guest) |
| 1665 return; | 1661 return; |
| 1666 | 1662 |
| 1667 if (!allow) | 1663 if (!allow) |
| 1668 guest->Destroy(); | 1664 guest->Destroy(); |
| 1669 } | 1665 } |
| OLD | NEW |