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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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) 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/singleton_tabs.h" 5 #include "chrome/browser/ui/singleton_tabs.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_navigator.h" 9 #include "chrome/browser/ui/browser_navigator.h"
10 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/browser_url_handler.h" 13 #include "content/public/browser/browser_url_handler.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 15
15 namespace chrome { 16 namespace chrome {
16 namespace { 17 namespace {
17 18
18 // Returns true if two URLs are equal after taking |replacements| into account. 19 // Returns true if two URLs are equal after taking |replacements| into account.
19 bool CompareURLsWithReplacements( 20 bool CompareURLsWithReplacements(
(...skipping 17 matching lines...) Expand all
37 38
38 void ShowSingletonTabRespectRef(Browser* browser, const GURL& url) { 39 void ShowSingletonTabRespectRef(Browser* browser, const GURL& url) {
39 browser::NavigateParams params(GetSingletonTabNavigateParams(browser, url)); 40 browser::NavigateParams params(GetSingletonTabNavigateParams(browser, url));
40 params.ref_behavior = browser::NavigateParams::RESPECT_REF; 41 params.ref_behavior = browser::NavigateParams::RESPECT_REF;
41 browser::Navigate(&params); 42 browser::Navigate(&params);
42 } 43 }
43 44
44 void ShowSingletonTabOverwritingNTP(Browser* browser, 45 void ShowSingletonTabOverwritingNTP(Browser* browser,
45 const browser::NavigateParams& params) { 46 const browser::NavigateParams& params) {
46 browser::NavigateParams local_params(params); 47 browser::NavigateParams local_params(params);
47 content::WebContents* contents = browser->GetActiveWebContents(); 48 content::WebContents* contents = chrome::GetActiveWebContents(browser);
48 if (contents) { 49 if (contents) {
49 const GURL& contents_url = contents->GetURL(); 50 const GURL& contents_url = contents->GetURL();
50 if ((contents_url == GURL(chrome::kChromeUINewTabURL) || 51 if ((contents_url == GURL(chrome::kChromeUINewTabURL) ||
51 contents_url == GURL(chrome::kAboutBlankURL)) && 52 contents_url == GURL(chrome::kAboutBlankURL)) &&
52 GetIndexOfSingletonTab(&local_params) < 0) { 53 GetIndexOfSingletonTab(&local_params) < 0) {
53 local_params.disposition = CURRENT_TAB; 54 local_params.disposition = CURRENT_TAB;
54 } 55 }
55 } 56 }
56 57
57 browser::Navigate(&local_params); 58 browser::Navigate(&local_params);
(...skipping 24 matching lines...) Expand all
82 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 83 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
83 &rewritten_url, 84 &rewritten_url,
84 params->browser->profile(), 85 params->browser->profile(),
85 &reverse_on_redirect); 86 &reverse_on_redirect);
86 87
87 // If there are several matches: prefer the active tab by starting there. 88 // If there are several matches: prefer the active tab by starting there.
88 int start_index = std::max(0, params->browser->active_index()); 89 int start_index = std::max(0, params->browser->active_index());
89 int tab_count = params->browser->tab_count(); 90 int tab_count = params->browser->tab_count();
90 for (int i = 0; i < tab_count; ++i) { 91 for (int i = 0; i < tab_count; ++i) {
91 int tab_index = (start_index + i) % tab_count; 92 int tab_index = (start_index + i) % tab_count;
92 TabContents* tab = params->browser->GetTabContentsAt(tab_index); 93 TabContents* tab = chrome::GetTabContentsAt(params->browser, tab_index);
93 94
94 url_canon::Replacements<char> replacements; 95 url_canon::Replacements<char> replacements;
95 if (params->ref_behavior == browser::NavigateParams::IGNORE_REF) 96 if (params->ref_behavior == browser::NavigateParams::IGNORE_REF)
96 replacements.ClearRef(); 97 replacements.ClearRef();
97 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE || 98 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE ||
98 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) { 99 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) {
99 replacements.ClearPath(); 100 replacements.ClearPath();
100 replacements.ClearQuery(); 101 replacements.ClearQuery();
101 } 102 }
102 103
103 if (CompareURLsWithReplacements(tab->web_contents()->GetURL(), 104 if (CompareURLsWithReplacements(tab->web_contents()->GetURL(),
104 params->url, replacements) || 105 params->url, replacements) ||
105 CompareURLsWithReplacements(tab->web_contents()->GetURL(), 106 CompareURLsWithReplacements(tab->web_contents()->GetURL(),
106 rewritten_url, replacements)) { 107 rewritten_url, replacements)) {
107 params->target_contents = tab; 108 params->target_contents = tab;
108 return tab_index; 109 return tab_index;
109 } 110 }
110 } 111 }
111 112
112 return -1; 113 return -1;
113 } 114 }
114 115
115 116
116 } // namespace chrome 117 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_delegate_unittest.cc ('k') | chrome/browser/ui/startup/autolaunch_prompt_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698