Index: chrome/browser/extensions/extension_tabs_module.cc |
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc |
index b1b60ed454c9bd4b52600cd3d853a0427314b221..665736a518601e8e53e5aee866388d13da8443c1 100644 |
--- a/chrome/browser/extensions/extension_tabs_module.cc |
+++ b/chrome/browser/extensions/extension_tabs_module.cc |
@@ -352,6 +352,49 @@ bool CreateWindowFunction::RunImpl() { |
bool saw_focus_key = false; |
std::string extension_id; |
+ // Decide whether we are opening a normal window or an incognito window. |
Aaron Boodman
2011/10/29 20:29:00
This function is getting a little long. Could you
rustema
2011/10/31 07:59:57
Done.
|
+ const IncognitoModePrefs::Availability incognito_availability = |
+ IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
+ bool incognito = false; |
+ if (args && args->HasKey(keys::kIncognitoKey)) { |
+ EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, |
+ &incognito)); |
+ if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) { |
+ error_ = keys::kIncognitoModeIsDisabled; |
+ return false; |
+ } |
+ if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) { |
+ error_ = keys::kIncognitoModeIsForced; |
+ return false; |
+ } |
+ } else if (incognito_availability == IncognitoModePrefs::FORCED) { |
+ // If incognito argument is not specified explicitly, we default to |
+ // incognito when forced so by policy. |
+ incognito = true; |
+ } |
+ |
+ // If we are opening an incognito window. |
+ if (incognito) { |
+ std::string first_url_erased; |
+ // Guest session is an exception as it always opens in incognito mode. |
+ for (size_t i = 0; i < urls.size();) { |
+ if (browser::IsURLAllowedInIncognito(urls[i]) && |
+ !Profile::IsGuestSession()) { |
+ if (first_url_erased.empty()) |
+ first_url_erased = urls[i].spec(); |
+ urls.erase(urls.begin() + i); |
+ } else { |
+ i++; |
+ } |
+ } |
+ if (urls.empty() && !first_url_erased.empty()) { |
+ error_ = ExtensionErrorUtils::FormatErrorMessage( |
+ keys::kURLsNotAllowedInIncognitoError, first_url_erased); |
+ return false; |
+ } |
+ window_profile = window_profile->GetOffTheRecordProfile(); |
+ } |
+ |
if (args) { |
// Any part of the bounds can optionally be set by the caller. |
int bounds_val; |
@@ -387,38 +430,6 @@ bool CreateWindowFunction::RunImpl() { |
panel_bounds.set_height(bounds_val); |
} |
- bool incognito = false; |
- if (args->HasKey(keys::kIncognitoKey)) { |
- EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, |
- &incognito)); |
- if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == |
- IncognitoModePrefs::DISABLED) { |
- error_ = keys::kIncognitoModeIsDisabled; |
- return false; |
- } |
- |
- if (incognito) { |
- std::string first_url_erased; |
- // Guest session is an exception as it always opens in incognito mode. |
- for (size_t i = 0; i < urls.size();) { |
- if (browser::IsURLAllowedInIncognito(urls[i]) && |
- !Profile::IsGuestSession()) { |
- if (first_url_erased.empty()) |
- first_url_erased = urls[i].spec(); |
- urls.erase(urls.begin() + i); |
- } else { |
- i++; |
- } |
- } |
- if (urls.empty() && !first_url_erased.empty()) { |
- error_ = ExtensionErrorUtils::FormatErrorMessage( |
- keys::kURLsNotAllowedInIncognitoError, first_url_erased); |
- return false; |
- } |
- window_profile = window_profile->GetOffTheRecordProfile(); |
- } |
- } |
- |
if (args->HasKey(keys::kFocusedKey)) { |
EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, |
&focused)); |