diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 21:56:58 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 21:56:58 +0000 |
commit | a4be1e85d6c73aea61d1c5b118d9804b1a8ca4f8 (patch) | |
tree | 4a2dd47cf3955e32839700f04a281e5cb742653f | |
parent | dbcb6d7712e923327e327b6fea5acf941d444fba (diff) | |
download | chromium_src-a4be1e85d6c73aea61d1c5b118d9804b1a8ca4f8.zip chromium_src-a4be1e85d6c73aea61d1c5b118d9804b1a8ca4f8.tar.gz chromium_src-a4be1e85d6c73aea61d1c5b118d9804b1a8ca4f8.tar.bz2 |
Implement more of the TabContentsDelegate to hook up loading URLs from the location bar where there is UI to do so.
Review URL: http://codereview.chromium.org/21264
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9601 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 32 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 43 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 74 |
5 files changed, 114 insertions, 46 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index af06203..a74a2ee 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1507,8 +1507,6 @@ void Browser::TabStripEmpty() { method_factory_.NewRunnableMethod(&Browser::CloseFrame)); } -#if defined(OS_WIN) - /////////////////////////////////////////////////////////////////////////////// // Browser, TabContentsDelegate implementation: @@ -1652,6 +1650,8 @@ void Browser::ReplaceContents(TabContents* source, TabContents* new_contents) { Source<TabContents>(new_contents)); } +#if defined(OS_WIN) + void Browser::AddNewContents(TabContents* source, TabContents* new_contents, WindowOpenDisposition disposition, @@ -2310,7 +2310,6 @@ bool Browser::HasCompletedUnloadProcessing() { tabs_needing_unload_fired_.empty(); } -#if defined(OS_WIN) void Browser::CancelWindowClose() { DCHECK(is_attempting_to_close_browser_); // Only cancelling beforeunload should be able to cancel the window's close. @@ -2341,7 +2340,6 @@ void Browser::ClearUnloadState(TabContents* tab) { ProcessPendingTabs(); } -#endif // OS_WIN /////////////////////////////////////////////////////////////////////////////// // Browser, Assorted utility functions (private): diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 1259829..ea9a57d 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -356,7 +356,6 @@ class Browser : public TabStripModelDelegate, int to_index); virtual void TabStripEmpty(); -#if defined(OS_WIN) // Overridden from TabContentsDelegate: virtual void OpenURLFromTab(TabContents* source, const GURL& url, const GURL& referrer, @@ -365,6 +364,7 @@ class Browser : public TabStripModelDelegate, virtual void NavigationStateChanged(const TabContents* source, unsigned changed_flags); virtual void ReplaceContents(TabContents* source, TabContents* new_contents); +#if defined(OS_WIN) virtual void AddNewContents(TabContents* source, TabContents* new_contents, WindowOpenDisposition disposition, @@ -477,7 +477,6 @@ class Browser : public TabStripModelDelegate, // Whether we've completed firing all the tabs' beforeunload/unload events. bool HasCompletedUnloadProcessing(); -#if defined(OS_WIN) // Clears all the state associated with processing tabs' beforeunload/unload // events since the user cancelled closing the window. void CancelWindowClose(); @@ -492,7 +491,6 @@ class Browser : public TabStripModelDelegate, // cases where a tab crashes or hangs even if the beforeunload/unload haven't // successfully fired. void ClearUnloadState(TabContents* tab); -#endif // Assorted utility functions /////////////////////////////////////////////// @@ -524,7 +522,6 @@ class Browser : public TabStripModelDelegate, // after a return to the message loop. void CloseFrame(); - // Compute a deterministic name based on the URL. We use this pseudo name // as a key to store window location per application URLs. static std::wstring ComputeApplicationNameFromURL(const GURL& url); diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm index ebcb3d7..31948ec 100644 --- a/chrome/browser/cocoa/tab_contents_controller.mm +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -4,6 +4,7 @@ #include "chrome/browser/cocoa/tab_contents_controller.h" +#import "base/sys_string_conversions.h" #import "chrome/app/chrome_dll_resource.h" #import "chrome/browser/command_updater.h" #import "chrome/browser/location_bar.h" @@ -15,6 +16,11 @@ - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled; @end +@interface TabContentsController(LocationBar) +- (NSString*)locationBarString; +- (void)focusLocationBar; +@end + @interface TabContentsController(Private) - (void)updateToolbarCommandStatus; @end @@ -35,20 +41,22 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver { CommandUpdater* commands_; // weak }; -// TODO(pinkerton): implement these +// A C++ bridge class that handles responding to requests from the +// cross-platform code for information about the location bar. Just passes +// everything back to the controller. class LocationBarBridge : public LocationBar { public: LocationBarBridge(TabContentsController* controller); // Overridden from LocationBar virtual void ShowFirstRunBubble() { NOTIMPLEMENTED(); } - virtual std::wstring GetInputString() const { NOTIMPLEMENTED(); return L""; } + virtual std::wstring GetInputString() const; virtual WindowOpenDisposition GetWindowOpenDisposition() const { NOTIMPLEMENTED(); return NEW_FOREGROUND_TAB; } virtual PageTransition::Type GetPageTransition() const { NOTIMPLEMENTED(); return 0; } virtual void AcceptInput() { NOTIMPLEMENTED(); } - virtual void FocusLocation() { NOTIMPLEMENTED(); } + virtual void FocusLocation(); virtual void FocusSearch() { NOTIMPLEMENTED(); } virtual void SaveStateToContents(TabContents* contents) { NOTIMPLEMENTED(); } @@ -152,6 +160,14 @@ class LocationBarBridge : public LocationBar { [self updateToolbarCommandStatus]; } +- (NSString*)locationBarString { + return [locationBar_ stringValue]; +} + +- (void)focusLocationBar { + [[locationBar_ window] makeFirstResponder:locationBar_]; +} + @end //-------------------------------------------------------------------------- @@ -184,3 +200,13 @@ void TabContentsCommandObserver::EnabledStateChangedForCommand(int command, LocationBarBridge::LocationBarBridge(TabContentsController* controller) : controller_(controller) { } + +std::wstring LocationBarBridge::GetInputString() const { + return base::SysNSStringToWide([controller_ locationBarString]); +} + +void LocationBarBridge::FocusLocation() { + [controller_ focusLocationBar]; +} + + diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 808b038..7497c8b 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -244,6 +244,49 @@ void TabContents::Destroy() { 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 std::wstring& 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(); + + entry = controller_->GetLastCommittedEntry(); + if (entry) + return entry->GetTitleForDisplay(); + else if (controller_->LoadingURLLazily()) + return controller_->GetLazyTitle(); + return EmptyWString(); +} + +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) { + // TODO(port): this is a subset of SetIsLoading() as a stub + is_loading_ = is_loading; +} + //-------------------------------------------------------------------------- bool RLZTracker::GetAccessPointRlz(AccessPoint point, std::wstring* rlz) { diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 9e1974c..937d244 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -29,6 +29,7 @@ #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/browser/tab_contents/page_navigator.h" #include "chrome/browser/tab_contents/tab_contents_type.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" @@ -580,8 +581,17 @@ class FaviconStatus { class TabContentsDelegate { public: - virtual void OpenURL(const GURL&, const GURL&, WindowOpenDisposition, - PageTransition::Type) { NOTIMPLEMENTED(); } + virtual void OpenURLFromTab(TabContents* source, + const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition, + PageTransition::Type transition) { + NOTIMPLEMENTED(); + } + virtual void OpenURL(const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition, + PageTransition::Type transition) { + OpenURLFromTab(NULL, url, referrer, disposition, transition); + } virtual void UpdateTargetURL(TabContents*, const GURL&) { NOTIMPLEMENTED(); } virtual void CloseContents(TabContents*) { NOTIMPLEMENTED(); } virtual void MoveContents(TabContents*, const gfx::Rect&) { @@ -616,6 +626,9 @@ class TabContentsDelegate { virtual void URLStarredChanged(WebContents*, bool) { NOTIMPLEMENTED(); } virtual void ConvertContentsToApplication(WebContents*) { NOTIMPLEMENTED(); } virtual void ReplaceContents(TabContents*, TabContents*) { NOTIMPLEMENTED(); } + virtual void NavigationStateChanged(const TabContents*, unsigned int) { + NOTIMPLEMENTED(); + } }; class InterstitialPage { @@ -643,7 +656,7 @@ class LoadNotificationDetails { base::TimeDelta, NavigationController*, int) { } }; -class TabContents : public NotificationObserver { +class TabContents : public PageNavigator, public NotificationObserver { public: enum InvalidateTypes { INVALIDATE_URL = 1, @@ -652,33 +665,26 @@ class TabContents : public NotificationObserver { INVALIDATE_LOAD = 8, INVALIDATE_EVERYTHING = 0xFFFFFFFF }; - TabContents(TabContentsType) : controller_() { } + TabContents(TabContentsType type) + : type_(type), is_active_(true), is_loading_(false), controller_(), + delegate_() { } virtual ~TabContents() { } NavigationController* controller() const { return controller_; } void set_controller(NavigationController* c) { controller_ = c; } - virtual WebContents* AsWebContents() const { return NULL; } + virtual WebContents* AsWebContents() { return NULL; } + WebContents* AsWebContents() const { + return const_cast<TabContents*>(this)->AsWebContents(); + } virtual SkBitmap GetFavIcon() const { NOTIMPLEMENTED(); return SkBitmap(); } - const GURL& GetURL() const { - NOTIMPLEMENTED(); - return url_; - } - virtual const std::wstring& GetTitle() const { - NOTIMPLEMENTED(); - return title_; - } - TabContentsType type() const { - NOTIMPLEMENTED(); - return TAB_CONTENTS_WEB; - } + const GURL& GetURL() const; + virtual const std::wstring& GetTitle() const; + TabContentsType type() const { return type_; } + void set_type(TabContentsType type) { type_ = type; } virtual void Focus() { NOTIMPLEMENTED(); } virtual void Stop() { NOTIMPLEMENTED(); } - bool is_loading() const { - NOTIMPLEMENTED(); - return false; - } Profile* profile() const; virtual void CloseContents(); virtual void SetupController(Profile* profile); @@ -700,29 +706,23 @@ class TabContents : public NotificationObserver { virtual void DidBecomeSelected() { NOTIMPLEMENTED(); } virtual void SetDownloadShelfVisible(bool) { NOTIMPLEMENTED(); } virtual void Destroy(); - virtual void SetIsLoading(bool, LoadNotificationDetails*) { - NOTIMPLEMENTED(); - } + virtual void SetIsLoading(bool, LoadNotificationDetails*); virtual void SetIsCrashed(bool) { NOTIMPLEMENTED(); } bool capturing_contents() const { NOTIMPLEMENTED(); return false; } void set_capturing_contents(bool) { NOTIMPLEMENTED(); } - bool is_active() { - NOTIMPLEMENTED(); - return true; - } - void set_is_active(bool) { NOTIMPLEMENTED(); } + bool is_active() const { return is_active_; } + void set_is_active(bool active) { is_active_ = active; } + bool is_loading() const { return is_loading_; } void SetNotWaitingForResponse() { NOTIMPLEMENTED(); } - void NotifyNavigationStateChanged(int) { NOTIMPLEMENTED(); } - TabContentsDelegate* delegate() const { - NOTIMPLEMENTED(); - return NULL; - } + void NotifyNavigationStateChanged(unsigned int); + TabContentsDelegate* delegate() const { return delegate_; } + void set_delegate(TabContentsDelegate* d) { delegate_ = d; } void AddInfoBar(InfoBarDelegate*) { NOTIMPLEMENTED(); } virtual void OpenURL(const GURL&, const GURL&, WindowOpenDisposition, - PageTransition::Type) { NOTIMPLEMENTED(); } + PageTransition::Type); void AddNewContents(TabContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, @@ -747,9 +747,13 @@ class TabContents : public NotificationObserver { typedef std::vector<ConstrainedWindow*> ConstrainedWindowList; ConstrainedWindowList child_windows_; private: + TabContentsType type_; + bool is_active_; + bool is_loading_; GURL url_; std::wstring title_; NavigationController* controller_; + TabContentsDelegate* delegate_; }; class SelectFileDialog : public base::RefCountedThreadSafe<SelectFileDialog> { |