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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 #include "chrome/common/chrome_switches.h" | 145 #include "chrome/common/chrome_switches.h" |
146 #include "chrome/common/custom_handlers/protocol_handler.h" | 146 #include "chrome/common/custom_handlers/protocol_handler.h" |
147 #include "chrome/common/pref_names.h" | 147 #include "chrome/common/pref_names.h" |
148 #include "chrome/common/profiling.h" | 148 #include "chrome/common/profiling.h" |
149 #include "chrome/common/search_types.h" | 149 #include "chrome/common/search_types.h" |
150 #include "chrome/common/url_constants.h" | 150 #include "chrome/common/url_constants.h" |
151 #include "components/bookmarks/browser/bookmark_model.h" | 151 #include "components/bookmarks/browser/bookmark_model.h" |
152 #include "components/bookmarks/browser/bookmark_utils.h" | 152 #include "components/bookmarks/browser/bookmark_utils.h" |
153 #include "components/google/core/browser/google_url_tracker.h" | 153 #include "components/google/core/browser/google_url_tracker.h" |
154 #include "components/startup_metric_utils/startup_metric_utils.h" | 154 #include "components/startup_metric_utils/startup_metric_utils.h" |
| 155 #include "components/web_modal/popup_manager.h" |
155 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 156 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
156 #include "content/public/browser/devtools_manager.h" | 157 #include "content/public/browser/devtools_manager.h" |
157 #include "content/public/browser/download_item.h" | 158 #include "content/public/browser/download_item.h" |
158 #include "content/public/browser/download_manager.h" | 159 #include "content/public/browser/download_manager.h" |
159 #include "content/public/browser/interstitial_page.h" | 160 #include "content/public/browser/interstitial_page.h" |
160 #include "content/public/browser/invalidate_type.h" | 161 #include "content/public/browser/invalidate_type.h" |
161 #include "content/public/browser/navigation_controller.h" | 162 #include "content/public/browser/navigation_controller.h" |
162 #include "content/public/browser/navigation_entry.h" | 163 #include "content/public/browser/navigation_entry.h" |
163 #include "content/public/browser/notification_details.h" | 164 #include "content/public/browser/notification_details.h" |
164 #include "content/public/browser/notification_service.h" | 165 #include "content/public/browser/notification_service.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // TODO(beng): move to ChromeBrowserMain: | 438 // TODO(beng): move to ChromeBrowserMain: |
438 if (first_run::ShouldDoPersonalDataManagerFirstRun()) { | 439 if (first_run::ShouldDoPersonalDataManagerFirstRun()) { |
439 #if defined(OS_WIN) | 440 #if defined(OS_WIN) |
440 // Notify PDM that this is a first run. | 441 // Notify PDM that this is a first run. |
441 ImportAutofillDataWin( | 442 ImportAutofillDataWin( |
442 autofill::PersonalDataManagerFactory::GetForProfile(profile_)); | 443 autofill::PersonalDataManagerFactory::GetForProfile(profile_)); |
443 #endif // defined(OS_WIN) | 444 #endif // defined(OS_WIN) |
444 } | 445 } |
445 | 446 |
446 fullscreen_controller_.reset(new FullscreenController(this)); | 447 fullscreen_controller_.reset(new FullscreenController(this)); |
| 448 |
| 449 // Must be initialized after window_. |
| 450 // Also: surprise! a modal dialog host is not necessary to host modal dialogs |
| 451 // without a modal dialog host, so that value may be null. |
| 452 popup_manager_.reset(new web_modal::PopupManager( |
| 453 GetWebContentsModalDialogHost())); |
447 } | 454 } |
448 | 455 |
449 Browser::~Browser() { | 456 Browser::~Browser() { |
450 // Stop observing notifications before continuing with destruction. Profile | 457 // Stop observing notifications before continuing with destruction. Profile |
451 // destruction will unload extensions and reentrant calls to Browser:: should | 458 // destruction will unload extensions and reentrant calls to Browser:: should |
452 // be avoided while it is being torn down. | 459 // be avoided while it is being torn down. |
453 registrar_.RemoveAll(); | 460 registrar_.RemoveAll(); |
454 | 461 |
455 // The tab strip should not have any tabs at this point. | 462 // The tab strip should not have any tabs at this point. |
456 DCHECK(tab_strip_model_->empty()); | 463 DCHECK(tab_strip_model_->empty()); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 return OpenURLFromTab(NULL, params); | 892 return OpenURLFromTab(NULL, params); |
886 } | 893 } |
887 | 894 |
888 /////////////////////////////////////////////////////////////////////////////// | 895 /////////////////////////////////////////////////////////////////////////////// |
889 // Browser, TabStripModelObserver implementation: | 896 // Browser, TabStripModelObserver implementation: |
890 | 897 |
891 void Browser::TabInsertedAt(WebContents* contents, | 898 void Browser::TabInsertedAt(WebContents* contents, |
892 int index, | 899 int index, |
893 bool foreground) { | 900 bool foreground) { |
894 SetAsDelegate(contents, true); | 901 SetAsDelegate(contents, true); |
| 902 |
| 903 if (popup_manager_) |
| 904 popup_manager_->RegisterWith(contents); |
| 905 |
895 SessionTabHelper* session_tab_helper = | 906 SessionTabHelper* session_tab_helper = |
896 SessionTabHelper::FromWebContents(contents); | 907 SessionTabHelper::FromWebContents(contents); |
897 session_tab_helper->SetWindowID(session_id()); | 908 session_tab_helper->SetWindowID(session_id()); |
898 | 909 |
899 content::NotificationService::current()->Notify( | 910 content::NotificationService::current()->Notify( |
900 chrome::NOTIFICATION_TAB_PARENTED, | 911 chrome::NOTIFICATION_TAB_PARENTED, |
901 content::Source<content::WebContents>(contents), | 912 content::Source<content::WebContents>(contents), |
902 content::NotificationService::NoDetails()); | 913 content::NotificationService::NoDetails()); |
903 | 914 |
904 SyncHistoryWithTabs(index); | 915 SyncHistoryWithTabs(index); |
(...skipping 21 matching lines...) Expand all Loading... |
926 fullscreen_controller_->OnTabClosing(contents); | 937 fullscreen_controller_->OnTabClosing(contents); |
927 SessionService* session_service = | 938 SessionService* session_service = |
928 SessionServiceFactory::GetForProfile(profile_); | 939 SessionServiceFactory::GetForProfile(profile_); |
929 if (session_service) | 940 if (session_service) |
930 session_service->TabClosing(contents); | 941 session_service->TabClosing(contents); |
931 content::NotificationService::current()->Notify( | 942 content::NotificationService::current()->Notify( |
932 chrome::NOTIFICATION_TAB_CLOSING, | 943 chrome::NOTIFICATION_TAB_CLOSING, |
933 content::Source<NavigationController>(&contents->GetController()), | 944 content::Source<NavigationController>(&contents->GetController()), |
934 content::NotificationService::NoDetails()); | 945 content::NotificationService::NoDetails()); |
935 | 946 |
| 947 if (popup_manager_) |
| 948 popup_manager_->UnregisterWith(contents); |
| 949 |
936 // Sever the WebContents' connection back to us. | 950 // Sever the WebContents' connection back to us. |
937 SetAsDelegate(contents, false); | 951 SetAsDelegate(contents, false); |
938 } | 952 } |
939 | 953 |
940 void Browser::TabDetachedAt(WebContents* contents, int index) { | 954 void Browser::TabDetachedAt(WebContents* contents, int index) { |
941 // TabDetachedAt is called before TabStripModel has updated the | 955 // TabDetachedAt is called before TabStripModel has updated the |
942 // active index. | 956 // active index. |
943 int old_active_index = tab_strip_model_->active_index(); | 957 int old_active_index = tab_strip_model_->active_index(); |
944 if (index < old_active_index && !tab_strip_model_->closing_all()) { | 958 if (index < old_active_index && !tab_strip_model_->closing_all()) { |
945 SessionService* session_service = | 959 SessionService* session_service = |
946 SessionServiceFactory::GetForProfileIfExisting(profile_); | 960 SessionServiceFactory::GetForProfileIfExisting(profile_); |
947 if (session_service) | 961 if (session_service) |
948 session_service->SetSelectedTabInWindow(session_id(), | 962 session_service->SetSelectedTabInWindow(session_id(), |
949 old_active_index - 1); | 963 old_active_index - 1); |
950 } | 964 } |
| 965 |
| 966 if (popup_manager_) |
| 967 popup_manager_->UnregisterWith(contents); |
| 968 |
951 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 969 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
952 } | 970 } |
953 | 971 |
954 void Browser::TabDeactivated(WebContents* contents) { | 972 void Browser::TabDeactivated(WebContents* contents) { |
955 fullscreen_controller_->OnTabDeactivated(contents); | 973 fullscreen_controller_->OnTabDeactivated(contents); |
956 search_delegate_->OnTabDeactivated(contents); | 974 search_delegate_->OnTabDeactivated(contents); |
957 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated(); | 975 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated(); |
958 | 976 |
959 // Save what the user's currently typing, so it can be restored when we | 977 // Save what the user's currently typing, so it can be restored when we |
960 // switch back to this tab. | 978 // switch back to this tab. |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2422 if (contents && !allow_js_access) { | 2440 if (contents && !allow_js_access) { |
2423 contents->web_contents()->GetController().LoadURL( | 2441 contents->web_contents()->GetController().LoadURL( |
2424 target_url, | 2442 target_url, |
2425 content::Referrer(), | 2443 content::Referrer(), |
2426 content::PAGE_TRANSITION_LINK, | 2444 content::PAGE_TRANSITION_LINK, |
2427 std::string()); // No extra headers. | 2445 std::string()); // No extra headers. |
2428 } | 2446 } |
2429 | 2447 |
2430 return contents != NULL; | 2448 return contents != NULL; |
2431 } | 2449 } |
OLD | NEW |