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/cocoa | |
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/cocoa')
8 files changed, 37 insertions, 22 deletions
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]; |