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

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

Issue 12418: Implement History as HTML and add/change a bunch of stuff to make it easier t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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/new_tab_ui.h ('k') | chrome/browser/history/history.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 #include "chrome/browser/dom_ui/new_tab_ui.h" 5 #include "chrome/browser/dom_ui/new_tab_ui.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "chrome/app/locales/locale_settings.h" 9 #include "chrome/app/locales/locale_settings.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_resources.h" 12 #include "chrome/browser/browser_resources.h"
13 #include "chrome/browser/dom_ui/dom_ui_contents.h"
13 #include "chrome/browser/history_tab_ui.h" 14 #include "chrome/browser/history_tab_ui.h"
14 #include "chrome/browser/history/page_usage_data.h" 15 #include "chrome/browser/history/page_usage_data.h"
15 #include "chrome/browser/navigation_entry.h" 16 #include "chrome/browser/navigation_entry.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/browser/render_view_host.h" 18 #include "chrome/browser/render_view_host.h"
18 #include "chrome/browser/template_url.h" 19 #include "chrome/browser/template_url.h"
19 #include "chrome/browser/user_metrics.h" 20 #include "chrome/browser/user_metrics.h"
20 #include "chrome/browser/views/keyword_editor_view.h" 21 #include "chrome/browser/views/keyword_editor_view.h"
21 #include "chrome/common/jstemplate_builder.h" 22 #include "chrome/common/jstemplate_builder.h"
22 #include "chrome/common/l10n_util.h" 23 #include "chrome/common/l10n_util.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/common/pref_service.h" 25 #include "chrome/common/pref_service.h"
25 #include "chrome/common/resource_bundle.h" 26 #include "chrome/common/resource_bundle.h"
26 27
27 #include "chromium_strings.h" 28 #include "chromium_strings.h"
28 #include "generated_resources.h" 29 #include "generated_resources.h"
29 30
30 using base::Time; 31 using base::Time;
31 using base::TimeDelta; 32 using base::TimeDelta;
32 using base::TimeTicks; 33 using base::TimeTicks;
33 34
34 // The URL scheme used for the new tab. 35 // The URL scheme used for the new tab.
35 static const char kNewTabUIScheme[] = "chrome-internal"; 36 static const char kNewTabUIScheme[] = "chrome-internal";
36 37
37 // The path used in internal URLs to thumbnail data.
38 static const char kThumbnailPath[] = "thumb";
39
40 // The path used in internal URLs to favicon data.
41 static const char kFavIconPath[] = "favicon";
42
43 // The number of most visited pages we show. 38 // The number of most visited pages we show.
44 const int kMostVisitedPages = 9; 39 const int kMostVisitedPages = 9;
45 40
46 // The number of days of history we consider for most visited entries. 41 // The number of days of history we consider for most visited entries.
47 const int kMostVisitedScope = 90; 42 const int kMostVisitedScope = 90;
48 43
49 // The number of recent bookmarks we show. 44 // The number of recent bookmarks we show.
50 static const int kRecentBookmarks = 9; 45 static const int kRecentBookmarks = 9;
51 46
52 // The number of search URLs to show. 47 // The number of search URLs to show.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 incognito_tab_html, &localized_strings, "t" /* template root node id */); 233 incognito_tab_html, &localized_strings, "t" /* template root node id */);
239 234
240 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 235 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
241 html_bytes->data.resize(full_html.size()); 236 html_bytes->data.resize(full_html.size());
242 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 237 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
243 238
244 SendResponse(request_id, html_bytes); 239 SendResponse(request_id, html_bytes);
245 } 240 }
246 241
247 /////////////////////////////////////////////////////////////////////////////// 242 ///////////////////////////////////////////////////////////////////////////////
248 // ThumbnailSource
249
250 ThumbnailSource::ThumbnailSource(Profile* profile)
251 : DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {}
252
253 void ThumbnailSource::StartDataRequest(const std::string& path,
254 int request_id) {
255 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
256 if (hs) {
257 HistoryService::Handle handle = hs->GetPageThumbnail(
258 GURL(path),
259 &cancelable_consumer_,
260 NewCallback(this, &ThumbnailSource::OnThumbnailDataAvailable));
261 // Attach the ChromeURLDataManager request ID to the history request.
262 cancelable_consumer_.SetClientData(hs, handle, request_id);
263 } else {
264 // Tell the caller that no thumbnail is available.
265 SendResponse(request_id, NULL);
266 }
267 }
268
269 void ThumbnailSource::OnThumbnailDataAvailable(
270 HistoryService::Handle request_handle,
271 scoped_refptr<RefCountedBytes> data) {
272 HistoryService* hs =
273 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
274 int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
275 // Forward the data along to the networking system.
276 if (data.get() && !data->data.empty()) {
277 SendResponse(request_id, data);
278 } else {
279 if (!default_thumbnail_.get()) {
280 default_thumbnail_ = new RefCountedBytes;
281 ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
282 IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
283 }
284
285 SendResponse(request_id, default_thumbnail_);
286 }
287 }
288
289 ///////////////////////////////////////////////////////////////////////////////
290 // FavIconSource
291
292 FavIconSource::FavIconSource(Profile* profile)
293 : DataSource(kFavIconPath, MessageLoop::current()), profile_(profile) {}
294
295 void FavIconSource::StartDataRequest(const std::string& path, int request_id) {
296 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
297 if (hs) {
298 HistoryService::Handle handle;
299 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
300 handle = hs->GetFavIcon(
301 GURL(path.substr(8)),
302 &cancelable_consumer_,
303 NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
304 } else {
305 handle = hs->GetFavIconForURL(
306 GURL(path),
307 &cancelable_consumer_,
308 NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
309 }
310 // Attach the ChromeURLDataManager request ID to the history request.
311 cancelable_consumer_.SetClientData(hs, handle, request_id);
312 } else {
313 SendResponse(request_id, NULL);
314 }
315 }
316
317 void FavIconSource::OnFavIconDataAvailable(
318 HistoryService::Handle request_handle,
319 bool know_favicon,
320 scoped_refptr<RefCountedBytes> data,
321 bool expired,
322 GURL icon_url) {
323 HistoryService* hs =
324 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
325 int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
326
327 if (know_favicon && data.get() && !data->data.empty()) {
328 // Forward the data along to the networking system.
329 SendResponse(request_id, data);
330 } else {
331 if (!default_favicon_.get()) {
332 default_favicon_ = new RefCountedBytes;
333 ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
334 IDR_DEFAULT_FAVICON, &default_favicon_->data);
335 }
336
337 SendResponse(request_id, default_favicon_);
338 }
339 }
340
341
342 ///////////////////////////////////////////////////////////////////////////////
343 // MostVisitedHandler 243 // MostVisitedHandler
344 244
345 MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host) 245 MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host)
346 : dom_ui_host_(dom_ui_host) { 246 : dom_ui_host_(dom_ui_host) {
347 // Register ourselves as the handler for the "mostvisited" message from 247 // Register ourselves as the handler for the "mostvisited" message from
348 // Javascript. 248 // Javascript.
349 dom_ui_host_->RegisterMessageCallback("getMostVisited", 249 dom_ui_host_->RegisterMessageCallback("getMostVisited",
350 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); 250 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited));
351 251
352 // Set up our sources for thumbnail and favicon data. 252 // Set up our sources for thumbnail and favicon data.
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // NewTabUIContents 716 // NewTabUIContents
817 717
818 // This is the top-level URL handler for chrome-internal: URLs, and exposed in 718 // This is the top-level URL handler for chrome-internal: URLs, and exposed in
819 // our header file. 719 // our header file.
820 bool NewTabUIHandleURL(GURL* url, 720 bool NewTabUIHandleURL(GURL* url,
821 TabContentsType* result_type) { 721 TabContentsType* result_type) {
822 if (!url->SchemeIs(kNewTabUIScheme)) 722 if (!url->SchemeIs(kNewTabUIScheme))
823 return false; 723 return false;
824 724
825 *result_type = TAB_CONTENTS_NEW_TAB_UI; 725 *result_type = TAB_CONTENTS_NEW_TAB_UI;
826 *url = GURL("chrome-resource://new-tab/"); 726 *url = GURL(DOMUIContents::GetScheme() + "://new-tab/");
827 727
828 return true; 728 return true;
829 } 729 }
830 730
831 GURL NewTabUIURL() { 731 GURL NewTabUIURL() {
832 std::string url(kNewTabUIScheme); 732 std::string url(kNewTabUIScheme);
833 url += ":"; 733 url += ":";
834 return GURL(url); 734 return GURL(url);
835 } 735 }
836 736
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 void NewTabUIContents::RequestOpenURL(const GURL& url, 829 void NewTabUIContents::RequestOpenURL(const GURL& url,
930 const GURL& /*referrer*/, 830 const GURL& /*referrer*/,
931 WindowOpenDisposition disposition) { 831 WindowOpenDisposition disposition) {
932 // The user opened a URL on the page (including "open in new window"). 832 // The user opened a URL on the page (including "open in new window").
933 // We count all such clicks as AUTO_BOOKMARK, which increments the site's 833 // We count all such clicks as AUTO_BOOKMARK, which increments the site's
934 // visit count (which is used for ranking the most visited entries). 834 // visit count (which is used for ranking the most visited entries).
935 // Note this means we're including clicks on not only most visited thumbnails, 835 // Note this means we're including clicks on not only most visited thumbnails,
936 // but also clicks on recently bookmarked. 836 // but also clicks on recently bookmarked.
937 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK); 837 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK);
938 } 838 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/new_tab_ui.h ('k') | chrome/browser/history/history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698