blob: c3eac660e5a3cc8533da87b82b5d45ca07d3406d [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]aa84a7e2012-03-15 21:29:069#include "chrome/browser/profiles/profile.h"
[email protected]d656595b2014-01-09 14:09:3510#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
11#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]b7e33ee2014-03-15 05:27:5316#include "extensions/browser/api/storage/storage_frontend.h"
[email protected]7c82539c2014-02-19 06:09:1717#include "extensions/browser/extension_prefs.h"
[email protected]885c0e92012-11-13 20:27:4218#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4119#include "extensions/common/extension.h"
[email protected]abe2c032011-03-31 18:49:3420#include "net/url_request/url_request_context_getter.h"
[email protected]c10da4b02010-03-25 14:38:3221
[email protected]d656595b2014-01-09 14:09:3522using base::WeakPtr;
[email protected]55eb70e762012-02-20 17:38:3923using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:3924using content::BrowserThread;
[email protected]fdf3e13c2013-07-31 06:23:4625using content::StoragePartition;
[email protected]631bb742011-11-02 11:29:3926
[email protected]d656595b2014-01-09 14:09:3527namespace {
[email protected]d9ede582012-08-14 19:21:3828
[email protected]d656595b2014-01-09 14:09:3529// Helper function that deletes data of a given |storage_origin| in a given
30// |partition|.
31void DeleteOrigin(Profile* profile,
32 StoragePartition* partition,
33 const GURL& origin) {
[email protected]dc0b5a12011-10-14 00:06:1334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]c10da4b02010-03-25 14:38:3235 DCHECK(profile);
[email protected]d656595b2014-01-09 14:09:3536 DCHECK(partition);
[email protected]cc3d2912012-11-13 07:33:4137
[email protected]d656595b2014-01-09 14:09:3538 if (origin.SchemeIs(extensions::kExtensionScheme)) {
[email protected]33ad6ce92013-08-27 14:39:0839 // 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]d656595b2014-01-09 14:09:3552 origin,
[email protected]33ad6ce92013-08-27 14:39:0853 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]d656595b2014-01-09 14:09:3561 origin,
[email protected]33ad6ce92013-08-27 14:39:0862 partition->GetURLRequestContext());
63 }
[email protected]d656595b2014-01-09 14:09:3564}
65
66void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
67 if (!es)
68 return;
[email protected]7c82539c2014-02-19 06:09:1769 extensions::ExtensionPrefs::Get(es->profile())
70 ->SetNeedsStorageGarbageCollection(true);
[email protected]d656595b2014-01-09 14:09:3571}
72
73} // namespace
74
75namespace extensions {
76
77// static
78void 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]dc0b5a12011-10-14 00:06:13103
[email protected]cc3d2912012-11-13 07:33:41104 // Begin removal of the settings for the current extension.
[email protected]b7e33ee2014-03-15 05:27:53105 // StorageFrontend may not exist in unit tests.
106 StorageFrontend* frontend = StorageFrontend::Get(profile);
[email protected]88e55d32014-02-27 21:52:24107 if (frontend)
108 frontend->DeleteStorageSoon(extension->id());
[email protected]dc0b5a12011-10-14 00:06:13109}
[email protected]5ef99bd92012-11-14 05:00:11110
[email protected]d9ede582012-08-14 19:21:38111} // namespace extensions