| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" |
| 12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 14 #include "base/json/string_escape.h" | 15 #include "base/json/string_escape.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 16 #include "base/process.h" | 17 #include "base/process.h" |
| 17 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 18 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 AutomationMsg_GoBackBlockUntilNavigationsComplete, | 352 AutomationMsg_GoBackBlockUntilNavigationsComplete, |
| 352 GoBackBlockUntilNavigationsComplete) | 353 GoBackBlockUntilNavigationsComplete) |
| 353 IPC_MESSAGE_HANDLER_DELAY_REPLY( | 354 IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 354 AutomationMsg_GoForwardBlockUntilNavigationsComplete, | 355 AutomationMsg_GoForwardBlockUntilNavigationsComplete, |
| 355 GoForwardBlockUntilNavigationsComplete) | 356 GoForwardBlockUntilNavigationsComplete) |
| 356 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, | 357 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, |
| 357 SavePackageShouldPromptUser) | 358 SavePackageShouldPromptUser) |
| 358 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) | 359 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) |
| 359 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) | 360 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) |
| 360 IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) | 361 IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) |
| 361 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CaptureEntirePageAsPNG, | |
| 362 CaptureEntirePageAsPNG) | |
| 363 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, | 362 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, |
| 364 SendJSONRequest) | 363 SendJSONRequest) |
| 365 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, | 364 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, |
| 366 WaitForTabCountToBecome) | 365 WaitForTabCountToBecome) |
| 367 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, | 366 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, |
| 368 WaitForInfoBarCount) | 367 WaitForInfoBarCount) |
| 369 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, | 368 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, |
| 370 GetPageCurrentEncoding) | 369 GetPageCurrentEncoding) |
| 371 IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService, | 370 IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService, |
| 372 ShutdownSessionService) | 371 ShutdownSessionService) |
| (...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 *count = static_cast<int>(container->GetBlockedContentsCount()); | 1983 *count = static_cast<int>(container->GetBlockedContentsCount()); |
| 1985 } else { | 1984 } else { |
| 1986 // If we don't have a container, we don't have any blocked popups to | 1985 // If we don't have a container, we don't have any blocked popups to |
| 1987 // contain! | 1986 // contain! |
| 1988 *count = 0; | 1987 *count = 0; |
| 1989 } | 1988 } |
| 1990 } | 1989 } |
| 1991 } | 1990 } |
| 1992 } | 1991 } |
| 1993 | 1992 |
| 1994 void TestingAutomationProvider::CaptureEntirePageAsPNG( | |
| 1995 int tab_handle, const FilePath& path, IPC::Message* reply_message) { | |
| 1996 RenderViewHost* render_view = GetViewForTab(tab_handle); | |
| 1997 if (render_view) { | |
| 1998 // This will delete itself when finished. | |
| 1999 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( | |
| 2000 this, reply_message, render_view, path); | |
| 2001 snapshot_taker->Start(); | |
| 2002 } else { | |
| 2003 LOG(ERROR) << "Could not get render view for tab handle"; | |
| 2004 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message, | |
| 2005 false); | |
| 2006 Send(reply_message); | |
| 2007 } | |
| 2008 } | |
| 2009 | |
| 2010 void TestingAutomationProvider::SendJSONRequest(int handle, | 1993 void TestingAutomationProvider::SendJSONRequest(int handle, |
| 2011 const std::string& json_request, | 1994 const std::string& json_request, |
| 2012 IPC::Message* reply_message) { | 1995 IPC::Message* reply_message) { |
| 2013 scoped_ptr<Value> values; | 1996 scoped_ptr<Value> values; |
| 2014 base::JSONReader reader; | 1997 base::JSONReader reader; |
| 2015 std::string error; | 1998 std::string error; |
| 2016 values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error)); | 1999 values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error)); |
| 2017 if (!error.empty()) { | 2000 if (!error.empty()) { |
| 2018 AutomationJSONReply(this, reply_message).SendError(error); | 2001 AutomationJSONReply(this, reply_message).SendError(error); |
| 2019 return; | 2002 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2047 handler_map["GoForward"] = | 2030 handler_map["GoForward"] = |
| 2048 &TestingAutomationProvider::GoForward; | 2031 &TestingAutomationProvider::GoForward; |
| 2049 handler_map["GoBack"] = | 2032 handler_map["GoBack"] = |
| 2050 &TestingAutomationProvider::GoBack; | 2033 &TestingAutomationProvider::GoBack; |
| 2051 handler_map["Reload"] = | 2034 handler_map["Reload"] = |
| 2052 &TestingAutomationProvider::ReloadJSON; | 2035 &TestingAutomationProvider::ReloadJSON; |
| 2053 handler_map["GetTabURL"] = | 2036 handler_map["GetTabURL"] = |
| 2054 &TestingAutomationProvider::GetTabURLJSON; | 2037 &TestingAutomationProvider::GetTabURLJSON; |
| 2055 handler_map["GetTabTitle"] = | 2038 handler_map["GetTabTitle"] = |
| 2056 &TestingAutomationProvider::GetTabTitleJSON; | 2039 &TestingAutomationProvider::GetTabTitleJSON; |
| 2040 handler_map["CaptureEntirePage"] = |
| 2041 &TestingAutomationProvider::CaptureEntirePageJSON; |
| 2057 handler_map["GetCookies"] = | 2042 handler_map["GetCookies"] = |
| 2058 &TestingAutomationProvider::GetCookiesJSON; | 2043 &TestingAutomationProvider::GetCookiesJSON; |
| 2059 handler_map["DeleteCookie"] = | 2044 handler_map["DeleteCookie"] = |
| 2060 &TestingAutomationProvider::DeleteCookieJSON; | 2045 &TestingAutomationProvider::DeleteCookieJSON; |
| 2061 handler_map["SetCookie"] = | 2046 handler_map["SetCookie"] = |
| 2062 &TestingAutomationProvider::SetCookieJSON; | 2047 &TestingAutomationProvider::SetCookieJSON; |
| 2063 handler_map["GetTabIds"] = | 2048 handler_map["GetTabIds"] = |
| 2064 &TestingAutomationProvider::GetTabIds; | 2049 &TestingAutomationProvider::GetTabIds; |
| 2065 handler_map["IsTabIdValid"] = | 2050 handler_map["IsTabIdValid"] = |
| 2066 &TestingAutomationProvider::IsTabIdValid; | 2051 &TestingAutomationProvider::IsTabIdValid; |
| (...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4954 std::string error; | 4939 std::string error; |
| 4955 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 4940 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 4956 reply.SendError(error); | 4941 reply.SendError(error); |
| 4957 return; | 4942 return; |
| 4958 } | 4943 } |
| 4959 DictionaryValue dict; | 4944 DictionaryValue dict; |
| 4960 dict.SetString("title", tab_contents->GetTitle()); | 4945 dict.SetString("title", tab_contents->GetTitle()); |
| 4961 reply.SendSuccess(&dict); | 4946 reply.SendSuccess(&dict); |
| 4962 } | 4947 } |
| 4963 | 4948 |
| 4949 void TestingAutomationProvider::CaptureEntirePageJSON( |
| 4950 DictionaryValue* args, |
| 4951 IPC::Message* reply_message) { |
| 4952 TabContents* tab_contents; |
| 4953 std::string error; |
| 4954 |
| 4955 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 4956 AutomationJSONReply(this, reply_message).SendError(error); |
| 4957 return; |
| 4958 } |
| 4959 |
| 4960 FilePath::StringType path_str; |
| 4961 if (!args->GetString("path", &path_str)) { |
| 4962 AutomationJSONReply(this, reply_message) |
| 4963 .SendError("'path' missing or invalid"); |
| 4964 return; |
| 4965 } |
| 4966 |
| 4967 RenderViewHost* render_view = tab_contents->render_view_host(); |
| 4968 if (render_view) { |
| 4969 FilePath path(path_str); |
| 4970 // This will delete itself when finished. |
| 4971 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( |
| 4972 this, reply_message, render_view, path); |
| 4973 snapshot_taker->Start(); |
| 4974 } else { |
| 4975 AutomationJSONReply(this, reply_message) |
| 4976 .SendError("Tab has no associated RenderViewHost"); |
| 4977 } |
| 4978 } |
| 4979 |
| 4964 void TestingAutomationProvider::GetCookiesJSON( | 4980 void TestingAutomationProvider::GetCookiesJSON( |
| 4965 DictionaryValue* args, IPC::Message* reply_message) { | 4981 DictionaryValue* args, IPC::Message* reply_message) { |
| 4966 automation_util::GetCookiesJSON(this, args, reply_message); | 4982 automation_util::GetCookiesJSON(this, args, reply_message); |
| 4967 } | 4983 } |
| 4968 | 4984 |
| 4969 void TestingAutomationProvider::DeleteCookieJSON( | 4985 void TestingAutomationProvider::DeleteCookieJSON( |
| 4970 DictionaryValue* args, IPC::Message* reply_message) { | 4986 DictionaryValue* args, IPC::Message* reply_message) { |
| 4971 automation_util::DeleteCookieJSON(this, args, reply_message); | 4987 automation_util::DeleteCookieJSON(this, args, reply_message); |
| 4972 } | 4988 } |
| 4973 | 4989 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5205 // If you change this, update Observer for NotificationType::SESSION_END | 5221 // If you change this, update Observer for NotificationType::SESSION_END |
| 5206 // below. | 5222 // below. |
| 5207 MessageLoop::current()->PostTask(FROM_HERE, | 5223 MessageLoop::current()->PostTask(FROM_HERE, |
| 5208 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5224 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5209 } | 5225 } |
| 5210 } | 5226 } |
| 5211 | 5227 |
| 5212 void TestingAutomationProvider::OnRemoveProvider() { | 5228 void TestingAutomationProvider::OnRemoveProvider() { |
| 5213 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5229 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5214 } | 5230 } |
| OLD | NEW |