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 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
32 #include "chrome/app/chrome_command_ids.h" | 32 #include "chrome/app/chrome_command_ids.h" |
33 #include "chrome/browser/app_mode/app_mode_utils.h" | 33 #include "chrome/browser/app_mode/app_mode_utils.h" |
34 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 34 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
35 #include "chrome/browser/background/background_contents.h" | 35 #include "chrome/browser/background/background_contents.h" |
36 #include "chrome/browser/background/background_contents_service.h" | 36 #include "chrome/browser/background/background_contents_service.h" |
37 #include "chrome/browser/background/background_contents_service_factory.h" | 37 #include "chrome/browser/background/background_contents_service_factory.h" |
38 #include "chrome/browser/banners/app_banner_manager_desktop.h" | 38 #include "chrome/browser/banners/app_banner_manager_desktop.h" |
39 #include "chrome/browser/browser_process.h" | 39 #include "chrome/browser/browser_process.h" |
40 #include "chrome/browser/browser_shutdown.h" | 40 #include "chrome/browser/browser_shutdown.h" |
41 #include "chrome/browser/character_encoding.h" | |
42 #include "chrome/browser/chrome_notification_types.h" | 41 #include "chrome/browser/chrome_notification_types.h" |
43 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 42 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
44 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 43 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
45 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 44 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
46 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" | 45 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" |
47 #include "chrome/browser/defaults.h" | 46 #include "chrome/browser/defaults.h" |
48 #include "chrome/browser/devtools/devtools_toggle_action.h" | 47 #include "chrome/browser/devtools/devtools_toggle_action.h" |
49 #include "chrome/browser/devtools/devtools_window.h" | 48 #include "chrome/browser/devtools/devtools_window.h" |
50 #include "chrome/browser/download/download_service.h" | 49 #include "chrome/browser/download/download_service.h" |
51 #include "chrome/browser/download/download_service_factory.h" | 50 #include "chrome/browser/download/download_service_factory.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 407 |
409 profile_pref_registrar_.Init(profile_->GetPrefs()); | 408 profile_pref_registrar_.Init(profile_->GetPrefs()); |
410 profile_pref_registrar_.Add( | 409 profile_pref_registrar_.Add( |
411 prefs::kDevToolsDisabled, | 410 prefs::kDevToolsDisabled, |
412 base::Bind(&Browser::OnDevToolsDisabledChanged, base::Unretained(this))); | 411 base::Bind(&Browser::OnDevToolsDisabledChanged, base::Unretained(this))); |
413 profile_pref_registrar_.Add( | 412 profile_pref_registrar_.Add( |
414 bookmarks::prefs::kShowBookmarkBar, | 413 bookmarks::prefs::kShowBookmarkBar, |
415 base::Bind(&Browser::UpdateBookmarkBarState, base::Unretained(this), | 414 base::Bind(&Browser::UpdateBookmarkBarState, base::Unretained(this), |
416 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE)); | 415 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE)); |
417 | 416 |
418 // NOTE: These prefs all need to be explicitly destroyed in the destructor | |
419 // or you'll get a nasty surprise when you run the incognito tests. | |
420 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | |
421 profile_->GetPrefs()); | |
422 | |
423 if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed()) | 417 if (search::IsInstantExtendedAPIEnabled() && is_type_tabbed()) |
424 instant_controller_.reset(new BrowserInstantController(this)); | 418 instant_controller_.reset(new BrowserInstantController(this)); |
425 | 419 |
426 if (extensions::HostedAppBrowserController::IsForHostedApp(this)) { | 420 if (extensions::HostedAppBrowserController::IsForHostedApp(this)) { |
427 hosted_app_controller_.reset( | 421 hosted_app_controller_.reset( |
428 new extensions::HostedAppBrowserController(this)); | 422 new extensions::HostedAppBrowserController(this)); |
429 } | 423 } |
430 | 424 |
431 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); | 425 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
432 | 426 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 if (session_service) | 483 if (session_service) |
490 session_service->WindowClosed(session_id_); | 484 session_service->WindowClosed(session_id_); |
491 | 485 |
492 sessions::TabRestoreService* tab_restore_service = | 486 sessions::TabRestoreService* tab_restore_service = |
493 TabRestoreServiceFactory::GetForProfile(profile()); | 487 TabRestoreServiceFactory::GetForProfile(profile()); |
494 if (tab_restore_service) | 488 if (tab_restore_service) |
495 tab_restore_service->BrowserClosed(live_tab_context()); | 489 tab_restore_service->BrowserClosed(live_tab_context()); |
496 | 490 |
497 profile_pref_registrar_.RemoveAll(); | 491 profile_pref_registrar_.RemoveAll(); |
498 | 492 |
499 encoding_auto_detect_.Destroy(); | |
500 | |
501 // Destroy BrowserExtensionWindowController before the incognito profile | 493 // Destroy BrowserExtensionWindowController before the incognito profile |
502 // is destroyed to make sure the chrome.windows.onRemoved event is sent. | 494 // is destroyed to make sure the chrome.windows.onRemoved event is sent. |
503 extension_window_controller_.reset(); | 495 extension_window_controller_.reset(); |
504 | 496 |
505 // Destroy BrowserInstantController before the incongnito profile is destroyed | 497 // Destroy BrowserInstantController before the incongnito profile is destroyed |
506 // because the InstantController destructor depends on this profile. | 498 // because the InstantController destructor depends on this profile. |
507 instant_controller_.reset(); | 499 instant_controller_.reset(); |
508 | 500 |
509 if (profile_->IsOffTheRecord() && | 501 if (profile_->IsOffTheRecord() && |
510 !BrowserList::IsIncognitoSessionActiveForProfile(profile_)) { | 502 !BrowserList::IsIncognitoSessionActiveForProfile(profile_)) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 813 } |
822 | 814 |
823 bool Browser::SupportsWindowFeature(WindowFeature feature) const { | 815 bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
824 return SupportsWindowFeatureImpl(feature, true); | 816 return SupportsWindowFeatureImpl(feature, true); |
825 } | 817 } |
826 | 818 |
827 bool Browser::CanSupportWindowFeature(WindowFeature feature) const { | 819 bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
828 return SupportsWindowFeatureImpl(feature, false); | 820 return SupportsWindowFeatureImpl(feature, false); |
829 } | 821 } |
830 | 822 |
831 void Browser::ToggleEncodingAutoDetect() { | |
832 content::RecordAction(UserMetricsAction("AutoDetectChange")); | |
833 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); | |
834 // If "auto detect" is turned on, then any current override encoding | |
835 // is cleared. This also implicitly performs a reload. | |
836 // OTOH, if "auto detect" is turned off, we don't change the currently | |
837 // active encoding. | |
838 if (encoding_auto_detect_.GetValue()) { | |
839 WebContents* contents = tab_strip_model_->GetActiveWebContents(); | |
840 if (contents) | |
841 contents->ResetOverrideEncoding(); | |
842 } | |
843 } | |
844 | |
845 void Browser::OverrideEncoding(int encoding_id) { | |
846 content::RecordAction(UserMetricsAction("OverrideEncoding")); | |
847 const std::string selected_encoding = | |
848 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); | |
849 WebContents* contents = tab_strip_model_->GetActiveWebContents(); | |
850 if (!selected_encoding.empty() && contents) | |
851 contents->SetOverrideEncoding(selected_encoding); | |
852 // Update the list of recently selected encodings. | |
853 std::string new_selected_encoding_list; | |
854 if (CharacterEncoding::UpdateRecentlySelectedEncoding( | |
855 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), | |
856 encoding_id, | |
857 &new_selected_encoding_list)) { | |
858 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, | |
859 new_selected_encoding_list); | |
860 } | |
861 } | |
862 | |
863 void Browser::OpenFile() { | 823 void Browser::OpenFile() { |
864 content::RecordAction(UserMetricsAction("OpenFile")); | 824 content::RecordAction(UserMetricsAction("OpenFile")); |
865 select_file_dialog_ = ui::SelectFileDialog::Create( | 825 select_file_dialog_ = ui::SelectFileDialog::Create( |
866 this, new ChromeSelectFilePolicy( | 826 this, new ChromeSelectFilePolicy( |
867 tab_strip_model_->GetActiveWebContents())); | 827 tab_strip_model_->GetActiveWebContents())); |
868 | 828 |
869 const base::FilePath directory = profile_->last_selected_directory(); | 829 const base::FilePath directory = profile_->last_selected_directory(); |
870 | 830 |
871 // TODO(beng): figure out how to juggle this. | 831 // TODO(beng): figure out how to juggle this. |
872 gfx::NativeWindow parent_window = window_->GetNativeWindow(); | 832 gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 if (contents && !allow_js_access) { | 2560 if (contents && !allow_js_access) { |
2601 contents->web_contents()->GetController().LoadURL( | 2561 contents->web_contents()->GetController().LoadURL( |
2602 target_url, | 2562 target_url, |
2603 content::Referrer(), | 2563 content::Referrer(), |
2604 ui::PAGE_TRANSITION_LINK, | 2564 ui::PAGE_TRANSITION_LINK, |
2605 std::string()); // No extra headers. | 2565 std::string()); // No extra headers. |
2606 } | 2566 } |
2607 | 2567 |
2608 return contents != NULL; | 2568 return contents != NULL; |
2609 } | 2569 } |
OLD | NEW |