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