| OLD | NEW |
| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" |
| 8 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/automation/automation_provider.h" | 12 #include "chrome/browser/automation/automation_provider.h" |
| 12 #include "chrome/browser/automation/automation_provider_json.h" | 13 #include "chrome/browser/automation/automation_provider_json.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 15 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/dom_operation_notification_details.h" | 17 #include "chrome/browser/dom_operation_notification_details.h" |
| 18 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 17 #include "chrome/browser/download/download_item.h" | 19 #include "chrome/browser/download/download_item.h" |
| 18 #include "chrome/browser/download/save_package.h" | 20 #include "chrome/browser/download/save_package.h" |
| 19 #include "chrome/browser/extensions/extension_host.h" | 21 #include "chrome/browser/extensions/extension_host.h" |
| 20 #include "chrome/browser/extensions/extension_process_manager.h" | 22 #include "chrome/browser/extensions/extension_process_manager.h" |
| 21 #include "chrome/browser/extensions/extension_updater.h" | 23 #include "chrome/browser/extensions/extension_updater.h" |
| 24 #include "chrome/browser/history/top_sites.h" |
| 22 #include "chrome/browser/login_prompt.h" | 25 #include "chrome/browser/login_prompt.h" |
| 23 #include "chrome/browser/metrics/metric_event_duration_details.h" | 26 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 24 #include "chrome/browser/printing/print_job.h" | 27 #include "chrome/browser/printing/print_job.h" |
| 25 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/search_engines/template_url_model.h" | 29 #include "chrome/browser/search_engines/template_url_model.h" |
| 30 #include "chrome/browser/sessions/tab_restore_service.h" |
| 27 #include "chrome/browser/tab_contents/navigation_controller.h" | 31 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents.h" | 32 #include "chrome/browser/tab_contents/tab_contents.h" |
| 29 #include "chrome/browser/translate/page_translated_details.h" | 33 #include "chrome/browser/translate/page_translated_details.h" |
| 30 #include "chrome/browser/translate/translate_infobar_delegate.h" | 34 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 31 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| 32 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
| 33 #include "chrome/test/automation/automation_constants.h" | 37 #include "chrome/test/automation/automation_constants.h" |
| 34 | 38 |
| 35 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 40 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 const NotificationSource& source, | 1306 const NotificationSource& source, |
| 1303 const NotificationDetails& details) { | 1307 const NotificationDetails& details) { |
| 1304 if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { | 1308 if (type == NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED) { |
| 1305 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); | 1309 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); |
| 1306 delete this; | 1310 delete this; |
| 1307 } else { | 1311 } else { |
| 1308 NOTREACHED(); | 1312 NOTREACHED(); |
| 1309 } | 1313 } |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1316 NTPInfoObserver::NTPInfoObserver( |
| 1317 AutomationProvider* automation, |
| 1318 IPC::Message* reply_message, |
| 1319 CancelableRequestConsumer* consumer) |
| 1320 : automation_(automation), |
| 1321 reply_message_(reply_message), |
| 1322 consumer_(consumer), |
| 1323 ntp_info_(new DictionaryValue) { |
| 1324 top_sites_ = automation_->profile()->GetTopSites(); |
| 1325 if (!top_sites_) { |
| 1326 AutomationJSONReply(automation_, reply_message_) |
| 1327 .SendError("Profile does not have service for querying the top sites."); |
| 1328 return; |
| 1329 } |
| 1330 TabRestoreService* service = automation_->profile()->GetTabRestoreService(); |
| 1331 if (!service) { |
| 1332 AutomationJSONReply(automation_, reply_message_) |
| 1333 .SendError("No TabRestoreService."); |
| 1334 return; |
| 1335 } |
| 1336 |
| 1337 // Get the info that would be displayed in the recently closed section. |
| 1338 ListValue* recently_closed_list = new ListValue; |
| 1339 NewTabUI::AddRecentlyClosedEntries(service->entries(), |
| 1340 recently_closed_list); |
| 1341 ntp_info_->Set("recently_closed", recently_closed_list); |
| 1342 |
| 1343 top_sites_->RefreshAndCallback( |
| 1344 consumer_, |
| 1345 NewCallback(this, &NTPInfoObserver::OnTopSitesRefreshed)); |
| 1346 } |
| 1347 |
| 1348 void NTPInfoObserver::OnTopSitesRefreshed() { |
| 1349 top_sites_->GetMostVisitedURLs( |
| 1350 consumer_, |
| 1351 NewCallback(this, &NTPInfoObserver::OnTopSitesReceived)); |
| 1352 } |
| 1353 |
| 1354 void NTPInfoObserver::OnTopSitesReceived( |
| 1355 history::MostVisitedURLList visited_list) { |
| 1356 ListValue* list_value = new ListValue; |
| 1357 for (size_t i = 0; i < visited_list.size(); ++i) { |
| 1358 const history::MostVisitedURL& visited = visited_list[i]; |
| 1359 if (visited.url.spec().empty()) |
| 1360 break; // This is the signal that there are no more real visited sites. |
| 1361 DictionaryValue* dict = new DictionaryValue; |
| 1362 dict->SetString("url", visited.url.spec()); |
| 1363 dict->SetString("title", visited.title); |
| 1364 dict->SetBoolean("is_pinned", top_sites_->IsURLPinned(visited.url)); |
| 1365 list_value->Append(dict); |
| 1366 } |
| 1367 ntp_info_->Set("most_visited", list_value); |
| 1368 AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get()); |
| 1369 delete this; |
| 1370 } |
| 1371 |
| 1312 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( | 1372 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( |
| 1313 AutomationProvider* automation, | 1373 AutomationProvider* automation, |
| 1314 AutocompleteEditModel* autocomplete_edit, | 1374 AutocompleteEditModel* autocomplete_edit, |
| 1315 IPC::Message* reply_message) | 1375 IPC::Message* reply_message) |
| 1316 : automation_(automation), | 1376 : automation_(automation), |
| 1317 reply_message_(reply_message), | 1377 reply_message_(reply_message), |
| 1318 autocomplete_edit_model_(autocomplete_edit) { | 1378 autocomplete_edit_model_(autocomplete_edit) { |
| 1319 Source<AutocompleteEditModel> source(autocomplete_edit); | 1379 Source<AutocompleteEditModel> source(autocomplete_edit); |
| 1320 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); | 1380 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); |
| 1321 } | 1381 } |
| 1322 | 1382 |
| 1323 void AutocompleteEditFocusedObserver::Observe( | 1383 void AutocompleteEditFocusedObserver::Observe( |
| 1324 NotificationType type, | 1384 NotificationType type, |
| 1325 const NotificationSource& source, | 1385 const NotificationSource& source, |
| 1326 const NotificationDetails& details) { | 1386 const NotificationDetails& details) { |
| 1327 DCHECK(type == NotificationType::AUTOCOMPLETE_EDIT_FOCUSED); | 1387 DCHECK(type == NotificationType::AUTOCOMPLETE_EDIT_FOCUSED); |
| 1328 AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( | 1388 AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( |
| 1329 reply_message_, true); | 1389 reply_message_, true); |
| 1330 automation_->Send(reply_message_); | 1390 automation_->Send(reply_message_); |
| 1331 delete this; | 1391 delete this; |
| 1332 } | 1392 } |
| OLD | NEW |