OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 } | 2830 } |
2831 } | 2831 } |
2832 } | 2832 } |
2833 | 2833 |
2834 void Browser::CloseContents(TabContents* source) { | 2834 void Browser::CloseContents(TabContents* source) { |
2835 if (is_attempting_to_close_browser_) { | 2835 if (is_attempting_to_close_browser_) { |
2836 // If we're trying to close the browser, just clear the state related to | 2836 // If we're trying to close the browser, just clear the state related to |
2837 // waiting for unload to fire. Don't actually try to close the tab as it | 2837 // waiting for unload to fire. Don't actually try to close the tab as it |
2838 // will go down the slow shutdown path instead of the fast path of killing | 2838 // will go down the slow shutdown path instead of the fast path of killing |
2839 // all the renderer processes. | 2839 // all the renderer processes. |
2840 ClearUnloadState(source, true); | 2840 ClearUnloadState(source); |
2841 return; | 2841 return; |
2842 } | 2842 } |
2843 | 2843 |
2844 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); | 2844 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); |
2845 if (index == TabStripModel::kNoTab) { | 2845 if (index == TabStripModel::kNoTab) { |
2846 NOTREACHED() << "CloseContents called for tab not in our strip"; | 2846 NOTREACHED() << "CloseContents called for tab not in our strip"; |
2847 return; | 2847 return; |
2848 } | 2848 } |
2849 tab_handler_->GetTabStripModel()->CloseTabContentsAt( | 2849 tab_handler_->GetTabStripModel()->CloseTabContentsAt( |
2850 index, | 2850 index, |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3191 | 3191 |
3192 /////////////////////////////////////////////////////////////////////////////// | 3192 /////////////////////////////////////////////////////////////////////////////// |
3193 // Browser, NotificationObserver implementation: | 3193 // Browser, NotificationObserver implementation: |
3194 | 3194 |
3195 void Browser::Observe(NotificationType type, | 3195 void Browser::Observe(NotificationType type, |
3196 const NotificationSource& source, | 3196 const NotificationSource& source, |
3197 const NotificationDetails& details) { | 3197 const NotificationDetails& details) { |
3198 switch (type.value) { | 3198 switch (type.value) { |
3199 case NotificationType::TAB_CONTENTS_DISCONNECTED: | 3199 case NotificationType::TAB_CONTENTS_DISCONNECTED: |
3200 if (is_attempting_to_close_browser_) { | 3200 if (is_attempting_to_close_browser_) { |
3201 // Pass in false so that we delay processing. We need to delay the | 3201 // Need to do this asynchronously as it will close the tab, which is |
3202 // processing as it may close the tab, which is currently on the call | 3202 // currently on the call stack above us. |
3203 // stack above us. | 3203 MessageLoop::current()->PostTask( |
3204 ClearUnloadState(Source<TabContents>(source).ptr(), false); | 3204 FROM_HERE, |
| 3205 method_factory_.NewRunnableMethod(&Browser::ClearUnloadState, |
| 3206 Source<TabContents>(source).ptr())); |
3205 } | 3207 } |
3206 break; | 3208 break; |
3207 | 3209 |
3208 case NotificationType::SSL_VISIBLE_STATE_CHANGED: | 3210 case NotificationType::SSL_VISIBLE_STATE_CHANGED: |
3209 // When the current tab's SSL state changes, we need to update the URL | 3211 // When the current tab's SSL state changes, we need to update the URL |
3210 // bar to reflect the new state. Note that it's possible for the selected | 3212 // bar to reflect the new state. Note that it's possible for the selected |
3211 // tab contents to be NULL. This is because we listen for all sources | 3213 // tab contents to be NULL. This is because we listen for all sources |
3212 // (NavigationControllers) for convenience, so the notification could | 3214 // (NavigationControllers) for convenience, so the notification could |
3213 // actually be for a different window while we're doing asynchronous | 3215 // actually be for a different window while we're doing asynchronous |
3214 // closing of this one. | 3216 // closing of this one. |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3851 | 3853 |
3852 // Process beforeunload tabs first. When that queue is empty, process | 3854 // Process beforeunload tabs first. When that queue is empty, process |
3853 // unload tabs. | 3855 // unload tabs. |
3854 if (!tabs_needing_before_unload_fired_.empty()) { | 3856 if (!tabs_needing_before_unload_fired_.empty()) { |
3855 TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); | 3857 TabContents* tab = *(tabs_needing_before_unload_fired_.begin()); |
3856 // Null check render_view_host here as this gets called on a PostTask and | 3858 // Null check render_view_host here as this gets called on a PostTask and |
3857 // the tab's render_view_host may have been nulled out. | 3859 // the tab's render_view_host may have been nulled out. |
3858 if (tab->render_view_host()) { | 3860 if (tab->render_view_host()) { |
3859 tab->render_view_host()->FirePageBeforeUnload(false); | 3861 tab->render_view_host()->FirePageBeforeUnload(false); |
3860 } else { | 3862 } else { |
3861 ClearUnloadState(tab, true); | 3863 ClearUnloadState(tab); |
3862 } | 3864 } |
3863 } else if (!tabs_needing_unload_fired_.empty()) { | 3865 } else if (!tabs_needing_unload_fired_.empty()) { |
3864 // We've finished firing all beforeunload events and can proceed with unload | 3866 // We've finished firing all beforeunload events and can proceed with unload |
3865 // events. | 3867 // events. |
3866 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting | 3868 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
3867 // somewhere around here so that we have accurate measurements of shutdown | 3869 // somewhere around here so that we have accurate measurements of shutdown |
3868 // time. | 3870 // time. |
3869 // TODO(ojan): We can probably fire all the unload events in parallel and | 3871 // TODO(ojan): We can probably fire all the unload events in parallel and |
3870 // get a perf benefit from that in the cases where the tab hangs in it's | 3872 // get a perf benefit from that in the cases where the tab hangs in it's |
3871 // unload handler or takes a long time to page in. | 3873 // unload handler or takes a long time to page in. |
3872 TabContents* tab = *(tabs_needing_unload_fired_.begin()); | 3874 TabContents* tab = *(tabs_needing_unload_fired_.begin()); |
3873 // Null check render_view_host here as this gets called on a PostTask and | 3875 // Null check render_view_host here as this gets called on a PostTask and |
3874 // the tab's render_view_host may have been nulled out. | 3876 // the tab's render_view_host may have been nulled out. |
3875 if (tab->render_view_host()) { | 3877 if (tab->render_view_host()) { |
3876 tab->render_view_host()->ClosePage(false, -1, -1); | 3878 tab->render_view_host()->ClosePage(false, -1, -1); |
3877 } else { | 3879 } else { |
3878 ClearUnloadState(tab, true); | 3880 ClearUnloadState(tab); |
3879 } | 3881 } |
3880 } else { | 3882 } else { |
3881 NOTREACHED(); | 3883 NOTREACHED(); |
3882 } | 3884 } |
3883 } | 3885 } |
3884 | 3886 |
3885 bool Browser::HasCompletedUnloadProcessing() const { | 3887 bool Browser::HasCompletedUnloadProcessing() const { |
3886 return is_attempting_to_close_browser_ && | 3888 return is_attempting_to_close_browser_ && |
3887 tabs_needing_before_unload_fired_.empty() && | 3889 tabs_needing_before_unload_fired_.empty() && |
3888 tabs_needing_unload_fired_.empty(); | 3890 tabs_needing_unload_fired_.empty(); |
(...skipping 19 matching lines...) Expand all Loading... |
3908 DCHECK(is_attempting_to_close_browser_); | 3910 DCHECK(is_attempting_to_close_browser_); |
3909 | 3911 |
3910 UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); | 3912 UnloadListenerSet::iterator iter = std::find(set->begin(), set->end(), tab); |
3911 if (iter != set->end()) { | 3913 if (iter != set->end()) { |
3912 set->erase(iter); | 3914 set->erase(iter); |
3913 return true; | 3915 return true; |
3914 } | 3916 } |
3915 return false; | 3917 return false; |
3916 } | 3918 } |
3917 | 3919 |
3918 void Browser::ClearUnloadState(TabContents* tab, bool process_now) { | 3920 void Browser::ClearUnloadState(TabContents* tab) { |
3919 // Closing of browser could be canceled (via IsClosingPermitted) between the | 3921 // Closing of browser could be canceled (via IsClosingPermitted) between the |
3920 // time when request was initiated and when this method is called, so check | 3922 // time when request was initiated and when this method is called, so check |
3921 // for is_attempting_to_close_browser_ flag before proceeding. | 3923 // for is_attempting_to_close_browser_ flag before proceeding. |
3922 if (is_attempting_to_close_browser_) { | 3924 if (is_attempting_to_close_browser_) { |
3923 RemoveFromSet(&tabs_needing_before_unload_fired_, tab); | 3925 RemoveFromSet(&tabs_needing_before_unload_fired_, tab); |
3924 RemoveFromSet(&tabs_needing_unload_fired_, tab); | 3926 RemoveFromSet(&tabs_needing_unload_fired_, tab); |
3925 if (process_now) { | 3927 ProcessPendingTabs(); |
3926 ProcessPendingTabs(); | |
3927 } else { | |
3928 MessageLoop::current()->PostTask( | |
3929 FROM_HERE, | |
3930 method_factory_.NewRunnableMethod(&Browser::ProcessPendingTabs)); | |
3931 } | |
3932 } | 3928 } |
3933 } | 3929 } |
3934 | 3930 |
| 3931 |
3935 /////////////////////////////////////////////////////////////////////////////// | 3932 /////////////////////////////////////////////////////////////////////////////// |
3936 // Browser, In-progress download termination handling (private): | 3933 // Browser, In-progress download termination handling (private): |
3937 | 3934 |
3938 void Browser::CheckDownloadsInProgress(bool* normal_downloads_are_present, | 3935 void Browser::CheckDownloadsInProgress(bool* normal_downloads_are_present, |
3939 bool* incognito_downloads_are_present) { | 3936 bool* incognito_downloads_are_present) { |
3940 *normal_downloads_are_present = false; | 3937 *normal_downloads_are_present = false; |
3941 *incognito_downloads_are_present = false; | 3938 *incognito_downloads_are_present = false; |
3942 | 3939 |
3943 // If there are no download in-progress, our job is done. | 3940 // If there are no download in-progress, our job is done. |
3944 DownloadManager* download_manager = NULL; | 3941 DownloadManager* download_manager = NULL; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4083 } | 4080 } |
4084 | 4081 |
4085 contents->tab_contents()->set_delegate(NULL); | 4082 contents->tab_contents()->set_delegate(NULL); |
4086 RemoveScheduledUpdatesFor(contents->tab_contents()); | 4083 RemoveScheduledUpdatesFor(contents->tab_contents()); |
4087 | 4084 |
4088 if (find_bar_controller_.get() && | 4085 if (find_bar_controller_.get() && |
4089 index == tab_handler_->GetTabStripModel()->selected_index()) { | 4086 index == tab_handler_->GetTabStripModel()->selected_index()) { |
4090 find_bar_controller_->ChangeTabContents(NULL); | 4087 find_bar_controller_->ChangeTabContents(NULL); |
4091 } | 4088 } |
4092 | 4089 |
4093 if (is_attempting_to_close_browser_) { | |
4094 // If this is the last tab with unload handlers, then ProcessPendingTabs | |
4095 // would call back into the TabStripModel (which is invoking this method on | |
4096 // us). Avoid that by passing in false so that the call to | |
4097 // ProcessPendingTabs is delayed. | |
4098 ClearUnloadState(contents->tab_contents(), false); | |
4099 } | |
4100 | |
4101 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | 4090 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, |
4102 Source<TabContentsWrapper>(contents)); | 4091 Source<TabContentsWrapper>(contents)); |
4103 } | 4092 } |
4104 | 4093 |
4105 // static | 4094 // static |
4106 void Browser::RegisterAppPrefs(const std::string& app_name) { | 4095 void Browser::RegisterAppPrefs(const std::string& app_name) { |
4107 // A set of apps that we've already started. | 4096 // A set of apps that we've already started. |
4108 static std::set<std::string>* g_app_names = NULL; | 4097 static std::set<std::string>* g_app_names = NULL; |
4109 | 4098 |
4110 if (!g_app_names) | 4099 if (!g_app_names) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4247 // The page transition below is only for the purpose of inserting the tab. | 4236 // The page transition below is only for the purpose of inserting the tab. |
4248 browser->AddTab(view_source_contents, PageTransition::LINK); | 4237 browser->AddTab(view_source_contents, PageTransition::LINK); |
4249 } | 4238 } |
4250 | 4239 |
4251 if (profile_->HasSessionService()) { | 4240 if (profile_->HasSessionService()) { |
4252 SessionService* session_service = profile_->GetSessionService(); | 4241 SessionService* session_service = profile_->GetSessionService(); |
4253 if (session_service) | 4242 if (session_service) |
4254 session_service->TabRestored(&view_source_contents->controller(), false); | 4243 session_service->TabRestored(&view_source_contents->controller(), false); |
4255 } | 4244 } |
4256 } | 4245 } |
OLD | NEW |