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

Unified Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 5088001: Add pyauto hook for getting and manipulating the data underneath the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/functional
Patch Set: change hook, remove ntp_model Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/automation_provider_observers.cc
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 8172fe393aecb18e8887489c8c50b7ef8036ca88..eaf496029bd431c38613b2665155ed12b70ec09c 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -23,11 +23,13 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/dom_operation_notification_details.h"
+#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/save_package.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_updater.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/login_prompt.h"
#include "chrome/browser/metrics/metric_event_duration_details.h"
#include "chrome/browser/notifications/balloon.h"
@@ -36,6 +38,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/thumbnail_generator.h"
@@ -1403,6 +1406,68 @@ void PageSnapshotTaker::SendMessage(bool success) {
delete this;
}
+NTPInfoObserver::NTPInfoObserver(
+ AutomationProvider* automation,
+ IPC::Message* reply_message,
+ CancelableRequestConsumer* consumer)
+ : automation_(automation),
+ reply_message_(reply_message),
+ consumer_(consumer),
+ request_(NULL),
+ ntp_info_(new DictionaryValue) {
+ top_sites_ = automation_->profile()->GetTopSites();
+ if (!top_sites_) {
+ AutomationJSONReply(automation_, reply_message_)
+ .SendError("Profile does not have service for querying the top sites.");
+ return;
+ }
+ TabRestoreService* service = automation_->profile()->GetTabRestoreService();
+ if (!service) {
+ AutomationJSONReply(automation_, reply_message_)
+ .SendError("No TabRestoreService.");
+ return;
+ }
+
+ // Get the info that would be displayed in the recently closed section.
+ ListValue* recently_closed_list = new ListValue;
+ NewTabUI::AddRecentlyClosedEntries(service->entries(),
+ recently_closed_list);
+ ntp_info_->Set("recently_closed", recently_closed_list);
+
+ registrar_.Add(this, NotificationType::TOP_SITES_UPDATED,
+ Source<history::TopSites>(top_sites_));
+ request_ = top_sites_->StartQueryForMostVisited();
+}
+
+void NTPInfoObserver::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ Details<CancelableRequestProvider::Handle> request_details(details);
+ if (request_ == *request_details.ptr()) {
+ top_sites_->GetMostVisitedURLs(
+ consumer_,
+ NewCallback(this, &NTPInfoObserver::OnTopSitesReceived));
+ }
+}
+
+void NTPInfoObserver::OnTopSitesReceived(
+ const history::MostVisitedURLList& visited_list) {
+ ListValue* list_value = new ListValue;
+ for (size_t i = 0; i < visited_list.size(); ++i) {
+ const history::MostVisitedURL& visited = visited_list[i];
+ if (visited.url.spec().empty())
+ break; // This is the signal that there are no more real visited sites.
+ DictionaryValue* dict = new DictionaryValue;
+ dict->SetString("url", visited.url.spec());
+ dict->SetString("title", visited.title);
+ dict->SetBoolean("is_pinned", top_sites_->IsURLPinned(visited.url));
+ list_value->Append(dict);
+ }
+ ntp_info_->Set("most_visited", list_value);
+ AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get());
+ delete this;
+}
+
AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver(
AutomationProvider* automation,
AutocompleteEditModel* autocomplete_edit,

Powered by Google App Engine
This is Rietveld 408576698