| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 | 16 |
| 17 class Browser; | 17 class Browser; |
| 18 class TabStripModel; | 18 class TabStripModel; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class NotificationSource; | 21 class NotificationSource; |
| 22 class NotifictaionDetails; | 22 class NotifictaionDetails; |
| 23 class WebContents; | 23 class WebContents; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace chrome { | 26 namespace chrome { |
| 27 // UnloadController manages closing tabs and windows -- especially in | 27 // FastUnloadController manages closing tabs and windows -- especially in |
| 28 // regards to beforeunload handlers (have proceed/cancel dialogs) and | 28 // regards to beforeunload handlers (have proceed/cancel dialogs) and |
| 29 // unload handlers (have no user interaction). | 29 // unload handlers (have no user interaction). |
| 30 // | 30 // |
| 31 // Typical flow of closing a tab: | 31 // Typical flow of closing a tab: |
| 32 // 1. Browser calls CanCloseContents(). | 32 // 1. Browser calls CanCloseContents(). |
| 33 // If true, browser calls contents::CloseWebContents(). | 33 // If true, browser calls contents::CloseWebContents(). |
| 34 // 2. WebContents notifies us via its delegate and BeforeUnloadFired() | 34 // 2. WebContents notifies us via its delegate and BeforeUnloadFired() |
| 35 // that the beforeunload handler was run. If the user allowed the | 35 // that the beforeunload handler was run. If the user allowed the |
| 36 // close to continue, we detached the tab and hold onto it while the | 36 // close to continue, we detached the tab and hold onto it while the |
| 37 // close finishes. | 37 // close finishes. |
| 38 // | 38 // |
| 39 // Typical flow of closing a window: | 39 // Typical flow of closing a window: |
| 40 // 1. BrowserView::CanClose() calls TabsNeedBeforeUnloadFired(). | 40 // 1. BrowserView::CanClose() calls TabsNeedBeforeUnloadFired(). |
| 41 // If beforeunload/unload handlers need to run, UnloadController returns | 41 // If beforeunload/unload handlers need to run, FastUnloadController returns |
| 42 // true and calls ProcessPendingTabs() (private method). | 42 // true and calls ProcessPendingTabs() (private method). |
| 43 // 2. For each tab with a beforeunload/unload handler, ProcessPendingTabs() | 43 // 2. For each tab with a beforeunload/unload handler, ProcessPendingTabs() |
| 44 // calls |CoreTabHelper::OnCloseStarted()| | 44 // calls |CoreTabHelper::OnCloseStarted()| |
| 45 // and |web_contents->GetRenderViewHost()->FirePageBeforeUnload()|. | 45 // and |web_contents->GetRenderViewHost()->FirePageBeforeUnload()|. |
| 46 // 3. If the user allowed the close to continue, we detach all the tabs with | 46 // 3. If the user allowed the close to continue, we detach all the tabs with |
| 47 // unload handlers, remove them from the tab strip, and finish closing | 47 // unload handlers, remove them from the tab strip, and finish closing |
| 48 // the tabs in the background. | 48 // the tabs in the background. |
| 49 // 4. The browser gets notified that the tab strip is empty and calls | 49 // 4. The browser gets notified that the tab strip is empty and calls |
| 50 // CloseFrame where the empty tab strip causes the window to hide. | 50 // CloseFrame where the empty tab strip causes the window to hide. |
| 51 // Once the detached tabs finish, the browser calls CloseFrame again and | 51 // Once the detached tabs finish, the browser calls CloseFrame again and |
| 52 // the window is finally closed. | 52 // the window is finally closed. |
| 53 // | 53 // |
| 54 class UnloadController : public content::NotificationObserver, | 54 class FastUnloadController : public content::NotificationObserver, |
| 55 public TabStripModelObserver { | 55 public TabStripModelObserver { |
| 56 public: | 56 public: |
| 57 explicit UnloadController(Browser* browser); | 57 explicit FastUnloadController(Browser* browser); |
| 58 virtual ~UnloadController(); | 58 virtual ~FastUnloadController(); |
| 59 | 59 |
| 60 // Returns true if |contents| can be cleanly closed. When |browser_| is being | 60 // Returns true if |contents| can be cleanly closed. When |browser_| is being |
| 61 // closed, this function will return false to indicate |contents| should not | 61 // closed, this function will return false to indicate |contents| should not |
| 62 // be cleanly closed, since the fast shutdown path will just kill its | 62 // be cleanly closed, since the fast shutdown path will just kill its |
| 63 // renderer. | 63 // renderer. |
| 64 bool CanCloseContents(content::WebContents* contents); | 64 bool CanCloseContents(content::WebContents* contents); |
| 65 | 65 |
| 66 // Called when a BeforeUnload handler is fired for |contents|. |proceed| | 66 // Called when a BeforeUnload handler is fired for |contents|. |proceed| |
| 67 // indicates the user's response to the Y/N BeforeUnload handler dialog. If | 67 // indicates the user's response to the Y/N BeforeUnload handler dialog. If |
| 68 // this parameter is false, any pending attempt to close the whole browser | 68 // this parameter is false, any pending attempt to close the whole browser |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // Tracks tabs that need their unload event started. | 155 // Tracks tabs that need their unload event started. |
| 156 // Only gets populated when we try to close the browser. | 156 // Only gets populated when we try to close the browser. |
| 157 WebContentsSet tabs_needing_unload_; | 157 WebContentsSet tabs_needing_unload_; |
| 158 | 158 |
| 159 // Tracks tabs that need to finish running their unload event. | 159 // Tracks tabs that need to finish running their unload event. |
| 160 // Populated both when closing individual tabs and when closing the browser. | 160 // Populated both when closing individual tabs and when closing the browser. |
| 161 WebContentsSet tabs_needing_unload_ack_; | 161 WebContentsSet tabs_needing_unload_ack_; |
| 162 | 162 |
| 163 // Whether we are processing the beforeunload and unload events of each tab | 163 // Whether we are processing the beforeunload and unload events of each tab |
| 164 // in preparation for closing the browser. UnloadController owns this | 164 // in preparation for closing the browser. FastUnloadController owns this |
| 165 // state rather than Browser because unload handlers are the only reason that | 165 // state rather than Browser because unload handlers are the only reason that |
| 166 // a Browser window isn't just immediately closed. | 166 // a Browser window isn't just immediately closed. |
| 167 bool is_attempting_to_close_browser_; | 167 bool is_attempting_to_close_browser_; |
| 168 | 168 |
| 169 // Manage tabs with beforeunload/unload handlers that close detached. | 169 // Manage tabs with beforeunload/unload handlers that close detached. |
| 170 class DetachedWebContentsDelegate; | 170 class DetachedWebContentsDelegate; |
| 171 scoped_ptr<DetachedWebContentsDelegate> detached_delegate_; | 171 scoped_ptr<DetachedWebContentsDelegate> detached_delegate_; |
| 172 | 172 |
| 173 base::WeakPtrFactory<UnloadController> weak_factory_; | 173 base::WeakPtrFactory<FastUnloadController> weak_factory_; |
| 174 | 174 |
| 175 DISALLOW_COPY_AND_ASSIGN(UnloadController); | 175 DISALLOW_COPY_AND_ASSIGN(FastUnloadController); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace chrome | 178 } // namespace chrome |
| 179 | 179 |
| 180 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 180 #endif // CHROME_BROWSER_UI_FAST_UNLOAD_CONTROLLER_H_ |
| OLD | NEW |