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

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: removed functions 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 AutomationMsg_GoBackBlockUntilNavigationsComplete, 351 AutomationMsg_GoBackBlockUntilNavigationsComplete,
351 GoBackBlockUntilNavigationsComplete) 352 GoBackBlockUntilNavigationsComplete)
352 IPC_MESSAGE_HANDLER_DELAY_REPLY( 353 IPC_MESSAGE_HANDLER_DELAY_REPLY(
353 AutomationMsg_GoForwardBlockUntilNavigationsComplete, 354 AutomationMsg_GoForwardBlockUntilNavigationsComplete,
354 GoForwardBlockUntilNavigationsComplete) 355 GoForwardBlockUntilNavigationsComplete)
355 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, 356 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser,
356 SavePackageShouldPromptUser) 357 SavePackageShouldPromptUser)
357 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) 358 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle)
358 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) 359 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility)
359 IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) 360 IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount)
360 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CaptureEntirePageAsPNG,
361 CaptureEntirePageAsPNG)
362 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, 361 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
363 SendJSONRequest) 362 SendJSONRequest)
364 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome, 363 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabCountToBecome,
365 WaitForTabCountToBecome) 364 WaitForTabCountToBecome)
366 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount, 365 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForInfoBarCount,
367 WaitForInfoBarCount) 366 WaitForInfoBarCount)
368 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, 367 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding,
369 GetPageCurrentEncoding) 368 GetPageCurrentEncoding)
370 IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService, 369 IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService,
371 ShutdownSessionService) 370 ShutdownSessionService)
(...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 *count = static_cast<int>(container->GetBlockedContentsCount()); 1982 *count = static_cast<int>(container->GetBlockedContentsCount());
1984 } else { 1983 } else {
1985 // If we don't have a container, we don't have any blocked popups to 1984 // If we don't have a container, we don't have any blocked popups to
1986 // contain! 1985 // contain!
1987 *count = 0; 1986 *count = 0;
1988 } 1987 }
1989 } 1988 }
1990 } 1989 }
1991 } 1990 }
1992 1991
1993 void TestingAutomationProvider::CaptureEntirePageAsPNG(
1994 int tab_handle, const FilePath& path, IPC::Message* reply_message) {
1995 RenderViewHost* render_view = GetViewForTab(tab_handle);
1996 if (render_view) {
1997 // This will delete itself when finished.
1998 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker(
1999 this, reply_message, render_view, path);
2000 snapshot_taker->Start();
2001 } else {
2002 LOG(ERROR) << "Could not get render view for tab handle";
2003 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message,
2004 false);
2005 Send(reply_message);
2006 }
2007 }
2008
2009 void TestingAutomationProvider::SendJSONRequest(int handle, 1992 void TestingAutomationProvider::SendJSONRequest(int handle,
2010 std::string json_request, 1993 std::string json_request,
2011 IPC::Message* reply_message) { 1994 IPC::Message* reply_message) {
2012 scoped_ptr<Value> values; 1995 scoped_ptr<Value> values;
2013 base::JSONReader reader; 1996 base::JSONReader reader;
2014 std::string error; 1997 std::string error;
2015 values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error)); 1998 values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error));
2016 if (!error.empty()) { 1999 if (!error.empty()) {
2017 AutomationJSONReply(this, reply_message).SendError(error); 2000 AutomationJSONReply(this, reply_message).SendError(error);
2018 return; 2001 return;
(...skipping 27 matching lines...) Expand all
2046 handler_map["GoForward"] = 2029 handler_map["GoForward"] =
2047 &TestingAutomationProvider::GoForward; 2030 &TestingAutomationProvider::GoForward;
2048 handler_map["GoBack"] = 2031 handler_map["GoBack"] =
2049 &TestingAutomationProvider::GoBack; 2032 &TestingAutomationProvider::GoBack;
2050 handler_map["Reload"] = 2033 handler_map["Reload"] =
2051 &TestingAutomationProvider::ReloadJSON; 2034 &TestingAutomationProvider::ReloadJSON;
2052 handler_map["GetTabURL"] = 2035 handler_map["GetTabURL"] =
2053 &TestingAutomationProvider::GetTabURLJSON; 2036 &TestingAutomationProvider::GetTabURLJSON;
2054 handler_map["GetTabTitle"] = 2037 handler_map["GetTabTitle"] =
2055 &TestingAutomationProvider::GetTabTitleJSON; 2038 &TestingAutomationProvider::GetTabTitleJSON;
2039 handler_map["CaptureEntirePage"] =
2040 &TestingAutomationProvider::CaptureEntirePageJSON;
2056 handler_map["GetCookies"] = 2041 handler_map["GetCookies"] =
2057 &TestingAutomationProvider::GetCookiesJSON; 2042 &TestingAutomationProvider::GetCookiesJSON;
2058 handler_map["DeleteCookie"] = 2043 handler_map["DeleteCookie"] =
2059 &TestingAutomationProvider::DeleteCookieJSON; 2044 &TestingAutomationProvider::DeleteCookieJSON;
2060 handler_map["SetCookie"] = 2045 handler_map["SetCookie"] =
2061 &TestingAutomationProvider::SetCookieJSON; 2046 &TestingAutomationProvider::SetCookieJSON;
2062 handler_map["GetTabIds"] = 2047 handler_map["GetTabIds"] =
2063 &TestingAutomationProvider::GetTabIds; 2048 &TestingAutomationProvider::GetTabIds;
2064 handler_map["IsTabIdValid"] = 2049 handler_map["IsTabIdValid"] =
2065 &TestingAutomationProvider::IsTabIdValid; 2050 &TestingAutomationProvider::IsTabIdValid;
(...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after
4953 std::string error; 4938 std::string error;
4954 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { 4939 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
4955 reply.SendError(error); 4940 reply.SendError(error);
4956 return; 4941 return;
4957 } 4942 }
4958 DictionaryValue dict; 4943 DictionaryValue dict;
4959 dict.SetString("title", tab_contents->GetTitle()); 4944 dict.SetString("title", tab_contents->GetTitle());
4960 reply.SendSuccess(&dict); 4945 reply.SendSuccess(&dict);
4961 } 4946 }
4962 4947
4948 void TestingAutomationProvider::CaptureEntirePageJSON(
4949 DictionaryValue* args,
4950 IPC::Message* reply_message) {
4951 TabContents* tab_contents;
4952 std::string error;
4953
4954 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
4955 AutomationJSONReply(this, reply_message).SendError(error);
4956 return;
4957 }
4958
4959 FilePath::StringType path_str;
4960 if (!args->GetString("path", &path_str)) {
4961 AutomationJSONReply(this, reply_message)
4962 .SendError("'path' missing or invalid");
4963 return;
4964 }
4965
4966 RenderViewHost* render_view = tab_contents->render_view_host();
4967 if (render_view) {
4968 FilePath path(path_str);
4969 // This will delete itself when finished.
4970 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker(
4971 this, reply_message, render_view, path);
4972 snapshot_taker->Start();
4973 } else {
4974 AutomationJSONReply(this, reply_message)
4975 .SendError("Tab has no associated RenderViewHost");
4976 }
4977 }
4978
4963 void TestingAutomationProvider::GetCookiesJSON( 4979 void TestingAutomationProvider::GetCookiesJSON(
4964 DictionaryValue* args, IPC::Message* reply_message) { 4980 DictionaryValue* args, IPC::Message* reply_message) {
4965 automation_util::GetCookiesJSON(this, args, reply_message); 4981 automation_util::GetCookiesJSON(this, args, reply_message);
4966 } 4982 }
4967 4983
4968 void TestingAutomationProvider::DeleteCookieJSON( 4984 void TestingAutomationProvider::DeleteCookieJSON(
4969 DictionaryValue* args, IPC::Message* reply_message) { 4985 DictionaryValue* args, IPC::Message* reply_message) {
4970 automation_util::DeleteCookieJSON(this, args, reply_message); 4986 automation_util::DeleteCookieJSON(this, args, reply_message);
4971 } 4987 }
4972 4988
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
5204 // If you change this, update Observer for NotificationType::SESSION_END 5220 // If you change this, update Observer for NotificationType::SESSION_END
5205 // below. 5221 // below.
5206 MessageLoop::current()->PostTask(FROM_HERE, 5222 MessageLoop::current()->PostTask(FROM_HERE,
5207 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5223 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5208 } 5224 }
5209 } 5225 }
5210 5226
5211 void TestingAutomationProvider::OnRemoveProvider() { 5227 void TestingAutomationProvider::OnRemoveProvider() {
5212 AutomationProviderList::GetInstance()->RemoveProvider(this); 5228 AutomationProviderList::GetInstance()->RemoveProvider(this);
5213 } 5229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698