| 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/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_shutdown.h" | 7 #include "chrome/browser/browser_shutdown.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/instant/instant_controller.h" | 9 #include "chrome/browser/instant/instant_controller.h" |
| 10 #include "chrome/browser/instant/instant_unload_handler.h" | 10 #include "chrome/browser/instant/instant_unload_handler.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // The omnibox currently doesn't use other dispositions, so we don't attempt | 70 // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 71 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add | 71 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 72 // support for the new disposition. | 72 // support for the new disposition. |
| 73 NOTREACHED(); | 73 NOTREACHED(); |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
| 78 // BrowserInstantController, InstantControllerDelegate implementation: | 78 // BrowserInstantController, InstantControllerDelegate implementation: |
| 79 | 79 |
| 80 void BrowserInstantController::ShowInstant() { | 80 void BrowserInstantController::ShowInstant(int height, InstantSizeUnits units) { |
| 81 // Call ShowInstant() first, before WasShown(), so that the preview is added | 81 // Call ShowInstant() first, before WasShown(), so that the preview is added |
| 82 // to the window hierarchy before it's painted. http://crbug.com/145568 | 82 // to the window hierarchy before it's painted. http://crbug.com/145568 |
| 83 TabContents* preview = instant_->GetPreviewContents(); | 83 TabContents* preview = instant_->GetPreviewContents(); |
| 84 browser_->window()->ShowInstant(preview); | 84 browser_->window()->ShowInstant(preview, height, units); |
| 85 | 85 |
| 86 // TODO(beng): Investigate if we can avoid this and instead rely on the | 86 // TODO(beng): Investigate if we can avoid this and instead rely on the |
| 87 // visibility of the WebContentsView. | 87 // visibility of the WebContentsView. |
| 88 preview->web_contents()->WasShown(); | 88 preview->web_contents()->WasShown(); |
| 89 chrome::GetActiveWebContents(browser_)->WasHidden(); | 89 chrome::GetActiveWebContents(browser_)->WasHidden(); |
| 90 | |
| 91 content::NotificationService::current()->Notify( | |
| 92 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | |
| 93 content::Source<InstantController>(instant()), | |
| 94 content::NotificationService::NoDetails()); | |
| 95 } | 90 } |
| 96 | 91 |
| 97 void BrowserInstantController::HideInstant() { | 92 void BrowserInstantController::HideInstant() { |
| 98 browser_->window()->HideInstant(); | 93 browser_->window()->HideInstant(); |
| 99 | 94 |
| 100 if (chrome::GetActiveWebContents(browser_)) | 95 if (chrome::GetActiveWebContents(browser_)) |
| 101 chrome::GetActiveWebContents(browser_)->WasShown(); | 96 chrome::GetActiveWebContents(browser_)->WasShown(); |
| 102 if (TabContents* preview = instant_->GetPreviewContents()) | 97 if (TabContents* preview = instant_->GetPreviewContents()) |
| 103 preview->web_contents()->WasHidden(); | 98 preview->web_contents()->WasHidden(); |
| 104 | |
| 105 content::NotificationService::current()->Notify( | |
| 106 chrome::NOTIFICATION_INSTANT_CONTROLLER_HIDDEN, | |
| 107 content::Source<InstantController>(instant()), | |
| 108 content::NotificationService::NoDetails()); | |
| 109 } | 99 } |
| 110 | 100 |
| 111 void BrowserInstantController::CommitInstant(TabContents* preview) { | 101 void BrowserInstantController::CommitInstant(TabContents* preview) { |
| 112 TabContents* active_tab = chrome::GetActiveTabContents(browser_); | 102 TabContents* active_tab = chrome::GetActiveTabContents(browser_); |
| 113 int index = browser_->tab_strip_model()->GetIndexOfTabContents(active_tab); | 103 int index = browser_->tab_strip_model()->GetIndexOfTabContents(active_tab); |
| 114 DCHECK_NE(TabStripModel::kNoTab, index); | 104 DCHECK_NE(TabStripModel::kNoTab, index); |
| 115 // TabStripModel takes ownership of |preview|. | 105 // TabStripModel takes ownership of |preview|. |
| 116 browser_->tab_strip_model()->ReplaceTabContentsAt(index, preview); | 106 browser_->tab_strip_model()->ReplaceTabContentsAt(index, preview); |
| 117 // InstantUnloadHandler takes ownership of |active_tab|. | 107 // InstantUnloadHandler takes ownership of |active_tab|. |
| 118 instant_unload_handler_->RunUnloadListenersOrDestroy(active_tab, index); | 108 instant_unload_handler_->RunUnloadListenersOrDestroy(active_tab, index); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void BrowserInstantController::ResetInstant() { | 163 void BrowserInstantController::ResetInstant() { |
| 174 instant_.reset( | 164 instant_.reset( |
| 175 !browser_shutdown::ShuttingDownWithoutClosingBrowsers() && | 165 !browser_shutdown::ShuttingDownWithoutClosingBrowsers() && |
| 176 browser_->is_type_tabbed() ? | 166 browser_->is_type_tabbed() ? |
| 177 InstantController::CreateInstant(browser_->profile(), this) : NULL); | 167 InstantController::CreateInstant(browser_->profile(), this) : NULL); |
| 178 instant_unload_handler_.reset(instant() ? | 168 instant_unload_handler_.reset(instant() ? |
| 179 new InstantUnloadHandler(browser_) : NULL); | 169 new InstantUnloadHandler(browser_) : NULL); |
| 180 } | 170 } |
| 181 | 171 |
| 182 } // namespace chrome | 172 } // namespace chrome |
| OLD | NEW |