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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/keyboard_codes.h" | 15 #include "base/keyboard_codes.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
19 #include "base/stl_util-inl.h" | 19 #include "base/stl_util-inl.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/task.h" | |
22 #include "base/thread.h" | 21 #include "base/thread.h" |
23 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
24 #include "base/values.h" | 23 #include "base/values.h" |
25 #include "base/waitable_event.h" | |
26 #include "chrome/app/chrome_dll_resource.h" | 24 #include "chrome/app/chrome_dll_resource.h" |
27 #include "chrome/app/chrome_version_info.h" | 25 #include "chrome/app/chrome_version_info.h" |
28 #include "chrome/browser/app_modal_dialog.h" | 26 #include "chrome/browser/app_modal_dialog.h" |
29 #include "chrome/browser/app_modal_dialog_queue.h" | 27 #include "chrome/browser/app_modal_dialog_queue.h" |
30 #include "chrome/browser/automation/automation_extension_tracker.h" | 28 #include "chrome/browser/automation/automation_extension_tracker.h" |
31 #include "chrome/browser/automation/automation_provider_list.h" | 29 #include "chrome/browser/automation/automation_provider_list.h" |
32 #include "chrome/browser/automation/automation_provider_observers.h" | 30 #include "chrome/browser/automation/automation_provider_observers.h" |
33 #include "chrome/browser/automation/extension_port_container.h" | 31 #include "chrome/browser/automation/extension_port_container.h" |
34 #include "chrome/browser/blocked_popup_container.h" | 32 #include "chrome/browser/blocked_popup_container.h" |
35 #include "chrome/browser/bookmarks/bookmark_model.h" | 33 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 Browser* AutomationProvider::FindAndActivateTab( | 1110 Browser* AutomationProvider::FindAndActivateTab( |
1113 NavigationController* controller) { | 1111 NavigationController* controller) { |
1114 int tab_index; | 1112 int tab_index; |
1115 Browser* browser = Browser::GetBrowserForController(controller, &tab_index); | 1113 Browser* browser = Browser::GetBrowserForController(controller, &tab_index); |
1116 if (browser) | 1114 if (browser) |
1117 browser->SelectTabContentsAt(tab_index, true); | 1115 browser->SelectTabContentsAt(tab_index, true); |
1118 | 1116 |
1119 return browser; | 1117 return browser; |
1120 } | 1118 } |
1121 | 1119 |
1122 namespace { | |
1123 | |
1124 class GetCookiesTask : public Task { | |
1125 public: | |
1126 GetCookiesTask(const GURL& url, | |
1127 URLRequestContextGetter* context_getter, | |
1128 base::WaitableEvent* event, | |
1129 std::string* cookies) | |
1130 : url_(url), | |
1131 context_getter_(context_getter), | |
1132 event_(event), | |
1133 cookies_(cookies) {} | |
1134 | |
1135 virtual void Run() { | |
1136 *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_); | |
1137 event_->Signal(); | |
1138 } | |
1139 | |
1140 private: | |
1141 const GURL& url_; | |
1142 URLRequestContextGetter* const context_getter_; | |
1143 base::WaitableEvent* const event_; | |
1144 std::string* const cookies_; | |
1145 | |
1146 DISALLOW_COPY_AND_ASSIGN(GetCookiesTask); | |
1147 }; | |
1148 | |
1149 std::string GetCookiesForURL( | |
1150 const GURL& url, | |
1151 URLRequestContextGetter* context_getter) { | |
1152 std::string cookies; | |
1153 base::WaitableEvent event(true /* manual reset */, | |
1154 false /* not initially signaled */); | |
1155 CHECK(ChromeThread::PostTask( | |
1156 ChromeThread::IO, FROM_HERE, | |
1157 new GetCookiesTask(url, context_getter, &event, &cookies))); | |
1158 event.Wait(); | |
1159 return cookies; | |
1160 } | |
1161 | |
1162 class SetCookieTask : public Task { | |
1163 public: | |
1164 SetCookieTask(const GURL& url, | |
1165 const std::string& value, | |
1166 URLRequestContextGetter* context_getter, | |
1167 base::WaitableEvent* event, | |
1168 bool* rv) | |
1169 : url_(url), | |
1170 value_(value), | |
1171 context_getter_(context_getter), | |
1172 event_(event), | |
1173 rv_(rv) {} | |
1174 | |
1175 virtual void Run() { | |
1176 *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_); | |
1177 event_->Signal(); | |
1178 } | |
1179 | |
1180 private: | |
1181 const GURL& url_; | |
1182 const std::string& value_; | |
1183 URLRequestContextGetter* const context_getter_; | |
1184 base::WaitableEvent* const event_; | |
1185 bool* const rv_; | |
1186 | |
1187 DISALLOW_COPY_AND_ASSIGN(SetCookieTask); | |
1188 }; | |
1189 | |
1190 bool SetCookieForURL( | |
1191 const GURL& url, | |
1192 const std::string& value, | |
1193 URLRequestContextGetter* context_getter) { | |
1194 base::WaitableEvent event(true /* manual reset */, | |
1195 false /* not initially signaled */); | |
1196 bool rv = false; | |
1197 CHECK(ChromeThread::PostTask( | |
1198 ChromeThread::IO, FROM_HERE, | |
1199 new SetCookieTask(url, value, context_getter, &event, &rv))); | |
1200 event.Wait(); | |
1201 return rv; | |
1202 } | |
1203 | |
1204 class DeleteCookieTask : public Task { | |
1205 public: | |
1206 DeleteCookieTask(const GURL& url, | |
1207 const std::string& name, | |
1208 const scoped_refptr<URLRequestContextGetter>& context_getter) | |
1209 : url_(url), | |
1210 name_(name), | |
1211 context_getter_(context_getter) {} | |
1212 | |
1213 virtual void Run() { | |
1214 net::CookieStore* cookie_store = context_getter_->GetCookieStore(); | |
1215 cookie_store->DeleteCookie(url_, name_); | |
1216 } | |
1217 | |
1218 private: | |
1219 const GURL url_; | |
1220 const std::string name_; | |
1221 const scoped_refptr<URLRequestContextGetter> context_getter_; | |
1222 | |
1223 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | |
1224 }; | |
1225 | |
1226 } // namespace | |
1227 | |
1228 void AutomationProvider::GetCookies(const GURL& url, int handle, | 1120 void AutomationProvider::GetCookies(const GURL& url, int handle, |
1229 int* value_size, | 1121 int* value_size, |
1230 std::string* value) { | 1122 std::string* value) { |
1231 *value_size = -1; | 1123 *value_size = -1; |
1232 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 1124 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
1233 NavigationController* tab = tab_tracker_->GetResource(handle); | 1125 NavigationController* tab = tab_tracker_->GetResource(handle); |
1234 | 1126 |
1235 // Since we are running on the UI thread don't call GetURLRequestContext(). | 1127 // Since we are running on the UI thread don't call GetURLRequestContext(). |
1236 scoped_refptr<URLRequestContextGetter> request_context = | 1128 scoped_refptr<URLRequestContextGetter> request_context = |
1237 tab->tab_contents()->request_context(); | 1129 tab->tab_contents()->request_context(); |
1238 if (!request_context.get()) | 1130 if (!request_context.get()) |
1239 request_context = tab->profile()->GetRequestContext(); | 1131 request_context = tab->profile()->GetRequestContext(); |
1240 | 1132 |
1241 *value = GetCookiesForURL(url, request_context.get()); | 1133 net::CookieStore* cookie_store = request_context->GetCookieStore(); |
| 1134 |
| 1135 *value = cookie_store->GetCookies(url); |
1242 *value_size = static_cast<int>(value->size()); | 1136 *value_size = static_cast<int>(value->size()); |
1243 } | 1137 } |
1244 } | 1138 } |
1245 | 1139 |
1246 void AutomationProvider::SetCookie(const GURL& url, | 1140 void AutomationProvider::SetCookie(const GURL& url, |
1247 const std::string value, | 1141 const std::string value, |
1248 int handle, | 1142 int handle, |
1249 int* response_value) { | 1143 int* response_value) { |
1250 *response_value = -1; | 1144 *response_value = -1; |
1251 | 1145 |
1252 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 1146 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
1253 NavigationController* tab = tab_tracker_->GetResource(handle); | 1147 NavigationController* tab = tab_tracker_->GetResource(handle); |
1254 | 1148 |
1255 scoped_refptr<URLRequestContextGetter> request_context = | 1149 scoped_refptr<URLRequestContextGetter> request_context = |
1256 tab->tab_contents()->request_context(); | 1150 tab->tab_contents()->request_context(); |
1257 if (!request_context.get()) | 1151 if (!request_context.get()) |
1258 request_context = tab->profile()->GetRequestContext(); | 1152 request_context = tab->profile()->GetRequestContext(); |
1259 | 1153 |
1260 if (SetCookieForURL(url, value, request_context.get())) | 1154 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 1155 scoped_refptr<net::CookieStore> cookie_store = |
| 1156 request_context->GetCookieStore(); |
| 1157 |
| 1158 if (cookie_store->SetCookie(url, value)) |
1261 *response_value = 1; | 1159 *response_value = 1; |
1262 } | 1160 } |
1263 } | 1161 } |
1264 | 1162 |
1265 void AutomationProvider::DeleteCookie(const GURL& url, | 1163 void AutomationProvider::DeleteCookie(const GURL& url, |
1266 const std::string& cookie_name, | 1164 const std::string& cookie_name, |
1267 int handle, bool* success) { | 1165 int handle, bool* success) { |
1268 *success = false; | 1166 *success = false; |
1269 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 1167 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
1270 NavigationController* tab = tab_tracker_->GetResource(handle); | 1168 NavigationController* tab = tab_tracker_->GetResource(handle); |
1271 ChromeThread::PostTask( | 1169 net::CookieStore* cookie_store = |
1272 ChromeThread::IO, FROM_HERE, | 1170 tab->profile()->GetRequestContext()->GetCookieStore(); |
1273 new DeleteCookieTask(url, cookie_name, | 1171 cookie_store->DeleteCookie(url, cookie_name); |
1274 tab->profile()->GetRequestContext())); | |
1275 *success = true; | 1172 *success = true; |
1276 } | 1173 } |
1277 } | 1174 } |
1278 | 1175 |
1279 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { | 1176 void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { |
1280 *success = false; | 1177 *success = false; |
1281 if (tab_tracker_->ContainsHandle(handle)) { | 1178 if (tab_tracker_->ContainsHandle(handle)) { |
1282 NavigationController* tab = tab_tracker_->GetResource(handle); | 1179 NavigationController* tab = tab_tracker_->GetResource(handle); |
1283 // Return what the user would see in the location bar. | 1180 // Return what the user would see in the location bar. |
1284 *url = tab->GetActiveEntry()->virtual_url(); | 1181 *url = tab->GetActiveEntry()->virtual_url(); |
(...skipping 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3548 } | 3445 } |
3549 | 3446 |
3550 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 3447 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
3551 NOTIMPLEMENTED(); | 3448 NOTIMPLEMENTED(); |
3552 } | 3449 } |
3553 #endif // !defined(TOOLKIT_VIEWS) | 3450 #endif // !defined(TOOLKIT_VIEWS) |
3554 | 3451 |
3555 void AutomationProvider::ResetToDefaultTheme() { | 3452 void AutomationProvider::ResetToDefaultTheme() { |
3556 profile_->ClearTheme(); | 3453 profile_->ClearTheme(); |
3557 } | 3454 } |
OLD | NEW |