OLD | NEW |
---|---|
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 Loading... | |
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()) |
James Hawkins
2011/11/22 00:59:27
Multi-line logic requires braces on the if block.
| |
85 params->browser ? params->browser->profile() : params->profile; | 83 return true; |
86 | 84 |
87 if ((profile->IsOffTheRecord() && !Profile::IsGuestSession()) || | 85 Profile* profile = |
88 params->disposition == OFF_THE_RECORD) { | 86 params->browser ? params->browser->profile() : params->profile; |
89 profile = profile->GetOriginalProfile(); | |
90 | 87 |
91 // If incognito is forced, we punt. | 88 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { |
92 PrefService* prefs = profile->GetPrefs(); | 89 profile = profile->GetOriginalProfile(); |
93 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == | |
94 IncognitoModePrefs::FORCED) { | |
95 return false; | |
96 } | |
97 | 90 |
98 params->disposition = SINGLETON_TAB; | 91 // If incognito is forced, we punt. |
99 params->profile = profile; | 92 PrefService* prefs = profile->GetPrefs(); |
100 params->browser = Browser::GetOrCreateTabbedBrowser(profile); | 93 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == |
101 params->window_action = browser::NavigateParams::SHOW_WINDOW; | 94 IncognitoModePrefs::FORCED) { |
95 return false; | |
102 } | 96 } |
97 | |
98 params->disposition = SINGLETON_TAB; | |
99 params->profile = profile; | |
100 params->browser = Browser::GetOrCreateTabbedBrowser(profile); | |
101 params->window_action = browser::NavigateParams::SHOW_WINDOW; | |
103 } | 102 } |
103 | |
104 return true; | 104 return true; |
105 } | 105 } |
106 | 106 |
107 // Returns a Browser that can host the navigation or tab addition specified in | 107 // 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 | 108 // |params|. This might just return the same Browser specified in |params|, or |
109 // some other if that Browser is deemed incompatible. | 109 // some other if that Browser is deemed incompatible. |
110 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { | 110 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { |
111 // If no source TabContents was specified, we use the selected one from the | 111 // If no source TabContents was specified, we use the selected one from the |
112 // target browser. This must happen first, before GetBrowserForDisposition() | 112 // target browser. This must happen first, before GetBrowserForDisposition() |
113 // has a chance to replace |params->browser| with another one. | 113 // has a chance to replace |params->browser| with another one. |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 rewritten_url, replacements)) { | 625 rewritten_url, replacements)) { |
626 params->target_contents = tab; | 626 params->target_contents = tab; |
627 return tab_index; | 627 return tab_index; |
628 } | 628 } |
629 } | 629 } |
630 | 630 |
631 return -1; | 631 return -1; |
632 } | 632 } |
633 | 633 |
634 bool IsURLAllowedInIncognito(const GURL& url) { | 634 bool IsURLAllowedInIncognito(const GURL& url) { |
635 return url.scheme() == chrome::kChromeUIScheme && | 635 // Most URLs are allowed in incognito; the following are exceptions. |
636 // chrome://extensions is on the list because it redirects to | |
637 // chrome://settings. | |
638 | |
639 return !(url.scheme() == chrome::kChromeUIScheme && | |
636 (url.host() == chrome::kChromeUISettingsHost || | 640 (url.host() == chrome::kChromeUISettingsHost || |
637 url.host() == chrome::kChromeUIExtensionsHost || | 641 url.host() == chrome::kChromeUIExtensionsHost || |
638 url.host() == chrome::kChromeUIBookmarksHost); | 642 url.host() == chrome::kChromeUIBookmarksHost || |
643 url.host() == chrome::kChromeUISyncPromoHost)); | |
639 } | 644 } |
640 | 645 |
641 } // namespace browser | 646 } // namespace browser |
OLD | NEW |