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

Side by Side 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: Default to creating incognito windows when incognito param is not specified. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extensions/extension_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 380 }
381 381
382 if (args->HasKey(keys::kHeightKey)) { 382 if (args->HasKey(keys::kHeightKey)) {
383 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 383 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey,
384 &bounds_val)); 384 &bounds_val));
385 window_bounds.set_height(bounds_val); 385 window_bounds.set_height(bounds_val);
386 popup_bounds.set_height(bounds_val); 386 popup_bounds.set_height(bounds_val);
387 panel_bounds.set_height(bounds_val); 387 panel_bounds.set_height(bounds_val);
388 } 388 }
389 389
390 const IncognitoModePrefs::Availability incognito_availability =
Joao da Silva 2011/10/28 11:05:29 These checks are scoped inside an "if (args)" bloc
rustema 2011/10/29 06:43:21 Done.
391 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
390 bool incognito = false; 392 bool incognito = false;
391 if (args->HasKey(keys::kIncognitoKey)) { 393 if (args->HasKey(keys::kIncognitoKey)) {
392 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, 394 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey,
393 &incognito)); 395 &incognito));
394 if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == 396 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) {
395 IncognitoModePrefs::DISABLED) {
396 error_ = keys::kIncognitoModeIsDisabled; 397 error_ = keys::kIncognitoModeIsDisabled;
397 return false; 398 return false;
398 } 399 }
400 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) {
401 error_ = keys::kIncognitoModeIsForced;
402 return false;
403 }
404 } else if (incognito_availability == IncognitoModePrefs::FORCED) {
405 // If incognito argument is not specified explicitly, we default to
406 // incognito.
pastarmovj 2011/10/27 09:14:31 maybe extend this sentence to include "...when for
rustema 2011/10/29 06:43:21 Done.
407 incognito = true;
408 }
399 409
400 if (incognito) { 410 // If we are opening an incognito window.
401 std::string first_url_erased; 411 if (incognito) {
402 // Guest session is an exception as it always opens in incognito mode. 412 std::string first_url_erased;
403 for (size_t i = 0; i < urls.size();) { 413 // Guest session is an exception as it always opens in incognito mode.
404 if (browser::IsURLAllowedInIncognito(urls[i]) && 414 for (size_t i = 0; i < urls.size();) {
405 !Profile::IsGuestSession()) { 415 if (browser::IsURLAllowedInIncognito(urls[i]) &&
406 if (first_url_erased.empty()) 416 !Profile::IsGuestSession()) {
407 first_url_erased = urls[i].spec(); 417 if (first_url_erased.empty())
408 urls.erase(urls.begin() + i); 418 first_url_erased = urls[i].spec();
409 } else { 419 urls.erase(urls.begin() + i);
410 i++; 420 } else {
411 } 421 i++;
412 } 422 }
413 if (urls.empty() && !first_url_erased.empty()) {
414 error_ = ExtensionErrorUtils::FormatErrorMessage(
415 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
416 return false;
417 }
418 window_profile = window_profile->GetOffTheRecordProfile();
419 } 423 }
424 if (urls.empty() && !first_url_erased.empty()) {
425 error_ = ExtensionErrorUtils::FormatErrorMessage(
426 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
427 return false;
428 }
429 window_profile = window_profile->GetOffTheRecordProfile();
420 } 430 }
421 431
422 if (args->HasKey(keys::kFocusedKey)) { 432 if (args->HasKey(keys::kFocusedKey)) {
423 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 433 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey,
424 &focused)); 434 &focused));
425 saw_focus_key = true; 435 saw_focus_key = true;
426 } 436 }
427 437
428 std::string type_str; 438 std::string type_str;
429 if (args->HasKey(keys::kWindowTypeKey)) { 439 if (args->HasKey(keys::kWindowTypeKey)) {
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 // called for every API call the extension made. 1548 // called for every API call the extension made.
1539 GotLanguage(language); 1549 GotLanguage(language);
1540 } 1550 }
1541 1551
1542 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1552 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1543 result_.reset(Value::CreateStringValue(language.c_str())); 1553 result_.reset(Value::CreateStringValue(language.c_str()));
1544 SendResponse(true); 1554 SendResponse(true);
1545 1555
1546 Release(); // Balanced in Run() 1556 Release(); // Balanced in Run()
1547 } 1557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698