| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_about_handler.h" | 12 #include "chrome/browser/browser_about_handler.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_tab_helper.h" | 14 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 15 #include "chrome/browser/google/google_url_tracker.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/rlz/rlz.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 19 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 16 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/omnibox/location_bar.h" | 24 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 20 #include "chrome/browser/ui/status_bubble.h" | 25 #include "chrome/browser/ui/status_bubble.h" |
| 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 22 #include "chrome/browser/web_applications/web_app.h" | 27 #include "chrome/browser/web_applications/web_app.h" |
| 23 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 25 #include "content/browser/browser_url_handler.h" | 31 #include "content/browser/browser_url_handler.h" |
| 26 #include "content/browser/site_instance.h" | 32 #include "content/browser/site_instance.h" |
| 27 #include "content/browser/tab_contents/tab_contents.h" | 33 #include "content/browser/tab_contents/tab_contents.h" |
| 34 #include "net/http/http_util.h" |
| 28 | 35 |
| 29 namespace { | 36 namespace { |
| 30 | 37 |
| 31 // Returns true if the specified Browser can open tabs. Not all Browsers support | 38 // Returns true if the specified Browser can open tabs. Not all Browsers support |
| 32 // multiple tabs, such as app frames and popups. This function returns false for | 39 // multiple tabs, such as app frames and popups. This function returns false for |
| 33 // those types of Browser. | 40 // those types of Browser. |
| 34 bool WindowCanOpenTabs(Browser* browser) { | 41 bool WindowCanOpenTabs(Browser* browser) { |
| 35 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || | 42 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || |
| 36 browser->tabstrip_model()->empty(); | 43 browser->tabstrip_model()->empty(); |
| 37 } | 44 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 TabContentsWrapper* ReleaseOwnership() { | 275 TabContentsWrapper* ReleaseOwnership() { |
| 269 return target_contents_owner_.release(); | 276 return target_contents_owner_.release(); |
| 270 } | 277 } |
| 271 | 278 |
| 272 private: | 279 private: |
| 273 browser::NavigateParams* params_; | 280 browser::NavigateParams* params_; |
| 274 scoped_ptr<TabContentsWrapper> target_contents_owner_; | 281 scoped_ptr<TabContentsWrapper> target_contents_owner_; |
| 275 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); | 282 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); |
| 276 }; | 283 }; |
| 277 | 284 |
| 285 void InitializeExtraHeaders(browser::NavigateParams* params, |
| 286 Profile* profile, |
| 287 std::string* extra_headers) { |
| 288 #if defined(GOOGLE_CHROME_BUILD) |
| 289 if (!profile) |
| 290 profile = params->profile; |
| 291 |
| 292 // If this is a home page navigation, check to see if the home page is |
| 293 // set to Google and add RLZ HTTP headers to the request. This is only |
| 294 // done if Google was the original home page, and not changed afterwards by |
| 295 // the user. |
| 296 if (profile && (params->transition & PageTransition::HOME_PAGE) != 0) { |
| 297 PrefService* pref_service = profile->GetPrefs(); |
| 298 if (pref_service) { |
| 299 if (!pref_service->GetBoolean(prefs::kHomePageChanged)) { |
| 300 std::string homepage = pref_service->GetString(prefs::kHomePage); |
| 301 if (homepage == GoogleURLTracker::kDefaultGoogleHomepage) { |
| 302 std::wstring rlz_string; |
| 303 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, &rlz_string); |
| 304 if (!rlz_string.empty()) { |
| 305 // DO NOT COMMIT: waiting for the search folks to tell me the |
| 306 // actual HTTP header name they want to see. |
| 307 net::HttpUtil::AppendHeaderIfMissing("X-Google-Rlz", |
| 308 WideToUTF8(rlz_string), |
| 309 extra_headers); |
| 310 } |
| 311 } |
| 312 } |
| 313 } |
| 314 } |
| 315 #endif |
| 316 } |
| 317 |
| 278 } // namespace | 318 } // namespace |
| 279 | 319 |
| 280 namespace browser { | 320 namespace browser { |
| 281 | 321 |
| 282 NavigateParams::NavigateParams( | 322 NavigateParams::NavigateParams( |
| 283 Browser* a_browser, | 323 Browser* a_browser, |
| 284 const GURL& a_url, | 324 const GURL& a_url, |
| 285 PageTransition::Type a_transition) | 325 PageTransition::Type a_transition) |
| 286 : url(a_url), | 326 : url(a_url), |
| 287 target_contents(NULL), | 327 target_contents(NULL), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 PageTransition::Type base_transition = | 410 PageTransition::Type base_transition = |
| 371 PageTransition::StripQualifier(params->transition); | 411 PageTransition::StripQualifier(params->transition); |
| 372 bool user_initiated = params->transition & PageTransition::FROM_ADDRESS_BAR || | 412 bool user_initiated = params->transition & PageTransition::FROM_ADDRESS_BAR || |
| 373 base_transition == PageTransition::TYPED || | 413 base_transition == PageTransition::TYPED || |
| 374 base_transition == PageTransition::AUTO_BOOKMARK || | 414 base_transition == PageTransition::AUTO_BOOKMARK || |
| 375 base_transition == PageTransition::GENERATED || | 415 base_transition == PageTransition::GENERATED || |
| 376 base_transition == PageTransition::START_PAGE || | 416 base_transition == PageTransition::START_PAGE || |
| 377 base_transition == PageTransition::RELOAD || | 417 base_transition == PageTransition::RELOAD || |
| 378 base_transition == PageTransition::KEYWORD; | 418 base_transition == PageTransition::KEYWORD; |
| 379 | 419 |
| 420 std::string extra_headers; |
| 421 |
| 380 // Check if this is a singleton tab that already exists | 422 // Check if this is a singleton tab that already exists |
| 381 int singleton_index = GetIndexOfSingletonTab(params); | 423 int singleton_index = GetIndexOfSingletonTab(params); |
| 382 | 424 |
| 383 // If no target TabContents was specified, we need to construct one if we are | 425 // If no target TabContents was specified, we need to construct one if we are |
| 384 // supposed to target a new tab; unless it's a singleton that already exists. | 426 // supposed to target a new tab; unless it's a singleton that already exists. |
| 385 if (!params->target_contents && singleton_index < 0) { | 427 if (!params->target_contents && singleton_index < 0) { |
| 386 GURL url = params->url.is_empty() ? params->browser->GetHomePage() | 428 GURL url; |
| 387 : params->url; | 429 if (params->url.is_empty()) { |
| 430 url = params->browser->GetHomePage(); |
| 431 params->transition |= PageTransition::HOME_PAGE; |
| 432 } else { |
| 433 url = params->url; |
| 434 } |
| 435 |
| 388 if (params->disposition != CURRENT_TAB) { | 436 if (params->disposition != CURRENT_TAB) { |
| 389 TabContents* source_contents = params->source_contents ? | 437 TabContents* source_contents = params->source_contents ? |
| 390 params->source_contents->tab_contents() : NULL; | 438 params->source_contents->tab_contents() : NULL; |
| 391 params->target_contents = | 439 params->target_contents = |
| 392 Browser::TabContentsFactory( | 440 Browser::TabContentsFactory( |
| 393 params->browser->profile(), | 441 params->browser->profile(), |
| 394 tab_util::GetSiteInstanceForNewTab( | 442 tab_util::GetSiteInstanceForNewTab( |
| 395 source_contents, params->browser->profile(), url), | 443 source_contents, params->browser->profile(), url), |
| 396 MSG_ROUTING_NONE, | 444 MSG_ROUTING_NONE, |
| 397 source_contents, | 445 source_contents, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 414 // same as the source. | 462 // same as the source. |
| 415 params->target_contents = params->source_contents; | 463 params->target_contents = params->source_contents; |
| 416 DCHECK(params->target_contents); | 464 DCHECK(params->target_contents); |
| 417 } | 465 } |
| 418 | 466 |
| 419 if (user_initiated) { | 467 if (user_initiated) { |
| 420 static_cast<RenderViewHostDelegate*>(params->target_contents-> | 468 static_cast<RenderViewHostDelegate*>(params->target_contents-> |
| 421 tab_contents())->OnUserGesture(); | 469 tab_contents())->OnUserGesture(); |
| 422 } | 470 } |
| 423 | 471 |
| 472 InitializeExtraHeaders(params, params->target_contents->profile(), |
| 473 &extra_headers); |
| 474 |
| 424 // Try to handle non-navigational URLs that popup dialogs and such, these | 475 // Try to handle non-navigational URLs that popup dialogs and such, these |
| 425 // should not actually navigate. | 476 // should not actually navigate. |
| 426 if (!HandleNonNavigationAboutURL(url)) { | 477 if (!HandleNonNavigationAboutURL(url)) { |
| 427 // Perform the actual navigation. | 478 // Perform the actual navigation. |
| 428 params->target_contents->controller().LoadURL(url, params->referrer, | 479 params->target_contents->controller().LoadURLWithHeaders( |
| 429 params->transition); | 480 url, params->referrer, params->transition, extra_headers); |
| 430 } | 481 } |
| 431 } else { | 482 } else { |
| 432 // |target_contents| was specified non-NULL, and so we assume it has already | 483 // |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 | 484 // been navigated appropriately. We need to do nothing more other than |
| 434 // add it to the appropriate tabstrip. | 485 // add it to the appropriate tabstrip. |
| 435 } | 486 } |
| 436 | 487 |
| 437 // If the user navigated from the omnibox, and the selected tab is going to | 488 // If the user navigated from the omnibox, and the selected tab is going to |
| 438 // lose focus, then make sure the focus for the source tab goes away from the | 489 // lose focus, then make sure the focus for the source tab goes away from the |
| 439 // omnibox. | 490 // omnibox. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 466 target_contents_owner.ReleaseOwnership(); | 517 target_contents_owner.ReleaseOwnership(); |
| 467 } | 518 } |
| 468 | 519 |
| 469 if (singleton_index >= 0) { | 520 if (singleton_index >= 0) { |
| 470 TabContents* target = params->browser->GetTabContentsAt(singleton_index); | 521 TabContents* target = params->browser->GetTabContentsAt(singleton_index); |
| 471 | 522 |
| 472 if (target->is_crashed()) { | 523 if (target->is_crashed()) { |
| 473 target->controller().Reload(true); | 524 target->controller().Reload(true); |
| 474 } else if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE && | 525 } else if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE && |
| 475 target->GetURL() != params->url) { | 526 target->GetURL() != params->url) { |
| 476 target->controller().LoadURL( | 527 InitializeExtraHeaders(params, NULL, &extra_headers); |
| 477 params->url, params->referrer, params->transition); | 528 target->controller().LoadURLWithHeaders( |
| 529 params->url, params->referrer, params->transition, extra_headers); |
| 478 } | 530 } |
| 479 | 531 |
| 480 // If the singleton tab isn't already selected, select it. | 532 // If the singleton tab isn't already selected, select it. |
| 481 if (params->source_contents != params->target_contents) | 533 if (params->source_contents != params->target_contents) |
| 482 params->browser->ActivateTabAt(singleton_index, user_initiated); | 534 params->browser->ActivateTabAt(singleton_index, user_initiated); |
| 483 } | 535 } |
| 484 } | 536 } |
| 485 | 537 |
| 486 // Returns the index of an existing singleton tab in |params->browser| matching | 538 // Returns the index of an existing singleton tab in |params->browser| matching |
| 487 // the URL specified in |params|. | 539 // the URL specified in |params|. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 rewritten_url, replacements)) { | 574 rewritten_url, replacements)) { |
| 523 params->target_contents = tab; | 575 params->target_contents = tab; |
| 524 return tab_index; | 576 return tab_index; |
| 525 } | 577 } |
| 526 } | 578 } |
| 527 | 579 |
| 528 return -1; | 580 return -1; |
| 529 } | 581 } |
| 530 | 582 |
| 531 } // namespace browser | 583 } // namespace browser |
| OLD | NEW |