| 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" |
| (...skipping 2327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 } | 2338 } |
| 2339 } | 2339 } |
| 2340 | 2340 |
| 2341 // If we get here, error. | 2341 // If we get here, error. |
| 2342 DCHECK(!json_return.empty()); | 2342 DCHECK(!json_return.empty()); |
| 2343 AutomationMsg_SendJSONRequest::WriteReplyParams( | 2343 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2344 reply_message, json_return, false); | 2344 reply_message, json_return, false); |
| 2345 Send(reply_message); | 2345 Send(reply_message); |
| 2346 } | 2346 } |
| 2347 | 2347 |
| 2348 // Sample json input: { "command": "GetThemeInfo" } |
| 2349 // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. |
| 2350 void AutomationProvider::GetThemeInfo(Browser* browser, |
| 2351 DictionaryValue* args, |
| 2352 IPC::Message* reply_message) { |
| 2353 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2354 Extension* theme = browser->profile()->GetTheme(); |
| 2355 if (theme) { |
| 2356 return_value->SetString(L"name", theme->name()); |
| 2357 return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); |
| 2358 return_value->Set(L"colors", theme->GetThemeColors()->DeepCopy()); |
| 2359 return_value->Set(L"tints", theme->GetThemeTints()->DeepCopy()); |
| 2360 } |
| 2361 |
| 2362 std::string json_return; |
| 2363 base::JSONWriter::Write(return_value.get(), false, &json_return); |
| 2364 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2365 reply_message, json_return, true); |
| 2366 Send(reply_message); |
| 2367 } |
| 2368 |
| 2348 /* static */ | 2369 /* static */ |
| 2349 std::string AutomationProvider::JSONErrorString(const std::string& err) { | 2370 std::string AutomationProvider::JSONErrorString(const std::string& err) { |
| 2350 std::string prefix = "{\"error\": \""; | 2371 std::string prefix = "{\"error\": \""; |
| 2351 std::string no_quote_err; | 2372 std::string no_quote_err; |
| 2352 std::string suffix = "\"}"; | 2373 std::string suffix = "\"}"; |
| 2353 | 2374 |
| 2354 base::JsonDoubleQuote(err, false, &no_quote_err); | 2375 base::JsonDoubleQuote(err, false, &no_quote_err); |
| 2355 return prefix + no_quote_err + suffix; | 2376 return prefix + no_quote_err + suffix; |
| 2356 } | 2377 } |
| 2357 | 2378 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; | 2436 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; |
| 2416 | 2437 |
| 2417 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; | 2438 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; |
| 2418 handler_map["WaitForAllDownloadsToComplete"] = | 2439 handler_map["WaitForAllDownloadsToComplete"] = |
| 2419 &AutomationProvider::WaitForDownloadsToComplete; | 2440 &AutomationProvider::WaitForDownloadsToComplete; |
| 2420 | 2441 |
| 2421 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; | 2442 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; |
| 2422 | 2443 |
| 2423 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; | 2444 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; |
| 2424 | 2445 |
| 2446 // SetTheme() implemented using InstallExtension(). |
| 2447 handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; |
| 2448 |
| 2425 if (error_string.empty()) { | 2449 if (error_string.empty()) { |
| 2426 if (handler_map.find(std::string(command)) != handler_map.end()) { | 2450 if (handler_map.find(std::string(command)) != handler_map.end()) { |
| 2427 (this->*handler_map[command])(browser, dict_value, reply_message); | 2451 (this->*handler_map[command])(browser, dict_value, reply_message); |
| 2428 return; | 2452 return; |
| 2429 } else { | 2453 } else { |
| 2430 error_string = "Unknown command. Options: "; | 2454 error_string = "Unknown command. Options: "; |
| 2431 for (std::map<std::string, JsonHandler>::const_iterator it = | 2455 for (std::map<std::string, JsonHandler>::const_iterator it = |
| 2432 handler_map.begin(); it != handler_map.end(); ++it) { | 2456 handler_map.begin(); it != handler_map.end(); ++it) { |
| 2433 error_string += it->first + ", "; | 2457 error_string += it->first + ", "; |
| 2434 } | 2458 } |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3610 } | 3634 } |
| 3611 | 3635 |
| 3612 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 3636 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
| 3613 NOTIMPLEMENTED(); | 3637 NOTIMPLEMENTED(); |
| 3614 } | 3638 } |
| 3615 #endif // !defined(TOOLKIT_VIEWS) | 3639 #endif // !defined(TOOLKIT_VIEWS) |
| 3616 | 3640 |
| 3617 void AutomationProvider::ResetToDefaultTheme() { | 3641 void AutomationProvider::ResetToDefaultTheme() { |
| 3618 profile_->ClearTheme(); | 3642 profile_->ClearTheme(); |
| 3619 } | 3643 } |
| OLD | NEW |