Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cache_storage/cache_storage_dispatcher_host.h" | 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "content/browser/bad_message.h" | 16 #include "content/browser/bad_message.h" |
| 17 #include "content/browser/cache_storage/cache_storage_cache.h" | 17 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 18 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 18 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
| 19 #include "content/browser/cache_storage/cache_storage_manager.h" | 19 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 20 #include "content/common/cache_storage/cache_storage_messages.h" | 20 #include "content/common/cache_storage/cache_storage_messages.h" |
| 21 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 22 #include "content/public/common/origin_util.h" | 22 #include "content/public/common/origin_util.h" |
| 23 #include "storage/browser/blob/blob_data_handle.h" | 23 #include "storage/browser/blob/blob_data_handle.h" |
| 24 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerCacheError.h" | 24 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerCacheError.h" |
| 25 #include "url/gurl.h" | |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; | 31 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; |
| 31 | 32 |
| 32 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 33 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
| 33 CacheStorageError err) { | 34 CacheStorageError err) { |
| 34 switch (err) { | 35 switch (err) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 45 return blink::WebServiceWorkerCacheErrorNotFound; | 46 return blink::WebServiceWorkerCacheErrorNotFound; |
| 46 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: | 47 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: |
| 47 return blink::WebServiceWorkerCacheErrorQuotaExceeded; | 48 return blink::WebServiceWorkerCacheErrorQuotaExceeded; |
| 48 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: | 49 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: |
| 49 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; | 50 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; |
| 50 } | 51 } |
| 51 NOTREACHED(); | 52 NOTREACHED(); |
| 52 return blink::WebServiceWorkerCacheErrorNotImplemented; | 53 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool OriginCanAccessCacheStorage(const GURL& url) { | 56 bool OriginCanAccessCacheStorage(const url::Origin& origin) { |
| 56 return IsOriginSecure(url); | 57 return IsOriginSecure(GURL(origin.Serialize())); |
|
Mike West
2016/03/24 14:29:23
Hrm. We should make this take an origin at some po
jsbell
2016/03/24 16:31:57
Yep. I'll tackle that in an upcoming CL.
| |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 61 CacheStorageDispatcherHost::CacheStorageDispatcherHost() | 62 CacheStorageDispatcherHost::CacheStorageDispatcherHost() |
| 62 : BrowserMessageFilter(kFilteredMessageClasses, | 63 : BrowserMessageFilter(kFilteredMessageClasses, |
| 63 arraysize(kFilteredMessageClasses)) { | 64 arraysize(kFilteredMessageClasses)) { |
| 64 } | 65 } |
| 65 | 66 |
| 66 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { | 67 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 108 |
| 108 void CacheStorageDispatcherHost::CreateCacheListener( | 109 void CacheStorageDispatcherHost::CreateCacheListener( |
| 109 CacheStorageContextImpl* context) { | 110 CacheStorageContextImpl* context) { |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 111 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 111 context_ = context; | 112 context_ = context; |
| 112 } | 113 } |
| 113 | 114 |
| 114 void CacheStorageDispatcherHost::OnCacheStorageHas( | 115 void CacheStorageDispatcherHost::OnCacheStorageHas( |
| 115 int thread_id, | 116 int thread_id, |
| 116 int request_id, | 117 int request_id, |
| 117 const GURL& origin, | 118 const url::Origin& origin, |
| 118 const base::string16& cache_name) { | 119 const base::string16& cache_name) { |
| 119 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); | 120 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); |
| 120 if (!OriginCanAccessCacheStorage(origin)) { | 121 if (!OriginCanAccessCacheStorage(origin)) { |
| 121 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 122 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 122 return; | 123 return; |
| 123 } | 124 } |
| 124 context_->cache_manager()->HasCache( | 125 context_->cache_manager()->HasCache( |
| 125 origin, base::UTF16ToUTF8(cache_name), | 126 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 126 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, | 127 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, |
| 127 thread_id, request_id)); | 128 thread_id, request_id)); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void CacheStorageDispatcherHost::OnCacheStorageOpen( | 131 void CacheStorageDispatcherHost::OnCacheStorageOpen( |
| 131 int thread_id, | 132 int thread_id, |
| 132 int request_id, | 133 int request_id, |
| 133 const GURL& origin, | 134 const url::Origin& origin, |
| 134 const base::string16& cache_name) { | 135 const base::string16& cache_name) { |
| 135 TRACE_EVENT0("CacheStorage", | 136 TRACE_EVENT0("CacheStorage", |
| 136 "CacheStorageDispatcherHost::OnCacheStorageOpen"); | 137 "CacheStorageDispatcherHost::OnCacheStorageOpen"); |
| 137 if (!OriginCanAccessCacheStorage(origin)) { | 138 if (!OriginCanAccessCacheStorage(origin)) { |
| 138 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 139 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 139 return; | 140 return; |
| 140 } | 141 } |
| 141 context_->cache_manager()->OpenCache( | 142 context_->cache_manager()->OpenCache( |
| 142 origin, base::UTF16ToUTF8(cache_name), | 143 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 143 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, | 144 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, |
| 144 thread_id, request_id)); | 145 thread_id, request_id)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void CacheStorageDispatcherHost::OnCacheStorageDelete( | 148 void CacheStorageDispatcherHost::OnCacheStorageDelete( |
| 148 int thread_id, | 149 int thread_id, |
| 149 int request_id, | 150 int request_id, |
| 150 const GURL& origin, | 151 const url::Origin& origin, |
| 151 const base::string16& cache_name) { | 152 const base::string16& cache_name) { |
| 152 TRACE_EVENT0("CacheStorage", | 153 TRACE_EVENT0("CacheStorage", |
| 153 "CacheStorageDispatcherHost::OnCacheStorageDelete"); | 154 "CacheStorageDispatcherHost::OnCacheStorageDelete"); |
| 154 if (!OriginCanAccessCacheStorage(origin)) { | 155 if (!OriginCanAccessCacheStorage(origin)) { |
| 155 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 156 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 156 return; | 157 return; |
| 157 } | 158 } |
| 158 context_->cache_manager()->DeleteCache( | 159 context_->cache_manager()->DeleteCache( |
| 159 origin, base::UTF16ToUTF8(cache_name), | 160 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 160 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, | 161 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, |
| 161 this, thread_id, request_id)); | 162 this, thread_id, request_id)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, | 165 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, |
| 165 int request_id, | 166 int request_id, |
| 166 const GURL& origin) { | 167 const url::Origin& origin) { |
| 167 TRACE_EVENT0("CacheStorage", | 168 TRACE_EVENT0("CacheStorage", |
| 168 "CacheStorageDispatcherHost::OnCacheStorageKeys"); | 169 "CacheStorageDispatcherHost::OnCacheStorageKeys"); |
| 169 if (!OriginCanAccessCacheStorage(origin)) { | 170 if (!OriginCanAccessCacheStorage(origin)) { |
| 170 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 171 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 context_->cache_manager()->EnumerateCaches( | 174 context_->cache_manager()->EnumerateCaches( |
| 174 origin, | 175 GURL(origin.Serialize()), |
| 175 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, | 176 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, |
| 176 thread_id, request_id)); | 177 thread_id, request_id)); |
| 177 } | 178 } |
| 178 | 179 |
| 179 void CacheStorageDispatcherHost::OnCacheStorageMatch( | 180 void CacheStorageDispatcherHost::OnCacheStorageMatch( |
| 180 int thread_id, | 181 int thread_id, |
| 181 int request_id, | 182 int request_id, |
| 182 const GURL& origin, | 183 const url::Origin& origin, |
| 183 const ServiceWorkerFetchRequest& request, | 184 const ServiceWorkerFetchRequest& request, |
| 184 const CacheStorageCacheQueryParams& match_params) { | 185 const CacheStorageCacheQueryParams& match_params) { |
| 185 TRACE_EVENT0("CacheStorage", | 186 TRACE_EVENT0("CacheStorage", |
| 186 "CacheStorageDispatcherHost::OnCacheStorageMatch"); | 187 "CacheStorageDispatcherHost::OnCacheStorageMatch"); |
| 187 if (!OriginCanAccessCacheStorage(origin)) { | 188 if (!OriginCanAccessCacheStorage(origin)) { |
| 188 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 189 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 189 return; | 190 return; |
| 190 } | 191 } |
| 191 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 192 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 192 new ServiceWorkerFetchRequest(request.url, request.method, | 193 new ServiceWorkerFetchRequest(request.url, request.method, |
| 193 request.headers, request.referrer, | 194 request.headers, request.referrer, |
| 194 request.is_reload)); | 195 request.is_reload)); |
| 195 | 196 |
| 196 if (match_params.cache_name.empty()) { | 197 if (match_params.cache_name.empty()) { |
| 197 context_->cache_manager()->MatchAllCaches( | 198 context_->cache_manager()->MatchAllCaches( |
| 198 origin, std::move(scoped_request), | 199 GURL(origin.Serialize()), std::move(scoped_request), |
| 199 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, | 200 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, |
| 200 this, thread_id, request_id)); | 201 this, thread_id, request_id)); |
| 201 return; | 202 return; |
| 202 } | 203 } |
| 203 context_->cache_manager()->MatchCache( | 204 context_->cache_manager()->MatchCache( |
| 204 origin, base::UTF16ToUTF8(match_params.cache_name), | 205 GURL(origin.Serialize()), base::UTF16ToUTF8(match_params.cache_name), |
| 205 std::move(scoped_request), | 206 std::move(scoped_request), |
| 206 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, | 207 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, |
| 207 thread_id, request_id)); | 208 thread_id, request_id)); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void CacheStorageDispatcherHost::OnCacheMatch( | 211 void CacheStorageDispatcherHost::OnCacheMatch( |
| 211 int thread_id, | 212 int thread_id, |
| 212 int request_id, | 213 int request_id, |
| 213 int cache_id, | 214 int cache_id, |
| 214 const ServiceWorkerFetchRequest& request, | 215 const ServiceWorkerFetchRequest& request, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 520 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 520 if (it == blob_handle_store_.end()) | 521 if (it == blob_handle_store_.end()) |
| 521 return; | 522 return; |
| 522 DCHECK(!it->second.empty()); | 523 DCHECK(!it->second.empty()); |
| 523 it->second.pop_front(); | 524 it->second.pop_front(); |
| 524 if (it->second.empty()) | 525 if (it->second.empty()) |
| 525 blob_handle_store_.erase(it); | 526 blob_handle_store_.erase(it); |
| 526 } | 527 } |
| 527 | 528 |
| 528 } // namespace content | 529 } // namespace content |
| OLD | NEW |