| 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 <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/most_visited_handler.h" |
| 27 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 26 #include "chrome/browser/download/download_item.h" | 28 #include "chrome/browser/download/download_item.h" |
| 27 #include "chrome/browser/download/save_package.h" | 29 #include "chrome/browser/download/save_package.h" |
| 28 #include "chrome/browser/extensions/extension_host.h" | 30 #include "chrome/browser/extensions/extension_host.h" |
| 29 #include "chrome/browser/extensions/extension_process_manager.h" | 31 #include "chrome/browser/extensions/extension_process_manager.h" |
| 30 #include "chrome/browser/extensions/extension_updater.h" | 32 #include "chrome/browser/extensions/extension_updater.h" |
| 33 #include "chrome/browser/history/top_sites.h" |
| 31 #include "chrome/browser/login_prompt.h" | 34 #include "chrome/browser/login_prompt.h" |
| 32 #include "chrome/browser/metrics/metric_event_duration_details.h" | 35 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 33 #include "chrome/browser/notifications/balloon.h" | 36 #include "chrome/browser/notifications/balloon.h" |
| 34 #include "chrome/browser/notifications/balloon_collection.h" | 37 #include "chrome/browser/notifications/balloon_collection.h" |
| 35 #include "chrome/browser/printing/print_job.h" | 38 #include "chrome/browser/printing/print_job.h" |
| 36 #include "chrome/browser/profile.h" | 39 #include "chrome/browser/profile.h" |
| 37 #include "chrome/browser/renderer_host/render_view_host.h" | 40 #include "chrome/browser/renderer_host/render_view_host.h" |
| 38 #include "chrome/browser/search_engines/template_url_model.h" | 41 #include "chrome/browser/search_engines/template_url_model.h" |
| 42 #include "chrome/browser/sessions/tab_restore_service.h" |
| 39 #include "chrome/browser/tab_contents/navigation_controller.h" | 43 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 40 #include "chrome/browser/tab_contents/tab_contents.h" | 44 #include "chrome/browser/tab_contents/tab_contents.h" |
| 41 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 45 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 42 #include "chrome/browser/translate/page_translated_details.h" | 46 #include "chrome/browser/translate/page_translated_details.h" |
| 43 #include "chrome/browser/translate/translate_infobar_delegate.h" | 47 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 44 #include "chrome/common/automation_constants.h" | 48 #include "chrome/common/automation_constants.h" |
| 45 #include "chrome/common/extensions/extension.h" | 49 #include "chrome/common/extensions/extension.h" |
| 46 #include "chrome/common/notification_service.h" | 50 #include "chrome/common/notification_service.h" |
| 47 #include "gfx/codec/png_codec.h" | 51 #include "gfx/codec/png_codec.h" |
| 48 #include "gfx/rect.h" | 52 #include "gfx/rect.h" |
| 53 #include "googleurl/src/gurl.h" |
| 49 | 54 |
| 50 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 51 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 56 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 52 #endif | 57 #endif |
| 53 | 58 |
| 54 // Holds onto start and stop timestamps for a particular tab | 59 // Holds onto start and stop timestamps for a particular tab |
| 55 class InitialLoadObserver::TabTime { | 60 class InitialLoadObserver::TabTime { |
| 56 public: | 61 public: |
| 57 explicit TabTime(base::TimeTicks started) | 62 explicit TabTime(base::TimeTicks started) |
| 58 : load_start_time_(started) { | 63 : load_start_time_(started) { |
| (...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 render_view_->ExecuteJavascriptInWebFrame(L"", javascript); | 1401 render_view_->ExecuteJavascriptInWebFrame(L"", javascript); |
| 1397 } | 1402 } |
| 1398 | 1403 |
| 1399 void PageSnapshotTaker::SendMessage(bool success) { | 1404 void PageSnapshotTaker::SendMessage(bool success) { |
| 1400 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, | 1405 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, |
| 1401 success); | 1406 success); |
| 1402 automation_->Send(reply_message_); | 1407 automation_->Send(reply_message_); |
| 1403 delete this; | 1408 delete this; |
| 1404 } | 1409 } |
| 1405 | 1410 |
| 1411 NTPInfoObserver::NTPInfoObserver( |
| 1412 AutomationProvider* automation, |
| 1413 IPC::Message* reply_message, |
| 1414 CancelableRequestConsumer* consumer) |
| 1415 : automation_(automation), |
| 1416 reply_message_(reply_message), |
| 1417 consumer_(consumer), |
| 1418 request_(NULL), |
| 1419 ntp_info_(new DictionaryValue) { |
| 1420 top_sites_ = automation_->profile()->GetTopSites(); |
| 1421 if (!top_sites_) { |
| 1422 AutomationJSONReply(automation_, reply_message_) |
| 1423 .SendError("Profile does not have service for querying the top sites."); |
| 1424 return; |
| 1425 } |
| 1426 TabRestoreService* service = automation_->profile()->GetTabRestoreService(); |
| 1427 if (!service) { |
| 1428 AutomationJSONReply(automation_, reply_message_) |
| 1429 .SendError("No TabRestoreService."); |
| 1430 return; |
| 1431 } |
| 1432 |
| 1433 // Get the info that would be displayed in the recently closed section. |
| 1434 ListValue* recently_closed_list = new ListValue; |
| 1435 NewTabUI::AddRecentlyClosedEntries(service->entries(), |
| 1436 recently_closed_list); |
| 1437 ntp_info_->Set("recently_closed", recently_closed_list); |
| 1438 |
| 1439 // Add default site URLs. |
| 1440 ListValue* default_sites_list = new ListValue; |
| 1441 std::vector<GURL> urls = MostVisitedHandler::GetPrePopulatedUrls(); |
| 1442 for (size_t i = 0; i < urls.size(); ++i) { |
| 1443 default_sites_list->Append(Value::CreateStringValue( |
| 1444 urls[i].possibly_invalid_spec())); |
| 1445 } |
| 1446 ntp_info_->Set("default_sites", default_sites_list); |
| 1447 |
| 1448 registrar_.Add(this, NotificationType::TOP_SITES_UPDATED, |
| 1449 Source<history::TopSites>(top_sites_)); |
| 1450 if (top_sites_->loaded()) { |
| 1451 OnTopSitesLoaded(); |
| 1452 } else { |
| 1453 registrar_.Add(this, NotificationType::TOP_SITES_LOADED, |
| 1454 Source<Profile>(automation_->profile())); |
| 1455 } |
| 1456 } |
| 1457 |
| 1458 void NTPInfoObserver::Observe(NotificationType type, |
| 1459 const NotificationSource& source, |
| 1460 const NotificationDetails& details) { |
| 1461 if (type == NotificationType::TOP_SITES_LOADED) { |
| 1462 OnTopSitesLoaded(); |
| 1463 } else if (type == NotificationType::TOP_SITES_UPDATED) { |
| 1464 Details<CancelableRequestProvider::Handle> request_details(details); |
| 1465 if (request_ == *request_details.ptr()) { |
| 1466 top_sites_->GetMostVisitedURLs( |
| 1467 consumer_, |
| 1468 NewCallback(this, &NTPInfoObserver::OnTopSitesReceived)); |
| 1469 } |
| 1470 } |
| 1471 } |
| 1472 |
| 1473 void NTPInfoObserver::OnTopSitesLoaded() { |
| 1474 request_ = top_sites_->StartQueryForMostVisited(); |
| 1475 } |
| 1476 |
| 1477 void NTPInfoObserver::OnTopSitesReceived( |
| 1478 const history::MostVisitedURLList& visited_list) { |
| 1479 ListValue* list_value = new ListValue; |
| 1480 for (size_t i = 0; i < visited_list.size(); ++i) { |
| 1481 const history::MostVisitedURL& visited = visited_list[i]; |
| 1482 if (visited.url.spec().empty()) |
| 1483 break; // This is the signal that there are no more real visited sites. |
| 1484 DictionaryValue* dict = new DictionaryValue; |
| 1485 dict->SetString("url", visited.url.spec()); |
| 1486 dict->SetString("title", visited.title); |
| 1487 dict->SetBoolean("is_pinned", top_sites_->IsURLPinned(visited.url)); |
| 1488 list_value->Append(dict); |
| 1489 } |
| 1490 ntp_info_->Set("most_visited", list_value); |
| 1491 AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get()); |
| 1492 delete this; |
| 1493 } |
| 1494 |
| 1406 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( | 1495 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( |
| 1407 AutomationProvider* automation, | 1496 AutomationProvider* automation, |
| 1408 AutocompleteEditModel* autocomplete_edit, | 1497 AutocompleteEditModel* autocomplete_edit, |
| 1409 IPC::Message* reply_message) | 1498 IPC::Message* reply_message) |
| 1410 : automation_(automation), | 1499 : automation_(automation), |
| 1411 reply_message_(reply_message), | 1500 reply_message_(reply_message), |
| 1412 autocomplete_edit_model_(autocomplete_edit) { | 1501 autocomplete_edit_model_(autocomplete_edit) { |
| 1413 Source<AutocompleteEditModel> source(autocomplete_edit); | 1502 Source<AutocompleteEditModel> source(autocomplete_edit); |
| 1414 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); | 1503 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); |
| 1415 } | 1504 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1437 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged)); | 1526 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged)); |
| 1438 } | 1527 } |
| 1439 | 1528 |
| 1440 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { | 1529 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { |
| 1441 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) { | 1530 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) { |
| 1442 collection_->set_on_collection_changed_callback(NULL); | 1531 collection_->set_on_collection_changed_callback(NULL); |
| 1443 reply_.SendSuccess(NULL); | 1532 reply_.SendSuccess(NULL); |
| 1444 delete this; | 1533 delete this; |
| 1445 } | 1534 } |
| 1446 } | 1535 } |
| OLD | NEW |