Chromium Code Reviews| Index: chrome/browser/automation/testing_automation_provider.cc |
| diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
| index 85cf92b829ddc39d5332bf2c1f58970fd730c137..feb34e64f0606196efc113b61d2d28c841109d59 100644 |
| --- a/chrome/browser/automation/testing_automation_provider.cc |
| +++ b/chrome/browser/automation/testing_automation_provider.cc |
| @@ -402,14 +402,8 @@ bool TestingAutomationProvider::OnMessageReceived( |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, |
| OpenNewBrowserWindowOfType) |
| IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) |
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, |
| - WaitForTabToBeRestored) |
| - IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) |
| - IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) |
| IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, |
| GetMetricEventDuration) |
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, |
| - ActionOnSSLBlockingPage) |
| IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) |
| IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, |
| HandleOpenFindInPageRequest) |
| @@ -1209,61 +1203,6 @@ void TestingAutomationProvider::GetWindowForBrowser(int browser_handle, |
| } |
| } |
| -void TestingAutomationProvider::WaitForTabToBeRestored( |
| - int tab_handle, |
| - IPC::Message* reply_message) { |
| - if (tab_tracker_->ContainsHandle(tab_handle)) { |
| - NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| - restore_tracker_.reset( |
| - new NavigationControllerRestoredObserver(this, tab, reply_message)); |
| - } else { |
| - AutomationMsg_WaitForTabToBeRestored::WriteReplyParams( |
| - reply_message, false); |
| - Send(reply_message); |
| - } |
| -} |
| - |
| -void TestingAutomationProvider::GetSecurityState( |
| - int handle, |
| - bool* success, |
| - content::SecurityStyle* security_style, |
| - net::CertStatus* ssl_cert_status, |
| - int* insecure_content_status) { |
| - if (tab_tracker_->ContainsHandle(handle)) { |
| - NavigationController* tab = tab_tracker_->GetResource(handle); |
| - NavigationEntry* entry = tab->GetActiveEntry(); |
| - *success = true; |
| - *security_style = entry->GetSSL().security_style; |
| - *ssl_cert_status = entry->GetSSL().cert_status; |
| - *insecure_content_status = entry->GetSSL().content_status; |
| - } else { |
| - *success = false; |
| - *security_style = content::SECURITY_STYLE_UNKNOWN; |
| - *ssl_cert_status = 0; |
| - *insecure_content_status = 0; |
| - } |
| -} |
| - |
| -void TestingAutomationProvider::GetPageType( |
| - int handle, |
| - bool* success, |
| - content::PageType* page_type) { |
| - if (tab_tracker_->ContainsHandle(handle)) { |
| - NavigationController* tab = tab_tracker_->GetResource(handle); |
| - NavigationEntry* entry = tab->GetActiveEntry(); |
| - *page_type = entry->GetPageType(); |
| - *success = true; |
| - // In order to return the proper result when an interstitial is shown and |
| - // no navigation entry were created for it we need to ask the WebContents. |
| - if (*page_type == content::PAGE_TYPE_NORMAL && |
| - tab->GetWebContents()->ShowingInterstitialPage()) |
| - *page_type = content::PAGE_TYPE_INTERSTITIAL; |
| - } else { |
| - *success = false; |
| - *page_type = content::PAGE_TYPE_NORMAL; |
| - } |
| -} |
| - |
| void TestingAutomationProvider::GetMetricEventDuration( |
| const std::string& event_name, |
| int* duration_ms) { |
| @@ -1271,38 +1210,6 @@ void TestingAutomationProvider::GetMetricEventDuration( |
| event_name); |
| } |
| -void TestingAutomationProvider::ActionOnSSLBlockingPage( |
| - int handle, |
| - bool proceed, |
| - IPC::Message* reply_message) { |
| - if (tab_tracker_->ContainsHandle(handle)) { |
| - NavigationController* tab = tab_tracker_->GetResource(handle); |
| - NavigationEntry* entry = tab->GetActiveEntry(); |
| - if (entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
| - WebContents* web_contents = tab->GetWebContents(); |
| - InterstitialPage* ssl_blocking_page = |
| - InterstitialPage::GetInterstitialPage(web_contents); |
| - if (ssl_blocking_page) { |
| - if (proceed) { |
| - new NavigationNotificationObserver(tab, this, reply_message, 1, |
| - false, false); |
| - ssl_blocking_page->Proceed(); |
| - return; |
| - } |
| - ssl_blocking_page->DontProceed(); |
| - AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| - reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); |
| - Send(reply_message); |
| - return; |
| - } |
| - } |
| - } |
| - // We failed. |
| - AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| - reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| - Send(reply_message); |
| -} |
| - |
| void TestingAutomationProvider::BringBrowserToFront(int browser_handle, |
| bool* success) { |
| *success = false; |
| @@ -1700,6 +1607,10 @@ void TestingAutomationProvider::BuildJSONHandlerMaps() { |
| &TestingAutomationProvider::GetAppModalDialogMessage; |
| handler_map_["AcceptOrDismissAppModalDialog"] = |
| &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
| + handler_map_["ActionOnSSLBlockingPage"] = |
| + &TestingAutomationProvider::ActionOnSSLBlockingPage; |
| + handler_map_["GetSecurityState"] = |
| + &TestingAutomationProvider::GetSecurityState; |
| handler_map_["GetChromeDriverAutomationVersion"] = |
| &TestingAutomationProvider::GetChromeDriverAutomationVersion; |
| handler_map_["IsPageActionVisible"] = |
| @@ -2081,7 +1992,8 @@ void TestingAutomationProvider::SendJSONRequest(Browser* browser, |
| (this->*handler_map_[command])(dict_value.get(), reply_message); |
| // Command has no handler. |
| } else { |
| - error_string = "Unknown command. Options: "; |
| + error_string = StringPrintf("Unknown command '%s'. Options: ", |
| + command.c_str()); |
| for (std::map<std::string, JsonHandler>::const_iterator it = |
| handler_map_.begin(); it != handler_map_.end(); ++it) { |
| error_string += it->first + ", "; |
| @@ -4412,6 +4324,61 @@ void TestingAutomationProvider::TriggerBrowserActionById( |
| } |
| } |
| +void TestingAutomationProvider::ActionOnSSLBlockingPage( |
| + DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + WebContents* web_contents; |
| + bool proceed; |
| + std::string error; |
| + if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
| + AutomationJSONReply(this, reply_message).SendError(error); |
| + return; |
| + } |
| + if (!args->GetBoolean("proceed", &proceed)) { |
| + AutomationJSONReply(this, reply_message).SendError( |
| + "'proceed' is missing or invalid"); |
| + return; |
| + } |
| + NavigationController& controller = web_contents->GetController(); |
| + NavigationEntry* entry = controller.GetActiveEntry(); |
| + if (entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
| + InterstitialPage* ssl_blocking_page = |
| + InterstitialPage::GetInterstitialPage(web_contents); |
| + if (ssl_blocking_page) { |
| + if (proceed) { |
| + new NavigationNotificationObserver(&controller, this, reply_message, 1, |
| + false, true); |
| + ssl_blocking_page->Proceed(); |
| + return; |
| + } |
| + ssl_blocking_page->DontProceed(); |
| + AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| + return; |
| + } |
| + } |
| + AutomationJSONReply(this, reply_message).SendError(error); |
| +} |
| + |
| +void TestingAutomationProvider::GetSecurityState(DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + AutomationJSONReply reply(this, reply_message); |
| + WebContents* web_contents; |
| + std::string error; |
| + if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
| + reply.SendError(error); |
| + return; |
| + } |
| + NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); |
| + DictionaryValue dict; |
| + dict.SetInteger("security_style", |
| + static_cast<int>(entry->GetSSL().security_style)); |
| + dict.SetInteger("ssl_cert_status", |
| + static_cast<int>(entry->GetSSL().cert_status)); |
| + dict.SetInteger("insecure_content_status", |
| + static_cast<int>(entry->GetSSL().content_status)); |
| + reply.SendSuccess(&dict); |
| +} |
| + |
| // Sample json input: { "command": "UpdateExtensionsNow" } |
| // Sample json output: {} |
| void TestingAutomationProvider::UpdateExtensionsNow( |
| @@ -6012,6 +5979,19 @@ void TestingAutomationProvider::WaitForAllViewsToStopLoading( |
| this, reply_message, profile()->GetExtensionProcessManager()); |
| } |
| +void TestingAutomationProvider::WaitForTabToBeRestored( |
| + DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + WebContents* web_contents; |
| + std::string error; |
| + if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
| + AutomationJSONReply(this, reply_message).SendError(error); |
| + return; |
| + } |
| + NavigationController& controller = web_contents->GetController(); |
| + new NavigationControllerRestoredObserver(this, &controller, reply_message); |
| +} |
| + |
| void TestingAutomationProvider::GetPolicyDefinitionList( |
| DictionaryValue* args, |
| IPC::Message* reply_message) { |
| @@ -6162,9 +6142,13 @@ void TestingAutomationProvider::NavigateToURL( |
| .SendError("'navigation_count' missing or invalid"); |
| return; |
| } |
| - new NavigationNotificationObserver( |
| - &web_contents->GetController(), this, reply_message, |
| - navigation_count, false, true); |
| + if (navigation_count > 0) { |
| + new NavigationNotificationObserver( |
| + &web_contents->GetController(), this, reply_message, |
| + navigation_count, false, true); |
| + } else { |
| + AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| + } |
| OpenURLParams params( |
| GURL(url), content::Referrer(), CURRENT_TAB, |
| content::PageTransitionFromInt( |
| @@ -6867,13 +6851,19 @@ void TestingAutomationProvider::CloseTabJSON( |
| Browser* browser; |
| WebContents* tab; |
| std::string error; |
| + bool wait_until_closed = false; // ChromeDriver does not use this. |
|
Nirnimesh
2012/08/07 00:37:35
nit: need 2 spaces before //
craigdh
2012/08/07 21:08:51
Done.
|
| + args->GetBoolean("wait_until_closed", &wait_until_closed); |
| // Close tabs synchronously. |
| if (GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) { |
| + if (wait_until_closed) { |
| + new TabClosedNotificationObserver(this, wait_until_closed, reply_message, |
| + true); |
| + } |
| chrome::CloseWebContents(browser, tab); |
| - reply.SendSuccess(NULL); |
| + if (!wait_until_closed) |
| + reply.SendSuccess(NULL); |
| return; |
| } |
| - |
| // Close other types of views asynchronously. |
| RenderViewHost* view; |
| if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |