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.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // defined(OS_WIN) | 10 #endif // defined(OS_WIN) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "chrome/browser/download/download_shelf.h" | 52 #include "chrome/browser/download/download_shelf.h" |
53 #include "chrome/browser/extensions/browser_extension_window_controller.h" | 53 #include "chrome/browser/extensions/browser_extension_window_controller.h" |
54 #include "chrome/browser/extensions/extension_prefs.h" | 54 #include "chrome/browser/extensions/extension_prefs.h" |
55 #include "chrome/browser/extensions/extension_service.h" | 55 #include "chrome/browser/extensions/extension_service.h" |
56 #include "chrome/browser/extensions/extension_system.h" | 56 #include "chrome/browser/extensions/extension_system.h" |
57 #include "chrome/browser/extensions/tab_helper.h" | 57 #include "chrome/browser/extensions/tab_helper.h" |
58 #include "chrome/browser/favicon/favicon_tab_helper.h" | 58 #include "chrome/browser/favicon/favicon_tab_helper.h" |
59 #include "chrome/browser/file_select_helper.h" | 59 #include "chrome/browser/file_select_helper.h" |
60 #include "chrome/browser/first_run/first_run.h" | 60 #include "chrome/browser/first_run/first_run.h" |
61 #include "chrome/browser/google/google_url_tracker.h" | 61 #include "chrome/browser/google/google_url_tracker.h" |
| 62 #include "chrome/browser/instant/instant_controller.h" |
62 #include "chrome/browser/lifetime/application_lifetime.h" | 63 #include "chrome/browser/lifetime/application_lifetime.h" |
63 #include "chrome/browser/net/url_fixer_upper.h" | 64 #include "chrome/browser/net/url_fixer_upper.h" |
64 #include "chrome/browser/notifications/notification_ui_manager.h" | 65 #include "chrome/browser/notifications/notification_ui_manager.h" |
65 #include "chrome/browser/pepper_broker_infobar_delegate.h" | 66 #include "chrome/browser/pepper_broker_infobar_delegate.h" |
66 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 67 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
67 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 68 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
68 #include "chrome/browser/profiles/profile.h" | 69 #include "chrome/browser/profiles/profile.h" |
69 #include "chrome/browser/profiles/profile_destroyer.h" | 70 #include "chrome/browser/profiles/profile_destroyer.h" |
70 #include "chrome/browser/profiles/profile_manager.h" | 71 #include "chrome/browser/profiles/profile_manager.h" |
71 #include "chrome/browser/profiles/profile_metrics.h" | 72 #include "chrome/browser/profiles/profile_metrics.h" |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 983 |
983 void Browser::TabDeactivated(WebContents* contents) { | 984 void Browser::TabDeactivated(WebContents* contents) { |
984 fullscreen_controller_->OnTabDeactivated(contents); | 985 fullscreen_controller_->OnTabDeactivated(contents); |
985 search_delegate_->OnTabDeactivated(contents); | 986 search_delegate_->OnTabDeactivated(contents); |
986 | 987 |
987 // Save what the user's currently typing, so it can be restored when we | 988 // Save what the user's currently typing, so it can be restored when we |
988 // switch back to this tab. | 989 // switch back to this tab. |
989 window_->GetLocationBar()->SaveStateToContents(contents); | 990 window_->GetLocationBar()->SaveStateToContents(contents); |
990 | 991 |
991 if (instant_controller_) | 992 if (instant_controller_) |
992 instant_controller_->TabDeactivated(contents); | 993 instant_controller_->instant()->TabDeactivated(contents); |
993 } | 994 } |
994 | 995 |
995 void Browser::ActiveTabChanged(WebContents* old_contents, | 996 void Browser::ActiveTabChanged(WebContents* old_contents, |
996 WebContents* new_contents, | 997 WebContents* new_contents, |
997 int index, | 998 int index, |
998 bool user_gesture) { | 999 bool user_gesture) { |
999 // On some platforms we want to automatically reload tabs that are | 1000 // On some platforms we want to automatically reload tabs that are |
1000 // killed when the user selects them. | 1001 // killed when the user selects them. |
1001 bool did_reload = false; | 1002 bool did_reload = false; |
1002 if (user_gesture && ShouldReloadCrashedTab(new_contents)) { | 1003 if (user_gesture && ShouldReloadCrashedTab(new_contents)) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 SessionServiceFactory::GetForProfileIfExisting(profile_); | 1055 SessionServiceFactory::GetForProfileIfExisting(profile_); |
1055 if (session_service && !tab_strip_model_->closing_all()) { | 1056 if (session_service && !tab_strip_model_->closing_all()) { |
1056 session_service->SetSelectedTabInWindow(session_id(), | 1057 session_service->SetSelectedTabInWindow(session_id(), |
1057 tab_strip_model_->active_index()); | 1058 tab_strip_model_->active_index()); |
1058 } | 1059 } |
1059 | 1060 |
1060 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); | 1061 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
1061 | 1062 |
1062 // This needs to be called after UpdateSearchState(). | 1063 // This needs to be called after UpdateSearchState(). |
1063 if (instant_controller_) | 1064 if (instant_controller_) |
1064 instant_controller_->ActiveTabChanged(); | 1065 instant_controller_->instant()->ActiveTabChanged(); |
1065 } | 1066 } |
1066 | 1067 |
1067 void Browser::TabMoved(WebContents* contents, | 1068 void Browser::TabMoved(WebContents* contents, |
1068 int from_index, | 1069 int from_index, |
1069 int to_index) { | 1070 int to_index) { |
1070 DCHECK(from_index >= 0 && to_index >= 0); | 1071 DCHECK(from_index >= 0 && to_index >= 0); |
1071 // Notify the history service. | 1072 // Notify the history service. |
1072 SyncHistoryWithTabs(std::min(from_index, to_index)); | 1073 SyncHistoryWithTabs(std::min(from_index, to_index)); |
1073 } | 1074 } |
1074 | 1075 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 GlobalErrorServiceFactory::GetForProfile(profile()); | 1199 GlobalErrorServiceFactory::GetForProfile(profile()); |
1199 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 1200 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
1200 if (error) | 1201 if (error) |
1201 error->ShowBubbleView(this); | 1202 error->ShowBubbleView(this); |
1202 } | 1203 } |
1203 | 1204 |
1204 void Browser::ShowFirstRunBubble() { | 1205 void Browser::ShowFirstRunBubble() { |
1205 window()->GetLocationBar()->ShowFirstRunBubble(); | 1206 window()->GetLocationBar()->ShowFirstRunBubble(); |
1206 } | 1207 } |
1207 | 1208 |
1208 void Browser::MaybeUpdateBookmarkBarStateForInstantPreview( | 1209 void Browser::MaybeUpdateBookmarkBarStateForInstantOverlay() { |
1209 const chrome::search::Mode& mode) { | |
1210 // This is invoked by a platform-specific implementation of | 1210 // This is invoked by a platform-specific implementation of |
1211 // |InstantPreviewController| to update bookmark bar state according to | 1211 // |InstantOverlayController| to update bookmark bar state according to |
1212 // instant preview state. | 1212 // Instant overlay state. |
1213 // ModeChanged() updates bookmark bar state for all mode transitions except | 1213 // ModeChanged() updates bookmark bar state for all mode transitions except |
1214 // when new mode is |SEARCH_SUGGESTIONS|, because that needs to be done when | 1214 // when new mode is |SEARCH_SUGGESTIONS|, because that needs to be done when |
1215 // the suggestions are ready. | 1215 // the suggestions are ready. |
1216 if (mode.is_search_suggestions() && | 1216 if (bookmark_bar_state_ == BookmarkBar::SHOW) |
1217 bookmark_bar_state_ == BookmarkBar::SHOW) { | |
1218 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 1217 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
1219 } | |
1220 } | 1218 } |
1221 | 1219 |
1222 /////////////////////////////////////////////////////////////////////////////// | 1220 /////////////////////////////////////////////////////////////////////////////// |
1223 // Browser, content::WebContentsDelegate implementation: | 1221 // Browser, content::WebContentsDelegate implementation: |
1224 | 1222 |
1225 WebContents* Browser::OpenURLFromTab(WebContents* source, | 1223 WebContents* Browser::OpenURLFromTab(WebContents* source, |
1226 const OpenURLParams& params) { | 1224 const OpenURLParams& params) { |
1227 chrome::NavigateParams nav_params(this, params.url, params.transition); | 1225 chrome::NavigateParams nav_params(this, params.url, params.transition); |
1228 nav_params.source_contents = source; | 1226 nav_params.source_contents = source; |
1229 nav_params.referrer = params.referrer; | 1227 nav_params.referrer = params.referrer; |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 break; | 1806 break; |
1809 | 1807 |
1810 default: | 1808 default: |
1811 NOTREACHED() << "Got a notification we didn't register for."; | 1809 NOTREACHED() << "Got a notification we didn't register for."; |
1812 } | 1810 } |
1813 } | 1811 } |
1814 | 1812 |
1815 void Browser::ModeChanged(const chrome::search::Mode& old_mode, | 1813 void Browser::ModeChanged(const chrome::search::Mode& old_mode, |
1816 const chrome::search::Mode& new_mode) { | 1814 const chrome::search::Mode& new_mode) { |
1817 // If new mode is |SEARCH_SUGGESTIONS|, don't update bookmark bar state now; | 1815 // If new mode is |SEARCH_SUGGESTIONS|, don't update bookmark bar state now; |
1818 // wait till the instant preview is ready to show suggestions before hiding | 1816 // wait till the Instant overlay is ready to show suggestions before hiding |
1819 // the bookmark bar (in MaybeUpdateBookmarkBarStateForInstantPreview()). | 1817 // the bookmark bar (in MaybeUpdateBookmarkBarStateForInstantOverlay()). |
1820 // TODO(kuan): but for now, only delay updating bookmark bar state if origin | 1818 // TODO(kuan): but for now, only delay updating bookmark bar state if origin |
1821 // is |DEFAULT|; other origins require more complex logic to be implemented | 1819 // is |DEFAULT|; other origins require more complex logic to be implemented |
1822 // to prevent jankiness caused by hiding bookmark bar, so just hide the | 1820 // to prevent jankiness caused by hiding bookmark bar, so just hide the |
1823 // bookmark bar immediately and tolerate the jankiness for a while. | 1821 // bookmark bar immediately and tolerate the jankiness for a while. |
1824 // For other mode transitions, update bookmark bar state accordingly. | 1822 // For other mode transitions, update bookmark bar state accordingly. |
1825 if (new_mode.is_search_suggestions() && | 1823 if (new_mode.is_search_suggestions() && |
1826 new_mode.is_origin_default() && | 1824 new_mode.is_origin_default() && |
1827 bookmark_bar_state_ == BookmarkBar::SHOW) { | 1825 bookmark_bar_state_ == BookmarkBar::SHOW) { |
1828 return; | 1826 return; |
1829 } | 1827 } |
1830 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 1828 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 1829 |
| 1830 if (instant_controller_) |
| 1831 instant_controller_->instant()->SearchModeChanged(old_mode, new_mode); |
1831 } | 1832 } |
1832 | 1833 |
1833 /////////////////////////////////////////////////////////////////////////////// | 1834 /////////////////////////////////////////////////////////////////////////////// |
1834 // Browser, Command and state updating (private): | 1835 // Browser, Command and state updating (private): |
1835 | 1836 |
1836 void Browser::OnDevToolsDisabledChanged() { | 1837 void Browser::OnDevToolsDisabledChanged() { |
1837 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 1838 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
1838 content::DevToolsManager::GetInstance()->CloseAllClientHosts(); | 1839 content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
1839 } | 1840 } |
1840 | 1841 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 | 1971 |
1971 void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { | 1972 void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
1972 if (!contents) | 1973 if (!contents) |
1973 return; | 1974 return; |
1974 | 1975 |
1975 UpdateMap::iterator i = scheduled_updates_.find(contents); | 1976 UpdateMap::iterator i = scheduled_updates_.find(contents); |
1976 if (i != scheduled_updates_.end()) | 1977 if (i != scheduled_updates_.end()) |
1977 scheduled_updates_.erase(i); | 1978 scheduled_updates_.erase(i); |
1978 } | 1979 } |
1979 | 1980 |
1980 | |
1981 /////////////////////////////////////////////////////////////////////////////// | 1981 /////////////////////////////////////////////////////////////////////////////// |
1982 // Browser, Getters for UI (private): | 1982 // Browser, Getters for UI (private): |
1983 | 1983 |
1984 StatusBubble* Browser::GetStatusBubble() { | 1984 StatusBubble* Browser::GetStatusBubble() { |
1985 // In kiosk and exclusive app mode, we want to always hide the status bubble. | 1985 // In kiosk and exclusive app mode, we want to always hide the status bubble. |
1986 if (chrome::IsRunningInAppMode()) | 1986 if (chrome::IsRunningInAppMode()) |
1987 return NULL; | 1987 return NULL; |
1988 | 1988 |
1989 return window_ ? window_->GetStatusBubble() : NULL; | 1989 return window_ ? window_->GetStatusBubble() : NULL; |
1990 } | 1990 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 state = BookmarkBar::HIDDEN; | 2140 state = BookmarkBar::HIDDEN; |
2141 #endif | 2141 #endif |
2142 | 2142 |
2143 if (state == bookmark_bar_state_) | 2143 if (state == bookmark_bar_state_) |
2144 return; | 2144 return; |
2145 | 2145 |
2146 bookmark_bar_state_ = state; | 2146 bookmark_bar_state_ = state; |
2147 | 2147 |
2148 // Inform NTP page of change in bookmark bar state, so that it can adjust the | 2148 // Inform NTP page of change in bookmark bar state, so that it can adjust the |
2149 // theme image top offset if necessary. | 2149 // theme image top offset if necessary. |
2150 if (instant_controller_) | 2150 if (instant_controller_) { |
2151 instant_controller_->UpdateThemeInfo(true); | 2151 instant_controller_->instant()->BookmarkBarStateChanged( |
| 2152 bookmark_bar_state_ == BookmarkBar::DETACHED); |
| 2153 } |
2152 | 2154 |
2153 if (!window_) | 2155 if (!window_) |
2154 return; // This is called from the constructor when window_ is NULL. | 2156 return; // This is called from the constructor when window_ is NULL. |
2155 | 2157 |
2156 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { | 2158 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
2157 // Don't notify BrowserWindow on a tab switch as at the time this is invoked | 2159 // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
2158 // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations | 2160 // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
2159 // end up querying state once they process the tab switch. | 2161 // end up querying state once they process the tab switch. |
2160 return; | 2162 return; |
2161 } | 2163 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2246 if (contents && !allow_js_access) { | 2248 if (contents && !allow_js_access) { |
2247 contents->web_contents()->GetController().LoadURL( | 2249 contents->web_contents()->GetController().LoadURL( |
2248 target_url, | 2250 target_url, |
2249 content::Referrer(), | 2251 content::Referrer(), |
2250 content::PAGE_TRANSITION_LINK, | 2252 content::PAGE_TRANSITION_LINK, |
2251 std::string()); // No extra headers. | 2253 std::string()); // No extra headers. |
2252 } | 2254 } |
2253 | 2255 |
2254 return contents != NULL; | 2256 return contents != NULL; |
2255 } | 2257 } |
OLD | NEW |