| 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 "chrome/browser/browser_url_handler.h" | 10 #include "chrome/browser/browser_url_handler.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const GURL& a_url, | 339 const GURL& a_url, |
| 340 PageTransition::Type a_transition) | 340 PageTransition::Type a_transition) |
| 341 : url(a_url), | 341 : url(a_url), |
| 342 target_contents(NULL), | 342 target_contents(NULL), |
| 343 source_contents(NULL), | 343 source_contents(NULL), |
| 344 disposition(CURRENT_TAB), | 344 disposition(CURRENT_TAB), |
| 345 transition(a_transition), | 345 transition(a_transition), |
| 346 tabstrip_index(-1), | 346 tabstrip_index(-1), |
| 347 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 347 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
| 348 window_action(NO_ACTION), | 348 window_action(NO_ACTION), |
| 349 user_gesture(true), |
| 349 path_behavior(RESPECT), | 350 path_behavior(RESPECT), |
| 350 browser(a_browser), | 351 browser(a_browser), |
| 351 profile(NULL) { | 352 profile(NULL) { |
| 352 } | 353 } |
| 353 | 354 |
| 354 NavigateParams::NavigateParams(Browser* a_browser, | 355 NavigateParams::NavigateParams(Browser* a_browser, |
| 355 TabContentsWrapper* a_target_contents) | 356 TabContentsWrapper* a_target_contents) |
| 356 : target_contents(a_target_contents), | 357 : target_contents(a_target_contents), |
| 357 source_contents(NULL), | 358 source_contents(NULL), |
| 358 disposition(CURRENT_TAB), | 359 disposition(CURRENT_TAB), |
| 359 transition(PageTransition::LINK), | 360 transition(PageTransition::LINK), |
| 360 tabstrip_index(-1), | 361 tabstrip_index(-1), |
| 361 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 362 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
| 362 window_action(NO_ACTION), | 363 window_action(NO_ACTION), |
| 364 user_gesture(true), |
| 363 path_behavior(RESPECT), | 365 path_behavior(RESPECT), |
| 364 browser(a_browser), | 366 browser(a_browser), |
| 365 profile(NULL) { | 367 profile(NULL) { |
| 366 } | 368 } |
| 367 | 369 |
| 368 NavigateParams::~NavigateParams() { | 370 NavigateParams::~NavigateParams() { |
| 369 } | 371 } |
| 370 | 372 |
| 371 void Navigate(NavigateParams* params) { | 373 void Navigate(NavigateParams* params) { |
| 372 Browser* source_browser = params->browser; | 374 Browser* source_browser = params->browser; |
| 373 AdjustNavigateParamsForURL(params); | 375 AdjustNavigateParamsForURL(params); |
| 374 | 376 |
| 377 // Adjust disposition based on size of popup window. |
| 378 if (params->disposition == NEW_POPUP && |
| 379 (source_browser && source_browser->window())) { |
| 380 params->disposition = |
| 381 source_browser->window()->GetDispositionForPopupBounds( |
| 382 params->window_bounds); |
| 383 } |
| 384 |
| 375 params->browser = GetBrowserForDisposition(params); | 385 params->browser = GetBrowserForDisposition(params); |
| 376 if (!params->browser) | 386 if (!params->browser) |
| 377 return; | 387 return; |
| 378 // Navigate() must not return early after this point. | 388 // Navigate() must not return early after this point. |
| 379 | 389 |
| 380 if (GetSourceProfile(params, source_browser) != params->browser->profile()) { | 390 if (GetSourceProfile(params, source_browser) != params->browser->profile()) { |
| 381 // A tab is being opened from a link from a different profile, we must reset | 391 // A tab is being opened from a link from a different profile, we must reset |
| 382 // source information that may cause state to be shared. | 392 // source information that may cause state to be shared. |
| 383 params->source_contents = NULL; | 393 params->source_contents = NULL; |
| 384 params->referrer = GURL(); | 394 params->referrer = GURL(); |
| 385 } | 395 } |
| 386 | 396 |
| 387 if (params->window_action == browser::NavigateParams::NO_ACTION && | |
| 388 source_browser != params->browser && | |
| 389 params->browser->tabstrip_model()->empty()) { | |
| 390 // A new window has been created. So it needs to be displayed. | |
| 391 params->window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 392 } | |
| 393 | |
| 394 // Make sure the Browser is shown if params call for it. | 397 // Make sure the Browser is shown if params call for it. |
| 395 ScopedBrowserDisplayer displayer(params); | 398 ScopedBrowserDisplayer displayer(params); |
| 396 | 399 |
| 397 // Makes sure any TabContents created by this function is destroyed if | 400 // Makes sure any TabContents created by this function is destroyed if |
| 398 // not properly added to a tab strip. | 401 // not properly added to a tab strip. |
| 399 ScopedTargetContentsOwner target_contents_owner(params); | 402 ScopedTargetContentsOwner target_contents_owner(params); |
| 400 | 403 |
| 401 // Some dispositions need coercion to base types. | 404 // Some dispositions need coercion to base types. |
| 402 NormalizeDisposition(params); | 405 NormalizeDisposition(params); |
| 403 | 406 |
| 407 // If a new window has been created, it needs to be displayed. |
| 408 if (params->window_action == browser::NavigateParams::NO_ACTION && |
| 409 source_browser != params->browser && |
| 410 params->browser->tabstrip_model()->empty()) { |
| 411 params->window_action = browser::NavigateParams::SHOW_WINDOW; |
| 412 } |
| 413 |
| 414 // If we create a popup window from a non user-gesture, don't activate it. |
| 415 if (params->window_action == browser::NavigateParams::SHOW_WINDOW && |
| 416 params->disposition == NEW_POPUP && |
| 417 params->user_gesture == false) { |
| 418 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; |
| 419 } |
| 420 |
| 404 // Determine if the navigation was user initiated. If it was, we need to | 421 // Determine if the navigation was user initiated. If it was, we need to |
| 405 // inform the target TabContents, and we may need to update the UI. | 422 // inform the target TabContents, and we may need to update the UI. |
| 406 PageTransition::Type base_transition = | 423 PageTransition::Type base_transition = |
| 407 PageTransition::StripQualifier(params->transition); | 424 PageTransition::StripQualifier(params->transition); |
| 408 bool user_initiated = base_transition == PageTransition::TYPED || | 425 bool user_initiated = base_transition == PageTransition::TYPED || |
| 409 base_transition == PageTransition::AUTO_BOOKMARK; | 426 base_transition == PageTransition::AUTO_BOOKMARK; |
| 410 | 427 |
| 411 // Check if this is a singleton tab that already exists | 428 // Check if this is a singleton tab that already exists |
| 412 int singleton_index = GetIndexOfSingletonTab(params); | 429 int singleton_index = GetIndexOfSingletonTab(params); |
| 413 | 430 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 params->url, params->referrer, params->transition); | 509 params->url, params->referrer, params->transition); |
| 493 } | 510 } |
| 494 | 511 |
| 495 // If the singleton tab isn't already selected, select it. | 512 // If the singleton tab isn't already selected, select it. |
| 496 if (params->source_contents != params->target_contents) | 513 if (params->source_contents != params->target_contents) |
| 497 params->browser->ActivateTabAt(singleton_index, user_initiated); | 514 params->browser->ActivateTabAt(singleton_index, user_initiated); |
| 498 } | 515 } |
| 499 } | 516 } |
| 500 | 517 |
| 501 } // namespace browser | 518 } // namespace browser |
| OLD | NEW |