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

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

Issue 427883002: <webview>: Move autosize from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_frame_url
Patch Set: Initialize variable Created 6 years, 4 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"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SetUpAutoSize();
301
300 std::string name; 302 std::string name;
301 if (extra_params()->GetString(webview::kName, &name)) { 303 if (extra_params()->GetString(webview::kName, &name)) {
302 // If the guest window's name is empty, then the WebView tag's name is 304 // 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 305 // assigned. Otherwise, the guest window's name takes precedence over the
304 // WebView tag's name. 306 // WebView tag's name.
305 if (name_.empty()) 307 if (name_.empty())
306 name_ = name; 308 name_ = name;
307 } 309 }
308 ReportFrameNameChange(name_); 310 ReportFrameNameChange(name_);
309 311
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void WebViewGuest::GuestDestroyed() { 417 void WebViewGuest::GuestDestroyed() {
416 // Clean up custom context menu items for this guest. 418 // Clean up custom context menu items for this guest.
417 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( 419 extensions::MenuManager* menu_manager = extensions::MenuManager::Get(
418 Profile::FromBrowserContext(browser_context())); 420 Profile::FromBrowserContext(browser_context()));
419 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( 421 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey(
420 embedder_extension_id(), view_instance_id())); 422 embedder_extension_id(), view_instance_id()));
421 423
422 RemoveWebViewStateFromIOThread(web_contents()); 424 RemoveWebViewStateFromIOThread(web_contents());
423 } 425 }
424 426
427 void WebViewGuest::GuestReady() {
428 // The guest RenderView should always live in an isolated guest process.
429 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
430 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
431 }
432
433 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
434 const gfx::Size& new_size) {
435 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
436 args->SetInteger(webview::kOldHeight, old_size.height());
437 args->SetInteger(webview::kOldWidth, old_size.width());
438 args->SetInteger(webview::kNewHeight, new_size.height());
439 args->SetInteger(webview::kNewWidth, new_size.width());
440 DispatchEventToEmbedder(
441 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass()));
442 }
443
444 bool WebViewGuest::IsAutoSizeSupported() const {
445 return true;
446 }
447
425 bool WebViewGuest::IsDragAndDropEnabled() const { 448 bool WebViewGuest::IsDragAndDropEnabled() const {
426 return true; 449 return true;
427 } 450 }
428 451
429 void WebViewGuest::WillDestroy() { 452 void WebViewGuest::WillDestroy() {
430 if (!attached() && GetOpener()) 453 if (!attached() && GetOpener())
431 GetOpener()->pending_new_windows_.erase(this); 454 GetOpener()->pending_new_windows_.erase(this);
432 DestroyUnattachedWindows(); 455 DestroyUnattachedWindows();
433 } 456 }
434 457
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 return; 814 return;
792 content::NavigationController& controller = 815 content::NavigationController& controller =
793 guest_web_contents()->GetController(); 816 guest_web_contents()->GetController();
794 content::NavigationEntry* entry = controller.GetVisibleEntry(); 817 content::NavigationEntry* entry = controller.GetVisibleEntry();
795 if (!entry) 818 if (!entry)
796 return; 819 return;
797 entry->SetIsOverridingUserAgent(!user_agent.empty()); 820 entry->SetIsOverridingUserAgent(!user_agent.empty());
798 guest_web_contents()->GetController().Reload(false); 821 guest_web_contents()->GetController().Reload(false);
799 } 822 }
800 823
801 void WebViewGuest::RenderViewReady() {
802 // The guest RenderView should always live in an isolated guest process.
803 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
804 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
805 }
806
807 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 824 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
808 name_ = name; 825 name_ = name;
809 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 826 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
810 args->SetString(webview::kName, name); 827 args->SetString(webview::kName, name);
811 DispatchEventToEmbedder( 828 DispatchEventToEmbedder(
812 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); 829 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass()));
813 } 830 }
814 831
815 void WebViewGuest::LoadHandlerCalled() { 832 void WebViewGuest::LoadHandlerCalled() {
816 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 833 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 const content::WebContents::CreateParams& create_params) { 890 const content::WebContents::CreateParams& create_params) {
874 GuestViewManager* guest_manager = 891 GuestViewManager* guest_manager =
875 GuestViewManager::FromBrowserContext(browser_context()); 892 GuestViewManager::FromBrowserContext(browser_context());
876 return guest_manager->CreateGuestWithWebContentsParams( 893 return guest_manager->CreateGuestWithWebContentsParams(
877 WebViewGuest::Type, 894 WebViewGuest::Type,
878 embedder_extension_id(), 895 embedder_extension_id(),
879 embedder_web_contents()->GetRenderProcessHost()->GetID(), 896 embedder_web_contents()->GetRenderProcessHost()->GetID(),
880 create_params); 897 create_params);
881 } 898 }
882 899
883 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
884 const gfx::Size& new_size) {
885 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
886 args->SetInteger(webview::kOldHeight, old_size.height());
887 args->SetInteger(webview::kOldWidth, old_size.width());
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 }
893
894 void WebViewGuest::RequestMediaAccessPermission( 900 void WebViewGuest::RequestMediaAccessPermission(
895 content::WebContents* source, 901 content::WebContents* source,
896 const content::MediaStreamRequest& request, 902 const content::MediaStreamRequest& request,
897 const content::MediaResponseCallback& callback) { 903 const content::MediaResponseCallback& callback) {
898 web_view_permission_helper_->RequestMediaAccessPermission(source, 904 web_view_permission_helper_->RequestMediaAccessPermission(source,
899 request, 905 request,
900 callback); 906 callback);
901 } 907 }
902 908
903 void WebViewGuest::CanDownload( 909 void WebViewGuest::CanDownload(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 1051
1046 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { 1052 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
1047 Go(1); 1053 Go(1);
1048 return true; 1054 return true;
1049 } 1055 }
1050 #endif 1056 #endif
1051 1057
1052 return false; 1058 return false;
1053 } 1059 }
1054 1060
1061 void WebViewGuest::SetUpAutoSize() {
1062 // Read the autosize parameters passed in from the embedder.
1063 bool auto_size_enabled = false;
1064 extra_params()->GetBoolean(webview::kAttributeAutoSize, &auto_size_enabled);
1065
1066 int max_height = 0;
1067 int max_width = 0;
1068 extra_params()->GetInteger(webview::kAttributeMaxHeight, &max_height);
1069 extra_params()->GetInteger(webview::kAttributeMaxWidth, &max_width);
1070
1071 int min_height = 0;
1072 int min_width = 0;
1073 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height);
1074 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width);
1075
1076 // Call SetAutoSize to apply all the appropriate validation and clipping of
1077 // values.
1078 SetAutoSize(auto_size_enabled,
1079 gfx::Size(min_width, min_height),
1080 gfx::Size(max_width, max_height));
1081 }
1082
1055 void WebViewGuest::ShowContextMenu(int request_id, 1083 void WebViewGuest::ShowContextMenu(int request_id,
1056 const MenuItemVector* items) { 1084 const MenuItemVector* items) {
1057 if (!pending_menu_.get()) 1085 if (!pending_menu_.get())
1058 return; 1086 return;
1059 1087
1060 // Make sure this was the correct request. 1088 // Make sure this was the correct request.
1061 if (request_id != pending_context_menu_request_id_) 1089 if (request_id != pending_context_menu_request_id_)
1062 return; 1090 return;
1063 1091
1064 // TODO(lazyboy): Implement. 1092 // TODO(lazyboy): Implement.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 bool allow, 1267 bool allow,
1240 const std::string& user_input) { 1268 const std::string& user_input) {
1241 WebViewGuest* guest = 1269 WebViewGuest* guest =
1242 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1270 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1243 if (!guest) 1271 if (!guest)
1244 return; 1272 return;
1245 1273
1246 if (!allow) 1274 if (!allow)
1247 guest->Destroy(); 1275 guest->Destroy();
1248 } 1276 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | chrome/common/extensions/api/guest_view_internal.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698