Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/ui/browser_navigator.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 case NEW_FOREGROUND_TAB: 223 case NEW_FOREGROUND_TAB:
222 case SINGLETON_TAB: 224 case SINGLETON_TAB:
223 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE; 225 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE;
224 break; 226 break;
225 227
226 default: 228 default:
227 break; 229 break;
228 } 230 }
229 } 231 }
230 232
233 GURL NormalizeURL(chrome::NavigateParams* params) {
sky 2013/02/05 21:40:13 Add description.
samarth 2013/02/05 22:41:57 Oops left over from a previous iteration. Removed
234 if (params->url.is_empty()) {
235 params->transition = content::PageTransitionFromInt(
236 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
237 return params->browser->profile()->GetHomePage();
238 }
239 return params->url;
240 }
241
231 // Obtain the profile used by the code that originated the Navigate() request. 242 // Obtain the profile used by the code that originated the Navigate() request.
232 Profile* GetSourceProfile(chrome::NavigateParams* params) { 243 Profile* GetSourceProfile(chrome::NavigateParams* params) {
233 if (params->source_contents) { 244 if (params->source_contents) {
234 return Profile::FromBrowserContext( 245 return Profile::FromBrowserContext(
235 params->source_contents->GetBrowserContext()); 246 params->source_contents->GetBrowserContext());
236 } 247 }
237 248
238 return params->initiating_profile; 249 return params->initiating_profile;
239 } 250 }
240 251
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 WebContents* ReleaseOwnership() { 313 WebContents* ReleaseOwnership() {
303 return target_contents_owner_.release(); 314 return target_contents_owner_.release();
304 } 315 }
305 316
306 private: 317 private:
307 chrome::NavigateParams* params_; 318 chrome::NavigateParams* params_;
308 scoped_ptr<WebContents> target_contents_owner_; 319 scoped_ptr<WebContents> target_contents_owner_;
309 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); 320 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
310 }; 321 };
311 322
323 content::WebContents* CreateTargetContents(chrome::NavigateParams* params,
sky 2013/02/05 21:40:13 const NavigateParams&
samarth 2013/02/05 22:41:57 Done.
324 const GURL& url) {
325 WebContents::CreateParams create_params(
326 params->browser->profile(),
327 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url));
328 if (params->source_contents) {
329 create_params.initial_size =
330 params->source_contents->GetView()->GetContainerSize();
331 }
332 #if defined(USE_AURA)
333 if (params->browser->window() &&
334 params->browser->window()->GetNativeWindow()) {
335 create_params.context =
336 params->browser->window()->GetNativeWindow();
337 }
338 #endif
339
340 content::WebContents* target_contents = WebContents::Create(create_params);
341 // New tabs can have WebUI URLs that will make calls back to arbitrary
342 // tab helpers, so the entire set of tab helpers needs to be set up
343 // immediately.
344 BrowserNavigatorWebContentsAdoption::AttachTabHelpers(target_contents);
345 extensions::TabHelper::FromWebContents(target_contents)->
346 SetExtensionAppById(params->extension_app_id);
347 // TODO(sky): Figure out why this is needed. Without it we seem to get
348 // failures in startup tests.
349 // By default, content believes it is not hidden. When adding contents
350 // in the background, tell it that it's hidden.
351 if ((params->tabstrip_add_types & TabStripModel::ADD_ACTIVE) == 0) {
352 // TabStripModel::AddWebContents invokes WasHidden if not foreground.
353 target_contents->WasHidden();
354 }
355 return target_contents;
356 }
357
312 // If a prerendered page exists for |url|, replace the page at |target_contents| 358 // If a prerendered page exists for |url|, replace the page at |target_contents|
313 // with it. 359 // with it.
314 bool SwapInPrerender(WebContents* target_contents, const GURL& url) { 360 bool SwapInPrerender(WebContents* target_contents, const GURL& url) {
315 prerender::PrerenderManager* prerender_manager = 361 prerender::PrerenderManager* prerender_manager =
316 prerender::PrerenderManagerFactory::GetForProfile( 362 prerender::PrerenderManagerFactory::GetForProfile(
317 Profile::FromBrowserContext(target_contents->GetBrowserContext())); 363 Profile::FromBrowserContext(target_contents->GetBrowserContext()));
318 return prerender_manager && 364 return prerender_manager &&
319 prerender_manager->MaybeUsePrerenderedPage(target_contents, url); 365 prerender_manager->MaybeUsePrerenderedPage(target_contents, url);
320 } 366 }
321 367
368 bool SwapInInstantNTP(chrome::NavigateParams* params,
369 const GURL& url,
370 content::WebContents* source_contents) {
371 if (!chrome::search::IsInstantExtendedAPIEnabled(params->browser->profile()))
372 return false;
373
374 chrome::BrowserInstantController* instant =
375 params->browser->instant_controller();
376 return instant && instant->MaybeSwapInInstantNTPContents(
377 url, source_contents, &params->target_contents);
378 }
379
322 } // namespace 380 } // namespace
323 381
324 namespace chrome { 382 namespace chrome {
325 383
326 NavigateParams::NavigateParams(Browser* a_browser, 384 NavigateParams::NavigateParams(Browser* a_browser,
327 const GURL& a_url, 385 const GURL& a_url,
328 content::PageTransition a_transition) 386 content::PageTransition a_transition)
329 : url(a_url), 387 : url(a_url),
330 target_contents(NULL), 388 target_contents(NULL),
331 source_contents(NULL), 389 source_contents(NULL),
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 base_transition == content::PAGE_TRANSITION_TYPED || 517 base_transition == content::PAGE_TRANSITION_TYPED ||
460 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 518 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
461 base_transition == content::PAGE_TRANSITION_GENERATED || 519 base_transition == content::PAGE_TRANSITION_GENERATED ||
462 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL || 520 base_transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL ||
463 base_transition == content::PAGE_TRANSITION_RELOAD || 521 base_transition == content::PAGE_TRANSITION_RELOAD ||
464 base_transition == content::PAGE_TRANSITION_KEYWORD; 522 base_transition == content::PAGE_TRANSITION_KEYWORD;
465 523
466 // Check if this is a singleton tab that already exists 524 // Check if this is a singleton tab that already exists
467 int singleton_index = chrome::GetIndexOfSingletonTab(params); 525 int singleton_index = chrome::GetIndexOfSingletonTab(params);
468 526
527 // Did we use Instant's NTP contents?
528 bool swapped_in_instant = false;
529
469 // If no target WebContents was specified, we need to construct one if 530 // 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 531 // we are supposed to target a new tab; unless it's a singleton that already
471 // exists. 532 // exists.
472 if (!params->target_contents && singleton_index < 0) { 533 if (!params->target_contents && singleton_index < 0) {
473 GURL url; 534 GURL url;
474 if (params->url.is_empty()) { 535 if (params->url.is_empty()) {
475 url = params->browser->profile()->GetHomePage(); 536 url = params->browser->profile()->GetHomePage();
476 params->transition = content::PageTransitionFromInt( 537 params->transition = content::PageTransitionFromInt(
477 params->transition | content::PAGE_TRANSITION_HOME_PAGE); 538 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
478 } else { 539 } else {
479 url = params->url; 540 url = params->url;
480 } 541 }
481 542
482 if (params->disposition != CURRENT_TAB) { 543 if (params->disposition != CURRENT_TAB) {
483 WebContents::CreateParams create_params( 544 swapped_in_instant = SwapInInstantNTP(params, url, NULL);
484 params->browser->profile(), 545 if (!swapped_in_instant)
485 tab_util::GetSiteInstanceForNewTab(params->browser->profile(), url)); 546 params->target_contents = CreateTargetContents(params, url);
486 if (params->source_contents) { 547
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 548 // This function takes ownership of |params->target_contents| until it
504 // is added to a TabStripModel. 549 // is added to a TabStripModel.
505 target_contents_owner.TakeOwnership(); 550 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 { 551 } else {
517 // ... otherwise if we're loading in the current tab, the target is the 552 // ... otherwise if we're loading in the current tab, the target is the
518 // same as the source. 553 // same as the source.
519 params->target_contents = params->source_contents; 554 DCHECK(params->source_contents);
555 swapped_in_instant = SwapInInstantNTP(params, url,
556 params->source_contents);
557 if (!swapped_in_instant)
558 params->target_contents = params->source_contents;
520 DCHECK(params->target_contents); 559 DCHECK(params->target_contents);
521 } 560 }
522 561
523 if (user_initiated) 562 if (user_initiated)
524 params->target_contents->UserGestureDone(); 563 params->target_contents->UserGestureDone();
525 564
526 if (SwapInPrerender(params->target_contents, url)) 565 if (!swapped_in_instant) {
527 return; 566 if (SwapInPrerender(params->target_contents, url))
567 return;
528 568
529 // Try to handle non-navigational URLs that popup dialogs and such, these 569 // Try to handle non-navigational URLs that popup dialogs and such, these
530 // should not actually navigate. 570 // should not actually navigate.
531 if (!HandleNonNavigationAboutURL(url)) { 571 if (!HandleNonNavigationAboutURL(url)) {
532 // Perform the actual navigation, tracking whether it came from the 572 // Perform the actual navigation, tracking whether it came from the
533 // renderer. 573 // renderer.
534 574
535 LoadURLInContents(params->target_contents, url, params); 575 LoadURLInContents(params->target_contents, url, params);
576 }
536 } 577 }
537 } else { 578 } else {
538 // |target_contents| was specified non-NULL, and so we assume it has already 579 // |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 580 // been navigated appropriately. We need to do nothing more other than
540 // add it to the appropriate tabstrip. 581 // add it to the appropriate tabstrip.
541 } 582 }
542 583
543 // If the user navigated from the omnibox, and the selected tab is going to 584 // 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 585 // lose focus, then make sure the focus for the source tab goes away from the
545 // omnibox. 586 // omnibox.
546 if (params->source_contents && 587 if (params->source_contents &&
547 (params->disposition == NEW_FOREGROUND_TAB || 588 (params->disposition == NEW_FOREGROUND_TAB ||
548 params->disposition == NEW_WINDOW) && 589 params->disposition == NEW_WINDOW) &&
549 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) 590 (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER))
550 params->source_contents->Focus(); 591 params->source_contents->Focus();
551 592
552 if (params->source_contents == params->target_contents) { 593 if (params->source_contents == params->target_contents ||
594 (swapped_in_instant && params->disposition == CURRENT_TAB)) {
553 // The navigation occurred in the source tab. 595 // The navigation occurred in the source tab.
554 params->browser->UpdateUIForNavigationInTab(params->target_contents, 596 params->browser->UpdateUIForNavigationInTab(params->target_contents,
555 params->transition, 597 params->transition,
556 user_initiated); 598 user_initiated);
557 } else if (singleton_index == -1) { 599 } else if (singleton_index == -1) {
558 // If some non-default value is set for the index, we should tell the 600 // If some non-default value is set for the index, we should tell the
559 // TabStripModel to respect it. 601 // TabStripModel to respect it.
560 if (params->tabstrip_index != -1) 602 if (params->tabstrip_index != -1)
561 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX; 603 params->tabstrip_add_types |= TabStripModel::ADD_FORCE_INDEX;
562 604
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 bool reverse_on_redirect = false; 658 bool reverse_on_redirect = false;
617 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 659 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
618 &rewritten_url, browser_context, &reverse_on_redirect); 660 &rewritten_url, browser_context, &reverse_on_redirect);
619 661
620 // Some URLs are mapped to uber subpages. Do not allow them in incognito. 662 // Some URLs are mapped to uber subpages. Do not allow them in incognito.
621 return !(rewritten_url.scheme() == chrome::kChromeUIScheme && 663 return !(rewritten_url.scheme() == chrome::kChromeUIScheme &&
622 rewritten_url.host() == chrome::kChromeUIUberHost); 664 rewritten_url.host() == chrome::kChromeUIUberHost);
623 } 665 }
624 666
625 } // namespace chrome 667 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698