| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <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 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/download/download_manager.h" | 33 #include "chrome/browser/download/download_manager.h" |
| 34 #include "chrome/browser/download/download_shelf.h" | 34 #include "chrome/browser/download/download_shelf.h" |
| 35 #include "chrome/browser/extensions/crx_installer.h" | 35 #include "chrome/browser/extensions/crx_installer.h" |
| 36 #include "chrome/browser/extensions/extension_install_ui.h" | 36 #include "chrome/browser/extensions/extension_install_ui.h" |
| 37 #include "chrome/browser/extensions/extension_message_service.h" | 37 #include "chrome/browser/extensions/extension_message_service.h" |
| 38 #include "chrome/browser/find_bar.h" | 38 #include "chrome/browser/find_bar.h" |
| 39 #include "chrome/browser/find_bar_controller.h" | 39 #include "chrome/browser/find_bar_controller.h" |
| 40 #include "chrome/browser/find_notification_details.h" | 40 #include "chrome/browser/find_notification_details.h" |
| 41 #include "chrome/browser/location_bar.h" | 41 #include "chrome/browser/location_bar.h" |
| 42 #include "chrome/browser/login_prompt.h" | 42 #include "chrome/browser/login_prompt.h" |
| 43 #include "chrome/browser/net/url_request_context_getter.h" |
| 43 #include "chrome/browser/net/url_request_mock_util.h" | 44 #include "chrome/browser/net/url_request_mock_util.h" |
| 44 #include "chrome/browser/profile_manager.h" | 45 #include "chrome/browser/profile_manager.h" |
| 45 #include "chrome/browser/renderer_host/render_process_host.h" | 46 #include "chrome/browser/renderer_host/render_process_host.h" |
| 46 #include "chrome/browser/renderer_host/render_view_host.h" | 47 #include "chrome/browser/renderer_host/render_view_host.h" |
| 47 #include "chrome/browser/ssl/ssl_manager.h" | 48 #include "chrome/browser/ssl/ssl_manager.h" |
| 48 #include "chrome/browser/ssl/ssl_blocking_page.h" | 49 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 49 #include "chrome/browser/tab_contents/tab_contents.h" | 50 #include "chrome/browser/tab_contents/tab_contents.h" |
| 50 #include "chrome/browser/tab_contents/tab_contents_view.h" | 51 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 51 #include "chrome/common/automation_constants.h" | 52 #include "chrome/common/automation_constants.h" |
| 52 #include "chrome/common/chrome_paths.h" | 53 #include "chrome/common/chrome_paths.h" |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 | 969 |
| 969 return browser; | 970 return browser; |
| 970 } | 971 } |
| 971 | 972 |
| 972 void AutomationProvider::GetCookies(const GURL& url, int handle, | 973 void AutomationProvider::GetCookies(const GURL& url, int handle, |
| 973 int* value_size, | 974 int* value_size, |
| 974 std::string* value) { | 975 std::string* value) { |
| 975 *value_size = -1; | 976 *value_size = -1; |
| 976 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 977 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 977 NavigationController* tab = tab_tracker_->GetResource(handle); | 978 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 978 *value = | 979 |
| 979 tab->profile()->GetRequestContext()->cookie_store()->GetCookies(url); | 980 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 981 net::CookieStore* cookie_store = |
| 982 tab->profile()->GetRequestContext()->GetCookieStore(); |
| 983 |
| 984 *value = cookie_store->GetCookies(url); |
| 980 *value_size = static_cast<int>(value->size()); | 985 *value_size = static_cast<int>(value->size()); |
| 981 } | 986 } |
| 982 } | 987 } |
| 983 | 988 |
| 984 void AutomationProvider::SetCookie(const GURL& url, | 989 void AutomationProvider::SetCookie(const GURL& url, |
| 985 const std::string value, | 990 const std::string value, |
| 986 int handle, | 991 int handle, |
| 987 int* response_value) { | 992 int* response_value) { |
| 988 *response_value = -1; | 993 *response_value = -1; |
| 989 | 994 |
| 990 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 995 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 991 NavigationController* tab = tab_tracker_->GetResource(handle); | 996 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 992 URLRequestContext* context = tab->profile()->GetRequestContext(); | 997 |
| 993 if (context->cookie_store()->SetCookie(url, value)) | 998 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 999 scoped_refptr<net::CookieStore> cookie_store = |
| 1000 tab->profile()->GetRequestContext()->GetCookieStore(); |
| 1001 |
| 1002 if (cookie_store->SetCookie(url, value)) |
| 994 *response_value = 1; | 1003 *response_value = 1; |
| 995 } | 1004 } |
| 996 } | 1005 } |
| 997 | 1006 |
| 998 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { | 1007 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { |
| 999 *success = false; | 1008 *success = false; |
| 1000 if (tab_tracker_->ContainsHandle(handle)) { | 1009 if (tab_tracker_->ContainsHandle(handle)) { |
| 1001 NavigationController* tab = tab_tracker_->GetResource(handle); | 1010 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1002 // Return what the user would see in the location bar. | 1011 // Return what the user would see in the location bar. |
| 1003 *url = tab->GetActiveEntry()->virtual_url(); | 1012 *url = tab->GetActiveEntry()->virtual_url(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 if (reply_message_) { | 1183 if (reply_message_) { |
| 1175 AutomationMsg_InspectElement::WriteReplyParams(reply_message_, | 1184 AutomationMsg_InspectElement::WriteReplyParams(reply_message_, |
| 1176 num_resources); | 1185 num_resources); |
| 1177 Send(reply_message_); | 1186 Send(reply_message_); |
| 1178 reply_message_ = NULL; | 1187 reply_message_ = NULL; |
| 1179 } | 1188 } |
| 1180 } | 1189 } |
| 1181 | 1190 |
| 1182 class SetProxyConfigTask : public Task { | 1191 class SetProxyConfigTask : public Task { |
| 1183 public: | 1192 public: |
| 1184 explicit SetProxyConfigTask(net::ProxyService* proxy_service, | 1193 SetProxyConfigTask(URLRequestContextGetter* request_context_getter, |
| 1185 const std::string& new_proxy_config) | 1194 const std::string& new_proxy_config) |
| 1186 : proxy_service_(proxy_service), proxy_config_(new_proxy_config) {} | 1195 : request_context_getter_(request_context_getter), proxy_config_(new_proxy
_config) {} |
| 1187 virtual void Run() { | 1196 virtual void Run() { |
| 1188 // First, deserialize the JSON string. If this fails, log and bail. | 1197 // First, deserialize the JSON string. If this fails, log and bail. |
| 1189 JSONStringValueSerializer deserializer(proxy_config_); | 1198 JSONStringValueSerializer deserializer(proxy_config_); |
| 1190 std::string error_message; | 1199 std::string error_message; |
| 1191 scoped_ptr<Value> root(deserializer.Deserialize(&error_message)); | 1200 scoped_ptr<Value> root(deserializer.Deserialize(&error_message)); |
| 1192 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { | 1201 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
| 1193 DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " | 1202 DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " |
| 1194 << error_message; | 1203 << error_message; |
| 1195 return; | 1204 return; |
| 1196 } | 1205 } |
| 1197 | 1206 |
| 1198 scoped_ptr<DictionaryValue> dict( | 1207 scoped_ptr<DictionaryValue> dict( |
| 1199 static_cast<DictionaryValue*>(root.release())); | 1208 static_cast<DictionaryValue*>(root.release())); |
| 1200 // Now put together a proxy configuration from the deserialized string. | 1209 // Now put together a proxy configuration from the deserialized string. |
| 1201 net::ProxyConfig pc; | 1210 net::ProxyConfig pc; |
| 1202 PopulateProxyConfig(*dict.get(), &pc); | 1211 PopulateProxyConfig(*dict.get(), &pc); |
| 1203 | 1212 |
| 1204 DCHECK(proxy_service_); | 1213 net::ProxyService* proxy_service = |
| 1214 request_context_getter_->GetURLRequestContext()->proxy_service(); |
| 1215 DCHECK(proxy_service); |
| 1205 scoped_ptr<net::ProxyConfigService> proxy_config_service( | 1216 scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 1206 new net::ProxyConfigServiceFixed(pc)); | 1217 new net::ProxyConfigServiceFixed(pc)); |
| 1207 proxy_service_->ResetConfigService(proxy_config_service.release()); | 1218 proxy_service->ResetConfigService(proxy_config_service.release()); |
| 1208 } | 1219 } |
| 1209 | 1220 |
| 1210 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { | 1221 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
| 1211 DCHECK(pc); | 1222 DCHECK(pc); |
| 1212 bool no_proxy = false; | 1223 bool no_proxy = false; |
| 1213 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { | 1224 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
| 1214 // Make no changes to the ProxyConfig. | 1225 // Make no changes to the ProxyConfig. |
| 1215 return; | 1226 return; |
| 1216 } | 1227 } |
| 1217 bool auto_config; | 1228 bool auto_config; |
| 1218 if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { | 1229 if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { |
| 1219 pc->auto_detect = true; | 1230 pc->auto_detect = true; |
| 1220 } | 1231 } |
| 1221 std::string pac_url; | 1232 std::string pac_url; |
| 1222 if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { | 1233 if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { |
| 1223 pc->pac_url = GURL(pac_url); | 1234 pc->pac_url = GURL(pac_url); |
| 1224 } | 1235 } |
| 1225 std::string proxy_bypass_list; | 1236 std::string proxy_bypass_list; |
| 1226 if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { | 1237 if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { |
| 1227 pc->ParseNoProxyList(proxy_bypass_list); | 1238 pc->ParseNoProxyList(proxy_bypass_list); |
| 1228 } | 1239 } |
| 1229 std::string proxy_server; | 1240 std::string proxy_server; |
| 1230 if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { | 1241 if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { |
| 1231 pc->proxy_rules.ParseFromString(proxy_server); | 1242 pc->proxy_rules.ParseFromString(proxy_server); |
| 1232 } | 1243 } |
| 1233 } | 1244 } |
| 1234 | 1245 |
| 1235 private: | 1246 private: |
| 1236 net::ProxyService* proxy_service_; | 1247 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
| 1237 std::string proxy_config_; | 1248 std::string proxy_config_; |
| 1238 }; | 1249 }; |
| 1239 | 1250 |
| 1240 | 1251 |
| 1241 void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { | 1252 void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { |
| 1242 URLRequestContext* context = Profile::GetDefaultRequestContext(); | 1253 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
| 1243 if (!context) { | 1254 if (!context_getter) { |
| 1244 FilePath user_data_dir; | 1255 FilePath user_data_dir; |
| 1245 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 1256 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 1246 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1257 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1247 DCHECK(profile_manager); | 1258 DCHECK(profile_manager); |
| 1248 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); | 1259 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 1249 DCHECK(profile); | 1260 DCHECK(profile); |
| 1250 context = profile->GetRequestContext(); | 1261 context_getter = profile->GetRequestContext(); |
| 1251 } | 1262 } |
| 1252 DCHECK(context); | 1263 DCHECK(context_getter); |
| 1253 // Every URLRequestContext should have a proxy service. | |
| 1254 net::ProxyService* proxy_service = context->proxy_service(); | |
| 1255 DCHECK(proxy_service); | |
| 1256 | 1264 |
| 1257 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 1265 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 1258 new SetProxyConfigTask(proxy_service, new_proxy_config)); | 1266 new SetProxyConfigTask(context_getter, new_proxy_config)); |
| 1259 } | 1267 } |
| 1260 | 1268 |
| 1261 void AutomationProvider::GetDownloadDirectory( | 1269 void AutomationProvider::GetDownloadDirectory( |
| 1262 int handle, FilePath* download_directory) { | 1270 int handle, FilePath* download_directory) { |
| 1263 DLOG(INFO) << "Handling download directory request"; | 1271 DLOG(INFO) << "Handling download directory request"; |
| 1264 if (tab_tracker_->ContainsHandle(handle)) { | 1272 if (tab_tracker_->ContainsHandle(handle)) { |
| 1265 NavigationController* tab = tab_tracker_->GetResource(handle); | 1273 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1266 DownloadManager* dlm = tab->profile()->GetDownloadManager(); | 1274 DownloadManager* dlm = tab->profile()->GetDownloadManager(); |
| 1267 DCHECK(dlm); | 1275 DCHECK(dlm); |
| 1268 *download_directory = dlm->download_path(); | 1276 *download_directory = dlm->download_path(); |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 reply_message); | 2158 reply_message); |
| 2151 | 2159 |
| 2152 profile_->GetExtensionsService()->LoadExtension(extension_dir); | 2160 profile_->GetExtensionsService()->LoadExtension(extension_dir); |
| 2153 profile_->GetUserScriptMaster()->AddWatchedPath(extension_dir); | 2161 profile_->GetUserScriptMaster()->AddWatchedPath(extension_dir); |
| 2154 } else { | 2162 } else { |
| 2155 AutomationMsg_LoadExpandedExtension::WriteReplyParams( | 2163 AutomationMsg_LoadExpandedExtension::WriteReplyParams( |
| 2156 reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); | 2164 reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 2157 Send(reply_message); | 2165 Send(reply_message); |
| 2158 } | 2166 } |
| 2159 } | 2167 } |
| OLD | NEW |