| 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 DOMUI 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 DOMUI 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 (DOMUIFactory::UseDOMUIForURL(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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 PageTransition::StripQualifier(params->transition); | 390 PageTransition::StripQualifier(params->transition); |
| 383 bool user_initiated = base_transition == PageTransition::TYPED || | 391 bool user_initiated = base_transition == PageTransition::TYPED || |
| 384 base_transition == PageTransition::AUTO_BOOKMARK; | 392 base_transition == PageTransition::AUTO_BOOKMARK; |
| 385 | 393 |
| 386 // Check if this is a singleton tab that already exists | 394 // Check if this is a singleton tab that already exists |
| 387 int singleton_index = GetIndexOfSingletonTab(params); | 395 int singleton_index = GetIndexOfSingletonTab(params); |
| 388 | 396 |
| 389 // If no target TabContents was specified, we need to construct one if we are | 397 // If no target TabContents was specified, we need to construct one if we are |
| 390 // supposed to target a new tab; unless it's a singleton that already exists. | 398 // supposed to target a new tab; unless it's a singleton that already exists. |
| 391 if (!params->target_contents && singleton_index < 0) { | 399 if (!params->target_contents && singleton_index < 0) { |
| 400 GURL url = params->url.is_empty() ? params->browser->GetHomePage() |
| 401 : params->url; |
| 392 if (params->disposition != CURRENT_TAB) { | 402 if (params->disposition != CURRENT_TAB) { |
| 393 TabContents* source_contents = params->source_contents ? | 403 TabContents* source_contents = params->source_contents ? |
| 394 params->source_contents->tab_contents() : NULL; | 404 params->source_contents->tab_contents() : NULL; |
| 395 params->target_contents = | 405 params->target_contents = |
| 396 Browser::TabContentsFactory( | 406 Browser::TabContentsFactory( |
| 397 params->browser->profile(), | 407 params->browser->profile(), |
| 398 GetSiteInstance(source_contents, params->url), | 408 GetSiteInstance(source_contents, params->browser->profile(), url), |
| 399 MSG_ROUTING_NONE, | 409 MSG_ROUTING_NONE, |
| 400 source_contents, | 410 source_contents, |
| 401 NULL); | 411 NULL); |
| 402 // This function takes ownership of |params->target_contents| until it | 412 // This function takes ownership of |params->target_contents| until it |
| 403 // is added to a TabStripModel. | 413 // is added to a TabStripModel. |
| 404 target_contents_owner.TakeOwnership(); | 414 target_contents_owner.TakeOwnership(); |
| 405 params->target_contents->SetExtensionAppById(params->extension_app_id); | 415 params->target_contents->SetExtensionAppById(params->extension_app_id); |
| 406 // TODO(sky): figure out why this is needed. Without it we seem to get | 416 // TODO(sky): figure out why this is needed. Without it we seem to get |
| 407 // failures in startup tests. | 417 // failures in startup tests. |
| 408 // By default, content believes it is not hidden. When adding contents | 418 // By default, content believes it is not hidden. When adding contents |
| 409 // in the background, tell it that it's hidden. | 419 // in the background, tell it that it's hidden. |
| 410 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { | 420 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { |
| 411 // TabStripModel::AddTabContents invokes HideContents if not foreground. | 421 // TabStripModel::AddTabContents invokes HideContents if not foreground. |
| 412 params->target_contents->tab_contents()->WasHidden(); | 422 params->target_contents->tab_contents()->WasHidden(); |
| 413 } | 423 } |
| 414 } else { | 424 } else { |
| 415 // ... otherwise if we're loading in the current tab, the target is the | 425 // ... otherwise if we're loading in the current tab, the target is the |
| 416 // same as the source. | 426 // same as the source. |
| 417 params->target_contents = params->source_contents; | 427 params->target_contents = params->source_contents; |
| 418 DCHECK(params->target_contents); | 428 DCHECK(params->target_contents); |
| 419 } | 429 } |
| 420 | 430 |
| 421 if (user_initiated) { | 431 if (user_initiated) { |
| 422 static_cast<RenderViewHostDelegate*>(params->target_contents-> | 432 static_cast<RenderViewHostDelegate*>(params->target_contents-> |
| 423 tab_contents())->OnUserGesture(); | 433 tab_contents())->OnUserGesture(); |
| 424 } | 434 } |
| 425 | 435 |
| 426 // Perform the actual navigation. | 436 // Perform the actual navigation. |
| 427 GURL url = params->url.is_empty() ? params->browser->GetHomePage() | |
| 428 : params->url; | |
| 429 params->target_contents->controller().LoadURL(url, params->referrer, | 437 params->target_contents->controller().LoadURL(url, params->referrer, |
| 430 params->transition); | 438 params->transition); |
| 431 } else { | 439 } else { |
| 432 // |target_contents| was specified non-NULL, and so we assume it has already | 440 // |target_contents| was specified non-NULL, and so we assume it has already |
| 433 // been navigated appropriately. We need to do nothing more other than | 441 // been navigated appropriately. We need to do nothing more other than |
| 434 // add it to the appropriate tabstrip. | 442 // add it to the appropriate tabstrip. |
| 435 } | 443 } |
| 436 | 444 |
| 437 if (params->source_contents == params->target_contents) { | 445 if (params->source_contents == params->target_contents) { |
| 438 // The navigation occurred in the source tab. | 446 // The navigation occurred in the source tab. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 467 params->url, params->referrer, params->transition); | 475 params->url, params->referrer, params->transition); |
| 468 } | 476 } |
| 469 | 477 |
| 470 // If the singleton tab isn't already selected, select it. | 478 // If the singleton tab isn't already selected, select it. |
| 471 if (params->source_contents != params->target_contents) | 479 if (params->source_contents != params->target_contents) |
| 472 params->browser->SelectTabContentsAt(singleton_index, user_initiated); | 480 params->browser->SelectTabContentsAt(singleton_index, user_initiated); |
| 473 } | 481 } |
| 474 } | 482 } |
| 475 | 483 |
| 476 } // namespace browser | 484 } // namespace browser |
| OLD | NEW |