summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 22:45:34 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 22:45:34 +0000
commitb689fce776a394377fed51ae063942509a2988a1 (patch)
treeeb52e9944db424e9e1b80bcefe9b9b96b1c27b50 /chrome
parent84ae20cba3059760948ca5d1f313dc25c74b26d6 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/back_forward_menu_model.cc4
-rw-r--r--chrome/browser/browser.cc27
-rw-r--r--chrome/browser/browser.scons8
-rw-r--r--chrome/browser/browser.vcproj20
-rw-r--r--chrome/browser/browser_url_handler.cc14
-rw-r--r--chrome/browser/debugger/debugger_view.cc6
-rw-r--r--chrome/browser/debugger/devtools_view.cc5
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc5
-rw-r--r--chrome/browser/dom_ui/debugger_ui.cc26
-rw-r--r--chrome/browser/dom_ui/debugger_ui.h10
-rw-r--r--chrome/browser/dom_ui/devtools_ui.cc8
-rw-r--r--chrome/browser/dom_ui/devtools_ui.h8
-rw-r--r--chrome/browser/dom_ui/dom_ui.cc26
-rw-r--r--chrome/browser/dom_ui/dom_ui.h94
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.cc300
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.h148
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.cc102
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.h33
-rw-r--r--chrome/browser/dom_ui/dom_ui_favicon_source.cc63
-rw-r--r--chrome/browser/dom_ui/dom_ui_favicon_source.h52
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.cc53
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.h48
-rw-r--r--chrome/browser/dom_ui/downloads_ui.cc134
-rw-r--r--chrome/browser/dom_ui/downloads_ui.h105
-rw-r--r--chrome/browser/dom_ui/history_ui.cc75
-rw-r--r--chrome/browser/dom_ui/history_ui.h17
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc471
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.h269
-rw-r--r--chrome/browser/download/download_shelf.cc6
-rw-r--r--chrome/browser/extensions/extensions_ui.cc20
-rw-r--r--chrome/browser/extensions/extensions_ui.h12
-rw-r--r--chrome/browser/history/history.cc3
-rw-r--r--chrome/browser/navigation_entry_unittest.cc4
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc19
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc3
-rw-r--r--chrome/browser/tab_contents/navigation_controller.cc2
-rw-r--r--chrome/browser/tab_contents/render_view_host_manager.cc8
-rw-r--r--chrome/browser/tab_contents/tab_contents.h2
-rw-r--r--chrome/browser/tab_contents/tab_contents_factory.cc16
-rw-r--r--chrome/browser/tab_contents/tab_contents_type.h3
-rw-r--r--chrome/browser/tab_contents/web_contents.cc105
-rw-r--r--chrome/browser/tab_contents/web_contents.h19
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.cc4
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc6
-rw-r--r--chrome/browser/views/options/general_page_view.cc6
-rw-r--r--chrome/chrome.gyp8
-rw-r--r--chrome/common/url_constants.cc16
-rw-r--r--chrome/common/url_constants.h22
48 files changed, 1189 insertions, 1226 deletions
diff --git a/chrome/browser/back_forward_menu_model.cc b/chrome/browser/back_forward_menu_model.cc
index f969364..6a95743 100644
--- a/chrome/browser/back_forward_menu_model.cc
+++ b/chrome/browser/back_forward_menu_model.cc
@@ -7,11 +7,11 @@
#include "chrome/browser/back_forward_menu_model.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/l10n_util.h"
+#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#include "net/base/registry_controlled_domain.h"
@@ -170,7 +170,7 @@ void BackForwardMenuModel::ExecuteCommandById(int menu_id) {
UserMetrics::RecordComputedAction(BuildActionName(L"ShowFullHistory", -1),
controller->profile());
#if defined(OS_WIN)
- browser_->ShowSingleDOMUITab(HistoryUI::GetBaseURL());
+ browser_->ShowSingleDOMUITab(GURL(chrome::kChromeUIHistoryURL));
#else
NOTIMPLEMENTED();
#endif
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index c1915aa..7014ef7b 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -8,6 +8,7 @@
#include "base/idle_timer.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/thread.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_list.h"
@@ -15,9 +16,6 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/debugger/devtools_manager.h"
-#include "chrome/browser/dom_ui/downloads_ui.h"
-#include "chrome/browser/dom_ui/history_ui.h"
-#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -40,6 +38,7 @@
#include "chrome/common/page_transition_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "chrome/common/url_constants.h"
#ifdef CHROME_PERSONALIZATION
#include "chrome/personalization/personalization.h"
#endif
@@ -536,16 +535,16 @@ void Browser::ReplaceRestoredTab(
}
void Browser::ShowSingleDOMUITab(const GURL& url) {
- int i, c;
- TabContents* tc;
- for (i = 0, c = tabstrip_model_.count(); i < c; ++i) {
- tc = tabstrip_model_.GetTabContentsAt(i);
- if (tc->type() == TAB_CONTENTS_DOM_UI &&
- tc->GetURL() == url) {
+ // See if we already have a tab with the given URL and select it if so.
+ for (int i = 0; i < tabstrip_model_.count(); i++) {
+ TabContents* tc = tabstrip_model_.GetTabContentsAt(i);
+ if (tc->GetURL() == url) {
tabstrip_model_.SelectTabContentsAt(i, false);
return;
}
}
+
+ // Otherwise, just create a new tab.
AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, true, NULL);
}
@@ -1006,12 +1005,12 @@ void Browser::OpenBookmarkManager() {
void Browser::ShowHistoryTab() {
UserMetrics::RecordAction(L"ShowHistory", profile_);
- ShowSingleDOMUITab(HistoryUI::GetBaseURL());
+ ShowSingleDOMUITab(GURL(chrome::kChromeUIHistoryURL));
}
void Browser::ShowDownloadsTab() {
UserMetrics::RecordAction(L"ShowDownloads", profile_);
- ShowSingleDOMUITab(DownloadsUI::GetBaseURL());
+ ShowSingleDOMUITab(GURL(chrome::kChromeUIDownloadsURL));
}
#if defined(OS_WIN)
@@ -1271,7 +1270,7 @@ void Browser::ExecuteCommand(int id) {
// Browser, TabStripModelDelegate implementation:
GURL Browser::GetBlankTabURL() const {
- return NewTabUI::GetBaseURL();
+ return GURL(chrome::kChromeUINewTabURL);
}
void Browser::CreateNewStripWithContents(TabContents* detached_contents,
@@ -2446,12 +2445,12 @@ GURL Browser::GetHomePage() {
return GURL("about:linux-splash");
#endif
if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
- return NewTabUI::GetBaseURL();
+ return GURL(chrome::kChromeUINewTabURL);
GURL home_page = GURL(URLFixerUpper::FixupURL(
WideToUTF8(profile_->GetPrefs()->GetString(prefs::kHomePage)),
std::string()));
if (!home_page.is_valid())
- return NewTabUI::GetBaseURL();
+ return GURL(chrome::kChromeUINewTabURL);
return home_page;
}
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 869ed45..ec8a77a 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -400,10 +400,14 @@ input_files = ChromeFileList([
'dom_ui/devtools_ui.h',
'dom_ui/dom_ui.cc',
'dom_ui/dom_ui.h',
- 'dom_ui/dom_ui_contents.cc',
- 'dom_ui/dom_ui_contents.h',
+ 'dom_ui/dom_ui_factory.cc',
+ 'dom_ui/dom_ui_factory.h',
+ 'dom_ui/dom_ui_favicon_source.cc',
+ 'dom_ui/dom_ui_favicon_source.h',
'dom_ui/dom_ui_host.cc',
'dom_ui/dom_ui_host.h',
+ 'dom_ui/dom_ui_thumbnail_source.cc',
+ 'dom_ui/dom_ui_thumbnail_source.h',
'dom_ui/downloads_ui.cc',
'dom_ui/downloads_ui.h',
'dom_ui/fileicon_source.cc',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index b766ab6..e0a49be 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -1514,11 +1514,19 @@
>
</File>
<File
- RelativePath=".\dom_ui\dom_ui_contents.cc"
+ RelativePath=".\dom_ui\dom_ui_factory.cc"
>
</File>
<File
- RelativePath=".\dom_ui\dom_ui_contents.h"
+ RelativePath=".\dom_ui\dom_ui_factory.h"
+ >
+ </File>
+ <File
+ RelativePath=".\dom_ui\dom_ui_favicon_source.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\dom_ui\dom_ui_favicon_source.h"
>
</File>
<File
@@ -1530,6 +1538,14 @@
>
</File>
<File
+ RelativePath=".\dom_ui\dom_ui_thumbnail_source.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\dom_ui\dom_ui_thumbnail_source.h"
+ >
+ </File>
+ <File
RelativePath=".\dom_ui\downloads_ui.cc"
>
</File>
diff --git a/chrome/browser/browser_url_handler.cc b/chrome/browser/browser_url_handler.cc
index 88cb0e2..4da1daf 100644
--- a/chrome/browser/browser_url_handler.cc
+++ b/chrome/browser/browser_url_handler.cc
@@ -6,8 +6,9 @@
#include "base/string_util.h"
#include "chrome/browser/browser_about_handler.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
+#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "chrome/common/url_constants.h"
+#include "googleurl/src/gurl.h"
// Handles rewriting view-source URLs for what we'll actually load.
static bool HandleViewSource(GURL* url, TabContentsType* type) {
@@ -20,6 +21,15 @@ static bool HandleViewSource(GURL* url, TabContentsType* type) {
return false;
}
+// Handles URLs for DOM UI. These URLs need no rewriting.
+static bool HandleDOMUI(GURL* url, TabContentsType* type) {
+ if (!DOMUIFactory::UseDOMUIForURL(*url))
+ return false;
+
+ *type = TAB_CONTENTS_WEB;
+ return true;
+}
+
std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_;
// static
@@ -29,7 +39,7 @@ void BrowserURLHandler::InitURLHandlers() {
// Add the default URL handlers.
url_handlers_.push_back(&WillHandleBrowserAboutURL); // about:
- url_handlers_.push_back(&DOMUIContentsCanHandleURL); // chrome-ui:
+ url_handlers_.push_back(&HandleDOMUI); // chrome-ui: & friends.
url_handlers_.push_back(&HandleViewSource); // view-source:
}
diff --git a/chrome/browser/debugger/debugger_view.cc b/chrome/browser/debugger/debugger_view.cc
index 9ada4eb..020083d 100644
--- a/chrome/browser/debugger/debugger_view.cc
+++ b/chrome/browser/debugger/debugger_view.cc
@@ -97,9 +97,9 @@ void DebuggerView::OnInit() {
// We can't create the WebContents until we've actually been put into a real
// view hierarchy somewhere.
Profile* profile = BrowserList::GetLastActive()->profile();
- TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_DEBUGGER, profile,
- NULL);
- web_contents_ = tc->AsWebContents();
+ web_contents_ = new WebContents(profile, NULL, NULL, MSG_ROUTING_NONE, NULL);
+ web_contents_->CreateView();
+
web_contents_->SetupController(profile);
web_contents_->set_delegate(this);
web_container_->SetTabContents(web_contents_);
diff --git a/chrome/browser/debugger/devtools_view.cc b/chrome/browser/debugger/devtools_view.cc
index 8305f2a..5c92ad9 100644
--- a/chrome/browser/debugger/devtools_view.cc
+++ b/chrome/browser/debugger/devtools_view.cc
@@ -51,7 +51,7 @@ void DevToolsView::Init() {
// view hierarchy somewhere.
Profile* profile = BrowserList::GetLastActive()->profile();
- TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_DOM_UI, profile,
+ TabContents* tc = TabContents::CreateWithType(TAB_CONTENTS_WEB, profile,
NULL);
web_contents_ = tc->AsWebContents();
web_contents_->SetupController(profile);
@@ -61,8 +61,7 @@ void DevToolsView::Init() {
descriptor_->SetDevToolsHost(web_contents_->render_view_host());
// chrome-ui://devtools/tools.html
- GURL contents(std::string(chrome::kChromeUIScheme) + "://" +
- chrome::kDevToolsHost + "/tools.html");
+ GURL contents(std::string(chrome::kChromeUIDevToolsURL) + "tools.html");
// this will call CreateRenderView to create renderer process
web_contents_->controller()->LoadURL(contents, GURL(),
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index b84cf75..113580a 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -104,7 +104,8 @@ void RegisterURLRequestChromeJob() {
// time being we need to serve the same content from chrome-ui://inspector
// for the Console Debugger and in-process Web Inspector.
chrome_url_data_manager.AddFileSource("inspector", inspector_dir);
- chrome_url_data_manager.AddFileSource(chrome::kDevToolsHost, inspector_dir);
+ chrome_url_data_manager.AddFileSource(chrome::kChromeUIDevToolsHost,
+ inspector_dir);
}
URLRequest::RegisterProtocolFactory(kChromeURLScheme,
@@ -120,7 +121,7 @@ void UnregisterURLRequestChromeJob() {
std::wstring inspector_dir;
if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
chrome_url_data_manager.RemoveFileSource("inspector");
- chrome_url_data_manager.RemoveFileSource(chrome::kDevToolsHost);
+ chrome_url_data_manager.RemoveFileSource(chrome::kChromeUIDevToolsHost);
}
}
diff --git a/chrome/browser/dom_ui/debugger_ui.cc b/chrome/browser/dom_ui/debugger_ui.cc
index 3af0faa..c8b4e74 100644
--- a/chrome/browser/dom_ui/debugger_ui.cc
+++ b/chrome/browser/dom_ui/debugger_ui.cc
@@ -19,6 +19,8 @@
#include "grit/debugger_resources.h"
+namespace {
+
class DebuggerHTMLSource : public ChromeURLDataManager::DataSource {
public:
// Creates our datasource and sets our user message to a specific message
@@ -80,7 +82,7 @@ class DebuggerHTMLSource : public ChromeURLDataManager::DataSource {
}
private:
- DISALLOW_EVIL_CONSTRUCTORS(DebuggerHTMLSource);
+ DISALLOW_COPY_AND_ASSIGN(DebuggerHTMLSource);
};
@@ -117,12 +119,9 @@ class DebuggerHandler : public DOMMessageHandler {
DISALLOW_COPY_AND_ASSIGN(DebuggerHandler);
};
+} // namespace
-DebuggerUI::DebuggerUI(DOMUIContents* contents)
- : DOMUI(contents) {
-}
-
-void DebuggerUI::Init() {
+DebuggerUI::DebuggerUI(WebContents* contents) : DOMUI(contents) {
AddMessageHandler(new DebuggerHandler(this));
DebuggerHTMLSource* html_source = new DebuggerHTMLSource();
@@ -131,18 +130,3 @@ void DebuggerUI::Init() {
&ChromeURLDataManager::AddDataSource,
html_source));
}
-
-// static
-bool DebuggerUI::IsDebuggerUrl(const GURL& url) {
- return url.SchemeIs(chrome::kChromeUIScheme) &&
- url.host() == chrome::kInspectorHost;
-}
-
-// static
-GURL DebuggerUI::GetBaseURL() {
- // DebuggerUI is accessible from chrome-ui://inspector.
- std::string url = chrome::kChromeUIScheme;
- url += chrome::kStandardSchemeSeparator;
- url += chrome::kInspectorHost;
- return GURL(url);
-}
diff --git a/chrome/browser/dom_ui/debugger_ui.h b/chrome/browser/dom_ui/debugger_ui.h
index 3b12ec9..8cefc66 100644
--- a/chrome/browser/dom_ui/debugger_ui.h
+++ b/chrome/browser/dom_ui/debugger_ui.h
@@ -11,15 +11,7 @@
class DebuggerUI : public DOMUI {
public:
- DebuggerUI(DOMUIContents* contents);
-
- // DOMUI Implementation
- virtual void Init();
-
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
-
- static bool IsDebuggerUrl(const GURL& url);
+ DebuggerUI(WebContents* contents);
private:
DISALLOW_COPY_AND_ASSIGN(DebuggerUI);
diff --git a/chrome/browser/dom_ui/devtools_ui.cc b/chrome/browser/dom_ui/devtools_ui.cc
index 61bfc06..daf2de6 100644
--- a/chrome/browser/dom_ui/devtools_ui.cc
+++ b/chrome/browser/dom_ui/devtools_ui.cc
@@ -6,13 +6,9 @@
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/url_constants.h"
-// DevToolsUI is accessible from chrome-ui://devtools.
-static const char kDevToolsHost[] = "devtools";
-
-// static
-GURL DevToolsUI::GetBaseURL() {
- return GURL(DOMUIContents::GetScheme() + "://" + kDevToolsHost);
+DevToolsUI::DevToolsUI(WebContents* contents) : DOMUI(contents) {
}
void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) {
diff --git a/chrome/browser/dom_ui/devtools_ui.h b/chrome/browser/dom_ui/devtools_ui.h
index 4abfaba..afc9fe5 100644
--- a/chrome/browser/dom_ui/devtools_ui.h
+++ b/chrome/browser/dom_ui/devtools_ui.h
@@ -9,13 +9,9 @@
class DevToolsUI : public DOMUI {
public:
- explicit DevToolsUI(DOMUIContents* contents) : DOMUI(contents) {}
+ explicit DevToolsUI(WebContents* contents);
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
-
- // DOMUI Implementation
- virtual void Init() {}
+ // DOMUI overrides.
virtual void RenderViewCreated(RenderViewHost* render_view_host);
private:
diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc
index 98a88e1..ea9e1a5 100644
--- a/chrome/browser/dom_ui/dom_ui.cc
+++ b/chrome/browser/dom_ui/dom_ui.cc
@@ -8,12 +8,17 @@
#include "base/json_writer.h"
#include "base/string_util.h"
#include "base/values.h"
+#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/common/l10n_util.h"
-
-///////////////////////////////////////////////////////////////////////////////
-// DOMMessageHandler
-
-DOMUI::DOMUI(DOMUIContents* contents) : contents_(contents) {
+#include "chrome/common/stl_util-inl.h"
+
+DOMUI::DOMUI(WebContents* contents)
+ : hide_favicon_(false),
+ force_bookmark_bar_visible_(false),
+ focus_location_bar_by_default_(false),
+ should_hide_url_(false),
+ link_transition_type_(PageTransition::LINK),
+ web_contents_(contents) {
}
DOMUI::~DOMUI() {
@@ -79,10 +84,8 @@ void DOMUI::RegisterMessageCallback(const std::string &message,
message_callbacks_.insert(std::make_pair(message, callback));
}
-void DOMUI::RequestOpenURL(const GURL& url,
- const GURL& /* referer */,
- WindowOpenDisposition disposition) {
- get_contents()->OpenURL(url, GURL(), disposition, PageTransition::LINK);
+Profile* DOMUI::GetProfile() {
+ return web_contents()->profile();
}
// DOMUI, protected: ----------------------------------------------------------
@@ -94,9 +97,8 @@ void DOMUI::AddMessageHandler(DOMMessageHandler* handler) {
// DOMUI, private: ------------------------------------------------------------
void DOMUI::ExecuteJavascript(const std::wstring& javascript) {
- DCHECK(contents_);
- contents_->render_view_host()->ExecuteJavascriptInWebFrame(std::wstring(),
- javascript);
+ web_contents()->render_view_host()->ExecuteJavascriptInWebFrame(
+ std::wstring(), javascript);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h
index 1d59bfc..4be503c 100644
--- a/chrome/browser/dom_ui/dom_ui.h
+++ b/chrome/browser/dom_ui/dom_ui.h
@@ -2,25 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_DOM_UI_H__
-#define CHROME_BROWSER_DOM_UI_H__
+#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_H_
+#define CHROME_BROWSER_DOM_UI_DOM_UI_H_
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/string16.h"
#include "base/task.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
+#include "chrome/common/page_transition_types.h"
+#include "webkit/glue/window_open_disposition.h"
class DictionaryValue;
class DOMMessageHandler;
+class GURL;
+class Profile;
class RenderViewHost;
class Value;
+class WebContents;
// A DOMUI sets up the datasources and message handlers for a given HTML-based
-// UI. It is contained by a DOMUIContents.
+// UI. It is contained by a DOMUIManager.
class DOMUI {
public:
- DOMUI(DOMUIContents* contents);
-
+ explicit DOMUI(WebContents* contents);
virtual ~DOMUI();
- virtual void Init() = 0;
virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
@@ -30,8 +37,45 @@ class DOMUI {
// Used by DOMMessageHandlers.
typedef Callback1<const Value*>::Type MessageCallback;
- void RegisterMessageCallback (const std::string& message,
- MessageCallback* callback);
+ void RegisterMessageCallback(const std::string& message,
+ MessageCallback* callback);
+
+ // Returns true if the favicon should be hidden for the current tab.
+ bool hide_favicon() const {
+ return hide_favicon_;
+ }
+
+ // Returns true if the bookmark bar should be forced to being visible,
+ // overriding the user's preference.
+ bool force_bookmark_bar_visible() const {
+ return force_bookmark_bar_visible_;
+ }
+
+ // Returns true if the location bar should be focused by default rather than
+ // the page contents. Some pages will want to use this to encourage the user
+ // to type in the URL bar.
+ bool focus_location_bar_by_default() const {
+ return focus_location_bar_by_default_;
+ }
+
+ // Returns true if the page's URL should be hidden. Some DOM UI pages
+ // like the new tab page will want to hide it.
+ bool should_hide_url() const {
+ return should_hide_url_;
+ }
+
+ // Gets a custom tab title provided by the DOM UI. If there is no title
+ // override, the string will be empty which should trigger the default title
+ // behavior for the tab.
+ const string16& overridden_title() const {
+ return overridden_title_;
+ }
+
+ // Returns the transition type that should be used for link clicks on this
+ // DOM UI. This will default to LINK but may be overridden.
+ const PageTransition::Type link_transition_type() const {
+ return link_transition_type_;
+ }
// Call a Javascript function by sending its name and arguments down to
// the renderer. This is asynchronous; there's no way to get the result
@@ -45,31 +89,29 @@ class DOMUI {
const Value& arg1,
const Value& arg2);
- // Overriddable control over the contents.
- // Favicon should be displayed normally.
- virtual bool ShouldDisplayFavIcon() { return true; }
- // No special bookmark bar behavior
- virtual bool IsBookmarkBarAlwaysVisible() { return false; }
- // Defaults to focusing the page.
- virtual void SetInitialFocus() { contents_->Focus(); }
- // Whether we want to display the page's URL.
- virtual bool ShouldDisplayURL() { return true; }
- // Hide the referrer.
- virtual void RequestOpenURL(const GURL& url, const GURL&,
- WindowOpenDisposition disposition);
-
- DOMUIContents* get_contents() { return contents_; }
- Profile* get_profile() { return contents_->profile(); }
+ WebContents* web_contents() { return web_contents_; }
+
+ Profile* GetProfile();
protected:
void AddMessageHandler(DOMMessageHandler* handler);
- DOMUIContents* contents_;
+ // Options that may be overridden by individual DOM UI implementations. The
+ // bool options default to false. See the public getters for more information.
+ bool hide_favicon_;
+ bool force_bookmark_bar_visible_;
+ bool focus_location_bar_by_default_;
+ bool should_hide_url_;
+ string16 overridden_title_; // Defaults to empty string.
+ PageTransition::Type link_transition_type_; // Defaults to LINK.
private:
// Execute a string of raw Javascript on the page.
void ExecuteJavascript(const std::wstring& javascript);
+ // Non-owning pointer to the WebContents this DOMUI is associated with.
+ WebContents* web_contents_;
+
// The DOMMessageHandlers we own.
std::vector<DOMMessageHandler*> handlers_;
@@ -107,4 +149,4 @@ class DOMMessageHandler {
DISALLOW_COPY_AND_ASSIGN(DOMMessageHandler);
};
-#endif // CHROME_BROWSER_DOM_UI_H__
+#endif // CHROME_BROWSER_DOM_UI_DOM_UI_H_
diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc
deleted file mode 100644
index 90e04dd..0000000
--- a/chrome/browser/dom_ui/dom_ui_contents.cc
+++ /dev/null
@@ -1,300 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
-
-#include "chrome/browser/dom_ui/debugger_ui.h"
-#include "chrome/browser/dom_ui/devtools_ui.h"
-#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/downloads_ui.h"
-#include "chrome/browser/dom_ui/history_ui.h"
-#include "chrome/browser/dom_ui/new_tab_ui.h"
-#include "chrome/browser/extensions/extensions_ui.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/tab_contents/navigation_entry.h"
-#include "chrome/browser/tab_contents/web_contents_view.h"
-#include "chrome/common/l10n_util.h"
-#include "chrome/common/resource_bundle.h"
-#include "chrome/common/url_constants.h"
-
-#include "grit/generated_resources.h"
-
-// The path used in internal URLs to thumbnail data.
-static const char kThumbnailPath[] = "thumb";
-
-// The path used in internal URLs to favicon data.
-static const char kFavIconPath[] = "favicon";
-
-///////////////////////////////////////////////////////////////////////////////
-// FavIconSource
-
-FavIconSource::FavIconSource(Profile* profile)
- : DataSource(kFavIconPath, MessageLoop::current()), profile_(profile) {}
-
-void FavIconSource::StartDataRequest(const std::string& path, int request_id) {
- HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
- if (hs) {
- HistoryService::Handle handle;
- if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
- handle = hs->GetFavIcon(
- GURL(path.substr(8)),
- &cancelable_consumer_,
- NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
- } else {
- handle = hs->GetFavIconForURL(
- GURL(path),
- &cancelable_consumer_,
- NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
- }
- // Attach the ChromeURLDataManager request ID to the history request.
- cancelable_consumer_.SetClientData(hs, handle, request_id);
- } else {
- SendResponse(request_id, NULL);
- }
-}
-
-void FavIconSource::OnFavIconDataAvailable(
- HistoryService::Handle request_handle,
- bool know_favicon,
- scoped_refptr<RefCountedBytes> data,
- bool expired,
- GURL icon_url) {
- HistoryService* hs =
- profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
- int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
-
- if (know_favicon && data.get() && !data->data.empty()) {
- // Forward the data along to the networking system.
- SendResponse(request_id, data);
- } else {
- if (!default_favicon_.get()) {
- default_favicon_ = new RefCountedBytes;
- ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
- IDR_DEFAULT_FAVICON, &default_favicon_->data);
- }
-
- SendResponse(request_id, default_favicon_);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ThumbnailSource
-
-ThumbnailSource::ThumbnailSource(Profile* profile)
- : DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {}
-
-void ThumbnailSource::StartDataRequest(const std::string& path,
- int request_id) {
- HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
- if (hs) {
- HistoryService::Handle handle = hs->GetPageThumbnail(
- GURL(path),
- &cancelable_consumer_,
- NewCallback(this, &ThumbnailSource::OnThumbnailDataAvailable));
- // Attach the ChromeURLDataManager request ID to the history request.
- cancelable_consumer_.SetClientData(hs, handle, request_id);
- } else {
- // Tell the caller that no thumbnail is available.
- SendResponse(request_id, NULL);
- }
-}
-
-void ThumbnailSource::OnThumbnailDataAvailable(
- HistoryService::Handle request_handle,
- scoped_refptr<RefCountedBytes> data) {
- HistoryService* hs =
- profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
- int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
- // Forward the data along to the networking system.
- if (data.get() && !data->data.empty()) {
- SendResponse(request_id, data);
- } else {
- if (!default_thumbnail_.get()) {
- default_thumbnail_ = new RefCountedBytes;
- ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
- IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
- }
-
- SendResponse(request_id, default_thumbnail_);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// DOMUIContents
-
-// This is the top-level URL handler for chrome-ui: URLs, and exposed in
-// our header file. The individual DOMUIs provide a chrome-ui:// HTML source
-// at the same host/path.
-bool DOMUIContentsCanHandleURL(GURL* url,
- TabContentsType* result_type) {
- // chrome-internal is a scheme we used to use for the new tab page.
- if (!url->SchemeIs(chrome::kChromeUIScheme) &&
- !url->SchemeIs(chrome::kChromeInternalScheme))
- return false;
-
- *result_type = TAB_CONTENTS_DOM_UI;
- return true;
-}
-
-DOMUIContents::DOMUIContents(Profile* profile,
- SiteInstance* instance,
- RenderViewHostFactory* render_view_factory)
- : WebContents(profile,
- instance,
- render_view_factory,
- MSG_ROUTING_NONE,
- NULL),
- current_ui_(NULL),
- current_url_(GURL()) {
- set_type(TAB_CONTENTS_DOM_UI);
-}
-
-DOMUIContents::~DOMUIContents() {
- if (current_ui_)
- delete current_ui_;
-}
-
-bool DOMUIContents::CreateRenderViewForRenderManager(
- RenderViewHost* render_view_host) {
- // Be sure to enable DOM UI bindings on the RenderViewHost before
- // CreateRenderView is called. Since a cross-site transition may be
- // involved, this may or may not be the same RenderViewHost that we had when
- // we were created.
- render_view_host->AllowDOMUIBindings();
- return WebContents::CreateRenderViewForRenderManager(render_view_host);
-}
-
-WebPreferences DOMUIContents::GetWebkitPrefs() {
- // Get the users preferences then force image loading to always be on.
- WebPreferences web_prefs = WebContents::GetWebkitPrefs();
- web_prefs.loads_images_automatically = true;
- web_prefs.javascript_enabled = true;
-
- return web_prefs;
-}
-
-void DOMUIContents::RenderViewCreated(RenderViewHost* render_view_host) {
- if (current_ui_)
- current_ui_->RenderViewCreated(render_view_host);
-}
-
-bool DOMUIContents::ShouldDisplayFavIcon() {
- if (InitCurrentUI(false))
- return current_ui_->ShouldDisplayFavIcon();
- return true;
-}
-
-bool DOMUIContents::IsBookmarkBarAlwaysVisible() {
- if (InitCurrentUI(false))
- return current_ui_->IsBookmarkBarAlwaysVisible();
- return false;
-}
-
-void DOMUIContents::SetInitialFocus() {
- if (InitCurrentUI(false))
- current_ui_->SetInitialFocus();
- else if (current_ui_)
- current_ui_->get_contents()->view()->SetInitialFocus();
-}
-
-const string16& DOMUIContents::GetTitle() const {
- // Workaround for new tab page - we may be asked for a title before
- // the content is ready, and we don't even want to display a 'loading...'
- // message, so we force it here.
- if (controller()->GetActiveEntry() &&
- controller()->GetActiveEntry()->url().host() ==
- NewTabUI::GetBaseURL().host()) {
- static string16* newtab_title = new string16(WideToUTF16Hack(
- l10n_util::GetString(IDS_NEW_TAB_TITLE)));
- return *newtab_title;
- }
- return WebContents::GetTitle();
-}
-
-bool DOMUIContents::ShouldDisplayURL() {
- if (InitCurrentUI(false))
- return current_ui_->ShouldDisplayURL();
- return TabContents::ShouldDisplayURL();
-}
-
-void DOMUIContents::RequestOpenURL(const GURL& url, const GURL& referrer,
- WindowOpenDisposition disposition) {
- if (InitCurrentUI(false))
- current_ui_->RequestOpenURL(url, referrer, disposition);
- else
- WebContents::RequestOpenURL(url, referrer, disposition);
-}
-
-bool DOMUIContents::NavigateToPendingEntry(bool reload) {
- InitCurrentUI(reload);
- // Let WebContents do whatever it's meant to do.
- return WebContents::NavigateToPendingEntry(reload);
-}
-
-void DOMUIContents::ProcessDOMUIMessage(const std::string& message,
- const std::string& content) {
- DCHECK(current_ui_);
- current_ui_->ProcessDOMUIMessage(message, content);
-}
-
-bool DOMUIContents::InitCurrentUI(bool reload) {
- if (!controller()->GetActiveEntry())
- return false;
-
- GURL url = controller()->GetActiveEntry()->url();
-
- if (url.is_empty() || !url.is_valid())
- return false;
-
- if (reload || url.host() != current_url_.host()) {
- // Shut down our existing DOMUI.
- delete current_ui_;
- current_ui_ = NULL;
-
- // Set up a new DOMUI.
- current_ui_ = GetDOMUIForURL(url);
- if (current_ui_) {
- current_ui_->Init();
- current_url_ = url;
- }
- }
-
- if (current_ui_)
- return true;
-
- return false;
-}
-
-// static
-const std::string DOMUIContents::GetScheme() {
- return chrome::kChromeUIScheme;
-}
-
-DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) {
- if (url.host() == NewTabUI::GetBaseURL().host() ||
- url.SchemeIs(chrome::kChromeInternalScheme)) {
- return new NewTabUI(this);
- }
- if (url.host() == HistoryUI::GetBaseURL().host()) {
- return new HistoryUI(this);
- }
- if (url.host() == DownloadsUI::GetBaseURL().host()) {
- return new DownloadsUI(this);
- }
-#if defined(OS_WIN)
-// TODO(port): include this once these are converted to HTML
- if (url.host() == ExtensionsUI::GetBaseURL().host()) {
- return new ExtensionsUI(this);
- }
- if (url.host() == DebuggerUI::GetBaseURL().host()) {
- return new DebuggerUI(this);
- }
- if (url.host() == DevToolsUI::GetBaseURL().host()) {
- return new DevToolsUI(this);
- }
-#else
- NOTIMPLEMENTED();
-#endif
- return NULL;
-}
diff --git a/chrome/browser/dom_ui/dom_ui_contents.h b/chrome/browser/dom_ui/dom_ui_contents.h
deleted file mode 100644
index f1796f2..0000000
--- a/chrome/browser/dom_ui/dom_ui_contents.h
+++ /dev/null
@@ -1,148 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Contains code for managing local HTML UI at chrome-ui:// URLs.
-
-#ifndef CHROME_BROWSER_DOM_UI_CONTENTS_H_
-#define CHROME_BROWSER_DOM_UI_CONTENTS_H_
-
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/tab_contents/web_contents.h"
-#include "webkit/glue/webpreferences.h"
-
-class DOMUI;
-class RenderViewHost;
-
-// FavIconSource is the gateway between network-level chrome:
-// requests for favicons and the history backend that serves these.
-class FavIconSource : public ChromeURLDataManager::DataSource {
- public:
- explicit FavIconSource(Profile* profile);
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path, int request_id);
-
- virtual std::string GetMimeType(const std::string&) const {
- // We need to explicitly return a mime type, otherwise if the user tries to
- // drag the image they get no extension.
- return "image/png";
- }
-
- // Called when favicon data is available from the history backend.
- void OnFavIconDataAvailable(
- HistoryService::Handle request_handle,
- bool know_favicon,
- scoped_refptr<RefCountedBytes> data,
- bool expired,
- GURL url);
-
- private:
- Profile* const profile_;
- CancelableRequestConsumerT<int, 0> cancelable_consumer_;
-
- // Raw PNG representation of the favicon to show when the favicon
- // database doesn't have a favicon for a webpage.
- scoped_refptr<RefCountedBytes> default_favicon_;
-
- DISALLOW_COPY_AND_ASSIGN(FavIconSource);
-};
-
-// ThumbnailSource is the gateway between network-level chrome:
-// requests for thumbnails and the history backend that serves these.
-class ThumbnailSource : public ChromeURLDataManager::DataSource {
- public:
- explicit ThumbnailSource(Profile* profile);
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path, int request_id);
-
- virtual std::string GetMimeType(const std::string&) const {
- // We need to explicitly return a mime type, otherwise if the user tries to
- // drag the image they get no extension.
- return "image/png";
- }
-
- // Called when thumbnail data is available from the history backend.
- void OnThumbnailDataAvailable(
- HistoryService::Handle request_handle,
- scoped_refptr<RefCountedBytes> data);
-
- private:
- Profile* const profile_;
- CancelableRequestConsumerT<int, 0> cancelable_consumer_;
-
- // Raw PNG representation of the thumbnail to show when the thumbnail
- // database doesn't have a thumbnail for a webpage.
- scoped_refptr<RefCountedBytes> default_thumbnail_;
-
- DISALLOW_COPY_AND_ASSIGN(ThumbnailSource);
-};
-
-// Exposed for use by BrowserURLHandler.
-bool DOMUIContentsCanHandleURL(GURL* url, TabContentsType* result_type);
-
-class DOMUIContents : public WebContents {
- public:
- DOMUIContents(Profile* profile,
- SiteInstance* instance,
- RenderViewHostFactory* render_view_factory);
- ~DOMUIContents();
-
- //
- // WebContents overrides
- //
- virtual void ProcessDOMUIMessage(const std::string& message,
- const std::string& content);
- virtual bool CreateRenderViewForRenderManager(
- RenderViewHost* render_view_host);
- // Override this method so we can ensure that javascript and image loading
- // are always on even for DOMUIHost tabs.
- virtual WebPreferences GetWebkitPrefs();
- // We don't want a favicon on the new tab page.
- virtual bool ShouldDisplayFavIcon();
- // The bookmark bar is always visible on the new tab.
- virtual bool IsBookmarkBarAlwaysVisible();
- // Whether we want to display the page's URL.
- virtual bool ShouldDisplayURL();
- // Get the title for this page.
- virtual const string16& GetTitle() const;
- // We may wish to control what happens when a URL is opened.
- virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
- WindowOpenDisposition disposition);
- virtual DOMUIContents* AsDOMUIContents() { return this; }
-
- virtual void RenderViewCreated(RenderViewHost* render_view_host);
-
- //
- // TabContents overrides
- //
- virtual void UpdateHistoryForNavigation(const GURL& url,
- const ViewHostMsg_FrameNavigate_Params& params) { }
- virtual bool NavigateToPendingEntry(bool reload);
-
- // Gives the DOMUI an opportunity to chose where the focus should go.
- void SetInitialFocus();
-
- // Return the scheme used. We currently use chrome-ui:
- static const std::string GetScheme();
-
- private:
- // Return a DOM UI for the provided URL.
- DOMUI* GetDOMUIForURL(const GURL& url);
-
- // Initialize our current UI.
- bool InitCurrentUI(bool reload);
-
- // The DOMUI we own and show.
- DOMUI* current_ui_;
-
- // URL that our current_ui_ is serving.
- GURL current_url_;
-
- DISALLOW_COPY_AND_ASSIGN(DOMUIContents);
-};
-
-#endif // CHROME_BROWSER_DOM_UI_CONTENTS_H_
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
new file mode 100644
index 0000000..228aa8c
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -0,0 +1,102 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/dom_ui/dom_ui_factory.h"
+
+#include "chrome/browser/dom_ui/downloads_ui.h"
+#include "chrome/browser/dom_ui/debugger_ui.h"
+#include "chrome/browser/dom_ui/devtools_ui.h"
+#include "chrome/browser/dom_ui/history_ui.h"
+#include "chrome/browser/dom_ui/new_tab_ui.h"
+#include "chrome/browser/extensions/extensions_ui.h"
+#include "chrome/common/url_constants.h"
+#include "googleurl/src/gurl.h"
+
+// Backend for both querying for and creating new DOMUI objects. If you're just
+// querying whether there's a DOM UI for the given URL, pass NULL for both the
+// web contents and the new_ui. The return value will indiacate whether a DOM UI
+// exists for the given URL.
+//
+// If you want to create a DOM UI, pass non-NULL pointers for both web_contents
+// and new_ui. The *new_ui pointer will be filled with the created UI if it
+// succeeds (indicated by a return value of true). The caller owns the *new_ui
+// pointer.
+static bool CreateDOMUI(const GURL& url, WebContents* web_contents,
+ DOMUI** new_ui) {
+ // This will get called a lot to check all URLs, so do a quick check of the
+ // scheme to filter out most URLs.
+ if (!url.SchemeIs(chrome::kChromeInternalScheme) &&
+ !url.SchemeIs(chrome::kChromeUIScheme))
+ return false;
+
+ // Special case the new tab page. In older versions of Chrome, the new tab
+ // page was hosted at chrome-internal:<blah>. This might be in people's saved
+ // sessions or bookmarks, so we say any URL with that scheme triggers the new
+ // tab page.
+ if (url.host() == chrome::kChromeUINewTabHost ||
+ url.SchemeIs(chrome::kChromeInternalScheme)) {
+ if (new_ui)
+ *new_ui = new NewTabUI(web_contents);
+ return true;
+ }
+
+ // We must compare hosts only since some of the DOM UIs append extra stuff
+ // after the host name.
+ if (url.host() == chrome::kChromeUIHistoryHost) {
+ if (new_ui)
+ *new_ui = new HistoryUI(web_contents);
+ return true;
+ }
+
+ if (url.host() == chrome::kChromeUIDownloadsHost) {
+ if (new_ui)
+ *new_ui = new DownloadsUI(web_contents);
+ return true;
+ }
+
+#if defined(OS_WIN)
+
+ // TODO(port): it should be possible to include these now.
+ if (url.host() == chrome::kChromeUIExtensionsHost) {
+ if (new_ui)
+ *new_ui = new ExtensionsUI(web_contents);
+ return true;
+ }
+
+ if (url.host() == chrome::kChromeUIInspectorHost) {
+ if (new_ui)
+ *new_ui = new DebuggerUI(web_contents);
+ return true;
+ }
+
+ if (url.host() == chrome::kChromeUIDevToolsHost) {
+ if (new_ui)
+ *new_ui = new DevToolsUI(web_contents);
+ return true;
+ }
+
+#endif
+
+ return false;
+}
+
+// static
+bool DOMUIFactory::HasDOMUIScheme(const GURL& url) {
+ return url.SchemeIs(chrome::kChromeInternalScheme) ||
+ url.SchemeIs(chrome::kChromeUIScheme);
+}
+
+// static
+bool DOMUIFactory::UseDOMUIForURL(const GURL& url) {
+ return CreateDOMUI(url, NULL, NULL);
+}
+
+// static
+DOMUI* DOMUIFactory::CreateDOMUIForURL(WebContents* web_contents,
+ const GURL& url) {
+ DOMUI* dom_ui;
+ if (!CreateDOMUI(url, web_contents, &dom_ui))
+ return NULL;
+ return dom_ui;
+}
diff --git a/chrome/browser/dom_ui/dom_ui_factory.h b/chrome/browser/dom_ui/dom_ui_factory.h
new file mode 100644
index 0000000..1641a8a
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_factory.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_
+#define CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_
+
+class DOMUI;
+class GURL;
+class WebContents;
+
+class DOMUIFactory {
+ public:
+ // Returns true if the given URL's scheme would trigger the DOM UI system.
+ // This is a less precise test than UseDONUIForURL, which tells you whether
+ // that specific URL matches a known one. This one is faster and can be used
+ // to determine security policy.
+ static bool HasDOMUIScheme(const GURL& url);
+
+ // Returns true if the given URL will use the DOM UI system.
+ static bool UseDOMUIForURL(const GURL& url);
+
+ // Allocates a new DOMUI object for the given URL, and returns it. If the URL
+ // is not a DOM UI URL, then it will return NULL. When non-NULL, ownership of
+ // the returned pointer is passed to the caller.
+ static DOMUI* CreateDOMUIForURL(WebContents* web_contents, const GURL& url);
+
+ private:
+ // Class is for scoping only.
+ DOMUIFactory() {};
+};
+
+#endif // CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_
diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.cc b/chrome/browser/dom_ui/dom_ui_favicon_source.cc
new file mode 100644
index 0000000..985ded4
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_favicon_source.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
+
+#include "chrome/browser/profile.h"
+#include "chrome/common/resource_bundle.h"
+#include "chrome/common/url_constants.h"
+#include "grit/theme_resources.h"
+
+DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile)
+ : DataSource(chrome::kChromeUIFavIconPath, MessageLoop::current()),
+ profile_(profile) {
+}
+
+void DOMUIFavIconSource::StartDataRequest(const std::string& path,
+ int request_id) {
+ HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ if (hs) {
+ HistoryService::Handle handle;
+ if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
+ handle = hs->GetFavIcon(
+ GURL(path.substr(8)),
+ &cancelable_consumer_,
+ NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable));
+ } else {
+ handle = hs->GetFavIconForURL(
+ GURL(path),
+ &cancelable_consumer_,
+ NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable));
+ }
+ // Attach the ChromeURLDataManager request ID to the history request.
+ cancelable_consumer_.SetClientData(hs, handle, request_id);
+ } else {
+ SendResponse(request_id, NULL);
+ }
+}
+
+void DOMUIFavIconSource::OnFavIconDataAvailable(
+ HistoryService::Handle request_handle,
+ bool know_favicon,
+ scoped_refptr<RefCountedBytes> data,
+ bool expired,
+ GURL icon_url) {
+ HistoryService* hs =
+ profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
+
+ if (know_favicon && data.get() && !data->data.empty()) {
+ // Forward the data along to the networking system.
+ SendResponse(request_id, data);
+ } else {
+ if (!default_favicon_.get()) {
+ default_favicon_ = new RefCountedBytes;
+ ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
+ IDR_DEFAULT_FAVICON, &default_favicon_->data);
+ }
+
+ SendResponse(request_id, default_favicon_);
+ }
+}
+
diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.h b/chrome/browser/dom_ui/dom_ui_favicon_source.h
new file mode 100644
index 0000000..e946b1e
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_favicon_source.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_FAVICON_SOURCE_H_
+#define CHROME_BROWSER_DOM_UI_DOM_UI_FAVICON_SOURCE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/browser/history/history.h"
+
+class GURL;
+class Profile;
+
+// FavIconSource is the gateway between network-level chrome:
+// requests for favicons and the history backend that serves these.
+class DOMUIFavIconSource : public ChromeURLDataManager::DataSource {
+ public:
+ explicit DOMUIFavIconSource(Profile* profile);
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+
+ virtual std::string GetMimeType(const std::string&) const {
+ // We need to explicitly return a mime type, otherwise if the user tries to
+ // drag the image they get no extension.
+ return "image/png";
+ }
+
+ // Called when favicon data is available from the history backend.
+ void OnFavIconDataAvailable(HistoryService::Handle request_handle,
+ bool know_favicon,
+ scoped_refptr<RefCountedBytes> data,
+ bool expired,
+ GURL url);
+
+ private:
+ Profile* profile_;
+ CancelableRequestConsumerT<int, 0> cancelable_consumer_;
+
+ // Raw PNG representation of the favicon to show when the favicon
+ // database doesn't have a favicon for a webpage.
+ scoped_refptr<RefCountedBytes> default_favicon_;
+
+ DISALLOW_COPY_AND_ASSIGN(DOMUIFavIconSource);
+};
+
+#endif // CHROME_BROWSER_DOM_UI_DOM_UI_FAVICON_SOURCE_H_
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
new file mode 100644
index 0000000..5f1724e3
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h"
+
+#include "chrome/browser/profile.h"
+#include "chrome/common/resource_bundle.h"
+#include "chrome/common/url_constants.h"
+#include "googleurl/src/gurl.h"
+#include "grit/theme_resources.h"
+
+DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile)
+ : DataSource(chrome::kChromeUIThumbnailPath, MessageLoop::current()),
+ profile_(profile) {
+}
+
+void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
+ int request_id) {
+ HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ if (hs) {
+ HistoryService::Handle handle = hs->GetPageThumbnail(
+ GURL(path),
+ &cancelable_consumer_,
+ NewCallback(this, &DOMUIThumbnailSource::OnThumbnailDataAvailable));
+ // Attach the ChromeURLDataManager request ID to the history request.
+ cancelable_consumer_.SetClientData(hs, handle, request_id);
+ } else {
+ // Tell the caller that no thumbnail is available.
+ SendResponse(request_id, NULL);
+ }
+}
+
+void DOMUIThumbnailSource::OnThumbnailDataAvailable(
+ HistoryService::Handle request_handle,
+ scoped_refptr<RefCountedBytes> data) {
+ HistoryService* hs =
+ profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
+ // Forward the data along to the networking system.
+ if (data.get() && !data->data.empty()) {
+ SendResponse(request_id, data);
+ } else {
+ if (!default_thumbnail_.get()) {
+ default_thumbnail_ = new RefCountedBytes;
+ ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
+ IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
+ }
+
+ SendResponse(request_id, default_thumbnail_);
+ }
+}
+
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
new file mode 100644
index 0000000..c4f7063
--- /dev/null
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_
+#define CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/browser/history/history.h"
+
+class Profile;
+
+// ThumbnailSource is the gateway between network-level chrome:
+// requests for thumbnails and the history backend that serves these.
+class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource {
+ public:
+ explicit DOMUIThumbnailSource(Profile* profile);
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+
+ virtual std::string GetMimeType(const std::string&) const {
+ // We need to explicitly return a mime type, otherwise if the user tries to
+ // drag the image they get no extension.
+ return "image/png";
+ }
+
+ // Called when thumbnail data is available from the history backend.
+ void OnThumbnailDataAvailable(HistoryService::Handle request_handle,
+ scoped_refptr<RefCountedBytes> data);
+
+ private:
+ Profile* profile_;
+ CancelableRequestConsumerT<int, 0> cancelable_consumer_;
+
+ // Raw PNG representation of the thumbnail to show when the thumbnail
+ // database doesn't have a thumbnail for a webpage.
+ scoped_refptr<RefCountedBytes> default_thumbnail_;
+
+ DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource);
+};
+
+#endif // CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_
diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc
index f8d9515..5ee67bd 100644
--- a/chrome/browser/dom_ui/downloads_ui.cc
+++ b/chrome/browser/dom_ui/downloads_ui.cc
@@ -9,7 +9,9 @@
#include "base/thread.h"
#include "base/time_format.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/fileicon_source.h"
+#include "chrome/browser/download/download_manager.h"
#if defined(OS_WIN)
// TODO(port): re-enable when download_util is ported
#include "chrome/browser/download/download_util.h"
@@ -19,11 +21,11 @@
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/time_format.h"
+#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
-// DownloadsUI is accessible from chrome-ui://downloads.
-static const char kDownloadsHost[] = "downloads";
+namespace {
// Maximum number of downloads to show. TODO(glen): Remove this and instead
// stuff the downloads down the pipe slowly.
@@ -35,8 +37,23 @@ static const int kMaxDownloads = 150;
//
///////////////////////////////////////////////////////////////////////////////
+class DownloadsUIHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ DownloadsUIHTMLSource();
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadsUIHTMLSource);
+};
+
DownloadsUIHTMLSource::DownloadsUIHTMLSource()
- : DataSource(kDownloadsHost, MessageLoop::current()) {
+ : DataSource(chrome::kChromeUIDownloadsHost, MessageLoop::current()) {
}
void DownloadsUIHTMLSource::StartDataRequest(const std::string& path,
@@ -100,6 +117,82 @@ void DownloadsUIHTMLSource::StartDataRequest(const std::string& path,
//
///////////////////////////////////////////////////////////////////////////////
+// The handler for Javascript messages related to the "downloads" view,
+// also observes changes to the download manager.
+class DownloadsDOMHandler : public DOMMessageHandler,
+ public DownloadManager::Observer,
+ public DownloadItem::Observer {
+ public:
+ explicit DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm);
+ virtual ~DownloadsDOMHandler();
+
+ void Init();
+
+ // DownloadItem::Observer interface
+ virtual void OnDownloadUpdated(DownloadItem* download);
+
+ // DownloadManager::Observer interface
+ virtual void ModelChanged();
+ virtual void SetDownloads(std::vector<DownloadItem*>& downloads);
+
+ // Callback for the "getDownloads" message.
+ void HandleGetDownloads(const Value* value);
+
+ // Callback for the "openFile" message - opens the file in the shell.
+ void HandleOpenFile(const Value* value);
+
+ // Callback for the "drag" message - initiates a file object drag.
+ void HandleDrag(const Value* value);
+
+ // Callback for the "saveDangerous" message - specifies that the user
+ // wishes to save a dangerous file.
+ void HandleSaveDangerous(const Value* value);
+
+ // Callback for the "discardDangerous" message - specifies that the user
+ // wishes to discard (remove) a dangerous file.
+ void HandleDiscardDangerous(const Value* value);
+
+ // Callback for the "show" message - shows the file in explorer.
+ void HandleShow(const Value* value);
+
+ // Callback for the "pause" message - pauses the file download.
+ void HandlePause(const Value* value);
+
+ // Callback for the "cancel" message - cancels the download.
+ void HandleCancel(const Value* value);
+
+ private:
+ // Send the current list of downloads to the page.
+ void SendCurrentDownloads();
+
+ // Creates a representation of a download in a format that the downloads
+ // HTML page can understand.
+ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id);
+
+ // Clear all download items and their observers.
+ void ClearDownloadItems();
+
+ // Return the download that corresponds to a given id.
+ DownloadItem* GetDownloadById(int id);
+
+ // Return the download that is referred to in a given value.
+ DownloadItem* GetDownloadByValue(const Value* value);
+
+ // Current search text.
+ std::wstring search_text_;
+
+ // Our model
+ DownloadManager* download_manager_;
+
+ // The current set of visible DownloadItems for this view received from the
+ // DownloadManager. DownloadManager owns the DownloadItems. The vector is
+ // kept in order, sorted by ascending start time.
+ typedef std::vector<DownloadItem*> OrderedDownloads;
+ OrderedDownloads download_items_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler);
+};
+
// Sort DownloadItems into descending order by their start time.
class DownloadItemSorter : public std::binary_function<DownloadItem*,
DownloadItem*,
@@ -120,20 +213,20 @@ DownloadsDOMHandler::DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm)
NewCallback(this, &DownloadsDOMHandler::HandleOpenFile));
dom_ui_->RegisterMessageCallback("drag",
- NewCallback(this, &DownloadsDOMHandler::HandleDrag));
+ NewCallback(this, &DownloadsDOMHandler::HandleDrag));
dom_ui_->RegisterMessageCallback("saveDangerous",
- NewCallback(this, &DownloadsDOMHandler::HandleSaveDangerous));
+ NewCallback(this, &DownloadsDOMHandler::HandleSaveDangerous));
dom_ui_->RegisterMessageCallback("discardDangerous",
- NewCallback(this, &DownloadsDOMHandler::HandleDiscardDangerous));
+ NewCallback(this, &DownloadsDOMHandler::HandleDiscardDangerous));
dom_ui_->RegisterMessageCallback("show",
- NewCallback(this, &DownloadsDOMHandler::HandleShow));
+ NewCallback(this, &DownloadsDOMHandler::HandleShow));
dom_ui_->RegisterMessageCallback("togglepause",
- NewCallback(this, &DownloadsDOMHandler::HandlePause));
+ NewCallback(this, &DownloadsDOMHandler::HandlePause));
dom_ui_->RegisterMessageCallback("resume",
- NewCallback(this, &DownloadsDOMHandler::HandlePause));
+ NewCallback(this, &DownloadsDOMHandler::HandlePause));
dom_ui_->RegisterMessageCallback("cancel",
- NewCallback(this, &DownloadsDOMHandler::HandleCancel));
+ NewCallback(this, &DownloadsDOMHandler::HandleCancel));
// Create our fileicon data source.
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
@@ -159,8 +252,8 @@ void DownloadsDOMHandler::OnDownloadUpdated(DownloadItem* download) {
// errors between the UI and the download_items_ list (we may wish to use
// something other than 'id').
OrderedDownloads::iterator it = find(download_items_.begin(),
- download_items_.end(),
- download);
+ download_items_.end(),
+ download);
if (it == download_items_.end())
return;
const int id = static_cast<int>(it - download_items_.begin());
@@ -346,17 +439,16 @@ DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const Value* value) {
return NULL;
}
+} // namespace
+
///////////////////////////////////////////////////////////////////////////////
//
// DownloadsUI
//
///////////////////////////////////////////////////////////////////////////////
-DownloadsUI::DownloadsUI(DOMUIContents* contents) : DOMUI(contents) {
-}
-
-void DownloadsUI::Init() {
- DownloadManager* dlm = get_profile()->GetDownloadManager();
+DownloadsUI::DownloadsUI(WebContents* contents) : DOMUI(contents) {
+ DownloadManager* dlm = GetProfile()->GetDownloadManager();
DownloadsDOMHandler* handler = new DownloadsDOMHandler(this, dlm);
AddMessageHandler(handler);
@@ -370,11 +462,3 @@ void DownloadsUI::Init() {
&ChromeURLDataManager::AddDataSource,
html_source));
}
-
-// static
-GURL DownloadsUI::GetBaseURL() {
- std::string url = DOMUIContents::GetScheme();
- url += "://";
- url += kDownloadsHost;
- return GURL(url);
-}
diff --git a/chrome/browser/dom_ui/downloads_ui.h b/chrome/browser/dom_ui/downloads_ui.h
index baaca9a..ed435e1 100644
--- a/chrome/browser/dom_ui/downloads_ui.h
+++ b/chrome/browser/dom_ui/downloads_ui.h
@@ -5,116 +5,13 @@
#ifndef CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_
#define CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
-#include "chrome/browser/download/download_manager.h"
-
-class GURL;
-
-class DownloadsUIHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- DownloadsUIHTMLSource();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path, int request_id);
- virtual std::string GetMimeType(const std::string&) const {
- return "text/html";
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DownloadsUIHTMLSource);
-};
-
-// The handler for Javascript messages related to the "downloads" view,
-// also observes changes to the download manager.
-class DownloadsDOMHandler : public DOMMessageHandler,
- public DownloadManager::Observer,
- public DownloadItem::Observer {
- public:
- explicit DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm);
- virtual ~DownloadsDOMHandler();
-
- void Init();
-
- // DownloadItem::Observer interface
- virtual void OnDownloadUpdated(DownloadItem* download);
-
- // DownloadManager::Observer interface
- virtual void ModelChanged();
- virtual void SetDownloads(std::vector<DownloadItem*>& downloads);
-
- // Callback for the "getDownloads" message.
- void HandleGetDownloads(const Value* value);
-
- // Callback for the "openFile" message - opens the file in the shell.
- void HandleOpenFile(const Value* value);
-
- // Callback for the "drag" message - initiates a file object drag.
- void HandleDrag(const Value* value);
-
- // Callback for the "saveDangerous" message - specifies that the user
- // wishes to save a dangerous file.
- void HandleSaveDangerous(const Value* value);
-
- // Callback for the "discardDangerous" message - specifies that the user
- // wishes to discard (remove) a dangerous file.
- void HandleDiscardDangerous(const Value* value);
-
- // Callback for the "show" message - shows the file in explorer.
- void HandleShow(const Value* value);
-
- // Callback for the "pause" message - pauses the file download.
- void HandlePause(const Value* value);
-
- // Callback for the "cancel" message - cancels the download.
- void HandleCancel(const Value* value);
-
- private:
- // Send the current list of downloads to the page.
- void SendCurrentDownloads();
-
- // Creates a representation of a download in a format that the downloads
- // HTML page can understand.
- DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id);
-
- // Clear all download items and their observers.
- void ClearDownloadItems();
-
- // Return the download that corresponds to a given id.
- DownloadItem* GetDownloadById(int id);
-
- // Return the download that is referred to in a given value.
- DownloadItem* GetDownloadByValue(const Value* value);
-
- // Current search text.
- std::wstring search_text_;
-
- // Our model
- DownloadManager* download_manager_;
-
- // The current set of visible DownloadItems for this view received from the
- // DownloadManager. DownloadManager owns the DownloadItems. The vector is
- // kept in order, sorted by ascending start time.
- typedef std::vector<DownloadItem*> OrderedDownloads;
- OrderedDownloads download_items_;
-
- DISALLOW_COPY_AND_ASSIGN(DownloadsDOMHandler);
-};
class DownloadsUI : public DOMUI {
public:
- explicit DownloadsUI(DOMUIContents* contents);
-
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
-
- // DOMUI Implementation
- virtual void Init();
+ explicit DownloadsUI(WebContents* contents);
private:
-
DISALLOW_COPY_AND_ASSIGN(DownloadsUI);
};
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc
index 8bc2013..9309732 100644
--- a/chrome/browser/dom_ui/history_ui.cc
+++ b/chrome/browser/dom_ui/history_ui.cc
@@ -12,6 +12,7 @@
#include "base/time_format.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/profile.h"
@@ -20,18 +21,13 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/time_format.h"
+#include "chrome/common/url_constants.h"
#include "net/base/escape.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
-using base::Time;
-using base::TimeDelta;
-
-// HistoryUI is accessible from chrome-ui://history.
-static const char kHistoryHost[] = "history";
-
// Maximum number of search results to return in a given search. We should
// eventually remove this.
static const int kMaxSearchResults = 100;
@@ -43,7 +39,7 @@ static const int kMaxSearchResults = 100;
////////////////////////////////////////////////////////////////////////////////
HistoryUIHTMLSource::HistoryUIHTMLSource()
- : DataSource(kHistoryHost, MessageLoop::current()) {
+ : DataSource(chrome::kChromeUIHistoryHost, MessageLoop::current()) {
}
void HistoryUIHTMLSource::StartDataRequest(const std::string& path,
@@ -113,12 +109,12 @@ BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui)
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
- new FavIconSource(dom_ui_->get_profile())));
+ new DOMUIFavIconSource(dom_ui_->GetProfile())));
// Get notifications when history is cleared.
NotificationService* service = NotificationService::current();
service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_->get_profile()));
+ Source<Profile>(dom_ui_->GetProfile()));
}
BrowsingHistoryHandler::~BrowsingHistoryHandler() {
@@ -126,7 +122,7 @@ BrowsingHistoryHandler::~BrowsingHistoryHandler() {
NotificationService* service = NotificationService::current();
service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_->get_profile()));
+ Source<Profile>(dom_ui_->GetProfile()));
if (remover_.get())
remover_->RemoveObserver(this);
@@ -142,10 +138,10 @@ void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
// Set our query options.
history::QueryOptions options;
- options.begin_time = Time::Now().LocalMidnight();
- options.begin_time -= TimeDelta::FromDays(day);
- options.end_time = Time::Now().LocalMidnight();
- options.end_time -= TimeDelta::FromDays(day - 1);
+ options.begin_time = base::Time::Now().LocalMidnight();
+ options.begin_time -= base::TimeDelta::FromDays(day);
+ options.end_time = base::Time::Now().LocalMidnight();
+ options.end_time -= base::TimeDelta::FromDays(day - 1);
// As we're querying per-day, we can turn entry repeats off.
options.most_recent_visit_only = true;
@@ -154,7 +150,7 @@ void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
search_text_ = std::wstring();
HistoryService* hs =
- dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QueryHistory(search_text_,
options,
&cancelable_consumer_,
@@ -181,7 +177,7 @@ void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) {
// Need to remember the query string for our results.
search_text_ = query;
HistoryService* hs =
- dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QueryHistory(search_text_,
options,
&cancelable_consumer_,
@@ -198,14 +194,15 @@ void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) {
cancelable_consumer_.CancelAllRequests();
// Get time.
- Time time;
- bool success = Time::FromString(ExtractStringValue(value).c_str(), &time);
+ base::Time time;
+ bool success = base::Time::FromString(ExtractStringValue(value).c_str(),
+ &time);
DCHECK(success);
- Time begin_time = time.LocalMidnight();
- Time end_time = begin_time + TimeDelta::FromDays(1);
+ base::Time begin_time = time.LocalMidnight();
+ base::Time end_time = begin_time + base::TimeDelta::FromDays(1);
- remover_.reset(new BrowsingDataRemover(dom_ui_->get_profile(),
+ remover_.reset(new BrowsingDataRemover(dom_ui_->GetProfile(),
begin_time,
end_time));
remover_->AddObserver(this);
@@ -225,7 +222,7 @@ void BrowsingHistoryHandler::QueryComplete(
history::QueryResults* results) {
ListValue results_value;
- Time midnight_today = Time::Now().LocalMidnight();
+ base::Time midnight_today = base::Time::Now().LocalMidnight();
for (size_t i = 0; i < results->size(); ++i) {
history::URLResult const &page = (*results)[i];
@@ -262,7 +259,7 @@ void BrowsingHistoryHandler::QueryComplete(
page_value->SetString(L"snippet", page.snippet().text());
}
page_value->SetBoolean(L"starred",
- dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url()));
+ dom_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url()));
results_value.Append(page_value);
}
@@ -307,17 +304,17 @@ history::QueryOptions BrowsingHistoryHandler::CreateMonthQueryOptions(
// Configure the begin point of the search to the start of the
// current month.
- Time::Exploded exploded;
- Time::Now().LocalMidnight().LocalExplode(&exploded);
+ base::Time::Exploded exploded;
+ base::Time::Now().LocalMidnight().LocalExplode(&exploded);
exploded.day_of_month = 1;
if (month == 0) {
- options.begin_time = Time::FromLocalExploded(exploded);
+ options.begin_time = base::Time::FromLocalExploded(exploded);
// Set the end time of this first search to null (which will
// show results from the future, should the user's clock have
// been set incorrectly).
- options.end_time = Time();
+ options.end_time = base::Time();
} else {
// Set the end-time of this search to the end of the month that is
// |depth| months before the search end point. The end time is not
@@ -328,7 +325,7 @@ history::QueryOptions BrowsingHistoryHandler::CreateMonthQueryOptions(
exploded.month += 12;
exploded.year--;
}
- options.end_time = Time::FromLocalExploded(exploded);
+ options.end_time = base::Time::FromLocalExploded(exploded);
// Set the begin-time of the search to the start of the month
// that is |depth| months prior to search_start_.
@@ -338,7 +335,7 @@ history::QueryOptions BrowsingHistoryHandler::CreateMonthQueryOptions(
exploded.month = 12;
exploded.year--;
}
- options.begin_time = Time::FromLocalExploded(exploded);
+ options.begin_time = base::Time::FromLocalExploded(exploded);
}
return options;
@@ -362,10 +359,7 @@ void BrowsingHistoryHandler::Observe(NotificationType type,
//
////////////////////////////////////////////////////////////////////////////////
-HistoryUI::HistoryUI(DOMUIContents* contents) : DOMUI(contents) {
-}
-
-void HistoryUI::Init() {
+HistoryUI::HistoryUI(WebContents* contents) : DOMUI(contents) {
AddMessageHandler(new BrowsingHistoryHandler(this));
HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource();
@@ -378,16 +372,7 @@ void HistoryUI::Init() {
}
// static
-GURL HistoryUI::GetBaseURL() {
- std::string url = DOMUIContents::GetScheme();
- url += "://";
- url += kHistoryHost;
- return GURL(url);
-}
-
-// static
-const GURL HistoryUI::GetHistoryURLWithSearchText(
- const std::wstring& text) {
- return GURL(GetBaseURL().spec() + "#q=" +
- EscapeQueryParamValue(WideToUTF8(text)));
+const GURL HistoryUI::GetHistoryURLWithSearchText(const std::wstring& text) {
+ return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
+ EscapeQueryParamValue(WideToUTF8(text)));
}
diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h
index 3bc550e..41bba82 100644
--- a/chrome/browser/dom_ui/history_ui.h
+++ b/chrome/browser/dom_ui/history_ui.h
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H__
-#define CHROME_BROWSER_DOM_UI_HISTORY_UI_H__
+#ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
+#define CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
#include "base/scoped_ptr.h"
#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
#include "chrome/browser/cancelable_request.h"
+#include "chrome/browser/history/history.h"
class GURL;
@@ -81,20 +81,13 @@ class BrowsingHistoryHandler : public DOMMessageHandler,
class HistoryUI : public DOMUI {
public:
- explicit HistoryUI(DOMUIContents* contents);
-
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
+ explicit HistoryUI(WebContents* contents);
// Return the URL for a given search term.
static const GURL GetHistoryURLWithSearchText(const std::wstring& text);
- // DOMUI Implementation
- virtual void Init();
-
private:
-
DISALLOW_COPY_AND_ASSIGN(HistoryUI);
};
-#endif // CHROME_BROWSER_DOM_UI_HISTORY_UI_H__
+#endif // CHROME_BROWSER_DOM_UI_HISTORY_UI_H_
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index 21cffa7..d3183d5 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -8,18 +8,23 @@
#include "base/histogram.h"
#include "base/string_piece.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
+#include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
+#include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h"
#include "chrome/browser/dom_ui/history_ui.h"
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/user_data_manager.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/l10n_util.h"
@@ -36,6 +41,8 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+namespace {
+
// The number of most visited pages we show.
const int kMostVisitedPages = 9;
@@ -43,19 +50,72 @@ const int kMostVisitedPages = 9;
const int kMostVisitedScope = 90;
// The number of recent bookmarks we show.
-static const int kRecentBookmarks = 9;
+const int kRecentBookmarks = 9;
// The number of search URLs to show.
-static const int kSearchURLs = 3;
+const int kSearchURLs = 3;
// Strings sent to the page via jstemplates used to set the direction of the
// HTML document based on locale.
-static const wchar_t kRTLHtmlTextDirection[] = L"rtl";
-static const wchar_t kDefaultHtmlTextDirection[] = L"ltr";
+const wchar_t kRTLHtmlTextDirection[] = L"rtl";
+const wchar_t kDefaultHtmlTextDirection[] = L"ltr";
-bool NewTabHTMLSource::first_view_ = true;
+// Adds "url", "title", and "direction" keys on incoming dictionary, setting
+// title as the url as a fallback on empty title.
+void SetURLTitleAndDirection(DictionaryValue* dictionary,
+ const string16& title,
+ const GURL& gurl) {
+ std::wstring wstring_url = UTF8ToWide(gurl.spec());
+ dictionary->SetString(L"url", wstring_url);
-namespace {
+ std::wstring wstring_title = UTF16ToWide(title);
+
+ bool using_url_as_the_title = false;
+ std::wstring title_to_set(wstring_title);
+ if (title_to_set.empty()) {
+ using_url_as_the_title = true;
+ title_to_set = wstring_url;
+ }
+
+ // We set the "dir" attribute of the title, so that in RTL locales, a LTR
+ // title is rendered left-to-right and truncated from the right. For example,
+ // the title of http://msdn.microsoft.com/en-us/default.aspx is "MSDN:
+ // Microsoft developer network". In RTL locales, in the [New Tab] page, if
+ // the "dir" of this title is not specified, it takes Chrome UI's
+ // directionality. So the title will be truncated as "soft developer
+ // network". Setting the "dir" attribute as "ltr" renders the truncated title
+ // as "MSDN: Microsoft D...". As another example, the title of
+ // http://yahoo.com is "Yahoo!". In RTL locales, in the [New Tab] page, the
+ // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
+ // "ltr".
+ //
+ // Since the title can contain BiDi text, we need to mark the text as either
+ // RTL or LTR, depending on the characters in the string. If we use the URL
+ // as the title, we mark the title as LTR since URLs are always treated as
+ // left to right strings. Simply setting the title's "dir" attribute works
+ // fine for rendering and truncating the title. However, it does not work for
+ // entire title within a tooltip when the mouse is over the title link.. For
+ // example, without LRE-PDF pair, the title "Yahoo!" will be rendered as
+ // "!Yahoo" within the tooltip when the mouse is over the title link.
+ std::wstring direction = kDefaultHtmlTextDirection;
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ if (using_url_as_the_title) {
+ l10n_util::WrapStringWithLTRFormatting(&title_to_set);
+ } else {
+ if (l10n_util::StringContainsStrongRTLChars(wstring_title)) {
+ l10n_util::WrapStringWithRTLFormatting(&title_to_set);
+ direction = kRTLHtmlTextDirection;
+ } else {
+ l10n_util::WrapStringWithLTRFormatting(&title_to_set);
+ }
+ }
+ }
+ dictionary->SetString(L"title", title_to_set);
+ dictionary->SetString(L"direction", direction);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PaintTimer
// To measure end-to-end performance of the new tab page, we observe paint
// messages and wait for the page to stop repainting.
@@ -115,67 +175,37 @@ class PaintTimer : public RenderWidgetHost::PaintObserver {
DISALLOW_COPY_AND_ASSIGN(PaintTimer);
};
-// Adds "url", "title", and "direction" keys on incoming dictionary, setting
-// title as the url as a fallback on empty title.
-void SetURLTitleAndDirection(DictionaryValue* dictionary,
- const string16& title,
- const GURL& gurl) {
- std::wstring wstring_url = UTF8ToWide(gurl.spec());
- dictionary->SetString(L"url", wstring_url);
+///////////////////////////////////////////////////////////////////////////////
+// NewTabHTMLSource
- std::wstring wstring_title = UTF16ToWide(title);
+class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ NewTabHTMLSource();
- bool using_url_as_the_title = false;
- std::wstring title_to_set(wstring_title);
- if (title_to_set.empty()) {
- using_url_as_the_title = true;
- title_to_set = wstring_url;
- }
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
- // We set the "dir" attribute of the title, so that in RTL locales, a LTR
- // title is rendered left-to-right and truncated from the right. For example,
- // the title of http://msdn.microsoft.com/en-us/default.aspx is "MSDN:
- // Microsoft developer network". In RTL locales, in the [New Tab] page, if
- // the "dir" of this title is not specified, it takes Chrome UI's
- // directionality. So the title will be truncated as "soft developer
- // network". Setting the "dir" attribute as "ltr" renders the truncated title
- // as "MSDN: Microsoft D...". As another example, the title of
- // http://yahoo.com is "Yahoo!". In RTL locales, in the [New Tab] page, the
- // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
- // "ltr".
- //
- // Since the title can contain BiDi text, we need to mark the text as either
- // RTL or LTR, depending on the characters in the string. If we use the URL
- // as the title, we mark the title as LTR since URLs are always treated as
- // left to right strings. Simply setting the title's "dir" attribute works
- // fine for rendering and truncating the title. However, it does not work for
- // entire title within a tooltip when the mouse is over the title link.. For
- // example, without LRE-PDF pair, the title "Yahoo!" will be rendered as
- // "!Yahoo" within the tooltip when the mouse is over the title link.
- std::wstring direction = kDefaultHtmlTextDirection;
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
- if (using_url_as_the_title) {
- l10n_util::WrapStringWithLTRFormatting(&title_to_set);
- } else {
- if (l10n_util::StringContainsStrongRTLChars(wstring_title)) {
- l10n_util::WrapStringWithRTLFormatting(&title_to_set);
- direction = kRTLHtmlTextDirection;
- } else {
- l10n_util::WrapStringWithLTRFormatting(&title_to_set);
- }
- }
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
}
- dictionary->SetString(L"title", title_to_set);
- dictionary->SetString(L"direction", direction);
-}
-} // end anonymous namespace
+ // Setters and getters for first_view.
+ static void set_first_view(bool first_view) { first_view_ = first_view; }
+ static bool first_view() { return first_view_; }
-///////////////////////////////////////////////////////////////////////////////
-// NewTabHTMLSource
+ private:
+ // Whether this is the is the first viewing of the new tab page and
+ // we think it is the user's startup page.
+ static bool first_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(NewTabHTMLSource);
+};
+
+bool NewTabHTMLSource::first_view_ = true;
NewTabHTMLSource::NewTabHTMLSource()
- : DataSource(chrome::kNewTabHost, MessageLoop::current()) {
+ : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()) {
}
void NewTabHTMLSource::StartDataRequest(const std::string& path,
@@ -253,8 +283,26 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path,
///////////////////////////////////////////////////////////////////////////////
// IncognitoTabHTMLSource
+class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ // Creates our datasource and sets our user message to a specific message
+ // from our string bundle.
+ IncognitoTabHTMLSource();
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path, int request_id);
+
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(IncognitoTabHTMLSource);
+};
+
IncognitoTabHTMLSource::IncognitoTabHTMLSource()
- : DataSource(chrome::kNewTabHost, MessageLoop::current()) {
+ : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()) {
}
void IncognitoTabHTMLSource::StartDataRequest(const std::string& path,
@@ -287,6 +335,43 @@ void IncognitoTabHTMLSource::StartDataRequest(const std::string& path,
///////////////////////////////////////////////////////////////////////////////
// MostVisitedHandler
+// The handler for Javascript messages related to the "most visited" view.
+class MostVisitedHandler : public DOMMessageHandler,
+ public NotificationObserver {
+ public:
+ explicit MostVisitedHandler(DOMUI* dom_ui);
+ virtual ~MostVisitedHandler();
+
+ // Callback for the "getMostVisited" message.
+ void HandleGetMostVisited(const Value* value);
+
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ const std::vector<GURL>& most_visited_urls() const {
+ return most_visited_urls_;
+ }
+
+ private:
+ // Callback from the history system when the most visited list is available.
+ void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
+ std::vector<PageUsageData*>* data);
+
+ DOMUI* dom_ui_;
+
+ // Our consumer for the history service.
+ CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
+
+ // The most visited URLs, in priority order.
+ // Only used for matching up clicks on the page to which most visited entry
+ // was clicked on for metrics purposes.
+ std::vector<GURL> most_visited_urls_;
+
+ DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler);
+};
+
MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui) {
@@ -300,27 +385,27 @@ MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui)
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
- new ThumbnailSource(dom_ui->get_profile())));
+ new DOMUIThumbnailSource(dom_ui->GetProfile())));
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource,
- new FavIconSource(dom_ui->get_profile())));
+ new DOMUIFavIconSource(dom_ui->GetProfile())));
// Get notifications when history is cleared.
NotificationService* service = NotificationService::current();
service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_->get_profile()));
+ Source<Profile>(dom_ui_->GetProfile()));
}
MostVisitedHandler::~MostVisitedHandler() {
NotificationService* service = NotificationService::current();
service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(dom_ui_->get_profile()));
+ Source<Profile>(dom_ui_->GetProfile()));
}
void MostVisitedHandler::HandleGetMostVisited(const Value* value) {
HistoryService* hs =
- dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QuerySegmentUsageSince(
&cancelable_consumer_,
base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope),
@@ -359,6 +444,31 @@ void MostVisitedHandler::Observe(NotificationType type,
///////////////////////////////////////////////////////////////////////////////
// TemplateURLHandler
+// The handler for Javascript messages related to the "common searches" view.
+class TemplateURLHandler : public DOMMessageHandler,
+ public TemplateURLModelObserver {
+ public:
+ explicit TemplateURLHandler(DOMUI* dom_ui);
+ virtual ~TemplateURLHandler();
+
+ // Callback for the "getMostSearched" message, sent when the page requests
+ // the list of available searches.
+ void HandleGetMostSearched(const Value* content);
+ // Callback for the "doSearch" message, sent when the user wants to
+ // run a search. Content of the message is an array containing
+ // [<the search keyword>, <the search term>].
+ void HandleDoSearch(const Value* content);
+
+ // TemplateURLModelObserver implementation.
+ virtual void OnTemplateURLModelChanged();
+
+ private:
+ DOMUI* dom_ui_;
+ TemplateURLModel* template_url_model_; // Owned by profile.
+
+ DISALLOW_COPY_AND_ASSIGN(TemplateURLHandler);
+};
+
TemplateURLHandler::TemplateURLHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui),
@@ -378,7 +488,7 @@ void TemplateURLHandler::HandleGetMostSearched(const Value* content) {
// The page Javascript has requested the list of keyword searches.
// Start loading them from the template URL backend.
if (!template_url_model_) {
- template_url_model_ = dom_ui_->get_profile()->GetTemplateURLModel();
+ template_url_model_ = dom_ui_->GetProfile()->GetTemplateURLModel();
template_url_model_->AddObserver(this);
}
if (template_url_model_->loaded()) {
@@ -435,7 +545,7 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) {
if (url.is_valid()) {
// Load the URL.
- dom_ui_->get_contents()->OpenURL(url, GURL(), CURRENT_TAB,
+ dom_ui_->web_contents()->OpenURL(url, GURL(), CURRENT_TAB,
PageTransition::LINK);
// Record the user action
@@ -456,7 +566,7 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) {
if (urls[i] == template_url) {
UserMetrics::RecordComputedAction(
StringPrintf(L"NTP_SearchURL%d", item_number),
- dom_ui_->get_profile());
+ dom_ui_->GetProfile());
break;
}
@@ -494,6 +604,51 @@ void TemplateURLHandler::OnTemplateURLModelChanged() {
///////////////////////////////////////////////////////////////////////////////
// RecentlyBookmarkedHandler
+class RecentlyBookmarkedHandler : public DOMMessageHandler,
+ public BookmarkModelObserver {
+ public:
+ explicit RecentlyBookmarkedHandler(DOMUI* dom_ui);
+ ~RecentlyBookmarkedHandler();
+
+ // Callback which navigates to the bookmarks page.
+ void HandleShowBookmarkPage(const Value*);
+
+ // Callback for the "getRecentlyBookmarked" message.
+ // It takes no arguments.
+ void HandleGetRecentlyBookmarked(const Value*);
+
+ private:
+ void SendBookmarksToPage();
+
+ // BookmarkModelObserver methods. These invoke SendBookmarksToPage.
+ virtual void Loaded(BookmarkModel* model);
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index);
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index);
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ BookmarkNode* node);
+
+ // These won't effect what is shown, so they do nothing.
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ BookmarkNode* old_parent,
+ int old_index,
+ BookmarkNode* new_parent,
+ int new_index) {}
+ virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ BookmarkNode* node) {}
+ virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
+ BookmarkNode* node) {}
+
+ DOMUI* dom_ui_;
+ // The model we're getting bookmarks from. The model is owned by the Profile.
+ BookmarkModel* model_;
+
+ DISALLOW_COPY_AND_ASSIGN(RecentlyBookmarkedHandler);
+};
+
RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui),
@@ -510,7 +665,7 @@ RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() {
void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
if (!model_) {
- model_ = dom_ui_->get_profile()->GetBookmarkModel();
+ model_ = dom_ui_->GetProfile()->GetBookmarkModel();
model_->AddObserver(this);
}
// If the model is loaded, synchronously send the bookmarks down. Otherwise
@@ -558,6 +713,48 @@ void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model,
///////////////////////////////////////////////////////////////////////////////
// RecentlyClosedTabsHandler
+class RecentlyClosedTabsHandler : public DOMMessageHandler,
+ public TabRestoreService::Observer {
+ public:
+ explicit RecentlyClosedTabsHandler(DOMUI* dom_ui);
+ virtual ~RecentlyClosedTabsHandler();
+
+ // Callback for the "reopenTab" message. Rewrites the history of the
+ // currently displayed tab to be the one in TabRestoreService with a
+ // history of a session passed in through the content pointer.
+ void HandleReopenTab(const Value* content);
+
+ // Callback for the "getRecentlyClosedTabs" message.
+ void HandleGetRecentlyClosedTabs(const Value* content);
+
+ // Observer callback for TabRestoreService::Observer. Sends data on
+ // recently closed tabs to the javascript side of this page to
+ // display to the user.
+ virtual void TabRestoreServiceChanged(TabRestoreService* service);
+
+ // Observer callback to notice when our associated TabRestoreService
+ // is destroyed.
+ virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
+
+ private:
+ // Converts a closed tab to the value sent down to the NTP. Returns true on
+ // success, false if the value shouldn't be sent down.
+ bool TabToValue(const TabRestoreService::Tab& tab,
+ DictionaryValue* dictionary);
+
+ // Converts a closed window to the value sent down to the NTP. Returns true
+ // on success, false if the value shouldn't be sent down.
+ bool WindowToValue(const TabRestoreService::Window& window,
+ DictionaryValue* dictionary);
+
+ DOMUI* dom_ui_;
+
+ // TabRestoreService that we are observing.
+ TabRestoreService* tab_restore_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(RecentlyClosedTabsHandler);
+};
+
RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui),
@@ -575,7 +772,7 @@ RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
}
void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
- NavigationController* controller = dom_ui_->get_contents()->controller();
+ NavigationController* controller = dom_ui_->web_contents()->controller();
Browser* browser = Browser::GetBrowserForController(
controller, NULL);
if (!browser)
@@ -608,7 +805,7 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) {
void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
const Value* content) {
if (!tab_restore_service_) {
- tab_restore_service_ = dom_ui_->get_profile()->GetTabRestoreService();
+ tab_restore_service_ = dom_ui_->GetProfile()->GetTabRestoreService();
// GetTabRestoreService() can return NULL (i.e., when in Off the
// Record mode)
@@ -666,7 +863,7 @@ bool RecentlyClosedTabsHandler::TabToValue(
const TabNavigation& current_navigation =
tab.navigations.at(tab.current_navigation_index);
- if (current_navigation.url() == NewTabUI::GetBaseURL())
+ if (current_navigation.url() == GURL(chrome::kChromeUINewTabURL))
return false;
SetURLTitleAndDirection(dictionary, current_navigation.title(),
@@ -704,6 +901,22 @@ bool RecentlyClosedTabsHandler::WindowToValue(
///////////////////////////////////////////////////////////////////////////////
// HistoryHandler
+class HistoryHandler : public DOMMessageHandler {
+ public:
+ explicit HistoryHandler(DOMUI* dom_ui);
+
+ // Callback which navigates to the history page.
+ void HandleShowHistoryPage(const Value*);
+
+ // Callback which navigates to the history page and performs a search.
+ void HandleSearchHistoryPage(const Value* content);
+
+ private:
+ DOMUI* dom_ui_;
+
+ DISALLOW_COPY_AND_ASSIGN(HistoryHandler);
+};
+
HistoryHandler::HistoryHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui) {
@@ -714,11 +927,11 @@ HistoryHandler::HistoryHandler(DOMUI* dom_ui)
}
void HistoryHandler::HandleShowHistoryPage(const Value*) {
- NavigationController* controller = dom_ui_->get_contents()->controller();
+ NavigationController* controller = dom_ui_->web_contents()->controller();
if (controller) {
- UserMetrics::RecordAction(L"NTP_ShowHistory",
- dom_ui_->get_profile());
- controller->LoadURL(HistoryUI::GetBaseURL(), GURL(), PageTransition::LINK);
+ UserMetrics::RecordAction(L"NTP_ShowHistory", dom_ui_->GetProfile());
+ controller->LoadURL(GURL(chrome::kChromeUINewTabURL), GURL(),
+ PageTransition::LINK);
// We are deleted by LoadURL, so do not call anything else.
}
}
@@ -733,13 +946,12 @@ void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
static_cast<const StringValue*>(list_member);
std::wstring wstring_value;
if (string_value->GetAsString(&wstring_value)) {
- UserMetrics::RecordAction(L"NTP_SearchHistory",
- dom_ui_->get_profile());
+ UserMetrics::RecordAction(L"NTP_SearchHistory", dom_ui_->GetProfile());
#if defined(OS_WIN)
// TODO(port): include this once history is converted to HTML
NavigationController* controller =
- dom_ui_->get_contents()->controller();
+ dom_ui_->web_contents()->controller();
controller->LoadURL(
HistoryUI::GetHistoryURLWithSearchText(wstring_value),
GURL(),
@@ -756,6 +968,25 @@ void HistoryHandler::HandleSearchHistoryPage(const Value* content) {
///////////////////////////////////////////////////////////////////////////////
// MetricsHandler
+// Let the page contents record UMA actions. Only use when you can't do it from
+// C++. For example, we currently use it to let the NTP log the postion of the
+// Most Visited or Bookmark the user clicked on, as we don't get that
+// information through RequestOpenURL. You will need to update the metrics
+// dashboard with the action names you use, as our processor won't catch that
+// information (treat it as RecordComputedMetrics)
+class MetricsHandler : public DOMMessageHandler {
+ public:
+ explicit MetricsHandler(DOMUI* dom_ui);
+
+ // Callback which records a user action.
+ void HandleMetrics(const Value* content);
+
+ private:
+ DOMUI* dom_ui_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsHandler);
+};
+
MetricsHandler::MetricsHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
dom_ui_(dom_ui) {
@@ -773,49 +1004,44 @@ void MetricsHandler::HandleMetrics(const Value* content) {
static_cast<const StringValue*>(list_member);
std::wstring wstring_value;
if (string_value->GetAsString(&wstring_value)) {
- UserMetrics::RecordComputedAction(wstring_value,
- dom_ui_->get_profile());
+ UserMetrics::RecordComputedAction(wstring_value, dom_ui_->GetProfile());
}
}
}
}
+} // namespace
+
///////////////////////////////////////////////////////////////////////////////
-// NewTabUIContents
-
-NewTabUI::NewTabUI(DOMUIContents* contents) :
- DOMUI(contents),
- motd_message_id_(0),
- incognito_(false),
- most_visited_handler_(NULL) {
- if (get_profile()->IsOffTheRecord())
- incognito_ = true;
+// NewTabUI
+
+NewTabUI::NewTabUI(WebContents* contents)
+ : DOMUI(contents),
+ motd_message_id_(0),
+ incognito_(false) {
+ // Override some options on the DOM UI.
+ hide_favicon_ = true;
+ force_bookmark_bar_visible_ = true;
+ focus_location_bar_by_default_ = true;
+ should_hide_url_ = true;
+ overridden_title_ = WideToUTF16Hack(l10n_util::GetString(IDS_NEW_TAB_TITLE));
+
+ // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more
+ // highly. Note this means we're including clicks on not only most visited
+ // thumbnails, but also clicks on recently bookmarked.
+ link_transition_type_ = PageTransition::AUTO_BOOKMARK;
if (NewTabHTMLSource::first_view() &&
- (get_profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 ||
- !get_profile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))
- ) {
+ (GetProfile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 ||
+ !GetProfile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))) {
NewTabHTMLSource::set_first_view(false);
}
- contents->render_view_host()->set_paint_observer(new PaintTimer);
-}
+ web_contents()->render_view_host()->set_paint_observer(new PaintTimer);
-void NewTabUI::Init() {
- // Regretfully, DataSources are global, instead of
- // per-TabContents. Because of the motd_message_id_ member, each
- // NewTabUIContents instance could theoretically have a different
- // message. Moving this from the constructor to here means that we
- // reconnect this source each time we reload so we should no longer
- // have the bug where we open a normal new tab page (no motd), open
- // another OTR new tab page (blurb motd describing what 'incognito'
- // means), refresh the normal new page (which now displays the
- // incognito blurb because that was the last NewTabHTMLSource hooked
- // up).
- //
- // This is a workaround until http://b/issue?id=1230312 is fixed.
+ if (GetProfile()->IsOffTheRecord()) {
+ incognito_ = true;
- if (incognito_) {
IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource();
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
@@ -824,8 +1050,7 @@ void NewTabUI::Init() {
html_source));
} else {
AddMessageHandler(new TemplateURLHandler(this));
- most_visited_handler_ = new MostVisitedHandler(this);
- AddMessageHandler(most_visited_handler_); // Takes ownership.
+ AddMessageHandler(new MostVisitedHandler(this));
AddMessageHandler(new RecentlyBookmarkedHandler(this));
AddMessageHandler(new RecentlyClosedTabsHandler(this));
AddMessageHandler(new HistoryHandler(this));
@@ -844,25 +1069,3 @@ void NewTabUI::Init() {
html_source));
}
}
-
-// static
-GURL NewTabUI::GetBaseURL() {
- return GURL(chrome::kChromeUINewTabURL);
-}
-
-void NewTabUI::SetInitialFocus() {
- if (get_contents()->delegate())
- get_contents()->delegate()->SetFocusToLocationBar();
-}
-
-void NewTabUI::RequestOpenURL(const GURL& url,
- const GURL&,
- WindowOpenDisposition disposition) {
- // The user opened a URL on the page (including "open in new window").
- // We count all such clicks as AUTO_BOOKMARK, which increments the site's
- // visit count (which is used for ranking the most visited entries).
- // Note this means we're including clicks on not only most visited
- // thumbnails, but also clicks on recently bookmarked.
- get_contents()->OpenURL(url, GURL(), disposition,
- PageTransition::AUTO_BOOKMARK);
-}
diff --git a/chrome/browser/dom_ui/new_tab_ui.h b/chrome/browser/dom_ui/new_tab_ui.h
index 3d915b7..4a59201 100644
--- a/chrome/browser/dom_ui/new_tab_ui.h
+++ b/chrome/browser/dom_ui/new_tab_ui.h
@@ -2,275 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
-#define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
+#ifndef CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H_
+#define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H_
-#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
-#include "chrome/browser/history/history.h"
-#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/browser/sessions/tab_restore_service.h"
-class DictionaryValue;
class GURL;
class Profile;
-class Value;
-enum TabContentsType;
-
-// The following classes aren't used outside of new_tab_ui.cc but are
-// put here for clarity.
-
-class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- NewTabHTMLSource();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path, int request_id);
-
- virtual std::string GetMimeType(const std::string&) const {
- return "text/html";
- }
-
- // Setters and getters for first_view.
- static void set_first_view(bool first_view) { first_view_ = first_view; }
- static bool first_view() { return first_view_; }
- private:
- // Whether this is the is the first viewing of the new tab page and
- // we think it is the user's startup page.
- static bool first_view_;
-
- DISALLOW_EVIL_CONSTRUCTORS(NewTabHTMLSource);
-};
-
-class IncognitoTabHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- // Creates our datasource and sets our user message to a specific message
- // from our string bundle.
- IncognitoTabHTMLSource();
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path, int request_id);
-
- virtual std::string GetMimeType(const std::string&) const {
- return "text/html";
- }
-
- private:
- DISALLOW_EVIL_CONSTRUCTORS(IncognitoTabHTMLSource);
-};
-
-// The handler for Javascript messages related to the "most visited" view.
-class MostVisitedHandler : public DOMMessageHandler,
- public NotificationObserver {
- public:
- explicit MostVisitedHandler(DOMUI* dom_ui);
- virtual ~MostVisitedHandler();
-
- // Callback for the "getMostVisited" message.
- void HandleGetMostVisited(const Value* value);
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- const std::vector<GURL>& most_visited_urls() const {
- return most_visited_urls_;
- }
-
- private:
- // Callback from the history system when the most visited list is available.
- void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
- std::vector<PageUsageData*>* data);
-
- DOMUI* dom_ui_;
-
- // Our consumer for the history service.
- CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
-
- // The most visited URLs, in priority order.
- // Only used for matching up clicks on the page to which most visited entry
- // was clicked on for metrics purposes.
- std::vector<GURL> most_visited_urls_;
-
- DISALLOW_EVIL_CONSTRUCTORS(MostVisitedHandler);
-};
-
-// The handler for Javascript messages related to the "common searches" view.
-class TemplateURLHandler : public DOMMessageHandler,
- public TemplateURLModelObserver {
- public:
- explicit TemplateURLHandler(DOMUI* dom_ui);
- virtual ~TemplateURLHandler();
-
- // Callback for the "getMostSearched" message, sent when the page requests
- // the list of available searches.
- void HandleGetMostSearched(const Value* content);
- // Callback for the "doSearch" message, sent when the user wants to
- // run a search. Content of the message is an array containing
- // [<the search keyword>, <the search term>].
- void HandleDoSearch(const Value* content);
-
- // TemplateURLModelObserver implementation.
- virtual void OnTemplateURLModelChanged();
-
- private:
- DOMUI* dom_ui_;
- TemplateURLModel* template_url_model_; // Owned by profile.
-
- DISALLOW_EVIL_CONSTRUCTORS(TemplateURLHandler);
-};
-
-class RecentlyBookmarkedHandler : public DOMMessageHandler,
- public BookmarkModelObserver {
- public:
- explicit RecentlyBookmarkedHandler(DOMUI* dom_ui);
- ~RecentlyBookmarkedHandler();
-
- // Callback which navigates to the bookmarks page.
- void HandleShowBookmarkPage(const Value*);
-
- // Callback for the "getRecentlyBookmarked" message.
- // It takes no arguments.
- void HandleGetRecentlyBookmarked(const Value*);
-
- private:
- void SendBookmarksToPage();
-
- // BookmarkModelObserver methods. These invoke SendBookmarksToPage.
- virtual void Loaded(BookmarkModel* model);
- virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
- int index);
- virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
- int index);
- virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
-
- // These won't effect what is shown, so they do nothing.
- virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
- int old_index,
- BookmarkNode* new_parent,
- int new_index) {}
- virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {}
- virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
-
- DOMUI* dom_ui_;
- // The model we're getting bookmarks from. The model is owned by the Profile.
- BookmarkModel* model_;
-
- DISALLOW_EVIL_CONSTRUCTORS(RecentlyBookmarkedHandler);
-};
-
-class RecentlyClosedTabsHandler : public DOMMessageHandler,
- public TabRestoreService::Observer {
- public:
- explicit RecentlyClosedTabsHandler(DOMUI* dom_ui);
- virtual ~RecentlyClosedTabsHandler();
-
- // Callback for the "reopenTab" message. Rewrites the history of the
- // currently displayed tab to be the one in TabRestoreService with a
- // history of a session passed in through the content pointer.
- void HandleReopenTab(const Value* content);
-
- // Callback for the "getRecentlyClosedTabs" message.
- void HandleGetRecentlyClosedTabs(const Value* content);
-
- // Observer callback for TabRestoreService::Observer. Sends data on
- // recently closed tabs to the javascript side of this page to
- // display to the user.
- virtual void TabRestoreServiceChanged(TabRestoreService* service);
-
- // Observer callback to notice when our associated TabRestoreService
- // is destroyed.
- virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
-
- private:
- // Converts a closed tab to the value sent down to the NTP. Returns true on
- // success, false if the value shouldn't be sent down.
- bool TabToValue(const TabRestoreService::Tab& tab,
- DictionaryValue* dictionary);
-
- // Converts a closed window to the value sent down to the NTP. Returns true
- // on success, false if the value shouldn't be sent down.
- bool WindowToValue(const TabRestoreService::Window& window,
- DictionaryValue* dictionary);
-
- DOMUI* dom_ui_;
-
- /// TabRestoreService that we are observing.
- TabRestoreService* tab_restore_service_;
-
- DISALLOW_EVIL_CONSTRUCTORS(RecentlyClosedTabsHandler);
-};
-
-class HistoryHandler : public DOMMessageHandler {
- public:
- explicit HistoryHandler(DOMUI* dom_ui);
-
- // Callback which navigates to the history page.
- void HandleShowHistoryPage(const Value*);
-
- // Callback which navigates to the history page and performs a search.
- void HandleSearchHistoryPage(const Value* content);
-
- private:
- DOMUI* dom_ui_;
- DISALLOW_EVIL_CONSTRUCTORS(HistoryHandler);
-};
-
-// Let the page contents record UMA actions. Only use when you can't do it from
-// C++. For example, we currently use it to let the NTP log the postion of the
-// Most Visited or Bookmark the user clicked on, as we don't get that
-// information through RequestOpenURL. You will need to update the metrics
-// dashboard with the action names you use, as our processor won't catch that
-// information (treat it as RecordComputedMetrics)
-class MetricsHandler : public DOMMessageHandler {
- public:
- explicit MetricsHandler(DOMUI* dom_ui);
-
- // Callback which records a user action.
- void HandleMetrics(const Value* content);
-
- private:
- DOMUI* dom_ui_;
- DISALLOW_EVIL_CONSTRUCTORS(MetricsHandler);
-};
// The TabContents used for the New Tab page.
class NewTabUI : public DOMUI {
public:
- explicit NewTabUI(DOMUIContents* contents);
-
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
-
- // DOMUI Implementation
- virtual void Init();
-
- // Overridden from DOMUI.
- // Favicon should not be displayed.
- virtual bool ShouldDisplayFavIcon() { return false; }
- // Bookmark bar should always be visible.
- virtual bool IsBookmarkBarAlwaysVisible() { return true; }
- // When NTP gets the initial focus, focus the URL bar.
- virtual void SetInitialFocus();
- // Should not display our URL.
- virtual bool ShouldDisplayURL() { return false; }
- // Control what happens when a link is clicked.
- virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
- WindowOpenDisposition disposition);
+ explicit NewTabUI(WebContents* manager);
private:
- DOMUIContents* contents_;
-
// The message id that should be displayed in this NewTabUIContents
// instance's motd area.
int motd_message_id_;
@@ -279,11 +24,7 @@ class NewTabUI : public DOMUI {
// what HTML to load.
bool incognito_;
- // A pointer to the handler for most visited.
- // Owned by the DOMUIHost.
- MostVisitedHandler* most_visited_handler_;
-
- DISALLOW_EVIL_CONSTRUCTORS(NewTabUI);
+ DISALLOW_COPY_AND_ASSIGN(NewTabUI);
};
-#endif // CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
+#endif // CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H_
diff --git a/chrome/browser/download/download_shelf.cc b/chrome/browser/download/download_shelf.cc
index 9644d26..f27b46d 100644
--- a/chrome/browser/download/download_shelf.cc
+++ b/chrome/browser/download/download_shelf.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/l10n_util.h"
+#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#if defined(OS_WIN)
@@ -25,9 +26,8 @@ void DownloadShelf::ShowAllDownloads() {
Profile* profile = tab_contents_->profile();
if (profile)
UserMetrics::RecordAction(L"ShowDownloads", profile);
- GURL url = DownloadsUI::GetBaseURL();
- tab_contents_->OpenURL(url, GURL(), NEW_FOREGROUND_TAB,
- PageTransition::AUTO_BOOKMARK);
+ tab_contents_->OpenURL(GURL(chrome::kChromeUIDownloadsURL), GURL(),
+ NEW_FOREGROUND_TAB, PageTransition::AUTO_BOOKMARK);
}
void DownloadShelf::ChangeTabContents(TabContents* old_contents,
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index 6c1c918..3048172 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -18,9 +18,6 @@
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
-// ExtensionsUI is accessible from chrome-ui://extensions.
-static const char kExtensionsHost[] = "extensions";
-
////////////////////////////////////////////////////////////////////////////////
//
// ExtensionsHTMLSource
@@ -28,7 +25,7 @@ static const char kExtensionsHost[] = "extensions";
////////////////////////////////////////////////////////////////////////////////
ExtensionsUIHTMLSource::ExtensionsUIHTMLSource()
- : DataSource(kExtensionsHost, MessageLoop::current()) {
+ : DataSource(chrome::kChromeUIExtensionsHost, MessageLoop::current()) {
}
void ExtensionsUIHTMLSource::StartDataRequest(const std::string& path,
@@ -150,11 +147,8 @@ ExtensionsDOMHandler::~ExtensionsDOMHandler() {
void ExtensionsDOMHandler::Init() {
}
-ExtensionsUI::ExtensionsUI(DOMUIContents* contents) : DOMUI(contents) {
-}
-
-void ExtensionsUI::Init() {
- ExtensionsService *exstension_service = get_profile()->GetExtensionsService();
+ExtensionsUI::ExtensionsUI(WebContents* contents) : DOMUI(contents) {
+ ExtensionsService *exstension_service = GetProfile()->GetExtensionsService();
ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(this,
exstension_service);
@@ -168,11 +162,3 @@ void ExtensionsUI::Init() {
NewRunnableMethod(&chrome_url_data_manager,
&ChromeURLDataManager::AddDataSource, html_source));
}
-
-// static
-GURL ExtensionsUI::GetBaseURL() {
- std::string url = DOMUIContents::GetScheme();
- url += chrome::kStandardSchemeSeparator;
- url += kExtensionsHost;
- return GURL(url);
-}
diff --git a/chrome/browser/extensions/extensions_ui.h b/chrome/browser/extensions/extensions_ui.h
index 457c73e..7234fea 100644
--- a/chrome/browser/extensions/extensions_ui.h
+++ b/chrome/browser/extensions/extensions_ui.h
@@ -7,8 +7,8 @@
#include <string>
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
-#include "chrome/browser/dom_ui/dom_ui_contents.h"
#include "chrome/browser/extensions/extensions_service.h"
class GURL;
@@ -58,17 +58,9 @@ class ExtensionsDOMHandler : public DOMMessageHandler {
class ExtensionsUI : public DOMUI {
public:
- explicit ExtensionsUI(DOMUIContents* contents);
-
- // Return the URL for the front page of this UI.
- static GURL GetBaseURL();
-
- // DOMUI Implementation
- virtual void Init();
+ explicit ExtensionsUI(WebContents* contents);
private:
- DOMUIContents* contents_;
-
DISALLOW_COPY_AND_ASSIGN(ExtensionsUI);
};
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index 2fe3669..576203f 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -576,7 +576,8 @@ bool HistoryService::CanAddURL(const GURL& url) const {
if (url.SchemeIs(chrome::kJavaScriptScheme) ||
url.SchemeIs(chrome::kChromeUIScheme) ||
- url.SchemeIs(chrome::kViewSourceScheme))
+ url.SchemeIs(chrome::kViewSourceScheme) ||
+ url.SchemeIs(chrome::kChromeInternalScheme))
return false;
if (url.SchemeIs(chrome::kAboutScheme)) {
diff --git a/chrome/browser/navigation_entry_unittest.cc b/chrome/browser/navigation_entry_unittest.cc
index 7d4f77a..2e36144 100644
--- a/chrome/browser/navigation_entry_unittest.cc
+++ b/chrome/browser/navigation_entry_unittest.cc
@@ -15,7 +15,7 @@ class NavigationEntryTest : public testing::Test {
entry1_.reset(new NavigationEntry(TAB_CONTENTS_WEB));
instance_ = SiteInstance::CreateSiteInstance(NULL);
- entry2_.reset(new NavigationEntry(TAB_CONTENTS_DOM_UI, instance_, 3,
+ entry2_.reset(new NavigationEntry(TAB_CONTENTS_WEB, instance_, 3,
GURL("test:url"),
GURL("from"),
ASCIIToUTF16("title"),
@@ -125,7 +125,7 @@ TEST_F(NavigationEntryTest, NavigationEntrySSLStatus) {
TEST_F(NavigationEntryTest, NavigationEntryAccessors) {
// Type
EXPECT_EQ(TAB_CONTENTS_WEB, entry1_.get()->tab_type());
- EXPECT_EQ(TAB_CONTENTS_DOM_UI, entry2_.get()->tab_type());
+ EXPECT_EQ(TAB_CONTENTS_WEB, entry2_.get()->tab_type());
// SiteInstance
EXPECT_TRUE(entry1_.get()->site_instance() == NULL);
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 877e0a7..7aeb243 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -217,13 +217,18 @@ bool BrowserRenderProcessHost::Init() {
// be doing.
channel_->set_sync_messages_with_no_timeout_allowed(false);
- // build command line for renderer, we have to quote the executable name to
- // deal with spaces
+ // Build command line for renderer, we have to quote the executable name to
+ // deal with spaces.
std::wstring renderer_path =
browser_command_line.GetSwitchValue(switches::kRendererPath);
- if (renderer_path.empty())
- if (!GetRendererPath(&renderer_path))
+ if (renderer_path.empty()) {
+ if (!GetRendererPath(&renderer_path)) {
+ // Need to reset the channel we created above or others might think the
+ // connection is live.
+ channel_.reset();
return false;
+ }
+ }
CommandLine cmd_line(renderer_path);
if (logging::DialogsAreSuppressed())
cmd_line.AppendSwitch(switches::kNoErrorDialogs);
@@ -358,11 +363,13 @@ bool BrowserRenderProcessHost::Init() {
if (!AddGenericPolicy(policy)) {
NOTREACHED();
+ channel_.reset();
return false;
}
if (!AddDllEvictionPolicy(policy)) {
NOTREACHED();
+ channel_.reset();
return false;
}
@@ -375,8 +382,10 @@ bool BrowserRenderProcessHost::Init() {
if (desktop)
CloseDesktop(desktop);
- if (sandbox::SBOX_ALL_OK != result)
+ if (sandbox::SBOX_ALL_OK != result) {
+ channel_.reset();
return false;
+ }
bool on_sandbox_desktop = (desktop != NULL);
NotificationService::current()->Notify(
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index 5ccc3f6..dd090c0 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -19,6 +19,7 @@
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
+#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
@@ -378,7 +379,7 @@ void SafeBrowsingBlockingPage::DontProceed() {
// for the tab has by then already been destroyed.
if (navigation_entry_index_to_remove_ != -1 && !tab()->is_being_destroyed()) {
tab()->controller()->RemoveEntryAtIndex(navigation_entry_index_to_remove_,
- NewTabUI::GetBaseURL());
+ GURL(chrome::kChromeUINewTabURL));
navigation_entry_index_to_remove_ = -1;
}
InterstitialPage::DontProceed();
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());
}
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index 2b29a16..8845024 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -31,7 +31,9 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
virtual ~TabStripDummyDelegate() {}
// Overridden from TabStripModelDelegate:
- virtual GURL GetBlankTabURL() const { return NewTabUI::GetBaseURL(); }
+ virtual GURL GetBlankTabURL() const {
+ return GURL(chrome::kChromeUINewTabURL);
+ }
virtual void CreateNewStripWithContents(TabContents* contents,
const gfx::Rect& window_bounds,
const DockInfo& dock_info) {}
@@ -43,7 +45,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
PageTransition::Type transition,
bool defer_load,
SiteInstance* instance) const {
- if (url == NewTabUI::GetBaseURL())
+ if (url == GURL(chrome::kChromeUINewTabURL))
return dummy_contents_;
return NULL;
}
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index a1abb9b..af3e9bd 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -28,6 +28,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/resource_bundle.h"
+#include "chrome/common/url_constants.h"
#include "chrome/views/controls/button/checkbox.h"
#include "chrome/views/controls/button/radio_button.h"
#include "chrome/views/controls/label.h"
@@ -39,14 +40,15 @@
#include "grit/theme_resources.h"
#include "skia/include/SkBitmap.h"
+namespace {
+
static const int kStartupRadioGroup = 1;
static const int kHomePageRadioGroup = 2;
static const SkColor kDefaultBrowserLabelColor = SkColorSetRGB(0, 135, 0);
static const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0);
-namespace {
std::wstring GetNewTabUIURLString() {
- return UTF8ToWide(NewTabUI::GetBaseURL().spec());
+ return UTF8ToWide(chrome::kChromeUINewTabURL);
}
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d75e285..65c2f4a 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -551,10 +551,14 @@
'browser/dom_ui/devtools_ui.h',
'browser/dom_ui/dom_ui.cc',
'browser/dom_ui/dom_ui.h',
- 'browser/dom_ui/dom_ui_contents.cc',
- 'browser/dom_ui/dom_ui_contents.h',
+ 'browser/dom_ui/dom_ui_factory.cc',
+ 'browser/dom_ui/dom_ui_factory.h',
+ 'browser/dom_ui/dom_ui_favicon_source.cc',
+ 'browser/dom_ui/dom_ui_favicon_source.h',
'browser/dom_ui/dom_ui_host.cc',
'browser/dom_ui/dom_ui_host.h',
+ 'browser/dom_ui/dom_ui_thumbnail_source.cc',
+ 'browser/dom_ui/dom_ui_thumbnail_source.h',
'browser/dom_ui/downloads_ui.cc',
'browser/dom_ui/downloads_ui.h',
'browser/dom_ui/fileicon_source.cc',
diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc
index c770320..8b62ef3 100644
--- a/chrome/common/url_constants.cc
+++ b/chrome/common/url_constants.cc
@@ -27,12 +27,22 @@ const char kAboutBlankURL[] = "about:blank";
const char kAboutCacheURL[] = "about:cache";
const char kAboutMemoryURL[] = "about:memory";
+const char kChromeUIDevToolsURL[] = "chrome-ui://devtools/";
+const char kChromeUIDownloadsURL[] = "chrome-ui://downloads/";
+const char kChromeUIExtensionsURL[] = "chrome-ui://extensions/";
+const char kChromeUIHistoryURL[] = "chrome-ui://history/";
+const char kChromeUIInspectorURL[] = "chrome-ui://inspector/";
const char kChromeUIIPCURL[] = "chrome-ui://about/ipc";
const char kChromeUINetworkURL[] = "chrome-ui://about/network";
const char kChromeUINewTabURL[] = "chrome-ui://newtab";
-const char kDevToolsHost[] = "devtools";
-const char kInspectorHost[] = "inspector";
-const char kNewTabHost[] = "newtab";
+const char kChromeUIDevToolsHost[] = "devtools";
+const char kChromeUIDownloadsHost[] = "downloads";
+const char kChromeUIExtensionsHost[] = "extensions";
+const char kChromeUIFavIconPath[] = "favicon";
+const char kChromeUIHistoryHost[] = "history";
+const char kChromeUIInspectorHost[] = "inspector";
+const char kChromeUINewTabHost[] = "newtab";
+const char kChromeUIThumbnailPath[] = "thumb";
} // namespace chrome
diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h
index 13313d3..88faaaf 100644
--- a/chrome/common/url_constants.h
+++ b/chrome/common/url_constants.h
@@ -33,15 +33,27 @@ extern const char kAboutBlankURL[];
extern const char kAboutCacheURL[];
extern const char kAboutMemoryURL[];
-// chrome-ui: URLs (including schemes).
+// chrome-ui: URLs (including schemes). Should be kept in sync with the
+// components below.
+extern const char kChromeUIDevToolsURL[];
+extern const char kChromeUIDownloadsURL[];
+extern const char kChromeUIExtensionsURL[];
+extern const char kChromeUIHistoryURL[];
extern const char kChromeUIIPCURL[];
+extern const char kChromeUIInspectorURL[];
extern const char kChromeUINetworkURL[];
extern const char kChromeUINewTabURL[];
-// chrome-ui components of URLs.
-extern const char kDevToolsHost[];
-extern const char kInspectorHost[];
-extern const char kNewTabHost[];
+// chrome-ui components of URLs. Should be kept in sync with the full URLs
+// above.
+extern const char kChromeUIDevToolsHost[];
+extern const char kChromeUIDownloadsHost[];
+extern const char kChromeUIExtensionsHost[];
+extern const char kChromeUIFavIconPath[];
+extern const char kChromeUIHistoryHost[];
+extern const char kChromeUIInspectorHost[];
+extern const char kChromeUINewTabHost[];
+extern const char kChromeUIThumbnailPath[];
} // namespace chrome