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

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

Issue 13183: Reupload of 12418 (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/sessions/session_types.h" 19 #include "chrome/browser/sessions/session_types.h"
19 #include "chrome/browser/template_url.h" 20 #include "chrome/browser/template_url.h"
20 #include "chrome/browser/user_data_manager.h" 21 #include "chrome/browser/user_data_manager.h"
21 #include "chrome/browser/user_metrics.h" 22 #include "chrome/browser/user_metrics.h"
22 #include "chrome/browser/views/keyword_editor_view.h" 23 #include "chrome/browser/views/keyword_editor_view.h"
23 #include "chrome/common/jstemplate_builder.h" 24 #include "chrome/common/jstemplate_builder.h"
24 #include "chrome/common/l10n_util.h" 25 #include "chrome/common/l10n_util.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/common/pref_service.h" 27 #include "chrome/common/pref_service.h"
27 #include "chrome/common/resource_bundle.h" 28 #include "chrome/common/resource_bundle.h"
28 29
29 #include "chromium_strings.h" 30 #include "chromium_strings.h"
30 #include "generated_resources.h" 31 #include "generated_resources.h"
31 32
32 using base::Time; 33 using base::Time;
33 using base::TimeDelta; 34 using base::TimeDelta;
34 using base::TimeTicks; 35 using base::TimeTicks;
35 36
36 // The URL scheme used for the new tab. 37 // The URL scheme used for the new tab.
37 static const char kNewTabUIScheme[] = "chrome-internal"; 38 static const char kNewTabUIScheme[] = "chrome-internal";
38 39
39 // The path used in internal URLs to thumbnail data.
40 static const char kThumbnailPath[] = "thumb";
41
42 // The path used in internal URLs to favicon data.
43 static const char kFavIconPath[] = "favicon";
44
45 // The number of most visited pages we show. 40 // The number of most visited pages we show.
46 const int kMostVisitedPages = 9; 41 const int kMostVisitedPages = 9;
47 42
48 // The number of days of history we consider for most visited entries. 43 // The number of days of history we consider for most visited entries.
49 const int kMostVisitedScope = 90; 44 const int kMostVisitedScope = 90;
50 45
51 // The number of recent bookmarks we show. 46 // The number of recent bookmarks we show.
52 static const int kRecentBookmarks = 9; 47 static const int kRecentBookmarks = 9;
53 48
54 // The number of search URLs to show. 49 // The number of search URLs to show.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 incognito_tab_html, &localized_strings, "t" /* template root node id */); 251 incognito_tab_html, &localized_strings, "t" /* template root node id */);
257 252
258 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 253 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
259 html_bytes->data.resize(full_html.size()); 254 html_bytes->data.resize(full_html.size());
260 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 255 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
261 256
262 SendResponse(request_id, html_bytes); 257 SendResponse(request_id, html_bytes);
263 } 258 }
264 259
265 /////////////////////////////////////////////////////////////////////////////// 260 ///////////////////////////////////////////////////////////////////////////////
266 // ThumbnailSource
267
268 ThumbnailSource::ThumbnailSource(Profile* profile)
269 : DataSource(kThumbnailPath, MessageLoop::current()), profile_(profile) {}
270
271 void ThumbnailSource::StartDataRequest(const std::string& path,
272 int request_id) {
273 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
274 if (hs) {
275 HistoryService::Handle handle = hs->GetPageThumbnail(
276 GURL(path),
277 &cancelable_consumer_,
278 NewCallback(this, &ThumbnailSource::OnThumbnailDataAvailable));
279 // Attach the ChromeURLDataManager request ID to the history request.
280 cancelable_consumer_.SetClientData(hs, handle, request_id);
281 } else {
282 // Tell the caller that no thumbnail is available.
283 SendResponse(request_id, NULL);
284 }
285 }
286
287 void ThumbnailSource::OnThumbnailDataAvailable(
288 HistoryService::Handle request_handle,
289 scoped_refptr<RefCountedBytes> data) {
290 HistoryService* hs =
291 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
292 int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
293 // Forward the data along to the networking system.
294 if (data.get() && !data->data.empty()) {
295 SendResponse(request_id, data);
296 } else {
297 if (!default_thumbnail_.get()) {
298 default_thumbnail_ = new RefCountedBytes;
299 ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
300 IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
301 }
302
303 SendResponse(request_id, default_thumbnail_);
304 }
305 }
306
307 ///////////////////////////////////////////////////////////////////////////////
308 // FavIconSource
309
310 FavIconSource::FavIconSource(Profile* profile)
311 : DataSource(kFavIconPath, MessageLoop::current()), profile_(profile) {}
312
313 void FavIconSource::StartDataRequest(const std::string& path, int request_id) {
314 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
315 if (hs) {
316 HistoryService::Handle handle;
317 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
318 handle = hs->GetFavIcon(
319 GURL(path.substr(8)),
320 &cancelable_consumer_,
321 NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
322 } else {
323 handle = hs->GetFavIconForURL(
324 GURL(path),
325 &cancelable_consumer_,
326 NewCallback(this, &FavIconSource::OnFavIconDataAvailable));
327 }
328 // Attach the ChromeURLDataManager request ID to the history request.
329 cancelable_consumer_.SetClientData(hs, handle, request_id);
330 } else {
331 SendResponse(request_id, NULL);
332 }
333 }
334
335 void FavIconSource::OnFavIconDataAvailable(
336 HistoryService::Handle request_handle,
337 bool know_favicon,
338 scoped_refptr<RefCountedBytes> data,
339 bool expired,
340 GURL icon_url) {
341 HistoryService* hs =
342 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
343 int request_id = cancelable_consumer_.GetClientData(hs, request_handle);
344
345 if (know_favicon && data.get() && !data->data.empty()) {
346 // Forward the data along to the networking system.
347 SendResponse(request_id, data);
348 } else {
349 if (!default_favicon_.get()) {
350 default_favicon_ = new RefCountedBytes;
351 ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
352 IDR_DEFAULT_FAVICON, &default_favicon_->data);
353 }
354
355 SendResponse(request_id, default_favicon_);
356 }
357 }
358
359
360 ///////////////////////////////////////////////////////////////////////////////
361 // MostVisitedHandler 261 // MostVisitedHandler
362 262
363 MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host) 263 MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host)
364 : dom_ui_host_(dom_ui_host) { 264 : dom_ui_host_(dom_ui_host) {
365 // Register ourselves as the handler for the "mostvisited" message from 265 // Register ourselves as the handler for the "mostvisited" message from
366 // Javascript. 266 // Javascript.
367 dom_ui_host_->RegisterMessageCallback("getMostVisited", 267 dom_ui_host_->RegisterMessageCallback("getMostVisited",
368 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); 268 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited));
369 269
370 // Set up our sources for thumbnail and favicon data. 270 // Set up our sources for thumbnail and favicon data.
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 // NewTabUIContents 740 // NewTabUIContents
841 741
842 // This is the top-level URL handler for chrome-internal: URLs, and exposed in 742 // This is the top-level URL handler for chrome-internal: URLs, and exposed in
843 // our header file. 743 // our header file.
844 bool NewTabUIHandleURL(GURL* url, 744 bool NewTabUIHandleURL(GURL* url,
845 TabContentsType* result_type) { 745 TabContentsType* result_type) {
846 if (!url->SchemeIs(kNewTabUIScheme)) 746 if (!url->SchemeIs(kNewTabUIScheme))
847 return false; 747 return false;
848 748
849 *result_type = TAB_CONTENTS_NEW_TAB_UI; 749 *result_type = TAB_CONTENTS_NEW_TAB_UI;
850 *url = GURL("chrome-resource://new-tab/"); 750 *url = GURL(DOMUIContents::GetScheme() + "://new-tab/");
851 751
852 return true; 752 return true;
853 } 753 }
854 754
855 GURL NewTabUIURL() { 755 GURL NewTabUIURL() {
856 std::string url(kNewTabUIScheme); 756 std::string url(kNewTabUIScheme);
857 url += ":"; 757 url += ":";
858 return GURL(url); 758 return GURL(url);
859 } 759 }
860 760
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 void NewTabUIContents::RequestOpenURL(const GURL& url, 863 void NewTabUIContents::RequestOpenURL(const GURL& url,
964 const GURL& /*referrer*/, 864 const GURL& /*referrer*/,
965 WindowOpenDisposition disposition) { 865 WindowOpenDisposition disposition) {
966 // The user opened a URL on the page (including "open in new window"). 866 // The user opened a URL on the page (including "open in new window").
967 // We count all such clicks as AUTO_BOOKMARK, which increments the site's 867 // We count all such clicks as AUTO_BOOKMARK, which increments the site's
968 // visit count (which is used for ranking the most visited entries). 868 // visit count (which is used for ranking the most visited entries).
969 // Note this means we're including clicks on not only most visited thumbnails, 869 // Note this means we're including clicks on not only most visited thumbnails,
970 // but also clicks on recently bookmarked. 870 // but also clicks on recently bookmarked.
971 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK); 871 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK);
972 } 872 }
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