diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 01:49:44 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-30 01:49:44 +0000 |
commit | 31145091d1402ced1c7bf7fe418dac36d441e82b (patch) | |
tree | 4d6eca68aa2cafd219f9641959febed7ec4a2389 /chrome/browser/ui | |
parent | 9be87ba466fa2259e27974b43633414e5e1293ab (diff) | |
download | chromium_src-31145091d1402ced1c7bf7fe418dac36d441e82b.zip chromium_src-31145091d1402ced1c7bf7fe418dac36d441e82b.tar.gz chromium_src-31145091d1402ced1c7bf7fe418dac36d441e82b.tar.bz2 |
content: Move constrained window code from TabContents to TabContentsWrapper
BUG=95257
TEST=compiles,ConstrainedWindowTabHelperUnit.ConstrainedWindows is green
Review URL: http://codereview.chromium.org/7880003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
37 files changed, 449 insertions, 91 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index f9308b0..ad29969 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -94,6 +94,7 @@ #include "chrome/browser/ui/browser_synced_window_delegate.h" #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/find_bar/find_bar.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" @@ -3515,15 +3516,6 @@ void Browser::ContentsZoomChange(bool zoom_in) { ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); } -void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) { - int index = tabstrip_model()->GetWrapperIndex(contents); - if (index == TabStripModel::kNoTab) { - NOTREACHED(); - return; - } - tabstrip_model()->SetTabBlocked(index, blocked); -} - void Browser::TabContentsFocused(TabContents* tab_content) { window_->TabContentsFocused(tab_content); } @@ -4167,6 +4159,15 @@ void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, new_tab_contents); } +void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) { + int index = tabstrip_model()->GetIndexOfTabContents(wrapper); + if (index == TabStripModel::kNoTab) { + NOTREACHED(); + return; + } + tabstrip_model()->SetTabBlocked(index, blocked); +} + void Browser::SetSuggestedText(const string16& text, InstantCompleteBehavior behavior) { if (window()->GetLocationBar()) @@ -4946,6 +4947,7 @@ void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { // ...and all the helpers. tab->blocked_content_tab_helper()->set_delegate(delegate); tab->bookmark_tab_helper()->set_delegate(delegate); + tab->constrained_window_tab_helper()->set_delegate(delegate); tab->search_engine_tab_helper()->set_delegate(delegate); } diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index ed58dab..588a0cf 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -33,6 +33,7 @@ #include "chrome/browser/ui/bookmarks/bookmark_bar.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" #include "chrome/browser/ui/browser_navigator.h" +#include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" #include "chrome/browser/ui/shell_dialogs.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" @@ -72,6 +73,7 @@ class Browser : public TabHandlerDelegate, public TabContentsDelegate, public TabContentsWrapperDelegate, public SearchEngineTabHelperDelegate, + public ConstrainedWindowTabHelperDelegate, public BlockedContentTabHelperDelegate, public BookmarkTabHelperDelegate, public PageNavigator, @@ -916,8 +918,6 @@ class Browser : public TabHandlerDelegate, virtual void ContentsMouseEvent( TabContents* source, const gfx::Point& location, bool motion) OVERRIDE; virtual void ContentsZoomChange(bool zoom_in) OVERRIDE; - virtual void SetTabContentBlocked(TabContents* contents, - bool blocked) OVERRIDE; virtual void TabContentsFocused(TabContents* tab_content) OVERRIDE; virtual bool TakeFocus(bool reverse) OVERRIDE; virtual bool IsApplication() const OVERRIDE; @@ -1009,6 +1009,10 @@ class Browser : public TabHandlerDelegate, virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) OVERRIDE; + // Overridden from ConstrainedWindowTabHelperDelegate: + virtual void SetTabContentBlocked(TabContentsWrapper* contents, + bool blocked) OVERRIDE; + // Overridden from BlockedContentTabHelperDelegate: virtual TabContentsWrapper* GetConstrainingContentsWrapper( TabContentsWrapper* source) OVERRIDE; diff --git a/chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm b/chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm index 164136f0..f5e93d0 100644 --- a/chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm +++ b/chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm @@ -140,7 +140,7 @@ ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( new ConstrainedHtmlDelegateMac(profile, delegate); // Deleted when ConstrainedHtmlDelegateMac::OnDialogCloseFromWebUI() runs. ConstrainedWindow* constrained_window = - new ConstrainedWindowMac(wrapper->tab_contents(), constrained_delegate); + new ConstrainedWindowMac(wrapper, constrained_delegate); constrained_delegate->set_window(constrained_window); return constrained_window; } diff --git a/chrome/browser/ui/cocoa/constrained_window_mac.h b/chrome/browser/ui/cocoa/constrained_window_mac.h index 4f8fc55..75c949a 100644 --- a/chrome/browser/ui/cocoa/constrained_window_mac.h +++ b/chrome/browser/ui/cocoa/constrained_window_mac.h @@ -18,7 +18,7 @@ @class GTMWindowSheetController; @class NSView; @class NSWindow; -class TabContents; +class TabContentsWrapper; // Base class for constrained dialog delegates. Never inherit from this // directly. @@ -109,7 +109,7 @@ class ConstrainedWindowMacDelegateCustomSheet // deleted. class ConstrainedWindowMac : public ConstrainedWindow { public: - ConstrainedWindowMac(TabContents* owner, + ConstrainedWindowMac(TabContentsWrapper* wrapper, ConstrainedWindowMacDelegate* delegate); virtual ~ConstrainedWindowMac(); @@ -117,8 +117,8 @@ class ConstrainedWindowMac : public ConstrainedWindow { virtual void ShowConstrainedWindow(); virtual void CloseConstrainedWindow(); - // Returns the TabContents that constrains this Constrained Window. - TabContents* owner() const { return owner_; } + // Returns the TabContentsWrapper that constrains this Constrained Window. + TabContentsWrapper* owner() const { return wrapper_; } // Returns the window's delegate. ConstrainedWindowMacDelegate* delegate() { return delegate_; } @@ -129,8 +129,8 @@ class ConstrainedWindowMac : public ConstrainedWindow { private: friend class ConstrainedWindow; - // The TabContents that owns and constrains this ConstrainedWindow. - TabContents* owner_; + // The TabContentsWrapper that owns and constrains this ConstrainedWindow. + TabContentsWrapper* wrapper_; // Delegate that provides the contents of this constrained window. ConstrainedWindowMacDelegate* delegate_; diff --git a/chrome/browser/ui/cocoa/constrained_window_mac.mm b/chrome/browser/ui/cocoa/constrained_window_mac.mm index e54257e..bed37c8 100644 --- a/chrome/browser/ui/cocoa/constrained_window_mac.mm +++ b/chrome/browser/ui/cocoa/constrained_window_mac.mm @@ -5,6 +5,8 @@ #include "chrome/browser/ui/cocoa/constrained_window_mac.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" #import "third_party/GTM/AppKit/GTMWindowSheetController.h" @@ -84,16 +86,16 @@ void ConstrainedWindowMacDelegateCustomSheet::RunSheet( } ConstrainedWindowMac::ConstrainedWindowMac( - TabContents* owner, ConstrainedWindowMacDelegate* delegate) - : owner_(owner), + TabContentsWrapper* wrapper, ConstrainedWindowMacDelegate* delegate) + : wrapper_(wrapper), delegate_(delegate), controller_(nil), should_be_visible_(false), closing_(false) { - DCHECK(owner); + DCHECK(wrapper); DCHECK(delegate); - owner->AddConstrainedDialog(this); + wrapper->constrained_window_tab_helper()->AddConstrainedDialog(this); } ConstrainedWindowMac::~ConstrainedWindowMac() {} @@ -103,7 +105,7 @@ void ConstrainedWindowMac::ShowConstrainedWindow() { // The TabContents only has a native window if it is currently visible. In // this case, open the sheet now. Else, Realize() will be called later, when // our tab becomes visible. - NSWindow* browserWindow = owner_->view()->GetTopLevelNativeWindow(); + NSWindow* browserWindow = wrapper_->view()->GetTopLevelNativeWindow(); NSWindowController* controller = [browserWindow windowController]; if (controller != nil) { DCHECK([controller isKindOfClass:[BrowserWindowController class]]); @@ -127,7 +129,7 @@ void ConstrainedWindowMac::CloseConstrainedWindow() { // ok. [controller_ removeConstrainedWindow:this]; delegate_->DeleteDelegate(); - owner_->WillClose(this); + wrapper_->constrained_window_tab_helper()->WillClose(this); delete this; } diff --git a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm index 75e1606..6b01865 100644 --- a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm +++ b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm @@ -92,7 +92,7 @@ CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, set_sheet([sheet_controller_ window]); - window_ = new ConstrainedWindowMac(wrapper->tab_contents(), this); + window_ = new ConstrainedWindowMac(wrapper, this); } CollectedCookiesMac::~CollectedCookiesMac() { diff --git a/chrome/browser/ui/cocoa/repost_form_warning_mac.h b/chrome/browser/ui/cocoa/repost_form_warning_mac.h index d83fefb..ba04032 100644 --- a/chrome/browser/ui/cocoa/repost_form_warning_mac.h +++ b/chrome/browser/ui/cocoa/repost_form_warning_mac.h @@ -12,6 +12,7 @@ #include "chrome/browser/ui/cocoa/constrained_window_mac.h" class RepostFormWarningController; +class TabContents; // Displays a dialog that warns the user that they are about to resubmit // a form. To show the dialog, call the |Create| method. It will open the @@ -21,7 +22,7 @@ class RepostFormWarningMac : public ConstrainedWindowMacDelegateSystemSheet { // Convenience method that creates a new |RepostFormWarningController| and // then a new |RepostFormWarningMac| from that. static RepostFormWarningMac* Create(NSWindow* parent, - TabContents* tab_contents); + TabContents* tab_contents); RepostFormWarningMac(NSWindow* parent, RepostFormWarningController* controller, diff --git a/chrome/browser/ui/cocoa/repost_form_warning_mac.mm b/chrome/browser/ui/cocoa/repost_form_warning_mac.mm index a05c376..4300ac1 100644 --- a/chrome/browser/ui/cocoa/repost_form_warning_mac.mm +++ b/chrome/browser/ui/cocoa/repost_form_warning_mac.mm @@ -6,6 +6,7 @@ #include "base/memory/scoped_nsobject.h" #include "chrome/browser/repost_form_warning_controller.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util_mac.h" @@ -69,7 +70,9 @@ RepostFormWarningMac::RepostFormWarningMac( set_sheet(alert); - controller->set_window(new ConstrainedWindowMac(tab_contents_, this)); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + controller->set_window(new ConstrainedWindowMac(wrapper, this)); } RepostFormWarningMac::~RepostFormWarningMac() { diff --git a/chrome/browser/ui/cocoa/ssl_client_certificate_selector.mm b/chrome/browser/ui/cocoa/ssl_client_certificate_selector.mm index f4f57ea..a095e3f 100644 --- a/chrome/browser/ui/cocoa/ssl_client_certificate_selector.mm +++ b/chrome/browser/ui/cocoa/ssl_client_certificate_selector.mm @@ -226,7 +226,7 @@ void ShowSSLClientCertificateSelector( } window_ = new ConstrainedWindowMac( - wrapper->tab_contents(), + wrapper, new ConstrainedSFChooseIdentityPanel( panel, self, @selector(sheetDidEnd:returnCode:context:), diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm index e06524d3..7464d6e 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm @@ -42,6 +42,7 @@ #import "chrome/browser/ui/cocoa/tabs/tab_view.h" #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" #import "chrome/browser/ui/cocoa/tracking_area.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/find_bar/find_bar.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" @@ -512,12 +513,13 @@ private: TabContentsWrapper* newTab = tabStripModel_->GetTabContentsAt(modelIndex); DCHECK(newTab); if (newTab) { - TabContents::ConstrainedWindowList::iterator it, end; - end = newTab->tab_contents()->constrained_window_end(); + ConstrainedWindowTabHelper::ConstrainedWindowList::iterator it, end; + end = newTab->constrained_window_tab_helper()->constrained_window_end(); NSWindowController* controller = [[newView window] windowController]; DCHECK([controller isKindOfClass:[BrowserWindowController class]]); - for (it = newTab->tab_contents()->constrained_window_begin(); + for (it = newTab->constrained_window_tab_helper()-> + constrained_window_begin(); it != end; ++it) { ConstrainedWindow* constrainedWindow = *it; @@ -1992,7 +1994,8 @@ private: // Changing it? Do not forget to modify removeConstrainedWindow too. // We use the TabContentsController's view in |swapInTabAtIndex|, so we have // to pass it to the sheet controller here. - NSView* tabContentsView = [window->owner()->GetNativeView() superview]; + NSView* tabContentsView = + [window->owner()->tab_contents()->GetNativeView() superview]; window->delegate()->RunSheet([self sheetController], tabContentsView); // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets @@ -2010,12 +2013,18 @@ private: } - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { - NSView* tabContentsView = [window->owner()->GetNativeView() superview]; + NSView* tabContentsView = + [window->owner()->tab_contents()->GetNativeView() superview]; // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets // between windows. Until then, we have to prevent having to move a tabsheet // between windows, e.g. no tearing off of tabs. NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; + if (modelIndex < 0) { + // This can happen during shutdown where the tab contents view has already + // removed itself. + return; + } NSInteger index = [self indexFromModelIndex:modelIndex]; BrowserWindowController* controller = (BrowserWindowController*)[[switchView_ window] windowController]; diff --git a/chrome/browser/ui/constrained_window_tab_helper.cc b/chrome/browser/ui/constrained_window_tab_helper.cc new file mode 100644 index 0000000..b9d250a --- /dev/null +++ b/chrome/browser/ui/constrained_window_tab_helper.cc @@ -0,0 +1,109 @@ +// 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. + +#include "chrome/browser/ui/constrained_window_tab_helper.h" + +#include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/renderer_host/render_widget_host_view.h" +#include "content/browser/tab_contents/navigation_details.h" +#include "net/base/registry_controlled_domain.h" + +ConstrainedWindowTabHelper::ConstrainedWindowTabHelper( + TabContentsWrapper* wrapper) + : TabContentsObserver(wrapper->tab_contents()), + wrapper_(wrapper), + delegate_(NULL) { +} + +ConstrainedWindowTabHelper::~ConstrainedWindowTabHelper() { + DCHECK(child_windows_.empty()); +} + +void ConstrainedWindowTabHelper::AddConstrainedDialog( + ConstrainedWindow* window) { + child_windows_.push_back(window); + + if (child_windows_.size() == 1) { + window->ShowConstrainedWindow(); + BlockTabContent(true); + } +} + +void ConstrainedWindowTabHelper::CloseConstrainedWindows() { + // Clear out any constrained windows since we are leaving this page entirely. + // To ensure that we iterate over every element in child_windows_ we + // need to use a copy of child_windows_. Otherwise if + // window->CloseConstrainedWindow() modifies child_windows_ we could end up + // skipping some elements. + ConstrainedWindowList child_windows_copy(child_windows_); + for (ConstrainedWindowList::iterator it = child_windows_copy.begin(); + it != child_windows_copy.end(); ++it) { + ConstrainedWindow* window = *it; + if (window) { + window->CloseConstrainedWindow(); + BlockTabContent(false); + } + } +} + +void ConstrainedWindowTabHelper::WillClose(ConstrainedWindow* window) { + ConstrainedWindowList::iterator i( + std::find(child_windows_.begin(), child_windows_.end(), window)); + bool removed_topmost_window = i == child_windows_.begin(); + if (i != child_windows_.end()) + child_windows_.erase(i); + if (child_windows_.empty()) { + BlockTabContent(false); + } else { + if (removed_topmost_window) + child_windows_[0]->ShowConstrainedWindow(); + BlockTabContent(true); + } +} + +void ConstrainedWindowTabHelper::BlockTabContent(bool blocked) { + TabContents* contents = tab_contents(); + if (!contents) { + // The TabContents has already disconnected. + return; + } + + RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView(); + // 70% opaque grey. + SkColor greyish = SkColorSetARGB(178, 0, 0, 0); + if (rwhv) + rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false); + // RenderViewHost may be NULL during shutdown. + if (contents->render_view_host()) + contents->render_view_host()->set_ignore_input_events(blocked); + if (delegate_) + delegate_->SetTabContentBlocked(wrapper_, blocked); +} + +void ConstrainedWindowTabHelper::DidNavigateMainFramePostCommit( + const content::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { + // Close constrained windows if necessary. + if (!net::RegistryControlledDomainService::SameDomainOrHost( + details.previous_url, details.entry->url())) + CloseConstrainedWindows(); +} + +void ConstrainedWindowTabHelper::DidGetIgnoredUIEvent() { + if (constrained_window_count()) { + ConstrainedWindow* window = *constrained_window_begin(); + window->FocusConstrainedWindow(); + } +} + +void ConstrainedWindowTabHelper::TabContentsDestroyed(TabContents* tab) { + // First cleanly close all child windows. + // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked + // some of these to close. CloseWindows is async, so it might get called + // twice before it runs. + CloseConstrainedWindows(); +} diff --git a/chrome/browser/ui/constrained_window_tab_helper.h b/chrome/browser/ui/constrained_window_tab_helper.h new file mode 100644 index 0000000..dee8093 --- /dev/null +++ b/chrome/browser/ui/constrained_window_tab_helper.h @@ -0,0 +1,74 @@ +// 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 CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_H_ +#define CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_H_ +#pragma once + +#include <deque> + +#include "content/browser/tab_contents/tab_contents_observer.h" + +class ConstrainedWindow; +class ConstrainedWindowTabHelperDelegate; +class TabContentsWrapper; + +// Per-tab class to manage constrained windows. +class ConstrainedWindowTabHelper : public TabContentsObserver { + public: + explicit ConstrainedWindowTabHelper(TabContentsWrapper* tab_contents); + virtual ~ConstrainedWindowTabHelper(); + + ConstrainedWindowTabHelperDelegate* delegate() const { return delegate_; } + void set_delegate(ConstrainedWindowTabHelperDelegate* d) { delegate_ = d; } + + // Adds the given window to the list of child windows. The window will notify + // via WillClose() when it is being destroyed. + void AddConstrainedDialog(ConstrainedWindow* window); + + // Closes all constrained windows. + void CloseConstrainedWindows(); + + // Called when a ConstrainedWindow we own is about to be closed. + void WillClose(ConstrainedWindow* window); + + // Blocks/unblocks interaction with renderer process. + void BlockTabContent(bool blocked); + + // Returns the number of constrained windows in this tab. Used by tests. + size_t constrained_window_count() { return child_windows_.size(); } + + typedef std::deque<ConstrainedWindow*> ConstrainedWindowList; + + // Return an iterator for the first constrained window in this tab contents. + ConstrainedWindowList::iterator constrained_window_begin() { + return child_windows_.begin(); + } + + // Return an iterator for the last constrained window in this tab contents. + ConstrainedWindowList::iterator constrained_window_end() { + return child_windows_.end(); + } + + private: + // Overridden from TabContentsObserver: + virtual void DidNavigateMainFramePostCommit( + const content::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; + virtual void DidGetIgnoredUIEvent() OVERRIDE; + virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE; + + // Our owning TabContentsWrapper. + TabContentsWrapper* wrapper_; + + // Delegate for notifying our owner about stuff. Not owned by us. + ConstrainedWindowTabHelperDelegate* delegate_; + + // All active constrained windows. + ConstrainedWindowList child_windows_; + + DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowTabHelper); +}; + +#endif // CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_H_ diff --git a/chrome/browser/ui/constrained_window_tab_helper_delegate.cc b/chrome/browser/ui/constrained_window_tab_helper_delegate.cc new file mode 100644 index 0000000..7df8db8 --- /dev/null +++ b/chrome/browser/ui/constrained_window_tab_helper_delegate.cc @@ -0,0 +1,19 @@ +// 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. + +#include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" + +void ConstrainedWindowTabHelperDelegate::WillShowConstrainedWindow( + TabContentsWrapper* source) { +} + +bool ConstrainedWindowTabHelperDelegate::ShouldFocusConstrainedWindow() { + return true; +} + +void ConstrainedWindowTabHelperDelegate::SetTabContentBlocked( + TabContentsWrapper* wrapper, bool blocked) { +} + +ConstrainedWindowTabHelperDelegate::~ConstrainedWindowTabHelperDelegate() {} diff --git a/chrome/browser/ui/constrained_window_tab_helper_delegate.h b/chrome/browser/ui/constrained_window_tab_helper_delegate.h new file mode 100644 index 0000000..292e4ce --- /dev/null +++ b/chrome/browser/ui/constrained_window_tab_helper_delegate.h @@ -0,0 +1,29 @@ +// 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 CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_DELEGATE_H_ +#define CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_DELEGATE_H_ +#pragma once + +class TabContentsWrapper; + +class ConstrainedWindowTabHelperDelegate { + public: + // Invoked prior to the TabContentsWrapper showing a constrained window. + virtual void WillShowConstrainedWindow(TabContentsWrapper* source); + + // Returns true if constrained windows should be focused. Default is true. + virtual bool ShouldFocusConstrainedWindow(); + + // Changes the blocked state of |wrapper|. TabContents are considered blocked + // while displaying a tab modal dialog. During that time renderer host will + // ignore any UI interaction within TabContent outside of the currently + // displaying dialog. + virtual void SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked); + + protected: + virtual ~ConstrainedWindowTabHelperDelegate(); +}; + +#endif // CHROME_BROWSER_UI_CONSTRAINED_WINDOW_TAB_HELPER_DELEGATE_H_ diff --git a/chrome/browser/ui/constrained_window_tab_helper_unittest.cc b/chrome/browser/ui/constrained_window_tab_helper_unittest.cc new file mode 100644 index 0000000..0c426d3 --- /dev/null +++ b/chrome/browser/ui/constrained_window_tab_helper_unittest.cc @@ -0,0 +1,55 @@ +// 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. + +#include "chrome/browser/ui/constrained_window_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" +#include "content/browser/tab_contents/constrained_window.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "content/browser/browser_thread.h" + +class ConstrainedWindowTabHelperUnit : public TabContentsWrapperTestHarness { + public: + ConstrainedWindowTabHelperUnit() + : TabContentsWrapperTestHarness(), + ui_thread_(BrowserThread::UI, &message_loop_) { + } + + private: + BrowserThread ui_thread_; +}; + +class ConstrainedWindowCloseTest : public ConstrainedWindow { + public: + explicit ConstrainedWindowCloseTest(TabContentsWrapper* wrapper) + : wrapper_(wrapper) { + } + + virtual void ShowConstrainedWindow() {} + virtual void FocusConstrainedWindow() {} + virtual ~ConstrainedWindowCloseTest() {} + + virtual void CloseConstrainedWindow() { + wrapper_->constrained_window_tab_helper()->WillClose(this); + close_count++; + } + + int close_count; + TabContentsWrapper* wrapper_; +}; + +TEST_F(ConstrainedWindowTabHelperUnit, ConstrainedWindows) { + ConstrainedWindowCloseTest window(contents_wrapper()); + window.close_count = 0; + + const int kWindowCount = 4; + for (int i = 0; i < kWindowCount; i++) { + contents_wrapper()->constrained_window_tab_helper()->AddConstrainedDialog( + &window); + } + EXPECT_EQ(window.close_count, 0); + contents_wrapper()->constrained_window_tab_helper()-> + CloseConstrainedWindows(); + EXPECT_EQ(window.close_count, kWindowCount); +} diff --git a/chrome/browser/ui/gtk/collected_cookies_gtk.cc b/chrome/browser/ui/gtk/collected_cookies_gtk.cc index 963dcc3..eb1095b 100644 --- a/chrome/browser/ui/gtk/collected_cookies_gtk.cc +++ b/chrome/browser/ui/gtk/collected_cookies_gtk.cc @@ -163,7 +163,7 @@ void CollectedCookiesGtk::Init() { blocked_cookies_tree_adapter_->Init(); EnableControls(); ShowCookieInfo(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_))); - window_ = new ConstrainedWindowGtk(wrapper_->tab_contents(), this); + window_ = new ConstrainedWindowGtk(wrapper_, this); } GtkWidget* CollectedCookiesGtk::CreateAllowedPane() { diff --git a/chrome/browser/ui/gtk/constrained_html_delegate_gtk.cc b/chrome/browser/ui/gtk/constrained_html_delegate_gtk.cc index bdf3e7a..38f6403 100644 --- a/chrome/browser/ui/gtk/constrained_html_delegate_gtk.cc +++ b/chrome/browser/ui/gtk/constrained_html_delegate_gtk.cc @@ -119,8 +119,7 @@ ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( ConstrainedHtmlDelegateGtk* constrained_delegate = new ConstrainedHtmlDelegateGtk(profile, delegate); ConstrainedWindow* constrained_window = - new ConstrainedWindowGtk(overshadowed->tab_contents(), - constrained_delegate); + new ConstrainedWindowGtk(overshadowed, constrained_delegate); constrained_delegate->set_window(constrained_window); return constrained_window; } diff --git a/chrome/browser/ui/gtk/constrained_window_gtk.cc b/chrome/browser/ui/gtk/constrained_window_gtk.cc index 01cc99b..a769891 100644 --- a/chrome/browser/ui/gtk/constrained_window_gtk.cc +++ b/chrome/browser/ui/gtk/constrained_window_gtk.cc @@ -7,7 +7,9 @@ #include <gdk/gdkkeysyms.h> #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/gtk/gtk_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" #include "ui/base/gtk/gtk_hig_constants.h" @@ -33,12 +35,12 @@ bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const { } ConstrainedWindowGtk::ConstrainedWindowGtk( - TabContents* owner, ConstrainedWindowGtkDelegate* delegate) - : owner_(owner), + TabContentsWrapper* wrapper, ConstrainedWindowGtkDelegate* delegate) + : wrapper_(wrapper), delegate_(delegate), visible_(false), factory_(this) { - DCHECK(owner); + DCHECK(wrapper); DCHECK(delegate); GtkWidget* dialog = delegate->GetWidgetRoot(); @@ -77,7 +79,7 @@ ConstrainedWindowGtk::ConstrainedWindowGtk( g_signal_connect(widget(), "hierarchy-changed", G_CALLBACK(OnHierarchyChangedThunk), this); - owner->AddConstrainedDialog(this); + wrapper_->constrained_window_tab_helper()->AddConstrainedDialog(this); } ConstrainedWindowGtk::~ConstrainedWindowGtk() { @@ -98,7 +100,7 @@ void ConstrainedWindowGtk::CloseConstrainedWindow() { if (visible_) ContainingView()->RemoveConstrainedWindow(this); delegate_->DeleteDelegate(); - owner_->WillClose(this); + wrapper_->constrained_window_tab_helper()->WillClose(this); delete this; } @@ -110,15 +112,17 @@ void ConstrainedWindowGtk::FocusConstrainedWindow() { // The user may have focused another tab. In this case do not grab focus // until this tab is refocused. - if ((!owner_->delegate() || - owner_->delegate()->ShouldFocusConstrainedWindow()) && + ConstrainedWindowTabHelper* helper = + wrapper_->constrained_window_tab_helper(); + if ((!helper->delegate() || + helper->delegate()->ShouldFocusConstrainedWindow()) && gtk_util::IsWidgetAncestryVisible(focus_widget)) { gtk_widget_grab_focus(focus_widget); } else { // TODO(estade): this define should not need to be here because this class // should not be used on linux/views. #if defined(TOOLKIT_GTK) - static_cast<TabContentsViewGtk*>(owner_->view())-> + static_cast<TabContentsViewGtk*>(wrapper_->view())-> SetFocusedWidget(focus_widget); #endif } @@ -128,10 +132,10 @@ ConstrainedWindowGtk::TabContentsViewType* ConstrainedWindowGtk::ContainingView() { #if defined(TOOLKIT_VIEWS) && !defined(TOUCH_UI) return static_cast<NativeTabContentsViewGtk*>( - static_cast<TabContentsViewViews*>(owner_->view())-> + static_cast<TabContentsViewViews*>(wrapper_->view())-> native_tab_contents_view()); #else - return static_cast<TabContentsViewType*>(owner_->view()); + return static_cast<TabContentsViewType*>(wrapper_->view()); #endif } diff --git a/chrome/browser/ui/gtk/constrained_window_gtk.h b/chrome/browser/ui/gtk/constrained_window_gtk.h index 2b7b4c1..5dbaa61 100644 --- a/chrome/browser/ui/gtk/constrained_window_gtk.h +++ b/chrome/browser/ui/gtk/constrained_window_gtk.h @@ -14,7 +14,7 @@ #include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/owned_widget_gtk.h" -class TabContents; +class TabContentsWrapper; typedef struct _GdkColor GdkColor; #if defined(TOUCH_UI) class TabContentsViewViews; @@ -58,7 +58,7 @@ class ConstrainedWindowGtk : public ConstrainedWindow { typedef TabContentsViewGtk TabContentsViewType; #endif - ConstrainedWindowGtk(TabContents* owner, + ConstrainedWindowGtk(TabContentsWrapper* wrapper, ConstrainedWindowGtkDelegate* delegate); virtual ~ConstrainedWindowGtk(); @@ -67,8 +67,8 @@ class ConstrainedWindowGtk : public ConstrainedWindow { virtual void CloseConstrainedWindow(); virtual void FocusConstrainedWindow(); - // Returns the TabContents that constrains this Constrained Window. - TabContents* owner() const { return owner_; } + // Returns the TabContentsWrapper that constrains this Constrained Window. + TabContentsWrapper* owner() const { return wrapper_; } // Returns the toplevel widget that displays this "window". GtkWidget* widget() { return border_.get(); } @@ -85,8 +85,8 @@ class ConstrainedWindowGtk : public ConstrainedWindow { CHROMEGTK_CALLBACK_1(ConstrainedWindowGtk, void, OnHierarchyChanged, GtkWidget*); - // The TabContents that owns and constrains this ConstrainedWindow. - TabContents* owner_; + // The TabContentsWrapper that owns and constrains this ConstrainedWindow. + TabContentsWrapper* wrapper_; // The top level widget container that exports to our TabContentsView. ui::OwnedWidgetGtk border_; diff --git a/chrome/browser/ui/gtk/repost_form_warning_gtk.cc b/chrome/browser/ui/gtk/repost_form_warning_gtk.cc index 39d576c..5edae8a 100644 --- a/chrome/browser/ui/gtk/repost_form_warning_gtk.cc +++ b/chrome/browser/ui/gtk/repost_form_warning_gtk.cc @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "chrome/browser/repost_form_warning_controller.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/tab_contents.h" @@ -54,7 +55,9 @@ RepostFormWarningGtk::RepostFormWarningGtk(GtkWindow* parent, g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this); gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0); - controller_->set_window(new ConstrainedWindowGtk(tab_contents, this)); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + controller_->set_window(new ConstrainedWindowGtk(wrapper, this)); } GtkWidget* RepostFormWarningGtk::GetWidgetRoot() { diff --git a/chrome/browser/ui/gtk/repost_form_warning_gtk.h b/chrome/browser/ui/gtk/repost_form_warning_gtk.h index a3b6f18..a464676 100644 --- a/chrome/browser/ui/gtk/repost_form_warning_gtk.h +++ b/chrome/browser/ui/gtk/repost_form_warning_gtk.h @@ -13,6 +13,7 @@ #include "ui/base/gtk/gtk_signal.h" class RepostFormWarningController; +class TabContents; // Displays a dialog that warns the user that they are about to resubmit // a form. diff --git a/chrome/browser/ui/gtk/ssl_client_certificate_selector.cc b/chrome/browser/ui/gtk/ssl_client_certificate_selector.cc index 4d7b67a..e28fdb4 100644 --- a/chrome/browser/ui/gtk/ssl_client_certificate_selector.cc +++ b/chrome/browser/ui/gtk/ssl_client_certificate_selector.cc @@ -198,7 +198,7 @@ SSLClientCertificateSelector::~SSLClientCertificateSelector() { void SSLClientCertificateSelector::Show() { DCHECK(!window_); - window_ = new ConstrainedWindowGtk(wrapper_->tab_contents(), this); + window_ = new ConstrainedWindowGtk(wrapper_, this); } void SSLClientCertificateSelector::OnCertSelectedByNotification() { diff --git a/chrome/browser/ui/login/login_prompt_gtk.cc b/chrome/browser/ui/login/login_prompt_gtk.cc index 6e35c90..97a546d 100644 --- a/chrome/browser/ui/login/login_prompt_gtk.cc +++ b/chrome/browser/ui/login/login_prompt_gtk.cc @@ -13,6 +13,7 @@ #include "chrome/browser/ui/gtk/constrained_window_gtk.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/login/login_model.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/tab_contents/navigation_controller.h" @@ -115,7 +116,9 @@ class LoginHandlerGtk : public LoginHandler, TabContents* requesting_contents = GetTabContentsForLogin(); DCHECK(requesting_contents); - SetDialog(new ConstrainedWindowGtk(requesting_contents, this)); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(requesting_contents); + SetDialog(new ConstrainedWindowGtk(wrapper, this)); NotifyAuthNeeded(); } diff --git a/chrome/browser/ui/login/login_prompt_mac.mm b/chrome/browser/ui/login/login_prompt_mac.mm index 93ccae4..99868e0 100644 --- a/chrome/browser/ui/login/login_prompt_mac.mm +++ b/chrome/browser/ui/login/login_prompt_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -13,6 +13,7 @@ #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/cocoa/constrained_window_mac.h" #include "chrome/browser/ui/login/login_model.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/tab_contents/navigation_controller.h" @@ -71,7 +72,12 @@ class LoginHandlerMac : public LoginHandler, // control). However, that's OK since any UI interaction in those functions // will occur via an InvokeLater on the UI thread, which is guaranteed // to happen after this is called (since this was InvokeLater'd first). - SetDialog(new ConstrainedWindowMac(GetTabContentsForLogin(), this)); + TabContents* requesting_contents = GetTabContentsForLogin(); + DCHECK(requesting_contents); + + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(requesting_contents); + SetDialog(new ConstrainedWindowMac(wrapper, this)); NotifyAuthNeeded(); } diff --git a/chrome/browser/ui/login/login_prompt_win.cc b/chrome/browser/ui/login/login_prompt_win.cc index 1a9a449..93d855d 100644 --- a/chrome/browser/ui/login/login_prompt_win.cc +++ b/chrome/browser/ui/login/login_prompt_win.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/constrained_window_views.h" #include "chrome/browser/ui/views/login_view.h" #include "content/browser/browser_thread.h" @@ -123,7 +124,10 @@ class LoginHandlerWin : public LoginHandler, // control). However, that's OK since any UI interaction in those functions // will occur via an InvokeLater on the UI thread, which is guaranteed // to happen after this is called (since this was InvokeLater'd first). - SetDialog(new ConstrainedWindowViews(GetTabContentsForLogin(), this)); + TabContents* requesting_contents = GetTabContentsForLogin(); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(requesting_contents); + SetDialog(new ConstrainedWindowViews(wrapper, this)); NotifyAuthNeeded(); } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 2cd321f7..7a97a87 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -43,6 +43,7 @@ #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/intents/web_intent_picker_factory_impl.h" #include "chrome/browser/ui/intents/web_intent_picker_controller.h" @@ -250,6 +251,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) automation_tab_helper_.reset(new AutomationTabHelper(contents)); blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); bookmark_tab_helper_.reset(new BookmarkTabHelper(this)); + constrained_window_tab_helper_.reset(new ConstrainedWindowTabHelper(this)); extension_tab_helper_.reset(new ExtensionTabHelper(this)); favicon_tab_helper_.reset(new FaviconTabHelper(contents)); find_tab_helper_.reset(new FindTabHelper(contents)); diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 019c0b7..5a532eb 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -23,6 +23,7 @@ class AutofillManager; class AutomationTabHelper; class BlockedContentTabHelper; class BookmarkTabHelper; +class ConstrainedWindowTabHelper; class DownloadRequestLimiterObserver; class Extension; class ExtensionTabHelper; @@ -158,6 +159,10 @@ class TabContentsWrapper : public TabContentsObserver, return bookmark_tab_helper_.get(); } + ConstrainedWindowTabHelper* constrained_window_tab_helper() { + return constrained_window_tab_helper_.get(); + } + ExtensionTabHelper* extension_tab_helper() { return extension_tab_helper_.get(); } @@ -274,6 +279,7 @@ class TabContentsWrapper : public TabContentsObserver, scoped_ptr<AutomationTabHelper> automation_tab_helper_; scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; scoped_ptr<BookmarkTabHelper> bookmark_tab_helper_; + scoped_ptr<ConstrainedWindowTabHelper> constrained_window_tab_helper_; scoped_ptr<ExtensionTabHelper> extension_tab_helper_; scoped_ptr<FaviconTabHelper> favicon_tab_helper_; scoped_ptr<FindTabHelper> find_tab_helper_; diff --git a/chrome/browser/ui/views/collected_cookies_win.cc b/chrome/browser/ui/views/collected_cookies_win.cc index 51b3b9f..d68290d 100644 --- a/chrome/browser/ui/views/collected_cookies_win.cc +++ b/chrome/browser/ui/views/collected_cookies_win.cc @@ -181,7 +181,7 @@ CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window, Init(); - window_ = new ConstrainedWindowViews(wrapper->tab_contents(), this); + window_ = new ConstrainedWindowViews(wrapper, this); } CollectedCookiesWin::~CollectedCookiesWin() { diff --git a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc index 7f0754b..38c33a9 100644 --- a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc +++ b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc @@ -127,7 +127,7 @@ ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( ConstrainedHtmlDelegateGtk* constrained_delegate = new ConstrainedHtmlDelegateGtk(profile, delegate); ConstrainedWindow* constrained_window = - new ConstrainedWindowGtk(wrapper->tab_contents(), constrained_delegate); + new ConstrainedWindowGtk(wrapper, constrained_delegate); constrained_delegate->set_window(constrained_window); return constrained_window; } diff --git a/chrome/browser/ui/views/constrained_html_delegate_views.cc b/chrome/browser/ui/views/constrained_html_delegate_views.cc index 74c2dbe2..606bc41 100644 --- a/chrome/browser/ui/views/constrained_html_delegate_views.cc +++ b/chrome/browser/ui/views/constrained_html_delegate_views.cc @@ -129,8 +129,7 @@ ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( ConstrainedHtmlDelegateViews* constrained_delegate = new ConstrainedHtmlDelegateViews(profile, delegate); ConstrainedWindow* constrained_window = - new ConstrainedWindowViews(container->tab_contents(), - constrained_delegate); + new ConstrainedWindowViews(container, constrained_delegate); constrained_delegate->set_window(constrained_window); return constrained_window; #endif diff --git a/chrome/browser/ui/views/constrained_window_views.cc b/chrome/browser/ui/views/constrained_window_views.cc index 22c2cd7..3321016 100644 --- a/chrome/browser/ui/views/constrained_window_views.cc +++ b/chrome/browser/ui/views/constrained_window_views.cc @@ -9,6 +9,8 @@ #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" @@ -211,7 +213,7 @@ class ConstrainedWindowFrameView gfx::Rect CalculateClientAreaBounds(int width, int height) const; SkColor GetTitleColor() const { - return container_->owner()->browser_context()->IsOffTheRecord() + return container_->owner()->profile()->IsOffTheRecord() #if defined(OS_WIN) && !defined(USE_AURA) || !views::NativeWidgetWin::IsAeroGlassEnabled() #endif @@ -588,9 +590,9 @@ void ConstrainedWindowFrameView::InitClass() { // ConstrainedWindowViews, public: ConstrainedWindowViews::ConstrainedWindowViews( - TabContents* owner, + TabContentsWrapper* wrapper, views::WidgetDelegate* widget_delegate) - : owner_(owner), + : wrapper_(wrapper), ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { views::Widget::InitParams params; @@ -606,15 +608,17 @@ ConstrainedWindowViews::ConstrainedWindowViews( // which has an inputmethod object that knows where to forward // event. } else { - params.parent_widget = static_cast<TabContentsViewViews*>(owner->view()); + params.parent_widget = + static_cast<TabContentsViewViews*>(wrapper->view()); } } else { params.child = true; - params.parent = owner->GetNativeView(); + params.parent = wrapper->tab_contents()->GetNativeView(); } Init(params); - owner->AddConstrainedDialog(this); + + wrapper_->constrained_window_tab_helper()->AddConstrainedDialog(this); } ConstrainedWindowViews::~ConstrainedWindowViews() { @@ -627,20 +631,24 @@ void ConstrainedWindowViews::ShowConstrainedWindow() { // We marked the view as hidden during construction. Mark it as // visible now so FocusManager will let us receive focus. non_client_view()->SetVisible(true); - if (owner_->delegate()) - owner_->delegate()->WillShowConstrainedWindow(owner_); + ConstrainedWindowTabHelper* helper = + wrapper_->constrained_window_tab_helper(); + if (helper && helper->delegate()) + helper->delegate()->WillShowConstrainedWindow(wrapper_); Activate(); FocusConstrainedWindow(); } void ConstrainedWindowViews::CloseConstrainedWindow() { - owner_->WillClose(this); + wrapper_->constrained_window_tab_helper()->WillClose(this); Close(); } void ConstrainedWindowViews::FocusConstrainedWindow() { - if ((!owner_->delegate() || - owner_->delegate()->ShouldFocusConstrainedWindow()) && + ConstrainedWindowTabHelper* helper = + wrapper_->constrained_window_tab_helper(); + if ((!helper->delegate() || + helper->delegate()->ShouldFocusConstrainedWindow()) && widget_delegate() && widget_delegate()->GetInitiallyFocusedView()) { widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); @@ -658,9 +666,7 @@ views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { - // Tell our constraining TabContents that we've gone so it can update its - // list. - owner_->WillClose(this); + wrapper_->constrained_window_tab_helper()->WillClose(this); } void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { diff --git a/chrome/browser/ui/views/constrained_window_views.h b/chrome/browser/ui/views/constrained_window_views.h index ef29024..8f84461 100644 --- a/chrome/browser/ui/views/constrained_window_views.h +++ b/chrome/browser/ui/views/constrained_window_views.h @@ -12,7 +12,7 @@ #include "ui/gfx/rect.h" #include "views/widget/widget.h" -class TabContents; +class TabContentsWrapper; namespace views { namespace internal { @@ -58,12 +58,12 @@ class ConstrainedWindowViews : public views::Widget, public ConstrainedWindow, public NativeConstrainedWindowDelegate { public: - ConstrainedWindowViews(TabContents* owner, + ConstrainedWindowViews(TabContentsWrapper* wrapper, views::WidgetDelegate* widget_delegate); virtual ~ConstrainedWindowViews(); - // Returns the TabContents that constrains this Constrained Window. - TabContents* owner() const { return owner_; } + // Returns the TabContentsWrapper that constrains this Constrained Window. + TabContentsWrapper* owner() const { return wrapper_; } // Overridden from ConstrainedWindow: virtual void ShowConstrainedWindow() OVERRIDE; @@ -80,8 +80,7 @@ class ConstrainedWindowViews : public views::Widget, virtual views::internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE; - // The TabContents that owns and constrains this ConstrainedWindow. - TabContents* owner_; + TabContentsWrapper* wrapper_; NativeConstrainedWindow* native_constrained_window_; diff --git a/chrome/browser/ui/views/default_search_view.cc b/chrome/browser/ui/views/default_search_view.cc index 098564b..8bfbfad 100644 --- a/chrome/browser/ui/views/default_search_view.cc +++ b/chrome/browser/ui/views/default_search_view.cc @@ -11,6 +11,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/constrained_window_views.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" @@ -194,7 +195,9 @@ DefaultSearchView::DefaultSearchView(TabContents* tab_contents, SetupControls(prefs); // Show the dialog. - new ConstrainedWindowViews(tab_contents, this); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + new ConstrainedWindowViews(wrapper, this); } void DefaultSearchView::SetupControls(PrefService* prefs) { diff --git a/chrome/browser/ui/views/repost_form_warning_view.cc b/chrome/browser/ui/views/repost_form_warning_view.cc index b9a5c4f..ce48ddf 100644 --- a/chrome/browser/ui/views/repost_form_warning_view.cc +++ b/chrome/browser/ui/views/repost_form_warning_view.cc @@ -8,6 +8,7 @@ #include "chrome/browser/repost_form_warning_controller.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/constrained_window_views.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/tab_contents.h" @@ -38,7 +39,9 @@ RepostFormWarningView::RepostFormWarningView( ui::MessageBoxFlags::kIsConfirmMessageBox, UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING)), std::wstring()); - controller_->set_window(new ConstrainedWindowViews(tab_contents, this)); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + controller_->set_window(new ConstrainedWindowViews(wrapper, this)); } RepostFormWarningView::~RepostFormWarningView() { diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector.cc b/chrome/browser/ui/views/ssl_client_certificate_selector.cc index 134e5d9..c164409 100644 --- a/chrome/browser/ui/views/ssl_client_certificate_selector.cc +++ b/chrome/browser/ui/views/ssl_client_certificate_selector.cc @@ -132,7 +132,7 @@ void SSLClientCertificateSelector::Init() { StartObserving(); - window_ = new ConstrainedWindowViews(wrapper_->tab_contents(), this); + window_ = new ConstrainedWindowViews(wrapper_, this); // Select the first row automatically. This must be done after the dialog has // been created. diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc index 827a37b..0a164b9 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc @@ -7,6 +7,8 @@ #include <vector> #include "base/time.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/sad_tab_view.h" #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" @@ -163,11 +165,20 @@ void TabContentsViewViews::Focus() { return; } - if (tab_contents_->constrained_window_count() > 0) { - ConstrainedWindow* window = *tab_contents_->constrained_window_begin(); - DCHECK(window); - window->FocusConstrainedWindow(); - return; + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); + if (wrapper) { + // TODO(erg): TabContents used to own constrained windows, which is why + // this is here. Eventually this should be ported to a containing view + // specializing in constrained window management. + ConstrainedWindowTabHelper* helper = + wrapper->constrained_window_tab_helper(); + if (helper->constrained_window_count() > 0) { + ConstrainedWindow* window = *helper->constrained_window_begin(); + DCHECK(window); + window->FocusConstrainedWindow(); + return; + } } RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); diff --git a/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc b/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc index e16f829..890a986 100644 --- a/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc +++ b/chrome/browser/ui/webui/constrained_html_ui_browsertest.cc @@ -8,6 +8,7 @@ #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/constrained_html_ui.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" @@ -74,5 +75,6 @@ IN_PROC_BROWSER_TEST_F(ConstrainedHtmlDialogBrowserTest, BasicTest) { delegate, wrapper); - ASSERT_EQ(1U, wrapper->tab_contents()->constrained_window_count()); + ASSERT_EQ(1U, wrapper->constrained_window_tab_helper()-> + constrained_window_count()); } |