summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:40:32 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:40:32 +0000
commitbc535ee5bb4eece29f5d88bcc688613b3b208b27 (patch)
tree37b90c6bbbe98732c81515b35f02f8b835ac5df7 /chrome/browser/net
parent7566dbf757617f9e77f4a7f9f031402eb7818b04 (diff)
downloadchromium_src-bc535ee5bb4eece29f5d88bcc688613b3b208b27.zip
chromium_src-bc535ee5bb4eece29f5d88bcc688613b3b208b27.tar.gz
chromium_src-bc535ee5bb4eece29f5d88bcc688613b3b208b27.tar.bz2
Add support for a "split" incognito behavior for extensions.
- On by default for apps, off by default for extensions. - Split mode means "run incognito extensions in a separate process if the user says OK, and the two processes can only see their own profile." - Spanning mode is what we have now, and means "run a single extension process, but allow it to access both profiles if the user says OK." BUG=49232 BUG=49114 TEST=extensions still work in incognito when you check "Allow in Incognito". Review URL: http://codereview.chromium.org/3210007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58033 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc42
-rw-r--r--chrome/browser/net/chrome_url_request_context.h19
2 files changed, 48 insertions, 13 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index c4104a5..f14958f 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -325,15 +325,18 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
// Factory that creates the ChromeURLRequestContext for extensions.
class FactoryForExtensions : public ChromeURLRequestContextFactory {
public:
- FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path)
+ FactoryForExtensions(Profile* profile, const FilePath& cookie_store_path,
+ bool incognito)
: ChromeURLRequestContextFactory(profile),
- cookie_store_path_(cookie_store_path) {
+ cookie_store_path_(cookie_store_path),
+ incognito_(incognito) {
}
virtual ChromeURLRequestContext* Create();
private:
FilePath cookie_store_path_;
+ bool incognito_;
};
ChromeURLRequestContext* FactoryForExtensions::Create() {
@@ -342,11 +345,14 @@ ChromeURLRequestContext* FactoryForExtensions::Create() {
IOThread::Globals* io_thread_globals = io_thread()->globals();
- // All we care about for extensions is the cookie store.
- DCHECK(!cookie_store_path_.empty());
+ // All we care about for extensions is the cookie store. For incognito, we
+ // use a non-persistent cookie store.
+ scoped_refptr<SQLitePersistentCookieStore> cookie_db = NULL;
+ if (!incognito_) {
+ DCHECK(!cookie_store_path_.empty());
+ cookie_db = new SQLitePersistentCookieStore(cookie_store_path_);
+ }
- scoped_refptr<SQLitePersistentCookieStore> cookie_db =
- new SQLitePersistentCookieStore(cookie_store_path_);
net::CookieMonster* cookie_monster =
new net::CookieMonster(cookie_db.get(), NULL);
@@ -624,7 +630,7 @@ ChromeURLRequestContextGetter::CreateOriginalForExtensions(
DCHECK(!profile->IsOffTheRecord());
return new ChromeURLRequestContextGetter(
profile,
- new FactoryForExtensions(profile, cookie_store_path));
+ new FactoryForExtensions(profile, cookie_store_path, false));
}
// static
@@ -635,6 +641,15 @@ ChromeURLRequestContextGetter::CreateOffTheRecord(Profile* profile) {
profile, new FactoryForOffTheRecord(profile));
}
+// static
+ChromeURLRequestContextGetter*
+ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions(
+ Profile* profile) {
+ DCHECK(profile->IsOffTheRecord());
+ return new ChromeURLRequestContextGetter(
+ profile, new FactoryForExtensions(profile, FilePath(), true));
+}
+
void ChromeURLRequestContextGetter::CleanupOnUIThread() {
CheckCurrentlyOnMainThread();
@@ -798,6 +813,13 @@ bool ChromeURLRequestContext::ExtensionHasWebExtent(const std::string& id) {
return iter != extension_info_.end() && !iter->second->extent.is_empty();
}
+bool ChromeURLRequestContext::ExtensionCanLoadInIncognito(
+ const std::string& id) {
+ ExtensionInfoMap::iterator iter = extension_info_.find(id);
+ // Only split-mode extensions can load in incognito profiles.
+ return iter != extension_info_.end() && iter->second->incognito_split_mode;
+}
+
std::string ChromeURLRequestContext::GetDefaultLocaleForExtension(
const std::string& id) {
ExtensionInfoMap::iterator iter = extension_info_.find(id);
@@ -852,14 +874,11 @@ const std::string& ChromeURLRequestContext::GetUserAgent(
void ChromeURLRequestContext::OnNewExtensions(const std::string& id,
ExtensionInfo* info) {
- if (!is_off_the_record_)
- extension_info_[id] = linked_ptr<ExtensionInfo>(info);
+ extension_info_[id] = linked_ptr<ExtensionInfo>(info);
}
void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
CheckCurrentlyOnIOThread();
- if (is_off_the_record_)
- return;
ExtensionInfoMap::iterator iter = extension_info_.find(id);
if (iter != extension_info_.end()) {
extension_info_.erase(iter);
@@ -976,6 +995,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
(*iter)->name(),
(*iter)->path(),
(*iter)->default_locale(),
+ (*iter)->incognito_split_mode(),
(*iter)->web_extent(),
(*iter)->GetEffectiveHostPermissions(),
(*iter)->api_permissions()));
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index 2638d46..97997e3 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -51,12 +51,17 @@ class ChromeURLRequestContext : public URLRequestContext {
// could be immutable and ref-counted so that we could use them directly from
// both threads. There is only a small amount of mutable state in Extension.
struct ExtensionInfo {
- ExtensionInfo(const std::string& name, const FilePath& path,
+ ExtensionInfo(const std::string& name,
+ const FilePath& path,
const std::string& default_locale,
+ bool incognito_split_mode,
const ExtensionExtent& extent,
const ExtensionExtent& effective_host_permissions,
const std::vector<std::string>& api_permissions)
- : name(name), path(path), default_locale(default_locale),
+ : name(name),
+ path(path),
+ default_locale(default_locale),
+ incognito_split_mode(incognito_split_mode),
extent(extent),
effective_host_permissions(effective_host_permissions),
api_permissions(api_permissions) {
@@ -64,6 +69,7 @@ class ChromeURLRequestContext : public URLRequestContext {
const std::string name;
const FilePath path;
const std::string default_locale;
+ const bool incognito_split_mode;
const ExtensionExtent extent;
const ExtensionExtent effective_host_permissions;
std::vector<std::string> api_permissions;
@@ -84,6 +90,10 @@ class ChromeURLRequestContext : public URLRequestContext {
// extent.
bool ExtensionHasWebExtent(const std::string& id);
+ // Returns true if the specified extension exists and can load in incognito
+ // contexts.
+ bool ExtensionCanLoadInIncognito(const std::string& id);
+
// Returns an empty string if the extension with |id| doesn't have a default
// locale.
std::string GetDefaultLocaleForExtension(const std::string& id);
@@ -312,6 +322,11 @@ class ChromeURLRequestContextGetter : public URLRequestContextGetter,
// called on the UI thread.
static ChromeURLRequestContextGetter* CreateOffTheRecord(Profile* profile);
+ // Create an instance for an OTR profile for extensions. This is expected
+ // to get called on UI thread.
+ static ChromeURLRequestContextGetter* CreateOffTheRecordForExtensions(
+ Profile* profile);
+
// Clean up UI thread resources. This is expected to get called on the UI
// thread before the instance is deleted on the IO thread.
void CleanupOnUIThread();