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