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 /content/browser/tab_contents | |
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
Diffstat (limited to 'content/browser/tab_contents')
3 files changed, 74 insertions, 68 deletions
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_ |