Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 5572001: Send screenshots back to the client for debugging (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: for review, still need to add a few more tests Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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/16 18:19:10 change name here too
Joe 2011/03/17 00:15:25 Done.
2055 &TestingAutomationProvider::GetScreenShotJSON;
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 2882 matching lines...) Expand 10 before | Expand all | Expand 10 after
4945 std::string error; 4948 std::string error;
4946 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { 4949 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
4947 reply.SendError(error); 4950 reply.SendError(error);
4948 return; 4951 return;
4949 } 4952 }
4950 DictionaryValue dict; 4953 DictionaryValue dict;
4951 dict.SetString("title", tab_contents->GetTitle()); 4954 dict.SetString("title", tab_contents->GetTitle());
4952 reply.SendSuccess(&dict); 4955 reply.SendSuccess(&dict);
4953 } 4956 }
4954 4957
4958 void TestingAutomationProvider::GetScreenShotJSON(
4959 DictionaryValue* args,
4960 IPC::Message* reply_message) {
4961 TabContents* tab_contents;
4962 std::string error;
4963
4964 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
4965 AutomationJSONReply(this, reply_message).SendError(error);
4966 return;
4967 }
4968
4969 #if defined(OS_WIN)
4970 string16 path_str;
4971 #elif defined(OS_POSIX)
4972 std::string path_str;
4973 #else
kkania 2011/03/16 18:19:10 I think you can get rid of the #else part; as you
Joe 2011/03/17 00:15:25 Done.
4974 NOTREACHED();
4975 #endif
kkania 2011/03/16 18:19:10 actually, I think you should be able to replace al
Joe 2011/03/17 00:15:25 Done.
4976
4977 if (!args->GetString("path", &path_str)) {
4978 AutomationJSONReply(this, reply_message)
4979 .SendError("'path' missing or invalid");
4980 return;
4981 }
4982
4983 FilePath path(path_str);
4984 RenderViewHost* render_view = tab_contents->render_view_host();
4985 if (render_view) {
4986 // This will delete itself when finished.
4987 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker(
4988 this, reply_message, render_view, path, true);
kkania 2011/03/16 18:19:10 just make the FilePath(path_str) here and get rid
Joe 2011/03/17 00:15:25 Done.
4989 snapshot_taker->Start();
4990 } else {
4991 LOG(ERROR) << "Could not get render view for tab handle";
kkania 2011/03/16 18:19:10 this should be replaced with a AutomationJSONRelpy
Joe 2011/03/17 00:15:25 Done.
4992 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message,
4993 false);
4994 Send(reply_message);
4995 }
4996 }
4997
4955 void TestingAutomationProvider::GetCookiesJSON( 4998 void TestingAutomationProvider::GetCookiesJSON(
4956 DictionaryValue* args, IPC::Message* reply_message) { 4999 DictionaryValue* args, IPC::Message* reply_message) {
4957 automation_util::GetCookiesJSON(this, args, reply_message); 5000 automation_util::GetCookiesJSON(this, args, reply_message);
4958 } 5001 }
4959 5002
4960 void TestingAutomationProvider::DeleteCookieJSON( 5003 void TestingAutomationProvider::DeleteCookieJSON(
4961 DictionaryValue* args, IPC::Message* reply_message) { 5004 DictionaryValue* args, IPC::Message* reply_message) {
4962 automation_util::DeleteCookieJSON(this, args, reply_message); 5005 automation_util::DeleteCookieJSON(this, args, reply_message);
4963 } 5006 }
4964 5007
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
5196 // If you change this, update Observer for NotificationType::SESSION_END 5239 // If you change this, update Observer for NotificationType::SESSION_END
5197 // below. 5240 // below.
5198 MessageLoop::current()->PostTask(FROM_HERE, 5241 MessageLoop::current()->PostTask(FROM_HERE,
5199 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5242 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5200 } 5243 }
5201 } 5244 }
5202 5245
5203 void TestingAutomationProvider::OnRemoveProvider() { 5246 void TestingAutomationProvider::OnRemoveProvider() {
5204 AutomationProviderList::GetInstance()->RemoveProvider(this); 5247 AutomationProviderList::GetInstance()->RemoveProvider(this);
5205 } 5248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698