OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/browser_url_handler.h" | 10 #include "chrome/browser/browser_url_handler.h" |
11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
12 #include "chrome/browser/location_bar.h" | 12 #include "chrome/browser/location_bar.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/renderer_host/site_instance.h" | 14 #include "chrome/browser/renderer_host/site_instance.h" |
15 #include "chrome/browser/status_bubble.h" | 15 #include "chrome/browser/status_bubble.h" |
16 #include "chrome/browser/tabs/tab_strip_model.h" | 16 #include "chrome/browser/tabs/tab_strip_model.h" |
17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/url_constants.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Returns the SiteInstance for |source_contents| if it represents the same | 23 // Returns the SiteInstance for |source_contents| if it represents the same |
23 // website as |url|, or NULL otherwise. |source_contents| cannot be NULL. | 24 // website as |url|, or NULL otherwise. |source_contents| cannot be NULL. |
24 SiteInstance* GetSiteInstance(TabContents* source_contents, const GURL& url) { | 25 SiteInstance* GetSiteInstance(TabContents* source_contents, const GURL& url) { |
25 if (!source_contents) | 26 if (!source_contents) |
26 return NULL; | 27 return NULL; |
27 | 28 |
28 // Don't use this logic when "--process-per-tab" is specified. | 29 // Don't use this logic when "--process-per-tab" is specified. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 TabContents* tab = params->browser->GetTabContentsAt(i); | 88 TabContents* tab = params->browser->GetTabContentsAt(i); |
88 if (CompareURLsIgnoreRef(tab->GetURL(), params->url) || | 89 if (CompareURLsIgnoreRef(tab->GetURL(), params->url) || |
89 CompareURLsIgnoreRef(tab->GetURL(), rewritten_url)) { | 90 CompareURLsIgnoreRef(tab->GetURL(), rewritten_url)) { |
90 params->target_contents = tab; | 91 params->target_contents = tab; |
91 return i; | 92 return i; |
92 } | 93 } |
93 } | 94 } |
94 return -1; | 95 return -1; |
95 } | 96 } |
96 | 97 |
| 98 // Change some of the navigation parameters based on the particular URL. |
| 99 // Currently this applies to chrome://settings and the bookmark manager, |
| 100 // which we always want to open in a normal (not incognito) window. |
| 101 void AdjustNavigateParamsForURL(browser::NavigateParams* params) { |
| 102 if (!params->target_contents && |
| 103 params->url.scheme() == chrome::kChromeUIScheme && |
| 104 (params->url.host() == chrome::kChromeUISettingsHost || |
| 105 params->url.host() == chrome::kChromeUIBookmarksHost)) { |
| 106 Profile* profile = |
| 107 params->browser ? params->browser->profile() : params->profile; |
| 108 |
| 109 if (profile->IsOffTheRecord()) { |
| 110 profile = profile->GetOriginalProfile(); |
| 111 |
| 112 params->disposition = SINGLETON_TAB; |
| 113 params->profile = profile; |
| 114 params->browser = Browser::GetOrCreateTabbedBrowser(profile); |
| 115 params->show_window = true; |
| 116 } |
| 117 } |
| 118 } |
| 119 |
97 // Returns a Browser that can host the navigation or tab addition specified in | 120 // Returns a Browser that can host the navigation or tab addition specified in |
98 // |params|. This might just return the same Browser specified in |params|, or | 121 // |params|. This might just return the same Browser specified in |params|, or |
99 // some other if that Browser is deemed incompatible. | 122 // some other if that Browser is deemed incompatible. |
100 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { | 123 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { |
101 // If no source TabContents was specified, we use the selected one from the | 124 // If no source TabContents was specified, we use the selected one from the |
102 // target browser. This must happen first, before GetBrowserForDisposition() | 125 // target browser. This must happen first, before GetBrowserForDisposition() |
103 // has a chance to replace |params->browser| with another one. | 126 // has a chance to replace |params->browser| with another one. |
104 if (!params->source_contents && params->browser) | 127 if (!params->source_contents && params->browser) |
105 params->source_contents = params->browser->GetSelectedTabContents(); | 128 params->source_contents = params->browser->GetSelectedTabContents(); |
106 | 129 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 tabstrip_add_types(TabStripModel::ADD_SELECTED), | 297 tabstrip_add_types(TabStripModel::ADD_SELECTED), |
275 show_window(false), | 298 show_window(false), |
276 browser(a_browser), | 299 browser(a_browser), |
277 profile(NULL) { | 300 profile(NULL) { |
278 } | 301 } |
279 | 302 |
280 NavigateParams::~NavigateParams() { | 303 NavigateParams::~NavigateParams() { |
281 } | 304 } |
282 | 305 |
283 void Navigate(NavigateParams* params) { | 306 void Navigate(NavigateParams* params) { |
| 307 AdjustNavigateParamsForURL(params); |
| 308 |
284 params->browser = GetBrowserForDisposition(params); | 309 params->browser = GetBrowserForDisposition(params); |
285 if (!params->browser) | 310 if (!params->browser) |
286 return; | 311 return; |
287 // Navigate() must not return early after this point. | 312 // Navigate() must not return early after this point. |
288 | 313 |
289 // Make sure the Browser is shown if params call for it. | 314 // Make sure the Browser is shown if params call for it. |
290 ScopedBrowserDisplayer displayer(params); | 315 ScopedBrowserDisplayer displayer(params); |
291 | 316 |
292 // Makes sure any TabContents created by this function is destroyed if | 317 // Makes sure any TabContents created by this function is destroyed if |
293 // not properly added to a tab strip. | 318 // not properly added to a tab strip. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 params->transition, | 398 params->transition, |
374 params->tabstrip_add_types); | 399 params->tabstrip_add_types); |
375 // Now that the |params->target_contents| is safely owned by the target | 400 // Now that the |params->target_contents| is safely owned by the target |
376 // Browser's TabStripModel, we can release ownership. | 401 // Browser's TabStripModel, we can release ownership. |
377 target_contents_owner.ReleaseOwnership(); | 402 target_contents_owner.ReleaseOwnership(); |
378 } | 403 } |
379 } | 404 } |
380 } | 405 } |
381 | 406 |
382 } // namespace browser | 407 } // namespace browser |
OLD | NEW |