Chromium Code Reviews| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 embedder_render_process_host->GetBrowserContext(), guest_site); | 290 embedder_render_process_host->GetBrowserContext(), guest_site); |
| 291 } | 291 } |
| 292 WebContents::CreateParams params( | 292 WebContents::CreateParams params( |
| 293 embedder_render_process_host->GetBrowserContext(), | 293 embedder_render_process_host->GetBrowserContext(), |
| 294 guest_site_instance); | 294 guest_site_instance); |
| 295 params.guest_delegate = this; | 295 params.guest_delegate = this; |
| 296 callback.Run(WebContents::Create(params)); | 296 callback.Run(WebContents::Create(params)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void WebViewGuest::DidAttachToEmbedder() { | 299 void WebViewGuest::DidAttachToEmbedder() { |
| 300 extra_params()->GetBoolean(webview::kAttributeAutoSize, &auto_size_enabled_); | |
| 301 | |
| 302 int max_height = 0; | |
| 303 int max_width = 0; | |
| 304 extra_params()->GetInteger(webview::kAttributeMaxHeight, &max_height); | |
|
lazyboy
2014/07/31 04:24:22
Do we need to DCHECK if GetInteger() returns true/
Fady Samuel
2014/08/01 18:12:52
Well we just rely on these being the default value
| |
| 305 extra_params()->GetInteger(webview::kAttributeMaxWidth, &max_width); | |
| 306 max_auto_size_.SetSize(max_width, max_height); | |
| 307 | |
| 308 int min_height = 0; | |
| 309 int min_width = 0; | |
| 310 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); | |
| 311 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); | |
| 312 min_auto_size_.SetSize(min_width, min_height); | |
| 313 | |
| 300 std::string name; | 314 std::string name; |
| 301 if (extra_params()->GetString(webview::kName, &name)) { | 315 if (extra_params()->GetString(webview::kName, &name)) { |
| 302 // If the guest window's name is empty, then the WebView tag's name is | 316 // If the guest window's name is empty, then the WebView tag's name is |
| 303 // assigned. Otherwise, the guest window's name takes precedence over the | 317 // assigned. Otherwise, the guest window's name takes precedence over the |
| 304 // WebView tag's name. | 318 // WebView tag's name. |
| 305 if (name_.empty()) | 319 if (name_.empty()) |
| 306 name_ = name; | 320 name_ = name; |
| 307 } | 321 } |
| 308 ReportFrameNameChange(name_); | 322 ReportFrameNameChange(name_); |
| 309 | 323 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 } | 707 } |
| 694 | 708 |
| 695 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, | 709 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
| 696 int guest_instance_id) | 710 int guest_instance_id) |
| 697 : GuestView<WebViewGuest>(browser_context, guest_instance_id), | 711 : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
| 698 pending_context_menu_request_id_(0), | 712 pending_context_menu_request_id_(0), |
| 699 is_overriding_user_agent_(false), | 713 is_overriding_user_agent_(false), |
| 700 chromevox_injected_(false), | 714 chromevox_injected_(false), |
| 701 current_zoom_factor_(1.0), | 715 current_zoom_factor_(1.0), |
| 702 find_helper_(this), | 716 find_helper_(this), |
| 703 javascript_dialog_helper_(this) { | 717 javascript_dialog_helper_(this), |
| 718 auto_size_enabled_(false) { | |
| 704 } | 719 } |
| 705 | 720 |
| 706 WebViewGuest::~WebViewGuest() { | 721 WebViewGuest::~WebViewGuest() { |
| 707 } | 722 } |
| 708 | 723 |
| 709 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 724 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 710 content::RenderFrameHost* render_frame_host, | 725 content::RenderFrameHost* render_frame_host, |
| 711 const GURL& url, | 726 const GURL& url, |
| 712 content::PageTransition transition_type) { | 727 content::PageTransition transition_type) { |
| 713 find_helper_.CancelAllFindSessions(); | 728 find_helper_.CancelAllFindSessions(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 if (!entry) | 810 if (!entry) |
| 796 return; | 811 return; |
| 797 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 812 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| 798 guest_web_contents()->GetController().Reload(false); | 813 guest_web_contents()->GetController().Reload(false); |
| 799 } | 814 } |
| 800 | 815 |
| 801 void WebViewGuest::RenderViewReady() { | 816 void WebViewGuest::RenderViewReady() { |
| 802 // The guest RenderView should always live in an isolated guest process. | 817 // The guest RenderView should always live in an isolated guest process. |
| 803 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 818 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| 804 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); | 819 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); |
| 820 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | |
| 821 if (auto_size_enabled_) | |
| 822 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | |
| 823 else | |
| 824 rvh->DisableAutoResize(element_size_); | |
| 825 | |
| 805 } | 826 } |
| 806 | 827 |
| 807 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | 828 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
| 808 name_ = name; | 829 name_ = name; |
| 809 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 830 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 810 args->SetString(webview::kName, name); | 831 args->SetString(webview::kName, name); |
| 811 DispatchEventToEmbedder( | 832 DispatchEventToEmbedder( |
| 812 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | 833 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
| 813 } | 834 } |
| 814 | 835 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 const content::WebContents::CreateParams& create_params) { | 894 const content::WebContents::CreateParams& create_params) { |
| 874 GuestViewManager* guest_manager = | 895 GuestViewManager* guest_manager = |
| 875 GuestViewManager::FromBrowserContext(browser_context()); | 896 GuestViewManager::FromBrowserContext(browser_context()); |
| 876 return guest_manager->CreateGuestWithWebContentsParams( | 897 return guest_manager->CreateGuestWithWebContentsParams( |
| 877 WebViewGuest::Type, | 898 WebViewGuest::Type, |
| 878 embedder_extension_id(), | 899 embedder_extension_id(), |
| 879 embedder_web_contents()->GetRenderProcessHost()->GetID(), | 900 embedder_web_contents()->GetRenderProcessHost()->GetID(), |
| 880 create_params); | 901 create_params); |
| 881 } | 902 } |
| 882 | 903 |
| 883 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 904 void WebViewGuest::GuestSizeChanged(const gfx::Size& old_size, |
| 884 const gfx::Size& new_size) { | 905 const gfx::Size& new_size) { |
| 885 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 906 if (!auto_size_enabled_) |
| 886 args->SetInteger(webview::kOldHeight, old_size.height()); | 907 return; |
| 887 args->SetInteger(webview::kOldWidth, old_size.width()); | 908 DispatchSizeChangedEvent(old_size, new_size); |
| 888 args->SetInteger(webview::kNewHeight, new_size.height()); | |
| 889 args->SetInteger(webview::kNewWidth, new_size.width()); | |
| 890 DispatchEventToEmbedder( | |
| 891 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | |
| 892 } | 909 } |
| 893 | 910 |
| 894 void WebViewGuest::RequestMediaAccessPermission( | 911 void WebViewGuest::RequestMediaAccessPermission( |
| 895 content::WebContents* source, | 912 content::WebContents* source, |
| 896 const content::MediaStreamRequest& request, | 913 const content::MediaStreamRequest& request, |
| 897 const content::MediaResponseCallback& callback) { | 914 const content::MediaResponseCallback& callback) { |
| 898 web_view_permission_helper_->RequestMediaAccessPermission(source, | 915 web_view_permission_helper_->RequestMediaAccessPermission(source, |
| 899 request, | 916 request, |
| 900 callback); | 917 callback); |
| 901 } | 918 } |
| 902 | 919 |
| 903 void WebViewGuest::CanDownload( | 920 void WebViewGuest::CanDownload( |
| 904 content::RenderViewHost* render_view_host, | 921 content::RenderViewHost* render_view_host, |
| 905 const GURL& url, | 922 const GURL& url, |
| 906 const std::string& request_method, | 923 const std::string& request_method, |
| 907 const base::Callback<void(bool)>& callback) { | 924 const base::Callback<void(bool)>& callback) { |
| 908 web_view_permission_helper_->CanDownload(render_view_host, | 925 web_view_permission_helper_->CanDownload(render_view_host, |
| 909 url, | 926 url, |
| 910 request_method, | 927 request_method, |
| 911 callback); | 928 callback); |
| 912 } | 929 } |
| 913 | 930 |
| 931 void WebViewGuest::ElementSizeChanged(const gfx::Size& old_size, | |
| 932 const gfx::Size& new_size) { | |
| 933 element_size_ = new_size; | |
| 934 } | |
| 935 | |
| 914 void WebViewGuest::RequestPointerLockPermission( | 936 void WebViewGuest::RequestPointerLockPermission( |
| 915 bool user_gesture, | 937 bool user_gesture, |
| 916 bool last_unlocked_by_target, | 938 bool last_unlocked_by_target, |
| 917 const base::Callback<void(bool)>& callback) { | 939 const base::Callback<void(bool)>& callback) { |
| 918 web_view_permission_helper_->RequestPointerLockPermission( | 940 web_view_permission_helper_->RequestPointerLockPermission( |
| 919 user_gesture, | 941 user_gesture, |
| 920 last_unlocked_by_target, | 942 last_unlocked_by_target, |
| 921 callback); | 943 callback); |
| 922 } | 944 } |
| 923 | 945 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 944 } | 966 } |
| 945 | 967 |
| 946 void WebViewGuest::RunFileChooser(WebContents* web_contents, | 968 void WebViewGuest::RunFileChooser(WebContents* web_contents, |
| 947 const content::FileChooserParams& params) { | 969 const content::FileChooserParams& params) { |
| 948 if (!attached() || !embedder_web_contents()->GetDelegate()) | 970 if (!attached() || !embedder_web_contents()->GetDelegate()) |
| 949 return; | 971 return; |
| 950 | 972 |
| 951 embedder_web_contents()->GetDelegate()->RunFileChooser(web_contents, params); | 973 embedder_web_contents()->GetDelegate()->RunFileChooser(web_contents, params); |
| 952 } | 974 } |
| 953 | 975 |
| 976 void WebViewGuest::SetAutoSize(bool enabled, | |
| 977 const gfx::Size& min_size, | |
| 978 const gfx::Size& max_size) { | |
| 979 min_auto_size_ = gfx::Size(std::min(max_size.width(), min_size.width()), | |
| 980 std::min(max_size.height(), min_size.height())); | |
| 981 max_auto_size_ = gfx::Size(std::max(max_size.width(), min_size.width()), | |
| 982 std::max(max_size.height(), min_size.height())); | |
| 983 enabled &= !!max_auto_size_.width() && !!max_auto_size_.height(); | |
| 984 if (!enabled && !auto_size_enabled_) | |
| 985 return; | |
| 986 | |
| 987 auto_size_enabled_ = enabled; | |
| 988 | |
| 989 if (!attached()) | |
| 990 return; | |
| 991 | |
| 992 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | |
| 993 if (auto_size_enabled_) { | |
| 994 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | |
| 995 } else { | |
| 996 rvh->DisableAutoResize(element_size_); | |
| 997 DispatchSizeChangedEvent(guest_size_, element_size_); | |
| 998 } | |
| 999 } | |
| 1000 | |
| 954 void WebViewGuest::NavigateGuest(const std::string& src) { | 1001 void WebViewGuest::NavigateGuest(const std::string& src) { |
| 955 GURL url = ResolveURL(src); | 1002 GURL url = ResolveURL(src); |
| 956 | 1003 |
| 957 // Do not allow navigating a guest to schemes other than known safe schemes. | 1004 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 958 // This will block the embedder trying to load unwanted schemes, e.g. | 1005 // This will block the embedder trying to load unwanted schemes, e.g. |
| 959 // chrome://settings. | 1006 // chrome://settings. |
| 960 bool scheme_is_blocked = | 1007 bool scheme_is_blocked = |
| 961 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1008 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
| 962 url.scheme()) && | 1009 url.scheme()) && |
| 963 !url.SchemeIs(url::kAboutScheme)) || | 1010 !url.SchemeIs(url::kAboutScheme)) || |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 | 1092 |
| 1046 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { | 1093 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { |
| 1047 Go(1); | 1094 Go(1); |
| 1048 return true; | 1095 return true; |
| 1049 } | 1096 } |
| 1050 #endif | 1097 #endif |
| 1051 | 1098 |
| 1052 return false; | 1099 return false; |
| 1053 } | 1100 } |
| 1054 | 1101 |
| 1102 void WebViewGuest::DispatchSizeChangedEvent(const gfx::Size& old_size, | |
| 1103 const gfx::Size& new_size) { | |
| 1104 guest_size_ = new_size; | |
| 1105 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 1106 args->SetInteger(webview::kOldHeight, old_size.height()); | |
| 1107 args->SetInteger(webview::kOldWidth, old_size.width()); | |
| 1108 args->SetInteger(webview::kNewHeight, new_size.height()); | |
| 1109 args->SetInteger(webview::kNewWidth, new_size.width()); | |
| 1110 DispatchEventToEmbedder( | |
| 1111 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | |
| 1112 } | |
| 1113 | |
| 1055 void WebViewGuest::ShowContextMenu(int request_id, | 1114 void WebViewGuest::ShowContextMenu(int request_id, |
| 1056 const MenuItemVector* items) { | 1115 const MenuItemVector* items) { |
| 1057 if (!pending_menu_.get()) | 1116 if (!pending_menu_.get()) |
| 1058 return; | 1117 return; |
| 1059 | 1118 |
| 1060 // Make sure this was the correct request. | 1119 // Make sure this was the correct request. |
| 1061 if (request_id != pending_context_menu_request_id_) | 1120 if (request_id != pending_context_menu_request_id_) |
| 1062 return; | 1121 return; |
| 1063 | 1122 |
| 1064 // TODO(lazyboy): Implement. | 1123 // TODO(lazyboy): Implement. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1239 bool allow, | 1298 bool allow, |
| 1240 const std::string& user_input) { | 1299 const std::string& user_input) { |
| 1241 WebViewGuest* guest = | 1300 WebViewGuest* guest = |
| 1242 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1301 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1243 if (!guest) | 1302 if (!guest) |
| 1244 return; | 1303 return; |
| 1245 | 1304 |
| 1246 if (!allow) | 1305 if (!allow) |
| 1247 guest->Destroy(); | 1306 guest->Destroy(); |
| 1248 } | 1307 } |
| OLD | NEW |