| 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.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 // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 #include "chrome/browser/ui/fullscreen_controller.h" | 112 #include "chrome/browser/ui/fullscreen_controller.h" |
| 113 #include "chrome/browser/ui/global_error.h" | 113 #include "chrome/browser/ui/global_error.h" |
| 114 #include "chrome/browser/ui/global_error_service.h" | 114 #include "chrome/browser/ui/global_error_service.h" |
| 115 #include "chrome/browser/ui/global_error_service_factory.h" | 115 #include "chrome/browser/ui/global_error_service_factory.h" |
| 116 #include "chrome/browser/ui/hung_plugin_tab_helper.h" | 116 #include "chrome/browser/ui/hung_plugin_tab_helper.h" |
| 117 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 117 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 118 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 118 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| 119 #include "chrome/browser/ui/omnibox/location_bar.h" | 119 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 120 #include "chrome/browser/ui/panels/panel.h" | 120 #include "chrome/browser/ui/panels/panel.h" |
| 121 #include "chrome/browser/ui/panels/panel_manager.h" | 121 #include "chrome/browser/ui/panels/panel_manager.h" |
| 122 #include "chrome/browser/ui/search/search.h" |
| 123 #include "chrome/browser/ui/search/search_delegate.h" |
| 124 #include "chrome/browser/ui/search/search_model.h" |
| 122 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" | 125 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
| 123 #include "chrome/browser/ui/status_bubble.h" | 126 #include "chrome/browser/ui/status_bubble.h" |
| 124 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" | 127 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
| 125 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 128 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 126 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 129 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 127 #include "chrome/browser/ui/tabs/dock_info.h" | 130 #include "chrome/browser/ui/tabs/dock_info.h" |
| 128 #include "chrome/browser/ui/tabs/tab_finder.h" | 131 #include "chrome/browser/ui/tabs/tab_finder.h" |
| 129 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 132 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 130 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 133 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 131 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 134 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 tab_restore_service_delegate_( | 370 tab_restore_service_delegate_( |
| 368 new BrowserTabRestoreServiceDelegate(this))), | 371 new BrowserTabRestoreServiceDelegate(this))), |
| 369 ALLOW_THIS_IN_INITIALIZER_LIST( | 372 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 370 synced_window_delegate_( | 373 synced_window_delegate_( |
| 371 new BrowserSyncedWindowDelegate(this))), | 374 new BrowserSyncedWindowDelegate(this))), |
| 372 bookmark_bar_state_(BookmarkBar::HIDDEN), | 375 bookmark_bar_state_(BookmarkBar::HIDDEN), |
| 373 window_has_shown_(false) { | 376 window_has_shown_(false) { |
| 374 tab_strip_model_->AddObserver(this); | 377 tab_strip_model_->AddObserver(this); |
| 375 | 378 |
| 376 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); | 379 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); |
| 380 search_model_.reset(new chrome::search::SearchModel(NULL)); |
| 381 search_delegate_.reset( |
| 382 new chrome::search::SearchDelegate(search_model_.get())); |
| 377 | 383 |
| 378 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 384 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
| 379 content::NotificationService::AllSources()); | 385 content::NotificationService::AllSources()); |
| 380 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 386 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 381 content::Source<Profile>(profile_->GetOriginalProfile())); | 387 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 382 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 388 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 383 content::Source<Profile>(profile_->GetOriginalProfile())); | 389 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 384 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 390 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 385 content::Source<Profile>(profile_->GetOriginalProfile())); | 391 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 386 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 392 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| (...skipping 2454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 // Sever the WebContents' connection back to us. | 2847 // Sever the WebContents' connection back to us. |
| 2842 SetAsDelegate(contents, NULL); | 2848 SetAsDelegate(contents, NULL); |
| 2843 } | 2849 } |
| 2844 | 2850 |
| 2845 void Browser::TabDetachedAt(TabContents* contents, int index) { | 2851 void Browser::TabDetachedAt(TabContents* contents, int index) { |
| 2846 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 2852 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
| 2847 } | 2853 } |
| 2848 | 2854 |
| 2849 void Browser::TabDeactivated(TabContents* contents) { | 2855 void Browser::TabDeactivated(TabContents* contents) { |
| 2850 fullscreen_controller_->OnTabDeactivated(contents); | 2856 fullscreen_controller_->OnTabDeactivated(contents); |
| 2857 search_delegate_->OnTabDeactivated(contents); |
| 2858 |
| 2851 if (instant()) | 2859 if (instant()) |
| 2852 instant()->Hide(); | 2860 instant()->Hide(); |
| 2853 | 2861 |
| 2854 // Save what the user's currently typing, so it can be restored when we | 2862 // Save what the user's currently typing, so it can be restored when we |
| 2855 // switch back to this tab. | 2863 // switch back to this tab. |
| 2856 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); | 2864 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
| 2857 } | 2865 } |
| 2858 | 2866 |
| 2859 void Browser::ActiveTabChanged(TabContents* old_contents, | 2867 void Browser::ActiveTabChanged(TabContents* old_contents, |
| 2860 TabContents* new_contents, | 2868 TabContents* new_contents, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2885 Reload(CURRENT_TAB); | 2893 Reload(CURRENT_TAB); |
| 2886 } | 2894 } |
| 2887 | 2895 |
| 2888 // If we have any update pending, do it now. | 2896 // If we have any update pending, do it now. |
| 2889 if (chrome_updater_factory_.HasWeakPtrs() && old_contents) | 2897 if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
| 2890 ProcessPendingUIUpdates(); | 2898 ProcessPendingUIUpdates(); |
| 2891 | 2899 |
| 2892 // Propagate the profile to the location bar. | 2900 // Propagate the profile to the location bar. |
| 2893 UpdateToolbar(true); | 2901 UpdateToolbar(true); |
| 2894 | 2902 |
| 2903 // Propagate tab state to toolbar, tab-strip, etc. |
| 2904 UpdateSearchState(new_contents); |
| 2905 |
| 2895 // Update reload/stop state. | 2906 // Update reload/stop state. |
| 2896 UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); | 2907 UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); |
| 2897 | 2908 |
| 2898 // Update commands to reflect current state. | 2909 // Update commands to reflect current state. |
| 2899 UpdateCommandsForTabState(); | 2910 UpdateCommandsForTabState(); |
| 2900 | 2911 |
| 2901 // Reset the status bubble. | 2912 // Reset the status bubble. |
| 2902 StatusBubble* status_bubble = GetStatusBubble(); | 2913 StatusBubble* status_bubble = GetStatusBubble(); |
| 2903 if (status_bubble) { | 2914 if (status_bubble) { |
| 2904 status_bubble->Hide(); | 2915 status_bubble->Hide(); |
| (...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4418 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 4429 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 4419 } | 4430 } |
| 4420 | 4431 |
| 4421 /////////////////////////////////////////////////////////////////////////////// | 4432 /////////////////////////////////////////////////////////////////////////////// |
| 4422 // Browser, UI update coalescing and handling (private): | 4433 // Browser, UI update coalescing and handling (private): |
| 4423 | 4434 |
| 4424 void Browser::UpdateToolbar(bool should_restore_state) { | 4435 void Browser::UpdateToolbar(bool should_restore_state) { |
| 4425 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state); | 4436 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state); |
| 4426 } | 4437 } |
| 4427 | 4438 |
| 4439 void Browser::UpdateSearchState(TabContents* contents) { |
| 4440 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) |
| 4441 search_delegate_->OnTabActivated(contents); |
| 4442 } |
| 4443 |
| 4428 void Browser::ScheduleUIUpdate(const WebContents* source, | 4444 void Browser::ScheduleUIUpdate(const WebContents* source, |
| 4429 unsigned changed_flags) { | 4445 unsigned changed_flags) { |
| 4430 if (!source) | 4446 if (!source) |
| 4431 return; | 4447 return; |
| 4432 | 4448 |
| 4433 // Do some synchronous updates. | 4449 // Do some synchronous updates. |
| 4434 if (changed_flags & content::INVALIDATE_TYPE_URL && | 4450 if (changed_flags & content::INVALIDATE_TYPE_URL && |
| 4435 source == GetActiveWebContents()) { | 4451 source == GetActiveWebContents()) { |
| 4436 // Only update the URL for the current tab. Note that we do not update | 4452 // Only update the URL for the current tab. Note that we do not update |
| 4437 // the navigation commands since those would have already been updated | 4453 // the navigation commands since those would have already been updated |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4780 } | 4796 } |
| 4781 | 4797 |
| 4782 if (is_attempting_to_close_browser_) { | 4798 if (is_attempting_to_close_browser_) { |
| 4783 // If this is the last tab with unload handlers, then ProcessPendingTabs | 4799 // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 4784 // would call back into the TabStripModel (which is invoking this method on | 4800 // would call back into the TabStripModel (which is invoking this method on |
| 4785 // us). Avoid that by passing in false so that the call to | 4801 // us). Avoid that by passing in false so that the call to |
| 4786 // ProcessPendingTabs is delayed. | 4802 // ProcessPendingTabs is delayed. |
| 4787 ClearUnloadState(contents->web_contents(), false); | 4803 ClearUnloadState(contents->web_contents(), false); |
| 4788 } | 4804 } |
| 4789 | 4805 |
| 4806 // Stop observing search model changes for this tab. |
| 4807 search_delegate_->OnTabDetached(contents); |
| 4808 |
| 4790 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 4809 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 4791 content::Source<WebContents>(contents->web_contents())); | 4810 content::Source<WebContents>(contents->web_contents())); |
| 4792 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, | 4811 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
| 4793 content::Source<WebContents>(contents->web_contents())); | 4812 content::Source<WebContents>(contents->web_contents())); |
| 4794 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 4813 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 4795 content::Source<WebContents>(contents->web_contents())); | 4814 content::Source<WebContents>(contents->web_contents())); |
| 4796 } | 4815 } |
| 4797 | 4816 |
| 4798 // static | 4817 // static |
| 4799 void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { | 4818 void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5160 if (contents && !allow_js_access) { | 5179 if (contents && !allow_js_access) { |
| 5161 contents->web_contents()->GetController().LoadURL( | 5180 contents->web_contents()->GetController().LoadURL( |
| 5162 target_url, | 5181 target_url, |
| 5163 content::Referrer(), | 5182 content::Referrer(), |
| 5164 content::PAGE_TRANSITION_LINK, | 5183 content::PAGE_TRANSITION_LINK, |
| 5165 std::string()); // No extra headers. | 5184 std::string()); // No extra headers. |
| 5166 } | 5185 } |
| 5167 | 5186 |
| 5168 return contents != NULL; | 5187 return contents != NULL; |
| 5169 } | 5188 } |
| OLD | NEW |