| 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" |
| 26 #include "url/origin.h" |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; | 32 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; |
| 31 | 33 |
| 32 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 34 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
| 33 CacheStorageError err) { | 35 CacheStorageError err) { |
| 34 switch (err) { | 36 switch (err) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 return blink::WebServiceWorkerCacheErrorNotFound; | 47 return blink::WebServiceWorkerCacheErrorNotFound; |
| 46 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: | 48 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: |
| 47 return blink::WebServiceWorkerCacheErrorQuotaExceeded; | 49 return blink::WebServiceWorkerCacheErrorQuotaExceeded; |
| 48 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: | 50 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: |
| 49 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; | 51 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; |
| 50 } | 52 } |
| 51 NOTREACHED(); | 53 NOTREACHED(); |
| 52 return blink::WebServiceWorkerCacheErrorNotImplemented; | 54 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 53 } | 55 } |
| 54 | 56 |
| 55 bool OriginCanAccessCacheStorage(const GURL& url) { | 57 bool OriginCanAccessCacheStorage(const url::Origin& origin) { |
| 56 return IsOriginSecure(url); | 58 return !origin.unique() && IsOriginSecure(GURL(origin.Serialize())); |
| 57 } | 59 } |
| 58 | 60 |
| 59 } // namespace | 61 } // namespace |
| 60 | 62 |
| 61 CacheStorageDispatcherHost::CacheStorageDispatcherHost() | 63 CacheStorageDispatcherHost::CacheStorageDispatcherHost() |
| 62 : BrowserMessageFilter(kFilteredMessageClasses, | 64 : BrowserMessageFilter(kFilteredMessageClasses, |
| 63 arraysize(kFilteredMessageClasses)) { | 65 arraysize(kFilteredMessageClasses)) { |
| 64 } | 66 } |
| 65 | 67 |
| 66 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { | 68 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 109 |
| 108 void CacheStorageDispatcherHost::CreateCacheListener( | 110 void CacheStorageDispatcherHost::CreateCacheListener( |
| 109 CacheStorageContextImpl* context) { | 111 CacheStorageContextImpl* context) { |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 111 context_ = context; | 113 context_ = context; |
| 112 } | 114 } |
| 113 | 115 |
| 114 void CacheStorageDispatcherHost::OnCacheStorageHas( | 116 void CacheStorageDispatcherHost::OnCacheStorageHas( |
| 115 int thread_id, | 117 int thread_id, |
| 116 int request_id, | 118 int request_id, |
| 117 const GURL& origin, | 119 const url::Origin& origin, |
| 118 const base::string16& cache_name) { | 120 const base::string16& cache_name) { |
| 119 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); | 121 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); |
| 120 if (!OriginCanAccessCacheStorage(origin)) { | 122 if (!OriginCanAccessCacheStorage(origin)) { |
| 121 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 123 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 122 return; | 124 return; |
| 123 } | 125 } |
| 124 context_->cache_manager()->HasCache( | 126 context_->cache_manager()->HasCache( |
| 125 origin, base::UTF16ToUTF8(cache_name), | 127 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 126 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, | 128 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, |
| 127 thread_id, request_id)); | 129 thread_id, request_id)); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void CacheStorageDispatcherHost::OnCacheStorageOpen( | 132 void CacheStorageDispatcherHost::OnCacheStorageOpen( |
| 131 int thread_id, | 133 int thread_id, |
| 132 int request_id, | 134 int request_id, |
| 133 const GURL& origin, | 135 const url::Origin& origin, |
| 134 const base::string16& cache_name) { | 136 const base::string16& cache_name) { |
| 135 TRACE_EVENT0("CacheStorage", | 137 TRACE_EVENT0("CacheStorage", |
| 136 "CacheStorageDispatcherHost::OnCacheStorageOpen"); | 138 "CacheStorageDispatcherHost::OnCacheStorageOpen"); |
| 137 if (!OriginCanAccessCacheStorage(origin)) { | 139 if (!OriginCanAccessCacheStorage(origin)) { |
| 138 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 140 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 139 return; | 141 return; |
| 140 } | 142 } |
| 141 context_->cache_manager()->OpenCache( | 143 context_->cache_manager()->OpenCache( |
| 142 origin, base::UTF16ToUTF8(cache_name), | 144 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 143 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, | 145 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, |
| 144 thread_id, request_id)); | 146 thread_id, request_id)); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void CacheStorageDispatcherHost::OnCacheStorageDelete( | 149 void CacheStorageDispatcherHost::OnCacheStorageDelete( |
| 148 int thread_id, | 150 int thread_id, |
| 149 int request_id, | 151 int request_id, |
| 150 const GURL& origin, | 152 const url::Origin& origin, |
| 151 const base::string16& cache_name) { | 153 const base::string16& cache_name) { |
| 152 TRACE_EVENT0("CacheStorage", | 154 TRACE_EVENT0("CacheStorage", |
| 153 "CacheStorageDispatcherHost::OnCacheStorageDelete"); | 155 "CacheStorageDispatcherHost::OnCacheStorageDelete"); |
| 154 if (!OriginCanAccessCacheStorage(origin)) { | 156 if (!OriginCanAccessCacheStorage(origin)) { |
| 155 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 157 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 156 return; | 158 return; |
| 157 } | 159 } |
| 158 context_->cache_manager()->DeleteCache( | 160 context_->cache_manager()->DeleteCache( |
| 159 origin, base::UTF16ToUTF8(cache_name), | 161 GURL(origin.Serialize()), base::UTF16ToUTF8(cache_name), |
| 160 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, | 162 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, |
| 161 this, thread_id, request_id)); | 163 this, thread_id, request_id)); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, | 166 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, |
| 165 int request_id, | 167 int request_id, |
| 166 const GURL& origin) { | 168 const url::Origin& origin) { |
| 167 TRACE_EVENT0("CacheStorage", | 169 TRACE_EVENT0("CacheStorage", |
| 168 "CacheStorageDispatcherHost::OnCacheStorageKeys"); | 170 "CacheStorageDispatcherHost::OnCacheStorageKeys"); |
| 169 if (!OriginCanAccessCacheStorage(origin)) { | 171 if (!OriginCanAccessCacheStorage(origin)) { |
| 170 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 172 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 171 return; | 173 return; |
| 172 } | 174 } |
| 173 context_->cache_manager()->EnumerateCaches( | 175 context_->cache_manager()->EnumerateCaches( |
| 174 origin, | 176 GURL(origin.Serialize()), |
| 175 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, | 177 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, |
| 176 thread_id, request_id)); | 178 thread_id, request_id)); |
| 177 } | 179 } |
| 178 | 180 |
| 179 void CacheStorageDispatcherHost::OnCacheStorageMatch( | 181 void CacheStorageDispatcherHost::OnCacheStorageMatch( |
| 180 int thread_id, | 182 int thread_id, |
| 181 int request_id, | 183 int request_id, |
| 182 const GURL& origin, | 184 const url::Origin& origin, |
| 183 const ServiceWorkerFetchRequest& request, | 185 const ServiceWorkerFetchRequest& request, |
| 184 const CacheStorageCacheQueryParams& match_params) { | 186 const CacheStorageCacheQueryParams& match_params) { |
| 185 TRACE_EVENT0("CacheStorage", | 187 TRACE_EVENT0("CacheStorage", |
| 186 "CacheStorageDispatcherHost::OnCacheStorageMatch"); | 188 "CacheStorageDispatcherHost::OnCacheStorageMatch"); |
| 187 if (!OriginCanAccessCacheStorage(origin)) { | 189 if (!OriginCanAccessCacheStorage(origin)) { |
| 188 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 190 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 189 return; | 191 return; |
| 190 } | 192 } |
| 191 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 193 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 192 new ServiceWorkerFetchRequest(request.url, request.method, | 194 new ServiceWorkerFetchRequest(request.url, request.method, |
| 193 request.headers, request.referrer, | 195 request.headers, request.referrer, |
| 194 request.is_reload)); | 196 request.is_reload)); |
| 195 | 197 |
| 196 if (match_params.cache_name.empty()) { | 198 if (match_params.cache_name.empty()) { |
| 197 context_->cache_manager()->MatchAllCaches( | 199 context_->cache_manager()->MatchAllCaches( |
| 198 origin, std::move(scoped_request), | 200 GURL(origin.Serialize()), std::move(scoped_request), |
| 199 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, | 201 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, |
| 200 this, thread_id, request_id)); | 202 this, thread_id, request_id)); |
| 201 return; | 203 return; |
| 202 } | 204 } |
| 203 context_->cache_manager()->MatchCache( | 205 context_->cache_manager()->MatchCache( |
| 204 origin, base::UTF16ToUTF8(match_params.cache_name), | 206 GURL(origin.Serialize()), base::UTF16ToUTF8(match_params.cache_name), |
| 205 std::move(scoped_request), | 207 std::move(scoped_request), |
| 206 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, | 208 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, |
| 207 thread_id, request_id)); | 209 thread_id, request_id)); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void CacheStorageDispatcherHost::OnCacheMatch( | 212 void CacheStorageDispatcherHost::OnCacheMatch( |
| 211 int thread_id, | 213 int thread_id, |
| 212 int request_id, | 214 int request_id, |
| 213 int cache_id, | 215 int cache_id, |
| 214 const ServiceWorkerFetchRequest& request, | 216 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); | 521 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 520 if (it == blob_handle_store_.end()) | 522 if (it == blob_handle_store_.end()) |
| 521 return; | 523 return; |
| 522 DCHECK(!it->second.empty()); | 524 DCHECK(!it->second.empty()); |
| 523 it->second.pop_front(); | 525 it->second.pop_front(); |
| 524 if (it->second.empty()) | 526 if (it->second.empty()) |
| 525 blob_handle_store_.erase(it); | 527 blob_handle_store_.erase(it); |
| 526 } | 528 } |
| 527 | 529 |
| 528 } // namespace content | 530 } // namespace content |
| OLD | NEW |