Chromium Code Reviews| 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 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1986 } | 1987 } |
| 1987 } | 1988 } |
| 1988 } | 1989 } |
| 1989 | 1990 |
| 1990 void TestingAutomationProvider::CaptureEntirePageAsPNG( | 1991 void TestingAutomationProvider::CaptureEntirePageAsPNG( |
| 1991 int tab_handle, const FilePath& path, IPC::Message* reply_message) { | 1992 int tab_handle, const FilePath& path, IPC::Message* reply_message) { |
| 1992 RenderViewHost* render_view = GetViewForTab(tab_handle); | 1993 RenderViewHost* render_view = GetViewForTab(tab_handle); |
| 1993 if (render_view) { | 1994 if (render_view) { |
| 1994 // This will delete itself when finished. | 1995 // This will delete itself when finished. |
| 1995 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( | 1996 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( |
| 1996 this, reply_message, render_view, path); | 1997 this, reply_message, render_view, path, false); |
| 1997 snapshot_taker->Start(); | 1998 snapshot_taker->Start(); |
| 1998 } else { | 1999 } else { |
| 1999 LOG(ERROR) << "Could not get render view for tab handle"; | 2000 LOG(ERROR) << "Could not get render view for tab handle"; |
| 2000 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message, | 2001 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message, |
| 2001 false); | 2002 false); |
| 2002 Send(reply_message); | 2003 Send(reply_message); |
| 2003 } | 2004 } |
| 2004 } | 2005 } |
| 2005 | 2006 |
| 2006 void TestingAutomationProvider::SendJSONRequest(int handle, | 2007 void TestingAutomationProvider::SendJSONRequest(int handle, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2043 handler_map["GoForward"] = | 2044 handler_map["GoForward"] = |
| 2044 &TestingAutomationProvider::GoForward; | 2045 &TestingAutomationProvider::GoForward; |
| 2045 handler_map["GoBack"] = | 2046 handler_map["GoBack"] = |
| 2046 &TestingAutomationProvider::GoBack; | 2047 &TestingAutomationProvider::GoBack; |
| 2047 handler_map["Reload"] = | 2048 handler_map["Reload"] = |
| 2048 &TestingAutomationProvider::ReloadJSON; | 2049 &TestingAutomationProvider::ReloadJSON; |
| 2049 handler_map["GetTabURL"] = | 2050 handler_map["GetTabURL"] = |
| 2050 &TestingAutomationProvider::GetTabURLJSON; | 2051 &TestingAutomationProvider::GetTabURLJSON; |
| 2051 handler_map["GetTabTitle"] = | 2052 handler_map["GetTabTitle"] = |
| 2052 &TestingAutomationProvider::GetTabTitleJSON; | 2053 &TestingAutomationProvider::GetTabTitleJSON; |
| 2054 handler_map["GetScreenShot"] = | |
|
kkania
2011/03/17 18:35:11
change this
Joe
2011/03/18 00:33:32
Done.
| |
| 2055 &TestingAutomationProvider::CaptureEntirePageJSON; | |
| 2053 handler_map["GetCookies"] = | 2056 handler_map["GetCookies"] = |
| 2054 &TestingAutomationProvider::GetCookiesJSON; | 2057 &TestingAutomationProvider::GetCookiesJSON; |
| 2055 handler_map["DeleteCookie"] = | 2058 handler_map["DeleteCookie"] = |
| 2056 &TestingAutomationProvider::DeleteCookieJSON; | 2059 &TestingAutomationProvider::DeleteCookieJSON; |
| 2057 handler_map["SetCookie"] = | 2060 handler_map["SetCookie"] = |
| 2058 &TestingAutomationProvider::SetCookieJSON; | 2061 &TestingAutomationProvider::SetCookieJSON; |
| 2059 handler_map["GetTabIds"] = | 2062 handler_map["GetTabIds"] = |
| 2060 &TestingAutomationProvider::GetTabIds; | 2063 &TestingAutomationProvider::GetTabIds; |
| 2061 handler_map["IsTabIdValid"] = | 2064 handler_map["IsTabIdValid"] = |
| 2062 &TestingAutomationProvider::IsTabIdValid; | 2065 &TestingAutomationProvider::IsTabIdValid; |
| (...skipping 2884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4947 std::string error; | 4950 std::string error; |
| 4948 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 4951 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 4949 reply.SendError(error); | 4952 reply.SendError(error); |
| 4950 return; | 4953 return; |
| 4951 } | 4954 } |
| 4952 DictionaryValue dict; | 4955 DictionaryValue dict; |
| 4953 dict.SetString("title", tab_contents->GetTitle()); | 4956 dict.SetString("title", tab_contents->GetTitle()); |
| 4954 reply.SendSuccess(&dict); | 4957 reply.SendSuccess(&dict); |
| 4955 } | 4958 } |
| 4956 | 4959 |
| 4960 void TestingAutomationProvider::CaptureEntirePageJSON( | |
| 4961 DictionaryValue* args, | |
| 4962 IPC::Message* reply_message) { | |
| 4963 TabContents* tab_contents; | |
| 4964 std::string error; | |
| 4965 | |
| 4966 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | |
| 4967 AutomationJSONReply(this, reply_message).SendError(error); | |
| 4968 return; | |
| 4969 } | |
| 4970 | |
| 4971 FilePath::StringType path_str; | |
| 4972 if (!args->GetString("path", &path_str)) { | |
| 4973 AutomationJSONReply(this, reply_message) | |
| 4974 .SendError("'path' missing or invalid"); | |
| 4975 return; | |
| 4976 } | |
| 4977 | |
| 4978 RenderViewHost* render_view = tab_contents->render_view_host(); | |
| 4979 if (render_view) { | |
| 4980 FilePath path(path_str); | |
| 4981 // This will delete itself when finished. | |
| 4982 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( | |
| 4983 this, reply_message, render_view, path, true); | |
| 4984 snapshot_taker->Start(); | |
| 4985 } else { | |
| 4986 AutomationJSONReply(this,reply_message) | |
|
kkania
2011/03/17 18:35:11
space after comma
Joe
2011/03/18 00:33:32
Done.
kkania
2011/03/18 19:18:22
hmm, for some reason there are now two spaces afte
| |
| 4987 .SendError("Could not get render view for tab handle"); | |
| 4988 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message, | |
|
kkania
2011/03/17 18:35:11
remove this and the following Send. We are already
Joe
2011/03/18 00:33:32
Is there any documentation with instructions on ho
kkania
2011/03/18 19:18:22
you can take a look at what Nirnimesh wrote a whil
| |
| 4989 false); | |
| 4990 Send(reply_message); | |
| 4991 } | |
| 4992 } | |
| 4993 | |
| 4957 void TestingAutomationProvider::GetCookiesJSON( | 4994 void TestingAutomationProvider::GetCookiesJSON( |
| 4958 DictionaryValue* args, IPC::Message* reply_message) { | 4995 DictionaryValue* args, IPC::Message* reply_message) { |
| 4959 automation_util::GetCookiesJSON(this, args, reply_message); | 4996 automation_util::GetCookiesJSON(this, args, reply_message); |
| 4960 } | 4997 } |
| 4961 | 4998 |
| 4962 void TestingAutomationProvider::DeleteCookieJSON( | 4999 void TestingAutomationProvider::DeleteCookieJSON( |
| 4963 DictionaryValue* args, IPC::Message* reply_message) { | 5000 DictionaryValue* args, IPC::Message* reply_message) { |
| 4964 automation_util::DeleteCookieJSON(this, args, reply_message); | 5001 automation_util::DeleteCookieJSON(this, args, reply_message); |
| 4965 } | 5002 } |
| 4966 | 5003 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5198 // If you change this, update Observer for NotificationType::SESSION_END | 5235 // If you change this, update Observer for NotificationType::SESSION_END |
| 5199 // below. | 5236 // below. |
| 5200 MessageLoop::current()->PostTask(FROM_HERE, | 5237 MessageLoop::current()->PostTask(FROM_HERE, |
| 5201 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5238 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5202 } | 5239 } |
| 5203 } | 5240 } |
| 5204 | 5241 |
| 5205 void TestingAutomationProvider::OnRemoveProvider() { | 5242 void TestingAutomationProvider::OnRemoveProvider() { |
| 5206 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5243 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5207 } | 5244 } |
| OLD | NEW |