| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "chrome/browser/extensions/extension_install_ui.h" | 55 #include "chrome/browser/extensions/extension_install_ui.h" |
| 56 #include "chrome/browser/extensions/extension_message_service.h" | 56 #include "chrome/browser/extensions/extension_message_service.h" |
| 57 #include "chrome/browser/extensions/extension_tabs_module.h" | 57 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 58 #include "chrome/browser/extensions/extension_toolbar_model.h" | 58 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 59 #include "chrome/browser/extensions/extensions_service.h" | 59 #include "chrome/browser/extensions/extensions_service.h" |
| 60 #include "chrome/browser/extensions/user_script_master.h" | 60 #include "chrome/browser/extensions/user_script_master.h" |
| 61 #include "chrome/browser/find_bar.h" | 61 #include "chrome/browser/find_bar.h" |
| 62 #include "chrome/browser/find_bar_controller.h" | 62 #include "chrome/browser/find_bar_controller.h" |
| 63 #include "chrome/browser/find_notification_details.h" | 63 #include "chrome/browser/find_notification_details.h" |
| 64 #include "chrome/browser/host_content_settings_map.h" | 64 #include "chrome/browser/host_content_settings_map.h" |
| 65 #include "chrome/browser/importer/importer.h" |
| 66 #include "chrome/browser/importer/importer_data_types.h" |
| 65 #include "chrome/browser/io_thread.h" | 67 #include "chrome/browser/io_thread.h" |
| 66 #include "chrome/browser/location_bar.h" | 68 #include "chrome/browser/location_bar.h" |
| 67 #include "chrome/browser/login_prompt.h" | 69 #include "chrome/browser/login_prompt.h" |
| 68 #include "chrome/browser/net/url_request_mock_util.h" | 70 #include "chrome/browser/net/url_request_mock_util.h" |
| 69 #include "chrome/browser/platform_util.h" | 71 #include "chrome/browser/platform_util.h" |
| 70 #include "chrome/browser/pref_service.h" | 72 #include "chrome/browser/pref_service.h" |
| 71 #include "chrome/browser/printing/print_job.h" | 73 #include "chrome/browser/printing/print_job.h" |
| 72 #include "chrome/browser/profile_manager.h" | 74 #include "chrome/browser/profile_manager.h" |
| 73 #include "chrome/browser/renderer_host/render_process_host.h" | 75 #include "chrome/browser/renderer_host/render_process_host.h" |
| 74 #include "chrome/browser/renderer_host/render_view_host.h" | 76 #include "chrome/browser/renderer_host/render_view_host.h" |
| (...skipping 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 } | 2357 } |
| 2356 } | 2358 } |
| 2357 | 2359 |
| 2358 // If we get here, error. | 2360 // If we get here, error. |
| 2359 DCHECK(!json_return.empty()); | 2361 DCHECK(!json_return.empty()); |
| 2360 AutomationMsg_SendJSONRequest::WriteReplyParams( | 2362 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2361 reply_message, json_return, false); | 2363 reply_message, json_return, false); |
| 2362 Send(reply_message); | 2364 Send(reply_message); |
| 2363 } | 2365 } |
| 2364 | 2366 |
| 2367 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample |
| 2368 // json input. |
| 2369 // Sample json output: "{}" |
| 2370 void AutomationProvider::ImportSettings(Browser* browser, |
| 2371 DictionaryValue* args, |
| 2372 IPC::Message* reply_message) { |
| 2373 std::string json_return = "{}"; |
| 2374 |
| 2375 // Map from the json string passed over to the import item masks. |
| 2376 std::map<std::string, ImportItem> string_to_import_item; |
| 2377 string_to_import_item["HISTORY"] = importer::HISTORY; |
| 2378 string_to_import_item["FAVORITES"] = importer::FAVORITES; |
| 2379 string_to_import_item["COOKIES"] = importer::COOKIES; |
| 2380 string_to_import_item["PASSWORDS"] = importer::PASSWORDS; |
| 2381 string_to_import_item["SEARCH_ENGINES"] = importer::SEARCH_ENGINES; |
| 2382 string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; |
| 2383 string_to_import_item["ALL"] = importer::ALL; |
| 2384 |
| 2385 std::wstring browser_name; |
| 2386 int import_items = 0; |
| 2387 ListValue* import_items_list = NULL; |
| 2388 bool first_run; |
| 2389 |
| 2390 if (!args->GetString(L"import_from", &browser_name) || |
| 2391 !args->GetBoolean(L"first_run", &first_run) || |
| 2392 !args->GetList(L"import_items", &import_items_list)) { |
| 2393 std::string json_return = |
| 2394 JSONErrorString("Incorrect type for one or more of the arguments."); |
| 2395 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2396 reply_message, json_return, false); |
| 2397 Send(reply_message); |
| 2398 return; |
| 2399 } |
| 2400 |
| 2401 int num_items = import_items_list->GetSize(); |
| 2402 for (int i = 0; i < num_items; i++) { |
| 2403 std::string item; |
| 2404 import_items_list->GetString(i, &item); |
| 2405 // If the provided string is not part of the map, error out. |
| 2406 if (!ContainsKey(string_to_import_item, item)) { |
| 2407 json_return = |
| 2408 JSONErrorString("Invalid item string found in import_items."); |
| 2409 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2410 reply_message, json_return, false); |
| 2411 Send(reply_message); |
| 2412 return; |
| 2413 } |
| 2414 import_items |= string_to_import_item[item]; |
| 2415 } |
| 2416 |
| 2417 ImporterHost* importer_host = new ImporterHost(); |
| 2418 // Get the correct ProfileInfo based on the browser they user provided. |
| 2419 importer::ProfileInfo profile_info; |
| 2420 int num_browsers = importer_host->GetAvailableProfileCount(); |
| 2421 int i = 0; |
| 2422 for ( ; i < num_browsers; i++) { |
| 2423 std::wstring name = importer_host->GetSourceProfileNameAt(i); |
| 2424 if (name == browser_name) { |
| 2425 profile_info = importer_host->GetSourceProfileInfoAt(i); |
| 2426 break; |
| 2427 } |
| 2428 } |
| 2429 // If we made it to the end of the loop, then the input was bad. |
| 2430 if (i == num_browsers) { |
| 2431 json_return = |
| 2432 JSONErrorString("Invalid browser name string found."); |
| 2433 AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2434 reply_message, json_return, false); |
| 2435 Send(reply_message); |
| 2436 return; |
| 2437 } |
| 2438 |
| 2439 Profile* profile = browser->profile(); |
| 2440 |
| 2441 importer_host->SetObserver( |
| 2442 new AutomationProviderImportSettingsObserver(this, reply_message)); |
| 2443 importer_host->StartImportSettings(profile_info, profile, import_items, |
| 2444 new ProfileWriter(profile), first_run); |
| 2445 } |
| 2446 |
| 2365 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample | 2447 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample |
| 2366 // json input. | 2448 // json input. |
| 2367 // Sample json output: {} | 2449 // Sample json output: {} |
| 2368 void AutomationProvider::ClearBrowsingData(Browser* browser, | 2450 void AutomationProvider::ClearBrowsingData(Browser* browser, |
| 2369 DictionaryValue* args, | 2451 DictionaryValue* args, |
| 2370 IPC::Message* reply_message) { | 2452 IPC::Message* reply_message) { |
| 2371 std::string json_return = "{}"; | 2453 std::string json_return = "{}"; |
| 2372 | 2454 |
| 2373 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; | 2455 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; |
| 2374 string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR; | 2456 string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2778 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; | 2860 handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; |
| 2779 | 2861 |
| 2780 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; | 2862 handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; |
| 2781 handler_map["WaitForAllDownloadsToComplete"] = | 2863 handler_map["WaitForAllDownloadsToComplete"] = |
| 2782 &AutomationProvider::WaitForDownloadsToComplete; | 2864 &AutomationProvider::WaitForDownloadsToComplete; |
| 2783 | 2865 |
| 2784 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; | 2866 handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; |
| 2785 | 2867 |
| 2786 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; | 2868 handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; |
| 2787 | 2869 |
| 2870 handler_map["ImportSettings"] = &AutomationProvider::ImportSettings; |
| 2871 |
| 2788 handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData; | 2872 handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData; |
| 2789 | 2873 |
| 2790 // SetTheme() implemented using InstallExtension(). | 2874 // SetTheme() implemented using InstallExtension(). |
| 2791 handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; | 2875 handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; |
| 2792 | 2876 |
| 2793 handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; | 2877 handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; |
| 2794 handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; | 2878 handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; |
| 2795 | 2879 |
| 2796 if (error_string.empty()) { | 2880 if (error_string.empty()) { |
| 2797 if (handler_map.find(std::string(command)) != handler_map.end()) { | 2881 if (handler_map.find(std::string(command)) != handler_map.end()) { |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3981 } | 4065 } |
| 3982 | 4066 |
| 3983 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 4067 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
| 3984 NOTIMPLEMENTED(); | 4068 NOTIMPLEMENTED(); |
| 3985 } | 4069 } |
| 3986 #endif // !defined(TOOLKIT_VIEWS) | 4070 #endif // !defined(TOOLKIT_VIEWS) |
| 3987 | 4071 |
| 3988 void AutomationProvider::ResetToDefaultTheme() { | 4072 void AutomationProvider::ResetToDefaultTheme() { |
| 3989 profile_->ClearTheme(); | 4073 profile_->ClearTheme(); |
| 3990 } | 4074 } |
| OLD | NEW |