Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 113482: Adding the ability to alter Chrome's proxy settings via the automation interf... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "app/message_box_flags.h" 7 #include "app/message_box_flags.h"
8 #include "base/file_version_info.h" 8 #include "base/file_version_info.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/thread.h" 12 #include "base/thread.h"
13 #include "base/values.h"
13 #include "chrome/app/chrome_dll_resource.h" 14 #include "chrome/app/chrome_dll_resource.h"
14 #include "chrome/browser/app_modal_dialog.h" 15 #include "chrome/browser/app_modal_dialog.h"
15 #include "chrome/browser/app_modal_dialog_queue.h" 16 #include "chrome/browser/app_modal_dialog_queue.h"
16 #include "chrome/browser/automation/automation_provider_list.h" 17 #include "chrome/browser/automation/automation_provider_list.h"
17 #include "chrome/browser/automation/url_request_failed_dns_job.h" 18 #include "chrome/browser/automation/url_request_failed_dns_job.h"
18 #include "chrome/browser/automation/url_request_mock_http_job.h" 19 #include "chrome/browser/automation/url_request_mock_http_job.h"
19 #include "chrome/browser/automation/url_request_slow_download_job.h" 20 #include "chrome/browser/automation/url_request_slow_download_job.h"
20 #include "chrome/browser/browser_window.h" 21 #include "chrome/browser/browser_window.h"
21 #include "chrome/browser/dom_operation_notification_details.h" 22 #include "chrome/browser/dom_operation_notification_details.h"
22 #include "chrome/browser/download/download_manager.h" 23 #include "chrome/browser/download/download_manager.h"
23 #include "chrome/browser/find_bar.h" 24 #include "chrome/browser/find_bar.h"
24 #include "chrome/browser/find_bar_controller.h" 25 #include "chrome/browser/find_bar_controller.h"
25 #include "chrome/browser/find_notification_details.h" 26 #include "chrome/browser/find_notification_details.h"
26 #include "chrome/browser/location_bar.h" 27 #include "chrome/browser/location_bar.h"
28 #include "chrome/browser/profile_manager.h"
27 #include "chrome/browser/renderer_host/render_view_host.h" 29 #include "chrome/browser/renderer_host/render_view_host.h"
28 #include "chrome/browser/ssl/ssl_manager.h" 30 #include "chrome/browser/ssl/ssl_manager.h"
29 #include "chrome/browser/ssl/ssl_blocking_page.h" 31 #include "chrome/browser/ssl/ssl_blocking_page.h"
30 #include "chrome/browser/tab_contents/tab_contents.h" 32 #include "chrome/browser/tab_contents/tab_contents.h"
31 #include "chrome/browser/tab_contents/tab_contents_view.h" 33 #include "chrome/browser/tab_contents/tab_contents_view.h"
34 #include "chrome/common/automation_constants.h"
32 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
36 #include "chrome/common/json_value_serializer.h"
33 #include "chrome/common/notification_registrar.h" 37 #include "chrome/common/notification_registrar.h"
34 #include "chrome/common/platform_util.h" 38 #include "chrome/common/platform_util.h"
35 #include "chrome/common/pref_service.h" 39 #include "chrome/common/pref_service.h"
36 #include "chrome/test/automation/automation_messages.h" 40 #include "chrome/test/automation/automation_messages.h"
37 #include "net/base/cookie_monster.h" 41 #include "net/base/cookie_monster.h"
42 #include "net/proxy/proxy_service.h"
43 #include "net/proxy/proxy_config_service_fixed.h"
38 #include "net/url_request/url_request_context.h" 44 #include "net/url_request/url_request_context.h"
39 #include "net/url_request/url_request_filter.h" 45 #include "net/url_request/url_request_filter.h"
40 46
41 #if defined(OS_WIN) 47 #if defined(OS_WIN)
42 // TODO(port): Port these headers. 48 // TODO(port): Port these headers.
43 #include "chrome/browser/automation/ui_controls.h" 49 #include "chrome/browser/automation/ui_controls.h"
44 #include "chrome/browser/character_encoding.h" 50 #include "chrome/browser/character_encoding.h"
45 #include "chrome/browser/download/save_package.h" 51 #include "chrome/browser/download/save_package.h"
46 #include "chrome/browser/external_tab_container.h" 52 #include "chrome/browser/external_tab_container.h"
47 #include "chrome/browser/login_prompt.h" 53 #include "chrome/browser/login_prompt.h"
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedTitle, 1051 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedTitle,
1046 GetConstrainedTitle) 1052 GetConstrainedTitle)
1047 IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, 1053 IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage,
1048 HandleFindInPageRequest) 1054 HandleFindInPageRequest)
1049 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, 1055 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID,
1050 GetFocusedViewID) 1056 GetFocusedViewID)
1051 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, 1057 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
1052 HandleInspectElementRequest) 1058 HandleInspectElementRequest)
1053 IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet, 1059 IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet,
1054 SetFilteredInet); 1060 SetFilteredInet);
1061 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig,
1062 SetProxyConfig);
1055 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, 1063 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory,
1056 GetDownloadDirectory); 1064 GetDownloadDirectory);
1057 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, 1065 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
1058 OpenNewBrowserWindow); 1066 OpenNewBrowserWindow);
1059 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, 1067 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser,
1060 GetWindowForBrowser); 1068 GetWindowForBrowser);
1061 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, 1069 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser,
1062 GetAutocompleteEditForBrowser); 1070 GetAutocompleteEditForBrowser);
1063 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, 1071 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow,
1064 GetBrowserForWindow); 1072 GetBrowserForWindow);
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 }; 2241 };
2234 2242
2235 void AutomationProvider::SetFilteredInet(const IPC::Message& message, 2243 void AutomationProvider::SetFilteredInet(const IPC::Message& message,
2236 bool enabled) { 2244 bool enabled) {
2237 // Since this involves changing the URLRequest ProtocolFactory, we want to 2245 // Since this involves changing the URLRequest ProtocolFactory, we want to
2238 // run on the main thread. 2246 // run on the main thread.
2239 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 2247 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
2240 new SetFilteredInetTask(enabled)); 2248 new SetFilteredInetTask(enabled));
2241 } 2249 }
2242 2250
2251 class SetProxyConfigTask : public Task {
2252 public:
2253 explicit SetProxyConfigTask(net::ProxyService* proxy_service,
2254 const std::string& new_proxy_config)
2255 : proxy_service_(proxy_service), proxy_config_(new_proxy_config) {}
2256 virtual void Run() {
2257 // First, deserialize the JSON string. If this fails, log and bail.
2258 JSONStringValueSerializer deserializer(proxy_config_);
2259 std::string error_message;
2260 scoped_ptr<Value> root(deserializer.Deserialize(&error_message));
2261 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) {
2262 DLOG(WARNING) << "Received bad JSON string for ProxyConfig: "
2263 << error_message;
2264 return;
2265 }
2266
2267 scoped_ptr<DictionaryValue> dict(
2268 static_cast<DictionaryValue*>(root.release()));
2269 // Now put together a proxy configuration from the deserialized string.
2270 net::ProxyConfig pc;
2271 PopulateProxyConfig(*dict.get(), &pc);
2272
2273 DCHECK(proxy_service_);
2274 scoped_ptr<net::ProxyConfigService> proxy_config_service(
2275 new net::ProxyConfigServiceFixed(pc));
2276 proxy_service_->ResetConfigService(proxy_config_service.release());
2277 }
2278
2279 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) {
2280 DCHECK(pc);
2281 bool no_proxy = false;
2282 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) {
2283 // Make no changes to the ProxyConfig.
2284 return;
2285 }
2286 bool auto_config;
2287 if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) {
2288 pc->auto_detect = true;
2289 }
2290 std::string pac_url;
2291 if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) {
2292 pc->pac_url = GURL(pac_url);
2293 }
2294 std::string proxy_bypass_list;
2295 if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) {
2296 pc->ParseNoProxyList(proxy_bypass_list);
2297 }
2298 std::string proxy_server;
2299 if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) {
2300 pc->proxy_rules.ParseFromString(proxy_server);
2301 }
2302 }
2303
2304 private:
2305 net::ProxyService* proxy_service_;
2306 std::string proxy_config_;
2307 };
2308
2309
2310 void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) {
2311 URLRequestContext* context = Profile::GetDefaultRequestContext();
2312 // If we don't have a default request context yet then we have to create
2313 // one.
2314 bool run_on_ui_thread = false;
2315 if (!context) {
2316 FilePath user_data_dir;
2317 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
2318 ProfileManager* profile_manager = g_browser_process->profile_manager();
2319 DCHECK(profile_manager);
2320 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
2321 DCHECK(profile);
2322 context = profile->GetRequestContext();
2323 run_on_ui_thread = true;
2324 }
2325 DCHECK(context);
2326 // Every URLRequestContext should have a proxy service.
2327 net::ProxyService* proxy_service = context->proxy_service();
2328 DCHECK(proxy_service);
2329
2330 // If we just now created the URLRequestContext then we can immediately
2331 // set the proxy settings on this (the UI) thread. If there was already
2332 // a URLRequestContext, then run the reset on the IO thread.
2333 if (run_on_ui_thread) {
2334 SetProxyConfigTask set_proxy_config_task(proxy_service, new_proxy_config);
2335 set_proxy_config_task.Run();
2336 } else {
2337 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
2338 new SetProxyConfigTask(proxy_service, new_proxy_config));
2339 }
2340 }
2341
2243 void AutomationProvider::GetDownloadDirectory( 2342 void AutomationProvider::GetDownloadDirectory(
2244 int handle, std::wstring* download_directory) { 2343 int handle, std::wstring* download_directory) {
2245 DLOG(INFO) << "Handling download directory request"; 2344 DLOG(INFO) << "Handling download directory request";
2246 if (tab_tracker_->ContainsHandle(handle)) { 2345 if (tab_tracker_->ContainsHandle(handle)) {
2247 NavigationController* tab = tab_tracker_->GetResource(handle); 2346 NavigationController* tab = tab_tracker_->GetResource(handle);
2248 DownloadManager* dlm = tab->profile()->GetDownloadManager(); 2347 DownloadManager* dlm = tab->profile()->GetDownloadManager();
2249 DCHECK(dlm); 2348 DCHECK(dlm);
2250 *download_directory = dlm->download_path().ToWStringHack(); 2349 *download_directory = dlm->download_path().ToWStringHack();
2251 } 2350 }
2252 } 2351 }
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2954 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError(); 3053 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError();
2955 } 3054 }
2956 } 3055 }
2957 } 3056 }
2958 #endif 3057 #endif
2959 3058
2960 void AutomationProvider::GetWindowTitle(int handle, string16* text) { 3059 void AutomationProvider::GetWindowTitle(int handle, string16* text) {
2961 gfx::NativeWindow window = window_tracker_->GetResource(handle); 3060 gfx::NativeWindow window = window_tracker_->GetResource(handle);
2962 text->assign(platform_util::GetWindowTitle(window)); 3061 text->assign(platform_util::GetWindowTitle(window));
2963 } 3062 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698