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

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

Issue 10698068: chrome: Put browser_navigator.h into chrome namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: already in chrome namespace 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/browser_tabstrip.h"
(...skipping 14 matching lines...) Expand all
25 return true; 25 return true;
26 26
27 GURL url_replaced = url.ReplaceComponents(replacements); 27 GURL url_replaced = url.ReplaceComponents(replacements);
28 GURL other_replaced = other.ReplaceComponents(replacements); 28 GURL other_replaced = other.ReplaceComponents(replacements);
29 return url_replaced == other_replaced; 29 return url_replaced == other_replaced;
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 void ShowSingletonTab(Browser* browser, const GURL& url) { 34 void ShowSingletonTab(Browser* browser, const GURL& url) {
35 browser::NavigateParams params(GetSingletonTabNavigateParams(browser, url)); 35 NavigateParams params(GetSingletonTabNavigateParams(browser, url));
36 browser::Navigate(&params); 36 Navigate(&params);
37 } 37 }
38 38
39 void ShowSingletonTabRespectRef(Browser* browser, const GURL& url) { 39 void ShowSingletonTabRespectRef(Browser* browser, const GURL& url) {
40 browser::NavigateParams params(GetSingletonTabNavigateParams(browser, url)); 40 NavigateParams params(GetSingletonTabNavigateParams(browser, url));
41 params.ref_behavior = browser::NavigateParams::RESPECT_REF; 41 params.ref_behavior = NavigateParams::RESPECT_REF;
42 browser::Navigate(&params); 42 Navigate(&params);
43 } 43 }
44 44
45 void ShowSingletonTabOverwritingNTP(Browser* browser, 45 void ShowSingletonTabOverwritingNTP(Browser* browser,
46 const browser::NavigateParams& params) { 46 const NavigateParams& params) {
47 browser::NavigateParams local_params(params); 47 NavigateParams local_params(params);
48 content::WebContents* contents = chrome::GetActiveWebContents(browser); 48 content::WebContents* contents = GetActiveWebContents(browser);
49 if (contents) { 49 if (contents) {
50 const GURL& contents_url = contents->GetURL(); 50 const GURL& contents_url = contents->GetURL();
51 if ((contents_url == GURL(chrome::kChromeUINewTabURL) || 51 if ((contents_url == GURL(kChromeUINewTabURL) ||
52 contents_url == GURL(chrome::kAboutBlankURL)) && 52 contents_url == GURL(kAboutBlankURL)) &&
53 GetIndexOfSingletonTab(&local_params) < 0) { 53 GetIndexOfSingletonTab(&local_params) < 0) {
54 local_params.disposition = CURRENT_TAB; 54 local_params.disposition = CURRENT_TAB;
55 } 55 }
56 } 56 }
57 57
58 browser::Navigate(&local_params); 58 Navigate(&local_params);
59 } 59 }
60 60
61 browser::NavigateParams GetSingletonTabNavigateParams(Browser* browser, 61 NavigateParams GetSingletonTabNavigateParams(Browser* browser,
62 const GURL& url) { 62 const GURL& url) {
63 browser::NavigateParams params(browser, 63 NavigateParams params(browser, url, content::PAGE_TRANSITION_AUTO_BOOKMARK);
64 url,
65 content::PAGE_TRANSITION_AUTO_BOOKMARK);
66 params.disposition = SINGLETON_TAB; 64 params.disposition = SINGLETON_TAB;
67 params.window_action = browser::NavigateParams::SHOW_WINDOW; 65 params.window_action = NavigateParams::SHOW_WINDOW;
68 params.user_gesture = true; 66 params.user_gesture = true;
69 return params; 67 return params;
70 } 68 }
71 69
72 // Returns the index of an existing singleton tab in |params->browser| matching 70 // Returns the index of an existing singleton tab in |params->browser| matching
73 // the URL specified in |params|. 71 // the URL specified in |params|.
74 int GetIndexOfSingletonTab(browser::NavigateParams* params) { 72 int GetIndexOfSingletonTab(NavigateParams* params) {
75 if (params->disposition != SINGLETON_TAB) 73 if (params->disposition != SINGLETON_TAB)
76 return -1; 74 return -1;
77 75
78 // In case the URL was rewritten by the BrowserURLHandler we need to ensure 76 // In case the URL was rewritten by the BrowserURLHandler we need to ensure
79 // that we do not open another URL that will get redirected to the rewritten 77 // that we do not open another URL that will get redirected to the rewritten
80 // URL. 78 // URL.
81 GURL rewritten_url(params->url); 79 GURL rewritten_url(params->url);
82 bool reverse_on_redirect = false; 80 bool reverse_on_redirect = false;
83 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 81 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
84 &rewritten_url, 82 &rewritten_url,
85 params->browser->profile(), 83 params->browser->profile(),
86 &reverse_on_redirect); 84 &reverse_on_redirect);
87 85
88 // If there are several matches: prefer the active tab by starting there. 86 // If there are several matches: prefer the active tab by starting there.
89 int start_index = std::max(0, params->browser->active_index()); 87 int start_index = std::max(0, params->browser->active_index());
90 int tab_count = params->browser->tab_count(); 88 int tab_count = params->browser->tab_count();
91 for (int i = 0; i < tab_count; ++i) { 89 for (int i = 0; i < tab_count; ++i) {
92 int tab_index = (start_index + i) % tab_count; 90 int tab_index = (start_index + i) % tab_count;
93 TabContents* tab = chrome::GetTabContentsAt(params->browser, tab_index); 91 TabContents* tab = GetTabContentsAt(params->browser, tab_index);
94 92
95 url_canon::Replacements<char> replacements; 93 url_canon::Replacements<char> replacements;
96 if (params->ref_behavior == browser::NavigateParams::IGNORE_REF) 94 if (params->ref_behavior == NavigateParams::IGNORE_REF)
97 replacements.ClearRef(); 95 replacements.ClearRef();
98 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE || 96 if (params->path_behavior == NavigateParams::IGNORE_AND_NAVIGATE ||
99 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) { 97 params->path_behavior == NavigateParams::IGNORE_AND_STAY_PUT) {
100 replacements.ClearPath(); 98 replacements.ClearPath();
101 replacements.ClearQuery(); 99 replacements.ClearQuery();
102 } 100 }
103 101
104 if (CompareURLsWithReplacements(tab->web_contents()->GetURL(), 102 if (CompareURLsWithReplacements(tab->web_contents()->GetURL(),
105 params->url, replacements) || 103 params->url, replacements) ||
106 CompareURLsWithReplacements(tab->web_contents()->GetURL(), 104 CompareURLsWithReplacements(tab->web_contents()->GetURL(),
107 rewritten_url, replacements)) { 105 rewritten_url, replacements)) {
108 params->target_contents = tab; 106 params->target_contents = tab;
109 return tab_index; 107 return tab_index;
110 } 108 }
111 } 109 }
112 110
113 return -1; 111 return -1;
114 } 112 }
115 113
116
117 } // namespace chrome 114 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/singleton_tabs.h ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698