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

Side by Side Diff: chrome/browser/ui/browser_navigator.cc

Issue 8588013: Fix crash in SyncSetupWizard::IsVisible() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 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
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/ui/browser_navigator.h" 5 #include "chrome/browser/ui/browser_navigator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const url_canon::Replacements<char>& replacements) { 64 const url_canon::Replacements<char>& replacements) {
65 if (url == other) 65 if (url == other)
66 return true; 66 return true;
67 67
68 GURL url_replaced = url.ReplaceComponents(replacements); 68 GURL url_replaced = url.ReplaceComponents(replacements);
69 GURL other_replaced = other.ReplaceComponents(replacements); 69 GURL other_replaced = other.ReplaceComponents(replacements);
70 return url_replaced == other_replaced; 70 return url_replaced == other_replaced;
71 } 71 }
72 72
73 // Change some of the navigation parameters based on the particular URL. 73 // Change some of the navigation parameters based on the particular URL.
74 // Currently this applies to chrome://settings, the bookmark manager, 74 // Currently this applies to some chrome:// pages which we always want to open
75 // and chrome://extensions, which we always want to open in a normal 75 // in a non-incognito window. Note that even though a ChromeOS guest session is
76 // (not incognito) window. Guest session is an exception. 76 // technically an incognito window, these URLs are allowed.
77 // chrome://extensions is on the list because it redirects to
78 // chrome://settings.
79 // Returns true on success. Otherwise, if changing params leads the browser into 77 // Returns true on success. Otherwise, if changing params leads the browser into
80 // an erroneous state, returns false. 78 // an erroneous state, returns false.
81 bool AdjustNavigateParamsForURL(browser::NavigateParams* params) { 79 bool AdjustNavigateParamsForURL(browser::NavigateParams* params) {
82 if (!params->target_contents && 80 if (params->target_contents != NULL ||
83 browser::IsURLAllowedInIncognito(params->url)) { 81 browser::IsURLAllowedInIncognito(params->url) ||
84 Profile* profile = 82 Profile::IsGuestSession()) {
85 params->browser ? params->browser->profile() : params->profile; 83 return true;
84 }
86 85
87 if ((profile->IsOffTheRecord() && !Profile::IsGuestSession()) || 86 Profile* profile =
88 params->disposition == OFF_THE_RECORD) { 87 params->browser ? params->browser->profile() : params->profile;
89 profile = profile->GetOriginalProfile();
90 88
91 // If incognito is forced, we punt. 89 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) {
92 PrefService* prefs = profile->GetPrefs(); 90 profile = profile->GetOriginalProfile();
93 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
94 IncognitoModePrefs::FORCED) {
95 return false;
96 }
97 91
98 params->disposition = SINGLETON_TAB; 92 // If incognito is forced, we punt.
99 params->profile = profile; 93 PrefService* prefs = profile->GetPrefs();
100 params->browser = Browser::GetOrCreateTabbedBrowser(profile); 94 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
101 params->window_action = browser::NavigateParams::SHOW_WINDOW; 95 IncognitoModePrefs::FORCED) {
96 return false;
102 } 97 }
98
99 params->disposition = SINGLETON_TAB;
100 params->profile = profile;
101 params->browser = Browser::GetOrCreateTabbedBrowser(profile);
102 params->window_action = browser::NavigateParams::SHOW_WINDOW;
103 } 103 }
104
104 return true; 105 return true;
105 } 106 }
106 107
107 // Returns a Browser that can host the navigation or tab addition specified in 108 // Returns a Browser that can host the navigation or tab addition specified in
108 // |params|. This might just return the same Browser specified in |params|, or 109 // |params|. This might just return the same Browser specified in |params|, or
109 // some other if that Browser is deemed incompatible. 110 // some other if that Browser is deemed incompatible.
110 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { 111 Browser* GetBrowserForDisposition(browser::NavigateParams* params) {
111 // If no source TabContents was specified, we use the selected one from the 112 // If no source TabContents was specified, we use the selected one from the
112 // target browser. This must happen first, before GetBrowserForDisposition() 113 // target browser. This must happen first, before GetBrowserForDisposition()
113 // has a chance to replace |params->browser| with another one. 114 // has a chance to replace |params->browser| with another one.
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 rewritten_url, replacements)) { 626 rewritten_url, replacements)) {
626 params->target_contents = tab; 627 params->target_contents = tab;
627 return tab_index; 628 return tab_index;
628 } 629 }
629 } 630 }
630 631
631 return -1; 632 return -1;
632 } 633 }
633 634
634 bool IsURLAllowedInIncognito(const GURL& url) { 635 bool IsURLAllowedInIncognito(const GURL& url) {
635 return url.scheme() == chrome::kChromeUIScheme && 636 // Most URLs are allowed in incognito; the following are exceptions.
637 // chrome://extensions is on the list because it redirects to
638 // chrome://settings.
639
640 return !(url.scheme() == chrome::kChromeUIScheme &&
636 (url.host() == chrome::kChromeUISettingsHost || 641 (url.host() == chrome::kChromeUISettingsHost ||
637 url.host() == chrome::kChromeUIExtensionsHost || 642 url.host() == chrome::kChromeUIExtensionsHost ||
638 url.host() == chrome::kChromeUIBookmarksHost); 643 url.host() == chrome::kChromeUIBookmarksHost ||
644 url.host() == chrome::kChromeUISyncPromoHost));
639 } 645 }
640 646
641 } // namespace browser 647 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.h ('k') | chrome/browser/ui/browser_navigator_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698