diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-17 22:45:34 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-17 22:45:34 +0000 |
commit | b689fce776a394377fed51ae063942509a2988a1 (patch) | |
tree | eb52e9944db424e9e1b80bcefe9b9b96b1c27b50 /chrome/browser/tab_contents | |
parent | 84ae20cba3059760948ca5d1f313dc25c74b26d6 (diff) | |
download | chromium_src-b689fce776a394377fed51ae063942509a2988a1.zip chromium_src-b689fce776a394377fed51ae063942509a2988a1.tar.gz chromium_src-b689fce776a394377fed51ae063942509a2988a1.tar.bz2 |
Merge DOMUIContents into WebContents.
I did a lot of cleanup of the DOM UI system as part of this.
Review URL: http://codereview.chromium.org/42227
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_host_manager.cc | 8 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_factory.cc | 16 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_type.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 105 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.h | 19 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_win.cc | 4 |
8 files changed, 128 insertions, 31 deletions
diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 263a5ce..38dafb6d 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -7,6 +7,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/string_util.h" +#include "base/time.h" #include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/dom_ui/dom_ui_host.h" @@ -54,7 +55,6 @@ void NotifyPrunedEntries(NavigationController* nav_controller, void SetContentStateIfEmpty(NavigationEntry* entry) { if (entry->content_state().empty() && (entry->tab_type() == TAB_CONTENTS_WEB || - entry->tab_type() == TAB_CONTENTS_DOM_UI || entry->tab_type() == TAB_CONTENTS_HTML_DIALOG || entry->IsViewSourceMode())) { entry->set_content_state( diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/chrome/browser/tab_contents/render_view_host_manager.cc index 715f2bf..d1f8259 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/chrome/browser/tab_contents/render_view_host_manager.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/logging.h" +#include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" @@ -278,6 +279,13 @@ bool RenderViewHostManager::ShouldSwapRenderViewsForNavigation( // it as a new navigation). So require a view switch. if (cur_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) return true; + + // For security, we should transition between processes when one is a DOM UI + // page and one isn't. + if (DOMUIFactory::HasDOMUIScheme(cur_entry->url()) != + DOMUIFactory::HasDOMUIScheme(new_entry->url())) + return true; + return false; } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index b7a2cc9..3188b7c 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -188,7 +188,7 @@ class TabContents : public PageNavigator, // pending may be provisional (e.g., the navigation could result in a // download, in which case the URL would revert to what it was previously). const GURL& GetURL() const; - virtual const string16& GetTitle() const; // Overridden by DOMUIContents. + virtual const string16& GetTitle() const; // The max PageID of any page that this TabContents has loaded. PageIDs // increase with each new page that is loaded by a tab. If this is a diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index d6087e9..034ea60 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -6,12 +6,12 @@ #include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_url_handler.h" #include "chrome/browser/dom_ui/debugger_ui.h" -#include "chrome/browser/dom_ui/dom_ui_contents.h" #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/tab_contents/tab_contents_factory.h" #include "chrome/browser/tab_contents/web_contents.h" +#include "chrome/common/url_constants.h" #include "net/base/net_util.h" #if defined(OS_WIN) @@ -48,17 +48,12 @@ TabContents* TabContents::CreateWithType(TabContentsType type, contents = new WebContents(profile, instance, NULL, MSG_ROUTING_NONE, NULL); break; -// TODO(port): remove this platform define, either by porting the tab contents -// types or removing them completely. #if defined(OS_WIN) + // TODO(brettw) This extra tab contents type should be deleted. case TAB_CONTENTS_HTML_DIALOG: contents = new HtmlDialogContents(profile, instance, NULL); break; #endif // defined(OS_WIN) - case TAB_CONTENTS_DEBUGGER: - case TAB_CONTENTS_DOM_UI: - contents = new DOMUIContents(profile, instance, NULL); - break; default: if (g_extra_types) { TabContentsFactoryMap::const_iterator it = g_extra_types->find(type); @@ -101,18 +96,11 @@ TabContentsType TabContents::TypeForURL(GURL* url) { if (HtmlDialogContents::IsHtmlDialogUrl(*url)) return TAB_CONTENTS_HTML_DIALOG; - if (DebuggerUI::IsDebuggerUrl(*url)) - return TAB_CONTENTS_DEBUGGER; - - if (url->SchemeIs(DOMUIContents::GetScheme().c_str())) - return TAB_CONTENTS_DOM_UI; #elif defined(OS_POSIX) TabContentsType type(TAB_CONTENTS_UNKNOWN_TYPE); if (BrowserURLHandler::HandleBrowserURL(url, &type)) { return type; } - if (url->SchemeIs(DOMUIContents::GetScheme().c_str())) - return TAB_CONTENTS_DOM_UI; NOTIMPLEMENTED(); #endif diff --git a/chrome/browser/tab_contents/tab_contents_type.h b/chrome/browser/tab_contents/tab_contents_type.h index 2b68a24..0d4e120 100644 --- a/chrome/browser/tab_contents/tab_contents_type.h +++ b/chrome/browser/tab_contents/tab_contents_type.h @@ -13,10 +13,7 @@ enum TabContentsType { TAB_CONTENTS_UNKNOWN_TYPE = 0, TAB_CONTENTS_WEB, - // These are all subclasses of DOM UI. TAB_CONTENTS_HTML_DIALOG, - TAB_CONTENTS_DEBUGGER, - TAB_CONTENTS_DOM_UI, // DO NOT EVEN THINK ABOUT ADDING MORE TAB CONTENTS TYPES HERE. SEE brettw. TAB_CONTENTS_NUM_TYPES diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 1e4e879..ac1917a 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -14,6 +14,8 @@ #include "chrome/browser/browser.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/dom_operation_notification_details.h" +#include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/gears_integration.h" #include "chrome/browser/google_util.h" @@ -344,10 +346,32 @@ void WebContents::Destroy() { TabContents::Destroy(); } +const string16& WebContents::GetTitle() const { + if (dom_ui_.get()) { + // Give the DOM UI the chance to override our title. + const string16& title = dom_ui_->overridden_title(); + if (!title.empty()) + return title; + } + return TabContents::GetTitle(); +} + SiteInstance* WebContents::GetSiteInstance() const { return render_manager_.current_host()->site_instance(); } +bool WebContents::ShouldDisplayURL() { + if (dom_ui_.get()) + return !dom_ui_->should_hide_url(); + return true; +} + +bool WebContents::ShouldDisplayFavIcon() { + if (dom_ui_.get()) + return !dom_ui_->hide_favicon(); + return true; +} + std::wstring WebContents::GetStatusText() const { if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) return std::wstring(); @@ -376,8 +400,13 @@ std::wstring WebContents::GetStatusText() const { } bool WebContents::NavigateToPendingEntry(bool reload) { - NavigationEntry* entry = controller()->GetPendingEntry(); - RenderViewHost* dest_render_view_host = render_manager_.Navigate(*entry); + const NavigationEntry& entry = *controller()->GetPendingEntry(); + + // This will possibly create (or NULL out) a DOM UI object for the page. We'll + // use this later when the page starts doing stuff to allow it to do so. + dom_ui_.reset(DOMUIFactory::CreateDOMUIForURL(this, entry.url())); + + RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); if (!dest_render_view_host) return false; // Unable to create the desired render view host. @@ -385,15 +414,15 @@ bool WebContents::NavigateToPendingEntry(bool reload) { current_load_start_ = TimeTicks::Now(); // Navigate in the desired RenderViewHost. - dest_render_view_host->NavigateToEntry(*entry, reload); + dest_render_view_host->NavigateToEntry(entry, reload); - if (entry->page_id() == -1) { + if (entry.page_id() == -1) { // HACK!! This code suppresses javascript: URLs from being added to // session history, which is what we want to do for javascript: URLs that // do not generate content. What we really need is a message from the // renderer telling us that a new page was not created. The same message // could be used for mailto: URLs and the like. - if (entry->url().SchemeIs(chrome::kJavaScriptScheme)) + if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) return false; } @@ -406,7 +435,7 @@ bool WebContents::NavigateToPendingEntry(bool reload) { HistoryService* history = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); if (history) - history->SetFavIconOutOfDateForPage(entry->url()); + history->SetFavIconOutOfDateForPage(entry.url()); } return true; @@ -488,6 +517,12 @@ void WebContents::HideContents() { WasHidden(); } +bool WebContents::IsBookmarkBarAlwaysVisible() { + if (dom_ui_.get()) + return dom_ui_->force_bookmark_bar_visible(); + return false; +} + void WebContents::SetDownloadShelfVisible(bool visible) { TabContents::SetDownloadShelfVisible(visible); if (visible) { @@ -501,6 +536,13 @@ void WebContents::PopupNotificationVisibilityChanged(bool visible) { render_view_host()->PopupNotificationVisibilityChanged(visible); } +bool WebContents::FocusLocationBarByDefault() { + // Allow the DOM Ui to override the default. + if (dom_ui_.get()) + return dom_ui_->focus_location_bar_by_default(); + return false; +} + // Stupid view pass-throughs void WebContents::CreateView() { view_->CreateView(); @@ -684,7 +726,9 @@ void WebContents::RenderViewCreated(RenderViewHost* render_view_host) { if (!entry) return; - if (entry->IsViewSourceMode()) { + if (dom_ui_.get()) { + dom_ui_->RenderViewCreated(render_view_host); + } else if (entry->IsViewSourceMode()) { // Put the renderer in view source mode. render_view_host->Send( new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); @@ -756,6 +800,11 @@ void WebContents::DidNavigate(RenderViewHost* rvh, // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if // necessary, please). + // When moving between DOM UI and non-DOM UI pages, we should always have + // gotten a NavigateToPendingEntry that should have set the dom_ui_ member + // correctly. + DCHECK(DOMUIFactory::UseDOMUIForURL(details.entry->url()) == !!dom_ui_.get()); + // Run post-commit tasks. if (details.is_main_frame) DidNavigateMainFramePostCommit(details, params); @@ -1026,7 +1075,19 @@ void WebContents::DidDownloadImage( void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition) { - OpenURL(url, referrer, disposition, PageTransition::LINK); + if (dom_ui_.get()) { + // When we're a DOM UI, it will provide a page transition type for us (this + // is so the new tab page can specify AUTO_BOOKMARK for automatically + // generated suggestions). + // + // Note also that we hide the referrer for DOM UI pages. We don't really + // want web sites to see a referrer of "chrome-ui://blah" (and some + // chrome-ui URLs might have search terms or other stuff we don't want to + // send to the site), so we send no referrer. + OpenURL(url, GURL(), disposition, dom_ui_->link_transition_type()); + } else { + OpenURL(url, referrer, disposition, PageTransition::LINK); + } } void WebContents::DomOperationResponse(const std::string& json_string, @@ -1037,6 +1098,18 @@ void WebContents::DomOperationResponse(const std::string& json_string, Details<DomOperationNotificationDetails>(&details)); } +void WebContents::ProcessDOMUIMessage(const std::string& message, + const std::string& content) { + if (!dom_ui_.get()) { + // We shouldn't get a DOM UI message when we haven't enabled the DOM UI. + // Because the renderer might be owned and sending random messages, we need + // to ignore these inproper ones. + NOTREACHED(); + return; + } + dom_ui_->ProcessDOMUIMessage(message, content); +} + void WebContents::ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target) { @@ -1329,8 +1402,14 @@ WebPreferences WebContents::GetWebkitPrefs() { web_prefs.default_encoding = prefs->GetString( prefs::kDefaultCharset); } - DCHECK(!web_prefs.default_encoding.empty()); + + // Override some prefs when we're a DOM UI, or the pages won't work. + if (dom_ui_.get()) { + web_prefs.loads_images_automatically = true; + web_prefs.javascript_enabled = true; + } + return web_prefs; } @@ -1505,6 +1584,11 @@ WebContents::GetLastCommittedNavigationEntryForRenderManager() { bool WebContents::CreateRenderViewForRenderManager( RenderViewHost* render_view_host) { + // When we're running a DOM UI, the RenderViewHost needs to be put in DOM UI + // mode before CreateRenderView is called. + if (dom_ui_.get()) + render_view_host->AllowDOMUIBindings(); + RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); if (!render_view_host->CreateRenderView()) return false; @@ -1719,7 +1803,8 @@ void WebContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, } } -void WebContents::UpdateHistoryForNavigation(const GURL& display_url, +void WebContents::UpdateHistoryForNavigation( + const GURL& display_url, const ViewHostMsg_FrameNavigate_Params& params) { if (profile()->IsOffTheRecord()) return; diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 71b2f97..1cd6d6c 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -36,6 +36,7 @@ class AutofillForm; class AutofillManager; +class DOMUI; class InterstitialPageDelegate; class LoadNotificationDetails; class PasswordManager; @@ -118,11 +119,21 @@ class WebContents : public TabContents, encoding_ = encoding; } + // Window stuff -------------------------------------------------------------- + + // Returns true if the location bar should be focused by default rather than + // the page contents. The view will call this function when the tab is + // to see what it should do. + bool FocusLocationBarByDefault(); + // TabContents (public overrides) -------------------------------------------- virtual void Destroy(); virtual WebContents* AsWebContents() { return this; } + const string16& GetTitle() const; virtual SiteInstance* GetSiteInstance() const; + virtual bool ShouldDisplayURL(); + virtual bool ShouldDisplayFavIcon(); virtual std::wstring GetStatusText() const; virtual bool NavigateToPendingEntry(bool reload); virtual void Stop(); @@ -134,6 +145,7 @@ class WebContents : public TabContents, virtual void WasHidden(); virtual void ShowContents(); virtual void HideContents(); + virtual bool IsBookmarkBarAlwaysVisible(); virtual void SetDownloadShelfVisible(bool visible); virtual void PopupNotificationVisibilityChanged(bool visible); @@ -341,6 +353,8 @@ class WebContents : public TabContents, WindowOpenDisposition disposition); virtual void DomOperationResponse(const std::string& json_string, int automation_id); + virtual void ProcessDOMUIMessage(const std::string& message, + const std::string& content); virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, const std::string& target); @@ -619,6 +633,11 @@ class WebContents : public TabContents, // PluginInstaller, lazily created. scoped_ptr<PluginInstaller> plugin_installer_; + // When the current page is a DOM UI page, this will point to the specific + // DOMUI object handling it. When we don't have a DOM UI page, this will be + // null. + scoped_ptr<DOMUI> dom_ui_; + // Handles downloading favicons. FavIconHelper fav_icon_helper_; diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc index fcb7a3a..6ce86db 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.cc +++ b/chrome/browser/tab_contents/web_contents_view_win.cc @@ -224,8 +224,8 @@ void WebContentsViewWin::SizeContents(const gfx::Size& size) { } void WebContentsViewWin::SetInitialFocus() { - if (web_contents_->AsDOMUIContents()) - web_contents_->AsDOMUIContents()->SetInitialFocus(); + if (web_contents_->FocusLocationBarByDefault()) + web_contents_->delegate()->SetFocusToLocationBar(); else ::SetFocus(GetNativeView()); } |