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 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); | |
Ben Goodger (Google)
2010/11/15 18:21:04
nix this line
| |
112 | |
113 params->disposition = NEW_FOREGROUND_TAB; | |
sadrul
2010/11/12 21:46:54
I think it should be SINGLETON_TAB here? In additi
Evan Stade
2010/11/12 23:53:41
oh yea, I think you're right.
| |
114 params->profile = profile; | |
115 params->browser = browser; | |
Ben Goodger (Google)
2010/11/15 18:21:04
params->browser = Browser::GetOrCreateTabbedBrowse
Evan Stade
2010/11/15 18:51:47
Done.
| |
116 params->tabstrip_add_types = TabStripModel::ADD_SELECTED; | |
Ben Goodger (Google)
2010/11/15 18:21:04
This should be inferred from NEW_FOREGROUND_TAB
sadrul
2010/11/15 18:41:00
I believe it should be SINGLETON_TAB (as noted ear
| |
117 params->show_window = true; | |
118 } | |
119 } | |
120 } | |
121 | |
97 // Returns a Browser that can host the navigation or tab addition specified in | 122 // 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 | 123 // |params|. This might just return the same Browser specified in |params|, or |
99 // some other if that Browser is deemed incompatible. | 124 // some other if that Browser is deemed incompatible. |
100 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { | 125 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { |
101 // If no source TabContents was specified, we use the selected one from the | 126 // If no source TabContents was specified, we use the selected one from the |
102 // target browser. This must happen first, before GetBrowserForDisposition() | 127 // target browser. This must happen first, before GetBrowserForDisposition() |
103 // has a chance to replace |params->browser| with another one. | 128 // has a chance to replace |params->browser| with another one. |
104 if (!params->source_contents && params->browser) | 129 if (!params->source_contents && params->browser) |
105 params->source_contents = params->browser->GetSelectedTabContents(); | 130 params->source_contents = params->browser->GetSelectedTabContents(); |
106 | 131 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 tabstrip_add_types(TabStripModel::ADD_SELECTED), | 299 tabstrip_add_types(TabStripModel::ADD_SELECTED), |
275 show_window(false), | 300 show_window(false), |
276 browser(a_browser), | 301 browser(a_browser), |
277 profile(NULL) { | 302 profile(NULL) { |
278 } | 303 } |
279 | 304 |
280 NavigateParams::~NavigateParams() { | 305 NavigateParams::~NavigateParams() { |
281 } | 306 } |
282 | 307 |
283 void Navigate(NavigateParams* params) { | 308 void Navigate(NavigateParams* params) { |
309 AdjustNavigateParamsForURL(params); | |
310 | |
284 params->browser = GetBrowserForDisposition(params); | 311 params->browser = GetBrowserForDisposition(params); |
285 if (!params->browser) | 312 if (!params->browser) |
286 return; | 313 return; |
287 // Navigate() must not return early after this point. | 314 // Navigate() must not return early after this point. |
288 | 315 |
289 // Make sure the Browser is shown if params call for it. | 316 // Make sure the Browser is shown if params call for it. |
290 ScopedBrowserDisplayer displayer(params); | 317 ScopedBrowserDisplayer displayer(params); |
291 | 318 |
292 // Makes sure any TabContents created by this function is destroyed if | 319 // Makes sure any TabContents created by this function is destroyed if |
293 // not properly added to a tab strip. | 320 // not properly added to a tab strip. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 params->transition, | 400 params->transition, |
374 params->tabstrip_add_types); | 401 params->tabstrip_add_types); |
375 // Now that the |params->target_contents| is safely owned by the target | 402 // Now that the |params->target_contents| is safely owned by the target |
376 // Browser's TabStripModel, we can release ownership. | 403 // Browser's TabStripModel, we can release ownership. |
377 target_contents_owner.ReleaseOwnership(); | 404 target_contents_owner.ReleaseOwnership(); |
378 } | 405 } |
379 } | 406 } |
380 } | 407 } |
381 | 408 |
382 } // namespace browser | 409 } // namespace browser |
OLD | NEW |