1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/web_contents_close_handler.h"
7 #include "chrome/browser/ui/views/frame/web_contents_close_handler_delegate.h"
9 WebContentsCloseHandler::WebContentsCloseHandler(
10 WebContentsCloseHandlerDelegate
* delegate
)
11 : delegate_(delegate
),
13 tab_changed_after_clone_(false) {
16 WebContentsCloseHandler::~WebContentsCloseHandler() {
19 void WebContentsCloseHandler::TabInserted() {
20 // Tests may end up reviving a TabStrip that is empty.
24 delegate_
->DestroyClonedLayer();
27 void WebContentsCloseHandler::ActiveTabChanged() {
29 tab_changed_after_clone_
= true;
31 delegate_
->DestroyClonedLayer();
34 void WebContentsCloseHandler::WillCloseAllTabs() {
37 tab_changed_after_clone_
= false;
38 delegate_
->CloneWebContentsLayer();
42 void WebContentsCloseHandler::CloseAllTabsCanceled() {
45 if (tab_changed_after_clone_
) {
46 // If the tab changed, destroy immediately. That way we make sure we aren't
47 // showing the wrong thing.
48 delegate_
->DestroyClonedLayer();
50 // The most common reason for a close to be canceled is a before unload
51 // handler. Often times the tab still ends up closing, but only after we get
52 // back a response from the renderer. Assume this is going to happen and
53 // keep around the cloned layer for a bit more time.
54 timer_
.Start(FROM_HERE
, base::TimeDelta::FromMilliseconds(500),
55 this, &WebContentsCloseHandler::OnStillHaventClosed
);
59 void WebContentsCloseHandler::OnStillHaventClosed() {
60 delegate_
->DestroyClonedLayer();