| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/devtools/protocol/storage_handler.h" |
| 6 |
| 7 #include <string> |
| 8 #include <unordered_set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/strings/string_split.h" |
| 12 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" |
| 13 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/storage_partition.h" |
| 16 |
| 17 namespace content { |
| 18 namespace devtools { |
| 19 namespace storage { |
| 20 |
| 21 namespace { |
| 22 static const char kAppCache[] = "appcache"; |
| 23 static const char kCookies[] = "cookies"; |
| 24 static const char kFileSystems[] = "filesystems"; |
| 25 static const char kIndexedDB[] = "indexeddb"; |
| 26 static const char kLocalStorage[] = "local_storage"; |
| 27 static const char kShaderCache[] = "shader_cache"; |
| 28 static const char kWebSQL[] = "websql"; |
| 29 static const char kWebRTCIdentity[] = "webrdc_identity"; |
| 30 static const char kServiceWorkers[] = "service_workers"; |
| 31 static const char kCacheStorage[] = "cache_storage"; |
| 32 static const char kAll[] = "all"; |
| 33 } |
| 34 |
| 35 typedef DevToolsProtocolClient::Response Response; |
| 36 |
| 37 StorageHandler::StorageHandler() |
| 38 : host_(nullptr) { |
| 39 } |
| 40 |
| 41 StorageHandler::~StorageHandler() = default; |
| 42 |
| 43 void StorageHandler::SetRenderFrameHost(RenderFrameHost* host) { |
| 44 host_ = host; |
| 45 } |
| 46 |
| 47 Response StorageHandler::ClearDataForOrigin( |
| 48 const std::string& origin, |
| 49 const std::string& storage_types) { |
| 50 if (!host_) |
| 51 return Response::InternalError("Not connected to host"); |
| 52 |
| 53 StoragePartition* partition = host_->GetProcess()->GetStoragePartition(); |
| 54 std::vector<std::string> types = base::SplitString( |
| 55 storage_types, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 56 std::unordered_set<std::string> set(types.begin(), types.end()); |
| 57 uint32_t remove_mask = 0; |
| 58 if (set.count(kAppCache)) |
| 59 remove_mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
| 60 if (set.count(kCookies)) |
| 61 remove_mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| 62 if (set.count(kFileSystems)) |
| 63 remove_mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
| 64 if (set.count(kIndexedDB)) |
| 65 remove_mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
| 66 if (set.count(kLocalStorage)) |
| 67 remove_mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
| 68 if (set.count(kShaderCache)) |
| 69 remove_mask |= StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; |
| 70 if (set.count(kWebSQL)) |
| 71 remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
| 72 if (set.count(kWebRTCIdentity)) |
| 73 remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY; |
| 74 if (set.count(kServiceWorkers)) |
| 75 remove_mask |= StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; |
| 76 if (set.count(kCacheStorage)) |
| 77 remove_mask |= StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; |
| 78 if (set.count(kAll)) |
| 79 remove_mask |= StoragePartition::REMOVE_DATA_MASK_ALL; |
| 80 |
| 81 if (!remove_mask) |
| 82 return Response::InvalidParams("No valid storage type specified"); |
| 83 |
| 84 partition->ClearDataForOrigin( |
| 85 remove_mask, |
| 86 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 87 GURL(origin), |
| 88 partition->GetURLRequestContext(), |
| 89 base::Bind(&base::DoNothing)); |
| 90 return Response::OK(); |
| 91 } |
| 92 |
| 93 } // namespace storage |
| 94 } // namespace devtools |
| 95 } // namespace content |
| OLD | NEW |