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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 7810002: Move infobar handling to a tab helper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 years, 3 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/download/download_prefs.h" 46 #include "chrome/browser/download/download_prefs.h"
47 #include "chrome/browser/download/save_package_file_picker.h" 47 #include "chrome/browser/download/save_package_file_picker.h"
48 #include "chrome/browser/extensions/extension_browser_event_router.h" 48 #include "chrome/browser/extensions/extension_browser_event_router.h"
49 #include "chrome/browser/extensions/extension_host.h" 49 #include "chrome/browser/extensions/extension_host.h"
50 #include "chrome/browser/extensions/extension_process_manager.h" 50 #include "chrome/browser/extensions/extension_process_manager.h"
51 #include "chrome/browser/extensions/extension_service.h" 51 #include "chrome/browser/extensions/extension_service.h"
52 #include "chrome/browser/extensions/extension_updater.h" 52 #include "chrome/browser/extensions/extension_updater.h"
53 #include "chrome/browser/history/top_sites.h" 53 #include "chrome/browser/history/top_sites.h"
54 #include "chrome/browser/importer/importer_host.h" 54 #include "chrome/browser/importer/importer_host.h"
55 #include "chrome/browser/importer/importer_list.h" 55 #include "chrome/browser/importer/importer_list.h"
56 #include "chrome/browser/infobars/infobar_tab_helper.h"
56 #include "chrome/browser/instant/instant_controller.h" 57 #include "chrome/browser/instant/instant_controller.h"
57 #include "chrome/browser/notifications/balloon.h" 58 #include "chrome/browser/notifications/balloon.h"
58 #include "chrome/browser/notifications/balloon_collection.h" 59 #include "chrome/browser/notifications/balloon_collection.h"
59 #include "chrome/browser/notifications/notification.h" 60 #include "chrome/browser/notifications/notification.h"
60 #include "chrome/browser/notifications/notification_ui_manager.h" 61 #include "chrome/browser/notifications/notification_ui_manager.h"
61 #include "chrome/browser/password_manager/password_store.h" 62 #include "chrome/browser/password_manager/password_store.h"
62 #include "chrome/browser/password_manager/password_store_change.h" 63 #include "chrome/browser/password_manager/password_store_change.h"
63 #include "chrome/browser/platform_util.h" 64 #include "chrome/browser/platform_util.h"
64 #include "chrome/browser/plugin_prefs.h" 65 #include "chrome/browser/plugin_prefs.h"
65 #include "chrome/browser/prefs/pref_service.h" 66 #include "chrome/browser/prefs/pref_service.h"
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 } 1875 }
1875 } 1876 }
1876 *success = false; 1877 *success = false;
1877 } 1878 }
1878 1879
1879 void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) { 1880 void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) {
1880 *count = static_cast<size_t>(-1); // -1 means error. 1881 *count = static_cast<size_t>(-1); // -1 means error.
1881 if (tab_tracker_->ContainsHandle(handle)) { 1882 if (tab_tracker_->ContainsHandle(handle)) {
1882 NavigationController* nav_controller = tab_tracker_->GetResource(handle); 1883 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
1883 if (nav_controller) { 1884 if (nav_controller) {
1884 TabContentsWrapper* wrapper = 1885 TabContentsWrapper* wrapper =
Peter Kasting 2011/08/31 18:47:32 Nit: Just combine these two lines
1885 TabContentsWrapper::GetCurrentWrapperForContents( 1886 TabContentsWrapper::GetCurrentWrapperForContents(
1886 nav_controller->tab_contents()); 1887 nav_controller->tab_contents());
1887 *count = wrapper->infobar_count(); 1888 *count = wrapper->infobar_tab_helper()->infobar_count();
1888 } 1889 }
1889 } 1890 }
1890 } 1891 }
1891 1892
1892 void TestingAutomationProvider::ClickInfoBarAccept( 1893 void TestingAutomationProvider::ClickInfoBarAccept(
1893 int handle, 1894 int handle,
1894 size_t info_bar_index, 1895 size_t info_bar_index,
1895 bool wait_for_navigation, 1896 bool wait_for_navigation,
1896 IPC::Message* reply_message) { 1897 IPC::Message* reply_message) {
1897 bool success = false; 1898 bool success = false;
1898 if (tab_tracker_->ContainsHandle(handle)) { 1899 if (tab_tracker_->ContainsHandle(handle)) {
1899 NavigationController* nav_controller = tab_tracker_->GetResource(handle); 1900 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
1900 if (nav_controller) { 1901 if (nav_controller) {
1901 TabContentsWrapper* wrapper = 1902 TabContentsWrapper* wrapper =
Peter Kasting 2011/08/31 18:47:32 Nit: Convert this TCW* temp into an InfoBarTabHelp
1902 TabContentsWrapper::GetCurrentWrapperForContents( 1903 TabContentsWrapper::GetCurrentWrapperForContents(
1903 nav_controller->tab_contents()); 1904 nav_controller->tab_contents());
1904 if (info_bar_index < wrapper->infobar_count()) { 1905 if (info_bar_index < wrapper->infobar_tab_helper()->infobar_count()) {
1905 if (wait_for_navigation) { 1906 if (wait_for_navigation) {
1906 new NavigationNotificationObserver(nav_controller, this, 1907 new NavigationNotificationObserver(nav_controller, this,
1907 reply_message, 1, false, false); 1908 reply_message, 1, false, false);
1908 } 1909 }
1909 InfoBarDelegate* delegate = 1910 InfoBarDelegate* delegate =
1910 TabContentsWrapper::GetCurrentWrapperForContents( 1911 TabContentsWrapper::GetCurrentWrapperForContents(
1911 nav_controller->tab_contents())->GetInfoBarDelegateAt( 1912 nav_controller->tab_contents())->infobar_tab_helper()->
1912 info_bar_index); 1913 GetInfoBarDelegateAt(info_bar_index);
1913 if (delegate->AsConfirmInfoBarDelegate()) 1914 if (delegate->AsConfirmInfoBarDelegate())
1914 delegate->AsConfirmInfoBarDelegate()->Accept(); 1915 delegate->AsConfirmInfoBarDelegate()->Accept();
1915 success = true; 1916 success = true;
1916 } 1917 }
1917 } 1918 }
1918 } 1919 }
1919 1920
1920 // This "!wait_for_navigation || !success condition" logic looks suspicious. 1921 // This "!wait_for_navigation || !success condition" logic looks suspicious.
1921 // It will send a failure message when success is true but 1922 // It will send a failure message when success is true but
1922 // |wait_for_navigation| is false. 1923 // |wait_for_navigation| is false.
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 rect.set_width(width); 2521 rect.set_width(width);
2521 if (args->GetInteger("height", &height)) 2522 if (args->GetInteger("height", &height))
2522 rect.set_height(height); 2523 rect.set_height(height);
2523 browser->window()->SetBounds(rect); 2524 browser->window()->SetBounds(rect);
2524 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2525 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2525 } 2526 }
2526 2527
2527 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { 2528 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) {
2528 // Each infobar may have different properties depending on the type. 2529 // Each infobar may have different properties depending on the type.
2529 ListValue* infobars = new ListValue; 2530 ListValue* infobars = new ListValue;
2530 TabContentsWrapper* wrapper = 2531 TabContentsWrapper* wrapper =
Peter Kasting 2011/08/31 18:47:32 Nit: Convert this TCW* temp into an InfoBarTabHelp
2531 TabContentsWrapper::GetCurrentWrapperForContents(tc); 2532 TabContentsWrapper::GetCurrentWrapperForContents(tc);
2532 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { 2533 for (size_t i = 0; i < wrapper->infobar_tab_helper()->infobar_count(); ++i) {
2533 DictionaryValue* infobar_item = new DictionaryValue; 2534 DictionaryValue* infobar_item = new DictionaryValue;
2534 InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); 2535 InfoBarDelegate* infobar =
2536 wrapper->infobar_tab_helper()->GetInfoBarDelegateAt(i);
2535 if (infobar->AsConfirmInfoBarDelegate()) { 2537 if (infobar->AsConfirmInfoBarDelegate()) {
2536 // Also covers ThemeInstalledInfoBarDelegate. 2538 // Also covers ThemeInstalledInfoBarDelegate.
2537 infobar_item->SetString("type", "confirm_infobar"); 2539 infobar_item->SetString("type", "confirm_infobar");
2538 ConfirmInfoBarDelegate* confirm_infobar = 2540 ConfirmInfoBarDelegate* confirm_infobar =
2539 infobar->AsConfirmInfoBarDelegate(); 2541 infobar->AsConfirmInfoBarDelegate();
2540 infobar_item->SetString("text", confirm_infobar->GetMessageText()); 2542 infobar_item->SetString("text", confirm_infobar->GetMessageText());
2541 infobar_item->SetString("link_text", confirm_infobar->GetLinkText()); 2543 infobar_item->SetString("link_text", confirm_infobar->GetLinkText());
2542 ListValue* buttons_list = new ListValue; 2544 ListValue* buttons_list = new ListValue;
2543 int buttons = confirm_infobar->GetButtons(); 2545 int buttons = confirm_infobar->GetButtons();
2544 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { 2546 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 return; 2598 return;
2597 } 2599 }
2598 TabContentsWrapper* tab_contents = 2600 TabContentsWrapper* tab_contents =
2599 browser->GetTabContentsWrapperAt(tab_index); 2601 browser->GetTabContentsWrapperAt(tab_index);
2600 if (!tab_contents) { 2602 if (!tab_contents) {
2601 reply.SendError(StringPrintf("No such tab at index %d", tab_index)); 2603 reply.SendError(StringPrintf("No such tab at index %d", tab_index));
2602 return; 2604 return;
2603 } 2605 }
2604 InfoBarDelegate* infobar = NULL; 2606 InfoBarDelegate* infobar = NULL;
2605 size_t infobar_index = static_cast<size_t>(infobar_index_int); 2607 size_t infobar_index = static_cast<size_t>(infobar_index_int);
2606 if (infobar_index >= tab_contents->infobar_count() || 2608 if (infobar_index >= tab_contents->infobar_tab_helper()->infobar_count() ||
Peter Kasting 2011/08/31 18:47:32 Nit: Can you factor this infobar_tab_helper() out
2607 !(infobar = tab_contents->GetInfoBarDelegateAt(infobar_index))) { 2609 !(infobar = tab_contents->infobar_tab_helper()->
Peter Kasting 2011/08/31 18:47:32 Nit: This assignment can be pulled out of the cond
2610 GetInfoBarDelegateAt(infobar_index))) {
2608 reply.SendError(StringPrintf("No such infobar at index %" PRIuS, 2611 reply.SendError(StringPrintf("No such infobar at index %" PRIuS,
2609 infobar_index)); 2612 infobar_index));
2610 return; 2613 return;
2611 } 2614 }
2612 if ("dismiss" == action) { 2615 if ("dismiss" == action) {
2613 infobar->InfoBarDismissed(); 2616 infobar->InfoBarDismissed();
2614 tab_contents->RemoveInfoBar(infobar); 2617 tab_contents->infobar_tab_helper()->RemoveInfoBar(infobar);
2615 reply.SendSuccess(NULL); 2618 reply.SendSuccess(NULL);
2616 return; 2619 return;
2617 } 2620 }
2618 if ("accept" == action || "cancel" == action) { 2621 if ("accept" == action || "cancel" == action) {
2619 ConfirmInfoBarDelegate* confirm_infobar; 2622 ConfirmInfoBarDelegate* confirm_infobar;
2620 if (!(confirm_infobar = infobar->AsConfirmInfoBarDelegate())) { 2623 if (!(confirm_infobar = infobar->AsConfirmInfoBarDelegate())) {
2621 reply.SendError("Not a confirm infobar"); 2624 reply.SendError("Not a confirm infobar");
2622 return; 2625 return;
2623 } 2626 }
2624 if ("accept" == action) { 2627 if ("accept" == action) {
2625 if (confirm_infobar->Accept()) 2628 if (confirm_infobar->Accept())
2626 tab_contents->RemoveInfoBar(infobar); 2629 tab_contents->infobar_tab_helper()->RemoveInfoBar(infobar);
2627 } else if ("cancel" == action) { 2630 } else if ("cancel" == action) {
2628 if (confirm_infobar->Cancel()) 2631 if (confirm_infobar->Cancel())
2629 tab_contents->RemoveInfoBar(infobar); 2632 tab_contents->infobar_tab_helper()->RemoveInfoBar(infobar);
2630 } 2633 }
2631 reply.SendSuccess(NULL); 2634 reply.SendSuccess(NULL);
2632 return; 2635 return;
2633 } 2636 }
2634 reply.SendError("Invalid action"); 2637 reply.SendError("Invalid action");
2635 } 2638 }
2636 2639
2637 namespace { 2640 namespace {
2638 2641
2639 // Task to get info about BrowserChildProcessHost. Must run on IO thread to 2642 // Task to get info about BrowserChildProcessHost. Must run on IO thread to
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
3888 if (!tab_contents) { 3891 if (!tab_contents) {
3889 *error_message = StringPrintf("No tab at index %d.", tab_index); 3892 *error_message = StringPrintf("No tab at index %d.", tab_index);
3890 return NULL; 3893 return NULL;
3891 } 3894 }
3892 return tab_contents; 3895 return tab_contents;
3893 } 3896 }
3894 3897
3895 // Get the TranslateInfoBarDelegate from TabContents. 3898 // Get the TranslateInfoBarDelegate from TabContents.
3896 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( 3899 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate(
3897 TabContents* tab_contents) { 3900 TabContents* tab_contents) {
3898 TabContentsWrapper* wrapper = 3901 TabContentsWrapper* wrapper =
Peter Kasting 2011/08/31 18:47:32 Nit: Convert this TCW* temp into an InfoBarTabHelp
3899 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); 3902 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
3900 for (size_t i = 0; i < wrapper->infobar_count(); i++) { 3903 for (size_t i = 0; i < wrapper->infobar_tab_helper()->infobar_count(); i++) {
3901 InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); 3904 InfoBarDelegate* infobar =
3905 wrapper->infobar_tab_helper()->GetInfoBarDelegateAt(i);
3902 if (infobar->AsTranslateInfoBarDelegate()) 3906 if (infobar->AsTranslateInfoBarDelegate())
3903 return infobar->AsTranslateInfoBarDelegate(); 3907 return infobar->AsTranslateInfoBarDelegate();
3904 } 3908 }
3905 // No translate infobar. 3909 // No translate infobar.
3906 return NULL; 3910 return NULL;
3907 } 3911 }
3908 3912
3909 } // namespace 3913 } // namespace
3910 3914
3911 void TestingAutomationProvider::FindInPage( 3915 void TestingAutomationProvider::FindInPage(
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4093 if (!translate_bar->ShouldShowNeverTranslateButton()) { 4097 if (!translate_bar->ShouldShowNeverTranslateButton()) {
4094 reply.SendError("Always translate button not showing."); 4098 reply.SendError("Always translate button not showing.");
4095 return; 4099 return;
4096 } 4100 }
4097 translate_bar->NeverTranslatePageLanguage(); 4101 translate_bar->NeverTranslatePageLanguage();
4098 reply.SendSuccess(NULL); 4102 reply.SendSuccess(NULL);
4099 } else if (option == "decline_translation") { 4103 } else if (option == "decline_translation") {
4100 // This is the function called when an infobar is dismissed or when the 4104 // This is the function called when an infobar is dismissed or when the
4101 // user clicks the 'Nope' translate button. 4105 // user clicks the 'Nope' translate button.
4102 translate_bar->TranslationDeclined(); 4106 translate_bar->TranslationDeclined();
4103 tab_contents_wrapper->RemoveInfoBar(translate_bar); 4107 tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(translate_bar);
4104 reply.SendSuccess(NULL); 4108 reply.SendSuccess(NULL);
4105 } else { 4109 } else {
4106 reply.SendError("Invalid string found for option."); 4110 reply.SendError("Invalid string found for option.");
4107 } 4111 }
4108 } 4112 }
4109 4113
4110 // Sample json input: { "command": "GetBlockedPopupsInfo", 4114 // Sample json input: { "command": "GetBlockedPopupsInfo",
4111 // "tab_index": 1 } 4115 // "tab_index": 1 }
4112 // Refer GetBlockedPopupsInfo() in pyauto.py for sample output. 4116 // Refer GetBlockedPopupsInfo() in pyauto.py for sample output.
4113 void TestingAutomationProvider::GetBlockedPopupsInfo( 4117 void TestingAutomationProvider::GetBlockedPopupsInfo(
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
6331 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); 6335 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl);
6332 6336
6333 Send(reply_message_); 6337 Send(reply_message_);
6334 redirect_query_ = 0; 6338 redirect_query_ = 0;
6335 reply_message_ = NULL; 6339 reply_message_ = NULL;
6336 } 6340 }
6337 6341
6338 void TestingAutomationProvider::OnRemoveProvider() { 6342 void TestingAutomationProvider::OnRemoveProvider() {
6339 AutomationProviderList::GetInstance()->RemoveProvider(this); 6343 AutomationProviderList::GetInstance()->RemoveProvider(this);
6340 } 6344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698