Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: chrome/browser/ui/unload_controller.h

Issue 2681203002: Add Browser::SkipCallBeforeUnload so that the browser windows can be closed regardless of beforeunl… (Closed)
Patch Set: sky's comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_UNLOAD_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_
7 7
8 #include <memory>
8 #include <set> 9 #include <set>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 17
17 class Browser; 18 class Browser;
18 class TabStripModel; 19 class TabStripModel;
20 class UnloadControllerWebContentsDelegate;
19 21
20 namespace content { 22 namespace content {
21 class NotificationSource; 23 class NotificationSource;
22 class NotificationDetails; 24 class NotificationDetails;
23 class WebContents; 25 class WebContents;
24 } 26 }
25 27
26 namespace chrome { 28 namespace chrome {
27 29
28 class UnloadController : public content::NotificationObserver, 30 class UnloadController : public content::NotificationObserver,
(...skipping 26 matching lines...) Expand all
55 57
56 bool is_attempting_to_close_browser() const { 58 bool is_attempting_to_close_browser() const {
57 return is_attempting_to_close_browser_; 59 return is_attempting_to_close_browser_;
58 } 60 }
59 61
60 // Called in response to a request to close |browser_|'s window. Returns true 62 // Called in response to a request to close |browser_|'s window. Returns true
61 // when there are no remaining beforeunload handlers to be run. 63 // when there are no remaining beforeunload handlers to be run.
62 bool ShouldCloseWindow(); 64 bool ShouldCloseWindow();
63 65
64 // Begins the process of confirming whether the associated browser can be 66 // Begins the process of confirming whether the associated browser can be
65 // closed. 67 // closed. Beforeunload events won't be fired if |skip_before_unload_event|
66 bool CallBeforeUnloadHandlers( 68 // is true.
67 const base::Callback<void(bool)>& on_close_confirmed); 69 bool TryToCloseWindow(bool skip_before_unload_event,
70 const base::Callback<void(bool)>& on_close_confirmed);
68 71
69 // Clears the results of any beforeunload confirmation dialogs triggered by a 72 // Clears the results of any beforeunload confirmation dialogs triggered by a
70 // CallBeforeUnloadHandlers call. 73 // TryToCloseWindow call.
71 void ResetBeforeUnloadHandlers(); 74 void ResetTryToCloseWindow();
72 75
73 // Returns true if |browser_| has any tabs that have BeforeUnload handlers 76 // Returns true if |browser_| has any tabs that have BeforeUnload handlers
74 // that have not been fired. This method is non-const because it builds a list 77 // that have not been fired. This method is non-const because it builds a list
75 // of tabs that need their BeforeUnloadHandlers fired. 78 // of tabs that need their BeforeUnloadHandlers fired.
76 // TODO(beng): This seems like it could be private but it is used by 79 // TODO(beng): This seems like it could be private but it is used by
77 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems 80 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems
78 // very similar to ShouldCloseWindow() and some consolidation 81 // very similar to ShouldCloseWindow() and some consolidation
79 // could be pursued. 82 // could be pursued.
80 bool TabsNeedBeforeUnloadFired(); 83 bool TabsNeedBeforeUnloadFired();
81 84
(...skipping 18 matching lines...) Expand all
100 void TabReplacedAt(TabStripModel* tab_strip_model, 103 void TabReplacedAt(TabStripModel* tab_strip_model,
101 content::WebContents* old_contents, 104 content::WebContents* old_contents,
102 content::WebContents* new_contents, 105 content::WebContents* new_contents,
103 int index) override; 106 int index) override;
104 void TabStripEmpty() override; 107 void TabStripEmpty() override;
105 108
106 void TabAttachedImpl(content::WebContents* contents); 109 void TabAttachedImpl(content::WebContents* contents);
107 void TabDetachedImpl(content::WebContents* contents); 110 void TabDetachedImpl(content::WebContents* contents);
108 111
109 // Processes the next tab that needs it's beforeunload/unload event fired. 112 // Processes the next tab that needs it's beforeunload/unload event fired.
110 void ProcessPendingTabs(); 113 void ProcessPendingTabs(bool skip_before_unload_event);
111 114
112 // Whether we've completed firing all the tabs' beforeunload/unload events. 115 // Whether we've completed firing all the tabs' beforeunload/unload events.
113 bool HasCompletedUnloadProcessing() const; 116 bool HasCompletedUnloadProcessing() const;
114 117
115 // Removes |web_contents| from the passed |set|. 118 // Removes |web_contents| from the passed |set|.
116 // Returns whether the tab was in the set in the first place. 119 // Returns whether the tab was in the set in the first place.
117 bool RemoveFromSet(UnloadListenerSet* set, 120 bool RemoveFromSet(UnloadListenerSet* set,
118 content::WebContents* web_contents); 121 content::WebContents* web_contents);
119 122
120 // Cleans up state appropriately when we are trying to close the browser and 123 // Cleans up state appropriately when we are trying to close the browser and
(...skipping 27 matching lines...) Expand all
148 // in preparation for closing the browser. UnloadController owns this state 151 // in preparation for closing the browser. UnloadController owns this state
149 // rather than Browser because unload handlers are the only reason that a 152 // rather than Browser because unload handlers are the only reason that a
150 // Browser window isn't just immediately closed. 153 // Browser window isn't just immediately closed.
151 bool is_attempting_to_close_browser_; 154 bool is_attempting_to_close_browser_;
152 155
153 // A callback to call to report whether the user chose to close all tabs of 156 // A callback to call to report whether the user chose to close all tabs of
154 // |browser_| that have beforeunload event handlers. This is set only if we 157 // |browser_| that have beforeunload event handlers. This is set only if we
155 // are currently confirming that the browser is closable. 158 // are currently confirming that the browser is closable.
156 base::Callback<void(bool)> on_close_confirmed_; 159 base::Callback<void(bool)> on_close_confirmed_;
157 160
161 // Manage tabs with beforeunload/unload handlers when beforeunload events are
162 // bypassed.
163 std::unique_ptr<UnloadControllerWebContentsDelegate> web_contents_delegate_;
164
158 base::WeakPtrFactory<UnloadController> weak_factory_; 165 base::WeakPtrFactory<UnloadController> weak_factory_;
159 166
160 DISALLOW_COPY_AND_ASSIGN(UnloadController); 167 DISALLOW_COPY_AND_ASSIGN(UnloadController);
161 }; 168 };
162 169
163 } // namespace chrome 170 } // namespace chrome
164 171
165 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ 172 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698