| 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 "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" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); | 501 &RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked)); |
| 502 } | 502 } |
| 503 | 503 |
| 504 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { | 504 RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() { |
| 505 if (model_) | 505 if (model_) |
| 506 model_->RemoveObserver(this); | 506 model_->RemoveObserver(this); |
| 507 } | 507 } |
| 508 | 508 |
| 509 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { | 509 void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) { |
| 510 if (!model_) { | 510 if (!model_) { |
| 511 model_ = dom_ui_host_->profile()->GetBookmarkBarModel(); | 511 model_ = dom_ui_host_->profile()->GetBookmarkModel(); |
| 512 model_->AddObserver(this); | 512 model_->AddObserver(this); |
| 513 } | 513 } |
| 514 // If the model is loaded, synchronously send the bookmarks down. Otherwise | 514 // If the model is loaded, synchronously send the bookmarks down. Otherwise |
| 515 // when the model loads we'll send the bookmarks down. | 515 // when the model loads we'll send the bookmarks down. |
| 516 if (model_->IsLoaded()) | 516 if (model_->IsLoaded()) |
| 517 SendBookmarksToPage(); | 517 SendBookmarksToPage(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 void RecentlyBookmarkedHandler::SendBookmarksToPage() { | 520 void RecentlyBookmarkedHandler::SendBookmarksToPage() { |
| 521 std::vector<BookmarkBarNode*> recently_bookmarked; | 521 std::vector<BookmarkNode*> recently_bookmarked; |
| 522 model_->GetMostRecentlyAddedEntries(kRecentBookmarks, &recently_bookmarked); | 522 model_->GetMostRecentlyAddedEntries(kRecentBookmarks, &recently_bookmarked); |
| 523 ListValue list_value; | 523 ListValue list_value; |
| 524 for (size_t i = 0; i < recently_bookmarked.size(); ++i) { | 524 for (size_t i = 0; i < recently_bookmarked.size(); ++i) { |
| 525 BookmarkBarNode* node = recently_bookmarked[i]; | 525 BookmarkNode* node = recently_bookmarked[i]; |
| 526 DictionaryValue* entry_value = new DictionaryValue; | 526 DictionaryValue* entry_value = new DictionaryValue; |
| 527 SetURLAndTitle(entry_value, node->GetTitle(), node->GetURL()); | 527 SetURLAndTitle(entry_value, node->GetTitle(), node->GetURL()); |
| 528 list_value.Append(entry_value); | 528 list_value.Append(entry_value); |
| 529 } | 529 } |
| 530 dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value); | 530 dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value); |
| 531 } | 531 } |
| 532 | 532 |
| 533 void RecentlyBookmarkedHandler::Loaded(BookmarkBarModel* model) { | 533 void RecentlyBookmarkedHandler::Loaded(BookmarkModel* model) { |
| 534 SendBookmarksToPage(); | 534 SendBookmarksToPage(); |
| 535 } | 535 } |
| 536 | 536 |
| 537 void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkBarModel* model, | 537 void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkModel* model, |
| 538 BookmarkBarNode* parent, | 538 BookmarkNode* parent, |
| 539 int index) { | 539 int index) { |
| 540 SendBookmarksToPage(); | 540 SendBookmarksToPage(); |
| 541 } | 541 } |
| 542 | 542 |
| 543 void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkBarModel* model, | 543 void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkModel* model, |
| 544 BookmarkBarNode* parent, | 544 BookmarkNode* parent, |
| 545 int index) { | 545 int index) { |
| 546 SendBookmarksToPage(); | 546 SendBookmarksToPage(); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkBarModel* model, | 549 void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkModel* model, |
| 550 BookmarkBarNode* node) { | 550 BookmarkNode* node) { |
| 551 SendBookmarksToPage(); | 551 SendBookmarksToPage(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host) | 554 RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host) |
| 555 : dom_ui_host_(dom_ui_host), | 555 : dom_ui_host_(dom_ui_host), |
| 556 tab_restore_service_(NULL), | 556 tab_restore_service_(NULL), |
| 557 handle_recently_closed_tab_factory_(this) { | 557 handle_recently_closed_tab_factory_(this) { |
| 558 dom_ui_host->RegisterMessageCallback("getRecentlyClosedTabs", | 558 dom_ui_host->RegisterMessageCallback("getRecentlyClosedTabs", |
| 559 NewCallback(this, | 559 NewCallback(this, |
| 560 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); | 560 &RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs)); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 for (size_t i = 0; i < urls.size(); ++i) { | 849 for (size_t i = 0; i < urls.size(); ++i) { |
| 850 if (url == urls[i]) { | 850 if (url == urls[i]) { |
| 851 UserMetrics::RecordComputedAction(StringPrintf(L"MostVisited%d", i), | 851 UserMetrics::RecordComputedAction(StringPrintf(L"MostVisited%d", i), |
| 852 profile()); | 852 profile()); |
| 853 break; | 853 break; |
| 854 } | 854 } |
| 855 } | 855 } |
| 856 } | 856 } |
| 857 } | 857 } |
| 858 | 858 |
| OLD | NEW |