| OLD | NEW |
| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/dom_ui/new_tab_ui.h" | 7 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 8 | 8 |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/dom_ui/dom_ui_contents.h" | 14 #include "chrome/browser/dom_ui/dom_ui_contents.h" |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 // TODO(port): include this once history is converted to HTML | 16 // TODO(port): include this once history is converted to HTML |
| 17 #include "chrome/browser/history_tab_ui.h" | 17 #include "chrome/browser/dom_ui/history_ui.h" |
| 18 #endif | 18 #endif |
| 19 #include "chrome/browser/history/page_usage_data.h" | 19 #include "chrome/browser/history/page_usage_data.h" |
| 20 #include "chrome/browser/metrics/user_metrics.h" | 20 #include "chrome/browser/metrics/user_metrics.h" |
| 21 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 22 #include "chrome/browser/renderer_host/render_view_host.h" | 22 #include "chrome/browser/renderer_host/render_view_host.h" |
| 23 #include "chrome/browser/sessions/session_types.h" | 23 #include "chrome/browser/sessions/session_types.h" |
| 24 #include "chrome/browser/tab_contents/navigation_entry.h" | 24 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 25 #include "chrome/browser/search_engines/template_url.h" | 25 #include "chrome/browser/search_engines/template_url.h" |
| 26 #include "chrome/browser/user_data_manager.h" | 26 #include "chrome/browser/user_data_manager.h" |
| 27 #include "chrome/common/jstemplate_builder.h" | 27 #include "chrome/common/jstemplate_builder.h" |
| 28 #include "chrome/common/l10n_util.h" | 28 #include "chrome/common/l10n_util.h" |
| 29 #include "chrome/common/notification_service.h" | 29 #include "chrome/common/notification_service.h" |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/pref_service.h" | 31 #include "chrome/common/pref_service.h" |
| 32 #include "chrome/common/resource_bundle.h" | 32 #include "chrome/common/resource_bundle.h" |
| 33 #ifdef CHROME_PERSONALIZATION | 33 #ifdef CHROME_PERSONALIZATION |
| 34 #include "chrome/personalization/personalization.h" | 34 #include "chrome/personalization/personalization.h" |
| 35 #endif | 35 #endif |
| 36 #include "grit/browser_resources.h" | 36 #include "grit/browser_resources.h" |
| 37 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
| 38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 39 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
| 40 | 40 |
| 41 // The URL scheme used for the new tab. | 41 // NewTabUI is accessible from chrome-ui://newtab. |
| 42 static const char kNewTabUIScheme[] = "chrome-internal"; | 42 static const char kNewTabHost[] = "newtab"; |
| 43 | 43 |
| 44 // The number of most visited pages we show. | 44 // The number of most visited pages we show. |
| 45 const int kMostVisitedPages = 9; | 45 const int kMostVisitedPages = 9; |
| 46 | 46 |
| 47 // The number of days of history we consider for most visited entries. | 47 // The number of days of history we consider for most visited entries. |
| 48 const int kMostVisitedScope = 90; | 48 const int kMostVisitedScope = 90; |
| 49 | 49 |
| 50 // The number of recent bookmarks we show. | 50 // The number of recent bookmarks we show. |
| 51 static const int kRecentBookmarks = 9; | 51 static const int kRecentBookmarks = 9; |
| 52 | 52 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 dictionary->SetString(L"title", title_to_set); | 170 dictionary->SetString(L"title", title_to_set); |
| 171 dictionary->SetString(L"direction", direction); | 171 dictionary->SetString(L"direction", direction); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // end anonymous namespace | 174 } // end anonymous namespace |
| 175 | 175 |
| 176 /////////////////////////////////////////////////////////////////////////////// | 176 /////////////////////////////////////////////////////////////////////////////// |
| 177 // NewTabHTMLSource | 177 // NewTabHTMLSource |
| 178 | 178 |
| 179 NewTabHTMLSource::NewTabHTMLSource() | 179 NewTabHTMLSource::NewTabHTMLSource() |
| 180 : DataSource("new-tab", MessageLoop::current()) { | 180 : DataSource(kNewTabHost, MessageLoop::current()) { |
| 181 } | 181 } |
| 182 | 182 |
| 183 void NewTabHTMLSource::StartDataRequest(const std::string& path, | 183 void NewTabHTMLSource::StartDataRequest(const std::string& path, |
| 184 int request_id) { | 184 int request_id) { |
| 185 if (!path.empty()) { | 185 if (!path.empty()) { |
| 186 // A path under new-tab was requested; it's likely a bad relative | 186 // A path under new-tab was requested; it's likely a bad relative |
| 187 // URL from the new tab page, but in any case it's an error. | 187 // URL from the new tab page, but in any case it's an error. |
| 188 NOTREACHED(); | 188 NOTREACHED(); |
| 189 return; | 189 return; |
| 190 } | 190 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 282 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 283 html_bytes->data.resize(full_html.size()); | 283 html_bytes->data.resize(full_html.size()); |
| 284 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 284 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 285 | 285 |
| 286 SendResponse(request_id, html_bytes); | 286 SendResponse(request_id, html_bytes); |
| 287 } | 287 } |
| 288 | 288 |
| 289 /////////////////////////////////////////////////////////////////////////////// | 289 /////////////////////////////////////////////////////////////////////////////// |
| 290 // MostVisitedHandler | 290 // MostVisitedHandler |
| 291 | 291 |
| 292 MostVisitedHandler::MostVisitedHandler(DOMUIHost* dom_ui_host) | 292 MostVisitedHandler::MostVisitedHandler(DOMUI* dom_ui) |
| 293 : dom_ui_host_(dom_ui_host) { | 293 : DOMMessageHandler(dom_ui), |
| 294 dom_ui_(dom_ui) { |
| 294 // Register ourselves as the handler for the "mostvisited" message from | 295 // Register ourselves as the handler for the "mostvisited" message from |
| 295 // Javascript. | 296 // Javascript. |
| 296 dom_ui_host_->RegisterMessageCallback("getMostVisited", | 297 dom_ui_->RegisterMessageCallback("getMostVisited", |
| 297 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); | 298 NewCallback(this, &MostVisitedHandler::HandleGetMostVisited)); |
| 298 | 299 |
| 299 // Set up our sources for thumbnail and favicon data. | 300 // Set up our sources for thumbnail and favicon data. |
| 300 // Ownership is passed to the ChromeURLDataManager. | 301 // Ownership is passed to the ChromeURLDataManager. |
| 301 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 302 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 302 NewRunnableMethod(&chrome_url_data_manager, | 303 NewRunnableMethod(&chrome_url_data_manager, |
| 303 &ChromeURLDataManager::AddDataSource, | 304 &ChromeURLDataManager::AddDataSource, |
| 304 new ThumbnailSource(dom_ui_host->profile()))); | 305 new ThumbnailSource(dom_ui->get_profile()))); |
| 305 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 306 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 306 NewRunnableMethod(&chrome_url_data_manager, | 307 NewRunnableMethod(&chrome_url_data_manager, |
| 307 &ChromeURLDataManager::AddDataSource, | 308 &ChromeURLDataManager::AddDataSource, |
| 308 new FavIconSource(dom_ui_host->profile()))); | 309 new FavIconSource(dom_ui->get_profile()))); |
| 309 | 310 |
| 310 // Get notifications when history is cleared. | 311 // Get notifications when history is cleared. |
| 311 NotificationService* service = NotificationService::current(); | 312 NotificationService* service = NotificationService::current(); |
| 312 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, | 313 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, |
| 313 Source<Profile>(dom_ui_host_->profile())); | 314 Source<Profile>(dom_ui_->get_profile())); |
| 314 } | 315 } |
| 315 | 316 |
| 316 MostVisitedHandler::~MostVisitedHandler() { | 317 MostVisitedHandler::~MostVisitedHandler() { |
| 317 NotificationService* service = NotificationService::current(); | 318 NotificationService* service = NotificationService::current(); |
| 318 service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED, | 319 service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED, |
| 319 Source<Profile>(dom_ui_host_->profile())); | 320 Source<Profile>(dom_ui_->get_profile())); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void MostVisitedHandler::HandleGetMostVisited(const Value* value) { | 323 void MostVisitedHandler::HandleGetMostVisited(const Value* value) { |
| 323 HistoryService* hs = | 324 HistoryService* hs = |
| 324 dom_ui_host_->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 325 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 325 hs->QuerySegmentUsageSince( | 326 hs->QuerySegmentUsageSince( |
| 326 &cancelable_consumer_, | 327 &cancelable_consumer_, |
| 327 base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope), | 328 base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope), |
| 328 NewCallback(this, &MostVisitedHandler::OnSegmentUsageAvailable)); | 329 NewCallback(this, &MostVisitedHandler::OnSegmentUsageAvailable)); |
| 329 } | 330 } |
| 330 | 331 |
| 331 void MostVisitedHandler::OnSegmentUsageAvailable( | 332 void MostVisitedHandler::OnSegmentUsageAvailable( |
| 332 CancelableRequestProvider::Handle handle, | 333 CancelableRequestProvider::Handle handle, |
| 333 std::vector<PageUsageData*>* data) { | 334 std::vector<PageUsageData*>* data) { |
| 334 most_visited_urls_.clear(); | 335 most_visited_urls_.clear(); |
| 335 | 336 |
| 336 ListValue pages_value; | 337 ListValue pages_value; |
| 337 const size_t count = std::min<size_t>(kMostVisitedPages, data->size()); | 338 const size_t count = std::min<size_t>(kMostVisitedPages, data->size()); |
| 338 for (size_t i = 0; i < count; ++i) { | 339 for (size_t i = 0; i < count; ++i) { |
| 339 const PageUsageData& page = *(*data)[i]; | 340 const PageUsageData& page = *(*data)[i]; |
| 340 DictionaryValue* page_value = new DictionaryValue; | 341 DictionaryValue* page_value = new DictionaryValue; |
| 341 SetURLTitleAndDirection(page_value, page.GetTitle(), page.GetURL()); | 342 SetURLTitleAndDirection(page_value, page.GetTitle(), page.GetURL()); |
| 342 pages_value.Append(page_value); | 343 pages_value.Append(page_value); |
| 343 most_visited_urls_.push_back(page.GetURL()); | 344 most_visited_urls_.push_back(page.GetURL()); |
| 344 } | 345 } |
| 345 dom_ui_host_->CallJavascriptFunction(L"mostVisitedPages", pages_value); | 346 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", pages_value); |
| 346 } | 347 } |
| 347 | 348 |
| 348 void MostVisitedHandler::Observe(NotificationType type, | 349 void MostVisitedHandler::Observe(NotificationType type, |
| 349 const NotificationSource& source, | 350 const NotificationSource& source, |
| 350 const NotificationDetails& details) { | 351 const NotificationDetails& details) { |
| 351 if (type != NotificationType::HISTORY_URLS_DELETED) { | 352 if (type != NotificationType::HISTORY_URLS_DELETED) { |
| 352 NOTREACHED(); | 353 NOTREACHED(); |
| 353 return; | 354 return; |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Some URLs were deleted from history. Reload the most visited list. | 357 // Some URLs were deleted from history. Reload the most visited list. |
| 357 HandleGetMostVisited(NULL); | 358 HandleGetMostVisited(NULL); |
| 358 } | 359 } |
| 359 | 360 |
| 360 /////////////////////////////////////////////////////////////////////////////// | 361 /////////////////////////////////////////////////////////////////////////////// |
| 361 // TemplateURLHandler | 362 // TemplateURLHandler |
| 362 | 363 |
| 363 TemplateURLHandler::TemplateURLHandler(DOMUIHost* dom_ui_host) | 364 TemplateURLHandler::TemplateURLHandler(DOMUI* dom_ui) |
| 364 : dom_ui_host_(dom_ui_host), template_url_model_(NULL) { | 365 : DOMMessageHandler(dom_ui), |
| 365 dom_ui_host->RegisterMessageCallback("getMostSearched", | 366 dom_ui_(dom_ui), |
| 367 template_url_model_(NULL) { |
| 368 dom_ui->RegisterMessageCallback("getMostSearched", |
| 366 NewCallback(this, &TemplateURLHandler::HandleGetMostSearched)); | 369 NewCallback(this, &TemplateURLHandler::HandleGetMostSearched)); |
| 367 dom_ui_host->RegisterMessageCallback("doSearch", | 370 dom_ui->RegisterMessageCallback("doSearch", |
| 368 NewCallback(this, &TemplateURLHandler::HandleDoSearch)); | 371 NewCallback(this, &TemplateURLHandler::HandleDoSearch)); |
| 369 } | 372 } |
| 370 | 373 |
| 371 TemplateURLHandler::~TemplateURLHandler() { | 374 TemplateURLHandler::~TemplateURLHandler() { |
| 372 if (template_url_model_) | 375 if (template_url_model_) |
| 373 template_url_model_->RemoveObserver(this); | 376 template_url_model_->RemoveObserver(this); |
| 374 } | 377 } |
| 375 | 378 |
| 376 void TemplateURLHandler::HandleGetMostSearched(const Value* content) { | 379 void TemplateURLHandler::HandleGetMostSearched(const Value* content) { |
| 377 // The page Javascript has requested the list of keyword searches. | 380 // The page Javascript has requested the list of keyword searches. |
| 378 // Start loading them from the template URL backend. | 381 // Start loading them from the template URL backend. |
| 379 if (!template_url_model_) { | 382 if (!template_url_model_) { |
| 380 template_url_model_ = dom_ui_host_->profile()->GetTemplateURLModel(); | 383 template_url_model_ = dom_ui_->get_profile()->GetTemplateURLModel(); |
| 381 template_url_model_->AddObserver(this); | 384 template_url_model_->AddObserver(this); |
| 382 } | 385 } |
| 383 if (template_url_model_->loaded()) { | 386 if (template_url_model_->loaded()) { |
| 384 OnTemplateURLModelChanged(); | 387 OnTemplateURLModelChanged(); |
| 385 } else { | 388 } else { |
| 386 template_url_model_->Load(); | 389 template_url_model_->Load(); |
| 387 } | 390 } |
| 388 } | 391 } |
| 389 | 392 |
| 390 // A helper function for sorting TemplateURLs where the most used ones show up | 393 // A helper function for sorting TemplateURLs where the most used ones show up |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 const TemplateURLRef* url_ref = template_url->url(); | 430 const TemplateURLRef* url_ref = template_url->url(); |
| 428 if (!url_ref || !url_ref->SupportsReplacement()) { | 431 if (!url_ref || !url_ref->SupportsReplacement()) { |
| 429 NOTREACHED(); | 432 NOTREACHED(); |
| 430 return; | 433 return; |
| 431 } | 434 } |
| 432 GURL url = url_ref->ReplaceSearchTerms(*template_url, search, | 435 GURL url = url_ref->ReplaceSearchTerms(*template_url, search, |
| 433 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); | 436 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); |
| 434 | 437 |
| 435 if (url.is_valid()) { | 438 if (url.is_valid()) { |
| 436 // Load the URL. | 439 // Load the URL. |
| 437 dom_ui_host_->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK); | 440 dom_ui_->get_contents()->OpenURL(url, GURL(), CURRENT_TAB, |
| 441 PageTransition::LINK); |
| 438 | 442 |
| 439 // Record the user action | 443 // Record the user action |
| 440 std::vector<const TemplateURL*> urls = | 444 std::vector<const TemplateURL*> urls = |
| 441 template_url_model_->GetTemplateURLs(); | 445 template_url_model_->GetTemplateURLs(); |
| 442 sort(urls.begin(), urls.end(), TemplateURLSortByUsage); | 446 sort(urls.begin(), urls.end(), TemplateURLSortByUsage); |
| 443 ListValue urls_value; | 447 ListValue urls_value; |
| 444 int item_number = 0; | 448 int item_number = 0; |
| 445 for (size_t i = 0; | 449 for (size_t i = 0; |
| 446 i < std::min<size_t>(urls.size(), kSearchURLs); ++i) { | 450 i < std::min<size_t>(urls.size(), kSearchURLs); ++i) { |
| 447 if (urls[i]->usage_count() == 0) | 451 if (urls[i]->usage_count() == 0) |
| 448 break; // The remainder would be no good. | 452 break; // The remainder would be no good. |
| 449 | 453 |
| 450 const TemplateURLRef* urlref = urls[i]->url(); | 454 const TemplateURLRef* urlref = urls[i]->url(); |
| 451 if (!urlref) | 455 if (!urlref) |
| 452 continue; | 456 continue; |
| 453 | 457 |
| 454 if (urls[i] == template_url) { | 458 if (urls[i] == template_url) { |
| 455 UserMetrics::RecordComputedAction( | 459 UserMetrics::RecordComputedAction( |
| 456 StringPrintf(L"NTP_SearchURL%d", item_number), | 460 StringPrintf(L"NTP_SearchURL%d", item_number), |
| 457 dom_ui_host_->profile()); | 461 dom_ui_->get_profile()); |
| 458 break; | 462 break; |
| 459 } | 463 } |
| 460 | 464 |
| 461 item_number++; | 465 item_number++; |
| 462 } | 466 } |
| 463 } | 467 } |
| 464 } | 468 } |
| 465 | 469 |
| 466 void TemplateURLHandler::OnTemplateURLModelChanged() { | 470 void TemplateURLHandler::OnTemplateURLModelChanged() { |
| 467 // We've loaded some template URLs. Send them to the page. | 471 // We've loaded some template URLs. Send them to the page. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 479 entry_value->SetString(L"short_name", urls[i]->short_name()); | 483 entry_value->SetString(L"short_name", urls[i]->short_name()); |
| 480 entry_value->SetString(L"keyword", urls[i]->keyword()); | 484 entry_value->SetString(L"keyword", urls[i]->keyword()); |
| 481 | 485 |
| 482 const GURL& url = urls[i]->GetFavIconURL(); | 486 const GURL& url = urls[i]->GetFavIconURL(); |
| 483 if (url.is_valid()) | 487 if (url.is_valid()) |
| 484 entry_value->SetString(L"favIconURL", UTF8ToWide(url.spec())); | 488 entry_value->SetString(L"favIconURL", UTF8ToWide(url.spec())); |
| 485 | 489 |
| 486 urls_value.Append(entry_value); | 490 urls_value.Append(entry_value); |
| 487 } | 491 } |
| 488 UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize()); | 492 UMA_HISTOGRAM_COUNTS("NewTabPage.SearchURLs.Total", urls_value.GetSize()); |
| 489 dom_ui_host_->CallJavascriptFunction(L"searchURLs", urls_value); | 493 dom_ui_->CallJavascriptFunction(L"searchURLs", urls_value); |
| 490 } | 494 } |
| 491 | 495 |
| 492 /////////////////////////////////////////////////////////////////////////////// | 496 /////////////////////////////////////////////////////////////////////////////// |
| 493 // RecentlyBookmarkedHandler | 497 // RecentlyBookmarkedHandler |
| 494 | 498 |
| 495 RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host) | 499 RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUI* dom_ui) |
| 496 : dom_ui_host_(dom_ui_host), | 500 : DOMMessageHandler(dom_ui), |
| 501 dom_ui_(dom_ui), |
| 497 model_(NULL) { | 502 model_(NULL) { |
| 498 dom_ui_host->RegisterMessageCallback("getRecentlyBookmarked", | 503 dom_ui->RegisterMessageCallback("getRecentlyBookmarked", |
| 499 NewCallback(this, | 504 NewCallback(this, |
| 500 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); | 505 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); |
| 501 } | 506 } |
| 502 | 507 |
| 503 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { | 508 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { |
| 504 if (model_) | 509 if (model_) |
| 505 model_->RemoveObserver(this); | 510 model_->RemoveObserver(this); |
| 506 } | 511 } |
| 507 | 512 |
| 508 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { | 513 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { |
| 509 if (!model_) { | 514 if (!model_) { |
| 510 model_ = dom_ui_host_->profile()->GetBookmarkModel(); | 515 model_ = dom_ui_->get_profile()->GetBookmarkModel(); |
| 511 model_->AddObserver(this); | 516 model_->AddObserver(this); |
| 512 } | 517 } |
| 513 // If the model is loaded, synchronously send the bookmarks down. Otherwise | 518 // If the model is loaded, synchronously send the bookmarks down. Otherwise |
| 514 // when the model loads we'll send the bookmarks down. | 519 // when the model loads we'll send the bookmarks down. |
| 515 if (model_->IsLoaded()) | 520 if (model_->IsLoaded()) |
| 516 SendBookmarksToPage(); | 521 SendBookmarksToPage(); |
| 517 } | 522 } |
| 518 | 523 |
| 519 void RecentlyBookmarkedHandler::SendBookmarksToPage() { | 524 void RecentlyBookmarkedHandler::SendBookmarksToPage() { |
| 520 std::vector<BookmarkNode*> recently_bookmarked; | 525 std::vector<BookmarkNode*> recently_bookmarked; |
| 521 bookmark_utils::GetMostRecentlyAddedEntries( | 526 bookmark_utils::GetMostRecentlyAddedEntries( |
| 522 model_, kRecentBookmarks, &recently_bookmarked); | 527 model_, kRecentBookmarks, &recently_bookmarked); |
| 523 ListValue list_value; | 528 ListValue list_value; |
| 524 for (size_t i = 0; i < recently_bookmarked.size(); ++i) { | 529 for (size_t i = 0; i < recently_bookmarked.size(); ++i) { |
| 525 BookmarkNode* node = recently_bookmarked[i]; | 530 BookmarkNode* node = recently_bookmarked[i]; |
| 526 DictionaryValue* entry_value = new DictionaryValue; | 531 DictionaryValue* entry_value = new DictionaryValue; |
| 527 SetURLTitleAndDirection(entry_value, node->GetTitle(), node->GetURL()); | 532 SetURLTitleAndDirection(entry_value, node->GetTitle(), node->GetURL()); |
| 528 list_value.Append(entry_value); | 533 list_value.Append(entry_value); |
| 529 } | 534 } |
| 530 dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value); | 535 dom_ui_->CallJavascriptFunction(L"recentlyBookmarked", list_value); |
| 531 } | 536 } |
| 532 | 537 |
| 533 void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) { | 538 void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) { |
| 534 SendBookmarksToPage(); | 539 SendBookmarksToPage(); |
| 535 } | 540 } |
| 536 | 541 |
| 537 void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model, | 542 void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model, |
| 538 BookmarkNode* parent, | 543 BookmarkNode* parent, |
| 539 int index) { | 544 int index) { |
| 540 SendBookmarksToPage(); | 545 SendBookmarksToPage(); |
| 541 } | 546 } |
| 542 | 547 |
| 543 void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model, | 548 void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model, |
| 544 BookmarkNode* parent, | 549 BookmarkNode* parent, |
| 545 int index) { | 550 int index) { |
| 546 SendBookmarksToPage(); | 551 SendBookmarksToPage(); |
| 547 } | 552 } |
| 548 | 553 |
| 549 void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model, | 554 void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model, |
| 550 BookmarkNode* node) { | 555 BookmarkNode* node) { |
| 551 SendBookmarksToPage(); | 556 SendBookmarksToPage(); |
| 552 } | 557 } |
| 553 | 558 |
| 554 /////////////////////////////////////////////////////////////////////////////// | 559 /////////////////////////////////////////////////////////////////////////////// |
| 555 // RecentlyClosedTabsHandler | 560 // RecentlyClosedTabsHandler |
| 556 | 561 |
| 557 RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host) | 562 RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUI* dom_ui) |
| 558 : dom_ui_host_(dom_ui_host), | 563 : DOMMessageHandler(dom_ui), |
| 564 dom_ui_(dom_ui), |
| 559 tab_restore_service_(NULL) { | 565 tab_restore_service_(NULL) { |
| 560 dom_ui_host->RegisterMessageCallback("getRecentlyClosedTabs", | 566 dom_ui->RegisterMessageCallback("getRecentlyClosedTabs", |
| 561 NewCallback(this, | 567 NewCallback(this, |
| 562 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); | 568 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); |
| 563 dom_ui_host->RegisterMessageCallback("reopenTab", | 569 dom_ui->RegisterMessageCallback("reopenTab", |
| 564 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab)); | 570 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab)); |
| 565 } | 571 } |
| 566 | 572 |
| 567 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { | 573 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { |
| 568 if (tab_restore_service_) | 574 if (tab_restore_service_) |
| 569 tab_restore_service_->RemoveObserver(this); | 575 tab_restore_service_->RemoveObserver(this); |
| 570 } | 576 } |
| 571 | 577 |
| 572 void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) { | 578 void RecentlyClosedTabsHandler::HandleReopenTab(const Value* content) { |
| 573 NavigationController* controller = dom_ui_host_->controller(); | 579 NavigationController* controller = dom_ui_->get_contents()->controller(); |
| 574 Browser* browser = Browser::GetBrowserForController( | 580 Browser* browser = Browser::GetBrowserForController( |
| 575 controller, NULL); | 581 controller, NULL); |
| 576 if (!browser) | 582 if (!browser) |
| 577 return; | 583 return; |
| 578 | 584 |
| 579 // Extract the integer value of the tab session to restore from the | 585 // Extract the integer value of the tab session to restore from the |
| 580 // incoming string array. This will be greatly simplified when | 586 // incoming string array. This will be greatly simplified when |
| 581 // DOMUIBindings::send() is generalized to all data types instead of | 587 // DOMUIBindings::send() is generalized to all data types instead of |
| 582 // silently failing when passed anything other then an array of | 588 // silently failing when passed anything other then an array of |
| 583 // strings. | 589 // strings. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 596 // The current tab has been nuked at this point; don't touch any member | 602 // The current tab has been nuked at this point; don't touch any member |
| 597 // variables. | 603 // variables. |
| 598 } | 604 } |
| 599 } | 605 } |
| 600 } | 606 } |
| 601 } | 607 } |
| 602 | 608 |
| 603 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( | 609 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( |
| 604 const Value* content) { | 610 const Value* content) { |
| 605 if (!tab_restore_service_) { | 611 if (!tab_restore_service_) { |
| 606 tab_restore_service_ = dom_ui_host_->profile()->GetTabRestoreService(); | 612 tab_restore_service_ = dom_ui_->get_profile()->GetTabRestoreService(); |
| 607 | 613 |
| 608 // GetTabRestoreService() can return NULL (i.e., when in Off the | 614 // GetTabRestoreService() can return NULL (i.e., when in Off the |
| 609 // Record mode) | 615 // Record mode) |
| 610 if (tab_restore_service_) { | 616 if (tab_restore_service_) { |
| 611 // This does nothing if the tabs have already been loaded or they | 617 // This does nothing if the tabs have already been loaded or they |
| 612 // shouldn't be loaded. | 618 // shouldn't be loaded. |
| 613 tab_restore_service_->LoadTabsFromLastSession(); | 619 tab_restore_service_->LoadTabsFromLastSession(); |
| 614 | 620 |
| 615 tab_restore_service_->AddObserver(this); | 621 tab_restore_service_->AddObserver(this); |
| 616 } | 622 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 638 (entry->type == TabRestoreService::WINDOW && | 644 (entry->type == TabRestoreService::WINDOW && |
| 639 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), | 645 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), |
| 640 value))) { | 646 value))) { |
| 641 value->SetInteger(L"sessionId", entry->id); | 647 value->SetInteger(L"sessionId", entry->id); |
| 642 list_value.Append(value); | 648 list_value.Append(value); |
| 643 added_count++; | 649 added_count++; |
| 644 } else { | 650 } else { |
| 645 delete value; | 651 delete value; |
| 646 } | 652 } |
| 647 } | 653 } |
| 648 dom_ui_host_->CallJavascriptFunction(L"recentlyClosedTabs", list_value); | 654 dom_ui_->CallJavascriptFunction(L"recentlyClosedTabs", list_value); |
| 649 } | 655 } |
| 650 | 656 |
| 651 void RecentlyClosedTabsHandler::TabRestoreServiceDestroyed( | 657 void RecentlyClosedTabsHandler::TabRestoreServiceDestroyed( |
| 652 TabRestoreService* service) { | 658 TabRestoreService* service) { |
| 653 tab_restore_service_ = NULL; | 659 tab_restore_service_ = NULL; |
| 654 } | 660 } |
| 655 | 661 |
| 656 bool RecentlyClosedTabsHandler::TabToValue( | 662 bool RecentlyClosedTabsHandler::TabToValue( |
| 657 const TabRestoreService::Tab& tab, | 663 const TabRestoreService::Tab& tab, |
| 658 DictionaryValue* dictionary) { | 664 DictionaryValue* dictionary) { |
| 659 if (tab.navigations.empty()) | 665 if (tab.navigations.empty()) |
| 660 return false; | 666 return false; |
| 661 | 667 |
| 662 const TabNavigation& current_navigation = | 668 const TabNavigation& current_navigation = |
| 663 tab.navigations.at(tab.current_navigation_index); | 669 tab.navigations.at(tab.current_navigation_index); |
| 664 if (current_navigation.url() == NewTabUIURL()) | 670 if (current_navigation.url() == NewTabUI::GetBaseURL()) |
| 665 return false; | 671 return false; |
| 666 | 672 |
| 667 SetURLTitleAndDirection(dictionary, current_navigation.title(), | 673 SetURLTitleAndDirection(dictionary, current_navigation.title(), |
| 668 current_navigation.url()); | 674 current_navigation.url()); |
| 669 dictionary->SetString(L"type", L"tab"); | 675 dictionary->SetString(L"type", L"tab"); |
| 670 return true; | 676 return true; |
| 671 } | 677 } |
| 672 | 678 |
| 673 bool RecentlyClosedTabsHandler::WindowToValue( | 679 bool RecentlyClosedTabsHandler::WindowToValue( |
| 674 const TabRestoreService::Window& window, | 680 const TabRestoreService::Window& window, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 692 } | 698 } |
| 693 | 699 |
| 694 dictionary->SetString(L"type", L"window"); | 700 dictionary->SetString(L"type", L"window"); |
| 695 dictionary->Set(L"tabs", tab_values); | 701 dictionary->Set(L"tabs", tab_values); |
| 696 return true; | 702 return true; |
| 697 } | 703 } |
| 698 | 704 |
| 699 /////////////////////////////////////////////////////////////////////////////// | 705 /////////////////////////////////////////////////////////////////////////////// |
| 700 // HistoryHandler | 706 // HistoryHandler |
| 701 | 707 |
| 702 HistoryHandler::HistoryHandler(DOMUIHost* dom_ui_host) | 708 HistoryHandler::HistoryHandler(DOMUI* dom_ui) |
| 703 : dom_ui_host_(dom_ui_host) { | 709 : DOMMessageHandler(dom_ui), |
| 704 dom_ui_host->RegisterMessageCallback("showHistoryPage", | 710 dom_ui_(dom_ui) { |
| 711 dom_ui->RegisterMessageCallback("showHistoryPage", |
| 705 NewCallback(this, &HistoryHandler::HandleShowHistoryPage)); | 712 NewCallback(this, &HistoryHandler::HandleShowHistoryPage)); |
| 706 dom_ui_host->RegisterMessageCallback("searchHistoryPage", | 713 dom_ui->RegisterMessageCallback("searchHistoryPage", |
| 707 NewCallback(this, &HistoryHandler::HandleSearchHistoryPage)); | 714 NewCallback(this, &HistoryHandler::HandleSearchHistoryPage)); |
| 708 } | 715 } |
| 709 | 716 |
| 710 void HistoryHandler::HandleShowHistoryPage(const Value*) { | 717 void HistoryHandler::HandleShowHistoryPage(const Value*) { |
| 711 NavigationController* controller = dom_ui_host_->controller(); | 718 NavigationController* controller = dom_ui_->get_contents()->controller(); |
| 712 if (controller) { | 719 if (controller) { |
| 713 #if defined(OS_WIN) | 720 #if defined(OS_WIN) |
| 714 // TODO(port): include this once history is converted to HTML | 721 // TODO(port): include this once history is converted to HTML |
| 715 controller->LoadURL(HistoryTabUI::GetURL(), GURL(), PageTransition::LINK); | 722 controller->LoadURL(HistoryUI::GetBaseURL(), GURL(), PageTransition::LINK); |
| 716 UserMetrics::RecordAction(L"NTP_ShowHistory", | 723 UserMetrics::RecordAction(L"NTP_ShowHistory", |
| 717 dom_ui_host_->profile()); | 724 dom_ui_->get_profile()); |
| 718 #else | 725 #else |
| 719 NOTIMPLEMENTED(); | 726 NOTIMPLEMENTED(); |
| 720 #endif | 727 #endif |
| 721 } | 728 } |
| 722 } | 729 } |
| 723 | 730 |
| 724 void HistoryHandler::HandleSearchHistoryPage(const Value* content) { | 731 void HistoryHandler::HandleSearchHistoryPage(const Value* content) { |
| 725 if (content && content->GetType() == Value::TYPE_LIST) { | 732 if (content && content->GetType() == Value::TYPE_LIST) { |
| 726 const ListValue* list_value = static_cast<const ListValue*>(content); | 733 const ListValue* list_value = static_cast<const ListValue*>(content); |
| 727 Value* list_member; | 734 Value* list_member; |
| 728 if (list_value->Get(0, &list_member) && | 735 if (list_value->Get(0, &list_member) && |
| 729 list_member->GetType() == Value::TYPE_STRING) { | 736 list_member->GetType() == Value::TYPE_STRING) { |
| 730 const StringValue* string_value = | 737 const StringValue* string_value = |
| 731 static_cast<const StringValue*>(list_member); | 738 static_cast<const StringValue*>(list_member); |
| 732 std::wstring wstring_value; | 739 std::wstring wstring_value; |
| 733 if (string_value->GetAsString(&wstring_value)) { | 740 if (string_value->GetAsString(&wstring_value)) { |
| 734 UserMetrics::RecordAction(L"NTP_SearchHistory", | 741 UserMetrics::RecordAction(L"NTP_SearchHistory", |
| 735 dom_ui_host_->profile()); | 742 dom_ui_->get_profile()); |
| 736 | 743 |
| 737 #if defined(OS_WIN) | 744 #if defined(OS_WIN) |
| 738 // TODO(port): include this once history is converted to HTML | 745 // TODO(port): include this once history is converted to HTML |
| 739 NavigationController* controller = dom_ui_host_->controller(); | 746 NavigationController* controller = |
| 747 dom_ui_->get_contents()->controller(); |
| 740 controller->LoadURL( | 748 controller->LoadURL( |
| 741 HistoryTabUI::GetHistoryURLWithSearchText(wstring_value), | 749 HistoryUI::GetHistoryURLWithSearchText(wstring_value), |
| 742 GURL(), | 750 GURL(), |
| 743 PageTransition::LINK); | 751 PageTransition::LINK); |
| 744 #else | 752 #else |
| 745 NOTIMPLEMENTED(); | 753 NOTIMPLEMENTED(); |
| 746 #endif | 754 #endif |
| 747 } | 755 } |
| 748 } | 756 } |
| 749 } | 757 } |
| 750 } | 758 } |
| 751 | 759 |
| 752 /////////////////////////////////////////////////////////////////////////////// | 760 /////////////////////////////////////////////////////////////////////////////// |
| 753 // MetricsHandler | 761 // MetricsHandler |
| 754 | 762 |
| 755 MetricsHandler::MetricsHandler(DOMUIHost* dom_ui_host) | 763 MetricsHandler::MetricsHandler(DOMUI* dom_ui) |
| 756 : dom_ui_host_(dom_ui_host) { | 764 : DOMMessageHandler(dom_ui), |
| 757 dom_ui_host->RegisterMessageCallback("metrics", | 765 dom_ui_(dom_ui) { |
| 766 dom_ui->RegisterMessageCallback("metrics", |
| 758 NewCallback(this, &MetricsHandler::HandleMetrics)); | 767 NewCallback(this, &MetricsHandler::HandleMetrics)); |
| 759 } | 768 } |
| 760 | 769 |
| 761 void MetricsHandler::HandleMetrics(const Value* content) { | 770 void MetricsHandler::HandleMetrics(const Value* content) { |
| 762 if (content && content->GetType() == Value::TYPE_LIST) { | 771 if (content && content->GetType() == Value::TYPE_LIST) { |
| 763 const ListValue* list_value = static_cast<const ListValue*>(content); | 772 const ListValue* list_value = static_cast<const ListValue*>(content); |
| 764 Value* list_member; | 773 Value* list_member; |
| 765 if (list_value->Get(0, &list_member) && | 774 if (list_value->Get(0, &list_member) && |
| 766 list_member->GetType() == Value::TYPE_STRING) { | 775 list_member->GetType() == Value::TYPE_STRING) { |
| 767 const StringValue* string_value = | 776 const StringValue* string_value = |
| 768 static_cast<const StringValue*>(list_member); | 777 static_cast<const StringValue*>(list_member); |
| 769 std::wstring wstring_value; | 778 std::wstring wstring_value; |
| 770 if (string_value->GetAsString(&wstring_value)) { | 779 if (string_value->GetAsString(&wstring_value)) { |
| 771 UserMetrics::RecordComputedAction(wstring_value, | 780 UserMetrics::RecordComputedAction(wstring_value, |
| 772 dom_ui_host_->profile()); | 781 dom_ui_->get_profile()); |
| 773 } | 782 } |
| 774 } | 783 } |
| 775 } | 784 } |
| 776 } | 785 } |
| 777 | 786 |
| 778 /////////////////////////////////////////////////////////////////////////////// | 787 /////////////////////////////////////////////////////////////////////////////// |
| 779 // NewTabUIContents | 788 // NewTabUIContents |
| 780 | 789 |
| 781 // This is the top-level URL handler for chrome-internal: URLs, and exposed in | 790 NewTabUI::NewTabUI(DOMUIContents* contents) : |
| 782 // our header file. | 791 DOMUI(contents), |
| 783 bool NewTabUIHandleURL(GURL* url, | |
| 784 TabContentsType* result_type) { | |
| 785 if (!url->SchemeIs(kNewTabUIScheme)) | |
| 786 return false; | |
| 787 | |
| 788 *result_type = TAB_CONTENTS_NEW_TAB_UI; | |
| 789 *url = GURL(DOMUIContents::GetScheme() + "://new-tab/"); | |
| 790 | |
| 791 return true; | |
| 792 } | |
| 793 | |
| 794 GURL NewTabUIURL() { | |
| 795 std::string url(kNewTabUIScheme); | |
| 796 url += ":"; | |
| 797 return GURL(url); | |
| 798 } | |
| 799 | |
| 800 NewTabUIContents::NewTabUIContents(Profile* profile, | |
| 801 SiteInstance* instance, RenderViewHostFactory* render_view_factory) : | |
| 802 DOMUIHost(profile, instance, render_view_factory), | |
| 803 motd_message_id_(0), | 792 motd_message_id_(0), |
| 804 incognito_(false), | 793 incognito_(false), |
| 805 most_visited_handler_(NULL) { | 794 most_visited_handler_(NULL) { |
| 806 set_type(TAB_CONTENTS_NEW_TAB_UI); | |
| 807 | |
| 808 // Show profile name in the title if the current profile is not the default. | 795 // Show profile name in the title if the current profile is not the default. |
| 809 std::wstring title; | 796 std::wstring title; |
| 810 if (UserDataManager::Get()->is_current_profile_default()) { | 797 if (UserDataManager::Get()->is_current_profile_default()) { |
| 811 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); | 798 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); |
| 812 } else { | 799 } else { |
| 813 title = l10n_util::GetStringF( | 800 title = l10n_util::GetStringF( |
| 814 IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, | 801 IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, |
| 815 UserDataManager::Get()->current_profile_name()); | 802 UserDataManager::Get()->current_profile_name()); |
| 816 } | 803 } |
| 817 set_forced_title(title); | 804 set_forced_title(title); |
| 818 | 805 |
| 819 if (profile->IsOffTheRecord()) | 806 if (get_profile()->IsOffTheRecord()) |
| 820 incognito_ = true; | 807 incognito_ = true; |
| 821 | 808 |
| 822 if (NewTabHTMLSource::first_view() && | 809 if (NewTabHTMLSource::first_view() && |
| 823 (profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || | 810 (get_profile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || |
| 824 !profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) | 811 !get_profile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 825 ) { | 812 ) { |
| 826 NewTabHTMLSource::set_first_view(false); | 813 NewTabHTMLSource::set_first_view(false); |
| 827 } | 814 } |
| 828 | 815 |
| 829 render_view_host()->set_paint_observer(new PaintTimer); | 816 contents->render_view_host()->set_paint_observer(new PaintTimer); |
| 830 } | 817 } |
| 831 | 818 |
| 832 void NewTabUIContents::AttachMessageHandlers() { | 819 void NewTabUI::Init() { |
| 833 // Regretfully, DataSources are global, instead of | 820 // Regretfully, DataSources are global, instead of |
| 834 // per-TabContents. Because of the motd_message_id_ member, each | 821 // per-TabContents. Because of the motd_message_id_ member, each |
| 835 // NewTabUIContents instance could theoretically have a different | 822 // NewTabUIContents instance could theoretically have a different |
| 836 // message. Moving this from the constructor to here means that we | 823 // message. Moving this from the constructor to here means that we |
| 837 // reconnect this source each time we reload so we should no longer | 824 // reconnect this source each time we reload so we should no longer |
| 838 // have the bug where we open a normal new tab page (no motd), open | 825 // have the bug where we open a normal new tab page (no motd), open |
| 839 // another OTR new tab page (blurb motd describing what 'incognito' | 826 // another OTR new tab page (blurb motd describing what 'incognito' |
| 840 // means), refresh the normal new page (which now displays the | 827 // means), refresh the normal new page (which now displays the |
| 841 // incognito blurb because that was the last NewTabHTMLSource hooked | 828 // incognito blurb because that was the last NewTabHTMLSource hooked |
| 842 // up). | 829 // up). |
| (...skipping 21 matching lines...) Expand all Loading... |
| 864 | 851 |
| 865 NewTabHTMLSource* html_source = new NewTabHTMLSource(); | 852 NewTabHTMLSource* html_source = new NewTabHTMLSource(); |
| 866 | 853 |
| 867 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 854 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 868 NewRunnableMethod(&chrome_url_data_manager, | 855 NewRunnableMethod(&chrome_url_data_manager, |
| 869 &ChromeURLDataManager::AddDataSource, | 856 &ChromeURLDataManager::AddDataSource, |
| 870 html_source)); | 857 html_source)); |
| 871 } | 858 } |
| 872 } | 859 } |
| 873 | 860 |
| 874 bool NewTabUIContents::NavigateToPendingEntry(bool reload) { | 861 // static |
| 875 const bool result = WebContents::NavigateToPendingEntry(reload); | 862 GURL NewTabUI::GetBaseURL() { |
| 876 controller()->GetPendingEntry()->set_title(forced_title_); | 863 std::string url = DOMUIContents::GetScheme(); |
| 877 return result; | 864 url += "://"; |
| 865 url += kNewTabHost; |
| 866 return GURL(url); |
| 878 } | 867 } |
| 879 | 868 |
| 880 const std::wstring& NewTabUIContents::GetTitle() const { | 869 void NewTabUI::SetInitialFocus() { |
| 881 if (!forced_title_.empty()) | 870 if (get_contents()->delegate()) |
| 882 return forced_title_; | 871 get_contents()->delegate()->SetFocusToLocationBar(); |
| 883 return WebContents::GetTitle(); | |
| 884 } | 872 } |
| 885 | 873 |
| 886 void NewTabUIContents::SetInitialFocus() { | 874 void NewTabUI::RequestOpenURL(const GURL& url, |
| 887 if (delegate()) | 875 const GURL&, |
| 888 delegate()->SetFocusToLocationBar(); | 876 WindowOpenDisposition disposition) { |
| 889 } | |
| 890 | |
| 891 bool NewTabUIContents::SupportsURL(GURL* url) { | |
| 892 if (url->SchemeIs("javascript")) | |
| 893 return true; | |
| 894 return DOMUIHost::SupportsURL(url); | |
| 895 } | |
| 896 | |
| 897 void NewTabUIContents::RequestOpenURL(const GURL& url, | |
| 898 const GURL& /*referrer*/, | |
| 899 WindowOpenDisposition disposition) { | |
| 900 // The user opened a URL on the page (including "open in new window"). | 877 // The user opened a URL on the page (including "open in new window"). |
| 901 // We count all such clicks as AUTO_BOOKMARK, which increments the site's | 878 // We count all such clicks as AUTO_BOOKMARK, which increments the site's |
| 902 // visit count (which is used for ranking the most visited entries). | 879 // visit count (which is used for ranking the most visited entries). |
| 903 // Note this means we're including clicks on not only most visited thumbnails, | 880 // Note this means we're including clicks on not only most visited |
| 904 // but also clicks on recently bookmarked. | 881 // thumbnails, but also clicks on recently bookmarked. |
| 905 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK); | 882 get_contents()->OpenURL(url, GURL(), disposition, |
| 883 PageTransition::AUTO_BOOKMARK); |
| 906 } | 884 } |
| OLD | NEW |