| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_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 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 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 |
| 13 namespace content { |
| 14 class WebContents; |
| 15 } |
| 13 | 16 |
| 14 // InstantUnloadHandler ensures that the beforeunload and unload handlers are | 17 // InstantUnloadHandler ensures that the beforeunload and unload handlers are |
| 15 // run when using Instant. When the user commits the Instant preview the | 18 // run when using Instant. When the user commits the Instant preview the |
| 16 // existing TabContents is passed to RunUnloadListenersOrDestroy(). If the tab | 19 // existing WebContents is passed to RunUnloadListenersOrDestroy(). If the tab |
| 17 // has no beforeunload or unload listeners, the tab is deleted; otherwise the | 20 // has no beforeunload or unload listeners, the tab is deleted; otherwise the |
| 18 // beforeunload and unload listeners are executed. If the beforeunload listener | 21 // beforeunload and unload listeners are executed. If the beforeunload listener |
| 19 // shows a dialog the tab is added back to the tabstrip at its original location | 22 // shows a dialog the tab is added back to the tabstrip at its original location |
| 20 // next to the Instant page. | 23 // next to the Instant page. |
| 21 class InstantUnloadHandler { | 24 class InstantUnloadHandler { |
| 22 public: | 25 public: |
| 23 explicit InstantUnloadHandler(Browser* browser); | 26 explicit InstantUnloadHandler(Browser* browser); |
| 24 ~InstantUnloadHandler(); | 27 ~InstantUnloadHandler(); |
| 25 | 28 |
| 26 // See class description for details on what this does. | 29 // See class description for details on what this does. |
| 27 void RunUnloadListenersOrDestroy(TabContents* tab_contents, int index); | 30 void RunUnloadListenersOrDestroy(content::WebContents* contents, int index); |
| 28 | 31 |
| 29 private: | 32 private: |
| 30 class WebContentsDelegateImpl; | 33 class WebContentsDelegateImpl; |
| 31 | 34 |
| 32 // Invoked if the tab is to be shown, at |index| on the tab strip. This | 35 // Invoked if the tab is to be shown, at |index| on the tab strip. This |
| 33 // happens if the before unload listener returns a string. Takes ownership of | 36 // happens if the before unload listener returns a string. Takes ownership of |
| 34 // |delegate| and |tab|. | 37 // |delegate| and |contents|. |
| 35 void Activate(WebContentsDelegateImpl* delegate, TabContents* tab, int index); | 38 void Activate(WebContentsDelegateImpl* delegate, |
| 39 content::WebContents* contents, |
| 40 int index); |
| 36 | 41 |
| 37 // Destroys the old tab. This is invoked if script tries to close the page. | 42 // Destroys the old tab. This is invoked if script tries to close the page. |
| 38 void Destroy(WebContentsDelegateImpl* delegate); | 43 void Destroy(WebContentsDelegateImpl* delegate); |
| 39 | 44 |
| 40 // TODO(sky): Browser really needs to wait to close until there are no more | 45 // TODO(sky): Browser really needs to wait to close until there are no more |
| 41 // tabs managed by InstantUnloadHandler. | 46 // tabs managed by InstantUnloadHandler. |
| 42 Browser* const browser_; | 47 Browser* const browser_; |
| 43 | 48 |
| 44 ScopedVector<WebContentsDelegateImpl> delegates_; | 49 ScopedVector<WebContentsDelegateImpl> delegates_; |
| 45 | 50 |
| 46 DISALLOW_COPY_AND_ASSIGN(InstantUnloadHandler); | 51 DISALLOW_COPY_AND_ASSIGN(InstantUnloadHandler); |
| 47 }; | 52 }; |
| 48 | 53 |
| 49 #endif // CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ | 54 #endif // CHROME_BROWSER_INSTANT_INSTANT_UNLOAD_HANDLER_H_ |
| OLD | NEW |