blob: 4ee5211b28a5520096fde39fd615f6325c8ecee5 [file] [log] [blame]
[email protected]aa84a7e2012-03-15 21:29:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c10da4b02010-03-25 14:38:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d9ede582012-08-14 19:21:385#include "chrome/browser/extensions/data_deleter.h"
[email protected]c10da4b02010-03-25 14:38:326
Sebastien Marchandf1349f52019-01-25 03:16:417#include "base/bind.h"
Randy Smith9512b33d2017-12-12 19:57:558#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_refptr.h"
Eric Seckler8652dcd52018-09-20 10:42:2810#include "base/task/post_task.h"
Randy Smith9512b33d2017-12-12 19:57:5511#include "base/task_runner.h"
Maks Orlovich710d5e32019-07-09 20:16:4512#include "chrome/browser/extensions/chrome_extension_cookies.h"
[email protected]dc0b5a12011-10-14 00:06:1313#include "chrome/browser/extensions/extension_service.h"
[email protected]d656595b2014-01-09 14:09:3514#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]aa84a7e2012-03-15 21:29:0615#include "chrome/browser/profiles/profile.h"
Reilly Grant78e17e32018-09-28 14:35:3516#include "chrome/browser/profiles/profile_io_data.h"
[email protected]d656595b2014-01-09 14:09:3517#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]cc3d2912012-11-13 07:33:4118#include "content/public/browser/browser_context.h"
Eric Seckler8652dcd52018-09-20 10:42:2819#include "content/public/browser/browser_task_traits.h"
[email protected]cc3d2912012-11-13 07:33:4120#include "content/public/browser/browser_thread.h"
[email protected]d656595b2014-01-09 14:09:3521#include "content/public/browser/site_instance.h"
[email protected]4c3a23582012-08-18 08:54:3422#include "content/public/browser/storage_partition.h"
[email protected]13e062e2014-08-09 10:21:5523#include "extensions/browser/api/storage/storage_frontend.h"
[email protected]7c82539c2014-02-19 06:09:1724#include "extensions/browser/extension_prefs.h"
[email protected]3a746ec2014-03-15 05:30:5625#include "extensions/browser/extension_system.h"
Michael Giuffrida7efeed142017-06-07 06:29:2126#include "extensions/browser/extension_util.h"
[email protected]885c0e92012-11-13 20:27:4227#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4128#include "extensions/common/extension.h"
tfarina0bcdf362015-06-29 22:19:2629#include "extensions/common/manifest_handlers/app_isolation_info.h"
Randy Smith9512b33d2017-12-12 19:57:5530#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3431#include "net/url_request/url_request_context_getter.h"
[email protected]c10da4b02010-03-25 14:38:3232
[email protected]d656595b2014-01-09 14:09:3533using base::WeakPtr;
[email protected]55eb70e762012-02-20 17:38:3934using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3935using content::BrowserThread;
[email protected]fdf3e13c2013-07-31 06:23:4636using content::StoragePartition;
[email protected]631bb742011-11-02 11:29:3937
[email protected]3a746ec2014-03-15 05:30:5638namespace extensions {
39
[email protected]d656595b2014-01-09 14:09:3540namespace {
[email protected]d9ede582012-08-14 19:21:3841
[email protected]d656595b2014-01-09 14:09:3542// Helper function that deletes data of a given |storage_origin| in a given
43// |partition|.
44void DeleteOrigin(Profile* profile,
45 StoragePartition* partition,
Devlin Cronina68c2a852017-11-29 19:11:2646 const GURL& origin) {
[email protected]54ee8192014-03-29 17:37:2447 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]c10da4b02010-03-25 14:38:3248 DCHECK(profile);
[email protected]d656595b2014-01-09 14:09:3549 DCHECK(partition);
[email protected]cc3d2912012-11-13 07:33:4150
[email protected]3a746ec2014-03-15 05:30:5651 if (origin.SchemeIs(kExtensionScheme)) {
[email protected]33ad6ce92013-08-27 14:39:0852 // 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 Smith9512b33d2017-12-12 19:57:5561
[email protected]33ad6ce92013-08-27 14:39:0862 partition->ClearDataForOrigin(
[email protected]93ea1882014-07-10 20:30:1263 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
Randy Smith9512b33d2017-12-12 19:57:5564 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 Orlovich710d5e32019-07-09 20:16:4568 extensions::ChromeExtensionCookies::Get(profile)->ClearCookies(origin);
[email protected]33ad6ce92013-08-27 14:39:0869 } 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]93ea1882014-07-10 20:30:1273 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
Randy Smith9512b33d2017-12-12 19:57:5574 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, origin);
[email protected]33ad6ce92013-08-27 14:39:0875 }
[email protected]d656595b2014-01-09 14:09:3576}
77
Devlin Cronina68c2a852017-11-29 19:11:2678void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
[email protected]42d58f62014-07-31 01:32:4579 if (es)
80 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
[email protected]d656595b2014-01-09 14:09:3581}
82
[email protected]fc103da2014-08-16 01:09:3283} // namespace
[email protected]d656595b2014-01-09 14:09:3584
[email protected]d656595b2014-01-09 14:09:3585// static
Devlin Cronina68c2a852017-11-29 19:11:2686void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) {
[email protected]d656595b2014-01-09 14:09:3587 DCHECK(profile);
88 DCHECK(extension);
89
[email protected]3a746ec2014-03-15 05:30:5690 if (AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]d656595b2014-01-09 14:09:3591 BrowserContext::AsyncObliterateStoragePartition(
Devlin Cronina68c2a852017-11-29 19:11:2692 profile, util::GetSiteForExtensionId(extension->id(), profile),
[email protected]3a746ec2014-03-15 05:30:5693 base::Bind(
94 &OnNeedsToGarbageCollectIsolatedStorage,
Devlin Cronina68c2a852017-11-29 19:11:2695 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr()));
[email protected]d656595b2014-01-09 14:09:3596 } else {
97 GURL launch_web_url_origin(
[email protected]3a746ec2014-03-15 05:30:5698 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
[email protected]d656595b2014-01-09 14:09:3599
100 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
101 profile,
102 Extension::GetBaseURLFromExtensionId(extension->id()));
103
xiyuanbaf3044e2015-05-13 03:17:22104 ExtensionSpecialStoragePolicy* storage_policy =
105 profile->GetExtensionSpecialStoragePolicy();
106 if (storage_policy->NeedsProtection(extension) &&
107 !storage_policy->IsStorageProtected(launch_web_url_origin)) {
Devlin Cronina68c2a852017-11-29 19:11:26108 DeleteOrigin(profile, partition, launch_web_url_origin);
[email protected]d656595b2014-01-09 14:09:35109 }
Devlin Cronina68c2a852017-11-29 19:11:26110 DeleteOrigin(profile, partition, extension->url());
[email protected]d656595b2014-01-09 14:09:35111 }
[email protected]dc0b5a12011-10-14 00:06:13112
[email protected]cc3d2912012-11-13 07:33:41113 // Begin removal of the settings for the current extension.
[email protected]b7e33ee2014-03-15 05:27:53114 // StorageFrontend may not exist in unit tests.
115 StorageFrontend* frontend = StorageFrontend::Get(profile);
[email protected]88e55d32014-02-27 21:52:24116 if (frontend)
117 frontend->DeleteStorageSoon(extension->id());
[email protected]dc0b5a12011-10-14 00:06:13118}
[email protected]5ef99bd92012-11-14 05:00:11119
[email protected]d9ede582012-08-14 19:21:38120} // namespace extensions