Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
| 15 #include "chrome/browser/google/google_url_tracker.h" | 15 #include "chrome/browser/google/google_url_tracker.h" |
| 16 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 16 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" | 18 #include "chrome/browser/prerender/prerender_manager.h" |
| 19 #include "chrome/browser/prerender/prerender_manager_factory.h" | 19 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_instant_controller.h" | |
| 24 #include "chrome/browser/ui/browser_tab_contents.h" | 25 #include "chrome/browser/ui/browser_tab_contents.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
| 27 #include "chrome/browser/ui/omnibox/location_bar.h" | 28 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 29 #include "chrome/browser/ui/search/search.h" | |
| 28 #include "chrome/browser/ui/singleton_tabs.h" | 30 #include "chrome/browser/ui/singleton_tabs.h" |
| 29 #include "chrome/browser/ui/status_bubble.h" | 31 #include "chrome/browser/ui/status_bubble.h" |
| 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 #include "chrome/browser/web_applications/web_app.h" | 33 #include "chrome/browser/web_applications/web_app.h" |
| 32 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
| 33 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| 34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 36 #include "content/public/browser/browser_url_handler.h" | 38 #include "content/public/browser/browser_url_handler.h" |
| 37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 WebContents* ReleaseOwnership() { | 304 WebContents* ReleaseOwnership() { |
| 303 return target_contents_owner_.release(); | 305 return target_contents_owner_.release(); |
| 304 } | 306 } |
| 305 | 307 |
| 306 private: | 308 private: |
| 307 chrome::NavigateParams* params_; | 309 chrome::NavigateParams* params_; |
| 308 scoped_ptr<WebContents> target_contents_owner_; | 310 scoped_ptr<WebContents> target_contents_owner_; |
| 309 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); | 311 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); |
| 310 }; | 312 }; |
| 311 | 313 |
| 314 content::WebContents* CreateTargetContents(const chrome::NavigateParams& params, | |
| 315 const GURL& url) { | |
| 316 WebContents::CreateParams create_params( | |
| 317 params.browser->profile(), | |
| 318 tab_util::GetSiteInstanceForNewTab(params.browser->profile(), url)); | |
| 319 if (params.source_contents) { | |
| 320 create_params.initial_size = | |
| 321 params.source_contents->GetView()->GetContainerSize(); | |
| 322 } | |
| 323 #if defined(USE_AURA) | |
| 324 if (params.browser->window() && | |
| 325 params.browser->window()->GetNativeWindow()) { | |
| 326 create_params.context = | |
| 327 params.browser->window()->GetNativeWindow(); | |
| 328 } | |
| 329 #endif | |
| 330 | |
| 331 content::WebContents* target_contents = WebContents::Create(create_params); | |
| 332 // New tabs can have WebUI URLs that will make calls back to arbitrary | |
| 333 // tab helpers, so the entire set of tab helpers needs to be set up | |
| 334 // immediately. | |
| 335 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents); | |
| 336 extensions::TabHelper::FromWebContents(target_contents)-> | |
| 337 SetExtensionAppById(params.extension_app_id); | |
| 338 // TODO(sky): Figure out why this is needed. Without it we seem to get | |
| 339 // failures in startup tests. | |
| 340 // By default, content believes it is not hidden. When adding contents | |
| 341 // in the background, tell it that it's hidden. | |
| 342 if ((params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) { | |
| 343 // TabStripModel::AddWebContents invokes WasHidden if not foreground. | |
| 344 target_contents->WasHidden(); | |
| 345 } | |
| 346 return target_contents; | |
| 347 } | |
| 348 | |
| 312 // If a prerendered page exists for |url|, replace the page at |target_contents| | 349 // If a prerendered page exists for |url|, replace the page at |target_contents| |
| 313 // with it. | 350 // with it. |
| 314 bool SwapInPrerender(WebContents* target_contents, const GURL& url) { | 351 bool SwapInPrerender(WebContents* target_contents, const GURL& url) { |
| 315 prerender::PrerenderManager* prerender_manager = | 352 prerender::PrerenderManager* prerender_manager = |
| 316 prerender::PrerenderManagerFactory::GetForProfile( | 353 prerender::PrerenderManagerFactory::GetForProfile( |
| 317 Profile::FromBrowserContext(target_contents->GetBrowserContext())); | 354 Profile::FromBrowserContext(target_contents->GetBrowserContext())); |
| 318 return prerender_manager && | 355 return prerender_manager && |
| 319 prerender_manager->MaybeUsePrerenderedPage(target_contents, url); | 356 prerender_manager->MaybeUsePrerenderedPage(target_contents, url); |
| 320 } | 357 } |
| 321 | 358 |
| 359 bool SwapInInstantNTP(chrome::NavigateParams* params, | |
|
sreeram
2013/02/07 21:17:50
I guess you can't do "const chrome::NavigateParams
samarth
2013/02/07 22:11:55
Exactly.
| |
| 360 const GURL& url, | |
| 361 content::WebContents* source_contents) { | |
| 362 if (!chrome::search::IsInstantExtendedAPIEnabled(params->browser->profile())) | |
| 363 return false; | |
|
sreeram
2013/02/07 21:17:50
We don't need this check (and thus the include of
samarth
2013/02/07 22:11:55
Done.
| |
| 364 | |
| 365 chrome::BrowserInstantController* instant = | |
| 366 params->browser->instant_controller(); | |
| 367 return instant && instant->MaybeSwapInInstantNTPContents( | |
| 368 url, source_contents, ¶ms->target_contents); | |
| 369 } | |
| 370 | |
| 322 } // namespace | 371 } // namespace |
| 323 | 372 |
| 324 namespace chrome { | 373 namespace chrome { |
| 325 | 374 |
| 326 NavigateParams::NavigateParams(Browser* a_browser, | 375 NavigateParams::NavigateParams(Browser* a_browser, |
| 327 const GURL& a_url, | 376 const GURL& a_url, |
| 328 content::PageTransition a_transition) | 377 content::PageTransition a_transition) |
| 329 : url(a_url), | 378 : url(a_url), |
| 330 target_contents(NULL), | 379 target_contents(NULL), |
| 331 source_contents(NULL), | 380 source_contents(NULL), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 base_transition == content::PAGE_TRANSITION_TYPED || | 508 base_transition == content::PAGE_TRANSITION_TYPED || |
| 460 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || | 509 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || |
| 461 base_transition == content::PAGE_TRANSITION_GENERATED || | 510 base_transition == content::PAGE_TRANSITION_GENERATED || |
| 462 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || | 511 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || |
| 463 base_transition == content::PAGE_TRANSITION_RELOAD || | 512 base_transition == content::PAGE_TRANSITION_RELOAD || |
| 464 base_transition == content::PAGE_TRANSITION_KEYWORD; | 513 base_transition == content::PAGE_TRANSITION_KEYWORD; |
| 465 | 514 |
| 466 // Check if this is a singleton tab that already exists | 515 // Check if this is a singleton tab that already exists |
| 467 int singleton_index = chrome::GetIndexOfSingletonTab(params); | 516 int singleton_index = chrome::GetIndexOfSingletonTab(params); |
| 468 | 517 |
| 518 // Did we use Instant's NTP contents? | |
| 519 bool swapped_in_instant = false; | |
| 520 | |
| 469 // If no target WebContents was specified, we need to construct one if | 521 // If no target WebContents was specified, we need to construct one if |
| 470 // we are supposed to target a new tab; unless it's a singleton that already | 522 // we are supposed to target a new tab; unless it's a singleton that already |
| 471 // exists. | 523 // exists. |
| 472 if (!params->target_contents && singleton_index < 0) { | 524 if (!params->target_contents && singleton_index < 0) { |
| 473 GURL url; | 525 GURL url; |
| 474 if (params->url.is_empty()) { | 526 if (params->url.is_empty()) { |
| 475 url = params->browser->profile()->GetHomePage(); | 527 url = params->browser->profile()->GetHomePage(); |
| 476 params->transition = content::PageTransitionFromInt( | 528 params->transition = content::PageTransitionFromInt( |
| 477 params->transition | content::PAGE_TRANSITION_HOME_PAGE); | 529 params->transition | content::PAGE_TRANSITION_HOME_PAGE); |
| 478 } else { | 530 } else { |
| 479 url = params->url; | 531 url = params->url; |
| 480 } | 532 } |
| 481 | 533 |
| 482 if (params->disposition != CURRENT_TAB) { | 534 if (params->disposition != CURRENT_TAB) { |
| 483 WebContents::CreateParams create_params( | 535 swapped_in_instant = SwapInInstantNTP(params, url, NULL); |
| 484 params->browser->profile(), | 536 if (!swapped_in_instant) |
| 485 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url)); | 537 params->target_contents = CreateTargetContents(*params, url); |
| 486 if (params->source_contents) { | 538 |
| 487 create_params.initial_size = | |
| 488 params->source_contents->GetView()->GetContainerSize(); | |
| 489 } | |
| 490 #if defined(USE_AURA) | |
| 491 if (params->browser->window() && | |
| 492 params->browser->window()->GetNativeWindow()) { | |
| 493 create_params.context = | |
| 494 params->browser->window()->GetNativeWindow(); | |
| 495 } | |
| 496 #endif | |
| 497 params->target_contents = WebContents::Create(create_params); | |
| 498 // New tabs can have WebUI URLs that will make calls back to arbitrary | |
| 499 // tab helpers, so the entire set of tab helpers needs to be set up | |
| 500 // immediately. | |
| 501 BrowserNavigatorWebContentsAdoption::AttachTabHelpers( | |
| 502 params->target_contents); | |
| 503 // This function takes ownership of |params->target_contents| until it | 539 // This function takes ownership of |params->target_contents| until it |
| 504 // is added to a TabStripModel. | 540 // is added to a TabStripModel. |
| 505 target_contents_owner.TakeOwnership(); | 541 target_contents_owner.TakeOwnership(); |
| 506 extensions::TabHelper::FromWebContents(params->target_contents)-> | |
| 507 SetExtensionAppById(params->extension_app_id); | |
| 508 // TODO(sky): Figure out why this is needed. Without it we seem to get | |
| 509 // failures in startup tests. | |
| 510 // By default, content believes it is not hidden. When adding contents | |
| 511 // in the background, tell it that it's hidden. | |
| 512 if ((params->tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) { | |
| 513 // TabStripModel::AddWebContents invokes WasHidden if not foreground. | |
| 514 params->target_contents->WasHidden(); | |
| 515 } | |
| 516 } else { | 542 } else { |
| 517 // ... otherwise if we're loading in the current tab, the target is the | 543 // ... otherwise if we're loading in the current tab, the target is the |
| 518 // same as the source. | 544 // same as the source. |
| 519 params->target_contents = params->source_contents; | 545 DCHECK(params->source_contents); |
| 546 swapped_in_instant = SwapInInstantNTP(params, url, | |
| 547 params->source_contents); | |
| 548 if (!swapped_in_instant) | |
| 549 params->target_contents = params->source_contents; | |
| 520 DCHECK(params->target_contents); | 550 DCHECK(params->target_contents); |
| 521 } | 551 } |
| 522 | 552 |
| 523 if (user_initiated) | 553 if (user_initiated) |
| 524 params->target_contents->UserGestureDone(); | 554 params->target_contents->UserGestureDone(); |
| 525 | 555 |
| 526 if (SwapInPrerender(params->target_contents, url)) | 556 if (!swapped_in_instant) { |
| 527 return; | 557 if (SwapInPrerender(params->target_contents, url)) |
| 558 return; | |
| 528 | 559 |
| 529 // Try to handle non-navigational URLs that popup dialogs and such, these | 560 // Try to handle non-navigational URLs that popup dialogs and such, these |
| 530 // should not actually navigate. | 561 // should not actually navigate. |
| 531 if (!HandleNonNavigationAboutURL(url)) { | 562 if (!HandleNonNavigationAboutURL(url)) { |
| 532 // Perform the actual navigation, tracking whether it came from the | 563 // Perform the actual navigation, tracking whether it came from the |
| 533 // renderer. | 564 // renderer. |
| 534 | 565 |
| 535 LoadURLInContents(params->target_contents, url, params); | 566 LoadURLInContents(params->target_contents, url, params); |
| 567 } | |
| 536 } | 568 } |
| 537 } else { | 569 } else { |
| 538 // |target_contents| was specified non-NULL, and so we assume it has already | 570 // |target_contents| was specified non-NULL, and so we assume it has already |
| 539 // been navigated appropriately. We need to do nothing more other than | 571 // been navigated appropriately. We need to do nothing more other than |
| 540 // add it to the appropriate tabstrip. | 572 // add it to the appropriate tabstrip. |
| 541 } | 573 } |
| 542 | 574 |
| 543 // If the user navigated from the omnibox, and the selected tab is going to | 575 // If the user navigated from the omnibox, and the selected tab is going to |
| 544 // lose focus, then make sure the focus for the source tab goes away from the | 576 // lose focus, then make sure the focus for the source tab goes away from the |
| 545 // omnibox. | 577 // omnibox. |
| 546 if (params->source_contents && | 578 if (params->source_contents && |
| 547 (params->disposition == NEW_FOREGROUND_TAB || | 579 (params->disposition == NEW_FOREGROUND_TAB || |
| 548 params->disposition == NEW_WINDOW) && | 580 params->disposition == NEW_WINDOW) && |
| 549 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) | 581 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) |
| 550 params->source_contents->Focus(); | 582 params->source_contents->Focus(); |
| 551 | 583 |
| 552 if (params->source_contents == params->target_contents) { | 584 if (params->source_contents == params->target_contents || |
| 585 (swapped_in_instant && params->disposition == CURRENT_TAB)) { | |
| 553 // The navigation occurred in the source tab. | 586 // The navigation occurred in the source tab. |
| 554 params->browser->UpdateUIForNavigationInTab(params->target_contents, | 587 params->browser->UpdateUIForNavigationInTab(params->target_contents, |
| 555 params->transition, | 588 params->transition, |
| 556 user_initiated); | 589 user_initiated); |
| 557 } else if (singleton_index == -1) { | 590 } else if (singleton_index == -1) { |
| 558 // If some non-default value is set for the index, we should tell the | 591 // If some non-default value is set for the index, we should tell the |
| 559 // TabStripModel to respect it. | 592 // TabStripModel to respect it. |
| 560 if (params->tabstrip_index != -1) | 593 if (params->tabstrip_index != -1) |
| 561 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; | 594 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; |
| 562 | 595 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 bool reverse_on_redirect = false; | 649 bool reverse_on_redirect = false; |
| 617 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 650 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 618 &rewritten_url, browser_context, &reverse_on_redirect); | 651 &rewritten_url, browser_context, &reverse_on_redirect); |
| 619 | 652 |
| 620 // Some URLs are mapped to uber subpages. Do not allow them in incognito. | 653 // Some URLs are mapped to uber subpages. Do not allow them in incognito. |
| 621 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && | 654 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && |
| 622 rewritten_url.host() == chrome::kChromeUIUberHost); | 655 rewritten_url.host() == chrome::kChromeUIUberHost); |
| 623 } | 656 } |
| 624 | 657 |
| 625 } // namespace chrome | 658 } // namespace chrome |
| OLD | NEW |