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

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

Issue 7791029: When the user navigates to the home page, make sure to set the RLZ string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
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
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-RLZ-String",
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; 405 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
366 } 406 }
367 407
368 // Determine if the navigation was user initiated. If it was, we need to 408 // Determine if the navigation was user initiated. If it was, we need to
369 // inform the target TabContents, and we may need to update the UI. 409 // inform the target TabContents, and we may need to update the UI.
370 PageTransition::Type base_transition = 410 PageTransition::Type base_transition =
371 PageTransition::StripQualifier(params->transition); 411 PageTransition::StripQualifier(params->transition);
372 bool user_initiated = base_transition == PageTransition::TYPED || 412 bool user_initiated = base_transition == PageTransition::TYPED ||
373 base_transition == PageTransition::AUTO_BOOKMARK; 413 base_transition == PageTransition::AUTO_BOOKMARK;
374 414
415 std::string extra_headers;
sky 2011/08/30 15:56:53 nit: move this closer to the two places that use i
Roger Tawa OOO till Jul 10th 2011/08/30 16:19:31 This is the closest given the nesting of the if bl
sky 2011/08/30 16:44:28 I was misreading the code. It's fine, leave it whe
416
375 // Check if this is a singleton tab that already exists 417 // Check if this is a singleton tab that already exists
376 int singleton_index = GetIndexOfSingletonTab(params); 418 int singleton_index = GetIndexOfSingletonTab(params);
377 419
378 // If no target TabContents was specified, we need to construct one if we are 420 // If no target TabContents was specified, we need to construct one if we are
379 // supposed to target a new tab; unless it's a singleton that already exists. 421 // supposed to target a new tab; unless it's a singleton that already exists.
380 if (!params->target_contents && singleton_index < 0) { 422 if (!params->target_contents && singleton_index < 0) {
381 GURL url = params->url.is_empty() ? params->browser->GetHomePage() 423 GURL url;
382 : params->url; 424 if (params->url.is_empty()) {
425 url = params->browser->GetHomePage();
426 params->transition |= PageTransition::HOME_PAGE;
427 } else {
428 url = params->url;
429 }
430
383 if (params->disposition != CURRENT_TAB) { 431 if (params->disposition != CURRENT_TAB) {
384 TabContents* source_contents = params->source_contents ? 432 TabContents* source_contents = params->source_contents ?
385 params->source_contents->tab_contents() : NULL; 433 params->source_contents->tab_contents() : NULL;
386 params->target_contents = 434 params->target_contents =
387 Browser::TabContentsFactory( 435 Browser::TabContentsFactory(
388 params->browser->profile(), 436 params->browser->profile(),
389 tab_util::GetSiteInstanceForNewTab( 437 tab_util::GetSiteInstanceForNewTab(
390 source_contents, params->browser->profile(), url), 438 source_contents, params->browser->profile(), url),
391 MSG_ROUTING_NONE, 439 MSG_ROUTING_NONE,
392 source_contents, 440 source_contents,
(...skipping 16 matching lines...) Expand all
409 // same as the source. 457 // same as the source.
410 params->target_contents = params->source_contents; 458 params->target_contents = params->source_contents;
411 DCHECK(params->target_contents); 459 DCHECK(params->target_contents);
412 } 460 }
413 461
414 if (user_initiated) { 462 if (user_initiated) {
415 static_cast<RenderViewHostDelegate*>(params->target_contents-> 463 static_cast<RenderViewHostDelegate*>(params->target_contents->
416 tab_contents())->OnUserGesture(); 464 tab_contents())->OnUserGesture();
417 } 465 }
418 466
467 InitializeExtraHeaders(params, params->target_contents->profile(),
468 &extra_headers);
469
419 // Try to handle non-navigational URLs that popup dialogs and such, these 470 // Try to handle non-navigational URLs that popup dialogs and such, these
420 // should not actually navigate. 471 // should not actually navigate.
421 if (!HandleNonNavigationAboutURL(url)) { 472 if (!HandleNonNavigationAboutURL(url)) {
422 // Perform the actual navigation. 473 // Perform the actual navigation.
423 params->target_contents->controller().LoadURL(url, params->referrer, 474 params->target_contents->controller().LoadURLWithHeaders(
424 params->transition); 475 url, params->referrer, params->transition, extra_headers);
425 } 476 }
426 } else { 477 } else {
427 // |target_contents| was specified non-NULL, and so we assume it has already 478 // |target_contents| was specified non-NULL, and so we assume it has already
428 // been navigated appropriately. We need to do nothing more other than 479 // been navigated appropriately. We need to do nothing more other than
429 // add it to the appropriate tabstrip. 480 // add it to the appropriate tabstrip.
430 } 481 }
431 482
432 // If the user navigated from the omnibox, and the selected tab is going to 483 // If the user navigated from the omnibox, and the selected tab is going to
433 // lose focus, then make sure the focus for the source tab goes away from the 484 // lose focus, then make sure the focus for the source tab goes away from the
434 // omnibox. 485 // omnibox.
(...skipping 26 matching lines...) Expand all
461 target_contents_owner.ReleaseOwnership(); 512 target_contents_owner.ReleaseOwnership();
462 } 513 }
463 514
464 if (singleton_index >= 0) { 515 if (singleton_index >= 0) {
465 TabContents* target = params->browser->GetTabContentsAt(singleton_index); 516 TabContents* target = params->browser->GetTabContentsAt(singleton_index);
466 517
467 if (target->is_crashed()) { 518 if (target->is_crashed()) {
468 target->controller().Reload(true); 519 target->controller().Reload(true);
469 } else if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE && 520 } else if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE &&
470 target->GetURL() != params->url) { 521 target->GetURL() != params->url) {
471 target->controller().LoadURL( 522 InitializeExtraHeaders(params, NULL, &extra_headers);
472 params->url, params->referrer, params->transition); 523 target->controller().LoadURLWithHeaders(
524 params->url, params->referrer, params->transition, extra_headers);
473 } 525 }
474 526
475 // If the singleton tab isn't already selected, select it. 527 // If the singleton tab isn't already selected, select it.
476 if (params->source_contents != params->target_contents) 528 if (params->source_contents != params->target_contents)
477 params->browser->ActivateTabAt(singleton_index, user_initiated); 529 params->browser->ActivateTabAt(singleton_index, user_initiated);
478 } 530 }
479 } 531 }
480 532
481 // Returns the index of an existing singleton tab in |params->browser| matching 533 // Returns the index of an existing singleton tab in |params->browser| matching
482 // the URL specified in |params|. 534 // the URL specified in |params|.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 rewritten_url, replacements)) { 569 rewritten_url, replacements)) {
518 params->target_contents = tab; 570 params->target_contents = tab;
519 return tab_index; 571 return tab_index;
520 } 572 }
521 } 573 }
522 574
523 return -1; 575 return -1;
524 } 576 }
525 577
526 } // namespace browser 578 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698