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 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 } | 2342 } |
2343 } | 2343 } |
2344 | 2344 |
2345 // If we get here, error. | 2345 // If we get here, error. |
2346 DCHECK(!json_return.empty()); | 2346 DCHECK(!json_return.empty()); |
2347 AutomationMsg_SendJSONRequest::WriteReplyParams( | 2347 AutomationMsg_SendJSONRequest::WriteReplyParams( |
2348 reply_message, json_return, false); | 2348 reply_message, json_return, false); |
2349 Send(reply_message); | 2349 Send(reply_message); |
2350 } | 2350 } |
2351 | 2351 |
| 2352 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample |
| 2353 // json input. |
| 2354 // Sample json output: {} |
| 2355 void AutomationProvider::ClearBrowsingData(Browser* browser, |
| 2356 DictionaryValue* args, |
| 2357 IPC::Message* reply_message) { |
| 2358 std::string json_return = "{}"; |
| 2359 |
| 2360 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; |
| 2361 string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR; |
| 2362 string_to_time_period["LAST_DAY"] = BrowsingDataRemover::LAST_DAY; |
| 2363 string_to_time_period["LAST_WEEK"] = BrowsingDataRemover::LAST_WEEK; |
| 2364 string_to_time_period["FOUR_WEEKS"] = BrowsingDataRemover::FOUR_WEEKS; |
| 2365 string_to_time_period["EVERYTHING"] = BrowsingDataRemover::EVERYTHING; |
| 2366 |
| 2367 std::map<std::string, int> string_to_mask_value; |
| 2368 string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY; |
| 2369 string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS; |
| 2370 string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_COOKIES; |
| 2371 string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS; |
| 2372 string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA; |
| 2373 string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE; |
| 2374 |
| 2375 std::string time_period; |
| 2376 ListValue* to_remove; |
| 2377 if (!args->GetString(L"time_period", &time_period) || |
| 2378 !args->GetList(L"to_remove", &to_remove)) { |
| 2379 // TODO(nirnimesh): Here and below refactor returns with pending CL. |
| 2380 std::string json_return = |
| 2381 JSONErrorString("time_period must be a string and to_remove a list."); |
| 2382 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2383 reply_message, json_return, false); |
| 2384 Send(reply_message); |
| 2385 return; |
| 2386 } |
| 2387 |
| 2388 int remove_mask = 0; |
| 2389 int num_removals = to_remove->GetSize(); |
| 2390 for (int i = 0; i < num_removals; i++) { |
| 2391 std::string removal; |
| 2392 to_remove->GetString(i, &removal); |
| 2393 // If the provided string is not part of the map, then error out. |
| 2394 if (!ContainsKey(string_to_mask_value, removal)) { |
| 2395 std::string json_return = |
| 2396 JSONErrorString("Invalid browsing data string found in to_remove."); |
| 2397 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2398 reply_message, json_return, false); |
| 2399 Send(reply_message); |
| 2400 return; |
| 2401 } |
| 2402 remove_mask |= string_to_mask_value[removal]; |
| 2403 } |
| 2404 |
| 2405 if (!ContainsKey(string_to_time_period, time_period)) { |
| 2406 std::string json_return = |
| 2407 JSONErrorString("Invalid string for time_period."); |
| 2408 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2409 reply_message, json_return, false); |
| 2410 Send(reply_message); |
| 2411 return; |
| 2412 } |
| 2413 |
| 2414 BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 2415 profile(), string_to_time_period[time_period], base::Time()); |
| 2416 |
| 2417 remover->AddObserver( |
| 2418 new AutomationProviderBrowsingDataObserver(this, reply_message)); |
| 2419 remover->Remove(remove_mask); |
| 2420 // BrowsingDataRemover deletes itself using DeleteTask. |
| 2421 // The observer also deletes itself after sending the reply. |
| 2422 } |
| 2423 |
2352 // Sample json input: { "command": "GetThemeInfo" } | 2424 // Sample json input: { "command": "GetThemeInfo" } |
2353 // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. | 2425 // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. |
2354 void AutomationProvider::GetThemeInfo(Browser* browser, | 2426 void AutomationProvider::GetThemeInfo(Browser* browser, |
2355 DictionaryValue* args, | 2427 DictionaryValue* args, |
2356 IPC::Message* reply_message) { | 2428 IPC::Message* reply_message) { |
2357 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2429 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
2358 Extension* theme = browser->profile()->GetTheme(); | 2430 Extension* theme = browser->profile()->GetTheme(); |
2359 if (theme) { | 2431 if (theme) { |
2360 return_value->SetString(L"name", theme->name()); | 2432 return_value->SetString(L"name", theme->name()); |
2361 return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); | 2433 return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2693 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; | 2765 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; |
2694 | 2766 |
2695 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; | 2767 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; |
2696 handler_map["WaitForAllDownloadsToComplete"] = | 2768 handler_map["WaitForAllDownloadsToComplete"] = |
2697 &AutomationProvider::WaitForDownloadsToComplete; | 2769 &AutomationProvider::WaitForDownloadsToComplete; |
2698 | 2770 |
2699 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; | 2771 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; |
2700 | 2772 |
2701 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; | 2773 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; |
2702 | 2774 |
| 2775 handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData; |
| 2776 |
2703 // SetTheme() implemented using InstallExtension(). | 2777 // SetTheme() implemented using InstallExtension(). |
2704 handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; | 2778 handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; |
2705 | 2779 |
2706 handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; | 2780 handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; |
2707 handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; | 2781 handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; |
2708 | 2782 |
2709 if (error_string.empty()) { | 2783 if (error_string.empty()) { |
2710 if (handler_map.find(std::string(command)) != handler_map.end()) { | 2784 if (handler_map.find(std::string(command)) != handler_map.end()) { |
2711 (this->*handler_map[command])(browser, dict_value, reply_message); | 2785 (this->*handler_map[command])(browser, dict_value, reply_message); |
2712 return; | 2786 return; |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3894 } | 3968 } |
3895 | 3969 |
3896 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 3970 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
3897 NOTIMPLEMENTED(); | 3971 NOTIMPLEMENTED(); |
3898 } | 3972 } |
3899 #endif // !defined(TOOLKIT_VIEWS) | 3973 #endif // !defined(TOOLKIT_VIEWS) |
3900 | 3974 |
3901 void AutomationProvider::ResetToDefaultTheme() { | 3975 void AutomationProvider::ResetToDefaultTheme() { |
3902 profile_->ClearTheme(); | 3976 profile_->ClearTheme(); |
3903 } | 3977 } |
OLD | NEW |