| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "chrome/browser/browser_shutdown.h" | 40 #include "chrome/browser/browser_shutdown.h" |
| 41 #include "chrome/browser/chrome_notification_types.h" | 41 #include "chrome/browser/chrome_notification_types.h" |
| 42 #include "chrome/browser/content_settings/mixed_content_settings_tab_helper.h" | 42 #include "chrome/browser/content_settings/mixed_content_settings_tab_helper.h" |
| 43 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 43 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 44 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 44 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 45 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 45 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 46 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" | 46 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" |
| 47 #include "chrome/browser/defaults.h" | 47 #include "chrome/browser/defaults.h" |
| 48 #include "chrome/browser/devtools/devtools_toggle_action.h" | 48 #include "chrome/browser/devtools/devtools_toggle_action.h" |
| 49 #include "chrome/browser/devtools/devtools_window.h" | 49 #include "chrome/browser/devtools/devtools_window.h" |
| 50 #include "chrome/browser/download/download_service.h" | 50 #include "chrome/browser/download/download_core_service.h" |
| 51 #include "chrome/browser/download/download_service_factory.h" | 51 #include "chrome/browser/download/download_core_service_factory.h" |
| 52 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" | 52 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" |
| 53 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" | 53 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" |
| 54 #include "chrome/browser/extensions/browser_extension_window_controller.h" | 54 #include "chrome/browser/extensions/browser_extension_window_controller.h" |
| 55 #include "chrome/browser/extensions/extension_service.h" | 55 #include "chrome/browser/extensions/extension_service.h" |
| 56 #include "chrome/browser/extensions/extension_ui_util.h" | 56 #include "chrome/browser/extensions/extension_ui_util.h" |
| 57 #include "chrome/browser/extensions/extension_util.h" | 57 #include "chrome/browser/extensions/extension_util.h" |
| 58 #include "chrome/browser/extensions/tab_helper.h" | 58 #include "chrome/browser/extensions/tab_helper.h" |
| 59 #include "chrome/browser/file_select_helper.h" | 59 #include "chrome/browser/file_select_helper.h" |
| 60 #include "chrome/browser/first_run/first_run.h" | 60 #include "chrome/browser/first_run/first_run.h" |
| 61 #include "chrome/browser/infobars/infobar_service.h" | 61 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 BrowserList::RemoveBrowser(this); | 495 BrowserList::RemoveBrowser(this); |
| 496 | 496 |
| 497 // If closing the window is going to trigger a shutdown, then we need to | 497 // If closing the window is going to trigger a shutdown, then we need to |
| 498 // schedule all active downloads to be cancelled. This needs to be after | 498 // schedule all active downloads to be cancelled. This needs to be after |
| 499 // removing |this| from BrowserList so that OkToClose...() can determine | 499 // removing |this| from BrowserList so that OkToClose...() can determine |
| 500 // whether there are any other windows open for the browser. | 500 // whether there are any other windows open for the browser. |
| 501 int num_downloads; | 501 int num_downloads; |
| 502 if (!browser_defaults::kBrowserAliveWithNoWindows && | 502 if (!browser_defaults::kBrowserAliveWithNoWindows && |
| 503 OkToCloseWithInProgressDownloads(&num_downloads) == | 503 OkToCloseWithInProgressDownloads(&num_downloads) == |
| 504 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN) { | 504 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN) { |
| 505 DownloadService::CancelAllDownloads(); | 505 DownloadCoreService::CancelAllDownloads(); |
| 506 } | 506 } |
| 507 | 507 |
| 508 SessionService* session_service = | 508 SessionService* session_service = |
| 509 SessionServiceFactory::GetForProfile(profile_); | 509 SessionServiceFactory::GetForProfile(profile_); |
| 510 if (session_service) | 510 if (session_service) |
| 511 session_service->WindowClosed(session_id_); | 511 session_service->WindowClosed(session_id_); |
| 512 | 512 |
| 513 sessions::TabRestoreService* tab_restore_service = | 513 sessions::TabRestoreService* tab_restore_service = |
| 514 TabRestoreServiceFactory::GetForProfile(profile()); | 514 TabRestoreServiceFactory::GetForProfile(profile()); |
| 515 if (tab_restore_service) | 515 if (tab_restore_service) |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 int* num_downloads_blocking) const { | 791 int* num_downloads_blocking) const { |
| 792 DCHECK(num_downloads_blocking); | 792 DCHECK(num_downloads_blocking); |
| 793 *num_downloads_blocking = 0; | 793 *num_downloads_blocking = 0; |
| 794 | 794 |
| 795 // If we're not running a full browser process with a profile manager | 795 // If we're not running a full browser process with a profile manager |
| 796 // (testing), it's ok to close the browser. | 796 // (testing), it's ok to close the browser. |
| 797 if (!g_browser_process->profile_manager()) | 797 if (!g_browser_process->profile_manager()) |
| 798 return DOWNLOAD_CLOSE_OK; | 798 return DOWNLOAD_CLOSE_OK; |
| 799 | 799 |
| 800 int total_download_count = | 800 int total_download_count = |
| 801 DownloadService::NonMaliciousDownloadCountAllProfiles(); | 801 DownloadCoreService::NonMaliciousDownloadCountAllProfiles(); |
| 802 if (total_download_count == 0) | 802 if (total_download_count == 0) |
| 803 return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. | 803 return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 804 | 804 |
| 805 // Figure out how many windows are open total, and associated with this | 805 // Figure out how many windows are open total, and associated with this |
| 806 // profile, that are relevant for the ok-to-close decision. | 806 // profile, that are relevant for the ok-to-close decision. |
| 807 int profile_window_count = 0; | 807 int profile_window_count = 0; |
| 808 int total_window_count = 0; | 808 int total_window_count = 0; |
| 809 for (auto* browser : *BrowserList::GetInstance()) { | 809 for (auto* browser : *BrowserList::GetInstance()) { |
| 810 // Don't count this browser window or any other in the process of closing. | 810 // Don't count this browser window or any other in the process of closing. |
| 811 // Window closing may be delayed, and windows that are in the process of | 811 // Window closing may be delayed, and windows that are in the process of |
| 812 // closing don't count against our totals. | 812 // closing don't count against our totals. |
| 813 if (browser == this || browser->IsAttemptingToCloseBrowser()) | 813 if (browser == this || browser->IsAttemptingToCloseBrowser()) |
| 814 continue; | 814 continue; |
| 815 | 815 |
| 816 if (browser->profile() == profile()) | 816 if (browser->profile() == profile()) |
| 817 profile_window_count++; | 817 profile_window_count++; |
| 818 total_window_count++; | 818 total_window_count++; |
| 819 } | 819 } |
| 820 | 820 |
| 821 // If there aren't any other windows, we're at browser shutdown, | 821 // If there aren't any other windows, we're at browser shutdown, |
| 822 // which would cancel all current downloads. | 822 // which would cancel all current downloads. |
| 823 if (total_window_count == 0) { | 823 if (total_window_count == 0) { |
| 824 *num_downloads_blocking = total_download_count; | 824 *num_downloads_blocking = total_download_count; |
| 825 return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; | 825 return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 826 } | 826 } |
| 827 | 827 |
| 828 // If there aren't any other windows on our profile, and we're an incognito | 828 // If there aren't any other windows on our profile, and we're an incognito |
| 829 // profile, and there are downloads associated with that profile, | 829 // profile, and there are downloads associated with that profile, |
| 830 // those downloads would be cancelled by our window (-> profile) close. | 830 // those downloads would be cancelled by our window (-> profile) close. |
| 831 DownloadService* download_service = | 831 DownloadCoreService* download_core_service = |
| 832 DownloadServiceFactory::GetForBrowserContext(profile()); | 832 DownloadCoreServiceFactory::GetForBrowserContext(profile()); |
| 833 if ((profile_window_count == 0) && | 833 if ((profile_window_count == 0) && |
| 834 (download_service->NonMaliciousDownloadCount() > 0) && | 834 (download_core_service->NonMaliciousDownloadCount() > 0) && |
| 835 profile()->IsOffTheRecord()) { | 835 profile()->IsOffTheRecord()) { |
| 836 *num_downloads_blocking = download_service->NonMaliciousDownloadCount(); | 836 *num_downloads_blocking = |
| 837 download_core_service->NonMaliciousDownloadCount(); |
| 837 return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; | 838 return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 838 } | 839 } |
| 839 | 840 |
| 840 // Those are the only conditions under which we will block shutdown. | 841 // Those are the only conditions under which we will block shutdown. |
| 841 return DOWNLOAD_CLOSE_OK; | 842 return DOWNLOAD_CLOSE_OK; |
| 842 } | 843 } |
| 843 | 844 |
| 844 //////////////////////////////////////////////////////////////////////////////// | 845 //////////////////////////////////////////////////////////////////////////////// |
| 845 // Browser, Tab adding/showing functions: | 846 // Browser, Tab adding/showing functions: |
| 846 | 847 |
| (...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2628 // new window later, thus we need to navigate the window now. | 2629 // new window later, thus we need to navigate the window now. |
| 2629 if (contents) { | 2630 if (contents) { |
| 2630 contents->web_contents()->GetController().LoadURL( | 2631 contents->web_contents()->GetController().LoadURL( |
| 2631 target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 2632 target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 2632 std::string()); // No extra headers. | 2633 std::string()); // No extra headers. |
| 2633 } | 2634 } |
| 2634 } | 2635 } |
| 2635 | 2636 |
| 2636 return contents != NULL; | 2637 return contents != NULL; |
| 2637 } | 2638 } |
| OLD | NEW |