[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 5 | #include "chrome/browser/extensions/data_deleter.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 6 | |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 7 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 11 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | cc3d291 | 2012-11-13 07:33:41 | [diff] [blame] | 12 | #include "content/public/browser/browser_context.h" |
| 13 | #include "content/public/browser/browser_thread.h" |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 14 | #include "content/public/browser/site_instance.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 15 | #include "content/public/browser/storage_partition.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 16 | #include "extensions/browser/api/storage/storage_frontend.h" |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 17 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 18 | #include "extensions/browser/extension_system.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 19 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 20 | #include "extensions/common/extension.h" |
tfarina | 0bcdf36 | 2015-06-29 22:19:26 | [diff] [blame^] | 21 | #include "extensions/common/manifest_handlers/app_isolation_info.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 22 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 23 | |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 24 | using base::WeakPtr; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 25 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 26 | using content::BrowserThread; |
[email protected] | fdf3e13c | 2013-07-31 06:23:46 | [diff] [blame] | 27 | using content::StoragePartition; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 28 | |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 29 | namespace extensions { |
| 30 | |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 31 | namespace { |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 32 | |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 33 | // Helper function that deletes data of a given |storage_origin| in a given |
| 34 | // |partition|. |
| 35 | void DeleteOrigin(Profile* profile, |
| 36 | StoragePartition* partition, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 37 | const GURL& origin, |
| 38 | const base::Closure& callback) { |
[email protected] | 54ee819 | 2014-03-29 17:37:24 | [diff] [blame] | 39 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 40 | DCHECK(profile); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 41 | DCHECK(partition); |
[email protected] | cc3d291 | 2012-11-13 07:33:41 | [diff] [blame] | 42 | |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 43 | if (origin.SchemeIs(kExtensionScheme)) { |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 44 | // TODO(ajwong): Cookies are not properly isolated for |
| 45 | // chrome-extension:// scheme. (http://crbug.com/158386). |
| 46 | // |
| 47 | // However, no isolated apps actually can write to kExtensionScheme |
| 48 | // origins. Thus, it is benign to delete from the |
| 49 | // RequestContextForExtensions because there's nothing stored there. We |
| 50 | // preserve this code path without checking for isolation because it's |
| 51 | // simpler than special casing. This code should go away once we merge |
| 52 | // the various URLRequestContexts (http://crbug.com/159193). |
| 53 | partition->ClearDataForOrigin( |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 54 | ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 55 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 56 | origin, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 57 | profile->GetRequestContextForExtensions(), |
| 58 | callback); |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 59 | } else { |
| 60 | // We don't need to worry about the media request context because that |
| 61 | // shares the same cookie store as the main request context. |
| 62 | partition->ClearDataForOrigin( |
[email protected] | 93ea188 | 2014-07-10 20:30:12 | [diff] [blame] | 63 | ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 64 | StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 65 | origin, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 66 | partition->GetURLRequestContext(), |
| 67 | callback); |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 68 | } |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 71 | void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es, |
| 72 | const base::Closure& callback) { |
| 73 | if (es) |
| 74 | ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true); |
| 75 | callback.Run(); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | fc103da | 2014-08-16 01:09:32 | [diff] [blame] | 78 | } // namespace |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 79 | |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 80 | // static |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 81 | void DataDeleter::StartDeleting(Profile* profile, |
| 82 | const Extension* extension, |
| 83 | const base::Closure& callback) { |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 84 | DCHECK(profile); |
| 85 | DCHECK(extension); |
| 86 | |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 87 | if (AppIsolationInfo::HasIsolatedStorage(extension)) { |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 88 | BrowserContext::AsyncObliterateStoragePartition( |
| 89 | profile, |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 90 | util::GetSiteForExtensionId(extension->id(), profile), |
| 91 | base::Bind( |
| 92 | &OnNeedsToGarbageCollectIsolatedStorage, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 93 | ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr(), |
| 94 | callback)); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 95 | } else { |
| 96 | GURL launch_web_url_origin( |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 97 | AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin()); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 98 | |
| 99 | StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 100 | profile, |
| 101 | Extension::GetBaseURLFromExtensionId(extension->id())); |
| 102 | |
xiyuan | baf3044e | 2015-05-13 03:17:22 | [diff] [blame] | 103 | ExtensionSpecialStoragePolicy* storage_policy = |
| 104 | profile->GetExtensionSpecialStoragePolicy(); |
| 105 | if (storage_policy->NeedsProtection(extension) && |
| 106 | !storage_policy->IsStorageProtected(launch_web_url_origin)) { |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 107 | DeleteOrigin(profile, |
| 108 | partition, |
| 109 | launch_web_url_origin, |
| 110 | base::Bind(&base::DoNothing)); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 111 | } |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 112 | DeleteOrigin(profile, partition, extension->url(), callback); |
[email protected] | d656595b | 2014-01-09 14:09:35 | [diff] [blame] | 113 | } |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 114 | |
[email protected] | cc3d291 | 2012-11-13 07:33:41 | [diff] [blame] | 115 | // Begin removal of the settings for the current extension. |
[email protected] | b7e33ee | 2014-03-15 05:27:53 | [diff] [blame] | 116 | // StorageFrontend may not exist in unit tests. |
| 117 | StorageFrontend* frontend = StorageFrontend::Get(profile); |
[email protected] | 88e55d3 | 2014-02-27 21:52:24 | [diff] [blame] | 118 | if (frontend) |
| 119 | frontend->DeleteStorageSoon(extension->id()); |
[email protected] | dc0b5a1 | 2011-10-14 00:06:13 | [diff] [blame] | 120 | } |
[email protected] | 5ef99bd9 | 2012-11-14 05:00:11 | [diff] [blame] | 121 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 122 | } // namespace extensions |