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 | |
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
24 files changed, 51 insertions, 37 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 90a4e59..074d832 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -645,7 +645,7 @@ TabContents* Browser::AddRestoredTab( bool select, bool pin) { TabContents* new_tab = new TabContents(profile(), NULL, - MSG_ROUTING_NONE, NULL); + MSG_ROUTING_NONE, NULL, tabstrip_model_.GetSelectedTabContents()); new_tab->controller().RestoreFromState(navigations, selected_navigation); bool really_pin = @@ -667,7 +667,7 @@ void Browser::ReplaceRestoredTab( const std::vector<TabNavigation>& navigations, int selected_navigation) { TabContents* replacement = new TabContents(profile(), NULL, - MSG_ROUTING_NONE, NULL); + MSG_ROUTING_NONE, NULL, tabstrip_model_.GetSelectedTabContents()); replacement->controller().RestoreFromState(navigations, selected_navigation); tabstrip_model_.ReplaceNavigationControllerAt( @@ -1578,7 +1578,7 @@ TabContents* Browser::CreateTabContentsForURL( PageTransition::Type transition, bool defer_load, SiteInstance* instance) const { TabContents* contents = new TabContents(profile, instance, - MSG_ROUTING_NONE, NULL); + MSG_ROUTING_NONE, NULL, tabstrip_model_.GetSelectedTabContents()); if (!defer_load) { // Load the initial URL before adding the new tab contents to the tab strip @@ -2604,7 +2604,7 @@ TabContents* Browser::BuildRestoredTab( // Create a NavigationController. This constructor creates the appropriate // set of TabContents. TabContents* new_tab = new TabContents(profile_, NULL, - MSG_ROUTING_NONE, NULL); + MSG_ROUTING_NONE, NULL, tabstrip_model_.GetSelectedTabContents()); new_tab->controller().RestoreFromState(navigations, selected_navigation); return new_tab; } else { diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index 75fb4fe..4095273 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -51,7 +51,8 @@ DevToolsWindow::DevToolsWindow(Profile* profile, inspected_window_(NULL), docked_(docked) { // Create TabContents with devtools. - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); + tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, + NULL); GURL url(std::string(chrome::kChromeUIDevToolsURL) + "devtools.html"); tab_contents_->render_view_host()->AllowBindings(BindingsPolicy::DOM_UI); tab_contents_->controller().LoadURL(url, GURL(), PageTransition::START_PAGE); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index c83bb46..489ce56 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -10,6 +10,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/debugger/devtools_manager.h" +#include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/profile.h" @@ -271,7 +272,7 @@ void ExtensionHost::CreateNewWindow(int route_id, base::WaitableEvent* modal_dialog_event) { delegate_view_helper_.CreateNewWindow( route_id, modal_dialog_event, render_view_host()->process()->profile(), - site_instance(), DOMUIFactory::GetDOMUIType(url_)); + site_instance(), DOMUIFactory::GetDOMUIType(url_), NULL); } void ExtensionHost::CreateNewWidget(int route_id, bool activatable) { diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index b478f14..b4bd12b 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -90,7 +90,8 @@ bool ExternalTabContainer::Init(Profile* profile, tab_contents_ = existing_contents; tab_contents_->controller().set_profile(profile); } else { - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); + tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, + NULL); } tab_contents_->set_delegate(this); diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index 0f680bc..0440820 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -400,6 +400,7 @@ void RenderWidgetHostViewGtk::SetSize(const gfx::Size& size) { // children. gtk_widget_set_size_request(view_.get(), width, height); #endif + requested_size_ = gfx::Size(width, height); host_->WasResized(); } diff --git a/chrome/browser/renderer_host/test/site_instance_unittest.cc b/chrome/browser/renderer_host/test/site_instance_unittest.cc index 0320152..24b269e 100644 --- a/chrome/browser/renderer_host/test/site_instance_unittest.cc +++ b/chrome/browser/renderer_host/test/site_instance_unittest.cc @@ -116,7 +116,7 @@ TEST_F(SiteInstanceTest, SiteInstanceDestructor) { &siteDeleteCounter, &browsingDeleteCounter); { - TabContents contents(profile.get(), instance, MSG_ROUTING_NONE, NULL); + TabContents contents(profile.get(), instance, MSG_ROUTING_NONE, NULL, NULL); EXPECT_EQ(1, siteDeleteCounter); EXPECT_EQ(1, browsingDeleteCounter); } 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) { } diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index bc2eaa8..afa1880 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -79,7 +79,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate { class TabStripModelTest : public RenderViewHostTestHarness { public: TabContents* CreateTabContents() { - return new TabContents(profile(), NULL, 0, NULL); + return new TabContents(profile(), NULL, 0, NULL, NULL); } // Forwards a URL "load" request through to our dummy TabContents @@ -1006,7 +1006,7 @@ TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { // Added for http://b/issue?id=958960 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { - TabContents fake_destinations_tab(profile(), NULL, 0, NULL); + TabContents fake_destinations_tab(profile(), NULL, 0, NULL, NULL); TabStripDummyDelegate delegate(&fake_destinations_tab); TabStripModel tabstrip(&delegate, profile()); EXPECT_TRUE(tabstrip.empty()); diff --git a/chrome/browser/views/dom_view.cc b/chrome/browser/views/dom_view.cc index 322281e..c8cebf7 100644 --- a/chrome/browser/views/dom_view.cc +++ b/chrome/browser/views/dom_view.cc @@ -22,7 +22,7 @@ bool DOMView::Init(Profile* profile, SiteInstance* instance) { initialized_ = true; tab_contents_.reset(new TabContents(profile, instance, - MSG_ROUTING_NONE, NULL)); + MSG_ROUTING_NONE, NULL, NULL)); views::NativeViewHost::Attach(tab_contents_->GetNativeView()); return true; } diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index e39bfde..6a4f76c 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -117,9 +117,10 @@ TabContentsViewGtk::~TabContentsViewGtk() { CloseNow(); } -void TabContentsViewGtk::CreateView() { +void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { set_delete_on_destroy(false); - WidgetGtk::Init(NULL, gfx::Rect()); + WidgetGtk::Init(NULL, gfx::Rect(0, 0, initial_size.width(), + initial_size.height())); } RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h index 8788468..1b03885 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h @@ -31,7 +31,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); virtual gfx::NativeView GetNativeView() const; diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 9d22dbf..22a1552 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -86,7 +86,7 @@ void TabContentsViewWin::Unparent() { ::SetParent(GetNativeView(), NULL); } -void TabContentsViewWin::CreateView() { +void TabContentsViewWin::CreateView(const gfx::Size& initial_size) { set_delete_on_destroy(false); // Since we create these windows parented to the desktop window initially, we // don't want to create them initially visible. diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.h b/chrome/browser/views/tab_contents/tab_contents_view_win.h index 479f3c4..cf52294 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.h @@ -34,7 +34,7 @@ class TabContentsViewWin : 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; |