OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/web_resource/web_resource_service.h" | 5 #include "chrome/browser/web_resource/web_resource_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_utility_messages.h" | 18 #include "chrome/common/chrome_utility_messages.h" |
19 #include "chrome/common/web_resource/web_resource_unpacker.h" | 19 #include "chrome/common/web_resource/web_resource_unpacker.h" |
20 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 20 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/utility_process_host.h" | 22 #include "content/public/browser/utility_process_host.h" |
23 #include "content/public/browser/utility_process_host_client.h" | 23 #include "content/public/browser/utility_process_host_client.h" |
| 24 #include "content/public/common/content_url_request_user_data.h" |
24 #include "content/public/common/url_fetcher.h" | 25 #include "content/public/common/url_fetcher.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
26 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
28 | 29 |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 using content::UtilityProcessHost; | 31 using content::UtilityProcessHost; |
31 using content::UtilityProcessHostClient; | 32 using content::UtilityProcessHostClient; |
32 | 33 |
33 // This class coordinates a web resource unpack and parse task which is run in | 34 // This class coordinates a web resource unpack and parse task which is run in |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 214 |
214 url_fetcher_.reset(content::URLFetcher::Create( | 215 url_fetcher_.reset(content::URLFetcher::Create( |
215 GURL(web_resource_server), content::URLFetcher::GET, this)); | 216 GURL(web_resource_server), content::URLFetcher::GET, this)); |
216 // Do not let url fetcher affect existing state in system context | 217 // Do not let url fetcher affect existing state in system context |
217 // (by setting cookies, for example). | 218 // (by setting cookies, for example). |
218 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 219 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
219 net::LOAD_DO_NOT_SAVE_COOKIES); | 220 net::LOAD_DO_NOT_SAVE_COOKIES); |
220 net::URLRequestContextGetter* url_request_context_getter = | 221 net::URLRequestContextGetter* url_request_context_getter = |
221 g_browser_process->system_request_context(); | 222 g_browser_process->system_request_context(); |
222 url_fetcher_->SetRequestContext(url_request_context_getter); | 223 url_fetcher_->SetRequestContext(url_request_context_getter); |
| 224 // TODO(jochen): Do cookie audit. |
| 225 url_fetcher_->SetContentURLRequestUserData( |
| 226 new content::ContentURLRequestUserData()); |
223 url_fetcher_->Start(); | 227 url_fetcher_->Start(); |
224 } | 228 } |
225 | 229 |
226 void WebResourceService::OnURLFetchComplete(const content::URLFetcher* source) { | 230 void WebResourceService::OnURLFetchComplete(const content::URLFetcher* source) { |
227 // Delete the URLFetcher when this function exits. | 231 // Delete the URLFetcher when this function exits. |
228 scoped_ptr<content::URLFetcher> clean_up_fetcher(url_fetcher_.release()); | 232 scoped_ptr<content::URLFetcher> clean_up_fetcher(url_fetcher_.release()); |
229 | 233 |
230 // Don't parse data if attempt to download was unsuccessful. | 234 // Don't parse data if attempt to download was unsuccessful. |
231 // Stop loading new web resource data, and silently exit. | 235 // Stop loading new web resource data, and silently exit. |
232 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) | 236 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) |
233 return; | 237 return; |
234 | 238 |
235 std::string data; | 239 std::string data; |
236 source->GetResponseAsString(&data); | 240 source->GetResponseAsString(&data); |
237 | 241 |
238 // UnpackerClient releases itself. | 242 // UnpackerClient releases itself. |
239 UnpackerClient* client = new UnpackerClient(this); | 243 UnpackerClient* client = new UnpackerClient(this); |
240 client->Start(data); | 244 client->Start(data); |
241 | 245 |
242 Release(); | 246 Release(); |
243 } | 247 } |
OLD | NEW |