| 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/instant/instant_unload_handler.h" | 5 #include "chrome/browser/instant/instant_unload_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_navigator.h" | 9 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_delegate.h" | 13 #include "content/public/browser/web_contents_delegate.h" |
| 15 | 14 |
| 16 // WebContentsDelegate implementation. This owns the TabContents supplied to the | 15 // WebContentsDelegate implementation. This owns the TabContents supplied to the |
| 17 // constructor. | 16 // constructor. |
| 18 class InstantUnloadHandler::WebContentsDelegateImpl | 17 class InstantUnloadHandler::WebContentsDelegateImpl |
| 19 : public content::WebContentsDelegate { | 18 : public content::WebContentsDelegate { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 91 } |
| 93 | 92 |
| 94 void InstantUnloadHandler::Activate(WebContentsDelegateImpl* delegate) { | 93 void InstantUnloadHandler::Activate(WebContentsDelegateImpl* delegate) { |
| 95 // Take ownership of the TabContents from the delegate. | 94 // Take ownership of the TabContents from the delegate. |
| 96 TabContents* tab = delegate->ReleaseTab(); | 95 TabContents* tab = delegate->ReleaseTab(); |
| 97 chrome::NavigateParams params(browser_, tab); | 96 chrome::NavigateParams params(browser_, tab); |
| 98 params.disposition = NEW_FOREGROUND_TAB; | 97 params.disposition = NEW_FOREGROUND_TAB; |
| 99 params.tabstrip_index = delegate->index(); | 98 params.tabstrip_index = delegate->index(); |
| 100 | 99 |
| 101 // Remove (and delete) the delegate. | 100 // Remove (and delete) the delegate. |
| 102 ScopedVector<WebContentsDelegateImpl>::iterator i = | 101 Destroy(delegate); |
| 103 std::find(delegates_.begin(), delegates_.end(), delegate); | |
| 104 DCHECK(i != delegates_.end()); | |
| 105 delegates_.erase(i); | |
| 106 delegate = NULL; | |
| 107 | 102 |
| 108 // Add the tab back in. | 103 // Add the tab back in. |
| 109 chrome::Navigate(¶ms); | 104 chrome::Navigate(¶ms); |
| 110 } | 105 } |
| 111 | 106 |
| 112 void InstantUnloadHandler::Destroy(WebContentsDelegateImpl* delegate) { | 107 void InstantUnloadHandler::Destroy(WebContentsDelegateImpl* delegate) { |
| 113 ScopedVector<WebContentsDelegateImpl>::iterator i = | 108 ScopedVector<WebContentsDelegateImpl>::iterator i = |
| 114 std::find(delegates_.begin(), delegates_.end(), delegate); | 109 std::find(delegates_.begin(), delegates_.end(), delegate); |
| 115 DCHECK(i != delegates_.end()); | 110 DCHECK(i != delegates_.end()); |
| 116 delegates_.erase(i); | 111 delegates_.erase(i); |
| 117 } | 112 } |
| OLD | NEW |