| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // technically an incognito window, these URLs are allowed. | 67 // technically an incognito window, these URLs are allowed. |
| 68 // Returns true on success. Otherwise, if changing params leads the browser into | 68 // Returns true on success. Otherwise, if changing params leads the browser into |
| 69 // an erroneous state, returns false. | 69 // an erroneous state, returns false. |
| 70 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { | 70 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { |
| 71 if (params->target_contents != NULL || | 71 if (params->target_contents != NULL || |
| 72 chrome::IsURLAllowedInIncognito(params->url) || | 72 chrome::IsURLAllowedInIncognito(params->url) || |
| 73 Profile::IsGuestSession()) { | 73 Profile::IsGuestSession()) { |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 Profile* profile = params->browser->profile(); | 77 Profile* profile = params->initiating_profile; |
| 78 | 78 |
| 79 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { | 79 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { |
| 80 profile = profile->GetOriginalProfile(); | 80 profile = profile->GetOriginalProfile(); |
| 81 | 81 |
| 82 // If incognito is forced, we punt. | 82 // If incognito is forced, we punt. |
| 83 PrefService* prefs = profile->GetPrefs(); | 83 PrefService* prefs = profile->GetPrefs(); |
| 84 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == | 84 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == |
| 85 IncognitoModePrefs::FORCED) { | 85 IncognitoModePrefs::FORCED) { |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 params->disposition = SINGLETON_TAB; | 89 params->disposition = SINGLETON_TAB; |
| 90 params->browser = browser::FindOrCreateTabbedBrowser(profile); | 90 params->browser = browser::FindOrCreateTabbedBrowser(profile); |
| 91 params->window_action = chrome::NavigateParams::SHOW_WINDOW; | 91 params->window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 92 } | 92 } |
| 93 | 93 |
| 94 return true; | 94 return true; |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Returns a Browser that can host the navigation or tab addition specified in | 97 // Returns a Browser that can host the navigation or tab addition specified in |
| 98 // |params|. This might just return the same Browser specified in |params|, or | 98 // |params|. This might just return the same Browser specified in |params|, or |
| 99 // some other if that Browser is deemed incompatible. | 99 // some other if that Browser is deemed incompatible. |
| 100 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { | 100 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { |
| 101 // If no source TabContents was specified, we use the selected one from | 101 // If no source TabContents was specified, we use the selected one from |
| 102 // the target browser. This must happen first, before | 102 // the target browser. This must happen first, before |
| 103 // GetBrowserForDisposition() has a chance to replace |params->browser| with | 103 // GetBrowserForDisposition() has a chance to replace |params->browser| with |
| 104 // another one. | 104 // another one. |
| 105 if (!params->source_contents) | 105 if (!params->source_contents && params->browser) |
| 106 params->source_contents = chrome::GetActiveTabContents(params->browser); | 106 params->source_contents = chrome::GetActiveTabContents(params->browser); |
| 107 | 107 |
| 108 Profile* profile = params->browser->profile(); | 108 Profile* profile = params->initiating_profile; |
| 109 | 109 |
| 110 switch (params->disposition) { | 110 switch (params->disposition) { |
| 111 case CURRENT_TAB: | 111 case CURRENT_TAB: |
| 112 return params->browser; | 112 if (params->browser) |
| 113 return params->browser; |
| 114 // Find a compatible window and re-execute this command in it. Otherwise |
| 115 // re-run with NEW_WINDOW. |
| 116 return GetOrCreateBrowser(profile); |
| 113 case SINGLETON_TAB: | 117 case SINGLETON_TAB: |
| 114 case NEW_FOREGROUND_TAB: | 118 case NEW_FOREGROUND_TAB: |
| 115 case NEW_BACKGROUND_TAB: | 119 case NEW_BACKGROUND_TAB: |
| 116 // See if we can open the tab in the window this navigator is bound to. | 120 // See if we can open the tab in the window this navigator is bound to. |
| 117 if (WindowCanOpenTabs(params->browser)) | 121 if (params->browser && WindowCanOpenTabs(params->browser)) |
| 118 return params->browser; | 122 return params->browser; |
| 119 // Find a compatible window and re-execute this command in it. Otherwise | 123 // Find a compatible window and re-execute this command in it. Otherwise |
| 120 // re-run with NEW_WINDOW. | 124 // re-run with NEW_WINDOW. |
| 121 return GetOrCreateBrowser(profile); | 125 return GetOrCreateBrowser(profile); |
| 122 case NEW_POPUP: { | 126 case NEW_POPUP: { |
| 123 // Make a new popup window. | 127 // Make a new popup window. |
| 124 // Coerce app-style if |source| represents an app. | 128 // Coerce app-style if |source| represents an app. |
| 125 std::string app_name; | 129 std::string app_name; |
| 126 if (!params->extension_app_id.empty()) { | 130 if (!params->extension_app_id.empty()) { |
| 127 app_name = web_app::GenerateApplicationNameFromExtensionId( | 131 app_name = web_app::GenerateApplicationNameFromExtensionId( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 case SINGLETON_TAB: | 201 case SINGLETON_TAB: |
| 198 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE; | 202 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE; |
| 199 break; | 203 break; |
| 200 | 204 |
| 201 default: | 205 default: |
| 202 break; | 206 break; |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 // Obtain the profile used by the code that originated the Navigate() request. | 210 // Obtain the profile used by the code that originated the Navigate() request. |
| 207 // |source_browser| represents the Browser that was supplied in |params| before | 211 Profile* GetSourceProfile(chrome::NavigateParams* params) { |
| 208 // it was modified. | |
| 209 Profile* GetSourceProfile(chrome::NavigateParams* params, | |
| 210 Browser* source_browser) { | |
| 211 if (params->source_contents) | 212 if (params->source_contents) |
| 212 return params->source_contents->profile(); | 213 return params->source_contents->profile(); |
| 213 | 214 |
| 214 return source_browser->profile(); | 215 return params->initiating_profile; |
| 215 } | 216 } |
| 216 | 217 |
| 217 void LoadURLInContents(WebContents* target_contents, | 218 void LoadURLInContents(WebContents* target_contents, |
| 218 const GURL& url, | 219 const GURL& url, |
| 219 chrome::NavigateParams* params, | 220 chrome::NavigateParams* params, |
| 220 const std::string& extra_headers) { | 221 const std::string& extra_headers) { |
| 221 content::NavigationController::LoadURLParams load_url_params(url); | 222 content::NavigationController::LoadURLParams load_url_params(url); |
| 222 load_url_params.referrer = params->referrer; | 223 load_url_params.referrer = params->referrer; |
| 223 load_url_params.transition_type = params->transition; | 224 load_url_params.transition_type = params->transition; |
| 224 load_url_params.extra_headers = extra_headers; | 225 load_url_params.extra_headers = extra_headers; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 source_contents(NULL), | 338 source_contents(NULL), |
| 338 disposition(CURRENT_TAB), | 339 disposition(CURRENT_TAB), |
| 339 transition(a_transition), | 340 transition(a_transition), |
| 340 is_renderer_initiated(false), | 341 is_renderer_initiated(false), |
| 341 tabstrip_index(-1), | 342 tabstrip_index(-1), |
| 342 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 343 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
| 343 window_action(NO_ACTION), | 344 window_action(NO_ACTION), |
| 344 user_gesture(true), | 345 user_gesture(true), |
| 345 path_behavior(RESPECT), | 346 path_behavior(RESPECT), |
| 346 ref_behavior(IGNORE_REF), | 347 ref_behavior(IGNORE_REF), |
| 347 browser(a_browser) { | 348 browser(a_browser), |
| 348 } | 349 initiating_profile(NULL) {} |
| 349 | 350 |
| 350 NavigateParams::NavigateParams(Browser* a_browser, | 351 NavigateParams::NavigateParams(Browser* a_browser, |
| 351 TabContents* a_target_contents) | 352 TabContents* a_target_contents) |
| 352 : target_contents(a_target_contents), | 353 : target_contents(a_target_contents), |
| 353 source_contents(NULL), | 354 source_contents(NULL), |
| 354 disposition(CURRENT_TAB), | 355 disposition(CURRENT_TAB), |
| 355 transition(content::PAGE_TRANSITION_LINK), | 356 transition(content::PAGE_TRANSITION_LINK), |
| 356 is_renderer_initiated(false), | 357 is_renderer_initiated(false), |
| 357 tabstrip_index(-1), | 358 tabstrip_index(-1), |
| 358 tabstrip_add_types(TabStripModel::ADD_ACTIVE), | 359 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
| 359 window_action(NO_ACTION), | 360 window_action(NO_ACTION), |
| 360 user_gesture(true), | 361 user_gesture(true), |
| 361 path_behavior(RESPECT), | 362 path_behavior(RESPECT), |
| 362 ref_behavior(IGNORE_REF), | 363 ref_behavior(IGNORE_REF), |
| 363 browser(a_browser) { | 364 browser(a_browser), |
| 364 } | 365 initiating_profile(NULL) {} |
| 365 | 366 |
| 366 NavigateParams::~NavigateParams() { | 367 NavigateParams::NavigateParams(Profile* a_profile, |
| 367 } | 368 const GURL& a_url, |
| 369 content::PageTransition a_transition) |
| 370 : url(a_url), |
| 371 target_contents(NULL), |
| 372 source_contents(NULL), |
| 373 disposition(NEW_FOREGROUND_TAB), |
| 374 transition(a_transition), |
| 375 is_renderer_initiated(false), |
| 376 tabstrip_index(-1), |
| 377 tabstrip_add_types(TabStripModel::ADD_ACTIVE), |
| 378 window_action(SHOW_WINDOW), |
| 379 user_gesture(true), |
| 380 path_behavior(RESPECT), |
| 381 ref_behavior(IGNORE_REF), |
| 382 browser(NULL), |
| 383 initiating_profile(a_profile) {} |
| 384 |
| 385 NavigateParams::~NavigateParams() {} |
| 368 | 386 |
| 369 void Navigate(NavigateParams* params) { | 387 void Navigate(NavigateParams* params) { |
| 370 Browser* source_browser = params->browser; | 388 Browser* source_browser = params->browser; |
| 389 if (source_browser) |
| 390 params->initiating_profile = source_browser->profile(); |
| 391 DCHECK(params->initiating_profile); |
| 371 | 392 |
| 372 if (!AdjustNavigateParamsForURL(params)) | 393 if (!AdjustNavigateParamsForURL(params)) |
| 373 return; | 394 return; |
| 374 | 395 |
| 375 // The browser window may want to adjust the disposition. | 396 // The browser window may want to adjust the disposition. |
| 376 if (params->disposition == NEW_POPUP && source_browser->window()) { | 397 if (params->disposition == NEW_POPUP && |
| 398 source_browser && |
| 399 source_browser->window()) { |
| 377 params->disposition = | 400 params->disposition = |
| 378 source_browser->window()->GetDispositionForPopupBounds( | 401 source_browser->window()->GetDispositionForPopupBounds( |
| 379 params->window_bounds); | 402 params->window_bounds); |
| 380 } | 403 } |
| 381 | 404 |
| 382 // Adjust disposition for the navigation happending in the sad page of the | 405 // Adjust disposition for the navigation happending in the sad page of the |
| 383 // panel window. | 406 // panel window. |
| 384 if (params->source_contents && | 407 if (params->source_contents && |
| 385 params->source_contents->web_contents()->IsCrashed() && | 408 params->source_contents->web_contents()->IsCrashed() && |
| 386 params->disposition == CURRENT_TAB && | 409 params->disposition == CURRENT_TAB && |
| 410 params->browser && |
| 387 params->browser->is_type_panel()) { | 411 params->browser->is_type_panel()) { |
| 388 params->disposition = NEW_FOREGROUND_TAB; | 412 params->disposition = NEW_FOREGROUND_TAB; |
| 389 } | 413 } |
| 390 | 414 |
| 391 params->browser = GetBrowserForDisposition(params); | 415 params->browser = GetBrowserForDisposition(params); |
| 392 | 416 |
| 393 if (!params->browser) | 417 if (!params->browser) |
| 394 return; | 418 return; |
| 395 | 419 |
| 396 // Navigate() must not return early after this point. | 420 // Navigate() must not return early after this point. |
| 397 | 421 |
| 398 if (GetSourceProfile(params, source_browser) != params->browser->profile()) { | 422 if (GetSourceProfile(params) != params->browser->profile()) { |
| 399 // A tab is being opened from a link from a different profile, we must reset | 423 // A tab is being opened from a link from a different profile, we must reset |
| 400 // source information that may cause state to be shared. | 424 // source information that may cause state to be shared. |
| 401 params->source_contents = NULL; | 425 params->source_contents = NULL; |
| 402 params->referrer = content::Referrer(); | 426 params->referrer = content::Referrer(); |
| 403 } | 427 } |
| 404 | 428 |
| 405 // Make sure the Browser is shown if params call for it. | 429 // Make sure the Browser is shown if params call for it. |
| 406 ScopedBrowserDisplayer displayer(params); | 430 ScopedBrowserDisplayer displayer(params); |
| 407 | 431 |
| 408 // Makes sure any TabContents created by this function is destroyed if | 432 // Makes sure any TabContents created by this function is destroyed if |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return !(url.scheme() == chrome::kChromeUIScheme && | 601 return !(url.scheme() == chrome::kChromeUIScheme && |
| 578 (url.host() == chrome::kChromeUISettingsHost || | 602 (url.host() == chrome::kChromeUISettingsHost || |
| 579 url.host() == chrome::kChromeUISettingsFrameHost || | 603 url.host() == chrome::kChromeUISettingsFrameHost || |
| 580 url.host() == chrome::kChromeUIExtensionsHost || | 604 url.host() == chrome::kChromeUIExtensionsHost || |
| 581 url.host() == chrome::kChromeUIBookmarksHost || | 605 url.host() == chrome::kChromeUIBookmarksHost || |
| 582 url.host() == chrome::kChromeUISyncPromoHost || | 606 url.host() == chrome::kChromeUISyncPromoHost || |
| 583 url.host() == chrome::kChromeUIUberHost)); | 607 url.host() == chrome::kChromeUIUberHost)); |
| 584 } | 608 } |
| 585 | 609 |
| 586 } // namespace chrome | 610 } // namespace chrome |
| OLD | NEW |