Chromium Code Reviews| 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/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 Loading... | |
| 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), | |
|
Nirnimesh
2010/11/16 22:25:05
I think this needs to be indented only 4 chars
| |
| 1414 reply_message_(reply_message), | |
| 1415 consumer_(consumer), | |
| 1416 ntp_info_(new DictionaryValue) { | |
| 1417 top_sites_ = automation_->profile()->GetTopSites(); | |
| 1418 if (!top_sites_) { | |
| 1419 AutomationJSONReply(automation_, reply_message_) | |
| 1420 .SendError("Profile does not have service for querying the top sites."); | |
| 1421 return; | |
| 1422 } | |
| 1423 TabRestoreService* service = automation_->profile()->GetTabRestoreService(); | |
| 1424 if (!service) { | |
| 1425 AutomationJSONReply(automation_, reply_message_) | |
| 1426 .SendError("No TabRestoreService."); | |
| 1427 return; | |
| 1428 } | |
| 1429 | |
| 1430 // Get the info that would be displayed in the recently closed section. | |
| 1431 ListValue* recently_closed_list = new ListValue; | |
| 1432 NewTabUI::AddRecentlyClosedEntries(service->entries(), | |
| 1433 recently_closed_list); | |
|
Nirnimesh
2010/11/16 22:25:05
nit: this might fit above
| |
| 1434 ntp_info_->Set("recently_closed", recently_closed_list); | |
| 1435 | |
| 1436 top_sites_->RefreshAndCallback( | |
| 1437 NewCallback(this, &NTPInfoObserver::OnTopSitesRefreshed)); | |
| 1438 } | |
| 1439 | |
| 1440 void NTPInfoObserver::OnTopSitesRefreshed() { | |
| 1441 top_sites_->GetMostVisitedURLs( | |
| 1442 consumer_, | |
| 1443 NewCallback(this, &NTPInfoObserver::OnTopSitesReceived)); | |
| 1444 } | |
| 1445 | |
| 1446 void NTPInfoObserver::OnTopSitesReceived( | |
| 1447 const history::MostVisitedURLList& visited_list) { | |
| 1448 ListValue* list_value = new ListValue; | |
| 1449 for (size_t i = 0; i < visited_list.size(); ++i) { | |
| 1450 const history::MostVisitedURL& visited = visited_list[i]; | |
| 1451 if (visited.url.spec().empty()) | |
| 1452 break; // This is the signal that there are no more real visited sites. | |
| 1453 DictionaryValue* dict = new DictionaryValue; | |
| 1454 dict->SetString("url", visited.url.spec()); | |
| 1455 dict->SetString("title", visited.title); | |
| 1456 dict->SetBoolean("is_pinned", top_sites_->IsURLPinned(visited.url)); | |
| 1457 list_value->Append(dict); | |
| 1458 } | |
| 1459 ntp_info_->Set("most_visited", list_value); | |
| 1460 AutomationJSONReply(automation_, reply_message_).SendSuccess(ntp_info_.get()); | |
| 1461 delete this; | |
| 1462 } | |
| 1463 | |
| 1406 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( | 1464 AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( |
| 1407 AutomationProvider* automation, | 1465 AutomationProvider* automation, |
| 1408 AutocompleteEditModel* autocomplete_edit, | 1466 AutocompleteEditModel* autocomplete_edit, |
| 1409 IPC::Message* reply_message) | 1467 IPC::Message* reply_message) |
| 1410 : automation_(automation), | 1468 : automation_(automation), |
| 1411 reply_message_(reply_message), | 1469 reply_message_(reply_message), |
| 1412 autocomplete_edit_model_(autocomplete_edit) { | 1470 autocomplete_edit_model_(autocomplete_edit) { |
| 1413 Source<AutocompleteEditModel> source(autocomplete_edit); | 1471 Source<AutocompleteEditModel> source(autocomplete_edit); |
| 1414 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); | 1472 registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); |
| 1415 } | 1473 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1437 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged)); | 1495 this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged)); |
| 1438 } | 1496 } |
| 1439 | 1497 |
| 1440 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { | 1498 void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() { |
| 1441 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) { | 1499 if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) { |
| 1442 collection_->set_on_collection_changed_callback(NULL); | 1500 collection_->set_on_collection_changed_callback(NULL); |
| 1443 reply_.SendSuccess(NULL); | 1501 reply_.SendSuccess(NULL); |
| 1444 delete this; | 1502 delete this; |
| 1445 } | 1503 } |
| 1446 } | 1504 } |
| OLD | NEW |