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 c86a5de679f420b5fabb256140f3756c016a0cc1..46ddc9ec749277c2f71ecae139147ba470ebfc89 100644 |
| --- a/chrome/browser/automation/testing_automation_provider.cc |
| +++ b/chrome/browser/automation/testing_automation_provider.cc |
| @@ -439,7 +439,9 @@ bool TestingAutomationProvider::OnMessageReceived( |
| GoForwardBlockUntilNavigationsComplete) |
| IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, |
| - SendJSONRequest) |
| + SendJSONRequestWithHandle) |
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequestWithIndex, |
| + SendJSONRequestWithIndex) |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, |
| WaitForTabCountToBecome) |
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, |
| @@ -1630,431 +1632,462 @@ void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) { |
| } |
| } |
| -void TestingAutomationProvider::SendJSONRequest(int handle, |
| - const std::string& json_request, |
| - IPC::Message* reply_message) { |
| - std::string error; |
| - scoped_ptr<Value> values(base::JSONReader::ReadAndReturnError(json_request, |
| - base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error)); |
| - if (!error.empty()) { |
| - AutomationJSONReply(this, reply_message).SendError(error); |
| - return; |
| - } |
| - |
| - // Make sure input is a dict with a string command. |
| - std::string command; |
| - DictionaryValue* dict_value = NULL; |
| - if (values->GetType() != Value::TYPE_DICTIONARY) { |
| - AutomationJSONReply(this, reply_message).SendError("not a dict"); |
| - return; |
| - } |
| - // Ownership remains with "values" variable. |
| - dict_value = static_cast<DictionaryValue*>(values.get()); |
| - if (!dict_value->GetStringASCII(std::string("command"), &command)) { |
| - AutomationJSONReply(this, reply_message) |
| - .SendError("no command key in dict or not a string command"); |
| - return; |
| - } |
| +void TestingAutomationProvider::BuildJSONHandlerMaps( |
|
Nirnimesh
2012/06/14 22:16:42
The whole handler map gets initialized for each au
craigdh
2012/06/15 19:24:53
Done.
|
| + std::map<std::string, JsonHandler>* handler_map, |
| + std::map<std::string, BrowserJsonHandler>* browser_handler_map) { |
| // Map json commands to their handlers. |
| - std::map<std::string, JsonHandler> handler_map; |
| - handler_map["WaitForAllTabsToStopLoading"] = |
| + (*handler_map)["WaitForAllTabsToStopLoading"] = |
| &TestingAutomationProvider::WaitForAllViewsToStopLoading; |
| - handler_map["GetIndicesFromTab"] = |
| + (*handler_map)["GetIndicesFromTab"] = |
| &TestingAutomationProvider::GetIndicesFromTab; |
| - handler_map["NavigateToURL"] = |
| + (*handler_map)["NavigateToURL"] = |
| &TestingAutomationProvider::NavigateToURL; |
| - handler_map["WaitUntilNavigationCompletes"] = |
| + (*handler_map)["WaitUntilNavigationCompletes"] = |
| &TestingAutomationProvider::WaitUntilNavigationCompletes; |
| - handler_map["GetLocalStatePrefsInfo"] = |
| + (*handler_map)["GetLocalStatePrefsInfo"] = |
| &TestingAutomationProvider::GetLocalStatePrefsInfo; |
| - handler_map["SetLocalStatePrefs"] = |
| + (*handler_map)["SetLocalStatePrefs"] = |
| &TestingAutomationProvider::SetLocalStatePrefs; |
| - handler_map["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
| - handler_map["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
| - handler_map["ExecuteJavascript"] = |
| + (*handler_map)["GetPrefsInfo"] = &TestingAutomationProvider::GetPrefsInfo; |
| + (*handler_map)["SetPrefs"] = &TestingAutomationProvider::SetPrefs; |
| + (*handler_map)["ExecuteJavascript"] = |
| &TestingAutomationProvider::ExecuteJavascriptJSON; |
| - handler_map["AddDomEventObserver"] = |
| + (*handler_map)["AddDomEventObserver"] = |
| &TestingAutomationProvider::AddDomEventObserver; |
| - handler_map["RemoveEventObserver"] = |
| + (*handler_map)["RemoveEventObserver"] = |
| &TestingAutomationProvider::RemoveEventObserver; |
| - handler_map["GetNextEvent"] = |
| + (*handler_map)["GetNextEvent"] = |
| &TestingAutomationProvider::GetNextEvent; |
| - handler_map["ClearEventQueue"] = |
| + (*handler_map)["ClearEventQueue"] = |
| &TestingAutomationProvider::ClearEventQueue; |
| - handler_map["ExecuteJavascriptInRenderView"] = |
| + (*handler_map)["ExecuteJavascriptInRenderView"] = |
| &TestingAutomationProvider::ExecuteJavascriptInRenderView; |
| - handler_map["GoForward"] = |
| + (*handler_map)["GoForward"] = |
| &TestingAutomationProvider::GoForward; |
| - handler_map["GoBack"] = |
| + (*handler_map)["GoBack"] = |
| &TestingAutomationProvider::GoBack; |
| - handler_map["Reload"] = |
| + (*handler_map)["Reload"] = |
| &TestingAutomationProvider::ReloadJSON; |
| - handler_map["CaptureEntirePage"] = |
| + (*handler_map)["CaptureEntirePage"] = |
| &TestingAutomationProvider::CaptureEntirePageJSON; |
| - handler_map["GetCookies"] = |
| + (*handler_map)["GetCookies"] = |
| &TestingAutomationProvider::GetCookiesJSON; |
| - handler_map["DeleteCookie"] = |
| + (*handler_map)["DeleteCookie"] = |
| &TestingAutomationProvider::DeleteCookieJSON; |
| - handler_map["SetCookie"] = |
| + (*handler_map)["SetCookie"] = |
| &TestingAutomationProvider::SetCookieJSON; |
| - handler_map["GetTabIds"] = |
| + (*handler_map)["GetTabIds"] = |
| &TestingAutomationProvider::GetTabIds; |
| - handler_map["GetViews"] = |
| + (*handler_map)["GetViews"] = |
| &TestingAutomationProvider::GetViews; |
| - handler_map["IsTabIdValid"] = |
| + (*handler_map)["IsTabIdValid"] = |
| &TestingAutomationProvider::IsTabIdValid; |
| - handler_map["DoesAutomationObjectExist"] = |
| + (*handler_map)["DoesAutomationObjectExist"] = |
| &TestingAutomationProvider::DoesAutomationObjectExist; |
| - handler_map["CloseTab"] = |
| + (*handler_map)["CloseTab"] = |
| &TestingAutomationProvider::CloseTabJSON; |
| - handler_map["SetViewBounds"] = |
| + (*handler_map)["SetViewBounds"] = |
| &TestingAutomationProvider::SetViewBounds; |
| - handler_map["WebkitMouseMove"] = |
| + (*handler_map)["WebkitMouseMove"] = |
| &TestingAutomationProvider::WebkitMouseMove; |
| - handler_map["WebkitMouseClick"] = |
| + (*handler_map)["WebkitMouseClick"] = |
| &TestingAutomationProvider::WebkitMouseClick; |
| - handler_map["WebkitMouseDrag"] = |
| + (*handler_map)["WebkitMouseDrag"] = |
| &TestingAutomationProvider::WebkitMouseDrag; |
| - handler_map["WebkitMouseButtonUp"] = |
| + (*handler_map)["WebkitMouseButtonUp"] = |
| &TestingAutomationProvider::WebkitMouseButtonUp; |
| - handler_map["WebkitMouseButtonDown"] = |
| + (*handler_map)["WebkitMouseButtonDown"] = |
| &TestingAutomationProvider::WebkitMouseButtonDown; |
| - handler_map["WebkitMouseDoubleClick"] = |
| + (*handler_map)["WebkitMouseDoubleClick"] = |
| &TestingAutomationProvider::WebkitMouseDoubleClick; |
| - handler_map["DragAndDropFilePaths"] = |
| + (*handler_map)["DragAndDropFilePaths"] = |
| &TestingAutomationProvider::DragAndDropFilePaths; |
| - handler_map["SendWebkitKeyEvent"] = |
| + (*handler_map)["SendWebkitKeyEvent"] = |
| &TestingAutomationProvider::SendWebkitKeyEvent; |
| - handler_map["SendOSLevelKeyEventToTab"] = |
| + (*handler_map)["SendOSLevelKeyEventToTab"] = |
| &TestingAutomationProvider::SendOSLevelKeyEventToTab; |
| - handler_map["ProcessWebMouseEvent"] = |
| + (*handler_map)["ProcessWebMouseEvent"] = |
| &TestingAutomationProvider::ProcessWebMouseEvent; |
| - handler_map["ActivateTab"] = |
| + (*handler_map)["ActivateTab"] = |
| &TestingAutomationProvider::ActivateTabJSON; |
| - handler_map["GetAppModalDialogMessage"] = |
| + (*handler_map)["GetAppModalDialogMessage"] = |
| &TestingAutomationProvider::GetAppModalDialogMessage; |
| - handler_map["AcceptOrDismissAppModalDialog"] = |
| + (*handler_map)["AcceptOrDismissAppModalDialog"] = |
| &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
| - handler_map["GetChromeDriverAutomationVersion"] = |
| + (*handler_map)["GetChromeDriverAutomationVersion"] = |
| &TestingAutomationProvider::GetChromeDriverAutomationVersion; |
| - handler_map["IsPageActionVisible"] = |
| + (*handler_map)["IsPageActionVisible"] = |
| &TestingAutomationProvider::IsPageActionVisible; |
| - handler_map["CreateNewAutomationProvider"] = |
| + (*handler_map)["CreateNewAutomationProvider"] = |
| &TestingAutomationProvider::CreateNewAutomationProvider; |
| - handler_map["GetBrowserInfo"] = |
| + (*handler_map)["GetBrowserInfo"] = |
| &TestingAutomationProvider::GetBrowserInfo; |
| - handler_map["OpenNewBrowserWindowWithNewProfile"] = |
| + (*handler_map)["OpenNewBrowserWindowWithNewProfile"] = |
| &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; |
| - handler_map["GetMultiProfileInfo"] = |
| + (*handler_map)["GetMultiProfileInfo"] = |
| &TestingAutomationProvider::GetMultiProfileInfo; |
| - handler_map["GetProcessInfo"] = |
| + (*handler_map)["GetProcessInfo"] = |
| &TestingAutomationProvider::GetProcessInfo; |
| - handler_map["GetPolicyDefinitionList"] = |
| + (*handler_map)["GetPolicyDefinitionList"] = |
| &TestingAutomationProvider::GetPolicyDefinitionList; |
| - handler_map["RefreshPolicies"] = |
| + (*handler_map)["RefreshPolicies"] = |
| &TestingAutomationProvider::RefreshPolicies; |
| - handler_map["InstallExtension"] = |
| + (*handler_map)["InstallExtension"] = |
| &TestingAutomationProvider::InstallExtension; |
| - handler_map["GetExtensionsInfo"] = |
| + (*handler_map)["GetExtensionsInfo"] = |
| &TestingAutomationProvider::GetExtensionsInfo; |
| - handler_map["UninstallExtensionById"] = |
| + (*handler_map)["UninstallExtensionById"] = |
| &TestingAutomationProvider::UninstallExtensionById; |
| - handler_map["SetExtensionStateById"] = |
| + (*handler_map)["SetExtensionStateById"] = |
| &TestingAutomationProvider::SetExtensionStateById; |
| - handler_map["TriggerPageActionById"] = |
| + (*handler_map)["TriggerPageActionById"] = |
| &TestingAutomationProvider::TriggerPageActionById; |
| - handler_map["TriggerBrowserActionById"] = |
| + (*handler_map)["TriggerBrowserActionById"] = |
| &TestingAutomationProvider::TriggerBrowserActionById; |
| - handler_map["UpdateExtensionsNow"] = |
| + (*handler_map)["UpdateExtensionsNow"] = |
| &TestingAutomationProvider::UpdateExtensionsNow; |
| #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| - handler_map["HeapProfilerDump"] = |
| + (*handler_map)["HeapProfilerDump"] = |
| &TestingAutomationProvider::HeapProfilerDump; |
| #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| - handler_map["OverrideGeoposition"] = |
| + (*handler_map)["OverrideGeoposition"] = |
| &TestingAutomationProvider::OverrideGeoposition; |
| - handler_map["AppendSwitchASCIIToCommandLine"] = |
| + (*handler_map)["AppendSwitchASCIIToCommandLine"] = |
| &TestingAutomationProvider::AppendSwitchASCIIToCommandLine; |
| - handler_map["SimulateAsanMemoryBug"] = |
| + (*handler_map)["SimulateAsanMemoryBug"] = |
| &TestingAutomationProvider::SimulateAsanMemoryBug; |
| #if defined(OS_CHROMEOS) |
| - handler_map["AcceptOOBENetworkScreen"] = |
| + (*handler_map)["AcceptOOBENetworkScreen"] = |
| &TestingAutomationProvider::AcceptOOBENetworkScreen; |
| - handler_map["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; |
| - handler_map["CancelOOBEUpdate"] = |
| + (*handler_map)["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; |
| + (*handler_map)["CancelOOBEUpdate"] = |
| &TestingAutomationProvider::CancelOOBEUpdate; |
| - handler_map["PickUserImage"] = &TestingAutomationProvider::PickUserImage; |
| - handler_map["SkipToLogin"] = &TestingAutomationProvider::SkipToLogin; |
| - handler_map["GetOOBEScreenInfo"] = |
| + (*handler_map)["PickUserImage"] = &TestingAutomationProvider::PickUserImage; |
| + (*handler_map)["SkipToLogin"] = &TestingAutomationProvider::SkipToLogin; |
| + (*handler_map)["GetOOBEScreenInfo"] = |
| &TestingAutomationProvider::GetOOBEScreenInfo; |
| - handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; |
| - handler_map["ShowCreateAccountUI"] = |
| + (*handler_map)["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; |
| + (*handler_map)["ShowCreateAccountUI"] = |
| &TestingAutomationProvider::ShowCreateAccountUI; |
| - handler_map["ExecuteJavascriptInOOBEWebUI"] = |
| + (*handler_map)["ExecuteJavascriptInOOBEWebUI"] = |
| &TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI; |
| - handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; |
| - handler_map["SubmitLoginForm"] = &TestingAutomationProvider::SubmitLoginForm; |
| - handler_map["AddLoginEventObserver"] = |
| + (*handler_map)["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; |
| + (*handler_map)["SubmitLoginForm"] = |
| + &TestingAutomationProvider::SubmitLoginForm; |
| + (*handler_map)["AddLoginEventObserver"] = |
| &TestingAutomationProvider::AddLoginEventObserver; |
| - handler_map["SignOut"] = &TestingAutomationProvider::SignOut; |
| + (*handler_map)["SignOut"] = &TestingAutomationProvider::SignOut; |
| - handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; |
| - handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; |
| - handler_map["SignoutInScreenLocker"] = |
| + (*handler_map)["LockScreen"] = &TestingAutomationProvider::LockScreen; |
| + (*handler_map)["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; |
| + (*handler_map)["SignoutInScreenLocker"] = |
| &TestingAutomationProvider::SignoutInScreenLocker; |
| - handler_map["GetBatteryInfo"] = &TestingAutomationProvider::GetBatteryInfo; |
| + (*handler_map)["GetBatteryInfo"] = &TestingAutomationProvider::GetBatteryInfo; |
| - handler_map["GetNetworkInfo"] = &TestingAutomationProvider::GetNetworkInfo; |
| - handler_map["NetworkScan"] = &TestingAutomationProvider::NetworkScan; |
| - handler_map["ToggleNetworkDevice"] = |
| + (*handler_map)["GetNetworkInfo"] = &TestingAutomationProvider::GetNetworkInfo; |
| + (*handler_map)["NetworkScan"] = &TestingAutomationProvider::NetworkScan; |
| + (*handler_map)["ToggleNetworkDevice"] = |
| &TestingAutomationProvider::ToggleNetworkDevice; |
| - handler_map["ConnectToCellularNetwork"] = |
| + (*handler_map)["ConnectToCellularNetwork"] = |
| &TestingAutomationProvider::ConnectToCellularNetwork; |
| - handler_map["DisconnectFromCellularNetwork"] = |
| + (*handler_map)["DisconnectFromCellularNetwork"] = |
| &TestingAutomationProvider::DisconnectFromCellularNetwork; |
| - handler_map["ConnectToWifiNetwork"] = |
| + (*handler_map)["ConnectToWifiNetwork"] = |
| &TestingAutomationProvider::ConnectToWifiNetwork; |
| - handler_map["ConnectToHiddenWifiNetwork"] = |
| + (*handler_map)["ConnectToHiddenWifiNetwork"] = |
| &TestingAutomationProvider::ConnectToHiddenWifiNetwork; |
| - handler_map["DisconnectFromWifiNetwork"] = |
| + (*handler_map)["DisconnectFromWifiNetwork"] = |
| &TestingAutomationProvider::DisconnectFromWifiNetwork; |
| - handler_map["ForgetWifiNetwork"] = |
| + (*handler_map)["ForgetWifiNetwork"] = |
| &TestingAutomationProvider::ForgetWifiNetwork; |
| - handler_map["AddPrivateNetwork"] = |
| + (*handler_map)["AddPrivateNetwork"] = |
| &TestingAutomationProvider::AddPrivateNetwork; |
| - handler_map["GetPrivateNetworkInfo"] = |
| + (*handler_map)["GetPrivateNetworkInfo"] = |
| &TestingAutomationProvider::GetPrivateNetworkInfo; |
| - handler_map["ConnectToPrivateNetwork"] = |
| + (*handler_map)["ConnectToPrivateNetwork"] = |
| &TestingAutomationProvider::ConnectToPrivateNetwork; |
| - handler_map["DisconnectFromPrivateNetwork"] = |
| + (*handler_map)["DisconnectFromPrivateNetwork"] = |
| &TestingAutomationProvider::DisconnectFromPrivateNetwork; |
| - handler_map["IsEnterpriseDevice"] = |
| + (*handler_map)["IsEnterpriseDevice"] = |
| &TestingAutomationProvider::IsEnterpriseDevice; |
| - handler_map["GetEnterprisePolicyInfo"] = |
| + (*handler_map)["GetEnterprisePolicyInfo"] = |
| &TestingAutomationProvider::GetEnterprisePolicyInfo; |
| - handler_map["EnrollEnterpriseDevice"] = |
| + (*handler_map)["EnrollEnterpriseDevice"] = |
| &TestingAutomationProvider::EnrollEnterpriseDevice; |
| - handler_map["EnableSpokenFeedback"] = |
| + (*handler_map)["EnableSpokenFeedback"] = |
| &TestingAutomationProvider::EnableSpokenFeedback; |
| - handler_map["IsSpokenFeedbackEnabled"] = |
| + (*handler_map)["IsSpokenFeedbackEnabled"] = |
| &TestingAutomationProvider::IsSpokenFeedbackEnabled; |
| - handler_map["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; |
| - handler_map["SetTimezone"] = &TestingAutomationProvider::SetTimezone; |
| + (*handler_map)["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; |
| + (*handler_map)["SetTimezone"] = &TestingAutomationProvider::SetTimezone; |
| - handler_map["GetUpdateInfo"] = &TestingAutomationProvider::GetUpdateInfo; |
| - handler_map["UpdateCheck"] = &TestingAutomationProvider::UpdateCheck; |
| - handler_map["SetReleaseTrack"] = &TestingAutomationProvider::SetReleaseTrack; |
| + (*handler_map)["GetUpdateInfo"] = &TestingAutomationProvider::GetUpdateInfo; |
| + (*handler_map)["UpdateCheck"] = &TestingAutomationProvider::UpdateCheck; |
| + (*handler_map)["SetReleaseTrack"] = |
| + &TestingAutomationProvider::SetReleaseTrack; |
| - handler_map["GetVolumeInfo"] = &TestingAutomationProvider::GetVolumeInfo; |
| - handler_map["SetVolume"] = &TestingAutomationProvider::SetVolume; |
| - handler_map["SetMute"] = &TestingAutomationProvider::SetMute; |
| + (*handler_map)["GetVolumeInfo"] = &TestingAutomationProvider::GetVolumeInfo; |
| + (*handler_map)["SetVolume"] = &TestingAutomationProvider::SetVolume; |
| + (*handler_map)["SetMute"] = &TestingAutomationProvider::SetMute; |
| - handler_map["OpenCrosh"] = &TestingAutomationProvider::OpenCrosh; |
| + (*handler_map)["OpenCrosh"] = &TestingAutomationProvider::OpenCrosh; |
| #endif // defined(OS_CHROMEOS) |
| - std::map<std::string, BrowserJsonHandler> browser_handler_map; |
| - browser_handler_map["DisablePlugin"] = |
| + (*browser_handler_map)["DisablePlugin"] = |
| &TestingAutomationProvider::DisablePlugin; |
| - browser_handler_map["EnablePlugin"] = |
| + (*browser_handler_map)["EnablePlugin"] = |
| &TestingAutomationProvider::EnablePlugin; |
| - browser_handler_map["GetPluginsInfo"] = |
| + (*browser_handler_map)["GetPluginsInfo"] = |
| &TestingAutomationProvider::GetPluginsInfo; |
| - browser_handler_map["GetNavigationInfo"] = |
| + (*browser_handler_map)["GetNavigationInfo"] = |
| &TestingAutomationProvider::GetNavigationInfo; |
| - browser_handler_map["PerformActionOnInfobar"] = |
| + (*browser_handler_map)["PerformActionOnInfobar"] = |
| &TestingAutomationProvider::PerformActionOnInfobar; |
| - browser_handler_map["GetHistoryInfo"] = |
| + (*browser_handler_map)["GetHistoryInfo"] = |
| &TestingAutomationProvider::GetHistoryInfo; |
| - browser_handler_map["AddHistoryItem"] = |
| + (*browser_handler_map)["AddHistoryItem"] = |
| &TestingAutomationProvider::AddHistoryItem; |
| - browser_handler_map["GetOmniboxInfo"] = |
| + (*browser_handler_map)["GetOmniboxInfo"] = |
| &TestingAutomationProvider::GetOmniboxInfo; |
| - browser_handler_map["SetOmniboxText"] = |
| + (*browser_handler_map)["SetOmniboxText"] = |
| &TestingAutomationProvider::SetOmniboxText; |
| - browser_handler_map["OmniboxAcceptInput"] = |
| + (*browser_handler_map)["OmniboxAcceptInput"] = |
| &TestingAutomationProvider::OmniboxAcceptInput; |
| - browser_handler_map["OmniboxMovePopupSelection"] = |
| + (*browser_handler_map)["OmniboxMovePopupSelection"] = |
| &TestingAutomationProvider::OmniboxMovePopupSelection; |
| - browser_handler_map["GetInstantInfo"] = |
| + (*browser_handler_map)["GetInstantInfo"] = |
| &TestingAutomationProvider::GetInstantInfo; |
| - browser_handler_map["LoadSearchEngineInfo"] = |
| + (*browser_handler_map)["LoadSearchEngineInfo"] = |
| &TestingAutomationProvider::LoadSearchEngineInfo; |
| - browser_handler_map["GetSearchEngineInfo"] = |
| + (*browser_handler_map)["GetSearchEngineInfo"] = |
| &TestingAutomationProvider::GetSearchEngineInfo; |
| - browser_handler_map["AddOrEditSearchEngine"] = |
| + (*browser_handler_map)["AddOrEditSearchEngine"] = |
| &TestingAutomationProvider::AddOrEditSearchEngine; |
| - browser_handler_map["PerformActionOnSearchEngine"] = |
| + (*browser_handler_map)["PerformActionOnSearchEngine"] = |
| &TestingAutomationProvider::PerformActionOnSearchEngine; |
| #if defined(ENABLE_PROTECTOR_SERVICE) |
| - browser_handler_map["GetProtectorState"] = |
| + (*browser_handler_map)["GetProtectorState"] = |
| &TestingAutomationProvider::GetProtectorState; |
| - browser_handler_map["PerformProtectorAction"] = |
| + (*browser_handler_map)["PerformProtectorAction"] = |
| &TestingAutomationProvider::PerformProtectorAction; |
| #endif |
| - browser_handler_map["SetWindowDimensions"] = |
| + (*browser_handler_map)["SetWindowDimensions"] = |
| &TestingAutomationProvider::SetWindowDimensions; |
| - browser_handler_map["GetDownloadsInfo"] = |
| + (*browser_handler_map)["GetDownloadsInfo"] = |
| &TestingAutomationProvider::GetDownloadsInfo; |
| - browser_handler_map["WaitForAllDownloadsToComplete"] = |
| + (*browser_handler_map)["WaitForAllDownloadsToComplete"] = |
| &TestingAutomationProvider::WaitForAllDownloadsToComplete; |
| - browser_handler_map["PerformActionOnDownload"] = |
| + (*browser_handler_map)["PerformActionOnDownload"] = |
| &TestingAutomationProvider::PerformActionOnDownload; |
| - browser_handler_map["GetInitialLoadTimes"] = |
| + (*browser_handler_map)["GetInitialLoadTimes"] = |
| &TestingAutomationProvider::GetInitialLoadTimes; |
| - browser_handler_map["SaveTabContents"] = |
| + (*browser_handler_map)["SaveTabContents"] = |
| &TestingAutomationProvider::SaveTabContents; |
| - browser_handler_map["ImportSettings"] = |
| + (*browser_handler_map)["ImportSettings"] = |
| &TestingAutomationProvider::ImportSettings; |
| - browser_handler_map["AddSavedPassword"] = |
| + (*browser_handler_map)["AddSavedPassword"] = |
| &TestingAutomationProvider::AddSavedPassword; |
| - browser_handler_map["RemoveSavedPassword"] = |
| + (*browser_handler_map)["RemoveSavedPassword"] = |
| &TestingAutomationProvider::RemoveSavedPassword; |
| - browser_handler_map["GetSavedPasswords"] = |
| + (*browser_handler_map)["GetSavedPasswords"] = |
| &TestingAutomationProvider::GetSavedPasswords; |
| - browser_handler_map["ClearBrowsingData"] = |
| + (*browser_handler_map)["ClearBrowsingData"] = |
| &TestingAutomationProvider::ClearBrowsingData; |
| - browser_handler_map["GetBlockedPopupsInfo"] = |
| + (*browser_handler_map)["GetBlockedPopupsInfo"] = |
| &TestingAutomationProvider::GetBlockedPopupsInfo; |
| - browser_handler_map["UnblockAndLaunchBlockedPopup"] = |
| + (*browser_handler_map)["UnblockAndLaunchBlockedPopup"] = |
| &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; |
| // SetTheme() implemented using InstallExtension(). |
| - browser_handler_map["GetThemeInfo"] = |
| + (*browser_handler_map)["GetThemeInfo"] = |
| &TestingAutomationProvider::GetThemeInfo; |
| - browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; |
| + (*browser_handler_map)["FindInPage"] = &TestingAutomationProvider::FindInPage; |
| - browser_handler_map["SelectTranslateOption"] = |
| + (*browser_handler_map)["SelectTranslateOption"] = |
| &TestingAutomationProvider::SelectTranslateOption; |
| - browser_handler_map["GetTranslateInfo"] = |
| + (*browser_handler_map)["GetTranslateInfo"] = |
| &TestingAutomationProvider::GetTranslateInfo; |
| - browser_handler_map["GetAutofillProfile"] = |
| + (*browser_handler_map)["GetAutofillProfile"] = |
| &TestingAutomationProvider::GetAutofillProfile; |
| - browser_handler_map["FillAutofillProfile"] = |
| + (*browser_handler_map)["FillAutofillProfile"] = |
| &TestingAutomationProvider::FillAutofillProfile; |
| - browser_handler_map["SubmitAutofillForm"] = |
| + (*browser_handler_map)["SubmitAutofillForm"] = |
| &TestingAutomationProvider::SubmitAutofillForm; |
| - browser_handler_map["AutofillTriggerSuggestions"] = |
| + (*browser_handler_map)["AutofillTriggerSuggestions"] = |
| &TestingAutomationProvider::AutofillTriggerSuggestions; |
| - browser_handler_map["AutofillHighlightSuggestion"] = |
| + (*browser_handler_map)["AutofillHighlightSuggestion"] = |
| &TestingAutomationProvider::AutofillHighlightSuggestion; |
| - browser_handler_map["AutofillAcceptSelection"] = |
| + (*browser_handler_map)["AutofillAcceptSelection"] = |
| &TestingAutomationProvider::AutofillAcceptSelection; |
| - browser_handler_map["GetAllNotifications"] = |
| + (*browser_handler_map)["GetAllNotifications"] = |
| &TestingAutomationProvider::GetAllNotifications; |
| - browser_handler_map["CloseNotification"] = |
| + (*browser_handler_map)["CloseNotification"] = |
| &TestingAutomationProvider::CloseNotification; |
| - browser_handler_map["WaitForNotificationCount"] = |
| + (*browser_handler_map)["WaitForNotificationCount"] = |
| &TestingAutomationProvider::WaitForNotificationCount; |
| - browser_handler_map["SignInToSync"] = |
| + (*browser_handler_map)["SignInToSync"] = |
| &TestingAutomationProvider::SignInToSync; |
| - browser_handler_map["GetSyncInfo"] = &TestingAutomationProvider::GetSyncInfo; |
| - browser_handler_map["AwaitFullSyncCompletion"] = |
| + (*browser_handler_map)["GetSyncInfo"] = |
| + &TestingAutomationProvider::GetSyncInfo; |
| + (*browser_handler_map)["AwaitFullSyncCompletion"] = |
| &TestingAutomationProvider::AwaitFullSyncCompletion; |
| - browser_handler_map["AwaitSyncRestart"] = |
| + (*browser_handler_map)["AwaitSyncRestart"] = |
| &TestingAutomationProvider::AwaitSyncRestart; |
| - browser_handler_map["EnableSyncForDatatypes"] = |
| + (*browser_handler_map)["EnableSyncForDatatypes"] = |
| &TestingAutomationProvider::EnableSyncForDatatypes; |
| - browser_handler_map["DisableSyncForDatatypes"] = |
| + (*browser_handler_map)["DisableSyncForDatatypes"] = |
| &TestingAutomationProvider::DisableSyncForDatatypes; |
| - browser_handler_map["GetNTPInfo"] = |
| + (*browser_handler_map)["GetNTPInfo"] = |
| &TestingAutomationProvider::GetNTPInfo; |
| - browser_handler_map["RemoveNTPMostVisitedThumbnail"] = |
| + (*browser_handler_map)["RemoveNTPMostVisitedThumbnail"] = |
| &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail; |
| - browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = |
| + (*browser_handler_map)["RestoreAllNTPMostVisitedThumbnails"] = |
| &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; |
| - browser_handler_map["KillRendererProcess"] = |
| + (*browser_handler_map)["KillRendererProcess"] = |
| &TestingAutomationProvider::KillRendererProcess; |
| - browser_handler_map["LaunchApp"] = &TestingAutomationProvider::LaunchApp; |
| - browser_handler_map["SetAppLaunchType"] = |
| + (*browser_handler_map)["LaunchApp"] = &TestingAutomationProvider::LaunchApp; |
| + (*browser_handler_map)["SetAppLaunchType"] = |
| &TestingAutomationProvider::SetAppLaunchType; |
| - browser_handler_map["GetV8HeapStats"] = |
| + (*browser_handler_map)["GetV8HeapStats"] = |
| &TestingAutomationProvider::GetV8HeapStats; |
| - browser_handler_map["GetFPS"] = |
| + (*browser_handler_map)["GetFPS"] = |
| &TestingAutomationProvider::GetFPS; |
| - browser_handler_map["IsFullscreenForBrowser"] = |
| + (*browser_handler_map)["IsFullscreenForBrowser"] = |
| &TestingAutomationProvider::IsFullscreenForBrowser; |
| - browser_handler_map["IsFullscreenForTab"] = |
| + (*browser_handler_map)["IsFullscreenForTab"] = |
| &TestingAutomationProvider::IsFullscreenForTab; |
| - browser_handler_map["IsMouseLocked"] = |
| + (*browser_handler_map)["IsMouseLocked"] = |
| &TestingAutomationProvider::IsMouseLocked; |
| - browser_handler_map["IsMouseLockPermissionRequested"] = |
| + (*browser_handler_map)["IsMouseLockPermissionRequested"] = |
| &TestingAutomationProvider::IsMouseLockPermissionRequested; |
| - browser_handler_map["IsFullscreenPermissionRequested"] = |
| + (*browser_handler_map)["IsFullscreenPermissionRequested"] = |
| &TestingAutomationProvider::IsFullscreenPermissionRequested; |
| - browser_handler_map["IsFullscreenBubbleDisplayed"] = |
| + (*browser_handler_map)["IsFullscreenBubbleDisplayed"] = |
| &TestingAutomationProvider::IsFullscreenBubbleDisplayed; |
| - browser_handler_map["IsFullscreenBubbleDisplayingButtons"] = |
| + (*browser_handler_map)["IsFullscreenBubbleDisplayingButtons"] = |
| &TestingAutomationProvider::IsFullscreenBubbleDisplayingButtons; |
| - browser_handler_map["AcceptCurrentFullscreenOrMouseLockRequest"] = |
| + (*browser_handler_map)["AcceptCurrentFullscreenOrMouseLockRequest"] = |
| &TestingAutomationProvider::AcceptCurrentFullscreenOrMouseLockRequest; |
| - browser_handler_map["DenyCurrentFullscreenOrMouseLockRequest"] = |
| + (*browser_handler_map)["DenyCurrentFullscreenOrMouseLockRequest"] = |
| &TestingAutomationProvider::DenyCurrentFullscreenOrMouseLockRequest; |
| #if defined(OS_CHROMEOS) |
| - browser_handler_map["CaptureProfilePhoto"] = |
| + (*browser_handler_map)["CaptureProfilePhoto"] = |
| &TestingAutomationProvider::CaptureProfilePhoto; |
| - browser_handler_map["GetTimeInfo"] = &TestingAutomationProvider::GetTimeInfo; |
| - browser_handler_map["GetProxySettings"] = |
| + (*browser_handler_map)["GetTimeInfo"] = |
| + &TestingAutomationProvider::GetTimeInfo; |
| + (*browser_handler_map)["GetProxySettings"] = |
| &TestingAutomationProvider::GetProxySettings; |
| - browser_handler_map["SetProxySettings"] = |
| + (*browser_handler_map)["SetProxySettings"] = |
| &TestingAutomationProvider::SetProxySettings; |
| #endif // defined(OS_CHROMEOS) |
| +} |
| + |
| +DictionaryValue* TestingAutomationProvider::ParseJSONRequestCommand( |
| + const std::string& json_request, |
| + std::string* command, |
| + std::string* error) { |
| + scoped_ptr<Value> values(base::JSONReader::ReadAndReturnError(json_request, |
| + base::JSON_ALLOW_TRAILING_COMMAS, NULL, error)); |
| + if (!error->empty()) |
| + return NULL; |
| + |
| + // Make sure input is a dict with a string command. |
| + if (values->GetType() != Value::TYPE_DICTIONARY) { |
| + *error = "Command dictionary is not a dictionary."; |
| + return NULL; |
| + } |
| + scoped_ptr<DictionaryValue> dict_value( |
| + static_cast<DictionaryValue*>(values.release())); |
| + if (!dict_value->GetStringASCII(std::string("command"), command)) { |
| + *error = "Command key string missing from dictionary."; |
| + return NULL; |
| + } |
| + return dict_value.release(); |
| +} |
| + |
| +void TestingAutomationProvider::SendJSONRequestWithHandle( |
| + int handle, |
| + const std::string& json_request, |
| + IPC::Message* reply_message) { |
| + Browser* browser = NULL; |
| + if (browser_tracker_->ContainsHandle(handle)) |
| + browser = browser_tracker_->GetResource(handle); |
| + SendJSONRequest(browser, json_request, reply_message, handle >= 0); |
| +} |
| + |
| +void TestingAutomationProvider::SendJSONRequestWithIndex( |
|
Nirnimesh
2012/06/14 22:16:42
It's not clear index of what.
Rename to SendJSONRe
craigdh
2012/06/15 19:24:53
Done.
|
| + int index, |
| + const std::string& json_request, |
| + IPC::Message* reply_message) { |
| + Browser* browser = index < 0 ? NULL : automation_util::GetBrowserAt(index); |
| + SendJSONRequest(browser, json_request, reply_message, index >= 0); |
| +} |
| - // Look for command in handlers that take a Browser handle. |
| +void TestingAutomationProvider::SendJSONRequest(Browser* browser, |
| + const std::string& json_request, |
| + IPC::Message* reply_message, |
| + bool browser_provided) { |
| + std::string command, error_string; |
| + scoped_ptr<DictionaryValue> dict_value( |
| + ParseJSONRequestCommand(json_request, &command, &error_string)); |
| + if (!dict_value.get()) { |
| + AutomationJSONReply(this, reply_message).SendError(error_string); |
| + return; |
| + } |
| + |
| + std::map<std::string, JsonHandler> handler_map; |
| + std::map<std::string, BrowserJsonHandler> browser_handler_map; |
| + BuildJSONHandlerMaps(&handler_map, &browser_handler_map); |
| + |
| + // Look for command in handlers that take a Browser. |
| if (browser_handler_map.find(std::string(command)) != |
| - browser_handler_map.end()) { |
| - Browser* browser = NULL; |
| - // Get Browser object associated with handle. |
| - if (!browser_tracker_->ContainsHandle(handle) || |
| - !(browser = browser_tracker_->GetResource(handle))) { |
| - // Browser not found; attempt to fallback to non-Browser handlers. |
| - if (handler_map.find(std::string(command)) != handler_map.end()) |
| - (this->*handler_map[command])(dict_value, reply_message); |
| - else |
| - AutomationJSONReply(this, reply_message).SendError( |
| - "No browser object."); |
| - } else { |
| - (this->*browser_handler_map[command])(browser, dict_value, reply_message); |
| - } |
| - // Look for command in handlers that don't take a Browser handle. |
| + browser_handler_map.end() && browser) { |
| + (this->*browser_handler_map[command])(browser, dict_value.get(), |
| + reply_message); |
| + // Look for command in handlers that don't take a Browser. |
| } else if (handler_map.find(std::string(command)) != handler_map.end()) { |
| - (this->*handler_map[command])(dict_value, reply_message); |
| - // Command has no handlers for it. |
| + (this->*handler_map[command])(dict_value.get(), reply_message); |
| + // Browser was given but doesn't exist. |
| + } else if (browser_provided && !browser) { |
| + AutomationJSONReply(this, reply_message).SendError( |
| + "The supplied browser window does not/no longer exists."); |
|
Nirnimesh
2012/06/14 22:16:42
It would be nice to specify which browser index.
craigdh
2012/06/15 19:24:53
Done.
|
| + // Command has no handler. |
| } else { |
| - std::string error_string = "Unknown command. Options: "; |
| + error_string = "Unknown command. Options: "; |
| for (std::map<std::string, JsonHandler>::const_iterator it = |
| handler_map.begin(); it != handler_map.end(); ++it) { |
| error_string += it->first + ", "; |