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 #include "chrome/browser/ui/unload_controller.h" | 5 #include "chrome/browser/ui/unload_controller.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/devtools/devtools_window.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
14 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 | 18 |
18 namespace chrome { | 19 namespace chrome { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return; | 115 return; |
115 CancelWindowClose(); | 116 CancelWindowClose(); |
116 } | 117 } |
117 | 118 |
118 bool UnloadController::TabsNeedBeforeUnloadFired() { | 119 bool UnloadController::TabsNeedBeforeUnloadFired() { |
119 if (tabs_needing_before_unload_fired_.empty()) { | 120 if (tabs_needing_before_unload_fired_.empty()) { |
120 for (int i = 0; i < browser_->tab_strip_model()->count(); ++i) { | 121 for (int i = 0; i < browser_->tab_strip_model()->count(); ++i) { |
121 content::WebContents* contents = | 122 content::WebContents* contents = |
122 browser_->tab_strip_model()->GetWebContentsAt(i); | 123 browser_->tab_strip_model()->GetWebContentsAt(i); |
123 if (!ContainsKey(tabs_needing_unload_fired_, contents) && | 124 if (!ContainsKey(tabs_needing_unload_fired_, contents) && |
124 contents->NeedToFireBeforeUnload()) { | 125 (contents->NeedToFireBeforeUnload() || |
| 126 DevToolsWindow::GetInstanceForInspectedTab(contents))) { |
125 tabs_needing_before_unload_fired_.insert(contents); | 127 tabs_needing_before_unload_fired_.insert(contents); |
126 } | 128 } |
127 } | 129 } |
128 } | 130 } |
129 return !tabs_needing_before_unload_fired_.empty(); | 131 return !tabs_needing_before_unload_fired_.empty(); |
130 } | 132 } |
131 | 133 |
132 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
133 // UnloadController, content::NotificationObserver implementation: | 135 // UnloadController, content::NotificationObserver implementation: |
134 | 136 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 213 } |
212 | 214 |
213 // Process beforeunload tabs first. When that queue is empty, process | 215 // Process beforeunload tabs first. When that queue is empty, process |
214 // unload tabs. | 216 // unload tabs. |
215 if (!tabs_needing_before_unload_fired_.empty()) { | 217 if (!tabs_needing_before_unload_fired_.empty()) { |
216 content::WebContents* web_contents = | 218 content::WebContents* web_contents = |
217 *(tabs_needing_before_unload_fired_.begin()); | 219 *(tabs_needing_before_unload_fired_.begin()); |
218 // Null check render_view_host here as this gets called on a PostTask and | 220 // Null check render_view_host here as this gets called on a PostTask and |
219 // the tab's render_view_host may have been nulled out. | 221 // the tab's render_view_host may have been nulled out. |
220 if (web_contents->GetRenderViewHost()) { | 222 if (web_contents->GetRenderViewHost()) { |
221 web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); | 223 DevToolsWindow* devtools_window = |
| 224 DevToolsWindow::GetInstanceForInspectedTab(web_contents); |
| 225 if (devtools_window) |
| 226 devtools_window->InspectedPageWillClose(); |
| 227 else |
| 228 web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
222 } else { | 229 } else { |
223 ClearUnloadState(web_contents, true); | 230 ClearUnloadState(web_contents, true); |
224 } | 231 } |
225 } else if (is_calling_before_unload_handlers()) { | 232 } else if (is_calling_before_unload_handlers()) { |
226 on_close_confirmed_.Run(true); | 233 on_close_confirmed_.Run(true); |
227 } else if (!tabs_needing_unload_fired_.empty()) { | 234 } else if (!tabs_needing_unload_fired_.empty()) { |
228 // We've finished firing all beforeunload events and can proceed with unload | 235 // We've finished firing all beforeunload events and can proceed with unload |
229 // events. | 236 // events. |
230 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting | 237 // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
231 // somewhere around here so that we have accurate measurements of shutdown | 238 // somewhere around here so that we have accurate measurements of shutdown |
(...skipping 17 matching lines...) Expand all Loading... |
249 bool UnloadController::HasCompletedUnloadProcessing() const { | 256 bool UnloadController::HasCompletedUnloadProcessing() const { |
250 return is_attempting_to_close_browser_ && | 257 return is_attempting_to_close_browser_ && |
251 tabs_needing_before_unload_fired_.empty() && | 258 tabs_needing_before_unload_fired_.empty() && |
252 tabs_needing_unload_fired_.empty(); | 259 tabs_needing_unload_fired_.empty(); |
253 } | 260 } |
254 | 261 |
255 void UnloadController::CancelWindowClose() { | 262 void UnloadController::CancelWindowClose() { |
256 // Closing of window can be canceled from a beforeunload handler. | 263 // Closing of window can be canceled from a beforeunload handler. |
257 DCHECK(is_attempting_to_close_browser_); | 264 DCHECK(is_attempting_to_close_browser_); |
258 tabs_needing_before_unload_fired_.clear(); | 265 tabs_needing_before_unload_fired_.clear(); |
| 266 for (UnloadListenerSet::iterator it = tabs_needing_unload_fired_.begin(); |
| 267 it != tabs_needing_unload_fired_.end(); ++it) { |
| 268 DevToolsWindow* dev_tools_window = |
| 269 DevToolsWindow::GetInstanceForInspectedTab(*it); |
| 270 if (dev_tools_window) |
| 271 dev_tools_window->InspectedPageCancelClose(); |
| 272 } |
259 tabs_needing_unload_fired_.clear(); | 273 tabs_needing_unload_fired_.clear(); |
260 if (is_calling_before_unload_handlers()) { | 274 if (is_calling_before_unload_handlers()) { |
261 base::Callback<void(bool)> on_close_confirmed = on_close_confirmed_; | 275 base::Callback<void(bool)> on_close_confirmed = on_close_confirmed_; |
262 on_close_confirmed_.Reset(); | 276 on_close_confirmed_.Reset(); |
263 on_close_confirmed.Run(false); | 277 on_close_confirmed.Run(false); |
264 } | 278 } |
265 is_attempting_to_close_browser_ = false; | 279 is_attempting_to_close_browser_ = false; |
266 | 280 |
267 content::NotificationService::current()->Notify( | 281 content::NotificationService::current()->Notify( |
268 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 282 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
(...skipping 24 matching lines...) Expand all Loading... |
293 } else { | 307 } else { |
294 base::MessageLoop::current()->PostTask( | 308 base::MessageLoop::current()->PostTask( |
295 FROM_HERE, | 309 FROM_HERE, |
296 base::Bind(&UnloadController::ProcessPendingTabs, | 310 base::Bind(&UnloadController::ProcessPendingTabs, |
297 weak_factory_.GetWeakPtr())); | 311 weak_factory_.GetWeakPtr())); |
298 } | 312 } |
299 } | 313 } |
300 } | 314 } |
301 | 315 |
302 } // namespace chrome | 316 } // namespace chrome |
OLD | NEW |