Chromium Code Reviews| 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 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2825 content::Source<WebContents>(contents->web_contents())); | 2831 content::Source<WebContents>(contents->web_contents())); |
| 2826 | 2832 |
| 2827 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, | 2833 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
| 2828 content::Source<WebContents>(contents->web_contents())); | 2834 content::Source<WebContents>(contents->web_contents())); |
| 2829 } | 2835 } |
| 2830 | 2836 |
| 2831 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 2837 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
| 2832 TabContents* contents, | 2838 TabContents* contents, |
| 2833 int index) { | 2839 int index) { |
| 2834 fullscreen_controller_->OnTabClosing(contents->web_contents()); | 2840 fullscreen_controller_->OnTabClosing(contents->web_contents()); |
| 2841 search_delegate_->OnTabClosing(contents); | |
|
sky
2012/06/21 18:26:49
I think you want TabDetachedAt, not this.
dhollowa
2012/06/21 22:16:43
TabDetachedAt is handled below. So I've removed t
| |
| 2835 content::NotificationService::current()->Notify( | 2842 content::NotificationService::current()->Notify( |
| 2836 chrome::NOTIFICATION_TAB_CLOSING, | 2843 chrome::NOTIFICATION_TAB_CLOSING, |
| 2837 content::Source<NavigationController>( | 2844 content::Source<NavigationController>( |
| 2838 &contents->web_contents()->GetController()), | 2845 &contents->web_contents()->GetController()), |
| 2839 content::NotificationService::NoDetails()); | 2846 content::NotificationService::NoDetails()); |
| 2840 | 2847 |
| 2841 // Sever the WebContents' connection back to us. | 2848 // Sever the WebContents' connection back to us. |
| 2842 SetAsDelegate(contents, NULL); | 2849 SetAsDelegate(contents, NULL); |
| 2843 } | 2850 } |
| 2844 | 2851 |
| 2845 void Browser::TabDetachedAt(TabContents* contents, int index) { | 2852 void Browser::TabDetachedAt(TabContents* contents, int index) { |
| 2846 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 2853 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
| 2847 } | 2854 } |
| 2848 | 2855 |
| 2849 void Browser::TabDeactivated(TabContents* contents) { | 2856 void Browser::TabDeactivated(TabContents* contents) { |
| 2850 fullscreen_controller_->OnTabDeactivated(contents); | 2857 fullscreen_controller_->OnTabDeactivated(contents); |
| 2858 search_delegate_->OnTabDeactivated(contents); | |
| 2859 | |
| 2851 if (instant()) | 2860 if (instant()) |
| 2852 instant()->Hide(); | 2861 instant()->Hide(); |
| 2853 | 2862 |
| 2854 // Save what the user's currently typing, so it can be restored when we | 2863 // Save what the user's currently typing, so it can be restored when we |
| 2855 // switch back to this tab. | 2864 // switch back to this tab. |
| 2856 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); | 2865 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
| 2857 } | 2866 } |
| 2858 | 2867 |
| 2859 void Browser::ActiveTabChanged(TabContents* old_contents, | 2868 void Browser::ActiveTabChanged(TabContents* old_contents, |
| 2860 TabContents* new_contents, | 2869 TabContents* new_contents, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2885 Reload(CURRENT_TAB); | 2894 Reload(CURRENT_TAB); |
| 2886 } | 2895 } |
| 2887 | 2896 |
| 2888 // If we have any update pending, do it now. | 2897 // If we have any update pending, do it now. |
| 2889 if (chrome_updater_factory_.HasWeakPtrs() && old_contents) | 2898 if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
| 2890 ProcessPendingUIUpdates(); | 2899 ProcessPendingUIUpdates(); |
| 2891 | 2900 |
| 2892 // Propagate the profile to the location bar. | 2901 // Propagate the profile to the location bar. |
| 2893 UpdateToolbar(true); | 2902 UpdateToolbar(true); |
| 2894 | 2903 |
| 2904 // Propagate tab state to toolbar, tab-strip, etc. | |
| 2905 UpdateSearchState(new_contents); | |
| 2906 | |
| 2895 // Update reload/stop state. | 2907 // Update reload/stop state. |
| 2896 UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); | 2908 UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); |
| 2897 | 2909 |
| 2898 // Update commands to reflect current state. | 2910 // Update commands to reflect current state. |
| 2899 UpdateCommandsForTabState(); | 2911 UpdateCommandsForTabState(); |
| 2900 | 2912 |
| 2901 // Reset the status bubble. | 2913 // Reset the status bubble. |
| 2902 StatusBubble* status_bubble = GetStatusBubble(); | 2914 StatusBubble* status_bubble = GetStatusBubble(); |
| 2903 if (status_bubble) { | 2915 if (status_bubble) { |
| 2904 status_bubble->Hide(); | 2916 status_bubble->Hide(); |
| (...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4418 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 4430 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 4419 } | 4431 } |
| 4420 | 4432 |
| 4421 /////////////////////////////////////////////////////////////////////////////// | 4433 /////////////////////////////////////////////////////////////////////////////// |
| 4422 // Browser, UI update coalescing and handling (private): | 4434 // Browser, UI update coalescing and handling (private): |
| 4423 | 4435 |
| 4424 void Browser::UpdateToolbar(bool should_restore_state) { | 4436 void Browser::UpdateToolbar(bool should_restore_state) { |
| 4425 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state); | 4437 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state); |
| 4426 } | 4438 } |
| 4427 | 4439 |
| 4440 void Browser::UpdateSearchState(TabContents* contents) { | |
| 4441 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) | |
| 4442 search_delegate_->OnTabActivated(contents); | |
| 4443 } | |
| 4444 | |
| 4428 void Browser::ScheduleUIUpdate(const WebContents* source, | 4445 void Browser::ScheduleUIUpdate(const WebContents* source, |
| 4429 unsigned changed_flags) { | 4446 unsigned changed_flags) { |
| 4430 if (!source) | 4447 if (!source) |
| 4431 return; | 4448 return; |
| 4432 | 4449 |
| 4433 // Do some synchronous updates. | 4450 // Do some synchronous updates. |
| 4434 if (changed_flags & content::INVALIDATE_TYPE_URL && | 4451 if (changed_flags & content::INVALIDATE_TYPE_URL && |
| 4435 source == GetActiveWebContents()) { | 4452 source == GetActiveWebContents()) { |
| 4436 // Only update the URL for the current tab. Note that we do not update | 4453 // 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 | 4454 // the navigation commands since those would have already been updated |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4780 } | 4797 } |
| 4781 | 4798 |
| 4782 if (is_attempting_to_close_browser_) { | 4799 if (is_attempting_to_close_browser_) { |
| 4783 // If this is the last tab with unload handlers, then ProcessPendingTabs | 4800 // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 4784 // would call back into the TabStripModel (which is invoking this method on | 4801 // 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 | 4802 // us). Avoid that by passing in false so that the call to |
| 4786 // ProcessPendingTabs is delayed. | 4803 // ProcessPendingTabs is delayed. |
| 4787 ClearUnloadState(contents->web_contents(), false); | 4804 ClearUnloadState(contents->web_contents(), false); |
| 4788 } | 4805 } |
| 4789 | 4806 |
| 4807 // Stop observing search model changes for this tab. | |
| 4808 search_delegate_->OnTabDettached(contents); | |
| 4809 | |
| 4790 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 4810 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 4791 content::Source<WebContents>(contents->web_contents())); | 4811 content::Source<WebContents>(contents->web_contents())); |
| 4792 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, | 4812 registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
| 4793 content::Source<WebContents>(contents->web_contents())); | 4813 content::Source<WebContents>(contents->web_contents())); |
| 4794 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 4814 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 4795 content::Source<WebContents>(contents->web_contents())); | 4815 content::Source<WebContents>(contents->web_contents())); |
| 4796 } | 4816 } |
| 4797 | 4817 |
| 4798 // static | 4818 // static |
| 4799 void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { | 4819 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) { | 5180 if (contents && !allow_js_access) { |
| 5161 contents->web_contents()->GetController().LoadURL( | 5181 contents->web_contents()->GetController().LoadURL( |
| 5162 target_url, | 5182 target_url, |
| 5163 content::Referrer(), | 5183 content::Referrer(), |
| 5164 content::PAGE_TRANSITION_LINK, | 5184 content::PAGE_TRANSITION_LINK, |
| 5165 std::string()); // No extra headers. | 5185 std::string()); // No extra headers. |
| 5166 } | 5186 } |
| 5167 | 5187 |
| 5168 return contents != NULL; | 5188 return contents != NULL; |
| 5169 } | 5189 } |
| OLD | NEW |