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

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

Issue 10535120: TabContentsWrapper -> TabContents, part 43. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 if (args->GetInteger("height", &height)) 2087 if (args->GetInteger("height", &height))
2088 rect.set_height(height); 2088 rect.set_height(height);
2089 browser->window()->SetBounds(rect); 2089 browser->window()->SetBounds(rect);
2090 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2090 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2091 } 2091 }
2092 2092
2093 ListValue* TestingAutomationProvider::GetInfobarsInfo(WebContents* wc) { 2093 ListValue* TestingAutomationProvider::GetInfobarsInfo(WebContents* wc) {
2094 // Each infobar may have different properties depending on the type. 2094 // Each infobar may have different properties depending on the type.
2095 ListValue* infobars = new ListValue; 2095 ListValue* infobars = new ListValue;
2096 InfoBarTabHelper* infobar_helper = 2096 InfoBarTabHelper* infobar_helper =
2097 TabContents::GetOwningTabContentsForWebContents(wc)-> 2097 TabContents::FromWebContents(wc)->infobar_tab_helper();
2098 infobar_tab_helper();
2099 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { 2098 for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) {
2100 DictionaryValue* infobar_item = new DictionaryValue; 2099 DictionaryValue* infobar_item = new DictionaryValue;
2101 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i); 2100 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i);
2102 switch (infobar->GetInfoBarAutomationType()) { 2101 switch (infobar->GetInfoBarAutomationType()) {
2103 case InfoBarDelegate::CONFIRM_INFOBAR: 2102 case InfoBarDelegate::CONFIRM_INFOBAR:
2104 infobar_item->SetString("type", "confirm_infobar"); 2103 infobar_item->SetString("type", "confirm_infobar");
2105 break; 2104 break;
2106 case InfoBarDelegate::ONE_CLICK_LOGIN_INFOBAR: 2105 case InfoBarDelegate::ONE_CLICK_LOGIN_INFOBAR:
2107 infobar_item->SetString("type", "oneclicklogin_infobar"); 2106 infobar_item->SetString("type", "oneclicklogin_infobar");
2108 break; 2107 break;
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
3641 *error_message = StringPrintf("No tab at index %d.", tab_index); 3640 *error_message = StringPrintf("No tab at index %d.", tab_index);
3642 return NULL; 3641 return NULL;
3643 } 3642 }
3644 return tab_contents; 3643 return tab_contents;
3645 } 3644 }
3646 3645
3647 // Get the TranslateInfoBarDelegate from WebContents. 3646 // Get the TranslateInfoBarDelegate from WebContents.
3648 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( 3647 TranslateInfoBarDelegate* GetTranslateInfoBarDelegate(
3649 WebContents* web_contents) { 3648 WebContents* web_contents) {
3650 InfoBarTabHelper* infobar_helper = 3649 InfoBarTabHelper* infobar_helper =
3651 TabContents::GetOwningTabContentsForWebContents(web_contents)-> 3650 TabContents::FromWebContents(web_contents)->infobar_tab_helper();
3652 infobar_tab_helper();
3653 for (size_t i = 0; i < infobar_helper->infobar_count(); i++) { 3651 for (size_t i = 0; i < infobar_helper->infobar_count(); i++) {
3654 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i); 3652 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i);
3655 if (infobar->AsTranslateInfoBarDelegate()) 3653 if (infobar->AsTranslateInfoBarDelegate())
3656 return infobar->AsTranslateInfoBarDelegate(); 3654 return infobar->AsTranslateInfoBarDelegate();
3657 } 3655 }
3658 // No translate infobar. 3656 // No translate infobar.
3659 return NULL; 3657 return NULL;
3660 } 3658 }
3661 3659
3662 } // namespace 3660 } // namespace
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 WebContents* web_contents = tab_contents->web_contents(); 3720 WebContents* web_contents = tab_contents->web_contents();
3723 // Get the translate bar if there is one and pass it to the observer. 3721 // Get the translate bar if there is one and pass it to the observer.
3724 // The observer will check for null and populate the information accordingly. 3722 // The observer will check for null and populate the information accordingly.
3725 TranslateInfoBarDelegate* translate_bar = 3723 TranslateInfoBarDelegate* translate_bar =
3726 GetTranslateInfoBarDelegate(web_contents); 3724 GetTranslateInfoBarDelegate(web_contents);
3727 3725
3728 TabLanguageDeterminedObserver* observer = new TabLanguageDeterminedObserver( 3726 TabLanguageDeterminedObserver* observer = new TabLanguageDeterminedObserver(
3729 this, reply_message, web_contents, translate_bar); 3727 this, reply_message, web_contents, translate_bar);
3730 // If the language for the page hasn't been loaded yet, then just make 3728 // If the language for the page hasn't been loaded yet, then just make
3731 // the observer, otherwise call observe directly. 3729 // the observer, otherwise call observe directly.
3732 TranslateTabHelper* helper = TabContents::GetOwningTabContentsForWebContents( 3730 TranslateTabHelper* helper =
3733 web_contents)->translate_tab_helper(); 3731 TabContents::FromWebContents(web_contents)->translate_tab_helper();
3734 std::string language = helper->language_state().original_language(); 3732 std::string language = helper->language_state().original_language();
3735 if (!language.empty()) { 3733 if (!language.empty()) {
3736 observer->Observe(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 3734 observer->Observe(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
3737 content::Source<WebContents>(web_contents), 3735 content::Source<WebContents>(web_contents),
3738 content::Details<std::string>(&language)); 3736 content::Details<std::string>(&language));
3739 } 3737 }
3740 } 3738 }
3741 3739
3742 // See SelectTranslateOption() in chrome/test/pyautolib/pyauto.py for sample 3740 // See SelectTranslateOption() in chrome/test/pyautolib/pyauto.py for sample
3743 // json input. 3741 // json input.
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
4389 reply.SendError(error); 4387 reply.SendError(error);
4390 return; 4388 return;
4391 } 4389 }
4392 4390
4393 RenderViewHost* render_view = web_contents->GetRenderViewHost(); 4391 RenderViewHost* render_view = web_contents->GetRenderViewHost();
4394 if (!render_view) { 4392 if (!render_view) {
4395 reply.SendError("Tab has no associated RenderViewHost"); 4393 reply.SendError("Tab has no associated RenderViewHost");
4396 return; 4394 return;
4397 } 4395 }
4398 4396
4399 TabContents* tab_contents = 4397 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
4400 TabContents::GetOwningTabContentsForWebContents(web_contents);
4401 tab_contents->automation_tab_helper()->HeapProfilerDump(reason_string); 4398 tab_contents->automation_tab_helper()->HeapProfilerDump(reason_string);
4402 reply.SendSuccess(NULL); 4399 reply.SendSuccess(NULL);
4403 return; 4400 return;
4404 } 4401 }
4405 4402
4406 reply.SendError("Process type is not supported"); 4403 reply.SendError("Process type is not supported");
4407 } 4404 }
4408 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) 4405 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS))
4409 4406
4410 namespace { 4407 namespace {
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
6006 reply.SendError("'tab_id' is invalid"); 6003 reply.SendError("'tab_id' is invalid");
6007 return; 6004 return;
6008 } 6005 }
6009 if (has_handle && (!args->GetInteger("tab_handle", &id_or_handle) || 6006 if (has_handle && (!args->GetInteger("tab_handle", &id_or_handle) ||
6010 !tab_tracker_->ContainsHandle(id_or_handle))) { 6007 !tab_tracker_->ContainsHandle(id_or_handle))) {
6011 reply.SendError("'tab_handle' is invalid"); 6008 reply.SendError("'tab_handle' is invalid");
6012 return; 6009 return;
6013 } 6010 }
6014 int id = id_or_handle; 6011 int id = id_or_handle;
6015 if (has_handle) { 6012 if (has_handle) {
6016 TabContents* tab = TabContents::GetOwningTabContentsForWebContents( 6013 TabContents* tab = TabContents::FromWebContents(
6017 tab_tracker_->GetResource(id_or_handle)->GetWebContents()); 6014 tab_tracker_->GetResource(id_or_handle)->GetWebContents());
6018 id = tab->restore_tab_helper()->session_id().id(); 6015 id = tab->restore_tab_helper()->session_id().id();
6019 } 6016 }
6020 BrowserList::const_iterator iter = BrowserList::begin(); 6017 BrowserList::const_iterator iter = BrowserList::begin();
6021 int browser_index = 0; 6018 int browser_index = 0;
6022 for (; iter != BrowserList::end(); ++iter, ++browser_index) { 6019 for (; iter != BrowserList::end(); ++iter, ++browser_index) {
6023 Browser* browser = *iter; 6020 Browser* browser = *iter;
6024 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { 6021 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) {
6025 TabContents* tab = browser->GetTabContentsAt(tab_index); 6022 TabContents* tab = browser->GetTabContentsAt(tab_index);
6026 if (tab->restore_tab_helper()->session_id().id() == id) { 6023 if (tab->restore_tab_helper()->session_id().id() == id) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
6331 AutomationJSONReply(this, reply_message) 6328 AutomationJSONReply(this, reply_message)
6332 .SendError("'path' missing or invalid"); 6329 .SendError("'path' missing or invalid");
6333 return; 6330 return;
6334 } 6331 }
6335 6332
6336 RenderViewHost* render_view = web_contents->GetRenderViewHost(); 6333 RenderViewHost* render_view = web_contents->GetRenderViewHost();
6337 if (render_view) { 6334 if (render_view) {
6338 FilePath path(path_str); 6335 FilePath path(path_str);
6339 // This will delete itself when finished. 6336 // This will delete itself when finished.
6340 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( 6337 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker(
6341 this, reply_message, 6338 this, reply_message, TabContents::FromWebContents(web_contents), path);
6342 TabContents::GetOwningTabContentsForWebContents(web_contents), path);
6343 snapshot_taker->Start(); 6339 snapshot_taker->Start();
6344 } else { 6340 } else {
6345 AutomationJSONReply(this, reply_message) 6341 AutomationJSONReply(this, reply_message)
6346 .SendError("Tab has no associated RenderViewHost"); 6342 .SendError("Tab has no associated RenderViewHost");
6347 } 6343 }
6348 } 6344 }
6349 6345
6350 void TestingAutomationProvider::GetCookiesJSON( 6346 void TestingAutomationProvider::GetCookiesJSON(
6351 DictionaryValue* args, IPC::Message* reply_message) { 6347 DictionaryValue* args, IPC::Message* reply_message) {
6352 automation_util::GetCookiesJSON(this, args, reply_message); 6348 automation_util::GetCookiesJSON(this, args, reply_message);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
6641 6637
6642 NavigationController* controller = tab_tracker_->GetResource(tab_handle); 6638 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
6643 if (!controller) { 6639 if (!controller) {
6644 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, false); 6640 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_, false);
6645 Send(reply_message_); 6641 Send(reply_message_);
6646 return; 6642 return;
6647 } 6643 }
6648 6644
6649 // The delegate will delete itself. 6645 // The delegate will delete itself.
6650 new InfoBarCountObserver(this, reply_message, 6646 new InfoBarCountObserver(this, reply_message,
6651 TabContents::GetOwningTabContentsForWebContents( 6647 TabContents::FromWebContents(controller->GetWebContents()), target_count);
6652 controller->GetWebContents()), target_count);
6653 } 6648 }
6654 6649
6655 void TestingAutomationProvider::ResetToDefaultTheme() { 6650 void TestingAutomationProvider::ResetToDefaultTheme() {
6656 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); 6651 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme();
6657 } 6652 }
6658 6653
6659 void TestingAutomationProvider::WaitForProcessLauncherThreadToGoIdle( 6654 void TestingAutomationProvider::WaitForProcessLauncherThreadToGoIdle(
6660 IPC::Message* reply_message) { 6655 IPC::Message* reply_message) {
6661 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message); 6656 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message);
6662 } 6657 }
6663 6658
6664 void TestingAutomationProvider::OnRemoveProvider() { 6659 void TestingAutomationProvider::OnRemoveProvider() {
6665 if (g_browser_process) 6660 if (g_browser_process)
6666 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6661 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6667 } 6662 }
6668 6663
6669 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6664 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6670 WebContents* tab) { 6665 WebContents* tab) {
6671 if (browser->GetActiveWebContents() != tab || 6666 if (browser->GetActiveWebContents() != tab ||
6672 browser != BrowserList::GetLastActive()) { 6667 browser != BrowserList::GetLastActive()) {
6673 browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()), 6668 browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()),
6674 true /* user_gesture */); 6669 true /* user_gesture */);
6675 } 6670 }
6676 } 6671 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_win.cc ('k') | chrome/browser/debugger/devtools_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698