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

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

Issue 1662783002: Remove HostDesktopType from Browser::CreateParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-12
Patch Set: remove desktop_type_ in bookmark_bubble_sign_in_delegate Created 4 years, 10 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
« no previous file with comments | « chrome/browser/ui/browser_mac.cc ('k') | chrome/browser/ui/browser_navigator_browsertest.cc » ('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) 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/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/macros.h" 10 #include "base/macros.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Returns true if the specified Browser can open tabs. Not all Browsers support 75 // Returns true if the specified Browser can open tabs. Not all Browsers support
76 // multiple tabs, such as app frames and popups. This function returns false for 76 // multiple tabs, such as app frames and popups. This function returns false for
77 // those types of Browser. 77 // those types of Browser.
78 bool WindowCanOpenTabs(Browser* browser) { 78 bool WindowCanOpenTabs(Browser* browser) {
79 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || 79 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) ||
80 browser->tab_strip_model()->empty(); 80 browser->tab_strip_model()->empty();
81 } 81 }
82 82
83 // Finds an existing Browser compatible with |profile|, making a new one if no 83 // Finds an existing Browser compatible with |profile|, making a new one if no
84 // such Browser is located. 84 // such Browser is located.
85 Browser* GetOrCreateBrowser(Profile* profile, 85 Browser* GetOrCreateBrowser(Profile* profile) {
86 chrome::HostDesktopType host_desktop_type) {
87 Browser* browser = chrome::FindTabbedBrowser(profile, false); 86 Browser* browser = chrome::FindTabbedBrowser(profile, false);
88 return browser ? browser : new Browser( 87 return browser ? browser : new Browser(Browser::CreateParams(profile));
89 Browser::CreateParams(profile, host_desktop_type));
90 } 88 }
91 89
92 // Change some of the navigation parameters based on the particular URL. 90 // Change some of the navigation parameters based on the particular URL.
93 // Currently this applies to some chrome:// pages which we always want to open 91 // Currently this applies to some chrome:// pages which we always want to open
94 // in a non-incognito window. Note that even though a ChromeOS guest session is 92 // in a non-incognito window. Note that even though a ChromeOS guest session is
95 // technically an incognito window, these URLs are allowed. 93 // technically an incognito window, these URLs are allowed.
96 // Returns true on success. Otherwise, if changing params leads the browser into 94 // Returns true on success. Otherwise, if changing params leads the browser into
97 // an erroneous state, returns false. 95 // an erroneous state, returns false.
98 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { 96 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) {
99 if (params->target_contents != NULL || 97 if (params->target_contents != NULL ||
100 chrome::IsURLAllowedInIncognito(params->url, 98 chrome::IsURLAllowedInIncognito(params->url,
101 params->initiating_profile) || 99 params->initiating_profile) ||
102 params->initiating_profile->IsGuestSession()) { 100 params->initiating_profile->IsGuestSession()) {
103 return true; 101 return true;
104 } 102 }
105 103
106 Profile* profile = params->initiating_profile; 104 Profile* profile = params->initiating_profile;
107 105
108 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { 106 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) {
109 profile = profile->GetOriginalProfile(); 107 profile = profile->GetOriginalProfile();
110 108
111 // If incognito is forced, we punt. 109 // If incognito is forced, we punt.
112 PrefService* prefs = profile->GetPrefs(); 110 PrefService* prefs = profile->GetPrefs();
113 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == 111 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
114 IncognitoModePrefs::FORCED) { 112 IncognitoModePrefs::FORCED) {
115 return false; 113 return false;
116 } 114 }
117 115
118 params->disposition = SINGLETON_TAB; 116 params->disposition = SINGLETON_TAB;
119 params->browser = GetOrCreateBrowser(profile, params->host_desktop_type); 117 params->browser = GetOrCreateBrowser(profile);
120 params->window_action = chrome::NavigateParams::SHOW_WINDOW; 118 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
121 } 119 }
122 120
123 return true; 121 return true;
124 } 122 }
125 123
126 // Returns a Browser that can host the navigation or tab addition specified in 124 // Returns a Browser that can host the navigation or tab addition specified in
127 // |params|. This might just return the same Browser specified in |params|, or 125 // |params|. This might just return the same Browser specified in |params|, or
128 // some other if that Browser is deemed incompatible. 126 // some other if that Browser is deemed incompatible.
129 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { 127 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) {
130 // If no source WebContents was specified, we use the selected one from 128 // If no source WebContents was specified, we use the selected one from
131 // the target browser. This must happen first, before 129 // the target browser. This must happen first, before
132 // GetBrowserForDisposition() has a chance to replace |params->browser| with 130 // GetBrowserForDisposition() has a chance to replace |params->browser| with
133 // another one. 131 // another one.
134 if (!params->source_contents && params->browser) { 132 if (!params->source_contents && params->browser) {
135 params->source_contents = 133 params->source_contents =
136 params->browser->tab_strip_model()->GetActiveWebContents(); 134 params->browser->tab_strip_model()->GetActiveWebContents();
137 } 135 }
138 136
139 Profile* profile = params->initiating_profile; 137 Profile* profile = params->initiating_profile;
140 138
141 switch (params->disposition) { 139 switch (params->disposition) {
142 case CURRENT_TAB: 140 case CURRENT_TAB:
143 if (params->browser) 141 if (params->browser)
144 return params->browser; 142 return params->browser;
145 // Find a compatible window and re-execute this command in it. Otherwise 143 // Find a compatible window and re-execute this command in it. Otherwise
146 // re-run with NEW_WINDOW. 144 // re-run with NEW_WINDOW.
147 return GetOrCreateBrowser(profile, params->host_desktop_type); 145 return GetOrCreateBrowser(profile);
148 case SINGLETON_TAB: 146 case SINGLETON_TAB:
149 case NEW_FOREGROUND_TAB: 147 case NEW_FOREGROUND_TAB:
150 case NEW_BACKGROUND_TAB: 148 case NEW_BACKGROUND_TAB:
151 // See if we can open the tab in the window this navigator is bound to. 149 // See if we can open the tab in the window this navigator is bound to.
152 if (params->browser && WindowCanOpenTabs(params->browser)) 150 if (params->browser && WindowCanOpenTabs(params->browser))
153 return params->browser; 151 return params->browser;
154 // Find a compatible window and re-execute this command in it. Otherwise 152 // Find a compatible window and re-execute this command in it. Otherwise
155 // re-run with NEW_WINDOW. 153 // re-run with NEW_WINDOW.
156 return GetOrCreateBrowser(profile, params->host_desktop_type); 154 return GetOrCreateBrowser(profile);
157 case NEW_POPUP: { 155 case NEW_POPUP: {
158 // Make a new popup window. 156 // Make a new popup window.
159 // Coerce app-style if |source| represents an app. 157 // Coerce app-style if |source| represents an app.
160 std::string app_name; 158 std::string app_name;
161 #if defined(ENABLE_EXTENSIONS) 159 #if defined(ENABLE_EXTENSIONS)
162 if (!params->extension_app_id.empty()) { 160 if (!params->extension_app_id.empty()) {
163 app_name = web_app::GenerateApplicationNameFromExtensionId( 161 app_name = web_app::GenerateApplicationNameFromExtensionId(
164 params->extension_app_id); 162 params->extension_app_id);
165 } else if (params->browser && !params->browser->app_name().empty()) { 163 } else if (params->browser && !params->browser->app_name().empty()) {
166 app_name = params->browser->app_name(); 164 app_name = params->browser->app_name();
167 } else if (params->source_contents) { 165 } else if (params->source_contents) {
168 extensions::TabHelper* extensions_tab_helper = 166 extensions::TabHelper* extensions_tab_helper =
169 extensions::TabHelper::FromWebContents(params->source_contents); 167 extensions::TabHelper::FromWebContents(params->source_contents);
170 if (extensions_tab_helper && extensions_tab_helper->is_app()) { 168 if (extensions_tab_helper && extensions_tab_helper->is_app()) {
171 app_name = web_app::GenerateApplicationNameFromExtensionId( 169 app_name = web_app::GenerateApplicationNameFromExtensionId(
172 extensions_tab_helper->extension_app()->id()); 170 extensions_tab_helper->extension_app()->id());
173 } 171 }
174 } 172 }
175 #endif 173 #endif
176 if (app_name.empty()) { 174 if (app_name.empty()) {
177 Browser::CreateParams browser_params( 175 Browser::CreateParams browser_params(Browser::TYPE_POPUP, profile);
178 Browser::TYPE_POPUP, profile, params->host_desktop_type);
179 browser_params.trusted_source = params->trusted_source; 176 browser_params.trusted_source = params->trusted_source;
180 browser_params.initial_bounds = params->window_bounds; 177 browser_params.initial_bounds = params->window_bounds;
181 return new Browser(browser_params); 178 return new Browser(browser_params);
182 } 179 }
183 180
184 return new Browser(Browser::CreateParams::CreateForApp( 181 return new Browser(Browser::CreateParams::CreateForApp(
185 app_name, 182 app_name, params->trusted_source, params->window_bounds, profile));
186 params->trusted_source,
187 params->window_bounds,
188 profile,
189 params->host_desktop_type));
190 } 183 }
191 case NEW_WINDOW: { 184 case NEW_WINDOW: {
192 // Make a new normal browser window. 185 // Make a new normal browser window.
193 return new Browser(Browser::CreateParams(profile, 186 return new Browser(Browser::CreateParams(profile));
194 params->host_desktop_type));
195 } 187 }
196 case OFF_THE_RECORD: 188 case OFF_THE_RECORD:
197 // Make or find an incognito window. 189 // Make or find an incognito window.
198 return GetOrCreateBrowser(profile->GetOffTheRecordProfile(), 190 return GetOrCreateBrowser(profile->GetOffTheRecordProfile());
199 params->host_desktop_type);
200 // The following types all result in no navigation. 191 // The following types all result in no navigation.
201 case SUPPRESS_OPEN: 192 case SUPPRESS_OPEN:
202 case SAVE_TO_DISK: 193 case SAVE_TO_DISK:
203 case IGNORE_ACTION: 194 case IGNORE_ACTION:
204 return NULL; 195 return NULL;
205 default: 196 default:
206 NOTREACHED(); 197 NOTREACHED();
207 } 198 }
208 return NULL; 199 return NULL;
209 } 200 }
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 bool reverse_on_redirect = false; 645 bool reverse_on_redirect = false;
655 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 646 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
656 &rewritten_url, browser_context, &reverse_on_redirect); 647 &rewritten_url, browser_context, &reverse_on_redirect);
657 648
658 // Some URLs are mapped to uber subpages. Do not allow them in incognito. 649 // Some URLs are mapped to uber subpages. Do not allow them in incognito.
659 return !(rewritten_url.scheme() == content::kChromeUIScheme && 650 return !(rewritten_url.scheme() == content::kChromeUIScheme &&
660 rewritten_url.host() == chrome::kChromeUIUberHost); 651 rewritten_url.host() == chrome::kChromeUIUberHost);
661 } 652 }
662 653
663 } // namespace chrome 654 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_mac.cc ('k') | chrome/browser/ui/browser_navigator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698