Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 287123002: [WebModals] New API for browser-scoped popup management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cocoa, more test fiddles, etc Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 be a DCHECK but tests.
449 if (GetWebContentsModalDialogHost()) {
450 popup_manager_.reset(new web_modal::PopupManager(
451 GetWebContentsModalDialogHost()));
452 }
445 } 453 }
446 454
447 Browser::~Browser() { 455 Browser::~Browser() {
448 // Stop observing notifications before continuing with destruction. Profile 456 // Stop observing notifications before continuing with destruction. Profile
449 // destruction will unload extensions and reentrant calls to Browser:: should 457 // destruction will unload extensions and reentrant calls to Browser:: should
450 // be avoided while it is being torn down. 458 // be avoided while it is being torn down.
451 registrar_.RemoveAll(); 459 registrar_.RemoveAll();
452 460
453 // The tab strip should not have any tabs at this point. 461 // The tab strip should not have any tabs at this point.
454 DCHECK(tab_strip_model_->empty()); 462 DCHECK(tab_strip_model_->empty());
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 return OpenURLFromTab(NULL, params); 891 return OpenURLFromTab(NULL, params);
884 } 892 }
885 893
886 /////////////////////////////////////////////////////////////////////////////// 894 ///////////////////////////////////////////////////////////////////////////////
887 // Browser, TabStripModelObserver implementation: 895 // Browser, TabStripModelObserver implementation:
888 896
889 void Browser::TabInsertedAt(WebContents* contents, 897 void Browser::TabInsertedAt(WebContents* contents,
890 int index, 898 int index,
891 bool foreground) { 899 bool foreground) {
892 SetAsDelegate(contents, this); 900 SetAsDelegate(contents, this);
901
902 if (popup_manager_.get())
903 popup_manager_->RegisterWith(contents);
904
893 SessionTabHelper* session_tab_helper = 905 SessionTabHelper* session_tab_helper =
894 SessionTabHelper::FromWebContents(contents); 906 SessionTabHelper::FromWebContents(contents);
895 session_tab_helper->SetWindowID(session_id()); 907 session_tab_helper->SetWindowID(session_id());
896 908
897 content::NotificationService::current()->Notify( 909 content::NotificationService::current()->Notify(
898 chrome::NOTIFICATION_TAB_PARENTED, 910 chrome::NOTIFICATION_TAB_PARENTED,
899 content::Source<content::WebContents>(contents), 911 content::Source<content::WebContents>(contents),
900 content::NotificationService::NoDetails()); 912 content::NotificationService::NoDetails());
901 913
902 SyncHistoryWithTabs(index); 914 SyncHistoryWithTabs(index);
(...skipping 21 matching lines...) Expand all
924 fullscreen_controller_->OnTabClosing(contents); 936 fullscreen_controller_->OnTabClosing(contents);
925 SessionService* session_service = 937 SessionService* session_service =
926 SessionServiceFactory::GetForProfile(profile_); 938 SessionServiceFactory::GetForProfile(profile_);
927 if (session_service) 939 if (session_service)
928 session_service->TabClosing(contents); 940 session_service->TabClosing(contents);
929 content::NotificationService::current()->Notify( 941 content::NotificationService::current()->Notify(
930 chrome::NOTIFICATION_TAB_CLOSING, 942 chrome::NOTIFICATION_TAB_CLOSING,
931 content::Source<NavigationController>(&contents->GetController()), 943 content::Source<NavigationController>(&contents->GetController()),
932 content::NotificationService::NoDetails()); 944 content::NotificationService::NoDetails());
933 945
946 if (popup_manager_.get())
947 popup_manager_->UnregisterWith(contents);
948
934 // Sever the WebContents' connection back to us. 949 // Sever the WebContents' connection back to us.
935 SetAsDelegate(contents, NULL); 950 SetAsDelegate(contents, NULL);
936 } 951 }
937 952
938 void Browser::TabDetachedAt(WebContents* contents, int index) { 953 void Browser::TabDetachedAt(WebContents* contents, int index) {
939 // TabDetachedAt is called before TabStripModel has updated the 954 // TabDetachedAt is called before TabStripModel has updated the
940 // active index. 955 // active index.
941 int old_active_index = tab_strip_model_->active_index(); 956 int old_active_index = tab_strip_model_->active_index();
942 if (index < old_active_index && !tab_strip_model_->closing_all()) { 957 if (index < old_active_index && !tab_strip_model_->closing_all()) {
943 SessionService* session_service = 958 SessionService* session_service =
944 SessionServiceFactory::GetForProfileIfExisting(profile_); 959 SessionServiceFactory::GetForProfileIfExisting(profile_);
945 if (session_service) 960 if (session_service)
946 session_service->SetSelectedTabInWindow(session_id(), 961 session_service->SetSelectedTabInWindow(session_id(),
947 old_active_index - 1); 962 old_active_index - 1);
948 } 963 }
964
965 if (popup_manager_.get())
966 popup_manager_->UnregisterWith(contents);
967
949 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); 968 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
950 } 969 }
951 970
952 void Browser::TabDeactivated(WebContents* contents) { 971 void Browser::TabDeactivated(WebContents* contents) {
953 fullscreen_controller_->OnTabDeactivated(contents); 972 fullscreen_controller_->OnTabDeactivated(contents);
954 search_delegate_->OnTabDeactivated(contents); 973 search_delegate_->OnTabDeactivated(contents);
955 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated(); 974 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated();
956 975
957 // Save what the user's currently typing, so it can be restored when we 976 // Save what the user's currently typing, so it can be restored when we
958 // switch back to this tab. 977 // switch back to this tab.
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 if (contents && !allow_js_access) { 2436 if (contents && !allow_js_access) {
2418 contents->web_contents()->GetController().LoadURL( 2437 contents->web_contents()->GetController().LoadURL(
2419 target_url, 2438 target_url,
2420 content::Referrer(), 2439 content::Referrer(),
2421 content::PAGE_TRANSITION_LINK, 2440 content::PAGE_TRANSITION_LINK,
2422 std::string()); // No extra headers. 2441 std::string()); // No extra headers.
2423 } 2442 }
2424 2443
2425 return contents != NULL; 2444 return contents != NULL;
2426 } 2445 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698