Chromium Code Reviews| 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/browser_navigator.h" | 5 #include "chrome/browser/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 bool isChromeUrl = params->url.scheme() == chrome::kChromeUIScheme; | |
| 103 bool isSettingsPage = isChromeUrl && | |
| 104 params->url.host() == chrome::kChromeUISettingsHost; | |
| 105 bool isBookmarksManager = isChromeUrl && | |
| 106 params->url.host() == chrome::kChromeUIBookmarksHost; | |
| 107 | |
| 108 if (!params->target_contents && (isSettingsPage || isBookmarksManager)) { | |
|
Peter Kasting
2010/11/12 19:49:01
Nit: It seems like it'd be simpler (and less redun
Evan Stade
2010/11/12 20:47:12
ok
| |
| 109 Profile* profile = | |
| 110 params->browser ? params->browser->profile() : params->profile; | |
| 111 | |
| 112 if (profile->IsOffTheRecord()) { | |
| 113 profile = profile->GetOriginalProfile(); | |
| 114 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); | |
| 115 | |
| 116 params->disposition = NEW_FOREGROUND_TAB; | |
| 117 params->profile = profile; | |
| 118 params->browser = browser; | |
| 119 params->tabstrip_add_types = TabStripModel::ADD_SELECTED; | |
| 120 params->show_window = true; | |
| 121 } | |
| 122 } | |
| 123 } | |
| 124 | |
| 97 // Returns a Browser that can host the navigation or tab addition specified in | 125 // 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 | 126 // |params|. This might just return the same Browser specified in |params|, or |
| 99 // some other if that Browser is deemed incompatible. | 127 // some other if that Browser is deemed incompatible. |
| 100 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { | 128 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { |
| 101 // If no source TabContents was specified, we use the selected one from the | 129 // If no source TabContents was specified, we use the selected one from the |
| 102 // target browser. This must happen first, before GetBrowserForDisposition() | 130 // target browser. This must happen first, before GetBrowserForDisposition() |
| 103 // has a chance to replace |params->browser| with another one. | 131 // has a chance to replace |params->browser| with another one. |
| 104 if (!params->source_contents && params->browser) | 132 if (!params->source_contents && params->browser) |
| 105 params->source_contents = params->browser->GetSelectedTabContents(); | 133 params->source_contents = params->browser->GetSelectedTabContents(); |
| 106 | 134 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 tabstrip_add_types(TabStripModel::ADD_SELECTED), | 302 tabstrip_add_types(TabStripModel::ADD_SELECTED), |
| 275 show_window(false), | 303 show_window(false), |
| 276 browser(a_browser), | 304 browser(a_browser), |
| 277 profile(NULL) { | 305 profile(NULL) { |
| 278 } | 306 } |
| 279 | 307 |
| 280 NavigateParams::~NavigateParams() { | 308 NavigateParams::~NavigateParams() { |
| 281 } | 309 } |
| 282 | 310 |
| 283 void Navigate(NavigateParams* params) { | 311 void Navigate(NavigateParams* params) { |
| 312 AdjustNavigateParamsForURL(params); | |
| 313 | |
| 284 params->browser = GetBrowserForDisposition(params); | 314 params->browser = GetBrowserForDisposition(params); |
| 285 if (!params->browser) | 315 if (!params->browser) |
| 286 return; | 316 return; |
| 287 // Navigate() must not return early after this point. | 317 // Navigate() must not return early after this point. |
| 288 | 318 |
| 289 // Make sure the Browser is shown if params call for it. | 319 // Make sure the Browser is shown if params call for it. |
| 290 ScopedBrowserDisplayer displayer(params); | 320 ScopedBrowserDisplayer displayer(params); |
| 291 | 321 |
| 292 // Makes sure any TabContents created by this function is destroyed if | 322 // Makes sure any TabContents created by this function is destroyed if |
| 293 // not properly added to a tab strip. | 323 // not properly added to a tab strip. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 params->transition, | 403 params->transition, |
| 374 params->tabstrip_add_types); | 404 params->tabstrip_add_types); |
| 375 // Now that the |params->target_contents| is safely owned by the target | 405 // Now that the |params->target_contents| is safely owned by the target |
| 376 // Browser's TabStripModel, we can release ownership. | 406 // Browser's TabStripModel, we can release ownership. |
| 377 target_contents_owner.ReleaseOwnership(); | 407 target_contents_owner.ReleaseOwnership(); |
| 378 } | 408 } |
| 379 } | 409 } |
| 380 } | 410 } |
| 381 | 411 |
| 382 } // namespace browser | 412 } // namespace browser |
| OLD | NEW |