OLD | NEW |
1 // Copyright 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 #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" | |
8 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
12 #include "chrome/browser/themes/theme_service_factory.h" | 11 #include "chrome/browser/themes/theme_service_factory.h" |
13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_tabstrip.h" | |
15 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/omnibox/location_bar.h" | 14 #include "chrome/browser/ui/omnibox/location_bar.h" |
17 #include "chrome/browser/ui/search/search.h" | 15 #include "chrome/browser/ui/search/search.h" |
18 #include "chrome/browser/ui/search/search_model.h" | |
19 #include "chrome/browser/ui/search/search_tab_helper.h" | 16 #include "chrome/browser/ui/search/search_tab_helper.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 19 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
23 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
25 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/web_contents.h" | |
27 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
28 #include "ui/gfx/color_utils.h" | 24 #include "ui/gfx/color_utils.h" |
29 #include "ui/gfx/sys_color_change_listener.h" | 25 #include "ui/gfx/sys_color_change_listener.h" |
30 | 26 |
31 | 27 |
32 namespace chrome { | 28 namespace chrome { |
33 | 29 |
34 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
35 // BrowserInstantController, public: | 31 // BrowserInstantController, public: |
36 | 32 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // The omnibox currently doesn't use other dispositions, so we don't attempt | 77 // The omnibox currently doesn't use other dispositions, so we don't attempt |
82 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add | 78 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add |
83 // support for the new disposition. | 79 // support for the new disposition. |
84 DCHECK(disposition == CURRENT_TAB || | 80 DCHECK(disposition == CURRENT_TAB || |
85 disposition == NEW_FOREGROUND_TAB) << disposition; | 81 disposition == NEW_FOREGROUND_TAB) << disposition; |
86 | 82 |
87 return instant_.CommitIfCurrent(disposition == CURRENT_TAB ? | 83 return instant_.CommitIfCurrent(disposition == CURRENT_TAB ? |
88 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); | 84 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); |
89 } | 85 } |
90 | 86 |
91 void BrowserInstantController::CommitInstant(TabContents* preview, | 87 void BrowserInstantController::CommitInstant(content::WebContents* preview, |
92 bool in_new_tab) { | 88 bool in_new_tab) { |
93 if (in_new_tab) { | 89 if (in_new_tab) { |
94 // TabStripModel takes ownership of |preview|. | 90 // TabStripModel takes ownership of |preview|. |
95 browser_->tab_strip_model()->AddWebContents(preview->web_contents(), -1, | 91 browser_->tab_strip_model()->AddWebContents(preview, -1, |
96 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); | 92 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); |
97 } else { | 93 } else { |
98 TabContents* active_tab = | 94 content::WebContents* active_tab = |
99 browser_->tab_strip_model()->GetActiveTabContents(); | 95 browser_->tab_strip_model()->GetActiveWebContents(); |
100 int index = browser_->tab_strip_model()->GetIndexOfTabContents(active_tab); | 96 int index = browser_->tab_strip_model()->GetIndexOfWebContents(active_tab); |
101 DCHECK_NE(TabStripModel::kNoTab, index); | 97 DCHECK_NE(TabStripModel::kNoTab, index); |
102 // TabStripModel takes ownership of |preview|. | 98 // TabStripModel takes ownership of |preview|. |
103 browser_->tab_strip_model()->ReplaceTabContentsAt(index, preview); | 99 browser_->tab_strip_model()->ReplaceTabContentsAt(index, |
| 100 TabContents::FromWebContents(preview)); |
104 // InstantUnloadHandler takes ownership of |active_tab|. | 101 // InstantUnloadHandler takes ownership of |active_tab|. |
105 instant_unload_handler_.RunUnloadListenersOrDestroy(active_tab, index); | 102 instant_unload_handler_.RunUnloadListenersOrDestroy(active_tab, index); |
106 | 103 |
107 GURL url = preview->web_contents()->GetURL(); | 104 GURL url = preview->GetURL(); |
108 DCHECK(browser_->profile()->GetExtensionService()); | 105 DCHECK(browser_->profile()->GetExtensionService()); |
109 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) { | 106 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) { |
110 AppLauncherHandler::RecordAppLaunchType( | 107 AppLauncherHandler::RecordAppLaunchType( |
111 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); | 108 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); |
112 } | 109 } |
113 } | 110 } |
114 } | 111 } |
115 | 112 |
116 void BrowserInstantController::SetInstantSuggestion( | 113 void BrowserInstantController::SetInstantSuggestion( |
117 const InstantSuggestion& suggestion) { | 114 const InstantSuggestion& suggestion) { |
118 if (browser_->window()->GetLocationBar()) | 115 if (browser_->window()->GetLocationBar()) |
119 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); | 116 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); |
120 } | 117 } |
121 | 118 |
122 gfx::Rect BrowserInstantController::GetInstantBounds() { | 119 gfx::Rect BrowserInstantController::GetInstantBounds() { |
123 return browser_->window()->GetInstantBounds(); | 120 return browser_->window()->GetInstantBounds(); |
124 } | 121 } |
125 | 122 |
126 void BrowserInstantController::InstantPreviewFocused() { | 123 void BrowserInstantController::InstantPreviewFocused() { |
127 // NOTE: This is only invoked on aura. | 124 // NOTE: This is only invoked on aura. |
128 browser_->window()->WebContentsFocused( | 125 browser_->window()->WebContentsFocused(instant_.GetPreviewContents()); |
129 instant_.GetPreviewContents()->web_contents()); | |
130 } | 126 } |
131 | 127 |
132 TabContents* BrowserInstantController::GetActiveTabContents() const { | 128 content::WebContents* BrowserInstantController::GetActiveWebContents() const { |
133 return browser_->tab_strip_model()->GetActiveTabContents(); | 129 return browser_->tab_strip_model()->GetActiveWebContents(); |
134 } | 130 } |
135 | 131 |
136 void BrowserInstantController::ActiveTabChanged() { | 132 void BrowserInstantController::ActiveTabChanged() { |
137 instant_.ActiveTabChanged(); | 133 instant_.ActiveTabChanged(); |
138 } | 134 } |
139 | 135 |
140 void BrowserInstantController::SetContentHeight(int height) { | 136 void BrowserInstantController::SetContentHeight(int height) { |
141 OnThemeAreaHeightChanged(height); | 137 OnThemeAreaHeightChanged(height); |
142 } | 138 } |
143 | 139 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // part of the image overlay should draw, 'cos the origin is top-left. | 264 // part of the image overlay should draw, 'cos the origin is top-left. |
269 if (!browser_->search_model()->mode().is_ntp() || | 265 if (!browser_->search_model()->mode().is_ntp() || |
270 theme_info_.theme_id.empty() || | 266 theme_info_.theme_id.empty() || |
271 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { | 267 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { |
272 return; | 268 return; |
273 } | 269 } |
274 instant_.ThemeAreaHeightChanged(theme_area_height_); | 270 instant_.ThemeAreaHeightChanged(theme_area_height_); |
275 } | 271 } |
276 | 272 |
277 } // namespace chrome | 273 } // namespace chrome |
OLD | NEW |