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; | |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
128 return webview::kPermissionTypeDialog; | 128 return webview::kPermissionTypeDialog; |
129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
130 return webview::kPermissionTypeLoadPlugin; | 130 return webview::kPermissionTypeLoadPlugin; |
131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | 131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
132 return webview::kPermissionTypeMedia; | 132 return webview::kPermissionTypeMedia; |
133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
134 return webview::kPermissionTypeNewWindow; | 134 return webview::kPermissionTypeNewWindow; |
135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
136 return webview::kPermissionTypePointerLock; | 136 return webview::kPermissionTypePointerLock; |
137 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
fsamuel
2014/05/30 15:13:21
Order alphabetically.
Xi Han
2014/05/30 18:15:56
Done.
| |
138 return webview::kPermissionTypeFileSystem; | |
137 default: | 139 default: |
138 NOTREACHED(); | 140 NOTREACHED(); |
139 return std::string(); | 141 return std::string(); |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
143 void RemoveWebViewEventListenersOnIOThread( | 145 void RemoveWebViewEventListenersOnIOThread( |
144 void* profile, | 146 void* profile, |
145 const std::string& extension_id, | 147 const std::string& extension_id, |
146 int embedder_process_id, | 148 int embedder_process_id, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 UserMetricsAction("WebView.PermissionAllow.Media")); | 252 UserMetricsAction("WebView.PermissionAllow.Media")); |
251 break; | 253 break; |
252 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 254 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
253 content::RecordAction( | 255 content::RecordAction( |
254 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | 256 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); |
255 break; | 257 break; |
256 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 258 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
257 content::RecordAction( | 259 content::RecordAction( |
258 UserMetricsAction("WebView.PermissionAllow.PointerLock")); | 260 UserMetricsAction("WebView.PermissionAllow.PointerLock")); |
259 break; | 261 break; |
262 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
fsamuel
2014/05/30 15:13:21
Order alphabetically
Xi Han
2014/05/30 18:15:56
Done.
| |
263 content::RecordAction( | |
264 UserMetricsAction("WebView.PermissionAllow.FileSystem")); | |
260 default: | 265 default: |
261 break; | 266 break; |
262 } | 267 } |
263 } else { | 268 } else { |
264 switch (info.permission_type) { | 269 switch (info.permission_type) { |
265 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 270 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
266 content::RecordAction( | 271 content::RecordAction( |
267 UserMetricsAction("WebView.PermissionDeny.Download")); | 272 UserMetricsAction("WebView.PermissionDeny.Download")); |
268 break; | 273 break; |
269 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 274 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
(...skipping 12 matching lines...) Expand all Loading... | |
282 UserMetricsAction("WebView.PermissionDeny.Media")); | 287 UserMetricsAction("WebView.PermissionDeny.Media")); |
283 break; | 288 break; |
284 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 289 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
285 content::RecordAction( | 290 content::RecordAction( |
286 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | 291 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); |
287 break; | 292 break; |
288 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 293 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
289 content::RecordAction( | 294 content::RecordAction( |
290 UserMetricsAction("WebView.PermissionDeny.PointerLock")); | 295 UserMetricsAction("WebView.PermissionDeny.PointerLock")); |
291 break; | 296 break; |
297 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
fsamuel
2014/05/30 15:13:21
Order alphabetically.
Xi Han
2014/05/30 18:15:56
Done.
| |
298 content::RecordAction( | |
299 UserMetricsAction("WebView.PermissionDeny.FileSystem")); | |
300 break; | |
292 default: | 301 default: |
293 break; | 302 break; |
294 } | 303 } |
295 } | 304 } |
296 } | 305 } |
297 | 306 |
298 // static | 307 // static |
299 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( | 308 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( |
300 const ui::SimpleMenuModel& menu_model) { | 309 const ui::SimpleMenuModel& menu_model) { |
301 scoped_ptr<base::ListValue> items(new base::ListValue()); | 310 scoped_ptr<base::ListValue> items(new base::ListValue()); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 guest_web_contents()->GetController().GoToOffset(relative_index); | 618 guest_web_contents()->GetController().GoToOffset(relative_index); |
610 } | 619 } |
611 | 620 |
612 void WebViewGuest::Reload() { | 621 void WebViewGuest::Reload() { |
613 // TODO(fsamuel): Don't check for repost because we don't want to show | 622 // 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 | 623 // Chromium's repost warning. We might want to implement a separate API |
615 // for registering a callback if a repost is about to happen. | 624 // for registering a callback if a repost is about to happen. |
616 guest_web_contents()->GetController().Reload(false); | 625 guest_web_contents()->GetController().Reload(false); |
617 } | 626 } |
618 | 627 |
628 void WebViewGuest::RequestFileSystemPermission( | |
629 const GURL& url, | |
630 const base::Callback<void(bool)>& callback) { | |
631 base::DictionaryValue request_info; | |
632 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); | |
633 RequestPermission( | |
634 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, | |
635 request_info, | |
636 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, | |
637 base::Unretained(this), | |
638 callback), | |
639 false /* allowed_by_default */); | |
640 } | |
641 | |
642 void WebViewGuest::OnWebViewFileSystemPermissionResponse( | |
643 const base::Callback<void(bool)>& callback, | |
644 bool allow, | |
645 const std::string& user_input) { | |
646 callback.Run(!allow || !attached()); | |
647 } | |
648 | |
619 void WebViewGuest::RequestGeolocationPermission( | 649 void WebViewGuest::RequestGeolocationPermission( |
620 int bridge_id, | 650 int bridge_id, |
621 const GURL& requesting_frame, | 651 const GURL& requesting_frame, |
622 bool user_gesture, | 652 bool user_gesture, |
623 const base::Callback<void(bool)>& callback) { | 653 const base::Callback<void(bool)>& callback) { |
624 base::DictionaryValue request_info; | 654 base::DictionaryValue request_info; |
625 request_info.Set(guestview::kUrl, | 655 request_info.Set(guestview::kUrl, |
626 base::Value::CreateStringValue(requesting_frame.spec())); | 656 base::Value::CreateStringValue(requesting_frame.spec())); |
627 request_info.Set(guestview::kUserGesture, | 657 request_info.Set(guestview::kUserGesture, |
628 base::Value::CreateBooleanValue(user_gesture)); | 658 base::Value::CreateBooleanValue(user_gesture)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 removal_mask, | 810 removal_mask, |
781 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 811 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
782 GURL(), | 812 GURL(), |
783 content::StoragePartition::OriginMatcherFunction(), | 813 content::StoragePartition::OriginMatcherFunction(), |
784 remove_since, | 814 remove_since, |
785 base::Time::Now(), | 815 base::Time::Now(), |
786 callback); | 816 callback); |
787 return true; | 817 return true; |
788 } | 818 } |
789 | 819 |
820 // static | |
821 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, | |
822 int render_frame_id, | |
823 int request_id, | |
824 const GURL& url, | |
825 bool blocked_by_policy) { | |
fsamuel
2014/05/30 15:13:21
This should be passing into allowed_by_default
Xi Han
2014/05/30 18:15:56
Done.
| |
826 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
fsamuel
2014/05/30 15:13:21
Drop this.
Xi Han
2014/05/30 18:15:56
Done.
| |
827 WebViewGuest* guest = GetWebViewGuest(render_process_id, render_frame_id); | |
828 DCHECK(guest); | |
829 guest->RequestFileSystemPermission( | |
830 url, | |
831 base::Bind(&WebViewGuest::FileSystemAccessedAsyncInternal, | |
832 render_process_id, | |
833 render_frame_id, | |
834 request_id, | |
835 url)); | |
836 } | |
837 | |
838 // static | |
839 void WebViewGuest::FileSystemAccessedAsyncInternal(int render_process_id, | |
fsamuel
2014/05/30 15:13:21
WebViewGuest::FileSystemAccessedAsyncResponse
Xi Han
2014/05/30 18:15:56
Done.
| |
840 int render_frame_id, | |
841 int request_id, | |
842 const GURL& url, | |
843 bool blocked_by_policy) { | |
fsamuel
2014/05/30 15:13:21
This should be passed into allowed_by_default.
Xi Han
2014/05/30 18:15:56
Not this one, but the one in WebViewGuest::FileSys
| |
844 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
fsamuel
2014/05/30 15:13:21
Drop this.
Xi Han
2014/05/30 18:15:56
Done.
| |
845 TabSpecificContentSettings::FileSystemAccessed( | |
846 render_process_id, render_frame_id, url, blocked_by_policy); | |
847 content::RenderFrameHost* render_frame_host = | |
848 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
849 render_frame_host->Send( | |
850 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( | |
851 render_frame_id, request_id, !blocked_by_policy)); | |
852 } | |
853 | |
854 // static | |
855 WebViewGuest* WebViewGuest::GetWebViewGuest(int render_process_id, | |
fsamuel
2014/05/30 15:13:21
Call it from WebViewGuest::FromFrame, and make it
Xi Han
2014/05/30 18:15:56
Done.
| |
856 int render_frame_id) { | |
857 content::RenderFrameHost* render_frame_host = | |
858 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
fsamuel
2014/05/30 15:13:21
if (!render_frame_host)
return NULL;
Xi Han
2014/05/30 18:15:56
Done.
| |
859 WebContents* web_contents = | |
860 WebContents::FromRenderFrameHost(render_frame_host); | |
861 return WebViewGuest::FromWebContents(web_contents); | |
862 } | |
863 | |
864 // static | |
865 void WebViewGuest::FileSystemAccessedSyncDelayReply(int render_process_id, | |
fsamuel
2014/05/30 15:13:21
WebViewGuest::FileSystemAccessedSync
Xi Han
2014/05/30 18:15:56
Done.
| |
866 int render_frame_id, | |
867 const GURL& url, | |
868 IPC::Message* reply_msg, | |
869 bool blocked_by_policy) { | |
870 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
fsamuel
2014/05/30 15:13:21
Drop this. Everything in WebViewGuest is assumed U
Xi Han
2014/05/30 18:15:56
Done.
| |
871 WebViewGuest* guest = GetWebViewGuest(render_process_id, render_frame_id); | |
872 DCHECK(guest); | |
873 guest->RequestFileSystemPermission( | |
874 url, | |
875 base::Bind(&WebViewGuest::FileSystemAccessedSyncDelayReplyInternal, | |
876 render_process_id, | |
877 render_frame_id, | |
878 url, | |
879 reply_msg)); | |
880 } | |
881 | |
882 // static | |
883 void WebViewGuest::FileSystemAccessedSyncDelayReplyInternal( | |
fsamuel
2014/05/30 15:13:21
WebViewGuest::FileSystemAccessedSyncResponse
Xi Han
2014/05/30 18:15:56
Done.
| |
884 int render_process_id, | |
885 int render_frame_id, | |
886 const GURL& url, | |
887 IPC::Message* reply_msg, | |
888 bool blocked_by_policy) { | |
fsamuel
2014/05/30 15:13:21
This is not blocked_by_policy. This is allowed.
Xi Han
2014/05/30 18:15:56
Done.
| |
889 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
fsamuel
2014/05/30 15:13:21
Drop this. Everything in WebViewGuest is assumed U
Xi Han
2014/05/30 18:15:56
Done.
Xi Han
2014/05/30 18:15:56
Done.
| |
890 TabSpecificContentSettings::FileSystemAccessed( | |
891 render_process_id, render_frame_id, url, blocked_by_policy); | |
892 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams( | |
893 reply_msg, !blocked_by_policy); | |
fsamuel
2014/05/30 15:13:21
Do you have the logic reversed here?
| |
894 content::RenderFrameHost* render_frame_host = | |
895 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
896 render_frame_host->Send(reply_msg); | |
897 } | |
898 | |
790 WebViewGuest::~WebViewGuest() { | 899 WebViewGuest::~WebViewGuest() { |
791 } | 900 } |
792 | 901 |
793 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 902 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
794 int64 frame_id, | 903 int64 frame_id, |
795 const base::string16& frame_unique_name, | 904 const base::string16& frame_unique_name, |
796 bool is_main_frame, | 905 bool is_main_frame, |
797 const GURL& url, | 906 const GURL& url, |
798 content::PageTransition transition_type, | 907 content::PageTransition transition_type, |
799 content::RenderViewHost* render_view_host) { | 908 content::RenderViewHost* render_view_host) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 content::RenderViewHost* render_view_host) { | 964 content::RenderViewHost* render_view_host) { |
856 if (frame_id == main_frame_id_) | 965 if (frame_id == main_frame_id_) |
857 InjectChromeVoxIfNeeded(render_view_host); | 966 InjectChromeVoxIfNeeded(render_view_host); |
858 } | 967 } |
859 | 968 |
860 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 969 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
861 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 970 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
862 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 971 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
863 } | 972 } |
864 | 973 |
865 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, | 974 bool WebViewGuest::OnMessageReceived( |
fsamuel
2014/05/30 15:13:21
Revert this part. This seems unnecessary.
Xi Han
2014/05/30 18:15:56
This is necessary to add "content::" before Render
| |
866 RenderFrameHost* render_frame_host) { | 975 const IPC::Message& message, |
976 content::RenderFrameHost* render_frame_host) { | |
867 bool handled = true; | 977 bool handled = true; |
868 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) | 978 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) |
869 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 979 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
870 IPC_MESSAGE_UNHANDLED(handled = false) | 980 IPC_MESSAGE_UNHANDLED(handled = false) |
871 IPC_END_MESSAGE_MAP() | 981 IPC_END_MESSAGE_MAP() |
872 return handled; | 982 return handled; |
873 } | 983 } |
874 | 984 |
875 void WebViewGuest::WebContentsDestroyed() { | 985 void WebViewGuest::WebContentsDestroyed() { |
876 // Clean up custom context menu items for this guest. | 986 // 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, | 1514 bool allow, |
1405 const std::string& user_input) { | 1515 const std::string& user_input) { |
1406 WebViewGuest* guest = | 1516 WebViewGuest* guest = |
1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1517 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1408 if (!guest) | 1518 if (!guest) |
1409 return; | 1519 return; |
1410 | 1520 |
1411 if (!allow) | 1521 if (!allow) |
1412 guest->Destroy(); | 1522 guest->Destroy(); |
1413 } | 1523 } |
OLD | NEW |