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

Side by Side Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 115204: Add a separate cookie store that's used for extensions.... (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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/net/chrome_url_request_context.h" 5 #include "chrome/browser/net/chrome_url_request_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/extensions/extension.h" 11 #include "chrome/browser/extensions/extension.h"
12 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/extensions/user_script_master.h" 13 #include "chrome/browser/extensions/user_script_master.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h"
19 #include "net/ftp/ftp_network_layer.h" 20 #include "net/ftp/ftp_network_layer.h"
20 #include "net/http/http_cache.h" 21 #include "net/http/http_cache.h"
21 #include "net/http/http_network_layer.h" 22 #include "net/http/http_network_layer.h"
22 #include "net/http/http_util.h" 23 #include "net/http/http_util.h"
23 #include "net/proxy/proxy_service.h" 24 #include "net/proxy/proxy_service.h"
24 #include "webkit/glue/webkit_glue.h" 25 #include "webkit/glue/webkit_glue.h"
25 26
26 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) { 27 net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
27 // Scan for all "enable" type proxy switches. 28 // Scan for all "enable" type proxy switches.
28 static const wchar_t* proxy_switches[] = { 29 static const wchar_t* proxy_switches[] = {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 149 }
149 150
150 // static 151 // static
151 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( 152 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
152 Profile* profile, const FilePath& disk_cache_path) { 153 Profile* profile, const FilePath& disk_cache_path) {
153 DCHECK(!profile->IsOffTheRecord()); 154 DCHECK(!profile->IsOffTheRecord());
154 return CreateRequestContextForMedia(profile, disk_cache_path, false); 155 return CreateRequestContextForMedia(profile, disk_cache_path, false);
155 } 156 }
156 157
157 // static 158 // static
159 ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions(
160 Profile* profile, const FilePath& cookie_store_path) {
161 DCHECK(!profile->IsOffTheRecord());
162 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
163
164 // All we care about for extensions is the cookie store.
165 DCHECK(!cookie_store_path.empty());
166 context->cookie_db_.reset(new SQLitePersistentCookieStore(
167 cookie_store_path.ToWStringHack(),
168 g_browser_process->db_thread()->message_loop()));
169 context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get());
170
171 // Enable cookies for extension URLs only.
172 const char* schemes[] = {chrome::kExtensionScheme};
173 context->cookie_store_->SetCookieableSchemes(schemes, 1);
174
175 return context;
176 }
177
178 // static
158 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( 179 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
159 Profile* profile) { 180 Profile* profile) {
160 DCHECK(profile->IsOffTheRecord()); 181 DCHECK(profile->IsOffTheRecord());
161 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 182 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
162 183
163 // Share the same proxy service as the original profile. This proxy 184 // Share the same proxy service as the original profile. This proxy
164 // service's lifespan is dependent on the lifespan of the original profile, 185 // service's lifespan is dependent on the lifespan of the original profile,
165 // which we reference (see above). 186 // which we reference (see above).
166 context->proxy_service_ = 187 context->proxy_service_ =
167 profile->GetOriginalProfile()->GetRequestContext()->proxy_service(); 188 profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
168 189
169 context->http_transaction_factory_ = 190 context->http_transaction_factory_ =
170 new net::HttpCache(context->proxy_service_, 0); 191 new net::HttpCache(context->proxy_service_, 0);
171 context->cookie_store_ = new net::CookieMonster; 192 context->cookie_store_ = new net::CookieMonster;
172 193
173 return context; 194 return context;
174 } 195 }
175 196
176 // static 197 // static
177 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( 198 ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia(
178 Profile* profile, const FilePath& disk_cache_path) { 199 Profile* profile, const FilePath& disk_cache_path) {
179 // TODO(hclam): since we don't have an implementation of disk cache backend 200 // TODO(hclam): since we don't have an implementation of disk cache backend
180 // for media files in OTR mode, we create a request context just like the 201 // for media files in OTR mode, we create a request context just like the
181 // original one. 202 // original one.
182 DCHECK(profile->IsOffTheRecord()); 203 DCHECK(profile->IsOffTheRecord());
183 return CreateRequestContextForMedia(profile, disk_cache_path, true); 204 return CreateRequestContextForMedia(profile, disk_cache_path, true);
184 } 205 }
185 206
186 // static 207 // static
208 ChromeURLRequestContext*
209 ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) {
210 DCHECK(profile->IsOffTheRecord());
211 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
212 context->cookie_store_ = new net::CookieMonster;
213
214 // Enable cookies for extension URLs only.
215 const char* schemes[] = {chrome::kExtensionScheme};
216 context->cookie_store_->SetCookieableSchemes(schemes, 1);
217
218 return context;
219 }
220
221 // static
187 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( 222 ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
188 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { 223 Profile* profile, const FilePath& disk_cache_path, bool off_the_record) {
189 URLRequestContext* original_context = 224 URLRequestContext* original_context =
190 profile->GetOriginalProfile()->GetRequestContext(); 225 profile->GetOriginalProfile()->GetRequestContext();
191 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); 226 ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
192 context->is_media_ = true; 227 context->is_media_ = true;
193 228
194 // Share the same proxy service of the common profile. 229 // Share the same proxy service of the common profile.
195 context->proxy_service_ = original_context->proxy_service(); 230 context->proxy_service_ = original_context->proxy_service();
196 // Also share the cookie store of the common profile. 231 // Also share the cookie store of the common profile.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // Do not delete the cookie store in the case of the media context, as it is 411 // Do not delete the cookie store in the case of the media context, as it is
377 // owned by the original context. 412 // owned by the original context.
378 if (!is_media_) 413 if (!is_media_)
379 delete cookie_store_; 414 delete cookie_store_;
380 415
381 // Do not delete the proxy service in the case of OTR or media contexts, as 416 // Do not delete the proxy service in the case of OTR or media contexts, as
382 // it is owned by the original URLRequestContext. 417 // it is owned by the original URLRequestContext.
383 if (!is_off_the_record_ && !is_media_) 418 if (!is_off_the_record_ && !is_media_)
384 delete proxy_service_; 419 delete proxy_service_;
385 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698