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

Side by Side Diff: chrome/browser/ui/browser_navigator.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/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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 Browser* browser = browser::FindTabbedBrowser(profile, false); 60 Browser* browser = browser::FindTabbedBrowser(profile, false);
61 return browser ? browser : Browser::Create(profile); 61 return browser ? browser : Browser::Create(profile);
62 } 62 }
63 63
64 // Change some of the navigation parameters based on the particular URL. 64 // Change some of the navigation parameters based on the particular URL.
65 // Currently this applies to some chrome:// pages which we always want to open 65 // Currently this applies to some chrome:// pages which we always want to open
66 // in a non-incognito window. Note that even though a ChromeOS guest session is 66 // in a non-incognito window. Note that even though a ChromeOS guest session is
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(browser::NavigateParams* params) { 70 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) {
71 if (params->target_contents != NULL || 71 if (params->target_contents != NULL ||
72 browser::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 = 77 Profile* profile =
78 params->browser ? params->browser->profile() : params->profile; 78 params->browser ? params->browser->profile() : params->profile;
79 79
80 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { 80 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) {
81 profile = profile->GetOriginalProfile(); 81 profile = profile->GetOriginalProfile();
82 82
83 // If incognito is forced, we punt. 83 // If incognito is forced, we punt.
84 PrefService* prefs = profile->GetPrefs(); 84 PrefService* prefs = profile->GetPrefs();
85 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == 85 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
86 IncognitoModePrefs::FORCED) { 86 IncognitoModePrefs::FORCED) {
87 return false; 87 return false;
88 } 88 }
89 89
90 params->disposition = SINGLETON_TAB; 90 params->disposition = SINGLETON_TAB;
91 params->profile = profile; 91 params->profile = profile;
92 params->browser = browser::FindOrCreateTabbedBrowser(profile); 92 params->browser = browser::FindOrCreateTabbedBrowser(profile);
93 params->window_action = browser::NavigateParams::SHOW_WINDOW; 93 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
94 } 94 }
95 95
96 return true; 96 return true;
97 } 97 }
98 98
99 // Returns a Browser that can host the navigation or tab addition specified in 99 // Returns a Browser that can host the navigation or tab addition specified in
100 // |params|. This might just return the same Browser specified in |params|, or 100 // |params|. This might just return the same Browser specified in |params|, or
101 // some other if that Browser is deemed incompatible. 101 // some other if that Browser is deemed incompatible.
102 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { 102 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) {
103 // If no source TabContents was specified, we use the selected one from 103 // If no source TabContents was specified, we use the selected one from
104 // the target browser. This must happen first, before 104 // the target browser. This must happen first, before
105 // GetBrowserForDisposition() has a chance to replace |params->browser| with 105 // GetBrowserForDisposition() has a chance to replace |params->browser| with
106 // another one. 106 // another one.
107 if (!params->source_contents && params->browser) 107 if (!params->source_contents && params->browser)
108 params->source_contents = chrome::GetActiveTabContents(params->browser); 108 params->source_contents = chrome::GetActiveTabContents(params->browser);
109 109
110 Profile* profile = 110 Profile* profile =
111 params->browser ? params->browser->profile() : params->profile; 111 params->browser ? params->browser->profile() : params->profile;
112 112
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 case IGNORE_ACTION: 176 case IGNORE_ACTION:
177 return NULL; 177 return NULL;
178 default: 178 default:
179 NOTREACHED(); 179 NOTREACHED();
180 } 180 }
181 return NULL; 181 return NULL;
182 } 182 }
183 183
184 // Fix disposition and other parameter values depending on prevailing 184 // Fix disposition and other parameter values depending on prevailing
185 // conditions. 185 // conditions.
186 void NormalizeDisposition(browser::NavigateParams* params) { 186 void NormalizeDisposition(chrome::NavigateParams* params) {
187 // Calculate the WindowOpenDisposition if necessary. 187 // Calculate the WindowOpenDisposition if necessary.
188 if (params->browser->tab_strip_model()->empty() && 188 if (params->browser->tab_strip_model()->empty() &&
189 (params->disposition == NEW_BACKGROUND_TAB || 189 (params->disposition == NEW_BACKGROUND_TAB ||
190 params->disposition == CURRENT_TAB || 190 params->disposition == CURRENT_TAB ||
191 params->disposition == SINGLETON_TAB)) { 191 params->disposition == SINGLETON_TAB)) {
192 params->disposition = NEW_FOREGROUND_TAB; 192 params->disposition = NEW_FOREGROUND_TAB;
193 } 193 }
194 if (params->browser->profile()->IsOffTheRecord() && 194 if (params->browser->profile()->IsOffTheRecord() &&
195 params->disposition == OFF_THE_RECORD) { 195 params->disposition == OFF_THE_RECORD) {
196 params->disposition = NEW_FOREGROUND_TAB; 196 params->disposition = NEW_FOREGROUND_TAB;
197 } 197 }
198 if (!params->source_contents && params->disposition == CURRENT_TAB) 198 if (!params->source_contents && params->disposition == CURRENT_TAB)
199 params->disposition = NEW_FOREGROUND_TAB; 199 params->disposition = NEW_FOREGROUND_TAB;
200 200
201 switch (params->disposition) { 201 switch (params->disposition) {
202 case NEW_BACKGROUND_TAB: 202 case NEW_BACKGROUND_TAB:
203 // Disposition trumps add types. ADD_ACTIVE is a default, so we need to 203 // Disposition trumps add types. ADD_ACTIVE is a default, so we need to
204 // remove it if disposition implies the tab is going to open in the 204 // remove it if disposition implies the tab is going to open in the
205 // background. 205 // background.
206 params->tabstrip_add_types &= ~TabStripModel::ADD_ACTIVE; 206 params->tabstrip_add_types &= ~TabStripModel::ADD_ACTIVE;
207 break; 207 break;
208 208
209 case NEW_WINDOW: 209 case NEW_WINDOW:
210 case NEW_POPUP: 210 case NEW_POPUP:
211 // Code that wants to open a new window typically expects it to be shown 211 // Code that wants to open a new window typically expects it to be shown
212 // automatically. 212 // automatically.
213 if (params->window_action == browser::NavigateParams::NO_ACTION) 213 if (params->window_action == chrome::NavigateParams::NO_ACTION)
214 params->window_action = browser::NavigateParams::SHOW_WINDOW; 214 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
215 // Fall-through. 215 // Fall-through.
216 case NEW_FOREGROUND_TAB: 216 case NEW_FOREGROUND_TAB:
217 case SINGLETON_TAB: 217 case SINGLETON_TAB:
218 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE; 218 params->tabstrip_add_types |= TabStripModel::ADD_ACTIVE;
219 break; 219 break;
220 220
221 default: 221 default:
222 break; 222 break;
223 } 223 }
224 } 224 }
225 225
226 // Obtain the profile used by the code that originated the Navigate() request. 226 // Obtain the profile used by the code that originated the Navigate() request.
227 // |source_browser| represents the Browser that was supplied in |params| before 227 // |source_browser| represents the Browser that was supplied in |params| before
228 // it was modified. 228 // it was modified.
229 Profile* GetSourceProfile(browser::NavigateParams* params, 229 Profile* GetSourceProfile(chrome::NavigateParams* params,
230 Browser* source_browser) { 230 Browser* source_browser) {
231 if (params->source_contents) 231 if (params->source_contents)
232 return params->source_contents->profile(); 232 return params->source_contents->profile();
233 233
234 if (source_browser) 234 if (source_browser)
235 return source_browser->profile(); 235 return source_browser->profile();
236 236
237 if (params->profile) 237 if (params->profile)
238 return params->profile; 238 return params->profile;
239 239
240 // We couldn't find one in any of the source metadata, so we'll fall back to 240 // We couldn't find one in any of the source metadata, so we'll fall back to
241 // the profile associated with the target browser. 241 // the profile associated with the target browser.
242 return params->browser->profile(); 242 return params->browser->profile();
243 } 243 }
244 244
245 void LoadURLInContents(WebContents* target_contents, 245 void LoadURLInContents(WebContents* target_contents,
246 const GURL& url, 246 const GURL& url,
247 browser::NavigateParams* params, 247 chrome::NavigateParams* params,
248 const std::string& extra_headers) { 248 const std::string& extra_headers) {
249 if (params->transferred_global_request_id != GlobalRequestID()) { 249 if (params->transferred_global_request_id != GlobalRequestID()) {
250 target_contents->GetController().TransferURL( 250 target_contents->GetController().TransferURL(
251 url, 251 url,
252 params->referrer, 252 params->referrer,
253 params->transition, extra_headers, 253 params->transition, extra_headers,
254 params->transferred_global_request_id, 254 params->transferred_global_request_id,
255 params->is_renderer_initiated); 255 params->is_renderer_initiated);
256 } else if (params->is_renderer_initiated) { 256 } else if (params->is_renderer_initiated) {
257 target_contents->GetController().LoadURLFromRenderer( 257 target_contents->GetController().LoadURLFromRenderer(
258 url, 258 url,
259 params->referrer, 259 params->referrer,
260 params->transition, extra_headers); 260 params->transition, extra_headers);
261 } else { 261 } else {
262 target_contents->GetController().LoadURL( 262 target_contents->GetController().LoadURL(
263 url, 263 url,
264 params->referrer, 264 params->referrer,
265 params->transition, extra_headers); 265 params->transition, extra_headers);
266 } 266 }
267 267
268 } 268 }
269 269
270 // This class makes sure the Browser object held in |params| is made visible 270 // This class makes sure the Browser object held in |params| is made visible
271 // by the time it goes out of scope, provided |params| wants it to be shown. 271 // by the time it goes out of scope, provided |params| wants it to be shown.
272 class ScopedBrowserDisplayer { 272 class ScopedBrowserDisplayer {
273 public: 273 public:
274 explicit ScopedBrowserDisplayer(browser::NavigateParams* params) 274 explicit ScopedBrowserDisplayer(chrome::NavigateParams* params)
275 : params_(params) { 275 : params_(params) {
276 } 276 }
277 ~ScopedBrowserDisplayer() { 277 ~ScopedBrowserDisplayer() {
278 if (params_->window_action == browser::NavigateParams::SHOW_WINDOW_INACTIVE) 278 if (params_->window_action == chrome::NavigateParams::SHOW_WINDOW_INACTIVE)
279 params_->browser->window()->ShowInactive(); 279 params_->browser->window()->ShowInactive();
280 else if (params_->window_action == browser::NavigateParams::SHOW_WINDOW) 280 else if (params_->window_action == chrome::NavigateParams::SHOW_WINDOW)
281 params_->browser->window()->Show(); 281 params_->browser->window()->Show();
282 } 282 }
283 private: 283 private:
284 browser::NavigateParams* params_; 284 chrome::NavigateParams* params_;
285 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer); 285 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer);
286 }; 286 };
287 287
288 // This class manages the lifetime of a TabContents created by the 288 // This class manages the lifetime of a TabContents created by the
289 // Navigate() function. When Navigate() creates a TabContents for a URL, 289 // Navigate() function. When Navigate() creates a TabContents for a URL,
290 // an instance of this class takes ownership of it via TakeOwnership() until the 290 // an instance of this class takes ownership of it via TakeOwnership() until the
291 // TabContents is added to a tab strip at which time ownership is 291 // TabContents is added to a tab strip at which time ownership is
292 // relinquished via ReleaseOwnership(). If this object goes out of scope without 292 // relinquished via ReleaseOwnership(). If this object goes out of scope without
293 // being added to a tab strip, the created TabContents is deleted to 293 // being added to a tab strip, the created TabContents is deleted to
294 // avoid a leak and the params->target_contents field is set to NULL. 294 // avoid a leak and the params->target_contents field is set to NULL.
295 class ScopedTargetContentsOwner { 295 class ScopedTargetContentsOwner {
296 public: 296 public:
297 explicit ScopedTargetContentsOwner(browser::NavigateParams* params) 297 explicit ScopedTargetContentsOwner(chrome::NavigateParams* params)
298 : params_(params) { 298 : params_(params) {
299 } 299 }
300 ~ScopedTargetContentsOwner() { 300 ~ScopedTargetContentsOwner() {
301 if (target_contents_owner_.get()) 301 if (target_contents_owner_.get())
302 params_->target_contents = NULL; 302 params_->target_contents = NULL;
303 } 303 }
304 304
305 // Assumes ownership of |params_|' target_contents until ReleaseOwnership 305 // Assumes ownership of |params_|' target_contents until ReleaseOwnership
306 // is called. 306 // is called.
307 void TakeOwnership() { 307 void TakeOwnership() {
308 target_contents_owner_.reset(params_->target_contents); 308 target_contents_owner_.reset(params_->target_contents);
309 } 309 }
310 310
311 // Relinquishes ownership of |params_|' target_contents. 311 // Relinquishes ownership of |params_|' target_contents.
312 TabContents* ReleaseOwnership() { 312 TabContents* ReleaseOwnership() {
313 return target_contents_owner_.release(); 313 return target_contents_owner_.release();
314 } 314 }
315 315
316 private: 316 private:
317 browser::NavigateParams* params_; 317 chrome::NavigateParams* params_;
318 scoped_ptr<TabContents> target_contents_owner_; 318 scoped_ptr<TabContents> target_contents_owner_;
319 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); 319 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
320 }; 320 };
321 321
322 void InitializeExtraHeaders(browser::NavigateParams* params, 322 void InitializeExtraHeaders(chrome::NavigateParams* params,
323 Profile* profile, 323 Profile* profile,
324 std::string* extra_headers) { 324 std::string* extra_headers) {
325 #if defined(ENABLE_RLZ) 325 #if defined(ENABLE_RLZ)
326 if (!profile) 326 if (!profile)
327 profile = params->profile; 327 profile = params->profile;
328 328
329 // If this is a home page navigation, check to see if the home page is 329 // If this is a home page navigation, check to see if the home page is
330 // set to Google and add RLZ HTTP headers to the request. This is only 330 // set to Google and add RLZ HTTP headers to the request. This is only
331 // done if Google was the original home page, and not changed afterwards by 331 // done if Google was the original home page, and not changed afterwards by
332 // the user. 332 // the user.
(...skipping 24 matching lines...) Expand all
357 prerender::PrerenderManager* prerender_manager = 357 prerender::PrerenderManager* prerender_manager =
358 prerender::PrerenderManagerFactory::GetForProfile( 358 prerender::PrerenderManagerFactory::GetForProfile(
359 target_contents->profile()); 359 target_contents->profile());
360 WebContents* web_contents = target_contents->web_contents(); 360 WebContents* web_contents = target_contents->web_contents();
361 return prerender_manager && 361 return prerender_manager &&
362 prerender_manager->MaybeUsePrerenderedPage(web_contents, url); 362 prerender_manager->MaybeUsePrerenderedPage(web_contents, url);
363 } 363 }
364 364
365 } // namespace 365 } // namespace
366 366
367 namespace browser { 367 namespace chrome {
368 368
369 NavigateParams::NavigateParams( 369 NavigateParams::NavigateParams(Browser* a_browser,
370 Browser* a_browser, 370 const GURL& a_url,
371 const GURL& a_url, 371 content::PageTransition a_transition)
372 content::PageTransition a_transition)
373 : url(a_url), 372 : url(a_url),
374 target_contents(NULL), 373 target_contents(NULL),
375 source_contents(NULL), 374 source_contents(NULL),
376 disposition(CURRENT_TAB), 375 disposition(CURRENT_TAB),
377 transition(a_transition), 376 transition(a_transition),
378 is_renderer_initiated(false), 377 is_renderer_initiated(false),
379 tabstrip_index(-1), 378 tabstrip_index(-1),
380 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 379 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
381 window_action(NO_ACTION), 380 window_action(NO_ACTION),
382 user_gesture(true), 381 user_gesture(true),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 ScopedBrowserDisplayer displayer(params); 446 ScopedBrowserDisplayer displayer(params);
448 447
449 // Makes sure any TabContents created by this function is destroyed if 448 // Makes sure any TabContents created by this function is destroyed if
450 // not properly added to a tab strip. 449 // not properly added to a tab strip.
451 ScopedTargetContentsOwner target_contents_owner(params); 450 ScopedTargetContentsOwner target_contents_owner(params);
452 451
453 // Some dispositions need coercion to base types. 452 // Some dispositions need coercion to base types.
454 NormalizeDisposition(params); 453 NormalizeDisposition(params);
455 454
456 // If a new window has been created, it needs to be displayed. 455 // If a new window has been created, it needs to be displayed.
457 if (params->window_action == browser::NavigateParams::NO_ACTION && 456 if (params->window_action == NavigateParams::NO_ACTION &&
458 source_browser != params->browser && 457 source_browser != params->browser &&
459 params->browser->tab_strip_model()->empty()) { 458 params->browser->tab_strip_model()->empty()) {
460 params->window_action = browser::NavigateParams::SHOW_WINDOW; 459 params->window_action = NavigateParams::SHOW_WINDOW;
461 } 460 }
462 461
463 // If we create a popup window from a non user-gesture, don't activate it. 462 // If we create a popup window from a non user-gesture, don't activate it.
464 if (params->window_action == browser::NavigateParams::SHOW_WINDOW && 463 if (params->window_action == NavigateParams::SHOW_WINDOW &&
465 params->disposition == NEW_POPUP && 464 params->disposition == NEW_POPUP &&
466 params->user_gesture == false) { 465 params->user_gesture == false) {
467 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; 466 params->window_action = NavigateParams::SHOW_WINDOW_INACTIVE;
468 } 467 }
469 468
470 // Determine if the navigation was user initiated. If it was, we need to 469 // Determine if the navigation was user initiated. If it was, we need to
471 // inform the target TabContents, and we may need to update the UI. 470 // inform the target TabContents, and we may need to update the UI.
472 content::PageTransition base_transition = 471 content::PageTransition base_transition =
473 content::PageTransitionStripQualifier(params->transition); 472 content::PageTransitionStripQualifier(params->transition);
474 bool user_initiated = 473 bool user_initiated =
475 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR || 474 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR ||
476 base_transition == content::PAGE_TRANSITION_TYPED || 475 base_transition == content::PAGE_TRANSITION_TYPED ||
477 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 476 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 616
618 return !(url.scheme() == chrome::kChromeUIScheme && 617 return !(url.scheme() == chrome::kChromeUIScheme &&
619 (url.host() == chrome::kChromeUISettingsHost || 618 (url.host() == chrome::kChromeUISettingsHost ||
620 url.host() == chrome::kChromeUISettingsFrameHost || 619 url.host() == chrome::kChromeUISettingsFrameHost ||
621 url.host() == chrome::kChromeUIExtensionsHost || 620 url.host() == chrome::kChromeUIExtensionsHost ||
622 url.host() == chrome::kChromeUIBookmarksHost || 621 url.host() == chrome::kChromeUIBookmarksHost ||
623 url.host() == chrome::kChromeUISyncPromoHost || 622 url.host() == chrome::kChromeUISyncPromoHost ||
624 url.host() == chrome::kChromeUIUberHost)); 623 url.host() == chrome::kChromeUIUberHost));
625 } 624 }
626 625
627 } // namespace browser 626 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.h ('k') | chrome/browser/ui/browser_navigator_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698