OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/appcache/web_application_cache_host_impl.h" | 5 #include "webkit/appcache/web_application_cache_host_impl.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
16 | 16 |
17 using WebKit::WebApplicationCacheHost; | 17 using WebKit::WebApplicationCacheHost; |
18 using WebKit::WebApplicationCacheHostClient; | 18 using WebKit::WebApplicationCacheHostClient; |
19 using WebKit::WebDataSource; | 19 using WebKit::WebDataSource; |
20 using WebKit::WebFrame; | 20 using WebKit::WebFrame; |
21 using WebKit::WebURLRequest; | 21 using WebKit::WebURLRequest; |
22 using WebKit::WebURL; | 22 using WebKit::WebURL; |
23 using WebKit::WebURLResponse; | 23 using WebKit::WebURLResponse; |
| 24 using WebKit::WebVector; |
24 | 25 |
25 namespace appcache { | 26 namespace appcache { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 typedef IDMap<WebApplicationCacheHostImpl> HostsMap; | 30 typedef IDMap<WebApplicationCacheHostImpl> HostsMap; |
30 | 31 |
31 // Note: the order of the elements in this array must match those | 32 // Note: the order of the elements in this array must match those |
32 // of the EventID enum in appcache_interfaces.h. | 33 // of the EventID enum in appcache_interfaces.h. |
33 const char* kEventNames[] = { | 34 const char* kEventNames[] = { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 DCHECK(client && backend && (host_id_ != kNoHostId)); | 81 DCHECK(client && backend && (host_id_ != kNoHostId)); |
81 | 82 |
82 backend_->RegisterHost(host_id_); | 83 backend_->RegisterHost(host_id_); |
83 } | 84 } |
84 | 85 |
85 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { | 86 WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { |
86 backend_->UnregisterHost(host_id_); | 87 backend_->UnregisterHost(host_id_); |
87 all_hosts()->Remove(host_id_); | 88 all_hosts()->Remove(host_id_); |
88 } | 89 } |
89 | 90 |
90 void WebApplicationCacheHostImpl::OnCacheSelected(int64 selected_cache_id, | 91 void WebApplicationCacheHostImpl::OnCacheSelected( |
91 appcache::Status status) { | 92 const appcache::AppCacheInfo& info) { |
92 status_ = status; | 93 status_ = info.status; |
93 has_status_ = true; | 94 has_status_ = true; |
| 95 cache_info_ = info; |
| 96 client_->didChangeCacheAssociation(); |
94 } | 97 } |
95 | 98 |
96 void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { | 99 void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { |
97 if (has_status_) | 100 if (has_status_) |
98 status_ = status; | 101 status_ = status; |
99 } | 102 } |
100 | 103 |
101 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { | 104 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { |
102 DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. | 105 DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. |
103 DCHECK(event_id != ERROR_EVENT); // See OnErrorEventRaised. | 106 DCHECK(event_id != ERROR_EVENT); // See OnErrorEventRaised. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Reset any previous status values we've received from the backend | 165 // Reset any previous status values we've received from the backend |
163 // since we're now selecting a new cache. | 166 // since we're now selecting a new cache. |
164 has_status_ = false; | 167 has_status_ = false; |
165 has_cached_status_ = false; | 168 has_cached_status_ = false; |
166 is_new_master_entry_ = NO; | 169 is_new_master_entry_ = NO; |
167 backend_->SelectCache(host_id_, document_url_, | 170 backend_->SelectCache(host_id_, document_url_, |
168 document_response_.appCacheID(), | 171 document_response_.appCacheID(), |
169 GURL()); | 172 GURL()); |
170 } | 173 } |
171 | 174 |
| 175 void WebApplicationCacheHostImpl::getAssociatedCacheInfo( |
| 176 WebApplicationCacheHost::CacheInfo* info) { |
| 177 if (!cache_info_.is_complete) |
| 178 return; |
| 179 info->manifestURL = cache_info_.manifest_url; |
| 180 info->creationTime = cache_info_.creation_time.ToDoubleT(); |
| 181 info->updateTime = cache_info_.last_update_time.ToDoubleT(); |
| 182 info->totalSize = cache_info_.size; |
| 183 } |
| 184 |
| 185 void WebApplicationCacheHostImpl::getResourceList( |
| 186 WebVector<ResourceInfo>* resources) { |
| 187 if (!cache_info_.is_complete) |
| 188 return; |
| 189 std::vector<AppCacheResourceInfo> resource_infos; |
| 190 backend_->GetResourceList(host_id_, &resource_infos); |
| 191 |
| 192 WebVector<ResourceInfo> web_resources(resource_infos.size()); |
| 193 // Convert resource_infos to WebKit API. |
| 194 for (size_t i = 0; i < resource_infos.size(); ++i) { |
| 195 web_resources[i].size = resource_infos[i].size; |
| 196 web_resources[i].isMaster = resource_infos[i].is_master; |
| 197 web_resources[i].isExplicit = resource_infos[i].is_explicit; |
| 198 web_resources[i].isManifest = resource_infos[i].is_manifest; |
| 199 web_resources[i].isForeign = resource_infos[i].is_foreign; |
| 200 web_resources[i].isFallback = resource_infos[i].is_fallback; |
| 201 web_resources[i].url = resource_infos[i].url; |
| 202 } |
| 203 |
| 204 resources->swap(web_resources); |
| 205 } |
| 206 |
172 bool WebApplicationCacheHostImpl::selectCacheWithManifest( | 207 bool WebApplicationCacheHostImpl::selectCacheWithManifest( |
173 const WebURL& manifest_url) { | 208 const WebURL& manifest_url) { |
174 // Reset any previous status values we've received from the backend | 209 // Reset any previous status values we've received from the backend |
175 // since we're now selecting a new cache. | 210 // since we're now selecting a new cache. |
176 has_status_ = false; | 211 has_status_ = false; |
177 has_cached_status_ = false; | 212 has_cached_status_ = false; |
178 | 213 |
179 GURL manifest_gurl(ClearUrlRef(manifest_url)); | 214 GURL manifest_gurl(ClearUrlRef(manifest_url)); |
180 | 215 |
181 // 6.9.6 The application cache selection algorithm | 216 // 6.9.6 The application cache selection algorithm |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 307 |
273 bool WebApplicationCacheHostImpl::swapCache() { | 308 bool WebApplicationCacheHostImpl::swapCache() { |
274 // Cache status will change when cache is swapped. Clear out any saved idea | 309 // Cache status will change when cache is swapped. Clear out any saved idea |
275 // of status so that backend will be queried for actual status. | 310 // of status so that backend will be queried for actual status. |
276 has_status_ = false; | 311 has_status_ = false; |
277 has_cached_status_ = false; | 312 has_cached_status_ = false; |
278 return backend_->SwapCache(host_id_); | 313 return backend_->SwapCache(host_id_); |
279 } | 314 } |
280 | 315 |
281 } // appcache namespace | 316 } // appcache namespace |
OLD | NEW |