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