| 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/extensions/data_deleter.h" | 5 #include "chrome/browser/extensions/data_deleter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 7 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
| 12 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 10 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/site_instance.h" |
| 12 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 13 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 16 | 20 |
| 17 using content::BrowserContext; | 21 using content::BrowserContext; |
| 18 using content::BrowserThread; | 22 using content::BrowserThread; |
| 19 using content::StoragePartition; | 23 using content::StoragePartition; |
| 20 | 24 |
| 21 namespace extensions { | 25 namespace extensions { |
| 22 | 26 |
| 23 // static | 27 // static |
| 24 void DataDeleter::StartDeleting(Profile* profile, | 28 void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) { |
| 25 const std::string& extension_id, | 29 DCHECK(profile); |
| 26 const GURL& storage_origin) { | 30 DCHECK(extension); |
| 31 |
| 32 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { |
| 33 BrowserContext::AsyncObliterateStoragePartition( |
| 34 profile, |
| 35 profile->GetExtensionService()->GetSiteForExtensionId(extension->id()), |
| 36 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage, |
| 37 profile->GetExtensionService()->AsWeakPtr())); |
| 38 } else { |
| 39 GURL launch_web_url_origin( |
| 40 extensions::AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin()); |
| 41 |
| 42 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 43 profile, |
| 44 Extension::GetBaseURLFromExtensionId(extension->id())); |
| 45 |
| 46 if (extension->is_hosted_app() && |
| 47 !profile->GetExtensionSpecialStoragePolicy()-> |
| 48 IsStorageProtected(launch_web_url_origin)) { |
| 49 DeleteOrigin(profile, partition, launch_web_url_origin); |
| 50 } |
| 51 DeleteOrigin(profile, partition, extension->url()); |
| 52 } |
| 53 |
| 54 // Begin removal of the settings for the current extension. |
| 55 profile->GetExtensionService()->settings_frontend()-> |
| 56 DeleteStorageSoon(extension->id()); |
| 57 } |
| 58 |
| 59 // static |
| 60 void DataDeleter::DeleteOrigin(Profile* profile, |
| 61 StoragePartition* partition, |
| 62 const GURL& origin) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 28 DCHECK(profile); | 64 DCHECK(profile); |
| 65 DCHECK(partition); |
| 29 | 66 |
| 30 const GURL& site = Extension::GetBaseURLFromExtensionId(extension_id); | 67 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 31 | |
| 32 StoragePartition* partition = | |
| 33 BrowserContext::GetStoragePartitionForSite(profile, site); | |
| 34 | |
| 35 if (storage_origin.SchemeIs(extensions::kExtensionScheme)) { | |
| 36 // TODO(ajwong): Cookies are not properly isolated for | 68 // TODO(ajwong): Cookies are not properly isolated for |
| 37 // chrome-extension:// scheme. (http://crbug.com/158386). | 69 // chrome-extension:// scheme. (http://crbug.com/158386). |
| 38 // | 70 // |
| 39 // However, no isolated apps actually can write to kExtensionScheme | 71 // However, no isolated apps actually can write to kExtensionScheme |
| 40 // origins. Thus, it is benign to delete from the | 72 // origins. Thus, it is benign to delete from the |
| 41 // RequestContextForExtensions because there's nothing stored there. We | 73 // RequestContextForExtensions because there's nothing stored there. We |
| 42 // preserve this code path without checking for isolation because it's | 74 // preserve this code path without checking for isolation because it's |
| 43 // simpler than special casing. This code should go away once we merge | 75 // simpler than special casing. This code should go away once we merge |
| 44 // the various URLRequestContexts (http://crbug.com/159193). | 76 // the various URLRequestContexts (http://crbug.com/159193). |
| 45 partition->ClearDataForOrigin( | 77 partition->ClearDataForOrigin( |
| 46 StoragePartition::REMOVE_DATA_MASK_ALL & | 78 StoragePartition::REMOVE_DATA_MASK_ALL & |
| 47 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), | 79 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), |
| 48 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 80 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 49 storage_origin, | 81 origin, |
| 50 profile->GetRequestContextForExtensions()); | 82 profile->GetRequestContextForExtensions()); |
| 51 } else { | 83 } else { |
| 52 // We don't need to worry about the media request context because that | 84 // We don't need to worry about the media request context because that |
| 53 // shares the same cookie store as the main request context. | 85 // shares the same cookie store as the main request context. |
| 54 partition->ClearDataForOrigin( | 86 partition->ClearDataForOrigin( |
| 55 StoragePartition::REMOVE_DATA_MASK_ALL & | 87 StoragePartition::REMOVE_DATA_MASK_ALL & |
| 56 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), | 88 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), |
| 57 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 89 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 58 storage_origin, | 90 origin, |
| 59 partition->GetURLRequestContext()); | 91 partition->GetURLRequestContext()); |
| 60 } | 92 } |
| 61 | |
| 62 // Begin removal of the settings for the current extension. | |
| 63 profile->GetExtensionService()->settings_frontend()-> | |
| 64 DeleteStorageSoon(extension_id); | |
| 65 } | 93 } |
| 66 | 94 |
| 67 } // namespace extensions | 95 } // namespace extensions |
| OLD | NEW |