| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/profiles/off_the_record_profile_impl.h" | 5 #include "chrome/browser/profiles/off_the_record_profile_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/permissions/permission_manager_factory.h" | 31 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 32 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 32 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 33 #include "chrome/browser/plugins/plugin_prefs.h" | 33 #include "chrome/browser/plugins/plugin_prefs.h" |
| 34 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 34 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 35 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 35 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 37 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 37 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 38 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | 38 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
| 39 #include "chrome/browser/themes/theme_service.h" | 39 #include "chrome/browser/themes/theme_service.h" |
| 40 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 40 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 41 #include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h" | |
| 42 #include "chrome/common/chrome_constants.h" | 41 #include "chrome/common/chrome_constants.h" |
| 43 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 44 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/features.h" | 44 #include "chrome/common/features.h" |
| 46 #include "components/content_settings/core/browser/host_content_settings_map.h" | 45 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 47 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 46 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 48 #include "components/prefs/json_pref_store.h" | 47 #include "components/prefs/json_pref_store.h" |
| 49 #include "components/proxy_config/pref_proxy_config_tracker.h" | 48 #include "components/proxy_config/pref_proxy_config_tracker.h" |
| 50 #include "components/sync_preferences/pref_service_syncable.h" | 49 #include "components/sync_preferences/pref_service_syncable.h" |
| 51 #include "components/user_prefs/user_prefs.h" | 50 #include "components/user_prefs/user_prefs.h" |
| 52 #include "components/zoom/zoom_event_manager.h" | |
| 53 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 54 #include "content/public/browser/host_zoom_map.h" | |
| 55 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
| 56 #include "content/public/browser/storage_partition.h" | 53 #include "content/public/browser/storage_partition.h" |
| 57 #include "content/public/browser/url_data_source.h" | 54 #include "content/public/browser/url_data_source.h" |
| 58 #include "content/public/browser/web_contents.h" | 55 #include "content/public/browser/web_contents.h" |
| 59 #include "extensions/features/features.h" | 56 #include "extensions/features/features.h" |
| 60 #include "net/http/http_server_properties.h" | 57 #include "net/http/http_server_properties.h" |
| 61 #include "net/http/transport_security_state.h" | 58 #include "net/http/transport_security_state.h" |
| 62 #include "ppapi/features/features.h" | 59 #include "ppapi/features/features.h" |
| 63 #include "storage/browser/database/database_tracker.h" | 60 #include "storage/browser/database/database_tracker.h" |
| 64 | 61 |
| 65 #if defined(OS_ANDROID) | 62 #if defined(OS_ANDROID) |
| 66 #include "components/prefs/scoped_user_pref_update.h" | 63 #include "components/prefs/scoped_user_pref_update.h" |
| 67 #include "components/proxy_config/proxy_prefs.h" | 64 #include "components/proxy_config/proxy_prefs.h" |
| 65 #else // !defined(OS_ANDROID) |
| 66 #include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h" |
| 67 #include "components/zoom/zoom_event_manager.h" |
| 68 #include "content/public/browser/host_zoom_map.h" |
| 68 #endif // defined(OS_ANDROID) | 69 #endif // defined(OS_ANDROID) |
| 69 | 70 |
| 70 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 71 #include "chrome/browser/chromeos/preferences.h" | 72 #include "chrome/browser/chromeos/preferences.h" |
| 72 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 73 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 73 #endif | 74 #endif |
| 74 | 75 |
| 75 #if !defined(OS_CHROMEOS) | 76 #if !defined(OS_CHROMEOS) |
| 76 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 77 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
| 77 #endif | 78 #endif |
| 78 | 79 |
| 79 #if BUILDFLAG(ENABLE_EXTENSIONS) | 80 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 80 #include "chrome/browser/extensions/extension_service.h" | 81 #include "chrome/browser/extensions/extension_service.h" |
| 81 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 82 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 82 #include "components/guest_view/browser/guest_view_manager.h" | 83 #include "components/guest_view/browser/guest_view_manager.h" |
| 83 #include "extensions/browser/api/web_request/web_request_api.h" | 84 #include "extensions/browser/api/web_request/web_request_api.h" |
| 84 #include "extensions/browser/extension_system.h" | 85 #include "extensions/browser/extension_system.h" |
| 85 #include "extensions/common/extension.h" | 86 #include "extensions/common/extension.h" |
| 86 #endif | 87 #endif |
| 87 | 88 |
| 88 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 89 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 89 #include "chrome/browser/content_settings/content_settings_supervised_provider.h
" | 90 #include "chrome/browser/content_settings/content_settings_supervised_provider.h
" |
| 90 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 91 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 91 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" | 92 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
| 92 #endif | 93 #endif |
| 93 | 94 |
| 94 using content::BrowserThread; | 95 using content::BrowserThread; |
| 95 using content::DownloadManagerDelegate; | 96 using content::DownloadManagerDelegate; |
| 97 #if !defined(OS_ANDROID) |
| 96 using content::HostZoomMap; | 98 using content::HostZoomMap; |
| 99 #endif |
| 97 | 100 |
| 98 #if BUILDFLAG(ENABLE_EXTENSIONS) | 101 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 99 namespace { | 102 namespace { |
| 100 | 103 |
| 101 void NotifyOTRProfileCreatedOnIOThread(void* original_profile, | 104 void NotifyOTRProfileCreatedOnIOThread(void* original_profile, |
| 102 void* otr_profile) { | 105 void* otr_profile) { |
| 103 extensions::ExtensionWebRequestEventRouter::GetInstance() | 106 extensions::ExtensionWebRequestEventRouter::GetInstance() |
| 104 ->OnOTRBrowserContextCreated(original_profile, otr_profile); | 107 ->OnOTRBrowserContextCreated(original_profile, otr_profile); |
| 105 } | 108 } |
| 106 | 109 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 this); | 144 this); |
| 142 | 145 |
| 143 set_is_guest_profile( | 146 set_is_guest_profile( |
| 144 profile_->GetPath() == ProfileManager::GetGuestProfilePath()); | 147 profile_->GetPath() == ProfileManager::GetGuestProfilePath()); |
| 145 | 148 |
| 146 // Guest profiles may always be OTR. Check IncognitoModePrefs otherwise. | 149 // Guest profiles may always be OTR. Check IncognitoModePrefs otherwise. |
| 147 DCHECK(profile_->IsGuestSession() || | 150 DCHECK(profile_->IsGuestSession() || |
| 148 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) != | 151 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) != |
| 149 IncognitoModePrefs::DISABLED); | 152 IncognitoModePrefs::DISABLED); |
| 150 | 153 |
| 154 #if !defined(OS_ANDROID) |
| 151 TrackZoomLevelsFromParent(); | 155 TrackZoomLevelsFromParent(); |
| 156 #endif |
| 152 | 157 |
| 153 #if BUILDFLAG(ENABLE_PLUGINS) | 158 #if BUILDFLAG(ENABLE_PLUGINS) |
| 154 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( | 159 ChromePluginServiceFilter::GetInstance()->RegisterResourceContext( |
| 155 this, io_data_->GetResourceContextNoInit()); | 160 this, io_data_->GetResourceContextNoInit()); |
| 156 #endif | 161 #endif |
| 157 | 162 |
| 158 #if BUILDFLAG(ENABLE_EXTENSIONS) | 163 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 159 // Make the chrome//extension-icon/ resource available. | 164 // Make the chrome//extension-icon/ resource available. |
| 160 extensions::ExtensionIconSource* icon_source = | 165 extensions::ExtensionIconSource* icon_source = |
| 161 new extensions::ExtensionIconSource(profile_); | 166 new extensions::ExtensionIconSource(profile_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 202 |
| 198 // This must be called before ProfileIOData::ShutdownOnUIThread but after | 203 // This must be called before ProfileIOData::ShutdownOnUIThread but after |
| 199 // other profile-related destroy notifications are dispatched. | 204 // other profile-related destroy notifications are dispatched. |
| 200 ShutdownStoragePartitions(); | 205 ShutdownStoragePartitions(); |
| 201 } | 206 } |
| 202 | 207 |
| 203 void OffTheRecordProfileImpl::InitIoData() { | 208 void OffTheRecordProfileImpl::InitIoData() { |
| 204 io_data_.reset(new OffTheRecordProfileIOData::Handle(this)); | 209 io_data_.reset(new OffTheRecordProfileIOData::Handle(this)); |
| 205 } | 210 } |
| 206 | 211 |
| 212 #if !defined(OS_ANDROID) |
| 207 void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() { | 213 void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() { |
| 208 DCHECK_NE(INCOGNITO_PROFILE, profile_->GetProfileType()); | 214 DCHECK_NE(INCOGNITO_PROFILE, profile_->GetProfileType()); |
| 209 | 215 |
| 210 // Here we only want to use zoom levels stored in the main-context's default | 216 // Here we only want to use zoom levels stored in the main-context's default |
| 211 // storage partition. We're not interested in zoom levels in special | 217 // storage partition. We're not interested in zoom levels in special |
| 212 // partitions, e.g. those used by WebViewGuests. | 218 // partitions, e.g. those used by WebViewGuests. |
| 213 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 219 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 214 HostZoomMap* parent_host_zoom_map = | 220 HostZoomMap* parent_host_zoom_map = |
| 215 HostZoomMap::GetDefaultForBrowserContext(profile_); | 221 HostZoomMap::GetDefaultForBrowserContext(profile_); |
| 216 host_zoom_map->CopyFrom(parent_host_zoom_map); | 222 host_zoom_map->CopyFrom(parent_host_zoom_map); |
| 217 // Observe parent profile's HostZoomMap changes so they can also be applied | 223 // Observe parent profile's HostZoomMap changes so they can also be applied |
| 218 // to this profile's HostZoomMap. | 224 // to this profile's HostZoomMap. |
| 219 track_zoom_subscription_ = parent_host_zoom_map->AddZoomLevelChangedCallback( | 225 track_zoom_subscription_ = parent_host_zoom_map->AddZoomLevelChangedCallback( |
| 220 base::Bind(&OffTheRecordProfileImpl::OnParentZoomLevelChanged, | 226 base::Bind(&OffTheRecordProfileImpl::OnParentZoomLevelChanged, |
| 221 base::Unretained(this))); | 227 base::Unretained(this))); |
| 222 if (!profile_->GetZoomLevelPrefs()) | 228 if (!profile_->GetZoomLevelPrefs()) |
| 223 return; | 229 return; |
| 224 | 230 |
| 225 // Also track changes to the parent profile's default zoom level. | 231 // Also track changes to the parent profile's default zoom level. |
| 226 parent_default_zoom_level_subscription_ = | 232 parent_default_zoom_level_subscription_ = |
| 227 profile_->GetZoomLevelPrefs()->RegisterDefaultZoomLevelCallback( | 233 profile_->GetZoomLevelPrefs()->RegisterDefaultZoomLevelCallback( |
| 228 base::Bind(&OffTheRecordProfileImpl::UpdateDefaultZoomLevel, | 234 base::Bind(&OffTheRecordProfileImpl::UpdateDefaultZoomLevel, |
| 229 base::Unretained(this))); | 235 base::Unretained(this))); |
| 230 } | 236 } |
| 237 #endif // !defined(OS_ANDROID) |
| 231 | 238 |
| 232 std::string OffTheRecordProfileImpl::GetProfileUserName() const { | 239 std::string OffTheRecordProfileImpl::GetProfileUserName() const { |
| 233 // Incognito profile should not return the username. | 240 // Incognito profile should not return the username. |
| 234 return std::string(); | 241 return std::string(); |
| 235 } | 242 } |
| 236 | 243 |
| 237 Profile::ProfileType OffTheRecordProfileImpl::GetProfileType() const { | 244 Profile::ProfileType OffTheRecordProfileImpl::GetProfileType() const { |
| 238 #if !defined(OS_CHROMEOS) | 245 #if !defined(OS_CHROMEOS) |
| 239 return profile_->IsGuestSession() ? GUEST_PROFILE : INCOGNITO_PROFILE; | 246 return profile_->IsGuestSession() ? GUEST_PROFILE : INCOGNITO_PROFILE; |
| 240 #else | 247 #else |
| 241 return INCOGNITO_PROFILE; | 248 return INCOGNITO_PROFILE; |
| 242 #endif | 249 #endif |
| 243 } | 250 } |
| 244 | 251 |
| 245 base::FilePath OffTheRecordProfileImpl::GetPath() const { | 252 base::FilePath OffTheRecordProfileImpl::GetPath() const { |
| 246 return profile_->GetPath(); | 253 return profile_->GetPath(); |
| 247 } | 254 } |
| 248 | 255 |
| 256 #if !defined(OS_ANDROID) |
| 249 std::unique_ptr<content::ZoomLevelDelegate> | 257 std::unique_ptr<content::ZoomLevelDelegate> |
| 250 OffTheRecordProfileImpl::CreateZoomLevelDelegate( | 258 OffTheRecordProfileImpl::CreateZoomLevelDelegate( |
| 251 const base::FilePath& partition_path) { | 259 const base::FilePath& partition_path) { |
| 252 return base::MakeUnique<ChromeZoomLevelOTRDelegate>( | 260 return base::MakeUnique<ChromeZoomLevelOTRDelegate>( |
| 253 zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()); | 261 zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()); |
| 254 } | 262 } |
| 263 #endif // !defined(OS_ANDROID) |
| 255 | 264 |
| 256 scoped_refptr<base::SequencedTaskRunner> | 265 scoped_refptr<base::SequencedTaskRunner> |
| 257 OffTheRecordProfileImpl::GetIOTaskRunner() { | 266 OffTheRecordProfileImpl::GetIOTaskRunner() { |
| 258 return profile_->GetIOTaskRunner(); | 267 return profile_->GetIOTaskRunner(); |
| 259 } | 268 } |
| 260 | 269 |
| 261 bool OffTheRecordProfileImpl::IsOffTheRecord() const { | 270 bool OffTheRecordProfileImpl::IsOffTheRecord() const { |
| 262 return true; | 271 return true; |
| 263 } | 272 } |
| 264 | 273 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 #if defined(OS_CHROMEOS) | 523 #if defined(OS_CHROMEOS) |
| 515 if (IsGuestSession()) | 524 if (IsGuestSession()) |
| 516 profile = new GuestSessionProfile(this); | 525 profile = new GuestSessionProfile(this); |
| 517 #endif | 526 #endif |
| 518 if (!profile) | 527 if (!profile) |
| 519 profile = new OffTheRecordProfileImpl(this); | 528 profile = new OffTheRecordProfileImpl(this); |
| 520 profile->Init(); | 529 profile->Init(); |
| 521 return profile; | 530 return profile; |
| 522 } | 531 } |
| 523 | 532 |
| 533 #if !defined(OS_ANDROID) |
| 524 void OffTheRecordProfileImpl::OnParentZoomLevelChanged( | 534 void OffTheRecordProfileImpl::OnParentZoomLevelChanged( |
| 525 const HostZoomMap::ZoomLevelChange& change) { | 535 const HostZoomMap::ZoomLevelChange& change) { |
| 526 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 536 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 527 switch (change.mode) { | 537 switch (change.mode) { |
| 528 case HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM: | 538 case HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM: |
| 529 return; | 539 return; |
| 530 case HostZoomMap::ZOOM_CHANGED_FOR_HOST: | 540 case HostZoomMap::ZOOM_CHANGED_FOR_HOST: |
| 531 host_zoom_map->SetZoomLevelForHost(change.host, change.zoom_level); | 541 host_zoom_map->SetZoomLevelForHost(change.host, change.zoom_level); |
| 532 return; | 542 return; |
| 533 case HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST: | 543 case HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST: |
| 534 host_zoom_map->SetZoomLevelForHostAndScheme(change.scheme, | 544 host_zoom_map->SetZoomLevelForHostAndScheme(change.scheme, |
| 535 change.host, | 545 change.host, |
| 536 change.zoom_level); | 546 change.zoom_level); |
| 537 return; | 547 return; |
| 538 case HostZoomMap::PAGE_SCALE_IS_ONE_CHANGED: | 548 case HostZoomMap::PAGE_SCALE_IS_ONE_CHANGED: |
| 539 return; | 549 return; |
| 540 } | 550 } |
| 541 } | 551 } |
| 542 | 552 |
| 543 void OffTheRecordProfileImpl::UpdateDefaultZoomLevel() { | 553 void OffTheRecordProfileImpl::UpdateDefaultZoomLevel() { |
| 544 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 554 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 545 double default_zoom_level = | 555 double default_zoom_level = |
| 546 profile_->GetZoomLevelPrefs()->GetDefaultZoomLevelPref(); | 556 profile_->GetZoomLevelPrefs()->GetDefaultZoomLevelPref(); |
| 547 host_zoom_map->SetDefaultZoomLevel(default_zoom_level); | 557 host_zoom_map->SetDefaultZoomLevel(default_zoom_level); |
| 548 // HostZoomMap does not trigger zoom notification events when the default | 558 // HostZoomMap does not trigger zoom notification events when the default |
| 549 // zoom level is set, so we need to do it here. | 559 // zoom level is set, so we need to do it here. |
| 550 zoom::ZoomEventManager::GetForBrowserContext(this) | 560 zoom::ZoomEventManager::GetForBrowserContext(this) |
| 551 ->OnDefaultZoomLevelChanged(); | 561 ->OnDefaultZoomLevelChanged(); |
| 552 } | 562 } |
| 563 #endif // !defined(OS_ANDROID) |
| 553 | 564 |
| 554 PrefProxyConfigTracker* OffTheRecordProfileImpl::CreateProxyConfigTracker() { | 565 PrefProxyConfigTracker* OffTheRecordProfileImpl::CreateProxyConfigTracker() { |
| 555 #if defined(OS_CHROMEOS) | 566 #if defined(OS_CHROMEOS) |
| 556 if (chromeos::ProfileHelper::IsSigninProfile(this)) { | 567 if (chromeos::ProfileHelper::IsSigninProfile(this)) { |
| 557 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( | 568 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 558 g_browser_process->local_state()); | 569 g_browser_process->local_state()); |
| 559 } | 570 } |
| 560 #endif // defined(OS_CHROMEOS) | 571 #endif // defined(OS_CHROMEOS) |
| 561 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( | 572 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( |
| 562 GetPrefs(), g_browser_process->local_state()); | 573 GetPrefs(), g_browser_process->local_state()); |
| 563 } | 574 } |
| OLD | NEW |