blob: b28e7b29711d73fd763fcd5175fc18b4cdc32e15 [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_isolation_info.h"
12#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]cc3d2912012-11-13 07:33:4113#include "content/public/browser/browser_context.h"
14#include "content/public/browser/browser_thread.h"
[email protected]d656595b2014-01-09 14:09:3515#include "content/public/browser/site_instance.h"
[email protected]4c3a23582012-08-18 08:54:3416#include "content/public/browser/storage_partition.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"
[email protected]abe2c032011-03-31 18:49:3421#include "net/url_request/url_request_context_getter.h"
[email protected]c10da4b02010-03-25 14:38:3222
[email protected]be514c32014-03-17 23:30:4423#if defined(ENABLE_EXTENSIONS)
24#include "extensions/browser/api/storage/storage_frontend.h"
25#endif
26
[email protected]d656595b2014-01-09 14:09:3527using base::WeakPtr;
[email protected]55eb70e762012-02-20 17:38:3928using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3929using content::BrowserThread;
[email protected]fdf3e13c2013-07-31 06:23:4630using content::StoragePartition;
[email protected]631bb742011-11-02 11:29:3931
[email protected]3a746ec2014-03-15 05:30:5632namespace extensions {
33
[email protected]d656595b2014-01-09 14:09:3534namespace {
[email protected]d9ede582012-08-14 19:21:3835
[email protected]d656595b2014-01-09 14:09:3536// Helper function that deletes data of a given |storage_origin| in a given
37// |partition|.
38void DeleteOrigin(Profile* profile,
39 StoragePartition* partition,
40 const GURL& origin) {
[email protected]54ee8192014-03-29 17:37:2441 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]c10da4b02010-03-25 14:38:3242 DCHECK(profile);
[email protected]d656595b2014-01-09 14:09:3543 DCHECK(partition);
[email protected]cc3d2912012-11-13 07:33:4144
[email protected]3a746ec2014-03-15 05:30:5645 if (origin.SchemeIs(kExtensionScheme)) {
[email protected]33ad6ce92013-08-27 14:39:0846 // 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]93ea1882014-07-10 20:30:1256 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
[email protected]33ad6ce92013-08-27 14:39:0857 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
[email protected]d656595b2014-01-09 14:09:3558 origin,
[email protected]33ad6ce92013-08-27 14:39:0859 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]93ea1882014-07-10 20:30:1264 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
[email protected]33ad6ce92013-08-27 14:39:0865 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
[email protected]d656595b2014-01-09 14:09:3566 origin,
[email protected]33ad6ce92013-08-27 14:39:0867 partition->GetURLRequestContext());
68 }
[email protected]d656595b2014-01-09 14:09:3569}
70
71void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
72 if (!es)
73 return;
[email protected]3a746ec2014-03-15 05:30:5674 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
[email protected]d656595b2014-01-09 14:09:3575}
76
77} // namespace
78
[email protected]d656595b2014-01-09 14:09:3579// static
80void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) {
81 DCHECK(profile);
82 DCHECK(extension);
83
[email protected]3a746ec2014-03-15 05:30:5684 if (AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]d656595b2014-01-09 14:09:3585 BrowserContext::AsyncObliterateStoragePartition(
86 profile,
[email protected]3a746ec2014-03-15 05:30:5687 util::GetSiteForExtensionId(extension->id(), profile),
88 base::Bind(
89 &OnNeedsToGarbageCollectIsolatedStorage,
90 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr()));
[email protected]d656595b2014-01-09 14:09:3591 } else {
92 GURL launch_web_url_origin(
[email protected]3a746ec2014-03-15 05:30:5693 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
[email protected]d656595b2014-01-09 14:09:3594
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]dc0b5a12011-10-14 00:06:13106
[email protected]be514c32014-03-17 23:30:44107#if defined(ENABLE_EXTENSIONS)
[email protected]cc3d2912012-11-13 07:33:41108 // Begin removal of the settings for the current extension.
[email protected]b7e33ee2014-03-15 05:27:53109 // StorageFrontend may not exist in unit tests.
110 StorageFrontend* frontend = StorageFrontend::Get(profile);
[email protected]88e55d32014-02-27 21:52:24111 if (frontend)
112 frontend->DeleteStorageSoon(extension->id());
[email protected]be514c32014-03-17 23:30:44113#endif // defined(ENABLE_EXTENSIONS)
[email protected]dc0b5a12011-10-14 00:06:13114}
[email protected]5ef99bd92012-11-14 05:00:11115
[email protected]d9ede582012-08-14 19:21:38116} // namespace extensions