OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #include "chrome/browser/password_manager/password_store.h" | 73 #include "chrome/browser/password_manager/password_store.h" |
74 #include "chrome/browser/password_manager/password_store_change.h" | 74 #include "chrome/browser/password_manager/password_store_change.h" |
75 #include "chrome/browser/password_manager/password_store_factory.h" | 75 #include "chrome/browser/password_manager/password_store_factory.h" |
76 #include "chrome/browser/platform_util.h" | 76 #include "chrome/browser/platform_util.h" |
77 #include "chrome/browser/plugins/plugin_prefs.h" | 77 #include "chrome/browser/plugins/plugin_prefs.h" |
78 #include "chrome/browser/prefs/pref_service.h" | 78 #include "chrome/browser/prefs/pref_service.h" |
79 #include "chrome/browser/printing/print_preview_tab_controller.h" | 79 #include "chrome/browser/printing/print_preview_tab_controller.h" |
80 #include "chrome/browser/profiles/profile.h" | 80 #include "chrome/browser/profiles/profile.h" |
81 #include "chrome/browser/profiles/profile_info_cache.h" | 81 #include "chrome/browser/profiles/profile_info_cache.h" |
82 #include "chrome/browser/profiles/profile_manager.h" | 82 #include "chrome/browser/profiles/profile_manager.h" |
83 #include "chrome/browser/protector/protector_service.h" | |
84 #include "chrome/browser/protector/protector_service_factory.h" | |
85 #include "chrome/browser/protector/protector_utils.h" | |
86 #include "chrome/browser/search_engines/template_url.h" | 83 #include "chrome/browser/search_engines/template_url.h" |
87 #include "chrome/browser/search_engines/template_url_service.h" | 84 #include "chrome/browser/search_engines/template_url_service.h" |
88 #include "chrome/browser/search_engines/template_url_service_factory.h" | 85 #include "chrome/browser/search_engines/template_url_service_factory.h" |
89 #include "chrome/browser/sessions/session_service_factory.h" | 86 #include "chrome/browser/sessions/session_service_factory.h" |
90 #include "chrome/browser/sessions/session_tab_helper.h" | 87 #include "chrome/browser/sessions/session_tab_helper.h" |
91 #include "chrome/browser/sync/profile_sync_service.h" | 88 #include "chrome/browser/sync/profile_sync_service.h" |
92 #include "chrome/browser/sync/profile_sync_service_factory.h" | 89 #include "chrome/browser/sync/profile_sync_service_factory.h" |
93 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 90 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
94 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 91 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
95 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 92 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 | 1900 |
1904 browser_handler_map_["LoadSearchEngineInfo"] = | 1901 browser_handler_map_["LoadSearchEngineInfo"] = |
1905 &TestingAutomationProvider::LoadSearchEngineInfo; | 1902 &TestingAutomationProvider::LoadSearchEngineInfo; |
1906 browser_handler_map_["GetSearchEngineInfo"] = | 1903 browser_handler_map_["GetSearchEngineInfo"] = |
1907 &TestingAutomationProvider::GetSearchEngineInfo; | 1904 &TestingAutomationProvider::GetSearchEngineInfo; |
1908 browser_handler_map_["AddOrEditSearchEngine"] = | 1905 browser_handler_map_["AddOrEditSearchEngine"] = |
1909 &TestingAutomationProvider::AddOrEditSearchEngine; | 1906 &TestingAutomationProvider::AddOrEditSearchEngine; |
1910 browser_handler_map_["PerformActionOnSearchEngine"] = | 1907 browser_handler_map_["PerformActionOnSearchEngine"] = |
1911 &TestingAutomationProvider::PerformActionOnSearchEngine; | 1908 &TestingAutomationProvider::PerformActionOnSearchEngine; |
1912 | 1909 |
1913 #if defined(ENABLE_PROTECTOR_SERVICE) | |
1914 browser_handler_map_["GetProtectorState"] = | |
1915 &TestingAutomationProvider::GetProtectorState; | |
1916 browser_handler_map_["PerformProtectorAction"] = | |
1917 &TestingAutomationProvider::PerformProtectorAction; | |
1918 #endif | |
1919 | |
1920 browser_handler_map_["SetWindowDimensions"] = | 1910 browser_handler_map_["SetWindowDimensions"] = |
1921 &TestingAutomationProvider::SetWindowDimensions; | 1911 &TestingAutomationProvider::SetWindowDimensions; |
1922 | 1912 |
1923 browser_handler_map_["GetDownloadsInfo"] = | 1913 browser_handler_map_["GetDownloadsInfo"] = |
1924 &TestingAutomationProvider::GetDownloadsInfo; | 1914 &TestingAutomationProvider::GetDownloadsInfo; |
1925 browser_handler_map_["WaitForAllDownloadsToComplete"] = | 1915 browser_handler_map_["WaitForAllDownloadsToComplete"] = |
1926 &TestingAutomationProvider::WaitForAllDownloadsToComplete; | 1916 &TestingAutomationProvider::WaitForAllDownloadsToComplete; |
1927 browser_handler_map_["PerformActionOnDownload"] = | 1917 browser_handler_map_["PerformActionOnDownload"] = |
1928 &TestingAutomationProvider::PerformActionOnDownload; | 1918 &TestingAutomationProvider::PerformActionOnDownload; |
1929 | 1919 |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2924 } else if (action == "default") { | 2914 } else if (action == "default") { |
2925 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 2915 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
2926 this, browser->profile(), reply_message)); | 2916 this, browser->profile(), reply_message)); |
2927 url_model->SetDefaultSearchProvider(template_url); | 2917 url_model->SetDefaultSearchProvider(template_url); |
2928 } else { | 2918 } else { |
2929 AutomationJSONReply(this, reply_message).SendError( | 2919 AutomationJSONReply(this, reply_message).SendError( |
2930 "Invalid action: " + action); | 2920 "Invalid action: " + action); |
2931 } | 2921 } |
2932 } | 2922 } |
2933 | 2923 |
2934 #if defined(ENABLE_PROTECTOR_SERVICE) | |
2935 // Sample json output: { "enabled": true, | |
2936 // "showing_change": false } | |
2937 void TestingAutomationProvider::GetProtectorState( | |
2938 Browser* browser, | |
2939 DictionaryValue* args, | |
2940 IPC::Message* reply_message) { | |
2941 protector::ProtectorService* protector_service = | |
2942 protector::ProtectorServiceFactory::GetForProfile(browser->profile()); | |
2943 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
2944 return_value->SetBoolean("enabled", protector::IsEnabled()); | |
2945 return_value->SetBoolean("showing_change", | |
2946 protector_service->IsShowingChange()); | |
2947 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | |
2948 } | |
2949 | |
2950 // Sample json inputs: | |
2951 // { "command": "PerformProtectorAction", "action": "apply_change" } | |
2952 // { "command": "PerformProtectorAction", "action": "discard_change" } | |
2953 void TestingAutomationProvider::PerformProtectorAction( | |
2954 Browser* browser, | |
2955 base::DictionaryValue* args, | |
2956 IPC::Message* reply_message) { | |
2957 protector::ProtectorService* protector_service = | |
2958 protector::ProtectorServiceFactory::GetForProfile(browser->profile()); | |
2959 AutomationJSONReply reply(this, reply_message); | |
2960 if (!protector::IsEnabled()) { | |
2961 reply.SendError("Protector is disabled"); | |
2962 return; | |
2963 } | |
2964 std::string action; | |
2965 if (!args->GetString("action", &action)) { | |
2966 reply.SendError("Missing 'action' value"); | |
2967 return; | |
2968 } | |
2969 protector::BaseSettingChange* change = | |
2970 protector_service->GetLastChange(); | |
2971 if (action == "apply_change") | |
2972 protector_service->ApplyChange(change, browser); | |
2973 else if (action == "discard_change") | |
2974 protector_service->DiscardChange(change, browser); | |
2975 else | |
2976 return reply.SendError("Invalid 'action' value"); | |
2977 reply.SendSuccess(NULL); | |
2978 } | |
2979 #endif // defined(ENABLE_PROTECTOR_SERVICE) | |
2980 | |
2981 // Sample json input: { "command": "GetLocalStatePrefsInfo" } | 2924 // Sample json input: { "command": "GetLocalStatePrefsInfo" } |
2982 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. | 2925 // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
2983 void TestingAutomationProvider::GetLocalStatePrefsInfo( | 2926 void TestingAutomationProvider::GetLocalStatePrefsInfo( |
2984 DictionaryValue* args, | 2927 DictionaryValue* args, |
2985 IPC::Message* reply_message) { | 2928 IPC::Message* reply_message) { |
2986 DictionaryValue* items = g_browser_process->local_state()-> | 2929 DictionaryValue* items = g_browser_process->local_state()-> |
2987 GetPreferenceValues(); | 2930 GetPreferenceValues(); |
2988 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2931 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
2989 return_value->Set("prefs", items); // return_value owns items. | 2932 return_value->Set("prefs", items); // return_value owns items. |
2990 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2933 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
(...skipping 3373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6364 if (g_browser_process) | 6307 if (g_browser_process) |
6365 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6308 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6366 } | 6309 } |
6367 | 6310 |
6368 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6311 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
6369 WebContents* tab) { | 6312 WebContents* tab) { |
6370 TabStripModel* tab_strip = browser->tab_strip_model(); | 6313 TabStripModel* tab_strip = browser->tab_strip_model(); |
6371 if (tab_strip->GetActiveWebContents() != tab) | 6314 if (tab_strip->GetActiveWebContents() != tab) |
6372 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 6315 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
6373 } | 6316 } |
OLD | NEW |