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

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

Issue 10105030: TabContents -> WebContentsImpl, part 21. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 params->window_action = browser::NavigateParams::SHOW_WINDOW; 105 params->window_action = browser::NavigateParams::SHOW_WINDOW;
106 } 106 }
107 107
108 return true; 108 return true;
109 } 109 }
110 110
111 // Returns a Browser that can host the navigation or tab addition specified in 111 // Returns a Browser that can host the navigation or tab addition specified in
112 // |params|. This might just return the same Browser specified in |params|, or 112 // |params|. This might just return the same Browser specified in |params|, or
113 // some other if that Browser is deemed incompatible. 113 // some other if that Browser is deemed incompatible.
114 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { 114 Browser* GetBrowserForDisposition(browser::NavigateParams* params) {
115 // If no source TabContents was specified, we use the selected one from the 115 // If no source TabContentsWrapper was specified, we use the selected one from
116 // target browser. This must happen first, before GetBrowserForDisposition() 116 // the target browser. This must happen first, before
117 // has a chance to replace |params->browser| with another one. 117 // GetBrowserForDisposition() has a chance to replace |params->browser| with
118 // another one.
118 if (!params->source_contents && params->browser) 119 if (!params->source_contents && params->browser)
119 params->source_contents = 120 params->source_contents =
120 params->browser->GetSelectedTabContentsWrapper(); 121 params->browser->GetSelectedTabContentsWrapper();
121 122
122 Profile* profile = 123 Profile* profile =
123 params->browser ? params->browser->profile() : params->profile; 124 params->browser ? params->browser->profile() : params->profile;
124 125
125 switch (params->disposition) { 126 switch (params->disposition) {
126 case CURRENT_TAB: 127 case CURRENT_TAB:
127 if (!params->browser && profile) { 128 if (!params->browser && profile) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (params_->window_action == browser::NavigateParams::SHOW_WINDOW_INACTIVE) 291 if (params_->window_action == browser::NavigateParams::SHOW_WINDOW_INACTIVE)
291 params_->browser->window()->ShowInactive(); 292 params_->browser->window()->ShowInactive();
292 else if (params_->window_action == browser::NavigateParams::SHOW_WINDOW) 293 else if (params_->window_action == browser::NavigateParams::SHOW_WINDOW)
293 params_->browser->window()->Show(); 294 params_->browser->window()->Show();
294 } 295 }
295 private: 296 private:
296 browser::NavigateParams* params_; 297 browser::NavigateParams* params_;
297 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer); 298 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer);
298 }; 299 };
299 300
300 // This class manages the lifetime of a TabContents created by the Navigate() 301 // This class manages the lifetime of a TabContentsWrapper created by the
301 // function. When Navigate() creates a TabContents for a URL, an instance of 302 // Navigate() function. When Navigate() creates a TabContentsWrapper for a URL,
302 // this class takes ownership of it via TakeOwnership() until the TabContents 303 // an instance of this class takes ownership of it via TakeOwnership() until the
303 // is added to a tab strip at which time ownership is relinquished via 304 // TabContentsWrapper is added to a tab strip at which time ownership is
304 // ReleaseOwnership(). If this object goes out of scope without being added 305 // relinquished via ReleaseOwnership(). If this object goes out of scope without
305 // to a tab strip, the created TabContents is deleted to avoid a leak and the 306 // being added to a tab strip, the created TabContentsWrapper is deleted to
306 // params->target_contents field is set to NULL. 307 // avoid a leak and the params->target_contents field is set to NULL.
307 class ScopedTargetContentsOwner { 308 class ScopedTargetContentsOwner {
308 public: 309 public:
309 explicit ScopedTargetContentsOwner(browser::NavigateParams* params) 310 explicit ScopedTargetContentsOwner(browser::NavigateParams* params)
310 : params_(params) { 311 : params_(params) {
311 } 312 }
312 ~ScopedTargetContentsOwner() { 313 ~ScopedTargetContentsOwner() {
313 if (target_contents_owner_.get()) 314 if (target_contents_owner_.get())
314 params_->target_contents = NULL; 315 params_->target_contents = NULL;
315 } 316 }
316 317
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (GetSourceProfile(params, source_browser) != params->browser->profile()) { 454 if (GetSourceProfile(params, source_browser) != params->browser->profile()) {
454 // A tab is being opened from a link from a different profile, we must reset 455 // A tab is being opened from a link from a different profile, we must reset
455 // source information that may cause state to be shared. 456 // source information that may cause state to be shared.
456 params->source_contents = NULL; 457 params->source_contents = NULL;
457 params->referrer = content::Referrer(); 458 params->referrer = content::Referrer();
458 } 459 }
459 460
460 // Make sure the Browser is shown if params call for it. 461 // Make sure the Browser is shown if params call for it.
461 ScopedBrowserDisplayer displayer(params); 462 ScopedBrowserDisplayer displayer(params);
462 463
463 // Makes sure any TabContents created by this function is destroyed if 464 // Makes sure any TabContentsWrapper created by this function is destroyed if
464 // not properly added to a tab strip. 465 // not properly added to a tab strip.
465 ScopedTargetContentsOwner target_contents_owner(params); 466 ScopedTargetContentsOwner target_contents_owner(params);
466 467
467 // Some dispositions need coercion to base types. 468 // Some dispositions need coercion to base types.
468 NormalizeDisposition(params); 469 NormalizeDisposition(params);
469 470
470 // If a new window has been created, it needs to be displayed. 471 // If a new window has been created, it needs to be displayed.
471 if (params->window_action == browser::NavigateParams::NO_ACTION && 472 if (params->window_action == browser::NavigateParams::NO_ACTION &&
472 source_browser != params->browser && 473 source_browser != params->browser &&
473 params->browser->tabstrip_model()->empty()) { 474 params->browser->tabstrip_model()->empty()) {
474 params->window_action = browser::NavigateParams::SHOW_WINDOW; 475 params->window_action = browser::NavigateParams::SHOW_WINDOW;
475 } 476 }
476 477
477 // If we create a popup window from a non user-gesture, don't activate it. 478 // If we create a popup window from a non user-gesture, don't activate it.
478 if (params->window_action == browser::NavigateParams::SHOW_WINDOW && 479 if (params->window_action == browser::NavigateParams::SHOW_WINDOW &&
479 params->disposition == NEW_POPUP && 480 params->disposition == NEW_POPUP &&
480 params->user_gesture == false) { 481 params->user_gesture == false) {
481 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; 482 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
482 } 483 }
483 484
484 // Determine if the navigation was user initiated. If it was, we need to 485 // Determine if the navigation was user initiated. If it was, we need to
485 // inform the target TabContents, and we may need to update the UI. 486 // inform the target TabContentsWrapper, and we may need to update the UI.
486 content::PageTransition base_transition = 487 content::PageTransition base_transition =
487 content::PageTransitionStripQualifier(params->transition); 488 content::PageTransitionStripQualifier(params->transition);
488 bool user_initiated = 489 bool user_initiated =
489 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR || 490 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR ||
490 base_transition == content::PAGE_TRANSITION_TYPED || 491 base_transition == content::PAGE_TRANSITION_TYPED ||
491 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 492 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
492 base_transition == content::PAGE_TRANSITION_GENERATED || 493 base_transition == content::PAGE_TRANSITION_GENERATED ||
493 base_transition == content::PAGE_TRANSITION_START_PAGE || 494 base_transition == content::PAGE_TRANSITION_START_PAGE ||
494 base_transition == content::PAGE_TRANSITION_RELOAD || 495 base_transition == content::PAGE_TRANSITION_RELOAD ||
495 base_transition == content::PAGE_TRANSITION_KEYWORD; 496 base_transition == content::PAGE_TRANSITION_KEYWORD;
496 497
497 std::string extra_headers; 498 std::string extra_headers;
498 499
499 // Check if this is a singleton tab that already exists 500 // Check if this is a singleton tab that already exists
500 int singleton_index = GetIndexOfSingletonTab(params); 501 int singleton_index = GetIndexOfSingletonTab(params);
501 502
502 // If no target TabContents was specified, we need to construct one if we are 503 // If no target TabContentsWrapper was specified, we need to construct one if
503 // supposed to target a new tab; unless it's a singleton that already exists. 504 // we are supposed to target a new tab; unless it's a singleton that already
505 // exists.
504 if (!params->target_contents && singleton_index < 0) { 506 if (!params->target_contents && singleton_index < 0) {
505 GURL url; 507 GURL url;
506 if (params->url.is_empty()) { 508 if (params->url.is_empty()) {
507 url = params->browser->profile()->GetHomePage(); 509 url = params->browser->profile()->GetHomePage();
508 params->transition = content::PageTransitionFromInt( 510 params->transition = content::PageTransitionFromInt(
509 params->transition | content::PAGE_TRANSITION_HOME_PAGE); 511 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
510 } else { 512 } else {
511 url = params->url; 513 url = params->url;
512 } 514 }
513 515
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 popup_bounds.height() > max_height || 701 popup_bounds.height() > max_height ||
700 popup_bounds.width() == 0 || 702 popup_bounds.width() == 0 ||
701 popup_bounds.height() == 0) { 703 popup_bounds.height() == 0) {
702 return NEW_FOREGROUND_TAB; 704 return NEW_FOREGROUND_TAB;
703 } 705 }
704 return NEW_POPUP; 706 return NEW_POPUP;
705 } 707 }
706 #endif 708 #endif
707 709
708 } // namespace browser 710 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.h ('k') | chrome/browser/ui/browser_navigator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698