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

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

Issue 10967003: Add desktop type context to most existing instances of FindTabbedBrowser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pre-review pass. Created 8 years, 2 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // Returns true if the specified Browser can open tabs. Not all Browsers support 46 // Returns true if the specified Browser can open tabs. Not all Browsers support
47 // multiple tabs, such as app frames and popups. This function returns false for 47 // multiple tabs, such as app frames and popups. This function returns false for
48 // those types of Browser. 48 // those types of Browser.
49 bool WindowCanOpenTabs(Browser* browser) { 49 bool WindowCanOpenTabs(Browser* browser) {
50 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || 50 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) ||
51 browser->tab_strip_model()->empty(); 51 browser->tab_strip_model()->empty();
52 } 52 }
53 53
54 // Finds an existing Browser compatible with |profile|, making a new one if no 54 // Finds an existing Browser compatible with |profile|, making a new one if no
55 // such Browser is located. 55 // such Browser is located.
56 Browser* GetOrCreateBrowser(Profile* profile) { 56 Browser* GetOrCreateBrowser(Profile* profile,
57 Browser* browser = browser::FindTabbedBrowser(profile, false); 57 chrome::HostDesktopType host_desktop_type) {
58 Browser* browser =
59 browser::FindTabbedBrowser(profile, false, host_desktop_type);
58 return browser ? browser : new Browser(Browser::CreateParams(profile)); 60 return browser ? browser : new Browser(Browser::CreateParams(profile));
59 } 61 }
60 62
61 // Change some of the navigation parameters based on the particular URL. 63 // Change some of the navigation parameters based on the particular URL.
62 // Currently this applies to some chrome:// pages which we always want to open 64 // Currently this applies to some chrome:// pages which we always want to open
63 // in a non-incognito window. Note that even though a ChromeOS guest session is 65 // in a non-incognito window. Note that even though a ChromeOS guest session is
64 // technically an incognito window, these URLs are allowed. 66 // technically an incognito window, these URLs are allowed.
65 // Returns true on success. Otherwise, if changing params leads the browser into 67 // Returns true on success. Otherwise, if changing params leads the browser into
66 // an erroneous state, returns false. 68 // an erroneous state, returns false.
67 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { 69 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) {
68 if (params->target_contents != NULL || 70 if (params->target_contents != NULL ||
69 chrome::IsURLAllowedInIncognito(params->url) || 71 chrome::IsURLAllowedInIncognito(params->url) ||
70 Profile::IsGuestSession()) { 72 Profile::IsGuestSession()) {
71 return true; 73 return true;
72 } 74 }
73 75
74 Profile* profile = params->initiating_profile; 76 Profile* profile = params->initiating_profile;
75 77
76 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) { 78 if (profile->IsOffTheRecord() || params->disposition == OFF_THE_RECORD) {
77 profile = profile->GetOriginalProfile(); 79 profile = profile->GetOriginalProfile();
78 80
79 // If incognito is forced, we punt. 81 // If incognito is forced, we punt.
80 PrefService* prefs = profile->GetPrefs(); 82 PrefService* prefs = profile->GetPrefs();
81 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == 83 if (prefs && IncognitoModePrefs::GetAvailability(prefs) ==
82 IncognitoModePrefs::FORCED) { 84 IncognitoModePrefs::FORCED) {
83 return false; 85 return false;
84 } 86 }
85 87
86 params->disposition = SINGLETON_TAB; 88 params->disposition = SINGLETON_TAB;
87 params->browser = browser::FindOrCreateTabbedBrowser(profile); 89 params->browser =
90 browser::FindOrCreateTabbedBrowser(profile, params->host_desktop_type);
88 params->window_action = chrome::NavigateParams::SHOW_WINDOW; 91 params->window_action = chrome::NavigateParams::SHOW_WINDOW;
89 } 92 }
90 93
91 return true; 94 return true;
92 } 95 }
93 96
94 // Returns a Browser that can host the navigation or tab addition specified in 97 // Returns a Browser that can host the navigation or tab addition specified in
95 // |params|. This might just return the same Browser specified in |params|, or 98 // |params|. This might just return the same Browser specified in |params|, or
96 // some other if that Browser is deemed incompatible. 99 // some other if that Browser is deemed incompatible.
97 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { 100 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) {
98 // If no source TabContents was specified, we use the selected one from 101 // If no source TabContents was specified, we use the selected one from
99 // the target browser. This must happen first, before 102 // the target browser. This must happen first, before
100 // GetBrowserForDisposition() has a chance to replace |params->browser| with 103 // GetBrowserForDisposition() has a chance to replace |params->browser| with
101 // another one. 104 // another one.
102 if (!params->source_contents && params->browser) 105 if (!params->source_contents && params->browser)
103 params->source_contents = chrome::GetActiveTabContents(params->browser); 106 params->source_contents = chrome::GetActiveTabContents(params->browser);
104 107
105 Profile* profile = params->initiating_profile; 108 Profile* profile = params->initiating_profile;
106 109
107 switch (params->disposition) { 110 switch (params->disposition) {
108 case CURRENT_TAB: 111 case CURRENT_TAB:
109 if (params->browser) 112 if (params->browser)
110 return params->browser; 113 return params->browser;
111 // Find a compatible window and re-execute this command in it. Otherwise 114 // Find a compatible window and re-execute this command in it. Otherwise
112 // re-run with NEW_WINDOW. 115 // re-run with NEW_WINDOW.
113 return GetOrCreateBrowser(profile); 116 return GetOrCreateBrowser(profile, params->host_desktop_type);
114 case SINGLETON_TAB: 117 case SINGLETON_TAB:
115 case NEW_FOREGROUND_TAB: 118 case NEW_FOREGROUND_TAB:
116 case NEW_BACKGROUND_TAB: 119 case NEW_BACKGROUND_TAB:
117 // See if we can open the tab in the window this navigator is bound to. 120 // See if we can open the tab in the window this navigator is bound to.
118 if (params->browser && WindowCanOpenTabs(params->browser)) 121 if (params->browser && WindowCanOpenTabs(params->browser))
119 return params->browser; 122 return params->browser;
120 // Find a compatible window and re-execute this command in it. Otherwise 123 // Find a compatible window and re-execute this command in it. Otherwise
121 // re-run with NEW_WINDOW. 124 // re-run with NEW_WINDOW.
122 return GetOrCreateBrowser(profile); 125 return GetOrCreateBrowser(profile, params->host_desktop_type);
123 case NEW_POPUP: { 126 case NEW_POPUP: {
124 // Make a new popup window. 127 // Make a new popup window.
125 // Coerce app-style if |source| represents an app. 128 // Coerce app-style if |source| represents an app.
126 std::string app_name; 129 std::string app_name;
127 if (!params->extension_app_id.empty()) { 130 if (!params->extension_app_id.empty()) {
128 app_name = web_app::GenerateApplicationNameFromExtensionId( 131 app_name = web_app::GenerateApplicationNameFromExtensionId(
129 params->extension_app_id); 132 params->extension_app_id);
130 } else if (!params->browser->app_name().empty()) { 133 } else if (!params->browser->app_name().empty()) {
131 app_name = params->browser->app_name(); 134 app_name = params->browser->app_name();
132 } else if (params->source_contents) { 135 } else if (params->source_contents) {
(...skipping 13 matching lines...) Expand all
146 149
147 return new Browser(Browser::CreateParams::CreateForApp( 150 return new Browser(Browser::CreateParams::CreateForApp(
148 Browser::TYPE_POPUP, app_name, params->window_bounds, profile)); 151 Browser::TYPE_POPUP, app_name, params->window_bounds, profile));
149 } 152 }
150 case NEW_WINDOW: { 153 case NEW_WINDOW: {
151 // Make a new normal browser window. 154 // Make a new normal browser window.
152 return new Browser(Browser::CreateParams(profile)); 155 return new Browser(Browser::CreateParams(profile));
153 } 156 }
154 case OFF_THE_RECORD: 157 case OFF_THE_RECORD:
155 // Make or find an incognito window. 158 // Make or find an incognito window.
156 return GetOrCreateBrowser(profile->GetOffTheRecordProfile()); 159 return GetOrCreateBrowser(profile->GetOffTheRecordProfile(),
160 params->host_desktop_type);
157 // The following types all result in no navigation. 161 // The following types all result in no navigation.
158 case SUPPRESS_OPEN: 162 case SUPPRESS_OPEN:
159 case SAVE_TO_DISK: 163 case SAVE_TO_DISK:
160 case IGNORE_ACTION: 164 case IGNORE_ACTION:
161 return NULL; 165 return NULL;
162 default: 166 default:
163 NOTREACHED(); 167 NOTREACHED();
164 } 168 }
165 return NULL; 169 return NULL;
166 } 170 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 disposition(CURRENT_TAB), 313 disposition(CURRENT_TAB),
310 transition(a_transition), 314 transition(a_transition),
311 is_renderer_initiated(false), 315 is_renderer_initiated(false),
312 tabstrip_index(-1), 316 tabstrip_index(-1),
313 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 317 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
314 window_action(NO_ACTION), 318 window_action(NO_ACTION),
315 user_gesture(true), 319 user_gesture(true),
316 path_behavior(RESPECT), 320 path_behavior(RESPECT),
317 ref_behavior(IGNORE_REF), 321 ref_behavior(IGNORE_REF),
318 browser(a_browser), 322 browser(a_browser),
319 initiating_profile(NULL) {} 323 initiating_profile(NULL) {
324 if (a_browser)
325 host_desktop_type = a_browser->host_desktop_type();
326 else
327 host_desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
328 }
320 329
321 NavigateParams::NavigateParams(Browser* a_browser, 330 NavigateParams::NavigateParams(Browser* a_browser,
322 TabContents* a_target_contents) 331 TabContents* a_target_contents)
323 : target_contents(a_target_contents), 332 : target_contents(a_target_contents),
324 source_contents(NULL), 333 source_contents(NULL),
325 disposition(CURRENT_TAB), 334 disposition(CURRENT_TAB),
326 transition(content::PAGE_TRANSITION_LINK), 335 transition(content::PAGE_TRANSITION_LINK),
327 is_renderer_initiated(false), 336 is_renderer_initiated(false),
328 tabstrip_index(-1), 337 tabstrip_index(-1),
329 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 338 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
330 window_action(NO_ACTION), 339 window_action(NO_ACTION),
331 user_gesture(true), 340 user_gesture(true),
332 path_behavior(RESPECT), 341 path_behavior(RESPECT),
333 ref_behavior(IGNORE_REF), 342 ref_behavior(IGNORE_REF),
334 browser(a_browser), 343 browser(a_browser),
335 initiating_profile(NULL) {} 344 initiating_profile(NULL) {
345 if (a_browser)
346 host_desktop_type = a_browser->host_desktop_type();
347 else
348 host_desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE;
349 }
336 350
337 NavigateParams::NavigateParams(Profile* a_profile, 351 NavigateParams::NavigateParams(Profile* a_profile,
338 const GURL& a_url, 352 const GURL& a_url,
339 content::PageTransition a_transition) 353 content::PageTransition a_transition)
340 : url(a_url), 354 : url(a_url),
341 target_contents(NULL), 355 target_contents(NULL),
342 source_contents(NULL), 356 source_contents(NULL),
343 disposition(NEW_FOREGROUND_TAB), 357 disposition(NEW_FOREGROUND_TAB),
344 transition(a_transition), 358 transition(a_transition),
345 is_renderer_initiated(false), 359 is_renderer_initiated(false),
346 tabstrip_index(-1), 360 tabstrip_index(-1),
347 tabstrip_add_types(TabStripModel::ADD_ACTIVE), 361 tabstrip_add_types(TabStripModel::ADD_ACTIVE),
348 window_action(SHOW_WINDOW), 362 window_action(SHOW_WINDOW),
349 user_gesture(true), 363 user_gesture(true),
350 path_behavior(RESPECT), 364 path_behavior(RESPECT),
351 ref_behavior(IGNORE_REF), 365 ref_behavior(IGNORE_REF),
352 browser(NULL), 366 browser(NULL),
353 initiating_profile(a_profile) {} 367 initiating_profile(a_profile),
368 host_desktop_type(chrome::HOST_DESKTOP_TYPE_NATIVE) {}
354 369
355 NavigateParams::~NavigateParams() {} 370 NavigateParams::~NavigateParams() {}
356 371
357 void Navigate(NavigateParams* params) { 372 void Navigate(NavigateParams* params) {
358 Browser* source_browser = params->browser; 373 Browser* source_browser = params->browser;
359 if (source_browser) 374 if (source_browser)
360 params->initiating_profile = source_browser->profile(); 375 params->initiating_profile = source_browser->profile();
361 DCHECK(params->initiating_profile); 376 DCHECK(params->initiating_profile);
362 377
363 if (!AdjustNavigateParamsForURL(params)) 378 if (!AdjustNavigateParamsForURL(params))
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 return !(url.scheme() == chrome::kChromeUIScheme && 569 return !(url.scheme() == chrome::kChromeUIScheme &&
555 (url.host() == chrome::kChromeUISettingsHost || 570 (url.host() == chrome::kChromeUISettingsHost ||
556 url.host() == chrome::kChromeUISettingsFrameHost || 571 url.host() == chrome::kChromeUISettingsFrameHost ||
557 url.host() == chrome::kChromeUIExtensionsHost || 572 url.host() == chrome::kChromeUIExtensionsHost ||
558 url.host() == chrome::kChromeUIBookmarksHost || 573 url.host() == chrome::kChromeUIBookmarksHost ||
559 url.host() == chrome::kChromeUISyncPromoHost || 574 url.host() == chrome::kChromeUISyncPromoHost ||
560 url.host() == chrome::kChromeUIUberHost)); 575 url.host() == chrome::kChromeUIUberHost));
561 } 576 }
562 577
563 } // namespace chrome 578 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698