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.h" | 5 #include "chrome/browser/browser.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/animation.h" | 10 #include "app/animation.h" |
(...skipping 3189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3200 | 3200 |
3201 bool Browser::CanCloseWithInProgressDownloads() { | 3201 bool Browser::CanCloseWithInProgressDownloads() { |
3202 if (cancel_download_confirmation_state_ != NOT_PROMPTED) { | 3202 if (cancel_download_confirmation_state_ != NOT_PROMPTED) { |
3203 if (cancel_download_confirmation_state_ == WAITING_FOR_RESPONSE) { | 3203 if (cancel_download_confirmation_state_ == WAITING_FOR_RESPONSE) { |
3204 // We need to hear from the user before we can close. | 3204 // We need to hear from the user before we can close. |
3205 return false; | 3205 return false; |
3206 } | 3206 } |
3207 // RESPONSE_RECEIVED case, the user decided to go along with the closing. | 3207 // RESPONSE_RECEIVED case, the user decided to go along with the closing. |
3208 return true; | 3208 return true; |
3209 } | 3209 } |
3210 | 3210 // Indicated that normal (non-incognito) downloads are pending. |
| 3211 bool normal_downloads_are_present = false; |
| 3212 bool incognito_downloads_are_present = false; |
3211 // If there are no download in-progress, our job is done. | 3213 // If there are no download in-progress, our job is done. |
3212 DownloadManager* download_manager = profile_->GetDownloadManager(); | 3214 DownloadManager* download_manager = profile_->GetDownloadManager(); |
3213 if (!download_manager || download_manager->in_progress_count() == 0) | 3215 if (profile_->IsOffTheRecord()) { |
| 3216 // Browser is incognito and so download_manager if present is for incognito |
| 3217 // downloads. |
| 3218 incognito_downloads_are_present = |
| 3219 (download_manager && download_manager->in_progress_count() != 0); |
| 3220 // Check original profile. |
| 3221 download_manager = profile_->GetOriginalProfile()->GetDownloadManager(); |
| 3222 } |
| 3223 |
| 3224 normal_downloads_are_present = |
| 3225 (download_manager && download_manager->in_progress_count() != 0); |
| 3226 if (!normal_downloads_are_present && !incognito_downloads_are_present) |
| 3227 return true; |
| 3228 |
| 3229 if (is_attempting_to_close_browser_) |
| 3230 return true; |
| 3231 |
| 3232 if ((!normal_downloads_are_present && !profile()->IsOffTheRecord()) || |
| 3233 (!incognito_downloads_are_present && profile()->IsOffTheRecord())) |
3214 return true; | 3234 return true; |
3215 | 3235 |
3216 // Let's figure out if we are the last window for our profile. | 3236 // Let's figure out if we are the last window for our profile. |
3217 // Note that we cannot just use BrowserList::GetBrowserCount as browser | 3237 // Note that we cannot just use BrowserList::GetBrowserCount as browser |
3218 // windows closing is delayed and the returned count might include windows | 3238 // windows closing is delayed and the returned count might include windows |
3219 // that are being closed. | 3239 // that are being closed. |
| 3240 // The browser allowed to be closed only if: |
| 3241 // 1. It is a regular browser and there are no regular downloads present or |
| 3242 // this is not the last regular browser window. |
| 3243 // 2. It is an incognito browser and there are no incognito downloads present |
| 3244 // or this is not the last incognito browser window. |
3220 int count = 0; | 3245 int count = 0; |
3221 for (BrowserList::const_iterator iter = BrowserList::begin(); | 3246 for (BrowserList::const_iterator iter = BrowserList::begin(); |
3222 iter != BrowserList::end(); ++iter) { | 3247 iter != BrowserList::end(); ++iter) { |
3223 // Don't count this browser window or any other in the process of closing. | 3248 // Don't count this browser window or any other in the process of closing. |
3224 if (*iter == this || (*iter)->is_attempting_to_close_browser_) | 3249 if (*iter == this || (*iter)->is_attempting_to_close_browser_) |
3225 continue; | 3250 continue; |
3226 | 3251 |
| 3252 // Verify that this is not the last non-incognito or incognito browser, |
| 3253 // depending on the pending downloads. |
| 3254 if (normal_downloads_are_present && !profile()->IsOffTheRecord() && |
| 3255 (*iter)->profile()->IsOffTheRecord()) |
| 3256 continue; |
| 3257 if (incognito_downloads_are_present && profile()->IsOffTheRecord() && |
| 3258 !(*iter)->profile()->IsOffTheRecord()) |
| 3259 continue; |
| 3260 |
3227 // We test the original profile, because an incognito browser window keeps | 3261 // We test the original profile, because an incognito browser window keeps |
3228 // the original profile alive (and its DownloadManager). | 3262 // the original profile alive (and its DownloadManager). |
3229 // We also need to test explicitly the profile directly so that 2 incognito | 3263 // We also need to test explicitly the profile directly so that 2 incognito |
3230 // profiles count as a match. | 3264 // profiles count as a match. |
3231 if ((*iter)->profile() == profile() || | 3265 if ((*iter)->profile() == profile() || |
3232 (*iter)->profile()->GetOriginalProfile() == profile()) | 3266 (*iter)->profile()->GetOriginalProfile() == profile()) |
3233 count++; | 3267 count++; |
3234 } | 3268 } |
3235 if (count > 0) | 3269 if (count > 0) |
3236 return true; | 3270 return true; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3496 if (TabHasUnloadListener(contents)) { | 3530 if (TabHasUnloadListener(contents)) { |
3497 // If the page has unload listeners, then we tell the renderer to fire | 3531 // If the page has unload listeners, then we tell the renderer to fire |
3498 // them. Once they have fired, we'll get a message back saying whether | 3532 // them. Once they have fired, we'll get a message back saying whether |
3499 // to proceed closing the page or not, which sends us back to this method | 3533 // to proceed closing the page or not, which sends us back to this method |
3500 // with the HasUnloadListener bit cleared. | 3534 // with the HasUnloadListener bit cleared. |
3501 contents->render_view_host()->FirePageBeforeUnload(false); | 3535 contents->render_view_host()->FirePageBeforeUnload(false); |
3502 return true; | 3536 return true; |
3503 } | 3537 } |
3504 return false; | 3538 return false; |
3505 } | 3539 } |
OLD | NEW |