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