blob: fbd9415bab16f58c2f8355ca6483d492c6422191 [file] [log] [blame]
[email protected]c333e792012-01-06 16:57:391// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8b0e9cc32010-11-09 04:00:192// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]339d6dd2010-11-12 00:41:585#include "chrome/browser/ui/browser_navigator.h"
[email protected]8b0e9cc32010-11-09 04:00:196
[email protected]07afd7c2011-02-17 10:07:117#include <algorithm>
8
[email protected]8b0e9cc32010-11-09 04:00:199#include "base/command_line.h"
[email protected]3853a4c2013-02-11 17:15:5710#include "base/prefs/pref_service.h"
[email protected]11521182013-06-11 04:06:3611#include "base/strings/stringprintf.h"
[email protected]5846d582013-06-08 16:02:1212#include "base/strings/utf_string_conversions.h"
[email protected]2f89b602011-06-01 05:49:1713#include "chrome/browser/browser_about_handler.h"
[email protected]dcc8fbc2013-07-12 00:54:0914#include "chrome/browser/chrome_notification_types.h"
[email protected]93ad8e1c2011-11-08 21:34:0515#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]a0358d72012-03-09 14:06:5016#include "chrome/browser/prerender/prerender_manager.h"
17#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]8ecad5e2010-12-02 21:18:3318#include "chrome/browser/profiles/profile.h"
[email protected]1ab4ddf2011-07-21 04:48:0419#include "chrome/browser/tab_contents/tab_util.h"
afakhry8394f942015-07-09 18:46:0920#include "chrome/browser/task_management/web_contents_tags.h"
[email protected]7b5dc002010-11-16 23:08:1021#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4322#include "chrome/browser/ui/browser_finder.h"
[email protected]0c9406632013-02-08 01:13:3323#include "chrome/browser/ui/browser_instant_controller.h"
[email protected]00070c732011-04-09 15:31:3324#include "chrome/browser/ui/browser_window.h"
[email protected]435d43e02012-12-09 09:13:5525#include "chrome/browser/ui/host_desktop.h"
[email protected]d57ce6a2014-07-03 15:39:2326#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]a1558992013-12-12 20:52:1627#include "chrome/browser/ui/search/instant_search_prerenderer.h"
[email protected]5d9cace72012-06-21 16:07:1228#include "chrome/browser/ui/singleton_tabs.h"
[email protected]6768ac02011-04-06 17:41:0429#include "chrome/browser/ui/status_bubble.h"
[email protected]e0bc75d52014-01-30 23:42:5930#include "chrome/browser/ui/tab_helpers.h"
[email protected]b56e2e32012-05-11 21:18:0431#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]eca258132010-11-15 23:33:0832#include "chrome/common/url_constants.h"
[email protected]825b1662012-03-12 19:07:3133#include "content/public/browser/browser_url_handler.h"
[email protected]df165e52013-12-05 00:00:5334#include "content/public/browser/navigation_entry.h"
[email protected]ad50def52011-10-19 23:17:0735#include "content/public/browser/notification_service.h"
[email protected]9c1662b2012-03-06 15:44:3336#include "content/public/browser/render_view_host.h"
[email protected]6acde6352012-01-04 16:52:2037#include "content/public/browser/web_contents.h"
[email protected]8b0e9cc32010-11-09 04:00:1938
[email protected]ad4c2d32013-12-06 12:59:2639#if defined(USE_ASH)
40#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
41#endif
thestig2dbee717e2014-09-05 14:54:2842
[email protected]54944cde2012-12-09 09:24:5943#if defined(USE_AURA)
44#include "ui/aura/window.h"
45#endif
46
thestig2dbee717e2014-09-05 14:54:2847#if defined(ENABLE_EXTENSIONS)
thestiga84d8e62014-10-17 22:27:5548#include "chrome/browser/extensions/tab_helper.h"
49#include "chrome/browser/web_applications/web_app.h"
thestig2dbee717e2014-09-05 14:54:2850#include "extensions/browser/extension_registry.h"
51#include "extensions/common/extension.h"
52#include "extensions/common/extension_set.h"
53#endif
54
[email protected]e5d549d2011-12-28 01:29:2055using content::GlobalRequestID;
[email protected]a2efc35d2013-08-03 23:17:2556using content::NavigationController;
[email protected]ea049a02011-12-25 21:37:0957using content::WebContents;
58
[email protected]e232c992012-12-06 12:43:2059class BrowserNavigatorWebContentsAdoption {
60 public:
[email protected]27e5b3912012-12-16 00:45:3761 static void AttachTabHelpers(content::WebContents* contents) {
[email protected]e0bc75d52014-01-30 23:42:5962 TabHelpers::AttachTabHelpers(contents);
afakhry8394f942015-07-09 18:46:0963
64 // Make the tab show up in the task manager.
65 task_management::WebContentsTags::CreateForTabContents(contents);
[email protected]e232c992012-12-06 12:43:2066 }
67};
68
[email protected]8b0e9cc32010-11-09 04:00:1969namespace {
70
[email protected]8b0e9cc32010-11-09 04:00:1971// Returns true if the specified Browser can open tabs. Not all Browsers support
72// multiple tabs, such as app frames and popups. This function returns false for
73// those types of Browser.
74bool WindowCanOpenTabs(Browser* browser) {
75 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) ||
[email protected]c0849252012-05-12 13:51:2776 browser->tab_strip_model()->empty();
[email protected]8b0e9cc32010-11-09 04:00:1977}
78
79// Finds an existing Browser compatible with |profile|, making a new one if no
80// such Browser is located.
[email protected]3b14b7f22012-10-04 01:29:0981Browser* GetOrCreateBrowser(Profile* profile,
82 chrome::HostDesktopType host_desktop_type) {
[email protected]75072732013-01-09 13:39:2583 Browser* browser = chrome::FindTabbedBrowser(profile, false,
84 host_desktop_type);
[email protected]435d43e02012-12-09 09:13:5585 return browser ? browser : new Browser(
86 Browser::CreateParams(profile, host_desktop_type));
[email protected]8b0e9cc32010-11-09 04:00:1987}
88
[email protected]eca258132010-11-15 23:33:0889// Change some of the navigation parameters based on the particular URL.
[email protected]fc0ed302011-11-29 23:17:1990// Currently this applies to some chrome:// pages which we always want to open
91// in a non-incognito window. Note that even though a ChromeOS guest session is
92// technically an incognito window, these URLs are allowed.
[email protected]93ad8e1c2011-11-08 21:34:0593// Returns true on success. Otherwise, if changing params leads the browser into
94// an erroneous state, returns false.
[email protected]78e2edc2012-07-01 23:32:2895bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) {
[email protected]fc0ed302011-11-29 23:17:1996 if (params->target_contents != NULL ||
[email protected]887ab0092012-10-16 08:48:2097 chrome::IsURLAllowedInIncognito(params->url,
[email protected]e232c992012-12-06 12:43:2098 params->initiating_profile) ||
[email protected]10507b332012-12-13 22:37:3399 params->initiating_profile->IsGuestSession()) {
[email protected]fc0ed302011-11-29 23:17:19100 return true;
[email protected]eca258132010-11-15 23:33:08101 }
[email protected]fc0ed302011-11-29 23:17:19102
[email protected]8fb16a82012-08-17 02:17:59103 Profile* profile = params->initiating_profile;
[email protected]fc0ed302011-11-29 23:17:19104
105 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) {
106 profile = profile->GetOriginalProfile();
107
108 // If incognito is forced, we punt.
109 PrefService* prefs = profile->GetPrefs();
110 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
111 IncognitoModePrefs::FORCED) {
112 return false;
113 }
114
115 params->disposition = SINGLETON_TAB;
[email protected]0edcdec2013-10-31 06:43:08116 params->browser = GetOrCreateBrowser(profile, params->host_desktop_type);
[email protected]50592b52013-05-02 22:26:25117 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]fc0ed302011-11-29 23:17:19118 }
119
[email protected]93ad8e1c2011-11-08 21:34:05120 return true;
[email protected]eca258132010-11-15 23:33:08121}
122
[email protected]8b0e9cc32010-11-09 04:00:19123// Returns a Browser that can host the navigation or tab addition specified in
124// |params|. This might just return the same Browser specified in |params|, or
125// some other if that Browser is deemed incompatible.
[email protected]78e2edc2012-07-01 23:32:28126Browser* GetBrowserForDisposition(chrome::NavigateParams* params) {
[email protected]e232c992012-12-06 12:43:20127 // If no source WebContents was specified, we use the selected one from
[email protected]075969d2012-04-17 20:05:55128 // the target browser. This must happen first, before
129 // GetBrowserForDisposition() has a chance to replace |params->browser| with
130 // another one.
[email protected]59253a652012-11-20 00:17:26131 if (!params->source_contents && params->browser) {
132 params->source_contents =
[email protected]e232c992012-12-06 12:43:20133 params->browser->tab_strip_model()->GetActiveWebContents();
[email protected]59253a652012-11-20 00:17:26134 }
[email protected]8b0e9cc32010-11-09 04:00:19135
[email protected]8fb16a82012-08-17 02:17:59136 Profile* profile = params->initiating_profile;
[email protected]8b0e9cc32010-11-09 04:00:19137
138 switch (params->disposition) {
139 case CURRENT_TAB:
[email protected]8fb16a82012-08-17 02:17:59140 if (params->browser)
141 return params->browser;
142 // Find a compatible window and re-execute this command in it. Otherwise
143 // re-run with NEW_WINDOW.
[email protected]3b14b7f22012-10-04 01:29:09144 return GetOrCreateBrowser(profile, params->host_desktop_type);
[email protected]8b0e9cc32010-11-09 04:00:19145 case SINGLETON_TAB:
146 case NEW_FOREGROUND_TAB:
147 case NEW_BACKGROUND_TAB:
148 // See if we can open the tab in the window this navigator is bound to.
[email protected]8fb16a82012-08-17 02:17:59149 if (params->browser && WindowCanOpenTabs(params->browser))
[email protected]8b0e9cc32010-11-09 04:00:19150 return params->browser;
151 // Find a compatible window and re-execute this command in it. Otherwise
152 // re-run with NEW_WINDOW.
[email protected]3b14b7f22012-10-04 01:29:09153 return GetOrCreateBrowser(profile, params->host_desktop_type);
[email protected]8b0e9cc32010-11-09 04:00:19154 case NEW_POPUP: {
[email protected]b35b26b32011-05-05 20:35:14155 // Make a new popup window.
[email protected]d04f59d2012-07-13 23:07:52156 // Coerce app-style if |source| represents an app.
157 std::string app_name;
thestiga84d8e62014-10-17 22:27:55158#if defined(ENABLE_EXTENSIONS)
[email protected]d04f59d2012-07-13 23:07:52159 if (!params->extension_app_id.empty()) {
160 app_name = web_app::GenerateApplicationNameFromExtensionId(
161 params->extension_app_id);
[email protected]190e5e22013-07-27 05:59:23162 } else if (params->browser && !params->browser->app_name().empty()) {
[email protected]d04f59d2012-07-13 23:07:52163 app_name = params->browser->app_name();
[email protected]7381d9f2012-09-12 20:26:22164 } else if (params->source_contents) {
165 extensions::TabHelper* extensions_tab_helper =
[email protected]e232c992012-12-06 12:43:20166 extensions::TabHelper::FromWebContents(params->source_contents);
167 if (extensions_tab_helper && extensions_tab_helper->is_app()) {
[email protected]7381d9f2012-09-12 20:26:22168 app_name = web_app::GenerateApplicationNameFromExtensionId(
169 extensions_tab_helper->extension_app()->id());
170 }
[email protected]8b0e9cc32010-11-09 04:00:19171 }
thestiga84d8e62014-10-17 22:27:55172#endif
[email protected]d04f59d2012-07-13 23:07:52173 if (app_name.empty()) {
[email protected]435d43e02012-12-09 09:13:55174 Browser::CreateParams browser_params(
175 Browser::TYPE_POPUP, profile, params->host_desktop_type);
[email protected]d2202e22014-04-14 20:20:53176 browser_params.trusted_source = params->trusted_source;
[email protected]d04f59d2012-07-13 23:07:52177 browser_params.initial_bounds = params->window_bounds;
[email protected]a4fe67012012-07-25 20:14:29178 return new Browser(browser_params);
[email protected]d04f59d2012-07-13 23:07:52179 }
180
[email protected]a4fe67012012-07-25 20:14:29181 return new Browser(Browser::CreateParams::CreateForApp(
[email protected]d2202e22014-04-14 20:20:53182 app_name,
183 params->trusted_source,
184 params->window_bounds,
185 profile,
[email protected]2b09ae552013-02-23 06:38:03186 params->host_desktop_type));
[email protected]8b0e9cc32010-11-09 04:00:19187 }
[email protected]d04f59d2012-07-13 23:07:52188 case NEW_WINDOW: {
[email protected]8b0e9cc32010-11-09 04:00:19189 // Make a new normal browser window.
[email protected]435d43e02012-12-09 09:13:55190 return new Browser(Browser::CreateParams(profile,
191 params->host_desktop_type));
[email protected]d04f59d2012-07-13 23:07:52192 }
[email protected]8b0e9cc32010-11-09 04:00:19193 case OFF_THE_RECORD:
194 // Make or find an incognito window.
[email protected]3b14b7f22012-10-04 01:29:09195 return GetOrCreateBrowser(profile->GetOffTheRecordProfile(),
196 params->host_desktop_type);
[email protected]8b0e9cc32010-11-09 04:00:19197 // The following types all result in no navigation.
198 case SUPPRESS_OPEN:
199 case SAVE_TO_DISK:
200 case IGNORE_ACTION:
201 return NULL;
202 default:
203 NOTREACHED();
204 }
205 return NULL;
206}
207
208// Fix disposition and other parameter values depending on prevailing
209// conditions.
[email protected]78e2edc2012-07-01 23:32:28210void NormalizeDisposition(chrome::NavigateParams* params) {
[email protected]8b0e9cc32010-11-09 04:00:19211 // Calculate the WindowOpenDisposition if necessary.
[email protected]c0849252012-05-12 13:51:27212 if (params->browser->tab_strip_model()->empty() &&
[email protected]8b0e9cc32010-11-09 04:00:19213 (params->disposition == NEW_BACKGROUND_TAB ||
214 params->disposition == CURRENT_TAB ||
215 params->disposition == SINGLETON_TAB)) {
216 params->disposition = NEW_FOREGROUND_TAB;
217 }
218 if (params->browser->profile()->IsOffTheRecord() &&
219 params->disposition == OFF_THE_RECORD) {
220 params->disposition = NEW_FOREGROUND_TAB;
221 }
[email protected]688c792c2012-02-22 01:09:16222 if (!params->source_contents && params->disposition == CURRENT_TAB)
223 params->disposition = NEW_FOREGROUND_TAB;
[email protected]8b0e9cc32010-11-09 04:00:19224
[email protected]0b17b7d2010-11-17 17:39:58225 switch (params->disposition) {
226 case NEW_BACKGROUND_TAB:
[email protected]eaca0ad12011-04-18 15:53:41227 // Disposition trumps add types. ADD_ACTIVE is a default, so we need to
[email protected]0b17b7d2010-11-17 17:39:58228 // remove it if disposition implies the tab is going to open in the
229 // background.
[email protected]eaca0ad12011-04-18 15:53:41230 params->tabstrip_add_types &= ~TabStripModel::ADD_ACTIVE;
[email protected]0b17b7d2010-11-17 17:39:58231 break;
[email protected]8b0e9cc32010-11-09 04:00:19232
[email protected]0b17b7d2010-11-17 17:39:58233 case NEW_WINDOW:
234 case NEW_POPUP:
235 // Code that wants to open a new window typically expects it to be shown
236 // automatically.
[email protected]78e2edc2012-07-01 23:32:28237 if (params->window_action == chrome::NavigateParams::NO_ACTION)
238 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]0b17b7d2010-11-17 17:39:58239 // Fall-through.
240 case NEW_FOREGROUND_TAB:
241 case SINGLETON_TAB:
[email protected]eaca0ad12011-04-18 15:53:41242 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE;
[email protected]0b17b7d2010-11-17 17:39:58243 break;
244
245 default:
246 break;
[email protected]8b0e9cc32010-11-09 04:00:19247 }
248}
249
[email protected]d7ff3592010-11-30 21:50:46250// Obtain the profile used by the code that originated the Navigate() request.
[email protected]8fb16a82012-08-17 02:17:59251Profile* GetSourceProfile(chrome::NavigateParams* params) {
[email protected]e232c992012-12-06 12:43:20252 if (params->source_contents) {
253 return Profile::FromBrowserContext(
254 params->source_contents->GetBrowserContext());
255 }
[email protected]d7ff3592010-11-30 21:50:46256
[email protected]8fb16a82012-08-17 02:17:59257 return params->initiating_profile;
[email protected]d7ff3592010-11-30 21:50:46258}
259
[email protected]6acde6352012-01-04 16:52:20260void LoadURLInContents(WebContents* target_contents,
[email protected]4ad5d77d2011-12-03 02:00:48261 const GURL& url,
[email protected]72ea827d2012-09-28 01:30:55262 chrome::NavigateParams* params) {
[email protected]a2efc35d2013-08-03 23:17:25263 NavigationController::LoadURLParams load_url_params(url);
lfg9ef7d2d2014-12-15 22:32:30264 load_url_params.source_site_instance = params->source_site_instance;
[email protected]cf002332012-08-14 19:17:47265 load_url_params.referrer = params->referrer;
[email protected]c80297782013-11-21 07:10:16266 load_url_params.frame_tree_node_id = params->frame_tree_node_id;
[email protected]f8872902013-10-30 03:18:57267 load_url_params.redirect_chain = params->redirect_chain;
[email protected]cf002332012-08-14 19:17:47268 load_url_params.transition_type = params->transition;
[email protected]72ea827d2012-09-28 01:30:55269 load_url_params.extra_headers = params->extra_headers;
[email protected]866fa2cc2013-07-22 22:19:52270 load_url_params.should_replace_current_entry =
271 params->should_replace_current_entry;
[email protected]4ad5d77d2011-12-03 02:00:48272
[email protected]cf002332012-08-14 19:17:47273 if (params->transferred_global_request_id != GlobalRequestID()) {
274 load_url_params.is_renderer_initiated = params->is_renderer_initiated;
275 load_url_params.transferred_global_request_id =
276 params->transferred_global_request_id;
277 } else if (params->is_renderer_initiated) {
278 load_url_params.is_renderer_initiated = true;
279 }
[email protected]a2efc35d2013-08-03 23:17:25280
281 // Only allows the browser-initiated navigation to use POST.
282 if (params->uses_post && !params->is_renderer_initiated) {
283 load_url_params.load_type =
284 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
285 load_url_params.browser_initiated_post_data =
286 params->browser_initiated_post_data;
287 }
[email protected]cf002332012-08-14 19:17:47288 target_contents->GetController().LoadURLWithParams(load_url_params);
[email protected]4ad5d77d2011-12-03 02:00:48289}
[email protected]d7ff3592010-11-30 21:50:46290
[email protected]8b0e9cc32010-11-09 04:00:19291// This class makes sure the Browser object held in |params| is made visible
292// by the time it goes out of scope, provided |params| wants it to be shown.
[email protected]0edcdec2013-10-31 06:43:08293class ScopedBrowserShower {
[email protected]8b0e9cc32010-11-09 04:00:19294 public:
[email protected]0edcdec2013-10-31 06:43:08295 explicit ScopedBrowserShower(chrome::NavigateParams* params)
[email protected]8b0e9cc32010-11-09 04:00:19296 : params_(params) {
297 }
[email protected]0edcdec2013-10-31 06:43:08298 ~ScopedBrowserShower() {
stevenjba92701cc2014-09-29 23:41:12299 if (params_->window_action ==
300 chrome::NavigateParams::SHOW_WINDOW_INACTIVE) {
[email protected]7d329992011-04-15 18:20:02301 params_->browser->window()->ShowInactive();
stevenjba92701cc2014-09-29 23:41:12302 } else if (params_->window_action == chrome::NavigateParams::SHOW_WINDOW) {
[email protected]8b0e9cc32010-11-09 04:00:19303 params_->browser->window()->Show();
stevenjba92701cc2014-09-29 23:41:12304 // If a user gesture opened a popup window, focus the contents.
305 if (params_->user_gesture && params_->disposition == NEW_POPUP &&
306 params_->target_contents) {
307 params_->target_contents->Focus();
308 }
309 }
[email protected]8b0e9cc32010-11-09 04:00:19310 }
stevenjba92701cc2014-09-29 23:41:12311
[email protected]8b0e9cc32010-11-09 04:00:19312 private:
[email protected]78e2edc2012-07-01 23:32:28313 chrome::NavigateParams* params_;
[email protected]0edcdec2013-10-31 06:43:08314 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserShower);
[email protected]8b0e9cc32010-11-09 04:00:19315};
316
[email protected]e232c992012-12-06 12:43:20317// This class manages the lifetime of a WebContents created by the
318// Navigate() function. When Navigate() creates a WebContents for a URL,
[email protected]075969d2012-04-17 20:05:55319// an instance of this class takes ownership of it via TakeOwnership() until the
[email protected]e232c992012-12-06 12:43:20320// WebContents is added to a tab strip at which time ownership is
[email protected]075969d2012-04-17 20:05:55321// relinquished via ReleaseOwnership(). If this object goes out of scope without
[email protected]e232c992012-12-06 12:43:20322// being added to a tab strip, the created WebContents is deleted to
[email protected]075969d2012-04-17 20:05:55323// avoid a leak and the params->target_contents field is set to NULL.
[email protected]8b0e9cc32010-11-09 04:00:19324class ScopedTargetContentsOwner {
325 public:
[email protected]78e2edc2012-07-01 23:32:28326 explicit ScopedTargetContentsOwner(chrome::NavigateParams* params)
[email protected]8b0e9cc32010-11-09 04:00:19327 : params_(params) {
328 }
329 ~ScopedTargetContentsOwner() {
330 if (target_contents_owner_.get())
331 params_->target_contents = NULL;
332 }
333
334 // Assumes ownership of |params_|' target_contents until ReleaseOwnership
335 // is called.
336 void TakeOwnership() {
337 target_contents_owner_.reset(params_->target_contents);
338 }
339
340 // Relinquishes ownership of |params_|' target_contents.
[email protected]e232c992012-12-06 12:43:20341 WebContents* ReleaseOwnership() {
[email protected]8b0e9cc32010-11-09 04:00:19342 return target_contents_owner_.release();
343 }
344
345 private:
[email protected]78e2edc2012-07-01 23:32:28346 chrome::NavigateParams* params_;
[email protected]e232c992012-12-06 12:43:20347 scoped_ptr<WebContents> target_contents_owner_;
[email protected]8b0e9cc32010-11-09 04:00:19348 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
349};
350
[email protected]0c9406632013-02-08 01:13:33351content::WebContents* CreateTargetContents(const chrome::NavigateParams& params,
352 const GURL& url) {
353 WebContents::CreateParams create_params(
354 params.browser->profile(),
355 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url));
356 if (params.source_contents) {
357 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45358 params.source_contents->GetContainerBounds().size();
alexmos090fae8e2015-05-28 17:09:28359 create_params.created_with_opener = params.created_with_opener;
[email protected]0c9406632013-02-08 01:13:33360 }
[email protected]1ac10dca2013-08-20 20:47:04361 if (params.disposition == NEW_BACKGROUND_TAB)
362 create_params.initially_hidden = true;
363
[email protected]0c9406632013-02-08 01:13:33364#if defined(USE_AURA)
365 if (params.browser->window() &&
366 params.browser->window()->GetNativeWindow()) {
367 create_params.context =
368 params.browser->window()->GetNativeWindow();
369 }
370#endif
371
[email protected]2188b012013-08-01 21:49:15372 WebContents* target_contents = WebContents::Create(create_params);
373
[email protected]0c9406632013-02-08 01:13:33374 // New tabs can have WebUI URLs that will make calls back to arbitrary
375 // tab helpers, so the entire set of tab helpers needs to be set up
376 // immediately.
377 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents);
thestiga84d8e62014-10-17 22:27:55378#if defined(ENABLE_EXTENSIONS)
[email protected]0c9406632013-02-08 01:13:33379 extensions::TabHelper::FromWebContents(target_contents)->
380 SetExtensionAppById(params.extension_app_id);
thestiga84d8e62014-10-17 22:27:55381#endif
[email protected]0c9406632013-02-08 01:13:33382 return target_contents;
383}
384
[email protected]2c13a4c2013-10-21 21:55:31385// If a prerendered page exists for |url|, replace the page at
386// |params->target_contents| with it and update to point to the swapped-in
387// WebContents.
388bool SwapInPrerender(const GURL& url, chrome::NavigateParams* params) {
[email protected]a1558992013-12-12 20:52:16389 Profile* profile =
390 Profile::FromBrowserContext(params->target_contents->GetBrowserContext());
391 InstantSearchPrerenderer* prerenderer =
392 InstantSearchPrerenderer::GetForProfile(profile);
393 if (prerenderer && prerenderer->UsePrerenderedPage(url, params))
394 return true;
395
[email protected]a0358d72012-03-09 14:06:50396 prerender::PrerenderManager* prerender_manager =
[email protected]a1558992013-12-12 20:52:16397 prerender::PrerenderManagerFactory::GetForProfile(profile);
[email protected]36ab69d2012-04-06 18:24:54398 return prerender_manager &&
[email protected]2c13a4c2013-10-21 21:55:31399 prerender_manager->MaybeUsePrerenderedPage(url, params);
[email protected]a0358d72012-03-09 14:06:50400}
401
[email protected]44e11ab2013-07-03 02:36:44402chrome::HostDesktopType GetHostDesktop(Browser* browser) {
403 if (browser)
404 return browser->host_desktop_type();
405 return chrome::GetActiveDesktop();
406}
407
[email protected]8b0e9cc32010-11-09 04:00:19408} // namespace
409
[email protected]78e2edc2012-07-01 23:32:28410namespace chrome {
[email protected]8b0e9cc32010-11-09 04:00:19411
[email protected]78e2edc2012-07-01 23:32:28412NavigateParams::NavigateParams(Browser* a_browser,
413 const GURL& a_url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35414 ui::PageTransition a_transition)
[email protected]8b0e9cc32010-11-09 04:00:19415 : url(a_url),
[email protected]c80297782013-11-21 07:10:16416 frame_tree_node_id(-1),
[email protected]a2efc35d2013-08-03 23:17:25417 uses_post(false),
[email protected]8b0e9cc32010-11-09 04:00:19418 target_contents(NULL),
419 source_contents(NULL),
420 disposition(CURRENT_TAB),
[email protected]d2202e22014-04-14 20:20:53421 trusted_source(false),
[email protected]8b0e9cc32010-11-09 04:00:19422 transition(a_transition),
[email protected]ff4330a2011-10-14 21:11:02423 is_renderer_initiated(false),
[email protected]8b0e9cc32010-11-09 04:00:19424 tabstrip_index(-1),
[email protected]eaca0ad12011-04-18 15:53:41425 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
[email protected]7d329992011-04-15 18:20:02426 window_action(NO_ACTION),
[email protected]588300d2011-04-28 21:06:35427 user_gesture(true),
[email protected]fee320542011-03-02 01:30:49428 path_behavior(RESPECT),
[email protected]578c6962011-08-24 22:06:40429 ref_behavior(IGNORE_REF),
[email protected]8fb16a82012-08-17 02:17:59430 browser(a_browser),
[email protected]e2caa032012-11-15 23:29:18431 initiating_profile(NULL),
[email protected]44e11ab2013-07-03 02:36:44432 host_desktop_type(GetHostDesktop(a_browser)),
[email protected]2188b012013-08-01 21:49:15433 should_replace_current_entry(false),
alexmos090fae8e2015-05-28 17:09:28434 created_with_opener(false) {
[email protected]44e11ab2013-07-03 02:36:44435}
[email protected]8b0e9cc32010-11-09 04:00:19436
437NavigateParams::NavigateParams(Browser* a_browser,
[email protected]e232c992012-12-06 12:43:20438 WebContents* a_target_contents)
[email protected]c80297782013-11-21 07:10:16439 : frame_tree_node_id(-1),
440 uses_post(false),
[email protected]a2efc35d2013-08-03 23:17:25441 target_contents(a_target_contents),
[email protected]8b0e9cc32010-11-09 04:00:19442 source_contents(NULL),
443 disposition(CURRENT_TAB),
[email protected]d2202e22014-04-14 20:20:53444 trusted_source(false),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35445 transition(ui::PAGE_TRANSITION_LINK),
[email protected]ff4330a2011-10-14 21:11:02446 is_renderer_initiated(false),
[email protected]8b0e9cc32010-11-09 04:00:19447 tabstrip_index(-1),
[email protected]eaca0ad12011-04-18 15:53:41448 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
[email protected]7d329992011-04-15 18:20:02449 window_action(NO_ACTION),
[email protected]588300d2011-04-28 21:06:35450 user_gesture(true),
[email protected]fee320542011-03-02 01:30:49451 path_behavior(RESPECT),
[email protected]578c6962011-08-24 22:06:40452 ref_behavior(IGNORE_REF),
[email protected]8fb16a82012-08-17 02:17:59453 browser(a_browser),
[email protected]e2caa032012-11-15 23:29:18454 initiating_profile(NULL),
[email protected]44e11ab2013-07-03 02:36:44455 host_desktop_type(GetHostDesktop(a_browser)),
[email protected]2188b012013-08-01 21:49:15456 should_replace_current_entry(false),
alexmos090fae8e2015-05-28 17:09:28457 created_with_opener(false) {
[email protected]44e11ab2013-07-03 02:36:44458}
[email protected]8b0e9cc32010-11-09 04:00:19459
[email protected]8fb16a82012-08-17 02:17:59460NavigateParams::NavigateParams(Profile* a_profile,
461 const GURL& a_url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35462 ui::PageTransition a_transition)
[email protected]8fb16a82012-08-17 02:17:59463 : url(a_url),
[email protected]c80297782013-11-21 07:10:16464 frame_tree_node_id(-1),
[email protected]a2efc35d2013-08-03 23:17:25465 uses_post(false),
[email protected]8fb16a82012-08-17 02:17:59466 target_contents(NULL),
467 source_contents(NULL),
468 disposition(NEW_FOREGROUND_TAB),
[email protected]d2202e22014-04-14 20:20:53469 trusted_source(false),
[email protected]8fb16a82012-08-17 02:17:59470 transition(a_transition),
471 is_renderer_initiated(false),
472 tabstrip_index(-1),
473 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
[email protected]50592b52013-05-02 22:26:25474 window_action(SHOW_WINDOW),
[email protected]8fb16a82012-08-17 02:17:59475 user_gesture(true),
476 path_behavior(RESPECT),
477 ref_behavior(IGNORE_REF),
478 browser(NULL),
[email protected]3b14b7f22012-10-04 01:29:09479 initiating_profile(a_profile),
[email protected]44e11ab2013-07-03 02:36:44480 host_desktop_type(chrome::GetActiveDesktop()),
[email protected]2188b012013-08-01 21:49:15481 should_replace_current_entry(false),
alexmos090fae8e2015-05-28 17:09:28482 created_with_opener(false) {
[email protected]44e11ab2013-07-03 02:36:44483}
[email protected]8fb16a82012-08-17 02:17:59484
485NavigateParams::~NavigateParams() {}
[email protected]8b0e9cc32010-11-09 04:00:19486
[email protected]19c64142013-03-06 20:08:53487void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params,
488 const content::OpenURLParams& params) {
489 nav_params->referrer = params.referrer;
lfg9ef7d2d2014-12-15 22:32:30490 nav_params->source_site_instance = params.source_site_instance;
[email protected]c80297782013-11-21 07:10:16491 nav_params->frame_tree_node_id = params.frame_tree_node_id;
[email protected]f8872902013-10-30 03:18:57492 nav_params->redirect_chain = params.redirect_chain;
[email protected]19c64142013-03-06 20:08:53493 nav_params->extra_headers = params.extra_headers;
494 nav_params->disposition = params.disposition;
[email protected]d2202e22014-04-14 20:20:53495 nav_params->trusted_source = false;
[email protected]19c64142013-03-06 20:08:53496 nav_params->is_renderer_initiated = params.is_renderer_initiated;
497 nav_params->transferred_global_request_id =
498 params.transferred_global_request_id;
[email protected]866fa2cc2013-07-22 22:19:52499 nav_params->should_replace_current_entry =
500 params.should_replace_current_entry;
[email protected]a2efc35d2013-08-03 23:17:25501 nav_params->uses_post = params.uses_post;
502 nav_params->browser_initiated_post_data = params.browser_initiated_post_data;
[email protected]19c64142013-03-06 20:08:53503}
504
[email protected]8b0e9cc32010-11-09 04:00:19505void Navigate(NavigateParams* params) {
[email protected]d7ff3592010-11-30 21:50:46506 Browser* source_browser = params->browser;
[email protected]8fb16a82012-08-17 02:17:59507 if (source_browser)
508 params->initiating_profile = source_browser->profile();
509 DCHECK(params->initiating_profile);
[email protected]93ad8e1c2011-11-08 21:34:05510
511 if (!AdjustNavigateParamsForURL(params))
512 return;
[email protected]eca258132010-11-15 23:33:08513
thestig2dbee717e2014-09-05 14:54:28514#if defined(ENABLE_EXTENSIONS)
[email protected]bfaf3d92014-03-19 06:43:51515 const extensions::Extension* extension =
516 extensions::ExtensionRegistry::Get(params->initiating_profile)->
517 enabled_extensions().GetExtensionOrAppByURL(params->url);
518 // Platform apps cannot navigate. Block the request.
519 if (extension && extension->is_platform_app())
520 params->url = GURL(chrome::kExtensionInvalidRequestURL);
thestig2dbee717e2014-09-05 14:54:28521#endif
[email protected]4d007b312012-10-17 03:00:48522
[email protected]4a5b1722012-05-04 21:16:04523 // The browser window may want to adjust the disposition.
[email protected]8fb16a82012-08-17 02:17:59524 if (params->disposition == NEW_POPUP &&
525 source_browser &&
526 source_browser->window()) {
[email protected]588300d2011-04-28 21:06:35527 params->disposition =
528 source_browser->window()->GetDispositionForPopupBounds(
529 params->window_bounds);
530 }
531
[email protected]8b0e9cc32010-11-09 04:00:19532 params->browser = GetBrowserForDisposition(params);
[email protected]9522ddf2011-10-07 19:12:11533 if (!params->browser)
[email protected]8b0e9cc32010-11-09 04:00:19534 return;
[email protected]9522ddf2011-10-07 19:12:11535
[email protected]ad4c2d32013-12-06 12:59:26536#if defined(USE_ASH)
537 if (source_browser && source_browser != params->browser) {
538 // When the newly created browser was spawned by a browser which visits
539 // another user's desktop, it should be shown on the same desktop as the
540 // originating one. (This is part of the desktop separation per profile).
541 MultiUserWindowManager* manager = MultiUserWindowManager::GetInstance();
542 // Some unit tests have no manager instantiated.
543 if (manager) {
544 aura::Window* src_window = source_browser->window()->GetNativeWindow();
545 aura::Window* new_window = params->browser->window()->GetNativeWindow();
546 const std::string& src_user =
547 manager->GetUserPresentingWindow(src_window);
548 if (src_user != manager->GetUserPresentingWindow(new_window)) {
549 // Once the window gets presented, it should be shown on the same
550 // desktop as the desktop of the creating browser. Note that this
551 // command will not show the window if it wasn't shown yet by the
552 // browser creation.
553 manager->ShowWindowForUser(new_window, src_user);
554 }
555 }
556 }
557#endif
558
[email protected]8b0e9cc32010-11-09 04:00:19559 // Navigate() must not return early after this point.
560
[email protected]8fb16a82012-08-17 02:17:59561 if (GetSourceProfile(params) != params->browser->profile()) {
[email protected]d7ff3592010-11-30 21:50:46562 // A tab is being opened from a link from a different profile, we must reset
563 // source information that may cause state to be shared.
564 params->source_contents = NULL;
[email protected]cb8fb01a2011-12-05 21:01:14565 params->referrer = content::Referrer();
[email protected]d7ff3592010-11-30 21:50:46566 }
567
[email protected]8b0e9cc32010-11-09 04:00:19568 // Make sure the Browser is shown if params call for it.
[email protected]0edcdec2013-10-31 06:43:08569 ScopedBrowserShower shower(params);
[email protected]8b0e9cc32010-11-09 04:00:19570
[email protected]e232c992012-12-06 12:43:20571 // Makes sure any WebContents created by this function is destroyed if
[email protected]8b0e9cc32010-11-09 04:00:19572 // not properly added to a tab strip.
573 ScopedTargetContentsOwner target_contents_owner(params);
574
575 // Some dispositions need coercion to base types.
576 NormalizeDisposition(params);
577
[email protected]0edcdec2013-10-31 06:43:08578 // If a new window has been created, it needs to be shown.
[email protected]78e2edc2012-07-01 23:32:28579 if (params->window_action == NavigateParams::NO_ACTION &&
[email protected]588300d2011-04-28 21:06:35580 source_browser != params->browser &&
[email protected]c0849252012-05-12 13:51:27581 params->browser->tab_strip_model()->empty()) {
[email protected]78e2edc2012-07-01 23:32:28582 params->window_action = NavigateParams::SHOW_WINDOW;
[email protected]588300d2011-04-28 21:06:35583 }
584
585 // If we create a popup window from a non user-gesture, don't activate it.
[email protected]78e2edc2012-07-01 23:32:28586 if (params->window_action == NavigateParams::SHOW_WINDOW &&
[email protected]588300d2011-04-28 21:06:35587 params->disposition == NEW_POPUP &&
588 params->user_gesture == false) {
[email protected]78e2edc2012-07-01 23:32:28589 params->window_action = NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]588300d2011-04-28 21:06:35590 }
591
[email protected]8b0e9cc32010-11-09 04:00:19592 // Determine if the navigation was user initiated. If it was, we need to
[email protected]e232c992012-12-06 12:43:20593 // inform the target WebContents, and we may need to update the UI.
Sylvain Defresnec6ccc77d2014-09-19 10:19:35594 ui::PageTransition base_transition =
595 ui::PageTransitionStripQualifier(params->transition);
[email protected]2905f742011-10-13 03:51:58596 bool user_initiated =
Sylvain Defresnec6ccc77d2014-09-19 10:19:35597 params->transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR ||
598 base_transition == ui::PAGE_TRANSITION_TYPED ||
599 base_transition == ui::PAGE_TRANSITION_AUTO_BOOKMARK ||
600 base_transition == ui::PAGE_TRANSITION_GENERATED ||
601 base_transition == ui::PAGE_TRANSITION_AUTO_TOPLEVEL ||
602 base_transition == ui::PAGE_TRANSITION_RELOAD ||
603 base_transition == ui::PAGE_TRANSITION_KEYWORD;
[email protected]8b0e9cc32010-11-09 04:00:19604
[email protected]fa7ebe02010-11-29 23:04:57605 // Check if this is a singleton tab that already exists
[email protected]5d9cace72012-06-21 16:07:12606 int singleton_index = chrome::GetIndexOfSingletonTab(params);
[email protected]fa7ebe02010-11-29 23:04:57607
[email protected]777590052014-01-17 22:11:54608 // Did we use a prerender?
609 bool swapped_in_prerender = false;
[email protected]0c9406632013-02-08 01:13:33610
[email protected]e232c992012-12-06 12:43:20611 // If no target WebContents was specified, we need to construct one if
[email protected]075969d2012-04-17 20:05:55612 // we are supposed to target a new tab; unless it's a singleton that already
613 // exists.
[email protected]fa7ebe02010-11-29 23:04:57614 if (!params->target_contents && singleton_index < 0) {
[email protected]f5ec3c922014-05-22 15:04:03615 DCHECK(!params->url.is_empty());
[email protected]8b0e9cc32010-11-09 04:00:19616 if (params->disposition != CURRENT_TAB) {
[email protected]f5ec3c922014-05-22 15:04:03617 params->target_contents = CreateTargetContents(*params, params->url);
[email protected]0c9406632013-02-08 01:13:33618
[email protected]8b0e9cc32010-11-09 04:00:19619 // This function takes ownership of |params->target_contents| until it
620 // is added to a TabStripModel.
621 target_contents_owner.TakeOwnership();
[email protected]8b0e9cc32010-11-09 04:00:19622 } else {
623 // ... otherwise if we're loading in the current tab, the target is the
624 // same as the source.
[email protected]0c9406632013-02-08 01:13:33625 DCHECK(params->source_contents);
[email protected]777590052014-01-17 22:11:54626 params->target_contents = params->source_contents;
[email protected]8b0e9cc32010-11-09 04:00:19627
davidben1f9befb2015-01-14 18:14:05628 // Prerender can only swap in CURRENT_TAB navigations; others have
629 // different sessionStorage namespaces.
630 swapped_in_prerender = SwapInPrerender(params->url, params);
631 }
[email protected]a5f730d52014-05-14 01:09:22632
[email protected]e35ccd52012-05-23 16:22:47633 if (user_initiated)
[email protected]e232c992012-12-06 12:43:20634 params->target_contents->UserGestureDone();
[email protected]8b0e9cc32010-11-09 04:00:19635
[email protected]777590052014-01-17 22:11:54636 if (!swapped_in_prerender) {
[email protected]0c9406632013-02-08 01:13:33637 // Try to handle non-navigational URLs that popup dialogs and such, these
638 // should not actually navigate.
[email protected]f5ec3c922014-05-22 15:04:03639 if (!HandleNonNavigationAboutURL(params->url)) {
[email protected]0c9406632013-02-08 01:13:33640 // Perform the actual navigation, tracking whether it came from the
641 // renderer.
[email protected]4ad5d77d2011-12-03 02:00:48642
[email protected]f5ec3c922014-05-22 15:04:03643 LoadURLInContents(params->target_contents, params->url, params);
[email protected]0c9406632013-02-08 01:13:33644 }
[email protected]2f89b602011-06-01 05:49:17645 }
[email protected]8b0e9cc32010-11-09 04:00:19646 } else {
647 // |target_contents| was specified non-NULL, and so we assume it has already
648 // been navigated appropriately. We need to do nothing more other than
649 // add it to the appropriate tabstrip.
650 }
651
[email protected]26c53e662011-07-09 02:21:02652 // If the user navigated from the omnibox, and the selected tab is going to
653 // lose focus, then make sure the focus for the source tab goes away from the
654 // omnibox.
655 if (params->source_contents &&
656 (params->disposition == NEW_FOREGROUND_TAB ||
657 params->disposition == NEW_WINDOW) &&
658 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER))
[email protected]fc2b46b2014-05-03 16:33:45659 params->source_contents->Focus();
[email protected]26c53e662011-07-09 02:21:02660
[email protected]0c9406632013-02-08 01:13:33661 if (params->source_contents == params->target_contents ||
[email protected]777590052014-01-17 22:11:54662 (swapped_in_prerender && params->disposition == CURRENT_TAB)) {
[email protected]3c9e1872010-11-18 16:17:49663 // The navigation occurred in the source tab.
[email protected]e232c992012-12-06 12:43:20664 params->browser->UpdateUIForNavigationInTab(params->target_contents,
665 params->transition,
666 user_initiated);
[email protected]637b3442011-01-10 23:31:48667 } else if (singleton_index == -1) {
668 // If some non-default value is set for the index, we should tell the
669 // TabStripModel to respect it.
670 if (params->tabstrip_index != -1)
671 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX;
[email protected]bb89e7482010-11-17 18:27:04672
[email protected]637b3442011-01-10 23:31:48673 // The navigation should insert a new tab into the target Browser.
[email protected]ee9b0cb2012-11-29 20:56:17674 params->browser->tab_strip_model()->AddWebContents(
[email protected]e232c992012-12-06 12:43:20675 params->target_contents,
[email protected]637b3442011-01-10 23:31:48676 params->tabstrip_index,
677 params->transition,
678 params->tabstrip_add_types);
679 // Now that the |params->target_contents| is safely owned by the target
680 // Browser's TabStripModel, we can release ownership.
681 target_contents_owner.ReleaseOwnership();
682 }
[email protected]bb89e7482010-11-17 18:27:04683
[email protected]637b3442011-01-10 23:31:48684 if (singleton_index >= 0) {
[email protected]52877dbc62012-06-29 22:22:03685 WebContents* target =
[email protected]e232c992012-12-06 12:43:20686 params->browser->tab_strip_model()->GetWebContentsAt(singleton_index);
[email protected]8b0e9cc32010-11-09 04:00:19687
[email protected]be1f56ab2011-12-22 06:55:31688 if (target->IsCrashed()) {
[email protected]f5fa20e2011-12-21 22:35:56689 target->GetController().Reload(true);
[email protected]7de53c62011-05-13 06:44:16690 } else if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE &&
[email protected]fee320542011-03-02 01:30:49691 target->GetURL() != params->url) {
[email protected]72ea827d2012-09-28 01:30:55692 LoadURLInContents(target, params->url, params);
[email protected]8b0e9cc32010-11-09 04:00:19693 }
[email protected]637b3442011-01-10 23:31:48694
695 // If the singleton tab isn't already selected, select it.
[email protected]57892182012-12-03 19:15:39696 if (params->source_contents != params->target_contents) {
697 params->browser->tab_strip_model()->ActivateTabAt(singleton_index,
698 user_initiated);
699 }
[email protected]8b0e9cc32010-11-09 04:00:19700 }
[email protected]0548c5352011-09-07 00:33:33701
702 if (params->disposition != CURRENT_TAB) {
[email protected]ad50def52011-10-19 23:17:07703 content::NotificationService::current()->Notify(
[email protected]884033e2012-04-16 19:38:42704 chrome::NOTIFICATION_TAB_ADDED,
[email protected]674bc592011-12-20 23:00:42705 content::Source<content::WebContentsDelegate>(params->browser),
[email protected]e232c992012-12-06 12:43:20706 content::Details<WebContents>(params->target_contents));
[email protected]0548c5352011-09-07 00:33:33707 }
[email protected]8b0e9cc32010-11-09 04:00:19708}
709
[email protected]887ab0092012-10-16 08:48:20710bool IsURLAllowedInIncognito(const GURL& url,
711 content::BrowserContext* browser_context) {
[email protected]dbdda5402013-05-30 22:13:48712 if (url.scheme() == content::kViewSourceScheme) {
[email protected]429e9712013-04-30 09:35:50713 // A view-source URL is allowed in incognito mode only if the URL itself
714 // is allowed in incognito mode. Remove the "view-source:" from the start
715 // of the URL and validate the rest.
716 std::string stripped_spec = url.spec();
[email protected]dbdda5402013-05-30 22:13:48717 DCHECK_GT(stripped_spec.size(), strlen(content::kViewSourceScheme));
718 stripped_spec.erase(0, strlen(content::kViewSourceScheme) + 1);
[email protected]429e9712013-04-30 09:35:50719 GURL stripped_url(stripped_spec);
720 return stripped_url.is_valid() &&
721 IsURLAllowedInIncognito(stripped_url, browser_context);
722 }
[email protected]fc0ed302011-11-29 23:17:19723 // Most URLs are allowed in incognito; the following are exceptions.
724 // chrome://extensions is on the list because it redirects to
725 // chrome://settings.
[email protected]2d9748b22014-02-11 00:17:29726 if (url.scheme() == content::kChromeUIScheme &&
[email protected]130b48e02011-10-14 15:48:19727 (url.host() == chrome::kChromeUISettingsHost ||
[email protected]846c3ecea2011-12-14 18:47:26728 url.host() == chrome::kChromeUISettingsFrameHost ||
michaelpg3dadf61a2014-11-04 23:05:36729 url.host() == chrome::kChromeUIHelpHost ||
[email protected]130b48e02011-10-14 15:48:19730 url.host() == chrome::kChromeUIExtensionsHost ||
[email protected]fc0ed302011-11-29 23:17:19731 url.host() == chrome::kChromeUIBookmarksHost ||
[email protected]aed04982014-01-14 00:50:45732#if !defined(OS_CHROMEOS)
733 url.host() == chrome::kChromeUIChromeSigninHost ||
734#endif
[email protected]89e1466e2013-10-22 15:47:18735 url.host() == chrome::kChromeUIUberHost ||
736 url.host() == chrome::kChromeUIThumbnailHost ||
737 url.host() == chrome::kChromeUIThumbnailHost2 ||
[email protected]ae16fc332014-02-25 02:14:08738 url.host() == chrome::kChromeUIThumbnailListHost ||
[email protected]09bb43a2014-04-15 04:39:02739 url.host() == chrome::kChromeUISuggestionsHost ||
[email protected]98a92442014-08-08 09:53:06740 url.host() == chrome::kChromeUIDevicesHost ||
741 url.host() == chrome::kChromeUIVoiceSearchHost)) {
[email protected]89e1466e2013-10-22 15:47:18742 return false;
743 }
744
745 if (url.scheme() == chrome::kChromeSearchScheme &&
746 (url.host() == chrome::kChromeUIThumbnailHost ||
747 url.host() == chrome::kChromeUIThumbnailHost2 ||
[email protected]ae16fc332014-02-25 02:14:08748 url.host() == chrome::kChromeUIThumbnailListHost ||
749 url.host() == chrome::kChromeUISuggestionsHost)) {
[email protected]887ab0092012-10-16 08:48:20750 return false;
751 }
752
753 GURL rewritten_url = url;
754 bool reverse_on_redirect = false;
755 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
756 &rewritten_url, browser_context, &reverse_on_redirect);
757
758 // Some URLs are mapped to uber subpages. Do not allow them in incognito.
[email protected]2d9748b22014-02-11 00:17:29759 return !(rewritten_url.scheme() == content::kChromeUIScheme &&
[email protected]887ab0092012-10-16 08:48:20760 rewritten_url.host() == chrome::kChromeUIUberHost);
[email protected]130b48e02011-10-14 15:48:19761}
762
[email protected]78e2edc2012-07-01 23:32:28763} // namespace chrome