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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #include "content/browser/host_zoom_map.h" 142 #include "content/browser/host_zoom_map.h"
143 #include "content/browser/plugin_service.h" 143 #include "content/browser/plugin_service.h"
144 #include "content/browser/renderer_host/render_view_host.h" 144 #include "content/browser/renderer_host/render_view_host.h"
145 #include "content/browser/site_instance.h" 145 #include "content/browser/site_instance.h"
146 #include "content/browser/tab_contents/interstitial_page.h" 146 #include "content/browser/tab_contents/interstitial_page.h"
147 #include "content/browser/tab_contents/navigation_controller.h" 147 #include "content/browser/tab_contents/navigation_controller.h"
148 #include "content/browser/tab_contents/navigation_entry.h" 148 #include "content/browser/tab_contents/navigation_entry.h"
149 #include "content/browser/tab_contents/tab_contents_view.h" 149 #include "content/browser/tab_contents/tab_contents_view.h"
150 #include "content/browser/user_metrics.h" 150 #include "content/browser/user_metrics.h"
151 #include "content/common/content_restriction.h" 151 #include "content/common/content_restriction.h"
152 #include "content/common/notification_service.h" 152 #include "content/public/browser/notification_service.h"
153 #include "content/common/page_zoom.h" 153 #include "content/common/page_zoom.h"
154 #include "content/public/browser/notification_details.h" 154 #include "content/public/browser/notification_details.h"
155 #include "content/public/common/content_switches.h" 155 #include "content/public/common/content_switches.h"
156 #include "grit/chromium_strings.h" 156 #include "grit/chromium_strings.h"
157 #include "grit/generated_resources.h" 157 #include "grit/generated_resources.h"
158 #include "grit/locale_settings.h" 158 #include "grit/locale_settings.h"
159 #include "grit/theme_resources_standard.h" 159 #include "grit/theme_resources_standard.h"
160 #include "net/base/cookie_monster.h" 160 #include "net/base/cookie_monster.h"
161 #include "net/base/net_util.h" 161 #include "net/base/net_util.h"
162 #include "net/base/registry_controlled_domain.h" 162 #include "net/base/registry_controlled_domain.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ALLOW_THIS_IN_INITIALIZER_LIST( 287 ALLOW_THIS_IN_INITIALIZER_LIST(
288 synced_window_delegate_( 288 synced_window_delegate_(
289 new BrowserSyncedWindowDelegate(this))), 289 new BrowserSyncedWindowDelegate(this))),
290 bookmark_bar_state_(BookmarkBar::HIDDEN), 290 bookmark_bar_state_(BookmarkBar::HIDDEN),
291 fullscreened_tab_(NULL), 291 fullscreened_tab_(NULL),
292 tab_caused_fullscreen_(false), 292 tab_caused_fullscreen_(false),
293 tab_fullscreen_accepted_(false), 293 tab_fullscreen_accepted_(false),
294 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), 294 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED),
295 window_has_shown_(false) { 295 window_has_shown_(false) {
296 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, 296 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
297 NotificationService::AllSources()); 297 content::NotificationService::AllSources());
298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
299 content::Source<Profile>(profile_)); 299 content::Source<Profile>(profile_));
300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 300 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
301 content::Source<Profile>(profile_)); 301 content::Source<Profile>(profile_));
302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
303 content::Source<Profile>(profile_)); 303 content::Source<Profile>(profile_));
304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
305 content::Source<Profile>(profile_)); 305 content::Source<Profile>(profile_));
306 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 306 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
307 NotificationService::AllSources()); 307 content::NotificationService::AllSources());
308 registrar_.Add( 308 registrar_.Add(
309 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 309 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
310 content::Source<ThemeService>( 310 content::Source<ThemeService>(
311 ThemeServiceFactory::GetForProfile(profile_))); 311 ThemeServiceFactory::GetForProfile(profile_)));
312 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, 312 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED,
313 NotificationService::AllSources()); 313 content::NotificationService::AllSources());
314 314
315 // Need to know when to alert the user of theme install delay. 315 // Need to know when to alert the user of theme install delay.
316 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL, 316 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_READY_FOR_INSTALL,
317 NotificationService::AllSources()); 317 content::NotificationService::AllSources());
318 318
319 PrefService* local_state = g_browser_process->local_state(); 319 PrefService* local_state = g_browser_process->local_state();
320 if (local_state) { 320 if (local_state) {
321 local_pref_registrar_.Init(local_state); 321 local_pref_registrar_.Init(local_state);
322 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); 322 local_pref_registrar_.Add(prefs::kPrintingEnabled, this);
323 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); 323 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this);
324 local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this); 324 local_pref_registrar_.Add(prefs::kMetricsReportingEnabled, this);
325 } 325 }
326 326
327 profile_pref_registrar_.Init(profile_->GetPrefs()); 327 profile_pref_registrar_.Init(profile_->GetPrefs());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // Set the app user model id for this application to that of the application 492 // Set the app user model id for this application to that of the application
493 // name. See http://crbug.com/7028. 493 // name. See http://crbug.com/7028.
494 ui::win::SetAppIdForWindow( 494 ui::win::SetAppIdForWindow(
495 is_app() ? 495 is_app() ?
496 ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : 496 ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) :
497 ShellIntegration::GetChromiumAppId(profile_->GetPath()), 497 ShellIntegration::GetChromiumAppId(profile_->GetPath()),
498 window()->GetNativeHandle()); 498 window()->GetNativeHandle());
499 } 499 }
500 #endif 500 #endif
501 501
502 NotificationService::current()->Notify( 502 content::NotificationService::current()->Notify(
503 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 503 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
504 content::Source<Browser>(this), 504 content::Source<Browser>(this),
505 NotificationService::NoDetails()); 505 content::NotificationService::NoDetails());
506 506
507 PrefService* local_state = g_browser_process->local_state(); 507 PrefService* local_state = g_browser_process->local_state();
508 if (local_state && local_state->FindPreference( 508 if (local_state && local_state->FindPreference(
509 prefs::kAutofillPersonalDataManagerFirstRun) && 509 prefs::kAutofillPersonalDataManagerFirstRun) &&
510 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { 510 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
511 // Notify PDM that this is a first run. 511 // Notify PDM that this is a first run.
512 #if defined(OS_WIN) 512 #if defined(OS_WIN)
513 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); 513 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_));
514 #endif // defined(OS_WIN) 514 #endif // defined(OS_WIN)
515 // Reset the preference so we don't call it again for subsequent windows. 515 // Reset the preference so we don't call it again for subsequent windows.
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 SessionServiceFactory::GetForProfile(profile()); 1005 SessionServiceFactory::GetForProfile(profile());
1006 if (session_service) 1006 if (session_service)
1007 session_service->WindowClosing(session_id()); 1007 session_service->WindowClosing(session_id());
1008 1008
1009 TabRestoreService* tab_restore_service = 1009 TabRestoreService* tab_restore_service =
1010 TabRestoreServiceFactory::GetForProfile(profile()); 1010 TabRestoreServiceFactory::GetForProfile(profile());
1011 if (tab_restore_service && is_type_tabbed() && tab_count()) 1011 if (tab_restore_service && is_type_tabbed() && tab_count())
1012 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); 1012 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
1013 1013
1014 // TODO(sky): convert session/tab restore to use notification. 1014 // TODO(sky): convert session/tab restore to use notification.
1015 NotificationService::current()->Notify( 1015 content::NotificationService::current()->Notify(
1016 chrome::NOTIFICATION_BROWSER_CLOSING, 1016 chrome::NOTIFICATION_BROWSER_CLOSING,
1017 content::Source<Browser>(this), 1017 content::Source<Browser>(this),
1018 content::Details<bool>(&exiting)); 1018 content::Details<bool>(&exiting));
1019 1019
1020 CloseAllTabs(); 1020 CloseAllTabs();
1021 } 1021 }
1022 1022
1023 void Browser::OnWindowActivated() { 1023 void Browser::OnWindowActivated() {
1024 // On some platforms we want to automatically reload tabs that are 1024 // On some platforms we want to automatically reload tabs that are
1025 // killed when the user selects them. 1025 // killed when the user selects them.
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 #if defined(OS_MACOSX) 1313 #if defined(OS_MACOSX)
1314 notify_tab_of_exit = !window_->InPresentationMode(); 1314 notify_tab_of_exit = !window_->InPresentationMode();
1315 #else 1315 #else
1316 notify_tab_of_exit = !window_->IsFullscreen(); 1316 notify_tab_of_exit = !window_->IsFullscreen();
1317 #endif 1317 #endif
1318 if (notify_tab_of_exit) 1318 if (notify_tab_of_exit)
1319 NotifyTabOfFullscreenExitIfNecessary(); 1319 NotifyTabOfFullscreenExitIfNecessary();
1320 } 1320 }
1321 1321
1322 void Browser::NotifyFullscreenChange() { 1322 void Browser::NotifyFullscreenChange() {
1323 NotificationService::current()->Notify( 1323 content::NotificationService::current()->Notify(
1324 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 1324 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
1325 content::Source<Browser>(this), 1325 content::Source<Browser>(this),
1326 NotificationService::NoDetails()); 1326 content::NotificationService::NoDetails());
1327 } 1327 }
1328 1328
1329 /////////////////////////////////////////////////////////////////////////////// 1329 ///////////////////////////////////////////////////////////////////////////////
1330 // Browser, Assorted browser commands: 1330 // Browser, Assorted browser commands:
1331 1331
1332 TabContents* Browser::GetOrCloneTabForDisposition( 1332 TabContents* Browser::GetOrCloneTabForDisposition(
1333 WindowOpenDisposition disposition) { 1333 WindowOpenDisposition disposition) {
1334 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 1334 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1335 switch (disposition) { 1335 switch (disposition) {
1336 case NEW_FOREGROUND_TAB: 1336 case NEW_FOREGROUND_TAB:
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, 3193 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
3194 content::Source<TabContents>(contents->tab_contents())); 3194 content::Source<TabContents>(contents->tab_contents()));
3195 3195
3196 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, 3196 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
3197 content::Source<TabContents>(contents->tab_contents())); 3197 content::Source<TabContents>(contents->tab_contents()));
3198 } 3198 }
3199 3199
3200 void Browser::TabClosingAt(TabStripModel* tab_strip_model, 3200 void Browser::TabClosingAt(TabStripModel* tab_strip_model,
3201 TabContentsWrapper* contents, 3201 TabContentsWrapper* contents,
3202 int index) { 3202 int index) {
3203 NotificationService::current()->Notify( 3203 content::NotificationService::current()->Notify(
3204 content::NOTIFICATION_TAB_CLOSING, 3204 content::NOTIFICATION_TAB_CLOSING,
3205 content::Source<NavigationController>(&contents->controller()), 3205 content::Source<NavigationController>(&contents->controller()),
3206 NotificationService::NoDetails()); 3206 content::NotificationService::NoDetails());
3207 3207
3208 // Sever the TabContents' connection back to us. 3208 // Sever the TabContents' connection back to us.
3209 SetAsDelegate(contents, NULL); 3209 SetAsDelegate(contents, NULL);
3210 } 3210 }
3211 3211
3212 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { 3212 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) {
3213 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); 3213 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
3214 } 3214 }
3215 3215
3216 void Browser::TabDeactivated(TabContentsWrapper* contents) { 3216 void Browser::TabDeactivated(TabContentsWrapper* contents) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
3576 3576
3577 void Browser::ContentsZoomChange(bool zoom_in) { 3577 void Browser::ContentsZoomChange(bool zoom_in) {
3578 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); 3578 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
3579 } 3579 }
3580 3580
3581 void Browser::TabContentsFocused(TabContents* tab_content) { 3581 void Browser::TabContentsFocused(TabContents* tab_content) {
3582 window_->TabContentsFocused(tab_content); 3582 window_->TabContentsFocused(tab_content);
3583 } 3583 }
3584 3584
3585 bool Browser::TakeFocus(bool reverse) { 3585 bool Browser::TakeFocus(bool reverse) {
3586 NotificationService::current()->Notify( 3586 content::NotificationService::current()->Notify(
3587 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, 3587 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
3588 content::Source<Browser>(this), 3588 content::Source<Browser>(this),
3589 NotificationService::NoDetails()); 3589 content::NotificationService::NoDetails());
3590 return false; 3590 return false;
3591 } 3591 }
3592 3592
3593 bool Browser::IsApplication() const { 3593 bool Browser::IsApplication() const {
3594 return is_app(); 3594 return is_app();
3595 } 3595 }
3596 3596
3597 void Browser::ConvertContentsToApplication(TabContents* contents) { 3597 void Browser::ConvertContentsToApplication(TabContents* contents) {
3598 const GURL& url = contents->controller().GetActiveEntry()->url(); 3598 const GURL& url = contents->controller().GetActiveEntry()->url();
3599 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 3599 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
5254 5254
5255 bool Browser::OpenInstant(WindowOpenDisposition disposition) { 5255 bool Browser::OpenInstant(WindowOpenDisposition disposition) {
5256 if (!instant() || !instant()->PrepareForCommit() || 5256 if (!instant() || !instant()->PrepareForCommit() ||
5257 disposition == NEW_BACKGROUND_TAB) { 5257 disposition == NEW_BACKGROUND_TAB) {
5258 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't 5258 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't
5259 // attempt to use the instant preview. 5259 // attempt to use the instant preview.
5260 return false; 5260 return false;
5261 } 5261 }
5262 5262
5263 if (disposition == CURRENT_TAB) { 5263 if (disposition == CURRENT_TAB) {
5264 NotificationService::current()->Notify( 5264 content::NotificationService::current()->Notify(
5265 chrome::NOTIFICATION_INSTANT_COMMITTED, 5265 chrome::NOTIFICATION_INSTANT_COMMITTED,
5266 content::Source<TabContentsWrapper>(instant()->CommitCurrentPreview( 5266 content::Source<TabContentsWrapper>(instant()->CommitCurrentPreview(
5267 INSTANT_COMMIT_PRESSED_ENTER)), 5267 INSTANT_COMMIT_PRESSED_ENTER)),
5268 NotificationService::NoDetails()); 5268 content::NotificationService::NoDetails());
5269 return true; 5269 return true;
5270 } 5270 }
5271 if (disposition == NEW_FOREGROUND_TAB) { 5271 if (disposition == NEW_FOREGROUND_TAB) {
5272 TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( 5272 TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents(
5273 INSTANT_COMMIT_PRESSED_ENTER); 5273 INSTANT_COMMIT_PRESSED_ENTER);
5274 // HideInstant is invoked after release so that InstantController is not 5274 // HideInstant is invoked after release so that InstantController is not
5275 // active when HideInstant asks it for its state. 5275 // active when HideInstant asks it for its state.
5276 HideInstant(); 5276 HideInstant();
5277 preview_contents->controller().PruneAllButActive(); 5277 preview_contents->controller().PruneAllButActive();
5278 tab_handler_->GetTabStripModel()->AddTabContents( 5278 tab_handler_->GetTabStripModel()->AddTabContents(
5279 preview_contents, 5279 preview_contents,
5280 -1, 5280 -1,
5281 instant()->last_transition_type(), 5281 instant()->last_transition_type(),
5282 TabStripModel::ADD_ACTIVE); 5282 TabStripModel::ADD_ACTIVE);
5283 instant()->CompleteRelease(preview_contents); 5283 instant()->CompleteRelease(preview_contents);
5284 NotificationService::current()->Notify( 5284 content::NotificationService::current()->Notify(
5285 chrome::NOTIFICATION_INSTANT_COMMITTED, 5285 chrome::NOTIFICATION_INSTANT_COMMITTED,
5286 content::Source<TabContentsWrapper>(preview_contents), 5286 content::Source<TabContentsWrapper>(preview_contents),
5287 NotificationService::NoDetails()); 5287 content::NotificationService::NoDetails());
5288 return true; 5288 return true;
5289 } 5289 }
5290 // The omnibox currently doesn't use other dispositions, so we don't attempt 5290 // The omnibox currently doesn't use other dispositions, so we don't attempt
5291 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 5291 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
5292 // support for the new disposition. 5292 // support for the new disposition.
5293 NOTREACHED(); 5293 NOTREACHED();
5294 return false; 5294 return false;
5295 } 5295 }
5296 5296
5297 void Browser::CreateInstantIfNecessary() { 5297 void Browser::CreateInstantIfNecessary() {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
5490 } 5490 }
5491 5491
5492 void Browser::UpdateFullscreenExitBubbleContent() { 5492 void Browser::UpdateFullscreenExitBubbleContent() {
5493 GURL url; 5493 GURL url;
5494 if (fullscreened_tab_) 5494 if (fullscreened_tab_)
5495 url = fullscreened_tab_->tab_contents()->GetURL(); 5495 url = fullscreened_tab_->tab_contents()->GetURL();
5496 5496
5497 window_->UpdateFullscreenExitBubbleContent( 5497 window_->UpdateFullscreenExitBubbleContent(
5498 url, GetFullscreenExitBubbleType()); 5498 url, GetFullscreenExitBubbleType());
5499 } 5499 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698