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

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

Issue 10546106: TabContentsWrapper -> TabContents, part 53. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_about_handler.h" 12 #include "chrome/browser/browser_about_handler.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_tab_helper.h" 14 #include "chrome/browser/extensions/extension_tab_helper.h"
15 #include "chrome/browser/google/google_url_tracker.h" 15 #include "chrome/browser/google/google_url_tracker.h"
16 #include "chrome/browser/google/google_util.h" 16 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/prefs/incognito_mode_prefs.h" 17 #include "chrome/browser/prefs/incognito_mode_prefs.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/prerender/prerender_manager.h" 19 #include "chrome/browser/prerender/prerender_manager.h"
20 #include "chrome/browser/prerender/prerender_manager_factory.h" 20 #include "chrome/browser/prerender/prerender_manager_factory.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/rlz/rlz.h" 22 #include "chrome/browser/rlz/rlz.h"
23 #include "chrome/browser/tab_contents/tab_util.h" 23 #include "chrome/browser/tab_contents/tab_util.h"
24 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/omnibox/location_bar.h" 27 #include "chrome/browser/ui/omnibox/location_bar.h"
28 #include "chrome/browser/ui/status_bubble.h" 28 #include "chrome/browser/ui/status_bubble.h"
29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 29 #include "chrome/browser/ui/tab_contents/tab_contents.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/web_applications/web_app.h" 31 #include "chrome/browser/web_applications/web_app.h"
32 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
36 #include "content/public/browser/browser_url_handler.h" 36 #include "content/public/browser/browser_url_handler.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 params->window_action = browser::NavigateParams::SHOW_WINDOW; 104 params->window_action = browser::NavigateParams::SHOW_WINDOW;
105 } 105 }
106 106
107 return true; 107 return true;
108 } 108 }
109 109
110 // Returns a Browser that can host the navigation or tab addition specified in 110 // Returns a Browser that can host the navigation or tab addition specified in
111 // |params|. This might just return the same Browser specified in |params|, or 111 // |params|. This might just return the same Browser specified in |params|, or
112 // some other if that Browser is deemed incompatible. 112 // some other if that Browser is deemed incompatible.
113 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { 113 Browser* GetBrowserForDisposition(browser::NavigateParams* params) {
114 // If no source TabContentsWrapper was specified, we use the selected one from 114 // If no source TabContents was specified, we use the selected one from
115 // the target browser. This must happen first, before 115 // the target browser. This must happen first, before
116 // GetBrowserForDisposition() has a chance to replace |params->browser| with 116 // GetBrowserForDisposition() has a chance to replace |params->browser| with
117 // another one. 117 // another one.
118 if (!params->source_contents && params->browser) 118 if (!params->source_contents && params->browser)
119 params->source_contents = 119 params->source_contents =
120 params->browser->GetSelectedTabContentsWrapper(); 120 params->browser->GetActiveTabContents();
121 121
122 Profile* profile = 122 Profile* profile =
123 params->browser ? params->browser->profile() : params->profile; 123 params->browser ? params->browser->profile() : params->profile;
124 124
125 switch (params->disposition) { 125 switch (params->disposition) {
126 case CURRENT_TAB: 126 case CURRENT_TAB:
127 if (!params->browser && profile) { 127 if (!params->browser && profile) {
128 // We specified a profile instead of a browser; find or create one. 128 // We specified a profile instead of a browser; find or create one.
129 params->browser = browser::FindOrCreateTabbedBrowser(profile); 129 params->browser = browser::FindOrCreateTabbedBrowser(profile);
130 } 130 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (params_->window_action == browser::NavigateParams::SHOW_WINDOW_INACTIVE) 290 if (params_->window_action == browser::NavigateParams::SHOW_WINDOW_INACTIVE)
291 params_->browser->window()->ShowInactive(); 291 params_->browser->window()->ShowInactive();
292 else if (params_->window_action == browser::NavigateParams::SHOW_WINDOW) 292 else if (params_->window_action == browser::NavigateParams::SHOW_WINDOW)
293 params_->browser->window()->Show(); 293 params_->browser->window()->Show();
294 } 294 }
295 private: 295 private:
296 browser::NavigateParams* params_; 296 browser::NavigateParams* params_;
297 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer); 297 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserDisplayer);
298 }; 298 };
299 299
300 // This class manages the lifetime of a TabContentsWrapper created by the 300 // This class manages the lifetime of a TabContents created by the
301 // Navigate() function. When Navigate() creates a TabContentsWrapper for a URL, 301 // Navigate() function. When Navigate() creates a TabContents for a URL,
302 // an instance of this class takes ownership of it via TakeOwnership() until the 302 // an instance of this class takes ownership of it via TakeOwnership() until the
303 // TabContentsWrapper is added to a tab strip at which time ownership is 303 // TabContents is added to a tab strip at which time ownership is
304 // relinquished via ReleaseOwnership(). If this object goes out of scope without 304 // relinquished via ReleaseOwnership(). If this object goes out of scope without
305 // being added to a tab strip, the created TabContentsWrapper is deleted to 305 // being added to a tab strip, the created TabContents is deleted to
306 // avoid a leak and the params->target_contents field is set to NULL. 306 // avoid a leak and the params->target_contents field is set to NULL.
307 class ScopedTargetContentsOwner { 307 class ScopedTargetContentsOwner {
308 public: 308 public:
309 explicit ScopedTargetContentsOwner(browser::NavigateParams* params) 309 explicit ScopedTargetContentsOwner(browser::NavigateParams* params)
310 : params_(params) { 310 : params_(params) {
311 } 311 }
312 ~ScopedTargetContentsOwner() { 312 ~ScopedTargetContentsOwner() {
313 if (target_contents_owner_.get()) 313 if (target_contents_owner_.get())
314 params_->target_contents = NULL; 314 params_->target_contents = NULL;
315 } 315 }
316 316
317 // Assumes ownership of |params_|' target_contents until ReleaseOwnership 317 // Assumes ownership of |params_|' target_contents until ReleaseOwnership
318 // is called. 318 // is called.
319 void TakeOwnership() { 319 void TakeOwnership() {
320 target_contents_owner_.reset(params_->target_contents); 320 target_contents_owner_.reset(params_->target_contents);
321 } 321 }
322 322
323 // Relinquishes ownership of |params_|' target_contents. 323 // Relinquishes ownership of |params_|' target_contents.
324 TabContentsWrapper* ReleaseOwnership() { 324 TabContents* ReleaseOwnership() {
325 return target_contents_owner_.release(); 325 return target_contents_owner_.release();
326 } 326 }
327 327
328 private: 328 private:
329 browser::NavigateParams* params_; 329 browser::NavigateParams* params_;
330 scoped_ptr<TabContentsWrapper> target_contents_owner_; 330 scoped_ptr<TabContents> target_contents_owner_;
331 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); 331 DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner);
332 }; 332 };
333 333
334 void InitializeExtraHeaders(browser::NavigateParams* params, 334 void InitializeExtraHeaders(browser::NavigateParams* params,
335 Profile* profile, 335 Profile* profile,
336 std::string* extra_headers) { 336 std::string* extra_headers) {
337 #if defined(ENABLE_RLZ) 337 #if defined(ENABLE_RLZ)
338 if (!profile) 338 if (!profile)
339 profile = params->profile; 339 profile = params->profile;
340 340
(...skipping 17 matching lines...) Expand all
358 } 358 }
359 } 359 }
360 } 360 }
361 } 361 }
362 } 362 }
363 #endif 363 #endif
364 } 364 }
365 365
366 // If a prerendered page exists for |url|, replace the page at |target_contents| 366 // If a prerendered page exists for |url|, replace the page at |target_contents|
367 // with it. 367 // with it.
368 bool SwapInPrerender(TabContentsWrapper* target_contents, const GURL& url) { 368 bool SwapInPrerender(TabContents* target_contents, const GURL& url) {
369 prerender::PrerenderManager* prerender_manager = 369 prerender::PrerenderManager* prerender_manager =
370 prerender::PrerenderManagerFactory::GetForProfile( 370 prerender::PrerenderManagerFactory::GetForProfile(
371 target_contents->profile()); 371 target_contents->profile());
372 WebContents* web_contents = target_contents->web_contents(); 372 WebContents* web_contents = target_contents->web_contents();
373 return prerender_manager && 373 return prerender_manager &&
374 prerender_manager->MaybeUsePrerenderedPage(web_contents, url); 374 prerender_manager->MaybeUsePrerenderedPage(web_contents, url);
375 } 375 }
376 376
377 } // namespace 377 } // namespace
378 378
(...skipping 13 matching lines...) Expand all
392 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 392 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
393 window_action(NO_ACTION), 393 window_action(NO_ACTION),
394 user_gesture(true), 394 user_gesture(true),
395 path_behavior(RESPECT), 395 path_behavior(RESPECT),
396 ref_behavior(IGNORE_REF), 396 ref_behavior(IGNORE_REF),
397 browser(a_browser), 397 browser(a_browser),
398 profile(NULL) { 398 profile(NULL) {
399 } 399 }
400 400
401 NavigateParams::NavigateParams(Browser* a_browser, 401 NavigateParams::NavigateParams(Browser* a_browser,
402 TabContentsWrapper* a_target_contents) 402 TabContents* a_target_contents)
403 : target_contents(a_target_contents), 403 : target_contents(a_target_contents),
404 source_contents(NULL), 404 source_contents(NULL),
405 disposition(CURRENT_TAB), 405 disposition(CURRENT_TAB),
406 transition(content::PAGE_TRANSITION_LINK), 406 transition(content::PAGE_TRANSITION_LINK),
407 is_renderer_initiated(false), 407 is_renderer_initiated(false),
408 tabstrip_index(-1), 408 tabstrip_index(-1),
409 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 409 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
410 window_action(NO_ACTION), 410 window_action(NO_ACTION),
411 user_gesture(true), 411 user_gesture(true),
412 path_behavior(RESPECT), 412 path_behavior(RESPECT),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (GetSourceProfile(params, source_browser) != params->browser->profile()) { 451 if (GetSourceProfile(params, source_browser) != params->browser->profile()) {
452 // A tab is being opened from a link from a different profile, we must reset 452 // A tab is being opened from a link from a different profile, we must reset
453 // source information that may cause state to be shared. 453 // source information that may cause state to be shared.
454 params->source_contents = NULL; 454 params->source_contents = NULL;
455 params->referrer = content::Referrer(); 455 params->referrer = content::Referrer();
456 } 456 }
457 457
458 // Make sure the Browser is shown if params call for it. 458 // Make sure the Browser is shown if params call for it.
459 ScopedBrowserDisplayer displayer(params); 459 ScopedBrowserDisplayer displayer(params);
460 460
461 // Makes sure any TabContentsWrapper created by this function is destroyed if 461 // Makes sure any TabContents created by this function is destroyed if
462 // not properly added to a tab strip. 462 // not properly added to a tab strip.
463 ScopedTargetContentsOwner target_contents_owner(params); 463 ScopedTargetContentsOwner target_contents_owner(params);
464 464
465 // Some dispositions need coercion to base types. 465 // Some dispositions need coercion to base types.
466 NormalizeDisposition(params); 466 NormalizeDisposition(params);
467 467
468 // If a new window has been created, it needs to be displayed. 468 // If a new window has been created, it needs to be displayed.
469 if (params->window_action == browser::NavigateParams::NO_ACTION && 469 if (params->window_action == browser::NavigateParams::NO_ACTION &&
470 source_browser != params->browser && 470 source_browser != params->browser &&
471 params->browser->tab_strip_model()->empty()) { 471 params->browser->tab_strip_model()->empty()) {
472 params->window_action = browser::NavigateParams::SHOW_WINDOW; 472 params->window_action = browser::NavigateParams::SHOW_WINDOW;
473 } 473 }
474 474
475 // If we create a popup window from a non user-gesture, don't activate it. 475 // If we create a popup window from a non user-gesture, don't activate it.
476 if (params->window_action == browser::NavigateParams::SHOW_WINDOW && 476 if (params->window_action == browser::NavigateParams::SHOW_WINDOW &&
477 params->disposition == NEW_POPUP && 477 params->disposition == NEW_POPUP &&
478 params->user_gesture == false) { 478 params->user_gesture == false) {
479 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; 479 params->window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
480 } 480 }
481 481
482 // Determine if the navigation was user initiated. If it was, we need to 482 // Determine if the navigation was user initiated. If it was, we need to
483 // inform the target TabContentsWrapper, and we may need to update the UI. 483 // inform the target TabContents, and we may need to update the UI.
484 content::PageTransition base_transition = 484 content::PageTransition base_transition =
485 content::PageTransitionStripQualifier(params->transition); 485 content::PageTransitionStripQualifier(params->transition);
486 bool user_initiated = 486 bool user_initiated =
487 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR || 487 params->transition & content::PAGE_TRANSITION_FROM_ADDRESS_BAR ||
488 base_transition == content::PAGE_TRANSITION_TYPED || 488 base_transition == content::PAGE_TRANSITION_TYPED ||
489 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || 489 base_transition == content::PAGE_TRANSITION_AUTO_BOOKMARK ||
490 base_transition == content::PAGE_TRANSITION_GENERATED || 490 base_transition == content::PAGE_TRANSITION_GENERATED ||
491 base_transition == content::PAGE_TRANSITION_START_PAGE || 491 base_transition == content::PAGE_TRANSITION_START_PAGE ||
492 base_transition == content::PAGE_TRANSITION_RELOAD || 492 base_transition == content::PAGE_TRANSITION_RELOAD ||
493 base_transition == content::PAGE_TRANSITION_KEYWORD; 493 base_transition == content::PAGE_TRANSITION_KEYWORD;
494 494
495 std::string extra_headers; 495 std::string extra_headers;
496 496
497 // Check if this is a singleton tab that already exists 497 // Check if this is a singleton tab that already exists
498 int singleton_index = GetIndexOfSingletonTab(params); 498 int singleton_index = GetIndexOfSingletonTab(params);
499 499
500 // If no target TabContentsWrapper was specified, we need to construct one if 500 // If no target TabContents was specified, we need to construct one if
501 // we are supposed to target a new tab; unless it's a singleton that already 501 // we are supposed to target a new tab; unless it's a singleton that already
502 // exists. 502 // exists.
503 if (!params->target_contents && singleton_index < 0) { 503 if (!params->target_contents && singleton_index < 0) {
504 GURL url; 504 GURL url;
505 if (params->url.is_empty()) { 505 if (params->url.is_empty()) {
506 url = params->browser->profile()->GetHomePage(); 506 url = params->browser->profile()->GetHomePage();
507 params->transition = content::PageTransitionFromInt( 507 params->transition = content::PageTransitionFromInt(
508 params->transition | content::PAGE_TRANSITION_HOME_PAGE); 508 params->transition | content::PAGE_TRANSITION_HOME_PAGE);
509 } else { 509 } else {
510 url = params->url; 510 url = params->url;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 635 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
636 &rewritten_url, 636 &rewritten_url,
637 params->browser->profile(), 637 params->browser->profile(),
638 &reverse_on_redirect); 638 &reverse_on_redirect);
639 639
640 // If there are several matches: prefer the active tab by starting there. 640 // If there are several matches: prefer the active tab by starting there.
641 int start_index = std::max(0, params->browser->active_index()); 641 int start_index = std::max(0, params->browser->active_index());
642 int tab_count = params->browser->tab_count(); 642 int tab_count = params->browser->tab_count();
643 for (int i = 0; i < tab_count; ++i) { 643 for (int i = 0; i < tab_count; ++i) {
644 int tab_index = (start_index + i) % tab_count; 644 int tab_index = (start_index + i) % tab_count;
645 TabContentsWrapper* tab = 645 TabContents* tab = params->browser->GetTabContentsAt(tab_index);
646 params->browser->GetTabContentsWrapperAt(tab_index);
647 646
648 url_canon::Replacements<char> replacements; 647 url_canon::Replacements<char> replacements;
649 if (params->ref_behavior == browser::NavigateParams::IGNORE_REF) 648 if (params->ref_behavior == browser::NavigateParams::IGNORE_REF)
650 replacements.ClearRef(); 649 replacements.ClearRef();
651 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE || 650 if (params->path_behavior == browser::NavigateParams::IGNORE_AND_NAVIGATE ||
652 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) { 651 params->path_behavior == browser::NavigateParams::IGNORE_AND_STAY_PUT) {
653 replacements.ClearPath(); 652 replacements.ClearPath();
654 replacements.ClearQuery(); 653 replacements.ClearQuery();
655 } 654 }
656 655
(...skipping 17 matching lines...) Expand all
674 return !(url.scheme() == chrome::kChromeUIScheme && 673 return !(url.scheme() == chrome::kChromeUIScheme &&
675 (url.host() == chrome::kChromeUISettingsHost || 674 (url.host() == chrome::kChromeUISettingsHost ||
676 url.host() == chrome::kChromeUISettingsFrameHost || 675 url.host() == chrome::kChromeUISettingsFrameHost ||
677 url.host() == chrome::kChromeUIExtensionsHost || 676 url.host() == chrome::kChromeUIExtensionsHost ||
678 url.host() == chrome::kChromeUIBookmarksHost || 677 url.host() == chrome::kChromeUIBookmarksHost ||
679 url.host() == chrome::kChromeUISyncPromoHost || 678 url.host() == chrome::kChromeUISyncPromoHost ||
680 url.host() == chrome::kChromeUIUberHost)); 679 url.host() == chrome::kChromeUIUberHost));
681 } 680 }
682 681
683 } // namespace browser 682 } // namespace browser
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