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_list.h" | 8 #include "chrome/browser/browser_list.h" |
9 #include "chrome/browser/browser_url_handler.h" | 9 #include "chrome/browser/browser_url_handler.h" |
10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/renderer_host/site_instance.h" | 12 #include "chrome/browser/renderer_host/site_instance.h" |
13 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/status_bubble.h" | 16 #include "chrome/browser/ui/status_bubble.h" |
17 #include "chrome/browser/ui/omnibox/location_bar.h" | 17 #include "chrome/browser/ui/omnibox/location_bar.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Returns the SiteInstance for |source_contents| if it represents the same | 24 // Returns an appropriate SiteInstance for WebUI URLs, or the SiteInstance for |
25 // website as |url|, or NULL otherwise. |source_contents| cannot be NULL. | 25 // |source_contents| if it represents the same website as |url|. Returns NULL |
26 SiteInstance* GetSiteInstance(TabContents* source_contents, const GURL& url) { | 26 // otherwise. |
| 27 SiteInstance* GetSiteInstance(TabContents* source_contents, Profile* profile, |
| 28 const GURL& url) { |
| 29 // If url is a WebUI or extension, we need to be sure to use the right type |
| 30 // of renderer process up front. Otherwise, we create a normal SiteInstance |
| 31 // as part of creating the tab. |
| 32 if (WebUIFactory::UseWebUIForURL(profile, url)) |
| 33 return SiteInstance::CreateSiteInstanceForURL(profile, url); |
| 34 |
27 if (!source_contents) | 35 if (!source_contents) |
28 return NULL; | 36 return NULL; |
29 | 37 |
30 // Don't use this logic when "--process-per-tab" is specified. | 38 // Don't use this logic when "--process-per-tab" is specified. |
31 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) && | 39 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) && |
32 SiteInstance::IsSameWebSite(source_contents->profile(), | 40 SiteInstance::IsSameWebSite(source_contents->profile(), |
33 source_contents->GetURL(), | 41 source_contents->GetURL(), |
34 url)) { | 42 url)) { |
35 return source_contents->GetSiteInstance(); | 43 return source_contents->GetSiteInstance(); |
36 } | 44 } |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 PageTransition::StripQualifier(params->transition); | 391 PageTransition::StripQualifier(params->transition); |
384 bool user_initiated = base_transition == PageTransition::TYPED || | 392 bool user_initiated = base_transition == PageTransition::TYPED || |
385 base_transition == PageTransition::AUTO_BOOKMARK; | 393 base_transition == PageTransition::AUTO_BOOKMARK; |
386 | 394 |
387 // Check if this is a singleton tab that already exists | 395 // Check if this is a singleton tab that already exists |
388 int singleton_index = GetIndexOfSingletonTab(params); | 396 int singleton_index = GetIndexOfSingletonTab(params); |
389 | 397 |
390 // If no target TabContents was specified, we need to construct one if we are | 398 // If no target TabContents was specified, we need to construct one if we are |
391 // supposed to target a new tab; unless it's a singleton that already exists. | 399 // supposed to target a new tab; unless it's a singleton that already exists. |
392 if (!params->target_contents && singleton_index < 0) { | 400 if (!params->target_contents && singleton_index < 0) { |
| 401 GURL url = params->url.is_empty() ? params->browser->GetHomePage() |
| 402 : params->url; |
393 if (params->disposition != CURRENT_TAB) { | 403 if (params->disposition != CURRENT_TAB) { |
394 TabContents* source_contents = params->source_contents ? | 404 TabContents* source_contents = params->source_contents ? |
395 params->source_contents->tab_contents() : NULL; | 405 params->source_contents->tab_contents() : NULL; |
396 params->target_contents = | 406 params->target_contents = |
397 Browser::TabContentsFactory( | 407 Browser::TabContentsFactory( |
398 params->browser->profile(), | 408 params->browser->profile(), |
399 GetSiteInstance(source_contents, params->url), | 409 GetSiteInstance(source_contents, params->browser->profile(), url), |
400 MSG_ROUTING_NONE, | 410 MSG_ROUTING_NONE, |
401 source_contents, | 411 source_contents, |
402 NULL); | 412 NULL); |
403 // This function takes ownership of |params->target_contents| until it | 413 // This function takes ownership of |params->target_contents| until it |
404 // is added to a TabStripModel. | 414 // is added to a TabStripModel. |
405 target_contents_owner.TakeOwnership(); | 415 target_contents_owner.TakeOwnership(); |
406 params->target_contents->SetExtensionAppById(params->extension_app_id); | 416 params->target_contents->SetExtensionAppById(params->extension_app_id); |
407 // TODO(sky): figure out why this is needed. Without it we seem to get | 417 // TODO(sky): figure out why this is needed. Without it we seem to get |
408 // failures in startup tests. | 418 // failures in startup tests. |
409 // By default, content believes it is not hidden. When adding contents | 419 // By default, content believes it is not hidden. When adding contents |
410 // in the background, tell it that it's hidden. | 420 // in the background, tell it that it's hidden. |
411 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { | 421 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { |
412 // TabStripModel::AddTabContents invokes HideContents if not foreground. | 422 // TabStripModel::AddTabContents invokes HideContents if not foreground. |
413 params->target_contents->tab_contents()->WasHidden(); | 423 params->target_contents->tab_contents()->WasHidden(); |
414 } | 424 } |
415 } else { | 425 } else { |
416 // ... otherwise if we're loading in the current tab, the target is the | 426 // ... otherwise if we're loading in the current tab, the target is the |
417 // same as the source. | 427 // same as the source. |
418 params->target_contents = params->source_contents; | 428 params->target_contents = params->source_contents; |
419 DCHECK(params->target_contents); | 429 DCHECK(params->target_contents); |
420 } | 430 } |
421 | 431 |
422 if (user_initiated) { | 432 if (user_initiated) { |
423 static_cast<RenderViewHostDelegate*>(params->target_contents-> | 433 static_cast<RenderViewHostDelegate*>(params->target_contents-> |
424 tab_contents())->OnUserGesture(); | 434 tab_contents())->OnUserGesture(); |
425 } | 435 } |
426 | 436 |
427 // Perform the actual navigation. | 437 // Perform the actual navigation. |
428 GURL url = params->url.is_empty() ? params->browser->GetHomePage() | |
429 : params->url; | |
430 params->target_contents->controller().LoadURL(url, params->referrer, | 438 params->target_contents->controller().LoadURL(url, params->referrer, |
431 params->transition); | 439 params->transition); |
432 } else { | 440 } else { |
433 // |target_contents| was specified non-NULL, and so we assume it has already | 441 // |target_contents| was specified non-NULL, and so we assume it has already |
434 // been navigated appropriately. We need to do nothing more other than | 442 // been navigated appropriately. We need to do nothing more other than |
435 // add it to the appropriate tabstrip. | 443 // add it to the appropriate tabstrip. |
436 } | 444 } |
437 | 445 |
438 if (params->source_contents == params->target_contents) { | 446 if (params->source_contents == params->target_contents) { |
439 // The navigation occurred in the source tab. | 447 // The navigation occurred in the source tab. |
(...skipping 28 matching lines...) Expand all Loading... |
468 params->url, params->referrer, params->transition); | 476 params->url, params->referrer, params->transition); |
469 } | 477 } |
470 | 478 |
471 // If the singleton tab isn't already selected, select it. | 479 // If the singleton tab isn't already selected, select it. |
472 if (params->source_contents != params->target_contents) | 480 if (params->source_contents != params->target_contents) |
473 params->browser->SelectTabContentsAt(singleton_index, user_initiated); | 481 params->browser->SelectTabContentsAt(singleton_index, user_initiated); |
474 } | 482 } |
475 } | 483 } |
476 | 484 |
477 } // namespace browser | 485 } // namespace browser |
OLD | NEW |