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

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

Issue 446823002: Revert 287732 "<webview>: Move autosize from content to chrome." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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
302 std::string name; 300 std::string name;
303 if (extra_params()->GetString(webview::kName, &name)) { 301 if (extra_params()->GetString(webview::kName, &name)) {
304 // If the guest window's name is empty, then the WebView tag's name is 302 // If the guest window's name is empty, then the WebView tag's name is
305 // assigned. Otherwise, the guest window's name takes precedence over the 303 // assigned. Otherwise, the guest window's name takes precedence over the
306 // WebView tag's name. 304 // WebView tag's name.
307 if (name_.empty()) 305 if (name_.empty())
308 name_ = name; 306 name_ = name;
309 } 307 }
310 ReportFrameNameChange(name_); 308 ReportFrameNameChange(name_);
311 309
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 void WebViewGuest::GuestDestroyed() { 415 void WebViewGuest::GuestDestroyed() {
418 // Clean up custom context menu items for this guest. 416 // Clean up custom context menu items for this guest.
419 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( 417 extensions::MenuManager* menu_manager = extensions::MenuManager::Get(
420 Profile::FromBrowserContext(browser_context())); 418 Profile::FromBrowserContext(browser_context()));
421 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( 419 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey(
422 embedder_extension_id(), view_instance_id())); 420 embedder_extension_id(), view_instance_id()));
423 421
424 RemoveWebViewStateFromIOThread(web_contents()); 422 RemoveWebViewStateFromIOThread(web_contents());
425 } 423 }
426 424
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
448 bool WebViewGuest::IsDragAndDropEnabled() const { 425 bool WebViewGuest::IsDragAndDropEnabled() const {
449 return true; 426 return true;
450 } 427 }
451 428
452 void WebViewGuest::WillDestroy() { 429 void WebViewGuest::WillDestroy() {
453 if (!attached() && GetOpener()) 430 if (!attached() && GetOpener())
454 GetOpener()->pending_new_windows_.erase(this); 431 GetOpener()->pending_new_windows_.erase(this);
455 DestroyUnattachedWindows(); 432 DestroyUnattachedWindows();
456 } 433 }
457 434
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 return; 791 return;
815 content::NavigationController& controller = 792 content::NavigationController& controller =
816 guest_web_contents()->GetController(); 793 guest_web_contents()->GetController();
817 content::NavigationEntry* entry = controller.GetVisibleEntry(); 794 content::NavigationEntry* entry = controller.GetVisibleEntry();
818 if (!entry) 795 if (!entry)
819 return; 796 return;
820 entry->SetIsOverridingUserAgent(!user_agent.empty()); 797 entry->SetIsOverridingUserAgent(!user_agent.empty());
821 guest_web_contents()->GetController().Reload(false); 798 guest_web_contents()->GetController().Reload(false);
822 } 799 }
823 800
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
824 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 807 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
825 name_ = name; 808 name_ = name;
826 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 809 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
827 args->SetString(webview::kName, name); 810 args->SetString(webview::kName, name);
828 DispatchEventToEmbedder( 811 DispatchEventToEmbedder(
829 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); 812 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass()));
830 } 813 }
831 814
832 void WebViewGuest::LoadHandlerCalled() { 815 void WebViewGuest::LoadHandlerCalled() {
833 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 816 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 const content::WebContents::CreateParams& create_params) { 873 const content::WebContents::CreateParams& create_params) {
891 GuestViewManager* guest_manager = 874 GuestViewManager* guest_manager =
892 GuestViewManager::FromBrowserContext(browser_context()); 875 GuestViewManager::FromBrowserContext(browser_context());
893 return guest_manager->CreateGuestWithWebContentsParams( 876 return guest_manager->CreateGuestWithWebContentsParams(
894 WebViewGuest::Type, 877 WebViewGuest::Type,
895 embedder_extension_id(), 878 embedder_extension_id(),
896 embedder_web_contents()->GetRenderProcessHost()->GetID(), 879 embedder_web_contents()->GetRenderProcessHost()->GetID(),
897 create_params); 880 create_params);
898 } 881 }
899 882
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
900 void WebViewGuest::RequestMediaAccessPermission( 894 void WebViewGuest::RequestMediaAccessPermission(
901 content::WebContents* source, 895 content::WebContents* source,
902 const content::MediaStreamRequest& request, 896 const content::MediaStreamRequest& request,
903 const content::MediaResponseCallback& callback) { 897 const content::MediaResponseCallback& callback) {
904 web_view_permission_helper_->RequestMediaAccessPermission(source, 898 web_view_permission_helper_->RequestMediaAccessPermission(source,
905 request, 899 request,
906 callback); 900 callback);
907 } 901 }
908 902
909 void WebViewGuest::CanDownload( 903 void WebViewGuest::CanDownload(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1045
1052 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { 1046 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
1053 Go(1); 1047 Go(1);
1054 return true; 1048 return true;
1055 } 1049 }
1056 #endif 1050 #endif
1057 1051
1058 return false; 1052 return false;
1059 } 1053 }
1060 1054
1061 void WebViewGuest::SetUpAutoSize() {
1062 // Read the autosize parameters passed in from the embedder.
1063 bool auto_size_enabled;
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
1083 void WebViewGuest::ShowContextMenu(int request_id, 1055 void WebViewGuest::ShowContextMenu(int request_id,
1084 const MenuItemVector* items) { 1056 const MenuItemVector* items) {
1085 if (!pending_menu_.get()) 1057 if (!pending_menu_.get())
1086 return; 1058 return;
1087 1059
1088 // Make sure this was the correct request. 1060 // Make sure this was the correct request.
1089 if (request_id != pending_context_menu_request_id_) 1061 if (request_id != pending_context_menu_request_id_)
1090 return; 1062 return;
1091 1063
1092 // TODO(lazyboy): Implement. 1064 // TODO(lazyboy): Implement.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 bool allow, 1239 bool allow,
1268 const std::string& user_input) { 1240 const std::string& user_input) {
1269 WebViewGuest* guest = 1241 WebViewGuest* guest =
1270 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1242 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1271 if (!guest) 1243 if (!guest)
1272 return; 1244 return;
1273 1245
1274 if (!allow) 1246 if (!allow)
1275 guest->Destroy(); 1247 guest->Destroy();
1276 } 1248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698