| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_INSTANT_INSTANT_UNLOAD_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 | 10 |
| 11 class Browser; | 11 class Browser; |
| 12 class TabContents; | 12 class TabContents; |
| 13 typedef TabContents TabContentsWrapper; | |
| 14 | 13 |
| 15 // InstantUnloadHandler makes sure the before unload and unload handler is run | 14 // InstantUnloadHandler makes sure the before unload and unload handler is run |
| 16 // when using instant. When the user commits the instant preview the existing | 15 // when using instant. When the user commits the instant preview the existing |
| 17 // TabContentsWrapper is passed to |RunUnloadListenersOrDestroy|. If the tab has | 16 // TabContents is passed to |RunUnloadListenersOrDestroy|. If the tab has |
| 18 // no before unload or unload listener the tab is deleted, otherwise the before | 17 // no before unload or unload listener the tab is deleted, otherwise the before |
| 19 // unload and unload listener is executed. If the before unload listener shows a | 18 // unload and unload listener is executed. If the before unload listener shows a |
| 20 // dialog the tab is added back to the tabstrip at its original location next to | 19 // dialog the tab is added back to the tabstrip at its original location next to |
| 21 // the instant page. | 20 // the instant page. |
| 22 class InstantUnloadHandler { | 21 class InstantUnloadHandler { |
| 23 public: | 22 public: |
| 24 explicit InstantUnloadHandler(Browser* browser); | 23 explicit InstantUnloadHandler(Browser* browser); |
| 25 ~InstantUnloadHandler(); | 24 ~InstantUnloadHandler(); |
| 26 | 25 |
| 27 // See class description for details on what this does. | 26 // See class description for details on what this does. |
| 28 void RunUnloadListenersOrDestroy(TabContentsWrapper* tab_contents, int index); | 27 void RunUnloadListenersOrDestroy(TabContents* tab_contents, int index); |
| 29 | 28 |
| 30 private: | 29 private: |
| 31 class TabContentsDelegateImpl; | 30 class TabContentsDelegateImpl; |
| 32 | 31 |
| 33 // Invoked if the tab is to be shown. This happens if the before unload | 32 // Invoked if the tab is to be shown. This happens if the before unload |
| 34 // listener returns a string. | 33 // listener returns a string. |
| 35 void Activate(TabContentsDelegateImpl* delegate); | 34 void Activate(TabContentsDelegateImpl* delegate); |
| 36 | 35 |
| 37 // Destroys the old tab. This is invoked if script tries to close the page. | 36 // Destroys the old tab. This is invoked if script tries to close the page. |
| 38 void Destroy(TabContentsDelegateImpl* delegate); | 37 void Destroy(TabContentsDelegateImpl* delegate); |
| 39 | 38 |
| 40 // TODO(sky): browser really needs to wait to close until there are no more | 39 // TODO(sky): browser really needs to wait to close until there are no more |
| 41 // tabs managed by InstantUnloadHandler. | 40 // tabs managed by InstantUnloadHandler. |
| 42 Browser* browser_; | 41 Browser* browser_; |
| 43 | 42 |
| 44 ScopedVector<TabContentsDelegateImpl> delegates_; | 43 ScopedVector<TabContentsDelegateImpl> delegates_; |
| 45 | 44 |
| 46 DISALLOW_COPY_AND_ASSIGN(InstantUnloadHandler); | 45 DISALLOW_COPY_AND_ASSIGN(InstantUnloadHandler); |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 #endif // CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ | 48 #endif // CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ |
| OLD | NEW |