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