| 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_about_handler.h" | 10 #include "chrome/browser/browser_about_handler.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const GURL& other, | 76 const GURL& other, |
| 77 const url_canon::Replacements<char>& replacements) { | 77 const url_canon::Replacements<char>& replacements) { |
| 78 if (url == other) | 78 if (url == other) |
| 79 return true; | 79 return true; |
| 80 | 80 |
| 81 GURL url_replaced = url.ReplaceComponents(replacements); | 81 GURL url_replaced = url.ReplaceComponents(replacements); |
| 82 GURL other_replaced = other.ReplaceComponents(replacements); | 82 GURL other_replaced = other.ReplaceComponents(replacements); |
| 83 return url_replaced == other_replaced; | 83 return url_replaced == other_replaced; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Returns the index of an existing singleton tab in |params->browser| matching | |
| 87 // the URL specified in |params|. | |
| 88 int GetIndexOfSingletonTab(browser::NavigateParams* params) { | |
| 89 if (params->disposition != SINGLETON_TAB) | |
| 90 return -1; | |
| 91 | |
| 92 // In case the URL was rewritten by the BrowserURLHandler we need to ensure | |
| 93 // that we do not open another URL that will get redirected to the rewritten | |
| 94 // URL. | |
| 95 GURL rewritten_url(params->url); | |
| 96 bool reverse_on_redirect = false; | |
| 97 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | |
| 98 &rewritten_url, | |
| 99 params->browser->profile(), | |
| 100 &reverse_on_redirect); | |
| 101 | |
| 102 // If there are several matches: prefer the active tab by starting there. | |
| 103 int start_index = std::max(0, params->browser->active_index()); | |
| 104 int tab_count = params->browser->tab_count(); | |
| 105 for (int i = 0; i < tab_count; ++i) { | |
| 106 int tab_index = (start_index + i) % tab_count; | |
| 107 TabContentsWrapper* tab = | |
| 108 params->browser->GetTabContentsWrapperAt(tab_index); | |
| 109 | |
| 110 url_canon::Replacements<char> replacements; | |
| 111 replacements.ClearRef(); | |
| 112 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE || | |
| 113 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) { | |
| 114 replacements.ClearPath(); | |
| 115 replacements.ClearQuery(); | |
| 116 } | |
| 117 | |
| 118 if (CompareURLsWithReplacements(tab->tab_contents()->GetURL(), | |
| 119 params->url, replacements) || | |
| 120 CompareURLsWithReplacements(tab->tab_contents()->GetURL(), | |
| 121 rewritten_url, replacements)) { | |
| 122 params->target_contents = tab; | |
| 123 return tab_index; | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 return -1; | |
| 128 } | |
| 129 | |
| 130 // Change some of the navigation parameters based on the particular URL. | 86 // Change some of the navigation parameters based on the particular URL. |
| 131 // Currently this applies to chrome://settings and the bookmark manager, | 87 // Currently this applies to chrome://settings and the bookmark manager, |
| 132 // which we always want to open in a normal (not incognito) window. Guest | 88 // which we always want to open in a normal (not incognito) window. Guest |
| 133 // session is an exception. | 89 // session is an exception. |
| 134 void AdjustNavigateParamsForURL(browser::NavigateParams* params) { | 90 void AdjustNavigateParamsForURL(browser::NavigateParams* params) { |
| 135 if (!params->target_contents && | 91 if (!params->target_contents && |
| 136 params->url.scheme() == chrome::kChromeUIScheme && | 92 params->url.scheme() == chrome::kChromeUIScheme && |
| 137 (params->url.host() == chrome::kChromeUISettingsHost || | 93 (params->url.host() == chrome::kChromeUISettingsHost || |
| 138 params->url.host() == chrome::kChromeUIBookmarksHost)) { | 94 params->url.host() == chrome::kChromeUIBookmarksHost)) { |
| 139 Profile* profile = | 95 Profile* profile = |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 target->controller().LoadURL( | 483 target->controller().LoadURL( |
| 528 params->url, params->referrer, params->transition); | 484 params->url, params->referrer, params->transition); |
| 529 } | 485 } |
| 530 | 486 |
| 531 // If the singleton tab isn't already selected, select it. | 487 // If the singleton tab isn't already selected, select it. |
| 532 if (params->source_contents != params->target_contents) | 488 if (params->source_contents != params->target_contents) |
| 533 params->browser->ActivateTabAt(singleton_index, user_initiated); | 489 params->browser->ActivateTabAt(singleton_index, user_initiated); |
| 534 } | 490 } |
| 535 } | 491 } |
| 536 | 492 |
| 493 // Returns the index of an existing singleton tab in |params->browser| matching |
| 494 // the URL specified in |params|. |
| 495 int GetIndexOfSingletonTab(browser::NavigateParams* params) { |
| 496 if (params->disposition != SINGLETON_TAB) |
| 497 return -1; |
| 498 |
| 499 // In case the URL was rewritten by the BrowserURLHandler we need to ensure |
| 500 // that we do not open another URL that will get redirected to the rewritten |
| 501 // URL. |
| 502 GURL rewritten_url(params->url); |
| 503 bool reverse_on_redirect = false; |
| 504 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 505 &rewritten_url, |
| 506 params->browser->profile(), |
| 507 &reverse_on_redirect); |
| 508 |
| 509 // If there are several matches: prefer the active tab by starting there. |
| 510 int start_index = std::max(0, params->browser->active_index()); |
| 511 int tab_count = params->browser->tab_count(); |
| 512 for (int i = 0; i < tab_count; ++i) { |
| 513 int tab_index = (start_index + i) % tab_count; |
| 514 TabContentsWrapper* tab = |
| 515 params->browser->GetTabContentsWrapperAt(tab_index); |
| 516 |
| 517 url_canon::Replacements<char> replacements; |
| 518 replacements.ClearRef(); |
| 519 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE || |
| 520 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) { |
| 521 replacements.ClearPath(); |
| 522 replacements.ClearQuery(); |
| 523 } |
| 524 |
| 525 if (CompareURLsWithReplacements(tab->tab_contents()->GetURL(), |
| 526 params->url, replacements) || |
| 527 CompareURLsWithReplacements(tab->tab_contents()->GetURL(), |
| 528 rewritten_url, replacements)) { |
| 529 params->target_contents = tab; |
| 530 return tab_index; |
| 531 } |
| 532 } |
| 533 |
| 534 return -1; |
| 535 } |
| 536 |
| 537 } // namespace browser | 537 } // namespace browser |
| OLD | NEW |