Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1112)

Side by Side Diff: chrome/browser/dom_ui/new_tab_ui.h

Issue 28104: Enable history and downloads by default, port NewTabUI from DOMUIHost to DOMU... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/history_ui.cc ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__ 5 #ifndef CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
6 #define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__ 6 #define CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
7 7
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/dom_ui/dom_ui_host.h" 9 #include "chrome/browser/dom_ui/dom_ui.h"
10 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 10 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
11 #include "chrome/browser/history/history.h" 11 #include "chrome/browser/history/history.h"
12 #include "chrome/browser/search_engines/template_url_model.h" 12 #include "chrome/browser/search_engines/template_url_model.h"
13 #include "chrome/browser/sessions/tab_restore_service.h" 13 #include "chrome/browser/sessions/tab_restore_service.h"
14 14
15 class DictionaryValue; 15 class DictionaryValue;
16 class GURL; 16 class GURL;
17 class Profile; 17 class Profile;
18 class Value; 18 class Value;
19 enum TabContentsType; 19 enum TabContentsType;
20 20
21 // Return the URL for the new tab page.
22 GURL NewTabUIURL();
23
24 // If a |url| is a chrome-internal: URL, this method sets up |url|, and
25 // |result_type| to the appropriate values for displaying the new tab page
26 // and returns true. Exposed for use by BrowserURLHandler.
27 bool NewTabUIHandleURL(GURL* url, TabContentsType* result_type);
28
29 // The following classes aren't used outside of new_tab_ui.cc but are 21 // The following classes aren't used outside of new_tab_ui.cc but are
30 // put here for clarity. 22 // put here for clarity.
31 23
32 class NewTabHTMLSource : public ChromeURLDataManager::DataSource { 24 class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
33 public: 25 public:
34 NewTabHTMLSource(); 26 NewTabHTMLSource();
35 27
36 // Called when the network layer has requested a resource underneath 28 // Called when the network layer has requested a resource underneath
37 // the path we registered. 29 // the path we registered.
38 virtual void StartDataRequest(const std::string& path, int request_id); 30 virtual void StartDataRequest(const std::string& path, int request_id);
(...skipping 28 matching lines...) Expand all
67 } 59 }
68 60
69 private: 61 private:
70 DISALLOW_EVIL_CONSTRUCTORS(IncognitoTabHTMLSource); 62 DISALLOW_EVIL_CONSTRUCTORS(IncognitoTabHTMLSource);
71 }; 63 };
72 64
73 // The handler for Javascript messages related to the "most visited" view. 65 // The handler for Javascript messages related to the "most visited" view.
74 class MostVisitedHandler : public DOMMessageHandler, 66 class MostVisitedHandler : public DOMMessageHandler,
75 public NotificationObserver { 67 public NotificationObserver {
76 public: 68 public:
77 explicit MostVisitedHandler(DOMUIHost* dom_ui_host); 69 explicit MostVisitedHandler(DOMUI* dom_ui);
78 virtual ~MostVisitedHandler(); 70 virtual ~MostVisitedHandler();
79 71
80 // Callback for the "getMostVisited" message. 72 // Callback for the "getMostVisited" message.
81 void HandleGetMostVisited(const Value* value); 73 void HandleGetMostVisited(const Value* value);
82 74
83 // NotificationObserver implementation. 75 // NotificationObserver implementation.
84 virtual void Observe(NotificationType type, 76 virtual void Observe(NotificationType type,
85 const NotificationSource& source, 77 const NotificationSource& source,
86 const NotificationDetails& details); 78 const NotificationDetails& details);
87 79
88 const std::vector<GURL>& most_visited_urls() const { 80 const std::vector<GURL>& most_visited_urls() const {
89 return most_visited_urls_; 81 return most_visited_urls_;
90 } 82 }
91 83
92 private: 84 private:
93 // Callback from the history system when the most visited list is available. 85 // Callback from the history system when the most visited list is available.
94 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, 86 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
95 std::vector<PageUsageData*>* data); 87 std::vector<PageUsageData*>* data);
96 88
97 DOMUIHost* dom_ui_host_; 89 DOMUI* dom_ui_;
98 90
99 // Our consumer for the history service. 91 // Our consumer for the history service.
100 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; 92 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
101 93
102 // The most visited URLs, in priority order. 94 // The most visited URLs, in priority order.
103 // Only used for matching up clicks on the page to which most visited entry 95 // Only used for matching up clicks on the page to which most visited entry
104 // was clicked on for metrics purposes. 96 // was clicked on for metrics purposes.
105 std::vector<GURL> most_visited_urls_; 97 std::vector<GURL> most_visited_urls_;
106 98
107 DISALLOW_EVIL_CONSTRUCTORS(MostVisitedHandler); 99 DISALLOW_EVIL_CONSTRUCTORS(MostVisitedHandler);
108 }; 100 };
109 101
110 // The handler for Javascript messages related to the "common searches" view. 102 // The handler for Javascript messages related to the "common searches" view.
111 class TemplateURLHandler : public DOMMessageHandler, 103 class TemplateURLHandler : public DOMMessageHandler,
112 public TemplateURLModelObserver { 104 public TemplateURLModelObserver {
113 public: 105 public:
114 explicit TemplateURLHandler(DOMUIHost* dom_ui_host); 106 explicit TemplateURLHandler(DOMUI* dom_ui);
115 virtual ~TemplateURLHandler(); 107 virtual ~TemplateURLHandler();
116 108
117 // Callback for the "getMostSearched" message, sent when the page requests 109 // Callback for the "getMostSearched" message, sent when the page requests
118 // the list of available searches. 110 // the list of available searches.
119 void HandleGetMostSearched(const Value* content); 111 void HandleGetMostSearched(const Value* content);
120 // Callback for the "doSearch" message, sent when the user wants to 112 // Callback for the "doSearch" message, sent when the user wants to
121 // run a search. Content of the message is an array containing 113 // run a search. Content of the message is an array containing
122 // [<the search keyword>, <the search term>]. 114 // [<the search keyword>, <the search term>].
123 void HandleDoSearch(const Value* content); 115 void HandleDoSearch(const Value* content);
124 116
125 // TemplateURLModelObserver implementation. 117 // TemplateURLModelObserver implementation.
126 virtual void OnTemplateURLModelChanged(); 118 virtual void OnTemplateURLModelChanged();
127 119
128 private: 120 private:
129 DOMUIHost* dom_ui_host_; 121 DOMUI* dom_ui_;
130 TemplateURLModel* template_url_model_; // Owned by profile. 122 TemplateURLModel* template_url_model_; // Owned by profile.
131 123
132 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLHandler); 124 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLHandler);
133 }; 125 };
134 126
135 class RecentlyBookmarkedHandler : public DOMMessageHandler, 127 class RecentlyBookmarkedHandler : public DOMMessageHandler,
136 public BookmarkModelObserver { 128 public BookmarkModelObserver {
137 public: 129 public:
138 explicit RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host); 130 explicit RecentlyBookmarkedHandler(DOMUI* dom_ui);
139 ~RecentlyBookmarkedHandler(); 131 ~RecentlyBookmarkedHandler();
140 132
141 // Callback which navigates to the bookmarks page. 133 // Callback which navigates to the bookmarks page.
142 void HandleShowBookmarkPage(const Value*); 134 void HandleShowBookmarkPage(const Value*);
143 135
144 // Callback for the "getRecentlyBookmarked" message. 136 // Callback for the "getRecentlyBookmarked" message.
145 // It takes no arguments. 137 // It takes no arguments.
146 void HandleGetRecentlyBookmarked(const Value*); 138 void HandleGetRecentlyBookmarked(const Value*);
147 139
148 private: 140 private:
(...skipping 12 matching lines...) Expand all
161 153
162 // These two won't effect what is shown, so they do nothing. 154 // These two won't effect what is shown, so they do nothing.
163 virtual void BookmarkNodeMoved(BookmarkModel* model, 155 virtual void BookmarkNodeMoved(BookmarkModel* model,
164 BookmarkNode* old_parent, 156 BookmarkNode* old_parent,
165 int old_index, 157 int old_index,
166 BookmarkNode* new_parent, 158 BookmarkNode* new_parent,
167 int new_index) {} 159 int new_index) {}
168 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, 160 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
169 BookmarkNode* node) {} 161 BookmarkNode* node) {}
170 162
171 DOMUIHost* dom_ui_host_; 163 DOMUI* dom_ui_;
172 // The model we're getting bookmarks from. The model is owned by the Profile. 164 // The model we're getting bookmarks from. The model is owned by the Profile.
173 BookmarkModel* model_; 165 BookmarkModel* model_;
174 166
175 DISALLOW_EVIL_CONSTRUCTORS(RecentlyBookmarkedHandler); 167 DISALLOW_EVIL_CONSTRUCTORS(RecentlyBookmarkedHandler);
176 }; 168 };
177 169
178 class RecentlyClosedTabsHandler : public DOMMessageHandler, 170 class RecentlyClosedTabsHandler : public DOMMessageHandler,
179 public TabRestoreService::Observer { 171 public TabRestoreService::Observer {
180 public: 172 public:
181 explicit RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host); 173 explicit RecentlyClosedTabsHandler(DOMUI* dom_ui);
182 virtual ~RecentlyClosedTabsHandler(); 174 virtual ~RecentlyClosedTabsHandler();
183 175
184 // Callback for the "reopenTab" message. Rewrites the history of the 176 // Callback for the "reopenTab" message. Rewrites the history of the
185 // currently displayed tab to be the one in TabRestoreService with a 177 // currently displayed tab to be the one in TabRestoreService with a
186 // history of a session passed in through the content pointer. 178 // history of a session passed in through the content pointer.
187 void HandleReopenTab(const Value* content); 179 void HandleReopenTab(const Value* content);
188 180
189 // Callback for the "getRecentlyClosedTabs" message. 181 // Callback for the "getRecentlyClosedTabs" message.
190 void HandleGetRecentlyClosedTabs(const Value* content); 182 void HandleGetRecentlyClosedTabs(const Value* content);
191 183
(...skipping 10 matching lines...) Expand all
202 // Converts a closed tab to the value sent down to the NTP. Returns true on 194 // Converts a closed tab to the value sent down to the NTP. Returns true on
203 // success, false if the value shouldn't be sent down. 195 // success, false if the value shouldn't be sent down.
204 bool TabToValue(const TabRestoreService::Tab& tab, 196 bool TabToValue(const TabRestoreService::Tab& tab,
205 DictionaryValue* dictionary); 197 DictionaryValue* dictionary);
206 198
207 // Converts a closed window to the value sent down to the NTP. Returns true 199 // Converts a closed window to the value sent down to the NTP. Returns true
208 // on success, false if the value shouldn't be sent down. 200 // on success, false if the value shouldn't be sent down.
209 bool WindowToValue(const TabRestoreService::Window& window, 201 bool WindowToValue(const TabRestoreService::Window& window,
210 DictionaryValue* dictionary); 202 DictionaryValue* dictionary);
211 203
212 DOMUIHost* dom_ui_host_; 204 DOMUI* dom_ui_;
213 205
214 /// TabRestoreService that we are observing. 206 /// TabRestoreService that we are observing.
215 TabRestoreService* tab_restore_service_; 207 TabRestoreService* tab_restore_service_;
216 208
217 DISALLOW_EVIL_CONSTRUCTORS(RecentlyClosedTabsHandler); 209 DISALLOW_EVIL_CONSTRUCTORS(RecentlyClosedTabsHandler);
218 }; 210 };
219 211
220 class HistoryHandler : public DOMMessageHandler { 212 class HistoryHandler : public DOMMessageHandler {
221 public: 213 public:
222 explicit HistoryHandler(DOMUIHost* dom_ui_host); 214 explicit HistoryHandler(DOMUI* dom_ui);
223 215
224 // Callback which navigates to the history page. 216 // Callback which navigates to the history page.
225 void HandleShowHistoryPage(const Value*); 217 void HandleShowHistoryPage(const Value*);
226 218
227 // Callback which navigates to the history page and performs a search. 219 // Callback which navigates to the history page and performs a search.
228 void HandleSearchHistoryPage(const Value* content); 220 void HandleSearchHistoryPage(const Value* content);
229 221
230 private: 222 private:
231 DOMUIHost* dom_ui_host_; 223 DOMUI* dom_ui_;
232 DISALLOW_EVIL_CONSTRUCTORS(HistoryHandler); 224 DISALLOW_EVIL_CONSTRUCTORS(HistoryHandler);
233 }; 225 };
234 226
235 // Let the page contents record UMA actions. Only use when you can't do it from 227 // Let the page contents record UMA actions. Only use when you can't do it from
236 // C++. For example, we currently use it to let the NTP log the postion of the 228 // C++. For example, we currently use it to let the NTP log the postion of the
237 // Most Visited or Bookmark the user clicked on, as we don't get that 229 // Most Visited or Bookmark the user clicked on, as we don't get that
238 // information through RequestOpenURL. You will need to update the metrics 230 // information through RequestOpenURL. You will need to update the metrics
239 // dashboard with the action names you use, as our processor won't catch that 231 // dashboard with the action names you use, as our processor won't catch that
240 // information (treat it as RecordComputedMetrics) 232 // information (treat it as RecordComputedMetrics)
241 class MetricsHandler : public DOMMessageHandler { 233 class MetricsHandler : public DOMMessageHandler {
242 public: 234 public:
243 explicit MetricsHandler(DOMUIHost* dom_ui_host); 235 explicit MetricsHandler(DOMUI* dom_ui);
244 236
245 // Callback which records a user action. 237 // Callback which records a user action.
246 void HandleMetrics(const Value* content); 238 void HandleMetrics(const Value* content);
247 239
248 private: 240 private:
249 DOMUIHost* dom_ui_host_; 241 DOMUI* dom_ui_;
250 DISALLOW_EVIL_CONSTRUCTORS(MetricsHandler); 242 DISALLOW_EVIL_CONSTRUCTORS(MetricsHandler);
251 }; 243 };
252 244
253 // The TabContents used for the New Tab page. 245 // The TabContents used for the New Tab page.
254 class NewTabUIContents : public DOMUIHost { 246 class NewTabUI : public DOMUI {
255 public: 247 public:
256 NewTabUIContents(Profile* profile, 248 explicit NewTabUI(DOMUIContents* contents);
257 SiteInstance* instance, 249
258 RenderViewHostFactory* render_view_factory); 250 // Return the URL for the front page of this UI.
251 static GURL GetBaseURL();
252
253 // DOMUI Implementation
254 virtual void Init();
259 255
260 // Set the title that overrides any other title provided for the tab. 256 // Set the title that overrides any other title provided for the tab.
261 // This lets you set the title that's displayed before the content loads, 257 // This lets you set the title that's displayed before the content loads,
262 // as well as override any "Loading..." text. 258 // as well as override any "Loading..." text.
263 void set_forced_title(const std::wstring& title) { 259 void set_forced_title(const std::wstring& title) {
264 forced_title_ = title; 260 forced_title_ = title;
265 } 261 }
266 262
267 // DOMUIHost implementation. 263 // Overridden from DOMUI.
268 virtual void AttachMessageHandlers(); 264 // Favicon should not be displayed.
265 virtual bool ShouldDisplayFavIcon() { return false; }
266 // Bookmark bar should always be visible.
267 virtual bool IsBookmarkBarAlwaysVisible() { return true; }
268 // When NTP gets the initial focus, focus the URL bar.
269 virtual void SetInitialFocus();
270 // Should not display our URL.
271 virtual bool ShouldDisplayURL() { return false; }
272 // Control what happens when a link is clicked.
273 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
274 WindowOpenDisposition disposition);
269 275
270 // WebContents overrides.
271 // Overriden to force the title of the page to forced_title_.
272 virtual bool NavigateToPendingEntry(bool reload);
273 // We don't want a favicon on the new tab page.
274 virtual bool ShouldDisplayFavIcon() { return false; }
275 // The bookmark bar is always visible on the new tab.
276 virtual bool IsBookmarkBarAlwaysVisible() { return true; }
277 // Return forced_title_ if it's available.
278 virtual const std::wstring& GetTitle() const;
279 // When we get the initial focus, focus the URL bar.
280 virtual void SetInitialFocus();
281 // The URL bar should not display the current page's URL.
282 virtual bool ShouldDisplayURL() { return false; }
283 virtual bool SupportsURL(GURL* url);
284 // Clicking a URL on the page should count as an autobookmark click.
285 virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
286 WindowOpenDisposition disposition);
287 private: 276 private:
277 DOMUIContents* contents_;
278
288 // The message id that should be displayed in this NewTabUIContents 279 // The message id that should be displayed in this NewTabUIContents
289 // instance's motd area. 280 // instance's motd area.
290 int motd_message_id_; 281 int motd_message_id_;
291 282
292 // Whether the user is in incognito mode or not, used to determine 283 // Whether the user is in incognito mode or not, used to determine
293 // what HTML to load. 284 // what HTML to load.
294 bool incognito_; 285 bool incognito_;
295 286
296 // A title for the page we force display of. 287 // A title for the page we force display of.
297 // This prevents intermediate titles (like "Loading...") from displaying. 288 // This prevents intermediate titles (like "Loading...") from displaying.
298 std::wstring forced_title_; 289 std::wstring forced_title_;
299 290
300 // A pointer to the handler for most visited. 291 // A pointer to the handler for most visited.
301 // Owned by the DOMUIHost. 292 // Owned by the DOMUIHost.
302 MostVisitedHandler* most_visited_handler_; 293 MostVisitedHandler* most_visited_handler_;
303 294
304 DISALLOW_EVIL_CONSTRUCTORS(NewTabUIContents); 295 DISALLOW_EVIL_CONSTRUCTORS(NewTabUI);
305 }; 296 };
306 297
307 #endif // CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__ 298 #endif // CHROME_BROWSER_DOM_UI_NEW_TAB_UI_H__
308 299
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/history_ui.cc ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698