blob: 158afb2483a75c38988b0b702c405d89c41a01b8 [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
[email protected]dc0b5a12011-10-14 00:06:137#include "chrome/browser/extensions/extension_service.h"
[email protected]d656595b2014-01-09 14:09:358#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]3a746ec2014-03-15 05:30:569#include "chrome/browser/extensions/extension_util.h"
[email protected]aa84a7e2012-03-15 21:29:0610#include "chrome/browser/profiles/profile.h"
[email protected]d656595b2014-01-09 14:09:3511#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]cc3d2912012-11-13 07:33:4112#include "content/public/browser/browser_context.h"
13#include "content/public/browser/browser_thread.h"
[email protected]d656595b2014-01-09 14:09:3514#include "content/public/browser/site_instance.h"
[email protected]4c3a23582012-08-18 08:54:3415#include "content/public/browser/storage_partition.h"
[email protected]13e062e2014-08-09 10:21:5516#include "extensions/browser/api/storage/storage_frontend.h"
[email protected]7c82539c2014-02-19 06:09:1717#include "extensions/browser/extension_prefs.h"
[email protected]3a746ec2014-03-15 05:30:5618#include "extensions/browser/extension_system.h"
[email protected]885c0e92012-11-13 20:27:4219#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4120#include "extensions/common/extension.h"
tfarina0bcdf362015-06-29 22:19:2621#include "extensions/common/manifest_handlers/app_isolation_info.h"
[email protected]abe2c032011-03-31 18:49:3422#include "net/url_request/url_request_context_getter.h"
[email protected]c10da4b02010-03-25 14:38:3223
[email protected]d656595b2014-01-09 14:09:3524using base::WeakPtr;
[email protected]55eb70e762012-02-20 17:38:3925using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3926using content::BrowserThread;
[email protected]fdf3e13c2013-07-31 06:23:4627using content::StoragePartition;
[email protected]631bb742011-11-02 11:29:3928
[email protected]3a746ec2014-03-15 05:30:5629namespace extensions {
30
[email protected]d656595b2014-01-09 14:09:3531namespace {
[email protected]d9ede582012-08-14 19:21:3832
[email protected]d656595b2014-01-09 14:09:3533// Helper function that deletes data of a given |storage_origin| in a given
34// |partition|.
35void DeleteOrigin(Profile* profile,
36 StoragePartition* partition,
[email protected]42d58f62014-07-31 01:32:4537 const GURL& origin,
38 const base::Closure& callback) {
[email protected]54ee8192014-03-29 17:37:2439 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]c10da4b02010-03-25 14:38:3240 DCHECK(profile);
[email protected]d656595b2014-01-09 14:09:3541 DCHECK(partition);
[email protected]cc3d2912012-11-13 07:33:4142
[email protected]3a746ec2014-03-15 05:30:5643 if (origin.SchemeIs(kExtensionScheme)) {
[email protected]33ad6ce92013-08-27 14:39:0844 // 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]93ea1882014-07-10 20:30:1254 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
[email protected]33ad6ce92013-08-27 14:39:0855 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
[email protected]d656595b2014-01-09 14:09:3556 origin,
[email protected]42d58f62014-07-31 01:32:4557 profile->GetRequestContextForExtensions(),
58 callback);
[email protected]33ad6ce92013-08-27 14:39:0859 } 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]93ea1882014-07-10 20:30:1263 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
[email protected]33ad6ce92013-08-27 14:39:0864 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
[email protected]d656595b2014-01-09 14:09:3565 origin,
[email protected]42d58f62014-07-31 01:32:4566 partition->GetURLRequestContext(),
67 callback);
[email protected]33ad6ce92013-08-27 14:39:0868 }
[email protected]d656595b2014-01-09 14:09:3569}
70
[email protected]42d58f62014-07-31 01:32:4571void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es,
72 const base::Closure& callback) {
73 if (es)
74 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
75 callback.Run();
[email protected]d656595b2014-01-09 14:09:3576}
77
[email protected]fc103da2014-08-16 01:09:3278} // namespace
[email protected]d656595b2014-01-09 14:09:3579
[email protected]d656595b2014-01-09 14:09:3580// static
[email protected]42d58f62014-07-31 01:32:4581void DataDeleter::StartDeleting(Profile* profile,
82 const Extension* extension,
83 const base::Closure& callback) {
[email protected]d656595b2014-01-09 14:09:3584 DCHECK(profile);
85 DCHECK(extension);
86
[email protected]3a746ec2014-03-15 05:30:5687 if (AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]d656595b2014-01-09 14:09:3588 BrowserContext::AsyncObliterateStoragePartition(
89 profile,
[email protected]3a746ec2014-03-15 05:30:5690 util::GetSiteForExtensionId(extension->id(), profile),
91 base::Bind(
92 &OnNeedsToGarbageCollectIsolatedStorage,
[email protected]42d58f62014-07-31 01:32:4593 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr(),
94 callback));
[email protected]d656595b2014-01-09 14:09:3595 } else {
96 GURL launch_web_url_origin(
[email protected]3a746ec2014-03-15 05:30:5697 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
[email protected]d656595b2014-01-09 14:09:3598
99 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
100 profile,
101 Extension::GetBaseURLFromExtensionId(extension->id()));
102
xiyuanbaf3044e2015-05-13 03:17:22103 ExtensionSpecialStoragePolicy* storage_policy =
104 profile->GetExtensionSpecialStoragePolicy();
105 if (storage_policy->NeedsProtection(extension) &&
106 !storage_policy->IsStorageProtected(launch_web_url_origin)) {
[email protected]42d58f62014-07-31 01:32:45107 DeleteOrigin(profile,
108 partition,
109 launch_web_url_origin,
110 base::Bind(&base::DoNothing));
[email protected]d656595b2014-01-09 14:09:35111 }
[email protected]42d58f62014-07-31 01:32:45112 DeleteOrigin(profile, partition, extension->url(), callback);
[email protected]d656595b2014-01-09 14:09:35113 }
[email protected]dc0b5a12011-10-14 00:06:13114
[email protected]cc3d2912012-11-13 07:33:41115 // Begin removal of the settings for the current extension.
[email protected]b7e33ee2014-03-15 05:27:53116 // StorageFrontend may not exist in unit tests.
117 StorageFrontend* frontend = StorageFrontend::Get(profile);
[email protected]88e55d32014-02-27 21:52:24118 if (frontend)
119 frontend->DeleteStorageSoon(extension->id());
[email protected]dc0b5a12011-10-14 00:06:13120}
[email protected]5ef99bd92012-11-14 05:00:11121
[email protected]d9ede582012-08-14 19:21:38122} // namespace extensions