diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 15:04:27 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 15:04:27 +0000 |
commit | 9cddb1a26ca716f6e3f42bc8d7180a2809afea69 (patch) | |
tree | 62c18c1dec6a8c9efda6ddb0054441d51054cccc /chrome/browser/tab_contents | |
parent | b60ae4b0ea0bcdd455e45a4971da0ddfc6464c69 (diff) | |
download | chromium_src-9cddb1a26ca716f6e3f42bc8d7180a2809afea69.zip chromium_src-9cddb1a26ca716f6e3f42bc8d7180a2809afea69.tar.gz chromium_src-9cddb1a26ca716f6e3f42bc8d7180a2809afea69.tar.bz2 |
Move Sad Tab implementation out of the TabContentsViews.
BUG=103258
TEST=no change in sad tab behavior
Review URL: http://codereview.chromium.org/8477042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
6 files changed, 50 insertions, 112 deletions
diff --git a/chrome/browser/tab_contents/background_contents.cc b/chrome/browser/tab_contents/background_contents.cc index b52f39b..19d04f3 100644 --- a/chrome/browser/tab_contents/background_contents.cc +++ b/chrome/browser/tab_contents/background_contents.cc @@ -94,7 +94,7 @@ void BackgroundContents::DidNavigateMainFramePostCommit(TabContents* tab) { content::Details<BackgroundContents>(this)); } -void BackgroundContents::RenderViewGone() { +void BackgroundContents::RenderViewGone(base::TerminationStatus status) { content::NotificationService::current()->Notify( chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, content::Source<Profile>(profile_), @@ -103,7 +103,7 @@ void BackgroundContents::RenderViewGone() { // Our RenderView went away, so we should go away also, so killing the process // via the TaskManager doesn't permanently leave a BackgroundContents hanging // around the system, blocking future instances from being created - // (http://crbug.com/65189). + // <http://crbug.com/65189>. delete this; } diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index e92f517..fc3a443 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -51,7 +51,7 @@ class BackgroundContents : public TabContentsDelegate, virtual void DidNavigateMainFramePostCommit(TabContents* tab) OVERRIDE; // TabContentsObserver implementation: - virtual void RenderViewGone() OVERRIDE; + virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; // content::NotificationObserver virtual void Observe(int type, diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 4284f64..d297b99 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -13,11 +13,9 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "build/build_config.h" -#include "chrome/browser/browser_shutdown.h" #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" #include "chrome/browser/ui/gtk/constrained_window_gtk.h" -#include "chrome/browser/ui/gtk/sad_tab_gtk.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_gtk.h" @@ -26,8 +24,6 @@ #include "content/browser/tab_contents/tab_contents_delegate.h" #include "content/browser/tab_contents/web_drag_dest_gtk.h" #include "content/browser/tab_contents/web_drag_source_gtk.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "ui/base/gtk/gtk_expanded_container.h" #include "ui/base/gtk/gtk_floating_container.h" #include "ui/gfx/point.h" @@ -81,7 +77,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) : tab_contents_(tab_contents), floating_(gtk_floating_container_new()), expanded_(gtk_expanded_container_new()), - constrained_window_(NULL) { + constrained_window_(NULL), + overlaid_view_(NULL) { gtk_widget_set_name(expanded_, "chrome-tab-contents-view"); g_signal_connect(expanded_, "size-allocate", G_CALLBACK(OnSizeAllocateThunk), this); @@ -93,8 +90,6 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_); gtk_widget_show(expanded_); gtk_widget_show(floating_.get()); - registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, - content::Source<TabContents>(tab_contents)); drag_source_.reset(new content::WebDragSourceGtk(tab_contents)); } @@ -198,20 +193,6 @@ void TabContentsViewGtk::SetPageTitle(const string16& title) { void TabContentsViewGtk::OnTabCrashed(base::TerminationStatus status, int error_code) { - // Only show the sad tab if we're not in browser shutdown, so that TabContents - // objects that are not in a browser (e.g., HTML dialogs) and thus are - // visible do not flash a sad tab page. - if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) - return; - - if (tab_contents_ != NULL && !sad_tab_.get()) { - sad_tab_.reset(new SadTabGtk( - tab_contents_, - status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? - SadTabGtk::KILLED : SadTabGtk::CRASHED)); - InsertIntoContentArea(sad_tab_->widget()); - gtk_widget_show(sad_tab_->widget()); - } } void TabContentsViewGtk::SizeContents(const gfx::Size& size) { @@ -279,6 +260,19 @@ void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const { out->SetRect(x, y, w, h); } +void TabContentsViewGtk::InstallOverlayView(gfx::NativeView view) { + DCHECK(!overlaid_view_); + overlaid_view_ = view; + InsertIntoContentArea(view); + gtk_widget_show(view); +} + +void TabContentsViewGtk::RemoveOverlayView() { + DCHECK(overlaid_view_); + gtk_container_remove(GTK_CONTAINER(expanded_), overlaid_view_); + overlaid_view_ = NULL; +} + void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { focus_store_.SetWidget(widget); } @@ -301,24 +295,6 @@ void TabContentsViewGtk::TakeFocus(bool reverse) { } } -void TabContentsViewGtk::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: { - // No need to remove the SadTabGtk's widget from the container since - // the new RenderWidgetHostViewGtk instance already removed all the - // vbox's children. - sad_tab_.reset(); - break; - } - default: - NOTREACHED() << "Got a notification we didn't register for."; - break; - } -} - - void TabContentsViewGtk::CreateNewWindow( int route_id, const ViewHostMsg_CreateWindow_Params& params) { diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index feb56b2..efa4133 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -14,14 +14,11 @@ #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" #include "chrome/browser/ui/gtk/focus_store_gtk.h" #include "content/browser/tab_contents/tab_contents_view.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/owned_widget_gtk.h" class ConstrainedWindowGtk; class RenderViewContextMenuGtk; -class SadTabGtk; class WebDragBookmarkHandlerGtk; namespace content { @@ -29,8 +26,7 @@ class WebDragDestGtk; class WebDragSourceGtk; } -class TabContentsViewGtk : public TabContentsView, - public content::NotificationObserver { +class TabContentsViewGtk : public TabContentsView { public: // The corresponding TabContents is passed in the constructor, and manages our // lifetime. This doesn't need to be the case, but is this way currently @@ -71,6 +67,8 @@ class TabContentsViewGtk : public TabContentsView, virtual bool IsEventTracking() const OVERRIDE; virtual void CloseTabAfterEventTracking() OVERRIDE; virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE; + virtual void InstallOverlayView(gfx::NativeView view) OVERRIDE; + virtual void RemoveOverlayView() OVERRIDE; // Backend implementation of RenderViewHostDelegate::View. virtual void CreateNewWindow( @@ -99,12 +97,6 @@ class TabContentsViewGtk : public TabContentsView, virtual void GotFocus(); virtual void TakeFocus(bool reverse); - // content::NotificationObserver implementation ------------------------------ - - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details); - private: // Insert the given widget into the content area. Should only be used for // web pages and the like (including interstitials and sad tab). Note that @@ -136,7 +128,6 @@ class TabContentsViewGtk : public TabContentsView, // Common implementations of some RenderViewHostDelegate::View methods. RenderViewHostDelegateViewHelper delegate_view_helper_; - // Contains |expanded_| as its GtkBin member. ui::OwnedWidgetGtk floating_; @@ -148,11 +139,6 @@ class TabContentsViewGtk : public TabContentsView, // between uses so that it won't go out of scope before we're done with it. scoped_ptr<RenderViewContextMenuGtk> context_menu_; - // Used to get notifications about renderers coming and going. - content::NotificationRegistrar registrar_; - - scoped_ptr<SadTabGtk> sad_tab_; - FocusStoreGtk focus_store_; // The UI for the constrained dialog currently displayed. This is owned by @@ -173,6 +159,10 @@ class TabContentsViewGtk : public TabContentsView, // variable because resizing in GTK+ is async. gfx::Size requested_size_; + // The overlaid view. Owned by the caller of |InstallOverlayView|; this is a + // weak reference. + GtkWidget* overlaid_view_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk); }; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 670358b..406e221 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -17,8 +17,6 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" #include "content/browser/tab_contents/tab_contents_view.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/base/cocoa/base_view.h" #include "ui/gfx/size.h" @@ -48,8 +46,7 @@ class Point; // Mac-specific implementation of the TabContentsView. It owns an NSView that // contains all of the contents of the tab and associated child views. -class TabContentsViewMac : public TabContentsView, - public content::NotificationObserver { +class TabContentsViewMac : public TabContentsView { public: // The corresponding TabContents is passed in the constructor, and manages our // lifetime. This doesn't need to be the case, but is this way currently @@ -80,6 +77,8 @@ class TabContentsViewMac : public TabContentsView, virtual bool IsEventTracking() const OVERRIDE; virtual void CloseTabAfterEventTracking() OVERRIDE; virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE; + virtual void InstallOverlayView(gfx::NativeView view) OVERRIDE; + virtual void RemoveOverlayView() OVERRIDE; // Backend implementation of RenderViewHostDelegate::View. virtual void CreateNewWindow( @@ -108,12 +107,6 @@ class TabContentsViewMac : public TabContentsView, virtual void GotFocus(); virtual void TakeFocus(bool reverse); - // content::NotificationObserver implementation ------------------------------ - - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details); - // A helper method for closing the tab in the // CloseTabAfterEventTracking() implementation. void CloseTab(); @@ -135,19 +128,16 @@ class TabContentsViewMac : public TabContentsView, // focus returns. scoped_nsobject<FocusTracker> focus_tracker_; - // Used to get notifications about renderers coming and going. - content::NotificationRegistrar registrar_; - - // Used to render the sad tab. This will be non-NULL only when the sad tab is - // visible. - scoped_nsobject<SadTabController> sad_tab_; - // The context menu. Callbacks are asynchronous so we need to keep it around. scoped_ptr<RenderViewContextMenuMac> context_menu_; // The page content's intrinsic width. int preferred_width_; + // The overlaid view. Owned by the caller of |InstallOverlayView|; this is a + // weak reference. + NSView* overlaid_view_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewMac); }; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 6f71e3a..ba507b4 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -8,12 +8,10 @@ #include <string> -#include "chrome/browser/browser_shutdown.h" #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" #import "chrome/browser/ui/cocoa/focus_tracker.h" -#import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" #import "chrome/browser/ui/cocoa/view_id_util.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host_factory.h" @@ -27,9 +25,6 @@ #import "content/common/chrome_application_mac.h" #import "content/common/mac/scoped_sending_event.h" #include "content/common/view_messages.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" @@ -71,9 +66,8 @@ TabContentsView* CreateTabContentsView(TabContents* tab_contents) { TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) : tab_contents_(tab_contents), - preferred_width_(0) { - registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, - content::Source<TabContents>(tab_contents)); + preferred_width_(0), + overlaid_view_(nil) { } TabContentsViewMac::~TabContentsViewMac() { @@ -120,6 +114,8 @@ RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget( NSView* view_view = view->native_view(); [view_view setFrame:[cocoa_view_.get() bounds]]; [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + // Add the new view below all other views; this also keeps it below any + // overlay view installed. [cocoa_view_.get() addSubview:view_view positioned:NSWindowBelow relativeTo:nil]; @@ -188,21 +184,6 @@ void TabContentsViewMac::SetPageTitle(const string16& title) { void TabContentsViewMac::OnTabCrashed(base::TerminationStatus /* status */, int /* error_code */) { - // Only show the sad tab if we're not in browser shutdown, so that TabContents - // objects that are not in a browser (e.g., HTML dialogs) and thus are - // visible do not flash a sad tab page. - if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) - return; - - if (!sad_tab_.get()) { - DCHECK(tab_contents_); - if (tab_contents_) { - SadTabController* sad_tab = - [[SadTabController alloc] initWithTabContents:tab_contents_ - superview:cocoa_view_]; - sad_tab_.reset(sad_tab); - } - } } void TabContentsViewMac::SizeContents(const gfx::Size& size) { @@ -397,21 +378,22 @@ void TabContentsViewMac::GetViewBounds(gfx::Rect* out) const { NOTIMPLEMENTED(); } -void TabContentsViewMac::CloseTab() { - tab_contents_->Close(tab_contents_->render_view_host()); +void TabContentsViewMac::InstallOverlayView(gfx::NativeView view) { + DCHECK(!overlaid_view_); + overlaid_view_ = view; + [view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; + [cocoa_view_.get() addSubview:view]; + [view setFrame:[cocoa_view_.get() bounds]]; } -void TabContentsViewMac::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: { - sad_tab_.reset(); - break; - } - default: - NOTREACHED() << "Got a notification we didn't register for."; - } +void TabContentsViewMac::RemoveOverlayView() { + DCHECK(overlaid_view_); + [overlaid_view_ removeFromSuperview]; + overlaid_view_ = nil; +} + +void TabContentsViewMac::CloseTab() { + tab_contents_->Close(tab_contents_->render_view_host()); } @implementation TabContentsViewCocoa |