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

Unified Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 8373027: Prevent incognito windows from opening when incognito mode is disabled. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Handle the case when args is NULL. Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
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));
« no previous file with comments | « chrome/browser/extensions/extension_tabs_apitest.cc ('k') | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698