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

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: fixes 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 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 } 1879 }
1879 1880
1880 void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) { 1881 void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) {
1881 *count = static_cast<size_t>(-1); // -1 means error. 1882 *count = static_cast<size_t>(-1); // -1 means error.
1882 if (tab_tracker_->ContainsHandle(handle)) { 1883 if (tab_tracker_->ContainsHandle(handle)) {
1883 NavigationController* nav_controller = tab_tracker_->GetResource(handle); 1884 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
1884 if (nav_controller) { 1885 if (nav_controller) {
1885 TabContentsWrapper* wrapper = 1886 TabContentsWrapper* wrapper =
1886 TabContentsWrapper::GetCurrentWrapperForContents( 1887 TabContentsWrapper::GetCurrentWrapperForContents(
1887 nav_controller->tab_contents()); 1888 nav_controller->tab_contents());
1888 *count = wrapper->infobar_count(); 1889 *count = wrapper->infobar_tab_helper()->infobar_count();
1889 } 1890 }
1890 } 1891 }
1891 } 1892 }
1892 1893
1893 void TestingAutomationProvider::ClickInfoBarAccept( 1894 void TestingAutomationProvider::ClickInfoBarAccept(
1894 int handle, 1895 int handle,
1895 size_t info_bar_index, 1896 size_t info_bar_index,
1896 bool wait_for_navigation, 1897 bool wait_for_navigation,
1897 IPC::Message* reply_message) { 1898 IPC::Message* reply_message) {
1898 bool success = false; 1899 bool success = false;
1899 if (tab_tracker_->ContainsHandle(handle)) { 1900 if (tab_tracker_->ContainsHandle(handle)) {
1900 NavigationController* nav_controller = tab_tracker_->GetResource(handle); 1901 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
1901 if (nav_controller) { 1902 if (nav_controller) {
1902 TabContentsWrapper* wrapper = 1903 InfoBarTabHelper* infobar_helper =
1903 TabContentsWrapper::GetCurrentWrapperForContents( 1904 TabContentsWrapper::GetCurrentWrapperForContents(
1904 nav_controller->tab_contents()); 1905 nav_controller->tab_contents())->infobar_tab_helper();
1905 if (info_bar_index < wrapper->infobar_count()) { 1906 if (info_bar_index < infobar_helper->infobar_count()) {
1906 if (wait_for_navigation) { 1907 if (wait_for_navigation) {
1907 new NavigationNotificationObserver(nav_controller, this, 1908 new NavigationNotificationObserver(nav_controller, this,
1908 reply_message, 1, false, false); 1909 reply_message, 1, false, false);
1909 } 1910 }
1910 InfoBarDelegate* delegate = 1911 InfoBarDelegate* delegate =
1911 TabContentsWrapper::GetCurrentWrapperForContents( 1912 infobar_helper->GetInfoBarDelegateAt(info_bar_index);
1912 nav_controller->tab_contents())->GetInfoBarDelegateAt(
1913 info_bar_index);
1914 if (delegate->AsConfirmInfoBarDelegate()) 1913 if (delegate->AsConfirmInfoBarDelegate())
1915 delegate->AsConfirmInfoBarDelegate()->Accept(); 1914 delegate->AsConfirmInfoBarDelegate()->Accept();
1916 success = true; 1915 success = true;
1917 } 1916 }
1918 } 1917 }
1919 } 1918 }
1920 1919
1921 // This "!wait_for_navigation || !success condition" logic looks suspicious. 1920 // This "!wait_for_navigation || !success condition" logic looks suspicious.
1922 // It will send a failure message when success is true but 1921 // It will send a failure message when success is true but
1923 // |wait_for_navigation| is false. 1922 // |wait_for_navigation| is false.
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 rect.set_width(width); 2520 rect.set_width(width);
2522 if (args->GetInteger("height", &height)) 2521 if (args->GetInteger("height", &height))
2523 rect.set_height(height); 2522 rect.set_height(height);
2524 browser->window()->SetBounds(rect); 2523 browser->window()->SetBounds(rect);
2525 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2524 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2526 } 2525 }
2527 2526
2528 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { 2527 ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) {
2529 // Each infobar may have different properties depending on the type. 2528 // Each infobar may have different properties depending on the type.
2530 ListValue* infobars = new ListValue; 2529 ListValue* infobars = new ListValue;
2531 TabContentsWrapper* wrapper = 2530 InfoBarTabHelper* infobar_helper =
2532 TabContentsWrapper::GetCurrentWrapperForContents(tc); 2531 TabContentsWrapper::GetCurrentWrapperForContents(tc)->
2533 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { 2532 infobar_tab_helper();
2533 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) {
2534 DictionaryValue* infobar_item = new DictionaryValue; 2534 DictionaryValue* infobar_item = new DictionaryValue;
2535 InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); 2535 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i);
2536 if (infobar->AsConfirmInfoBarDelegate()) { 2536 if (infobar->AsConfirmInfoBarDelegate()) {
2537 // Also covers ThemeInstalledInfoBarDelegate. 2537 // Also covers ThemeInstalledInfoBarDelegate.
2538 infobar_item->SetString("type", "confirm_infobar"); 2538 infobar_item->SetString("type", "confirm_infobar");
2539 ConfirmInfoBarDelegate* confirm_infobar = 2539 ConfirmInfoBarDelegate* confirm_infobar =
2540 infobar->AsConfirmInfoBarDelegate(); 2540 infobar->AsConfirmInfoBarDelegate();
2541 infobar_item->SetString("text", confirm_infobar->GetMessageText()); 2541 infobar_item->SetString("text", confirm_infobar->GetMessageText());
2542 infobar_item->SetString("link_text", confirm_infobar->GetLinkText()); 2542 infobar_item->SetString("link_text", confirm_infobar->GetLinkText());
2543 ListValue* buttons_list = new ListValue; 2543 ListValue* buttons_list = new ListValue;
2544 int buttons = confirm_infobar->GetButtons(); 2544 int buttons = confirm_infobar->GetButtons();
2545 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { 2545 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 AutomationJSONReply reply(this, reply_message); 2589 AutomationJSONReply reply(this, reply_message);
2590 int tab_index; 2590 int tab_index;
2591 int infobar_index_int; 2591 int infobar_index_int;
2592 std::string action; 2592 std::string action;
2593 if (!args->GetInteger("tab_index", &tab_index) || 2593 if (!args->GetInteger("tab_index", &tab_index) ||
2594 !args->GetInteger("infobar_index", &infobar_index_int) || 2594 !args->GetInteger("infobar_index", &infobar_index_int) ||
2595 !args->GetString("action", &action)) { 2595 !args->GetString("action", &action)) {
2596 reply.SendError("Invalid or missing args"); 2596 reply.SendError("Invalid or missing args");
2597 return; 2597 return;
2598 } 2598 }
2599
2599 TabContentsWrapper* tab_contents = 2600 TabContentsWrapper* tab_contents =
2600 browser->GetTabContentsWrapperAt(tab_index); 2601 browser->GetTabContentsWrapperAt(tab_index);
2601 if (!tab_contents) { 2602 if (!tab_contents) {
2602 reply.SendError(StringPrintf("No such tab at index %d", tab_index)); 2603 reply.SendError(StringPrintf("No such tab at index %d", tab_index));
2603 return; 2604 return;
2604 } 2605 }
2606 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
2607
2605 InfoBarDelegate* infobar = NULL; 2608 InfoBarDelegate* infobar = NULL;
2606 size_t infobar_index = static_cast<size_t>(infobar_index_int); 2609 size_t infobar_index = static_cast<size_t>(infobar_index_int);
2607 if (infobar_index >= tab_contents->infobar_count() || 2610 if (infobar_index >= infobar_helper->infobar_count()) {
2608 !(infobar = tab_contents->GetInfoBarDelegateAt(infobar_index))) {
2609 reply.SendError(StringPrintf("No such infobar at index %" PRIuS, 2611 reply.SendError(StringPrintf("No such infobar at index %" PRIuS,
2610 infobar_index)); 2612 infobar_index));
2611 return; 2613 return;
2612 } 2614 }
2615 infobar = infobar_helper->GetInfoBarDelegateAt(infobar_index);
2616
2613 if ("dismiss" == action) { 2617 if ("dismiss" == action) {
2614 infobar->InfoBarDismissed(); 2618 infobar->InfoBarDismissed();
2615 tab_contents->RemoveInfoBar(infobar); 2619 infobar_helper->RemoveInfoBar(infobar);
2616 reply.SendSuccess(NULL); 2620 reply.SendSuccess(NULL);
2617 return; 2621 return;
2618 } 2622 }
2619 if ("accept" == action || "cancel" == action) { 2623 if ("accept" == action || "cancel" == action) {
2620 ConfirmInfoBarDelegate* confirm_infobar; 2624 ConfirmInfoBarDelegate* confirm_infobar;
2621 if (!(confirm_infobar = infobar->AsConfirmInfoBarDelegate())) { 2625 if (!(confirm_infobar = infobar->AsConfirmInfoBarDelegate())) {
2622 reply.SendError("Not a confirm infobar"); 2626 reply.SendError("Not a confirm infobar");
2623 return; 2627 return;
2624 } 2628 }
2625 if ("accept" == action) { 2629 if ("accept" == action) {
2626 if (confirm_infobar->Accept()) 2630 if (confirm_infobar->Accept())
2627 tab_contents->RemoveInfoBar(infobar); 2631 infobar_helper->RemoveInfoBar(infobar);
2628 } else if ("cancel" == action) { 2632 } else if ("cancel" == action) {
2629 if (confirm_infobar->Cancel()) 2633 if (confirm_infobar->Cancel())
2630 tab_contents->RemoveInfoBar(infobar); 2634 infobar_helper->RemoveInfoBar(infobar);
2631 } 2635 }
2632 reply.SendSuccess(NULL); 2636 reply.SendSuccess(NULL);
2633 return; 2637 return;
2634 } 2638 }
2635 reply.SendError("Invalid action"); 2639 reply.SendError("Invalid action");
2636 } 2640 }
2637 2641
2638 namespace { 2642 namespace {
2639 2643
2640 // Task to get info about BrowserChildProcessHost. Must run on IO thread to 2644 // Task to get info about BrowserChildProcessHost. Must run on IO thread to
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
3889 if (!tab_contents) { 3893 if (!tab_contents) {
3890 *error_message = StringPrintf("No tab at index %d.", tab_index); 3894 *error_message = StringPrintf("No tab at index %d.", tab_index);
3891 return NULL; 3895 return NULL;
3892 } 3896 }
3893 return tab_contents; 3897 return tab_contents;
3894 } 3898 }
3895 3899
3896 // Get the TranslateInfoBarDelegate from TabContents. 3900 // Get the TranslateInfoBarDelegate from TabContents.
3897 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( 3901 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate(
3898 TabContents* tab_contents) { 3902 TabContents* tab_contents) {
3899 TabContentsWrapper* wrapper = 3903 InfoBarTabHelper* infobar_helper =
3900 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); 3904 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)->
3901 for (size_t i = 0; i < wrapper->infobar_count(); i++) { 3905 infobar_tab_helper();
3902 InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); 3906 for (size_t i = 0; i < infobar_helper->infobar_count(); i++) {
3907 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i);
3903 if (infobar->AsTranslateInfoBarDelegate()) 3908 if (infobar->AsTranslateInfoBarDelegate())
3904 return infobar->AsTranslateInfoBarDelegate(); 3909 return infobar->AsTranslateInfoBarDelegate();
3905 } 3910 }
3906 // No translate infobar. 3911 // No translate infobar.
3907 return NULL; 3912 return NULL;
3908 } 3913 }
3909 3914
3910 } // namespace 3915 } // namespace
3911 3916
3912 void TestingAutomationProvider::FindInPage( 3917 void TestingAutomationProvider::FindInPage(
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4094 if (!translate_bar->ShouldShowNeverTranslateButton()) { 4099 if (!translate_bar->ShouldShowNeverTranslateButton()) {
4095 reply.SendError("Always translate button not showing."); 4100 reply.SendError("Always translate button not showing.");
4096 return; 4101 return;
4097 } 4102 }
4098 translate_bar->NeverTranslatePageLanguage(); 4103 translate_bar->NeverTranslatePageLanguage();
4099 reply.SendSuccess(NULL); 4104 reply.SendSuccess(NULL);
4100 } else if (option == "decline_translation") { 4105 } else if (option == "decline_translation") {
4101 // This is the function called when an infobar is dismissed or when the 4106 // This is the function called when an infobar is dismissed or when the
4102 // user clicks the 'Nope' translate button. 4107 // user clicks the 'Nope' translate button.
4103 translate_bar->TranslationDeclined(); 4108 translate_bar->TranslationDeclined();
4104 tab_contents_wrapper->RemoveInfoBar(translate_bar); 4109 tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(translate_bar);
4105 reply.SendSuccess(NULL); 4110 reply.SendSuccess(NULL);
4106 } else { 4111 } else {
4107 reply.SendError("Invalid string found for option."); 4112 reply.SendError("Invalid string found for option.");
4108 } 4113 }
4109 } 4114 }
4110 4115
4111 // Sample json input: { "command": "GetBlockedPopupsInfo", 4116 // Sample json input: { "command": "GetBlockedPopupsInfo",
4112 // "tab_index": 1 } 4117 // "tab_index": 1 }
4113 // Refer GetBlockedPopupsInfo() in pyauto.py for sample output. 4118 // Refer GetBlockedPopupsInfo() in pyauto.py for sample output.
4114 void TestingAutomationProvider::GetBlockedPopupsInfo( 4119 void TestingAutomationProvider::GetBlockedPopupsInfo(
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
6332 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); 6337 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl);
6333 6338
6334 Send(reply_message_); 6339 Send(reply_message_);
6335 redirect_query_ = 0; 6340 redirect_query_ = 0;
6336 reply_message_ = NULL; 6341 reply_message_ = NULL;
6337 } 6342 }
6338 6343
6339 void TestingAutomationProvider::OnRemoveProvider() { 6344 void TestingAutomationProvider::OnRemoveProvider() {
6340 AutomationProviderList::GetInstance()->RemoveProvider(this); 6345 AutomationProviderList::GetInstance()->RemoveProvider(this);
6341 } 6346 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.cc ('k') | chrome/browser/chrome_quota_permission_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698