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

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: Handle the case when args is NULL. 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 #else 345 #else
346 popup_bounds = window_bounds; // Use window size as default for popups 346 popup_bounds = window_bounds; // Use window size as default for popups
347 #endif 347 #endif
348 348
349 Profile* window_profile = profile(); 349 Profile* window_profile = profile();
350 Browser::Type window_type = Browser::TYPE_TABBED; 350 Browser::Type window_type = Browser::TYPE_TABBED;
351 bool focused = true; 351 bool focused = true;
352 bool saw_focus_key = false; 352 bool saw_focus_key = false;
353 std::string extension_id; 353 std::string extension_id;
354 354
355 // 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.
356 const IncognitoModePrefs::Availability incognito_availability =
357 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
358 bool incognito = false;
359 if (args && args->HasKey(keys::kIncognitoKey)) {
360 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey,
361 &incognito));
362 if (incognito && incognito_availability == IncognitoModePrefs::DISABLED) {
363 error_ = keys::kIncognitoModeIsDisabled;
364 return false;
365 }
366 if (!incognito && incognito_availability == IncognitoModePrefs::FORCED) {
367 error_ = keys::kIncognitoModeIsForced;
368 return false;
369 }
370 } else if (incognito_availability == IncognitoModePrefs::FORCED) {
371 // If incognito argument is not specified explicitly, we default to
372 // incognito when forced so by policy.
373 incognito = true;
374 }
375
376 // If we are opening an incognito window.
377 if (incognito) {
378 std::string first_url_erased;
379 // Guest session is an exception as it always opens in incognito mode.
380 for (size_t i = 0; i < urls.size();) {
381 if (browser::IsURLAllowedInIncognito(urls[i]) &&
382 !Profile::IsGuestSession()) {
383 if (first_url_erased.empty())
384 first_url_erased = urls[i].spec();
385 urls.erase(urls.begin() + i);
386 } else {
387 i++;
388 }
389 }
390 if (urls.empty() && !first_url_erased.empty()) {
391 error_ = ExtensionErrorUtils::FormatErrorMessage(
392 keys::kURLsNotAllowedInIncognitoError, first_url_erased);
393 return false;
394 }
395 window_profile = window_profile->GetOffTheRecordProfile();
396 }
397
355 if (args) { 398 if (args) {
356 // Any part of the bounds can optionally be set by the caller. 399 // Any part of the bounds can optionally be set by the caller.
357 int bounds_val; 400 int bounds_val;
358 if (args->HasKey(keys::kLeftKey)) { 401 if (args->HasKey(keys::kLeftKey)) {
359 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, 402 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey,
360 &bounds_val)); 403 &bounds_val));
361 window_bounds.set_x(bounds_val); 404 window_bounds.set_x(bounds_val);
362 popup_bounds.set_x(bounds_val); 405 popup_bounds.set_x(bounds_val);
363 panel_bounds.set_x(bounds_val); 406 panel_bounds.set_x(bounds_val);
364 } 407 }
(...skipping 15 matching lines...) Expand all
380 } 423 }
381 424
382 if (args->HasKey(keys::kHeightKey)) { 425 if (args->HasKey(keys::kHeightKey)) {
383 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey, 426 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey,
384 &bounds_val)); 427 &bounds_val));
385 window_bounds.set_height(bounds_val); 428 window_bounds.set_height(bounds_val);
386 popup_bounds.set_height(bounds_val); 429 popup_bounds.set_height(bounds_val);
387 panel_bounds.set_height(bounds_val); 430 panel_bounds.set_height(bounds_val);
388 } 431 }
389 432
390 bool incognito = false;
391 if (args->HasKey(keys::kIncognitoKey)) {
392 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey,
393 &incognito));
394 if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) ==
395 IncognitoModePrefs::DISABLED) {
396 error_ = keys::kIncognitoModeIsDisabled;
397 return false;
398 }
399
400 if (incognito) {
401 std::string first_url_erased;
402 // Guest session is an exception as it always opens in incognito mode.
403 for (size_t i = 0; i < urls.size();) {
404 if (browser::IsURLAllowedInIncognito(urls[i]) &&
405 !Profile::IsGuestSession()) {
406 if (first_url_erased.empty())
407 first_url_erased = urls[i].spec();
408 urls.erase(urls.begin() + i);
409 } else {
410 i++;
411 }
412 }
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 }
420 }
421
422 if (args->HasKey(keys::kFocusedKey)) { 433 if (args->HasKey(keys::kFocusedKey)) {
423 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, 434 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey,
424 &focused)); 435 &focused));
425 saw_focus_key = true; 436 saw_focus_key = true;
426 } 437 }
427 438
428 std::string type_str; 439 std::string type_str;
429 if (args->HasKey(keys::kWindowTypeKey)) { 440 if (args->HasKey(keys::kWindowTypeKey)) {
430 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, 441 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey,
431 &type_str)); 442 &type_str));
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 // called for every API call the extension made. 1549 // called for every API call the extension made.
1539 GotLanguage(language); 1550 GotLanguage(language);
1540 } 1551 }
1541 1552
1542 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1553 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1543 result_.reset(Value::CreateStringValue(language.c_str())); 1554 result_.reset(Value::CreateStringValue(language.c_str()));
1544 SendResponse(true); 1555 SendResponse(true);
1545 1556
1546 Release(); // Balanced in Run() 1557 Release(); // Balanced in Run()
1547 } 1558 }
OLDNEW
« 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