| OLD | NEW |
| 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_window.h" | 10 #include "chrome/browser/browser_window.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // Calculate the WindowOpenDisposition if necessary. | 107 // Calculate the WindowOpenDisposition if necessary. |
| 108 if (params->browser->tabstrip_model()->empty() && | 108 if (params->browser->tabstrip_model()->empty() && |
| 109 params->disposition == NEW_BACKGROUND_TAB) { | 109 params->disposition == NEW_BACKGROUND_TAB) { |
| 110 params->disposition = NEW_FOREGROUND_TAB; | 110 params->disposition = NEW_FOREGROUND_TAB; |
| 111 } | 111 } |
| 112 if (params->browser->profile()->IsOffTheRecord() && | 112 if (params->browser->profile()->IsOffTheRecord() && |
| 113 params->disposition == OFF_THE_RECORD) { | 113 params->disposition == OFF_THE_RECORD) { |
| 114 params->disposition = NEW_FOREGROUND_TAB; | 114 params->disposition = NEW_FOREGROUND_TAB; |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Disposition trumps add types. ADD_SELECTED is a default, so we need to | 117 switch (params->disposition) { |
| 118 // remove it if disposition implies the tab is going to open in the | 118 case NEW_BACKGROUND_TAB: |
| 119 // background. | 119 // Disposition trumps add types. ADD_SELECTED is a default, so we need to |
| 120 if (params->disposition == NEW_BACKGROUND_TAB) | 120 // remove it if disposition implies the tab is going to open in the |
| 121 params->tabstrip_add_types &= ~TabStripModel::ADD_SELECTED; | 121 // background. |
| 122 params->tabstrip_add_types &= ~TabStripModel::ADD_SELECTED; |
| 123 break; |
| 124 |
| 125 case NEW_WINDOW: |
| 126 case NEW_POPUP: |
| 127 // Code that wants to open a new window typically expects it to be shown |
| 128 // automatically. |
| 129 params->show_window = true; |
| 130 // Fall-through. |
| 131 case NEW_FOREGROUND_TAB: |
| 132 case SINGLETON_TAB: |
| 133 params->tabstrip_add_types |= TabStripModel::ADD_SELECTED; |
| 134 break; |
| 135 |
| 136 default: |
| 137 break; |
| 138 } |
| 122 } | 139 } |
| 123 | 140 |
| 124 // This class makes sure the Browser object held in |params| is made visible | 141 // This class makes sure the Browser object held in |params| is made visible |
| 125 // by the time it goes out of scope, provided |params| wants it to be shown. | 142 // by the time it goes out of scope, provided |params| wants it to be shown. |
| 126 class ScopedBrowserDisplayer { | 143 class ScopedBrowserDisplayer { |
| 127 public: | 144 public: |
| 128 explicit ScopedBrowserDisplayer(browser::NavigateParams* params) | 145 explicit ScopedBrowserDisplayer(browser::NavigateParams* params) |
| 129 : params_(params) { | 146 : params_(params) { |
| 130 } | 147 } |
| 131 ~ScopedBrowserDisplayer() { | 148 ~ScopedBrowserDisplayer() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 tabstrip_add_types(TabStripModel::ADD_SELECTED), | 218 tabstrip_add_types(TabStripModel::ADD_SELECTED), |
| 202 show_window(false), | 219 show_window(false), |
| 203 browser(a_browser) { | 220 browser(a_browser) { |
| 204 DCHECK(browser); | 221 DCHECK(browser); |
| 205 } | 222 } |
| 206 | 223 |
| 207 NavigateParams::~NavigateParams() { | 224 NavigateParams::~NavigateParams() { |
| 208 } | 225 } |
| 209 | 226 |
| 210 void Navigate(NavigateParams* params, NavigatorDelegate* delegate) { | 227 void Navigate(NavigateParams* params, NavigatorDelegate* delegate) { |
| 228 Browser* browser = params->browser; |
| 211 DCHECK(delegate); | 229 DCHECK(delegate); |
| 212 params->browser = GetBrowserForDisposition(params); | 230 params->browser = GetBrowserForDisposition(params); |
| 213 if (!params->browser) | 231 if (!params->browser) |
| 214 return; | 232 return; |
| 215 // Navigate() must not return early after this point. | 233 // Navigate() must not return early after this point. |
| 216 | 234 |
| 235 if (browser != params->browser && |
| 236 params->browser->tabstrip_model()->empty()) { |
| 237 // A new window has been created. So it needs to be displayed. |
| 238 params->show_window = true; |
| 239 } |
| 240 |
| 217 // Make sure the Browser is shown if params call for it. | 241 // Make sure the Browser is shown if params call for it. |
| 218 ScopedBrowserDisplayer displayer(params); | 242 ScopedBrowserDisplayer displayer(params); |
| 219 | 243 |
| 220 // Makes sure any TabContents created by this function is destroyed if | 244 // Makes sure any TabContents created by this function is destroyed if |
| 221 // not properly added to a tab strip. | 245 // not properly added to a tab strip. |
| 222 ScopedTargetContentsOwner target_contents_owner(params); | 246 ScopedTargetContentsOwner target_contents_owner(params); |
| 223 | 247 |
| 224 // Some dispositions need coercion to base types. | 248 // Some dispositions need coercion to base types. |
| 225 NormalizeDisposition(params); | 249 NormalizeDisposition(params); |
| 226 | 250 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 params->transition, | 309 params->transition, |
| 286 params->tabstrip_add_types); | 310 params->tabstrip_add_types); |
| 287 // Now that the |params->target_contents| is safely owned by the target | 311 // Now that the |params->target_contents| is safely owned by the target |
| 288 // Browser's TabStripModel, we can release ownership. | 312 // Browser's TabStripModel, we can release ownership. |
| 289 target_contents_owner.ReleaseOwnership(); | 313 target_contents_owner.ReleaseOwnership(); |
| 290 } | 314 } |
| 291 } | 315 } |
| 292 | 316 |
| 293 } // namespace browser | 317 } // namespace browser |
| 294 | 318 |
| OLD | NEW |