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

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

Issue 4055004: Change window opening behavior for HtmlDialogTabContentsDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased from trunk and fixed comments in HtmlDialogTabContentsDelegate Created 10 years, 1 month 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
« no previous file with comments | « chrome/browser/browser_navigator.h ('k') | chrome/browser/browser_navigator_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser_navigator.h" 5 #include "chrome/browser/browser_navigator.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_url_handler.h" 10 #include "chrome/browser/browser_url_handler.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return -1; 94 return -1;
95 } 95 }
96 96
97 // 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
98 // |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
99 // some other if that Browser is deemed incompatible. 99 // some other if that Browser is deemed incompatible.
100 Browser* GetBrowserForDisposition(browser::NavigateParams* params) { 100 Browser* GetBrowserForDisposition(browser::NavigateParams* params) {
101 // If no source TabContents was specified, we use the selected one from the 101 // If no source TabContents was specified, we use the selected one from the
102 // target browser. This must happen first, before GetBrowserForDisposition() 102 // target browser. This must happen first, before GetBrowserForDisposition()
103 // has a chance to replace |params->browser| with another one. 103 // has a chance to replace |params->browser| with another one.
104 if (!params->source_contents) 104 if (!params->source_contents && params->browser)
105 params->source_contents = params->browser->GetSelectedTabContents(); 105 params->source_contents = params->browser->GetSelectedTabContents();
106 106
107 Profile* profile =
108 params->browser ? params->browser->profile() : params->profile;
109
107 switch (params->disposition) { 110 switch (params->disposition) {
108 case CURRENT_TAB: 111 case CURRENT_TAB:
112 if (!params->browser && profile) {
113 // We specified a profile instead of a browser; find or create one.
114 params->browser = Browser::GetOrCreateTabbedBrowser(profile);
115 }
109 return params->browser; 116 return params->browser;
110 case SINGLETON_TAB: 117 case SINGLETON_TAB:
111 case NEW_FOREGROUND_TAB: 118 case NEW_FOREGROUND_TAB:
112 case NEW_BACKGROUND_TAB: 119 case NEW_BACKGROUND_TAB:
113 // 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.
114 if (WindowCanOpenTabs(params->browser)) 121 if (params->browser && WindowCanOpenTabs(params->browser))
115 return params->browser; 122 return params->browser;
116 // 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
117 // re-run with NEW_WINDOW. 124 // re-run with NEW_WINDOW.
118 return GetOrCreateBrowser(params->browser->profile()); 125 if (profile)
126 return GetOrCreateBrowser(profile);
127 return NULL;
119 case NEW_POPUP: { 128 case NEW_POPUP: {
120 // Make a new popup window. Coerce app-style if |params->browser| or the 129 // Make a new popup window. Coerce app-style if |params->browser| or the
121 // |source| represents an app. 130 // |source| represents an app.
122 Browser::Type type = Browser::TYPE_POPUP; 131 Browser::Type type = Browser::TYPE_POPUP;
123 if (params->browser->type() == Browser::TYPE_APP || 132 if ((params->browser && params->browser->type() == Browser::TYPE_APP) ||
124 (params->source_contents && params->source_contents->is_app())) { 133 (params->source_contents && params->source_contents->is_app())) {
125 type = Browser::TYPE_APP_POPUP; 134 type = Browser::TYPE_APP_POPUP;
126 } 135 }
127 Browser* browser = new Browser(type, params->browser->profile()); 136 if (profile) {
128 browser->set_override_bounds(params->window_bounds); 137 Browser* browser = new Browser(type, profile);
129 browser->CreateBrowserWindow(); 138 browser->set_override_bounds(params->window_bounds);
130 return browser; 139 browser->CreateBrowserWindow();
140 return browser;
141 }
142 return NULL;
131 } 143 }
132 case NEW_WINDOW: 144 case NEW_WINDOW:
133 // Make a new normal browser window. 145 // Make a new normal browser window.
134 return Browser::Create(params->browser->profile()); 146 if (profile) {
147 Browser* browser = new Browser(Browser::TYPE_NORMAL, profile);
148 browser->CreateBrowserWindow();
149 return browser;
150 }
151 return NULL;
135 case OFF_THE_RECORD: 152 case OFF_THE_RECORD:
136 // Make or find an incognito window. 153 // Make or find an incognito window.
137 return GetOrCreateBrowser( 154 if (profile)
138 params->browser->profile()->GetOffTheRecordProfile()); 155 return GetOrCreateBrowser(profile->GetOffTheRecordProfile());
156 return NULL;
139 // The following types all result in no navigation. 157 // The following types all result in no navigation.
140 case SUPPRESS_OPEN: 158 case SUPPRESS_OPEN:
141 case SAVE_TO_DISK: 159 case SAVE_TO_DISK:
142 case IGNORE_ACTION: 160 case IGNORE_ACTION:
143 return NULL; 161 return NULL;
144 default: 162 default:
145 NOTREACHED(); 163 NOTREACHED();
146 } 164 }
147 return NULL; 165 return NULL;
148 } 166 }
149 167
150 // Fix disposition and other parameter values depending on prevailing 168 // Fix disposition and other parameter values depending on prevailing
151 // conditions. 169 // conditions.
152 void NormalizeDisposition(browser::NavigateParams* params) { 170 void NormalizeDisposition(browser::NavigateParams* params) {
153 // Calculate the WindowOpenDisposition if necessary. 171 // Calculate the WindowOpenDisposition if necessary.
154 if (params->browser->tabstrip_model()->empty() && 172 if (params->browser->tabstrip_model()->empty() &&
155 (params->disposition == NEW_BACKGROUND_TAB || 173 (params->disposition == NEW_BACKGROUND_TAB ||
156 params->disposition == CURRENT_TAB)) { 174 params->disposition == CURRENT_TAB ||
175 params->disposition == SINGLETON_TAB)) {
157 params->disposition = NEW_FOREGROUND_TAB; 176 params->disposition = NEW_FOREGROUND_TAB;
158 } 177 }
159 if (params->browser->profile()->IsOffTheRecord() && 178 if (params->browser->profile()->IsOffTheRecord() &&
160 params->disposition == OFF_THE_RECORD) { 179 params->disposition == OFF_THE_RECORD) {
161 params->disposition = NEW_FOREGROUND_TAB; 180 params->disposition = NEW_FOREGROUND_TAB;
162 } 181 }
163 182
164 // Disposition trumps add types. ADD_SELECTED is a default, so we need to 183 // Disposition trumps add types. ADD_SELECTED is a default, so we need to
165 // remove it if disposition implies the tab is going to open in the 184 // remove it if disposition implies the tab is going to open in the
166 // background. 185 // background.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 const GURL& a_url, 253 const GURL& a_url,
235 PageTransition::Type a_transition) 254 PageTransition::Type a_transition)
236 : url(a_url), 255 : url(a_url),
237 target_contents(NULL), 256 target_contents(NULL),
238 source_contents(NULL), 257 source_contents(NULL),
239 disposition(CURRENT_TAB), 258 disposition(CURRENT_TAB),
240 transition(a_transition), 259 transition(a_transition),
241 tabstrip_index(-1), 260 tabstrip_index(-1),
242 tabstrip_add_types(TabStripModel::ADD_SELECTED), 261 tabstrip_add_types(TabStripModel::ADD_SELECTED),
243 show_window(false), 262 show_window(false),
244 browser(a_browser) { 263 browser(a_browser),
245 DCHECK(browser); 264 profile(NULL) {
246 } 265 }
247 266
248 NavigateParams::NavigateParams(Browser* a_browser, 267 NavigateParams::NavigateParams(Browser* a_browser,
249 TabContents* a_target_contents) 268 TabContents* a_target_contents)
250 : target_contents(a_target_contents), 269 : target_contents(a_target_contents),
251 source_contents(NULL), 270 source_contents(NULL),
252 disposition(CURRENT_TAB), 271 disposition(CURRENT_TAB),
253 transition(PageTransition::LINK), 272 transition(PageTransition::LINK),
254 tabstrip_index(-1), 273 tabstrip_index(-1),
255 tabstrip_add_types(TabStripModel::ADD_SELECTED), 274 tabstrip_add_types(TabStripModel::ADD_SELECTED),
256 show_window(false), 275 show_window(false),
257 browser(a_browser) { 276 browser(a_browser),
258 DCHECK(browser); 277 profile(NULL) {
259 } 278 }
260 279
261 NavigateParams::~NavigateParams() { 280 NavigateParams::~NavigateParams() {
262 } 281 }
263 282
264 void Navigate(NavigateParams* params) { 283 void Navigate(NavigateParams* params) {
265 params->browser = GetBrowserForDisposition(params); 284 params->browser = GetBrowserForDisposition(params);
266 if (!params->browser) 285 if (!params->browser)
267 return; 286 return;
268 // Navigate() must not return early after this point. 287 // Navigate() must not return early after this point.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // By default, content believes it is not hidden. When adding contents 322 // By default, content believes it is not hidden. When adding contents
304 // in the background, tell it that it's hidden. 323 // in the background, tell it that it's hidden.
305 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { 324 if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) {
306 // TabStripModel::AddTabContents invokes HideContents if not foreground. 325 // TabStripModel::AddTabContents invokes HideContents if not foreground.
307 params->target_contents->WasHidden(); 326 params->target_contents->WasHidden();
308 } 327 }
309 } else { 328 } else {
310 // ... otherwise if we're loading in the current tab, the target is the 329 // ... otherwise if we're loading in the current tab, the target is the
311 // same as the source. 330 // same as the source.
312 params->target_contents = params->source_contents; 331 params->target_contents = params->source_contents;
332 DCHECK(params->target_contents);
313 } 333 }
314 334
315 if (user_initiated) { 335 if (user_initiated) {
316 RenderViewHostDelegate::BrowserIntegration* integration = 336 RenderViewHostDelegate::BrowserIntegration* integration =
317 params->target_contents; 337 params->target_contents;
318 integration->OnUserGesture(); 338 integration->OnUserGesture();
319 } 339 }
320 340
321 // Perform the actual navigation. 341 // Perform the actual navigation.
322 GURL url = params->url.is_empty() ? params->browser->GetHomePage() 342 GURL url = params->url.is_empty() ? params->browser->GetHomePage()
(...skipping 30 matching lines...) Expand all
353 params->transition, 373 params->transition,
354 params->tabstrip_add_types); 374 params->tabstrip_add_types);
355 // Now that the |params->target_contents| is safely owned by the target 375 // Now that the |params->target_contents| is safely owned by the target
356 // Browser's TabStripModel, we can release ownership. 376 // Browser's TabStripModel, we can release ownership.
357 target_contents_owner.ReleaseOwnership(); 377 target_contents_owner.ReleaseOwnership();
358 } 378 }
359 } 379 }
360 } 380 }
361 381
362 } // namespace browser 382 } // namespace browser
363
OLDNEW
« no previous file with comments | « chrome/browser/browser_navigator.h ('k') | chrome/browser/browser_navigator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698