diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-12 18:20:17 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-12 18:20:17 +0000 |
commit | 3fd84030164d46c4c5390bfc5ab98f452f4e2df4 (patch) | |
tree | e8a9a8dae170ca1381fa1ece0c44e39261c35743 | |
parent | 2f1fe2982fa83f9503538b73962aabaa59203db0 (diff) | |
download | chromium_src-3fd84030164d46c4c5390bfc5ab98f452f4e2df4.zip chromium_src-3fd84030164d46c4c5390bfc5ab98f452f4e2df4.tar.gz chromium_src-3fd84030164d46c4c5390bfc5ab98f452f4e2df4.tar.bz2 |
Now that TabContentsViewHelper is in content, make TabContentsViewWin use it instead of duplicating the code from it. This simplifies things a bit.
Review URL: http://codereview.chromium.org/9148061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117457 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc | 13 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.cc | 98 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.h | 12 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win_delegate.h | 32 | ||||
-rw-r--r-- | content/content_shell.gypi | 1 | ||||
-rw-r--r-- | content/shell/shell.cc | 38 | ||||
-rw-r--r-- | content/shell/shell.h | 7 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 17 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.h | 18 |
9 files changed, 110 insertions, 126 deletions
diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc index 699f31e..9d31ad1 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc @@ -17,19 +17,10 @@ using content::WebContents; namespace { -// Tabs must be created as child widgets, otherwise they will be given +// See comment above TempParent in tab_contents_view_win.cc. +// Also, Tabs must be created as child widgets, otherwise they will be given // a FocusManager which will conflict with the FocusManager of the // window they eventually end up attached to. -// -// A tab will not have a parent HWND whenever it is not active in its -// host window - for example at creation time and when it's in the -// background, so we provide a default widget to host them. -// -// It may be tempting to use GetDesktopWindow() instead, but this is -// problematic as the shell sends messages to children of the desktop -// window that interact poorly with us. -// -// See: http://crbug.com/16476 class HiddenTabHostWindow : public views::Widget { public: static HWND Instance(); diff --git a/content/browser/tab_contents/tab_contents_view_win.cc b/content/browser/tab_contents/tab_contents_view_win.cc index 98f7a54..3bd9d5c 100644 --- a/content/browser/tab_contents/tab_contents_view_win.cc +++ b/content/browser/tab_contents/tab_contents_view_win.cc @@ -5,17 +5,50 @@ #include "content/browser/tab_contents/tab_contents_view_win.h" #include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/renderer_host/render_view_host_factory.h" #include "content/browser/renderer_host/render_widget_host_view_win.h" #include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_view_win_delegate.h" #include "content/public/browser/web_contents_delegate.h" -TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents, - TabContentsViewWinDelegate* delegate) +namespace { + +// We need to have a parent window for the compositing code to work correctly. +// +// A tab will not have a parent HWND whenever it is not active in its +// host window - for example at creation time and when it's in the +// background, so we provide a default widget to host them. +// +// It may be tempting to use GetDesktopWindow() instead, but this is +// problematic as the shell sends messages to children of the desktop +// window that interact poorly with us. +// +// See: http://crbug.com/16476 +class TempParent : public ui::WindowImpl { + public: + static TempParent* Get() { + static TempParent* g_temp_parent; + if (!g_temp_parent) { + g_temp_parent = new TempParent(); + + g_temp_parent->set_window_style(WS_POPUP); + g_temp_parent->set_window_ex_style(WS_EX_TOOLWINDOW); + g_temp_parent->Init(GetDesktopWindow(), gfx::Rect()); + EnableWindow(g_temp_parent->hwnd(), FALSE); + } + return g_temp_parent; + } + + private: + BEGIN_MSG_MAP_EX(TabContentsViewWin) + END_MSG_MAP() +}; + +} // namespace namespace + +TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) : parent_(NULL), tab_contents_(tab_contents), - delegate_(delegate), view_(NULL) { } @@ -26,19 +59,28 @@ void TabContentsViewWin::SetParent(HWND parent) { DCHECK(!parent_); parent_ = parent; - set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); - - Init(parent_, gfx::Rect(initial_size_)); + ::SetParent(hwnd(), parent_); } void TabContentsViewWin::CreateView(const gfx::Size& initial_size) { initial_size_ = initial_size; + + set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); + + Init(TempParent::Get()->hwnd(), gfx::Rect(initial_size_)); } RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( RenderWidgetHost* render_widget_host) { - if (view_) - delete view_; // TODO(jam): need to do anything else? + if (render_widget_host->view()) { + // During testing, the view will already be set up in most cases to the + // test view, so we don't want to clobber it with a real one. To verify that + // this actually is happening (and somebody isn't accidentally creating the + // view twice), we check for the RVH Factory, which will be set when we're + // making special ones (which go along with the special views). + DCHECK(RenderViewHostFactory::has_factory()); + return render_widget_host->view(); + } view_ = new RenderWidgetHostViewWin(render_widget_host); view_->CreateWnd(GetNativeView()); @@ -160,45 +202,45 @@ void TabContentsViewWin::RemoveOverlayView() { void TabContentsViewWin::CreateNewWindow( int route_id, const ViewHostMsg_CreateWindow_Params& params) { - TabContents* tab = delegate_->CreateNewWindow(this, route_id, params); - - // Copy logic from RenderViewHostDelegateViewHelper. - TabContentsView* new_view = tab->GetView(); - new_view->CreateViewForWidget(tab->GetRenderViewHost()); - pending_contents_[route_id] = tab->GetRenderViewHost(); + tab_contents_view_helper_.CreateNewWindow(tab_contents_, route_id, params); } void TabContentsViewWin::CreateNewWidget(int route_id, WebKit::WebPopupType popup_type) { - NOTIMPLEMENTED(); + tab_contents_view_helper_.CreateNewWidget(tab_contents_, + route_id, + false, + popup_type); } void TabContentsViewWin::CreateNewFullscreenWidget(int route_id) { - NOTIMPLEMENTED(); + tab_contents_view_helper_.CreateNewWidget(tab_contents_, + route_id, + true, + WebKit::WebPopupTypeNone); } void TabContentsViewWin::ShowCreatedWindow(int route_id, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { - PendingContents::iterator iter = pending_contents_.find(route_id); - if (iter == pending_contents_.end()) - return; - - RenderViewHost* new_rvh = iter->second; - pending_contents_.erase(route_id); - if (!new_rvh->process()->HasConnection() || !new_rvh->view()) - return; - new_rvh->Init(); + tab_contents_view_helper_.ShowCreatedWindow( + tab_contents_, route_id, disposition, initial_pos, user_gesture); } void TabContentsViewWin::ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos) { - NOTIMPLEMENTED(); + tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, + route_id, + false, + initial_pos); } void TabContentsViewWin::ShowCreatedFullscreenWidget(int route_id) { - NOTIMPLEMENTED(); + tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, + route_id, + true, + gfx::Rect()); } void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { diff --git a/content/browser/tab_contents/tab_contents_view_win.h b/content/browser/tab_contents/tab_contents_view_win.h index f726eba..582ce48 100644 --- a/content/browser/tab_contents/tab_contents_view_win.h +++ b/content/browser/tab_contents/tab_contents_view_win.h @@ -6,20 +6,17 @@ #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_ #pragma once -#include <map> - #include "content/browser/tab_contents/tab_contents_view.h" +#include "content/browser/tab_contents/tab_contents_view_helper.h" #include "ui/base/win/window_impl.h" class RenderWidgetHostViewWin; -class TabContentsViewWinDelegate; // An implementation of TabContentsView for Windows. class TabContentsViewWin : public TabContentsView, public ui::WindowImpl { public: - TabContentsViewWin(TabContents* tab_contents, - TabContentsViewWinDelegate* delegate); + explicit TabContentsViewWin(TabContents* tab_contents); virtual ~TabContentsViewWin(); void SetParent(HWND parent); @@ -94,12 +91,11 @@ class TabContentsViewWin : public TabContentsView, // The TabContents whose contents we display. TabContents* tab_contents_; - TabContentsViewWinDelegate* delegate_; RenderWidgetHostViewWin* view_; - typedef std::map<int, RenderViewHost*> PendingContents; - PendingContents pending_contents_; + // Common implementations of some TabContentsView methods. + TabContentsViewHelper tab_contents_view_helper_; DISALLOW_COPY_AND_ASSIGN(TabContentsViewWin); }; diff --git a/content/browser/tab_contents/tab_contents_view_win_delegate.h b/content/browser/tab_contents/tab_contents_view_win_delegate.h deleted file mode 100644 index 76d7fc2..0000000 --- a/content/browser/tab_contents/tab_contents_view_win_delegate.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_DELEGATE_H_ -#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_DELEGATE_H_ -#pragma once - -#include "base/basictypes.h" - -class TabContents; -class TabContentsViewWin; -struct ViewHostMsg_CreateWindow_Params; - -// A delegate interface for TabContentsViewWin. -class TabContentsViewWinDelegate { - public: - virtual ~TabContentsViewWinDelegate() {} - - // These match the TabContentsView methods. - virtual TabContents* CreateNewWindow( - TabContentsViewWin* tab_contents_view, - int route_id, - const ViewHostMsg_CreateWindow_Params& params) = 0; - - protected: - TabContentsViewWinDelegate() {} - - DISALLOW_COPY_AND_ASSIGN(TabContentsViewWinDelegate); -}; - -#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_DELEGATE_H_ diff --git a/content/content_shell.gypi b/content/content_shell.gypi index cf58a57..1045301 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -43,7 +43,6 @@ 'sources': [ 'browser/tab_contents/tab_contents_view_win.cc', 'browser/tab_contents/tab_contents_view_win.h', - 'browser/tab_contents/tab_contents_view_win_delegate.h', 'shell/shell.cc', 'shell/shell.h', 'shell/shell_gtk.cc', diff --git a/content/shell/shell.cc b/content/shell/shell.cc index 95e1e24..c837d5a 100644 --- a/content/shell/shell.cc +++ b/content/shell/shell.cc @@ -44,30 +44,35 @@ Shell::~Shell() { } } -Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, - const GURL& url, - SiteInstance* site_instance, - int routing_id, - TabContents* base_tab_contents) { +Shell* Shell::CreateShell(TabContents* tab_contents) { Shell* shell = new Shell(); shell->PlatformCreateWindow(kTestWindowWidth, kTestWindowHeight); - shell->tab_contents_.reset(new TabContents( - browser_context, - site_instance, - routing_id, - base_tab_contents, - NULL)); - shell->tab_contents_->SetDelegate(shell); + shell->tab_contents_.reset(tab_contents); + tab_contents->SetDelegate(shell); #if defined(OS_WIN) TabContentsViewWin* view = - static_cast<TabContentsViewWin*>(shell->tab_contents_->GetView()); + static_cast<TabContentsViewWin*>(tab_contents->GetView()); view->SetParent(shell->window_); #endif shell->PlatformResizeSubViews(); + return shell; +} +Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, + const GURL& url, + SiteInstance* site_instance, + int routing_id, + TabContents* base_tab_contents) { + TabContents* tab_contents = new TabContents( + browser_context, + site_instance, + routing_id, + base_tab_contents, + NULL); + Shell* shell = CreateShell(tab_contents); if (!url.is_empty()) shell->LoadURL(url); return shell; @@ -116,6 +121,13 @@ void Shell::LoadingStateChanged(WebContents* source) { UpdateNavigationControls(); } +void Shell::WebContentsCreated(WebContents* source_contents, + int64 source_frame_id, + const GURL& target_url, + WebContents* new_contents) { + CreateShell(static_cast<TabContents*>(new_contents)); +} + void Shell::DidNavigateMainFramePostCommit(WebContents* tab) { PlatformSetAddressBarURL(tab->GetURL()); } diff --git a/content/shell/shell.h b/content/shell/shell.h index 064171d..9e161e0 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -67,6 +67,9 @@ class Shell : public WebContentsDelegate { Shell(); + // Helper to create a new Shell given a newly created TabContents. + static Shell* CreateShell(TabContents* tab_contents); + // All the methods that begin with Platform need to be implemented by the // platform specific Shell implementation. // Called from the destructor to let each platform do any necessary cleanup. @@ -86,6 +89,10 @@ class Shell : public WebContentsDelegate { // content::WebContentsDelegate virtual void LoadingStateChanged(WebContents* source) OVERRIDE; + virtual void WebContentsCreated(WebContents* source_contents, + int64 source_frame_id, + const GURL& target_url, + WebContents* new_contents) OVERRIDE; virtual void DidNavigateMainFramePostCommit(WebContents* tab) OVERRIDE; virtual void UpdatePreferredSize(WebContents* source, const gfx::Size& pref_size) OVERRIDE; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 904e9ff..99e665c 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -35,7 +35,7 @@ BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( TabContentsView* ShellContentBrowserClient::CreateTabContentsView( TabContents* tab_contents) { #if defined(OS_WIN) - return new TabContentsViewWin(tab_contents, this); + return new TabContentsViewWin(tab_contents); #else return NULL; #endif @@ -322,19 +322,4 @@ crypto::CryptoModuleBlockingPasswordDelegate* } #endif -#if defined(OS_WIN) -TabContents* ShellContentBrowserClient::CreateNewWindow( - TabContentsViewWin* tab_contents_view, - int route_id, - const ViewHostMsg_CreateWindow_Params& params) { - Shell* shell = Shell::CreateNewWindow( - tab_contents_view->tab_contents()->GetBrowserContext(), - GURL(), - tab_contents_view->tab_contents()->GetSiteInstance(), - route_id, - tab_contents_view->tab_contents()); - return shell->tab_contents(); -} -#endif - } // namespace content diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index a81c445..98fa144 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -12,19 +12,11 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" -#if defined(OS_WIN) -#include "content/browser/tab_contents/tab_contents_view_win_delegate.h" -#endif - namespace content { class ShellBrowserMainParts; -class ShellContentBrowserClient : public ContentBrowserClient -#if defined(OS_WIN) - , public TabContentsViewWinDelegate -#endif -{ +class ShellContentBrowserClient : public ContentBrowserClient { public: ShellContentBrowserClient(); virtual ~ShellContentBrowserClient(); @@ -170,14 +162,6 @@ class ShellContentBrowserClient : public ContentBrowserClient const GURL& url) OVERRIDE; #endif -#if defined(OS_WIN) - // TabContentsViewWinDelegate implementation. - virtual TabContents* CreateNewWindow( - TabContentsViewWin* tab_contents_view, - int route_id, - const ViewHostMsg_CreateWindow_Params& params) OVERRIDE; -#endif - private: ShellBrowserMainParts* shell_browser_main_parts_; }; |