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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 13 #include "content/browser/cache_storage/cache_storage_cache.h" | 13 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 14 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 14 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
| 15 #include "content/browser/cache_storage/cache_storage_manager.h" | 15 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 16 #include "content/common/cache_storage/cache_storage_messages.h" | 16 #include "content/common/cache_storage/cache_storage_messages.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/origin_util.h" | |
| 18 #include "storage/browser/blob/blob_data_handle.h" | 19 #include "storage/browser/blob/blob_data_handle.h" |
| 19 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" | 20 #include "third_party/WebKit/public/platform/WebServiceWorkerCacheError.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const uint32 kFilteredMessageClasses[] = {CacheStorageMsgStart}; | 26 const uint32 kFilteredMessageClasses[] = {CacheStorageMsgStart}; |
| 26 | 27 |
| 27 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 28 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
| 28 CacheStorageError err) { | 29 CacheStorageError err) { |
| 29 switch (err) { | 30 switch (err) { |
| 30 case CACHE_STORAGE_OK: | 31 case CACHE_STORAGE_OK: |
| 31 NOTREACHED(); | 32 NOTREACHED(); |
| 32 return blink::WebServiceWorkerCacheErrorNotImplemented; | 33 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 33 case CACHE_STORAGE_ERROR_EXISTS: | 34 case CACHE_STORAGE_ERROR_EXISTS: |
| 34 return blink::WebServiceWorkerCacheErrorExists; | 35 return blink::WebServiceWorkerCacheErrorExists; |
| 35 case CACHE_STORAGE_ERROR_STORAGE: | 36 case CACHE_STORAGE_ERROR_STORAGE: |
| 36 // TODO(nhiroki): Add WebServiceWorkerCacheError equivalent to | 37 // TODO(nhiroki): Add WebServiceWorkerCacheError equivalent to |
| 37 // CACHE_STORAGE_ERROR_STORAGE. | 38 // CACHE_STORAGE_ERROR_STORAGE. |
| 38 return blink::WebServiceWorkerCacheErrorNotFound; | 39 return blink::WebServiceWorkerCacheErrorNotFound; |
| 39 case CACHE_STORAGE_ERROR_NOT_FOUND: | 40 case CACHE_STORAGE_ERROR_NOT_FOUND: |
| 40 return blink::WebServiceWorkerCacheErrorNotFound; | 41 return blink::WebServiceWorkerCacheErrorNotFound; |
| 41 } | 42 } |
| 42 NOTREACHED(); | 43 NOTREACHED(); |
| 43 return blink::WebServiceWorkerCacheErrorNotImplemented; | 44 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 44 } | 45 } |
| 45 | 46 |
| 47 bool OriginCanAccessCacheStorage(const GURL& url) { | |
| 48 // TODO(jsbell): Further restrict to HTTPS, like Service Workers? | |
|
Mike West
2015/06/18 19:57:14
Aren't service workers available to any "secure co
jsbell
2015/06/18 20:00:04
Whoops, the TODO is incorrect. I mean to refer to
| |
| 49 return IsOriginSecure(url); | |
| 50 } | |
| 51 | |
| 46 } // namespace | 52 } // namespace |
| 47 | 53 |
| 48 CacheStorageDispatcherHost::CacheStorageDispatcherHost() | 54 CacheStorageDispatcherHost::CacheStorageDispatcherHost() |
| 49 : BrowserMessageFilter(kFilteredMessageClasses, | 55 : BrowserMessageFilter(kFilteredMessageClasses, |
| 50 arraysize(kFilteredMessageClasses)) { | 56 arraysize(kFilteredMessageClasses)) { |
| 51 } | 57 } |
| 52 | 58 |
| 53 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { | 59 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { |
| 54 } | 60 } |
| 55 | 61 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 98 context_ = context; | 104 context_ = context; |
| 99 } | 105 } |
| 100 | 106 |
| 101 void CacheStorageDispatcherHost::OnCacheStorageHas( | 107 void CacheStorageDispatcherHost::OnCacheStorageHas( |
| 102 int thread_id, | 108 int thread_id, |
| 103 int request_id, | 109 int request_id, |
| 104 const GURL& origin, | 110 const GURL& origin, |
| 105 const base::string16& cache_name) { | 111 const base::string16& cache_name) { |
| 106 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); | 112 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); |
| 113 if (!OriginCanAccessCacheStorage(origin)) { | |
| 114 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | |
| 115 return; | |
| 116 } | |
| 107 context_->cache_manager()->HasCache( | 117 context_->cache_manager()->HasCache( |
| 108 origin, base::UTF16ToUTF8(cache_name), | 118 origin, base::UTF16ToUTF8(cache_name), |
| 109 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, | 119 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, |
| 110 thread_id, request_id)); | 120 thread_id, request_id)); |
| 111 } | 121 } |
| 112 | 122 |
| 113 void CacheStorageDispatcherHost::OnCacheStorageOpen( | 123 void CacheStorageDispatcherHost::OnCacheStorageOpen( |
| 114 int thread_id, | 124 int thread_id, |
| 115 int request_id, | 125 int request_id, |
| 116 const GURL& origin, | 126 const GURL& origin, |
| 117 const base::string16& cache_name) { | 127 const base::string16& cache_name) { |
| 118 TRACE_EVENT0("CacheStorage", | 128 TRACE_EVENT0("CacheStorage", |
| 119 "CacheStorageDispatcherHost::OnCacheStorageOpen"); | 129 "CacheStorageDispatcherHost::OnCacheStorageOpen"); |
| 130 if (!OriginCanAccessCacheStorage(origin)) { | |
| 131 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | |
| 132 return; | |
| 133 } | |
| 120 context_->cache_manager()->OpenCache( | 134 context_->cache_manager()->OpenCache( |
| 121 origin, base::UTF16ToUTF8(cache_name), | 135 origin, base::UTF16ToUTF8(cache_name), |
| 122 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, | 136 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, |
| 123 thread_id, request_id)); | 137 thread_id, request_id)); |
| 124 } | 138 } |
| 125 | 139 |
| 126 void CacheStorageDispatcherHost::OnCacheStorageDelete( | 140 void CacheStorageDispatcherHost::OnCacheStorageDelete( |
| 127 int thread_id, | 141 int thread_id, |
| 128 int request_id, | 142 int request_id, |
| 129 const GURL& origin, | 143 const GURL& origin, |
| 130 const base::string16& cache_name) { | 144 const base::string16& cache_name) { |
| 131 TRACE_EVENT0("CacheStorage", | 145 TRACE_EVENT0("CacheStorage", |
| 132 "CacheStorageDispatcherHost::OnCacheStorageDelete"); | 146 "CacheStorageDispatcherHost::OnCacheStorageDelete"); |
| 147 if (!OriginCanAccessCacheStorage(origin)) { | |
| 148 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | |
| 149 return; | |
| 150 } | |
| 133 context_->cache_manager()->DeleteCache( | 151 context_->cache_manager()->DeleteCache( |
| 134 origin, base::UTF16ToUTF8(cache_name), | 152 origin, base::UTF16ToUTF8(cache_name), |
| 135 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, | 153 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, |
| 136 this, thread_id, request_id)); | 154 this, thread_id, request_id)); |
| 137 } | 155 } |
| 138 | 156 |
| 139 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, | 157 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, |
| 140 int request_id, | 158 int request_id, |
| 141 const GURL& origin) { | 159 const GURL& origin) { |
| 142 TRACE_EVENT0("CacheStorage", | 160 TRACE_EVENT0("CacheStorage", |
| 143 "CacheStorageDispatcherHost::OnCacheStorageKeys"); | 161 "CacheStorageDispatcherHost::OnCacheStorageKeys"); |
| 162 if (!OriginCanAccessCacheStorage(origin)) { | |
| 163 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | |
| 164 return; | |
| 165 } | |
| 144 context_->cache_manager()->EnumerateCaches( | 166 context_->cache_manager()->EnumerateCaches( |
| 145 origin, | 167 origin, |
| 146 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, | 168 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageKeysCallback, this, |
| 147 thread_id, request_id)); | 169 thread_id, request_id)); |
| 148 } | 170 } |
| 149 | 171 |
| 150 void CacheStorageDispatcherHost::OnCacheStorageMatch( | 172 void CacheStorageDispatcherHost::OnCacheStorageMatch( |
| 151 int thread_id, | 173 int thread_id, |
| 152 int request_id, | 174 int request_id, |
| 153 const GURL& origin, | 175 const GURL& origin, |
| 154 const ServiceWorkerFetchRequest& request, | 176 const ServiceWorkerFetchRequest& request, |
| 155 const CacheStorageCacheQueryParams& match_params) { | 177 const CacheStorageCacheQueryParams& match_params) { |
| 156 TRACE_EVENT0("CacheStorage", | 178 TRACE_EVENT0("CacheStorage", |
| 157 "CacheStorageDispatcherHost::OnCacheStorageMatch"); | 179 "CacheStorageDispatcherHost::OnCacheStorageMatch"); |
| 158 | 180 if (!OriginCanAccessCacheStorage(origin)) { |
| 181 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | |
| 182 return; | |
| 183 } | |
| 159 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( | 184 scoped_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 160 new ServiceWorkerFetchRequest(request.url, request.method, | 185 new ServiceWorkerFetchRequest(request.url, request.method, |
| 161 request.headers, request.referrer, | 186 request.headers, request.referrer, |
| 162 request.is_reload)); | 187 request.is_reload)); |
| 163 | 188 |
| 164 if (match_params.cache_name.empty()) { | 189 if (match_params.cache_name.empty()) { |
| 165 context_->cache_manager()->MatchAllCaches( | 190 context_->cache_manager()->MatchAllCaches( |
| 166 origin, scoped_request.Pass(), | 191 origin, scoped_request.Pass(), |
| 167 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, | 192 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, |
| 168 this, thread_id, request_id)); | 193 this, thread_id, request_id)); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 450 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 426 if (it == blob_handle_store_.end()) | 451 if (it == blob_handle_store_.end()) |
| 427 return; | 452 return; |
| 428 DCHECK(!it->second.empty()); | 453 DCHECK(!it->second.empty()); |
| 429 it->second.pop_front(); | 454 it->second.pop_front(); |
| 430 if (it->second.empty()) | 455 if (it->second.empty()) |
| 431 blob_handle_store_.erase(it); | 456 blob_handle_store_.erase(it); |
| 432 } | 457 } |
| 433 | 458 |
| 434 } // namespace content | 459 } // namespace content |
| OLD | NEW |