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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/automation/automation_provider_observers.h" 5 #include "chrome/browser/automation/automation_provider_observers.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/thread_restrictions.h" 16 #include "base/thread_restrictions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/app/chrome_command_ids.h" 18 #include "chrome/app/chrome_command_ids.h"
19 #include "chrome/browser/automation/automation_provider.h" 19 #include "chrome/browser/automation/automation_provider.h"
20 #include "chrome/browser/automation/automation_provider_json.h" 20 #include "chrome/browser/automation/automation_provider_json.h"
21 #include "chrome/browser/bookmarks/bookmark_model.h" 21 #include "chrome/browser/bookmarks/bookmark_model.h"
22 #include "chrome/browser/browser.h" 22 #include "chrome/browser/browser.h"
23 #include "chrome/browser/browser_list.h" 23 #include "chrome/browser/browser_list.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/dom_operation_notification_details.h" 25 #include "chrome/browser/dom_operation_notification_details.h"
26 #include "chrome/browser/dom_ui/new_tab_ui.h"
26 #include "chrome/browser/download/download_item.h" 27 #include "chrome/browser/download/download_item.h"
27 #include "chrome/browser/download/save_package.h" 28 #include "chrome/browser/download/save_package.h"
28 #include "chrome/browser/extensions/extension_host.h" 29 #include "chrome/browser/extensions/extension_host.h"
29 #include "chrome/browser/extensions/extension_process_manager.h" 30 #include "chrome/browser/extensions/extension_process_manager.h"
30 #include "chrome/browser/extensions/extension_updater.h" 31 #include "chrome/browser/extensions/extension_updater.h"
32 #include "chrome/browser/history/top_sites.h"
31 #include "chrome/browser/login_prompt.h" 33 #include "chrome/browser/login_prompt.h"
32 #include "chrome/browser/metrics/metric_event_duration_details.h" 34 #include "chrome/browser/metrics/metric_event_duration_details.h"
33 #include "chrome/browser/notifications/balloon.h" 35 #include "chrome/browser/notifications/balloon.h"
34 #include "chrome/browser/notifications/balloon_collection.h" 36 #include "chrome/browser/notifications/balloon_collection.h"
35 #include "chrome/browser/printing/print_job.h" 37 #include "chrome/browser/printing/print_job.h"
36 #include "chrome/browser/profile.h" 38 #include "chrome/browser/profile.h"
37 #include "chrome/browser/renderer_host/render_view_host.h" 39 #include "chrome/browser/renderer_host/render_view_host.h"
38 #include "chrome/browser/search_engines/template_url_model.h" 40 #include "chrome/browser/search_engines/template_url_model.h"
41 #include "chrome/browser/sessions/tab_restore_service.h"
39 #include "chrome/browser/tab_contents/navigation_controller.h" 42 #include "chrome/browser/tab_contents/navigation_controller.h"
40 #include "chrome/browser/tab_contents/tab_contents.h" 43 #include "chrome/browser/tab_contents/tab_contents.h"
41 #include "chrome/browser/tab_contents/thumbnail_generator.h" 44 #include "chrome/browser/tab_contents/thumbnail_generator.h"
42 #include "chrome/browser/translate/page_translated_details.h" 45 #include "chrome/browser/translate/page_translated_details.h"
43 #include "chrome/browser/translate/translate_infobar_delegate.h" 46 #include "chrome/browser/translate/translate_infobar_delegate.h"
44 #include "chrome/common/automation_constants.h" 47 #include "chrome/common/automation_constants.h"
45 #include "chrome/common/extensions/extension.h" 48 #include "chrome/common/extensions/extension.h"
46 #include "chrome/common/notification_service.h" 49 #include "chrome/common/notification_service.h"
47 #include "gfx/codec/png_codec.h" 50 #include "gfx/codec/png_codec.h"
48 #include "gfx/rect.h" 51 #include "gfx/rect.h"
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 render_view_->ExecuteJavascriptInWebFrame(L"", javascript); 1399 render_view_->ExecuteJavascriptInWebFrame(L"", javascript);
1397 } 1400 }
1398 1401
1399 void PageSnapshotTaker::SendMessage(bool success) { 1402 void PageSnapshotTaker::SendMessage(bool success) {
1400 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, 1403 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_,
1401 success); 1404 success);
1402 automation_->Send(reply_message_); 1405 automation_->Send(reply_message_);
1403 delete this; 1406 delete this;
1404 } 1407 }
1405 1408
1409 NTPInfoObserver::NTPInfoObserver(
1410 AutomationProvider* automation,
1411 IPC::Message* reply_message,
1412 CancelableRequestConsumer* consumer)
1413 : automation_(automation),
1414 reply_message_(reply_message),
1415 consumer_(consumer),
1416 request_(NULL),
1417 ntp_info_(new DictionaryValue) {
1418 top_sites_ = automation_->profile()->GetTopSites();
1419 if (!top_sites_) {
1420 AutomationJSONReply(automation_, reply_message_)
1421 .SendError("Profile does not have service for querying the top sites.");
1422 return;
1423 }
1424 TabRestoreService* service = automation_->profile()->GetTabRestoreService();
1425 if (!service) {
1426 AutomationJSONReply(automation_, reply_message_)
1427 .SendError("No TabRestoreService.");
1428 return;
1429 }
1430
1431 // Get the info that would be displayed in the recently closed section.
1432 ListValue* recently_closed_list = new ListValue;
1433 NewTabUI::AddRecentlyClosedEntries(service->entries(),
1434 recently_closed_list);
1435 ntp_info_->Set("recently_closed", recently_closed_list);
1436
1437 registrar_.Add(this, NotificationType::TOP_SITES_UPDATED,
1438 Source<history::TopSites>(top_sites_));
1439 request_ = top_sites_->StartQueryForMostVisited();
1440 }
1441
1442 void NTPInfoObserver::Observe(NotificationType type,
1443 const NotificationSource& source,
1444 const NotificationDetails& details) {
1445 Details<CancelableRequestProvider::Handle> request_details(details);
1446 if (request_ == *request_details.ptr()) {
1447 top_sites_->GetMostVisitedURLs(
1448 consumer_,
1449 NewCallback(this, &NTPInfoObserver::OnTopSitesReceived));
1450 }
1451 }
1452
1453 void NTPInfoObserver::OnTopSitesReceived(
1454 const history::MostVisitedURLList& visited_list) {
1455 ListValue* list_value = new ListValue;
1456 for (size_t i = 0; i < visited_list.size(); ++i) {
1457 const history::MostVisitedURL& visited = visited_list[i];
1458 if (visited.url.spec().empty())
1459 break; // This is the signal that there are no more real visited sites.
1460 DictionaryValue* dict = new DictionaryValue;
1461 dict->SetString("url", visited.url.spec());
1462 dict->SetString("title", visited.title);
1463 dict->SetBoolean("is_pinned", top_sites_->IsURLPinned(visited.url));
1464 list_value->Append(dict);
1465 }
1466 ntp_info_->Set("most_visited", list_value);
1467 AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get());
1468 delete this;
1469 }
1470
1406 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( 1471 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver(
1407 AutomationProvider* automation, 1472 AutomationProvider* automation,
1408 AutocompleteEditModel* autocomplete_edit, 1473 AutocompleteEditModel* autocomplete_edit,
1409 IPC::Message* reply_message) 1474 IPC::Message* reply_message)
1410 : automation_(automation), 1475 : automation_(automation),
1411 reply_message_(reply_message), 1476 reply_message_(reply_message),
1412 autocomplete_edit_model_(autocomplete_edit) { 1477 autocomplete_edit_model_(autocomplete_edit) {
1413 Source<AutocompleteEditModel> source(autocomplete_edit); 1478 Source<AutocompleteEditModel> source(autocomplete_edit);
1414 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); 1479 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source);
1415 } 1480 }
(...skipping 21 matching lines...) Expand all
1437 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged)); 1502 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged));
1438 } 1503 }
1439 1504
1440 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { 1505 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() {
1441 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) { 1506 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) {
1442 collection_->set_on_collection_changed_callback(NULL); 1507 collection_->set_on_collection_changed_callback(NULL);
1443 reply_.SendSuccess(NULL); 1508 reply_.SendSuccess(NULL);
1444 delete this; 1509 delete this;
1445 } 1510 }
1446 } 1511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698