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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 11348315: Prevent chrome from launching apps in incognito mode from the command line. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/startup/startup_browser_creator_impl.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 height = std::min(height, work_area.height()); 446 height = std::min(height, work_area.height());
447 bounds->set_size(gfx::Size(width, height)); 447 bounds->set_size(gfx::Size(width, height));
448 bounds->set_x((work_area.width() - bounds->width()) / 2); 448 bounds->set_x((work_area.width() - bounds->width()) / 2);
449 // TODO(nkostylev): work_area does include launcher but should not. 449 // TODO(nkostylev): work_area does include launcher but should not.
450 // Launcher auto hide pref is synced and is most likely not applied here. 450 // Launcher auto hide pref is synced and is most likely not applied here.
451 bounds->set_y((work_area.height() - bounds->height()) / 2); 451 bounds->set_y((work_area.height() - bounds->height()) / 2);
452 } 452 }
453 } 453 }
454 } 454 }
455 455
456 bool StartupBrowserCreatorImpl::IsAppLaunch(std::string* app_url, 456 bool StartupBrowserCreatorImpl::IsAppLaunch(Profile* profile,
457 std::string* app_url,
457 std::string* app_id) { 458 std::string* app_id) {
459 // Don't launch apps in incognito mode.
460 if (profile->IsOffTheRecord())
461 return false;
458 if (command_line_.HasSwitch(switches::kApp)) { 462 if (command_line_.HasSwitch(switches::kApp)) {
459 if (app_url) 463 if (app_url)
460 *app_url = command_line_.GetSwitchValueASCII(switches::kApp); 464 *app_url = command_line_.GetSwitchValueASCII(switches::kApp);
461 return true; 465 return true;
462 } 466 }
463 if (command_line_.HasSwitch(switches::kAppId)) { 467 if (command_line_.HasSwitch(switches::kAppId)) {
464 if (app_id) 468 if (app_id)
465 *app_id = command_line_.GetSwitchValueASCII(switches::kAppId); 469 *app_id = command_line_.GetSwitchValueASCII(switches::kAppId);
466 return true; 470 return true;
467 } 471 }
468 return false; 472 return false;
469 } 473 }
470 474
471 bool StartupBrowserCreatorImpl::OpenApplicationTab(Profile* profile) { 475 bool StartupBrowserCreatorImpl::OpenApplicationTab(Profile* profile) {
472 std::string app_id; 476 std::string app_id;
473 // App shortcuts to URLs always open in an app window. Because this 477 // App shortcuts to URLs always open in an app window. Because this
474 // function will open an app that should be in a tab, there is no need 478 // function will open an app that should be in a tab, there is no need
475 // to look at the app URL. OpenApplicationWindow() will open app url 479 // to look at the app URL. OpenApplicationWindow() will open app url
476 // shortcuts. 480 // shortcuts.
477 if (!IsAppLaunch(NULL, &app_id) || app_id.empty()) 481 if (!IsAppLaunch(profile, NULL, &app_id) || app_id.empty())
478 return false; 482 return false;
479 483
480 extension_misc::LaunchContainer launch_container; 484 extension_misc::LaunchContainer launch_container;
481 const Extension* extension; 485 const Extension* extension;
482 if (!GetAppLaunchContainer(profile, app_id, &extension, &launch_container)) 486 if (!GetAppLaunchContainer(profile, app_id, &extension, &launch_container))
483 return false; 487 return false;
484 488
485 // If the user doesn't want to open a tab, fail. 489 // If the user doesn't want to open a tab, fail.
486 if (launch_container != extension_misc::LAUNCH_TAB) 490 if (launch_container != extension_misc::LAUNCH_TAB)
487 return false; 491 return false;
488 492
489 RecordCmdLineAppHistogram(); 493 RecordCmdLineAppHistogram();
490 494
491 WebContents* app_tab = application_launch::OpenApplication( 495 WebContents* app_tab = application_launch::OpenApplication(
492 application_launch::LaunchParams(profile, extension, 496 application_launch::LaunchParams(profile, extension,
493 extension_misc::LAUNCH_TAB, NEW_FOREGROUND_TAB)); 497 extension_misc::LAUNCH_TAB, NEW_FOREGROUND_TAB));
494 return (app_tab != NULL); 498 return (app_tab != NULL);
495 } 499 }
496 500
497 bool StartupBrowserCreatorImpl::OpenApplicationWindow( 501 bool StartupBrowserCreatorImpl::OpenApplicationWindow(
498 Profile* profile, 502 Profile* profile,
499 content::WebContents** out_app_contents) { 503 content::WebContents** out_app_contents) {
500 // Set |out_app_contents| to NULL early on (just in case). 504 // Set |out_app_contents| to NULL early on (just in case).
501 if (out_app_contents) 505 if (out_app_contents)
502 *out_app_contents = NULL; 506 *out_app_contents = NULL;
503 507
504 std::string url_string, app_id; 508 std::string url_string, app_id;
505 if (!IsAppLaunch(&url_string, &app_id)) 509 if (!IsAppLaunch(profile, &url_string, &app_id))
506 return false; 510 return false;
507 511
508 // This can fail if the app_id is invalid. It can also fail if the 512 // This can fail if the app_id is invalid. It can also fail if the
509 // extension is external, and has not yet been installed. 513 // extension is external, and has not yet been installed.
510 // TODO(skerner): Do something reasonable here. Pop up a warning panel? 514 // TODO(skerner): Do something reasonable here. Pop up a warning panel?
511 // Open an URL to the gallery page of the extension id? 515 // Open an URL to the gallery page of the extension id?
512 if (!app_id.empty()) { 516 if (!app_id.empty()) {
513 extension_misc::LaunchContainer launch_container; 517 extension_misc::LaunchContainer launch_container;
514 const Extension* extension; 518 const Extension* extension;
515 if (!GetAppLaunchContainer(profile, app_id, &extension, &launch_container)) 519 if (!GetAppLaunchContainer(profile, app_id, &extension, &launch_container))
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1055
1052 #if !defined(OS_WIN) || defined(USE_AURA) 1056 #if !defined(OS_WIN) || defined(USE_AURA)
1053 // static 1057 // static
1054 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( 1058 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser(
1055 Profile* profile, 1059 Profile* profile,
1056 const std::vector<GURL>& startup_urls) { 1060 const std::vector<GURL>& startup_urls) {
1057 return false; 1061 return false;
1058 } 1062 }
1059 #endif 1063 #endif
1060 1064
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698