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