| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
| 156 // UnloadController, TabStripModelObserver implementation: | 156 // UnloadController, TabStripModelObserver implementation: |
| 157 | 157 |
| 158 void UnloadController::TabInsertedAt(content::WebContents* contents, | 158 void UnloadController::TabInsertedAt(content::WebContents* contents, |
| 159 int index, | 159 int index, |
| 160 bool foreground) { | 160 bool foreground) { |
| 161 TabAttachedImpl(contents); | 161 TabAttachedImpl(contents); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void UnloadController::TabDetachedAt(content::WebContents* contents, | 164 void UnloadController::TabDetachedAt(content::WebContents* contents, |
| 165 int index) { | 165 int index, |
| 166 bool closing_all) { |
| 166 TabDetachedImpl(contents); | 167 TabDetachedImpl(contents); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void UnloadController::TabReplacedAt(TabStripModel* tab_strip_model, | 170 void UnloadController::TabReplacedAt(TabStripModel* tab_strip_model, |
| 170 content::WebContents* old_contents, | 171 content::WebContents* old_contents, |
| 171 content::WebContents* new_contents, | 172 content::WebContents* new_contents, |
| 172 int index) { | 173 int index) { |
| 173 TabDetachedImpl(old_contents); | 174 TabDetachedImpl(old_contents); |
| 174 TabAttachedImpl(new_contents); | 175 TabAttachedImpl(new_contents); |
| 175 } | 176 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 215 |
| 215 if (is_attempting_to_close_browser_) | 216 if (is_attempting_to_close_browser_) |
| 216 ClearUnloadState(contents); | 217 ClearUnloadState(contents); |
| 217 } | 218 } |
| 218 | 219 |
| 219 bool UnloadController::DetachWebContents(content::WebContents* contents) { | 220 bool UnloadController::DetachWebContents(content::WebContents* contents) { |
| 220 int index = browser_->tab_strip_model()->GetIndexOfWebContents(contents); | 221 int index = browser_->tab_strip_model()->GetIndexOfWebContents(contents); |
| 221 if (index != TabStripModel::kNoTab && | 222 if (index != TabStripModel::kNoTab && |
| 222 contents->NeedToFireBeforeUnload()) { | 223 contents->NeedToFireBeforeUnload()) { |
| 223 tabs_needing_unload_ack_.insert(contents); | 224 tabs_needing_unload_ack_.insert(contents); |
| 225 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); |
| 226 core_tab_helper->OnUnloadAboutToDetach(); |
| 224 browser_->tab_strip_model()->DetachWebContentsAt(index); | 227 browser_->tab_strip_model()->DetachWebContentsAt(index); |
| 225 contents->SetDelegate(detached_delegate_.get()); | 228 contents->SetDelegate(detached_delegate_.get()); |
| 226 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); | |
| 227 core_tab_helper->OnUnloadDetachedStarted(); | 229 core_tab_helper->OnUnloadDetachedStarted(); |
| 228 return true; | 230 return true; |
| 229 } | 231 } |
| 230 return false; | 232 return false; |
| 231 } | 233 } |
| 232 | 234 |
| 233 void UnloadController::ProcessPendingTabs() { | 235 void UnloadController::ProcessPendingTabs() { |
| 234 if (!is_attempting_to_close_browser_) { | 236 if (!is_attempting_to_close_browser_) { |
| 235 // Because we might invoke this after a delay it's possible for the value of | 237 // Because we might invoke this after a delay it's possible for the value of |
| 236 // is_attempting_to_close_browser_ to have changed since we scheduled the | 238 // is_attempting_to_close_browser_ to have changed since we scheduled the |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 371 } |
| 370 | 372 |
| 371 void UnloadController::PostTaskForProcessPendingTabs() { | 373 void UnloadController::PostTaskForProcessPendingTabs() { |
| 372 base::MessageLoop::current()->PostTask( | 374 base::MessageLoop::current()->PostTask( |
| 373 FROM_HERE, | 375 FROM_HERE, |
| 374 base::Bind(&UnloadController::ProcessPendingTabs, | 376 base::Bind(&UnloadController::ProcessPendingTabs, |
| 375 weak_factory_.GetWeakPtr())); | 377 weak_factory_.GetWeakPtr())); |
| 376 } | 378 } |
| 377 | 379 |
| 378 } // namespace chrome | 380 } // namespace chrome |
| OLD | NEW |