From 85a61eb46a3f1b93e19cded05773e6784ed1adb7 Mon Sep 17 00:00:00 2001
From: "thakis@chromium.org"
 <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 29 Jun 2012 03:01:17 +0000
Subject: Revert 144610 (speculative; possibly caused http://crbug.com/135059)
 - First pass at refactoring pyautolib in preparation for removing proxy
 dependencies.

BUG=132789
TEST=functional/apptest.py, functional/browser.py, functional/navigation.py


Review URL: https://chromiumcodereview.appspot.com/10534163

TBR=craigdh@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10703040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144868 0039d316-1c4b-4281-b951-d872f2087c98
---
 .../automation/testing_automation_provider.cc      | 488 ++++++++++-----------
 .../automation/testing_automation_provider.h       |  18 +-
 2 files changed, 228 insertions(+), 278 deletions(-)

(limited to 'chrome/browser')

diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 913f8c2..a9b1759 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -442,10 +442,7 @@ bool TestingAutomationProvider::OnMessageReceived(
         GoForwardBlockUntilNavigationsComplete)
     IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
-                                    SendJSONRequestWithBrowserIndex)
-    IPC_MESSAGE_HANDLER_DELAY_REPLY(
-        AutomationMsg_SendJSONRequestWithBrowserHandle,
-        SendJSONRequestWithBrowserHandle)
+                                    SendJSONRequest)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome,
                                     WaitForTabCountToBecome)
     IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount,
@@ -1668,472 +1665,441 @@ void TestingAutomationProvider::SetShelfVisibility(int handle, bool visible) {
   }
 }
 
-void TestingAutomationProvider::BuildJSONHandlerMaps() {
+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;
+  }
+
   // Map json commands to their handlers.
-  handler_map_["WaitForAllTabsToStopLoading"] =
+  std::map<std::string, JsonHandler> handler_map;
+  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_["MaximizeView"] =
+  handler_map["MaximizeView"] =
       &TestingAutomationProvider::MaximizeView;
-  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_["OpenProfileWindow"] =
+  handler_map["OpenProfileWindow"] =
       &TestingAutomationProvider::OpenProfileWindow;
-  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)
 
-  browser_handler_map_["DisablePlugin"] =
+  std::map<std::string, BrowserJsonHandler> browser_handler_map;
+  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)
-}
 
-scoped_ptr<DictionaryValue> TestingAutomationProvider::ParseJSONRequestCommand(
-    const std::string& json_request,
-    std::string* command,
-    std::string* error) {
-  scoped_ptr<DictionaryValue> dict_value;
-  scoped_ptr<Value> values(base::JSONReader::ReadAndReturnError(json_request,
-      base::JSON_ALLOW_TRAILING_COMMAS, NULL, error));
-  if (values.get()) {
-    // Make sure input is a dict with a string command.
-    if (values->GetType() != Value::TYPE_DICTIONARY) {
-      *error = "Command dictionary is not a dictionary.";
+  // Look for command in handlers that take a Browser handle.
+  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 {
-      dict_value.reset(static_cast<DictionaryValue*>(values.release()));
-      if (!dict_value->GetStringASCII("command", command)) {
-        *error = "Command key string missing from dictionary.";
-        dict_value.reset(NULL);
-      }
+      (this->*browser_handler_map[command])(browser, dict_value, reply_message);
     }
-  }
-  return dict_value.Pass();
-}
-
-void TestingAutomationProvider::SendJSONRequestWithBrowserHandle(
-    int handle,
-    const std::string& json_request,
-    IPC::Message* reply_message) {
-  Browser* browser = NULL;
-  if (browser_tracker_->ContainsHandle(handle))
-    browser = browser_tracker_->GetResource(handle);
-  if (browser) {
-    SendJSONRequest(browser, json_request, reply_message);
-  } else {
-    AutomationJSONReply(this, reply_message).SendError(
-        "The browser window does not exist.");
-  }
-}
-
-void TestingAutomationProvider::SendJSONRequestWithBrowserIndex(
-    int index,
-    const std::string& json_request,
-    IPC::Message* reply_message) {
-  Browser* browser = index < 0 ? NULL : automation_util::GetBrowserAt(index);
-  if (!browser && index >= 0) {
-    AutomationJSONReply(this, reply_message).SendError(
-        StringPrintf("Browser window with index=%d does not exist.", index));
-  } else {
-    SendJSONRequest(browser, json_request, reply_message);
-  }
-}
-
-void TestingAutomationProvider::SendJSONRequest(Browser* browser,
-                                                const std::string& json_request,
-                                                IPC::Message* reply_message) {
-  std::string command, error_string;
-  scoped_ptr<DictionaryValue> dict_value(
-      ParseJSONRequestCommand(json_request, &command, &error_string));
-  if (!dict_value.get() || command.empty()) {
-    AutomationJSONReply(this, reply_message).SendError(error_string);
-    return;
-  }
-
-  if (handler_map_.empty() || browser_handler_map_.empty())
-    BuildJSONHandlerMaps();
-
-  // Look for command in handlers that take a Browser.
-  if (browser_handler_map_.find(std::string(command)) !=
-      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.get(), reply_message);
-  // Command has no handler.
+  // Look for command in handlers that don't take a Browser handle.
+  } 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.
   } else {
-    error_string = "Unknown command. Options: ";
+    std::string error_string = "Unknown command. Options: ";
     for (std::map<std::string, JsonHandler>::const_iterator it =
-         handler_map_.begin(); it != handler_map_.end(); ++it) {
+         handler_map.begin(); it != handler_map.end(); ++it) {
       error_string += it->first + ", ";
     }
     for (std::map<std::string, BrowserJsonHandler>::const_iterator it =
-         browser_handler_map_.begin(); it != browser_handler_map_.end(); ++it) {
+         browser_handler_map.begin(); it != browser_handler_map.end(); ++it) {
       error_string += it->first + ", ";
     }
     AutomationJSONReply(this, reply_message).SendError(error_string);
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index e916897..a723303 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -246,13 +246,7 @@ class TestingAutomationProvider : public AutomationProvider,
 
   // Generic pattern for pyautolib
   // Uses the JSON interface for input/output.
-  void SendJSONRequestWithBrowserHandle(int handle,
-                                        const std::string& json_request,
-                                        IPC::Message* reply_message);
-  void SendJSONRequestWithBrowserIndex(int index,
-                                       const std::string& json_request,
-                                       IPC::Message* reply_message);
-  void SendJSONRequest(Browser* browser,
+  void SendJSONRequest(int handle,
                        const std::string& json_request,
                        IPC::Message* reply_message);
 
@@ -268,13 +262,6 @@ class TestingAutomationProvider : public AutomationProvider,
       base::DictionaryValue*,
       IPC::Message*);
 
-  // JSON interface helper functions.
-  static scoped_ptr<DictionaryValue> ParseJSONRequestCommand(
-      const std::string& json_request,
-      std::string* command,
-      std::string* error);
-  void BuildJSONHandlerMaps();
-
   // Set window dimensions.
   // Uses the JSON interface for input/output.
   void SetWindowDimensions(Browser* browser,
@@ -1568,9 +1555,6 @@ class TestingAutomationProvider : public AutomationProvider,
   PowerManagerClientObserverForTesting* power_manager_observer_;
 #endif  // defined(OS_CHROMEOS)
 
-  std::map<std::string, JsonHandler> handler_map_;
-  std::map<std::string, BrowserJsonHandler> browser_handler_map_;
-
   // Used to wait on various browser sync events.
   scoped_ptr<ProfileSyncServiceHarness> sync_waiter_;
 
-- 
cgit v1.1