diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 17:07:23 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 17:07:23 +0000 |
commit | 34ac70504d7090a9689c78fbcadd1a1224fc9cdd (patch) | |
tree | 67aed39edc366610a7f3e56f057d8e7916e6975d /chrome/browser/tab_contents | |
parent | 43d4bfc54a2d1ef06281acbb0456f04dcae81c18 (diff) | |
download | chromium_src-34ac70504d7090a9689c78fbcadd1a1224fc9cdd.zip chromium_src-34ac70504d7090a9689c78fbcadd1a1224fc9cdd.tar.gz chromium_src-34ac70504d7090a9689c78fbcadd1a1224fc9cdd.tar.bz2 |
Allow the initial size of TabContentViews to be based on the
size of another TabContents by having an optional TabContents*
passed into the TabContents ctor.
This fixes a race condition where it's possible for a web
page to load before getting the sizing information from the
browser. The new flow passes the size information to the
renderer process before passing the URL to load.
BUG=20159
Review URL: http://codereview.chromium.org/201130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27199 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
12 files changed, 30 insertions, 21 deletions
diff --git a/chrome/browser/tab_contents/navigation_controller_unittest.cc b/chrome/browser/tab_contents/navigation_controller_unittest.cc index 24e2d7b..deae8c0 100644 --- a/chrome/browser/tab_contents/navigation_controller_unittest.cc +++ b/chrome/browser/tab_contents/navigation_controller_unittest.cc @@ -1148,7 +1148,7 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { navigations.push_back(TabNavigation(0, url, GURL(), ASCIIToUTF16("Title"), "state", PageTransition::LINK)); - TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL); + TabContents our_contents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); NavigationController& our_controller = our_contents.controller(); our_controller.RestoreFromState(navigations, 0); our_controller.GoToIndex(0); diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc index e61e0f7..2d5c359 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc @@ -21,14 +21,15 @@ void RenderViewHostDelegateViewHelper::CreateNewWindow(int route_id, base::WaitableEvent* modal_dialog_event, Profile* profile, - SiteInstance* site, DOMUITypeID domui_type) { + SiteInstance* site, DOMUITypeID domui_type, TabContents* old_tab_contents) { // Create the new web contents. This will automatically create the new // TabContentsView. In the future, we may want to create the view separately. TabContents* new_contents = new TabContents(profile, site, route_id, - modal_dialog_event); + modal_dialog_event, + old_tab_contents); new_contents->set_opener_dom_ui_type(domui_type); TabContentsView* new_view = new_contents->view(); diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.h b/chrome/browser/tab_contents/render_view_host_delegate_helper.h index 215cddcc..a55e222 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.h +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.h @@ -32,8 +32,10 @@ class RenderViewHostDelegateViewHelper { virtual void CreateNewWindow(int route_id, base::WaitableEvent* modal_dialog_event, - Profile* profile, SiteInstance* site, - DOMUITypeID domui_type); + Profile* profile, + SiteInstance* site, + DOMUITypeID domui_type, + TabContents* old_tab_contents); virtual RenderWidgetHostView* CreateNewWidget(int route_id, bool activatable, RenderProcessHost* process); virtual TabContents* GetCreatedWindow(int route_id); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 2483d47..a28ccf1 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -213,7 +213,8 @@ class TabContents::GearsCreateShortcutCallbackFunctor { TabContents::TabContents(Profile* profile, SiteInstance* site_instance, int routing_id, - base::WaitableEvent* modal_dialog_event) + base::WaitableEvent* modal_dialog_event, + const TabContents* base_tab_contents) : delegate_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)), ALLOW_THIS_IN_INITIALIZER_LIST(view_( @@ -276,7 +277,10 @@ TabContents::TabContents(Profile* profile, render_manager_.Init(profile, site_instance, routing_id, modal_dialog_event); - view_->CreateView(); + // We have the initial size of the view be based on the size of the passed in + // tab contents (normally a tab from the same window). + view_->CreateView(base_tab_contents ? + base_tab_contents->view()->GetContainerSize() : gfx::Size()); // Register for notifications about all interested prefs change. PrefService* prefs = profile->GetPrefs(); @@ -751,7 +755,7 @@ TabContents* TabContents::Clone() { // processes for some reason. TabContents* tc = new TabContents(profile(), SiteInstance::CreateSiteInstance(profile()), - MSG_ROUTING_NONE, NULL); + MSG_ROUTING_NONE, NULL, this); tc->controller().CopyStateFrom(controller_); return tc; } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 1d39921..4faba02 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -113,10 +113,13 @@ class TabContents : public PageNavigator, INVALIDATE_EVERYTHING = 0xFFFFFFFF }; + // |base_tab_contents| is used if we want to size the new tab contents view + // based on an existing tab contents view. This can be NULL if not needed. TabContents(Profile* profile, SiteInstance* site_instance, int routing_id, - base::WaitableEvent* modal_dialog_event); + base::WaitableEvent* modal_dialog_event, + const TabContents* base_tab_contents); virtual ~TabContents(); static void RegisterUserPrefs(PrefService* prefs); diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index ecdf697..df09b21 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -15,9 +15,6 @@ TabContentsView::TabContentsView(TabContents* tab_contents) preferred_width_(0) { } -void TabContentsView::CreateView() { -} - void TabContentsView::RenderWidgetHostDestroyed(RenderWidgetHost* host) { delegate_view_helper_.RenderWidgetHostDestroyed(host); } @@ -35,7 +32,7 @@ void TabContentsView::CreateNewWindow(int route_id, delegate_view_helper_.CreateNewWindow( route_id, modal_dialog_event, tab_contents_->profile(), tab_contents_->GetSiteInstance(), - DOMUIFactory::GetDOMUIType(tab_contents_->GetURL())); + DOMUIFactory::GetDOMUIType(tab_contents_->GetURL()), tab_contents_); } void TabContentsView::CreateNewWidget(int route_id, bool activatable) { diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index abb7cf3..a83d4dd 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -45,7 +45,7 @@ class TabContentsView : public RenderViewHostDelegate::View { TabContents* tab_contents() const { return tab_contents_; } - virtual void CreateView() = 0; + virtual void CreateView(const gfx::Size& initial_size) = 0; // Sets up the View that holds the rendered web page, receives messages for // it and contains page plugins. The host view should be sized to the current diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 32ac7cf..c85060b 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -406,9 +406,10 @@ void TabContentsViewGtk::RemoveConstrainedWindow( constrained_windows_.erase(item); } -void TabContentsViewGtk::CreateView() { - // Windows uses this to do initialization, but we do all our initialization - // in the constructor. +void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { + requested_size_ = initial_size; + gtk_widget_set_size_request(fixed_, requested_size_.width(), + requested_size_.height()); } RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( @@ -636,6 +637,7 @@ gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, if (view->tab_contents()->delegate()) height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); gfx::Size size(width, height); + view->requested_size_ = size; gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); return FALSE; diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 12bc936..3e777b8 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -46,7 +46,7 @@ class TabContentsViewGtk : public TabContentsView, // TabContentsView implementation -------------------------------------------- - virtual void CreateView(); + virtual void CreateView(const gfx::Size& initial_size); virtual RenderWidgetHostView* CreateViewForWidget( RenderWidgetHost* render_widget_host); diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index c9151378..a7ee015 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -47,7 +47,7 @@ class TabContentsViewMac : public TabContentsView, // TabContentsView implementation -------------------------------------------- - virtual void CreateView(); + virtual void CreateView(const gfx::Size& initial_size); virtual RenderWidgetHostView* CreateViewForWidget( RenderWidgetHost* render_widget_host); virtual gfx::NativeView GetNativeView() const; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 1dad0a5..c560fb6 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -58,7 +58,7 @@ TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) Source<TabContents>(tab_contents)); } -void TabContentsViewMac::CreateView() { +void TabContentsViewMac::CreateView(const gfx::Size& initial_size) { TabContentsViewCocoa* view = [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this]; cocoa_view_.reset(view); diff --git a/chrome/browser/tab_contents/test_tab_contents.cc b/chrome/browser/tab_contents/test_tab_contents.cc index 97643f3..904c780 100644 --- a/chrome/browser/tab_contents/test_tab_contents.cc +++ b/chrome/browser/tab_contents/test_tab_contents.cc @@ -7,7 +7,7 @@ #include "chrome/browser/renderer_host/test/test_render_view_host.h" TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance) - : TabContents(profile, instance, MSG_ROUTING_NONE, NULL), + : TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL), transition_cross_site(false) { } |