diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 20:31:32 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 20:31:32 +0000 |
commit | 76f68dc0563bd9acf63e7b8989da0205fd1e7968 (patch) | |
tree | 03f7739a6b801b9af080874aeb21f61055f49045 | |
parent | 92a208486448513db6cf7b33372f329c6a82ea6f (diff) | |
download | chromium_src-76f68dc0563bd9acf63e7b8989da0205fd1e7968.zip chromium_src-76f68dc0563bd9acf63e7b8989da0205fd1e7968.tar.gz chromium_src-76f68dc0563bd9acf63e7b8989da0205fd1e7968.tar.bz2 |
First step at removing TabContents from temp scaffolding. Get rid of duplicated code in scaffolding in deference to equivalent code in tab_contents.cc.
Review URL: http://codereview.chromium.org/42031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11372 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 27 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 182 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 21 |
4 files changed, 49 insertions, 182 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 56db088..d9c7191 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -5,6 +5,7 @@ #if defined(OS_WIN) #include "chrome/browser/tab_contents/tab_contents.h" #elif defined(OS_POSIX) +// TODO(port): port the rest of this file. #include "chrome/common/temp_scaffolding_stubs.h" #endif @@ -32,7 +33,6 @@ #include "chrome/views/widget.h" #endif -// TODO(port): port the rest of this file. #if defined(OS_WIN) namespace { @@ -61,8 +61,10 @@ TabContents::TabContents(TabContentsType type) last_focused_view_storage_id_ = views::ViewStorage::GetSharedInstance()->CreateStorageID(); } +#endif TabContents::~TabContents() { +#if defined(OS_WIN) // Makes sure to remove any stored view we may still have in the ViewStorage. // // It is possible the view went away before us, so we only do this if the @@ -70,6 +72,7 @@ TabContents::~TabContents() { views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) view_storage->RemoveView(last_focused_view_storage_id_); +#endif } // static @@ -88,6 +91,7 @@ void TabContents::Destroy() { DCHECK(!is_being_destroyed_); is_being_destroyed_ = true; +#if defined(OS_WIN) // 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 @@ -107,6 +111,7 @@ void TabContents::Destroy() { delegate->InfoBarClosed(); } infobar_delegates_.clear(); +#endif // Notify any observer that have a reference on this tab contents. NotificationService::current()->Notify( @@ -114,10 +119,12 @@ void TabContents::Destroy() { Source<TabContents>(this), NotificationService::NoDetails()); +#if defined(OS_WIN) // If we still have a window handle, destroy it. GetNativeView can return // NULL if this contents was part of a window that closed. if (GetNativeView()) ::DestroyWindow(GetNativeView()); +#endif // Notify our NavigationController. Make sure we are deleted first, so // that the controller is the last to die. @@ -191,7 +198,6 @@ void TabContents::UpdateMaxPageID(int32 page_id) { const std::wstring TabContents::GetDefaultTitle() const { return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE); } -#endif // defined(OS_WIN) SkBitmap TabContents::GetFavIcon() const { // Like GetTitle(), we also want to use the favicon for the last committed @@ -236,6 +242,7 @@ bool TabContents::GetSSLEVText(std::wstring* ev_text, return SSLManager::GetEVCertNames(*cert, ev_text, ev_tooltip_text); } +#endif void TabContents::SetIsCrashed(bool state) { if (state == is_crashed_) @@ -255,8 +262,10 @@ void TabContents::DidBecomeSelected() { if (controller_) controller_->SetActive(true); +#if defined(OS_WIN) // Invalidate all descendants. (take care to exclude invalidating ourselves!) EnumChildWindows(GetNativeView(), InvalidateWindow, 0); +#endif } void TabContents::WasHidden() { @@ -280,11 +289,13 @@ void TabContents::OpenURL(const GURL& url, const GURL& referrer, bool TabContents::NavigateToPendingEntry(bool reload) { // Our benavior is just to report that the entry was committed. - controller()->GetPendingEntry()->set_title(GetDefaultTitle()); + string16 default_title = WideToUTF16Hack(GetDefaultTitle()); + controller()->GetPendingEntry()->set_title(default_title); controller()->CommitPendingEntry(); return true; } +#if defined(OS_WIN) ConstrainedWindow* TabContents::CreateConstrainedDialog( views::WindowDelegate* window_delegate, views::View* contents_view) { @@ -490,7 +501,6 @@ void TabContents::SetDownloadShelfVisible(bool visible) { ToolbarSizeChanged(false); } -#if defined(OS_WIN) || defined(OS_LINUX) void TabContents::OnStartDownload(DownloadItem* download) { DCHECK(download); TabContents* tab_contents = this; @@ -542,7 +552,6 @@ void TabContents::MigrateShelf(TabContents* from, TabContents* to) { to->MigrateShelfFrom(from); to->SetDownloadShelfVisible(was_shelf_visible); } -#endif // defined(OS_WIN) || defined(OS_LINUX) #if defined(OS_WIN) void TabContents::WillClose(ConstrainedWindow* window) { @@ -576,6 +585,7 @@ void TabContents::Observe(NotificationType type, *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); ExpireInfoBars(committed_details); } +#endif void TabContents::SetIsLoading(bool is_loading, LoadNotificationDetails* details) { @@ -594,14 +604,15 @@ void TabContents::SetIsLoading(bool is_loading, NotificationType type = is_loading ? NotificationType::LOAD_START : NotificationType::LOAD_STOP; - NotificationDetails det = details ? - Details<LoadNotificationDetails>(details) : - NotificationService::NoDetails(); + NotificationDetails det = NotificationService::NoDetails();; + if (details) + det = Details<LoadNotificationDetails>(details); NotificationService::current()->Notify(type, Source<NavigationController>(this->controller()), det); } +#if defined(OS_WIN) // TODO(brettw) This should be on the WebContentsView. void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { // TODO(erg): There's no way to detect whether scroll bars are diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index df6da82..013bc6a 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1187,6 +1187,7 @@ ['exclude', '^browser/download/'], ['include', '^browser/download/download_(file|manager|shelf)\\.cc$'], ['include', '^browser/download/download_request_manager\\.cc$'], + ['include', '^browser/download/download_item_model\\.cc$'], ['include', '^browser/download/save_(file(_manager)?|item|package)\\.cc$'], ], 'sources!': [ diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 174459a..5d1e633 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -242,169 +242,6 @@ void UninstallJankometer() { //-------------------------------------------------------------------------- -void TabContents::SetupController(Profile* profile) { - DCHECK(!controller_); - controller_ = new NavigationController(this, profile); -} - -Profile* TabContents::profile() const { - return controller_ ? controller_->profile() : NULL; -} - -void TabContents::CloseContents() { - // Destroy our NavigationController, which will Destroy all tabs it owns. - controller_->Destroy(); - // Note that the controller may have deleted us at this point, - // so don't touch any member variables here. -} - -void TabContents::Destroy() { - // TODO(pinkerton): this isn't the real version of Destroy(), just enough to - // get the scaffolding working. - - is_being_destroyed_ = true; - - // Notify any observer that have a reference on this tab contents. - NotificationService::current()->Notify( - NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(this), - NotificationService::NoDetails()); - - // Notify our NavigationController. Make sure we are deleted first, so - // that the controller is the last to die. - NavigationController* controller = controller_; - TabContentsType type = this->type(); - - delete this; - - controller->TabContentsWasDestroyed(type); -} - -const GURL& TabContents::GetURL() const { - // We may not have a navigation entry yet - NavigationEntry* entry = controller_->GetActiveEntry(); - return entry ? entry->display_url() : GURL::EmptyGURL(); -} - -const string16& TabContents::GetTitle() const { - // We use the title for the last committed entry rather than a pending - // navigation entry. For example, when the user types in a URL, we want to - // keep the old page's title until the new load has committed and we get a new - // title. - // The exception is with transient pages, for which we really want to use - // their title, as they are not committed. - NavigationEntry* entry = controller_->GetTransientEntry(); - if (entry) - return entry->GetTitleForDisplay(controller_); - - entry = controller_->GetLastCommittedEntry(); - if (entry) - return entry->GetTitleForDisplay(controller_); - else if (controller_->LoadingURLLazily()) - return controller_->GetLazyTitle(); - return EmptyString16(); -} - -void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { - if (delegate_) - delegate_->NavigationStateChanged(this, changed_flags); -} - -void TabContents::OpenURL(const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition) { - if (delegate_) - delegate_->OpenURLFromTab(this, url, referrer, disposition, transition); -} - -void TabContents::SetIsLoading(bool is_loading, - LoadNotificationDetails* details) { - if (is_loading == is_loading_) - return; - - is_loading_ = is_loading; - waiting_for_response_ = is_loading; - - // Suppress notifications for this TabContents if we are not active. - if (!is_active_) - return; - - if (delegate_) - delegate_->LoadingStateChanged(this); - - NotificationType type = is_loading ? NotificationType::LOAD_START : - NotificationType::LOAD_STOP; - NotificationDetails det = NotificationService::NoDetails();; - if (details) - det = Details<LoadNotificationDetails>(details); - NotificationService::current()->Notify(type, - Source<NavigationController>(this->controller()), - det); -} - -bool TabContents::SupportsURL(GURL* url) { - GURL u(*url); - if (TabContents::TypeForURL(&u) == type()) { - *url = u; - return true; - } - return false; -} - -int32 TabContents::GetMaxPageID() { - if (GetSiteInstance()) - return GetSiteInstance()->max_page_id(); - else - return max_page_id_; -} - -void TabContents::UpdateMaxPageID(int32 page_id) { - // Ensure both the SiteInstance and RenderProcessHost update their max page - // IDs in sync. Only WebContents will also have site instances, except during - // testing. - if (GetSiteInstance()) - GetSiteInstance()->UpdateMaxPageID(page_id); - - if (AsWebContents()) - AsWebContents()->process()->UpdateMaxPageID(page_id); - else - max_page_id_ = std::max(max_page_id_, page_id); -} - -void TabContents::SetIsCrashed(bool state) { - if (state == is_crashed_) - return; - - is_crashed_ = state; - if (delegate_) - delegate_->ContentsStateChanged(this); -} - -#if defined(OS_MACOSX) -void TabContents::OnStartDownload(DownloadItem* download){ - NOTIMPLEMENTED(); -} - -DownloadShelf* TabContents::GetDownloadShelf(){ - NOTIMPLEMENTED(); - return NULL; -} - -void TabContents::ReleaseDownloadShelf() { - NOTIMPLEMENTED(); -} - -void TabContents::MigrateShelf(TabContents* from, TabContents* to){ - NOTIMPLEMENTED(); -} - -void TabContents::MigrateShelfFrom(TabContents* tab_contents){ - NOTIMPLEMENTED(); -} -#endif - -//-------------------------------------------------------------------------- - void RLZTracker::CleanupRlz() { // http://code.google.com/p/chromium/issues/detail?id=8152 } @@ -427,6 +264,25 @@ bool IsPluginProcess() { //-------------------------------------------------------------------------- +#if defined(OS_MACOSX) + +class DownloadShelfMac : public DownloadShelf { + public: + explicit DownloadShelfMac(TabContents* tab_contents) + : DownloadShelf(tab_contents) { } + virtual void AddDownload(BaseDownloadItemModel* download_model) { } + virtual bool IsShowing() const { return false; } +}; + +// static +DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) { + return new DownloadShelfMac(tab_contents); +} + +#endif + +//-------------------------------------------------------------------------- + void RunJavascriptMessageBox(WebContents* web_contents, const GURL& url, int dialog_flags, diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 1e20c34..d724764 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -432,7 +432,7 @@ class TabContents : public PageNavigator, public NotificationObserver { : type_(type), is_crashed_(false), is_active_(true), is_loading_(false), is_being_destroyed_(false), waiting_for_response_(false), shelf_visible_(false), controller_(), delegate_(), max_page_id_(-1) { } - virtual ~TabContents() { } + virtual ~TabContents(); NavigationController* controller() const { return controller_; } void set_controller(NavigationController* c) { controller_ = c; } virtual WebContents* AsWebContents() { return NULL; } @@ -446,12 +446,12 @@ class TabContents : public PageNavigator, public NotificationObserver { void set_type(TabContentsType type) { type_ = type; } virtual void Focus() { NOTIMPLEMENTED(); } virtual void Stop() { NOTIMPLEMENTED(); } - Profile* profile() const; + Profile* profile() const { + return controller_ ? controller_->profile() : NULL; + } virtual void CloseContents(); virtual void SetupController(Profile* profile); - virtual void WasHidden() { - NOTIMPLEMENTED(); - } + virtual void WasHidden(); virtual void SetInitialFocus() { NOTIMPLEMENTED(); } virtual void SetInitialFocus(bool reverse) { NOTIMPLEMENTED(); } virtual void RestoreFocus() { NOTIMPLEMENTED(); } @@ -462,7 +462,7 @@ class TabContents : public PageNavigator, public NotificationObserver { virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { NOTIMPLEMENTED(); } - virtual void DidBecomeSelected() { NOTIMPLEMENTED(); } + virtual void DidBecomeSelected(); virtual void SetDownloadShelfVisible(bool visible); bool IsDownloadShelfVisible() { return shelf_visible_; } virtual void Destroy(); @@ -490,17 +490,15 @@ class TabContents : public PageNavigator, public NotificationObserver { WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { NOTIMPLEMENTED(); } - virtual void Activate() { NOTIMPLEMENTED(); } + virtual void Activate(); virtual bool SupportsURL(GURL*); virtual SiteInstance* GetSiteInstance() const { return NULL; } int32 GetMaxPageID(); void UpdateMaxPageID(int32); - virtual bool NavigateToPendingEntry(bool) { NOTIMPLEMENTED(); return true; } + virtual bool NavigateToPendingEntry(bool); virtual DOMUIHost* AsDOMUIHost() { return NULL; } virtual std::wstring GetStatusText() const { return std::wstring(); } - static void RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kBlockPopups, false); - } + static void RegisterUserPrefs(PrefService* prefs); virtual void CreateView() {} virtual gfx::NativeView GetNativeView() const { return NULL; } static TabContentsFactory* RegisterFactory(TabContentsType type, @@ -512,6 +510,7 @@ class TabContents : public PageNavigator, public NotificationObserver { DownloadShelf* GetDownloadShelf(); static void MigrateShelf(TabContents* from, TabContents* to); void MigrateShelfFrom(TabContents* tab_contents); + virtual const std::wstring GetDefaultTitle() const; protected: typedef std::vector<ConstrainedWindow*> ConstrainedWindowList; ConstrainedWindowList child_windows_; |