OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_version_info.h" | 13 #include "base/file_version_info.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/json/string_escape.h" |
16 #include "base/keyboard_codes.h" | 17 #include "base/keyboard_codes.h" |
17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
20 #include "base/stl_util-inl.h" | 21 #include "base/stl_util-inl.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/thread.h" | 23 #include "base/thread.h" |
23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
24 #include "base/values.h" | 25 #include "base/values.h" |
25 #include "chrome/app/chrome_dll_resource.h" | 26 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 if (args->GetInteger(L"width", &width)) | 1603 if (args->GetInteger(L"width", &width)) |
1603 rect.set_width(width); | 1604 rect.set_width(width); |
1604 if (args->GetInteger(L"height", &height)) | 1605 if (args->GetInteger(L"height", &height)) |
1605 rect.set_height(height); | 1606 rect.set_height(height); |
1606 browser->window()->SetBounds(rect); | 1607 browser->window()->SetBounds(rect); |
1607 AutomationMsg_SendJSONRequest::WriteReplyParams( | 1608 AutomationMsg_SendJSONRequest::WriteReplyParams( |
1608 reply_message, std::string("{}"), true); | 1609 reply_message, std::string("{}"), true); |
1609 Send(reply_message); | 1610 Send(reply_message); |
1610 } | 1611 } |
1611 | 1612 |
1612 std::string AutomationProvider::JSONErrorString(std::string err) { | |
1613 std::string prefix = "{\"error\": \""; | |
1614 std::string no_quote_err = err; | |
1615 std::string suffix = "\"}"; | |
1616 | |
1617 // Don't allow input string to break JSON by embedding quotes. | |
1618 // Try and make sure the input string won't break json quoting rules. | |
1619 if (no_quote_err.find("\"") != std::string::npos) | |
1620 no_quote_err = "unhappy about embedded quote in error string"; | |
1621 | |
1622 return prefix + no_quote_err + suffix; | |
1623 } | |
1624 | |
1625 // Sample json input: { "command": "GetBrowserInfo" } | 1613 // Sample json input: { "command": "GetBrowserInfo" } |
1626 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 1614 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
1627 // sample json output. | 1615 // sample json output. |
1628 void AutomationProvider::GetBrowserInfo(Browser* browser, | 1616 void AutomationProvider::GetBrowserInfo(Browser* browser, |
1629 DictionaryValue* args, | 1617 DictionaryValue* args, |
1630 IPC::Message* reply_message) { | 1618 IPC::Message* reply_message) { |
1631 std::string json_return; | 1619 std::string json_return; |
1632 bool reply_return = true; | 1620 bool reply_return = true; |
1633 | 1621 |
1634 DictionaryValue* properties = new DictionaryValue; | 1622 DictionaryValue* properties = new DictionaryValue; |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 SavePackage::SAVE_AS_ONLY_HTML)) { | 2223 SavePackage::SAVE_AS_ONLY_HTML)) { |
2236 json_return = JSONErrorString("Could not initiate SavePage"); | 2224 json_return = JSONErrorString("Could not initiate SavePage"); |
2237 } else { | 2225 } else { |
2238 // The observer will delete itself when done. | 2226 // The observer will delete itself when done. |
2239 new SavePackageNotificationObserver(tab_contents->save_package(), | 2227 new SavePackageNotificationObserver(tab_contents->save_package(), |
2240 this, reply_message); | 2228 this, reply_message); |
2241 return; | 2229 return; |
2242 } | 2230 } |
2243 } | 2231 } |
2244 | 2232 |
2245 // if we get here, error. | 2233 // If we get here, error. |
2246 DCHECK(!json_return.empty()); | 2234 DCHECK(!json_return.empty()); |
2247 AutomationMsg_SendJSONRequest::WriteReplyParams( | 2235 AutomationMsg_SendJSONRequest::WriteReplyParams( |
2248 reply_message, json_return, false); | 2236 reply_message, json_return, false); |
2249 Send(reply_message); | 2237 Send(reply_message); |
2250 } | 2238 } |
2251 | 2239 |
| 2240 /* static */ |
| 2241 std::string AutomationProvider::JSONErrorString(std::string err) { |
| 2242 std::string prefix = "{\"error\": \""; |
| 2243 std::string no_quote_err; |
| 2244 std::string suffix = "\"}"; |
| 2245 |
| 2246 base::JsonDoubleQuote(err, false, &no_quote_err); |
| 2247 return prefix + no_quote_err + suffix; |
| 2248 } |
| 2249 |
2252 void AutomationProvider::SendJSONRequest(int handle, | 2250 void AutomationProvider::SendJSONRequest(int handle, |
2253 std::string json_request, | 2251 std::string json_request, |
2254 IPC::Message* reply_message) { | 2252 IPC::Message* reply_message) { |
2255 Browser* browser = NULL; | 2253 Browser* browser = NULL; |
2256 std::string error_string; | 2254 std::string error_string; |
2257 scoped_ptr<Value> values; | 2255 scoped_ptr<Value> values; |
2258 | 2256 |
2259 // Basic error checking. | 2257 // Basic error checking. |
2260 if (browser_tracker_->ContainsHandle(handle)) { | 2258 if (browser_tracker_->ContainsHandle(handle)) { |
2261 browser = browser_tracker_->GetResource(handle); | 2259 browser = browser_tracker_->GetResource(handle); |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3504 } | 3502 } |
3505 | 3503 |
3506 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 3504 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
3507 NOTIMPLEMENTED(); | 3505 NOTIMPLEMENTED(); |
3508 } | 3506 } |
3509 #endif // !defined(TOOLKIT_VIEWS) | 3507 #endif // !defined(TOOLKIT_VIEWS) |
3510 | 3508 |
3511 void AutomationProvider::ResetToDefaultTheme() { | 3509 void AutomationProvider::ResetToDefaultTheme() { |
3512 profile_->ClearTheme(); | 3510 profile_->ClearTheme(); |
3513 } | 3511 } |
OLD | NEW |