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

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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_avail =
Finnur 2011/10/24 10:08:08 nit: Please don't abbreviate the variable names.
rustema 2011/10/25 03:35:17 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()) ==
395 IncognitoModePrefs::DISABLED) {
396 error_ = keys::kIncognitoModeIsDisabled;
397 return false;
398 }
399
400 if (incognito) { 396 if (incognito) {
397 if (incognito_avail == IncognitoModePrefs::DISABLED) {
398 error_ = keys::kIncognitoModeIsDisabled;
399 return false;
400 }
401 std::string first_url_erased; 401 std::string first_url_erased;
402 // Guest session is an exception as it always opens in incognito mode. 402 // Guest session is an exception as it always opens in incognito mode.
403 for (size_t i = 0; i < urls.size();) { 403 for (size_t i = 0; i < urls.size();) {
404 if (browser::IsURLAllowedInIncognito(urls[i]) && 404 if (browser::IsURLAllowedInIncognito(urls[i]) &&
405 !Profile::IsGuestSession()) { 405 !Profile::IsGuestSession()) {
406 if (first_url_erased.empty()) 406 if (first_url_erased.empty())
407 first_url_erased = urls[i].spec(); 407 first_url_erased = urls[i].spec();
408 urls.erase(urls.begin() + i); 408 urls.erase(urls.begin() + i);
409 } else { 409 } else {
410 i++; 410 i++;
411 } 411 }
412 } 412 }
413 if (urls.empty() && !first_url_erased.empty()) { 413 if (urls.empty() && !first_url_erased.empty()) {
414 error_ = ExtensionErrorUtils::FormatErrorMessage( 414 error_ = ExtensionErrorUtils::FormatErrorMessage(
415 keys::kURLsNotAllowedInIncognitoError, first_url_erased); 415 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
416 return false; 416 return false;
417 } 417 }
418 window_profile = window_profile->GetOffTheRecordProfile(); 418 window_profile = window_profile->GetOffTheRecordProfile();
419 } 419 }
420 } 420 }
421 if (!incognito && incognito_avail == IncognitoModePrefs::FORCED) {
422 error_ = keys::kIncognitoModeIsForced;
423 return false;
424 }
421 425
422 if (args->HasKey(keys::kFocusedKey)) { 426 if (args->HasKey(keys::kFocusedKey)) {
423 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 427 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey,
424 &focused)); 428 &focused));
425 saw_focus_key = true; 429 saw_focus_key = true;
426 } 430 }
427 431
428 std::string type_str; 432 std::string type_str;
429 if (args->HasKey(keys::kWindowTypeKey)) { 433 if (args->HasKey(keys::kWindowTypeKey)) {
430 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, 434 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 // called for every API call the extension made. 1542 // called for every API call the extension made.
1539 GotLanguage(language); 1543 GotLanguage(language);
1540 } 1544 }
1541 1545
1542 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1546 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1543 result_.reset(Value::CreateStringValue(language.c_str())); 1547 result_.reset(Value::CreateStringValue(language.c_str()));
1544 SendResponse(true); 1548 SendResponse(true);
1545 1549
1546 Release(); // Balanced in Run() 1550 Release(); // Balanced in Run()
1547 } 1551 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698