| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/api/public/WebURL.h" | 9 #include "webkit/api/public/WebURL.h" |
| 10 #include "webkit/api/public/WebURLRequest.h" | 10 #include "webkit/api/public/WebURLRequest.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 if (has_status_) | 56 if (has_status_) |
| 57 status_ = status; | 57 status_ = status; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { | 60 void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { |
| 61 client_->notifyEventListener(static_cast<EventID>(event_id)); | 61 client_->notifyEventListener(static_cast<EventID>(event_id)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void WebApplicationCacheHostImpl::willStartMainResourceRequest( | 64 void WebApplicationCacheHostImpl::willStartMainResourceRequest( |
| 65 WebURLRequest& request) { | 65 WebURLRequest& request) { |
| 66 request.setAppCacheContextID(host_id_); | 66 request.setAppCacheHostID(host_id_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void WebApplicationCacheHostImpl::willStartSubResourceRequest( | 69 void WebApplicationCacheHostImpl::willStartSubResourceRequest( |
| 70 WebURLRequest& request) { | 70 WebURLRequest& request) { |
| 71 request.setAppCacheContextID(host_id_); | 71 request.setAppCacheHostID(host_id_); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { | 74 void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { |
| 75 // Reset any previous status values we've received from the backend | 75 // Reset any previous status values we've received from the backend |
| 76 // since we're now selecting a new cache. | 76 // since we're now selecting a new cache. |
| 77 has_status_ = false; | 77 has_status_ = false; |
| 78 has_cached_status_ = false; | 78 has_cached_status_ = false; |
| 79 should_capture_main_response_ = NO; | 79 should_capture_main_response_ = NO; |
| 80 backend_->SelectCache(host_id_, main_response_url_, | 80 backend_->SelectCache(host_id_, main_response_url_, |
| 81 main_response_.appCacheID(), | 81 main_response_.appCacheID(), |
| 82 GURL()); | 82 GURL()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool WebApplicationCacheHostImpl::selectCacheWithManifest( | 85 bool WebApplicationCacheHostImpl::selectCacheWithManifest( |
| 86 const WebURL& manifest_url) { | 86 const WebURL& manifest_url) { |
| 87 // Reset any previous status values we've received from the backend | 87 // Reset any previous status values we've received from the backend |
| 88 // since we're now selecting a new cache. | 88 // since we're now selecting a new cache. |
| 89 has_status_ = false; | 89 has_status_ = false; |
| 90 has_cached_status_ = false; | 90 has_cached_status_ = false; |
| 91 | 91 |
| 92 GURL manifest_gurl(manifest_url); |
| 93 if (manifest_gurl.has_ref()) { |
| 94 GURL::Replacements replacements; |
| 95 replacements.ClearRef(); |
| 96 manifest_gurl = manifest_gurl.ReplaceComponents(replacements); |
| 97 } |
| 98 |
| 92 // Check for new 'master' entries. | 99 // Check for new 'master' entries. |
| 93 if (main_response_.appCacheID() == kNoCacheId) { | 100 if (main_response_.appCacheID() == kNoCacheId) { |
| 94 should_capture_main_response_ = is_in_http_family_ ? YES : NO; | 101 should_capture_main_response_ = is_in_http_family_ ? YES : NO; |
| 95 backend_->SelectCache(host_id_, main_response_url_, | 102 backend_->SelectCache(host_id_, main_response_url_, |
| 96 kNoCacheId, manifest_url); | 103 kNoCacheId, manifest_gurl); |
| 97 return true; | 104 return true; |
| 98 } | 105 } |
| 99 | 106 |
| 100 // Check for 'foreign' entries. | 107 // Check for 'foreign' entries. |
| 101 // TODO(michaeln): add manifestUrl() accessor to WebURLResponse, | 108 GURL main_response_manifest_gurl(main_response_.appCacheManifestURL()); |
| 102 // for now we don't really detect 'foreign' entries. | |
| 103 // TODO(michaeln): put an == operator on WebURL? | |
| 104 GURL manifest_gurl(manifest_url); | |
| 105 GURL main_response_manifest_gurl(manifest_url); // = mainResp.manifestUrl() | |
| 106 if (main_response_manifest_gurl != manifest_gurl) { | 109 if (main_response_manifest_gurl != manifest_gurl) { |
| 107 backend_->MarkAsForeignEntry(host_id_, main_response_url_, | 110 backend_->MarkAsForeignEntry(host_id_, main_response_url_, |
| 108 main_response_.appCacheID()); | 111 main_response_.appCacheID()); |
| 109 selectCacheWithoutManifest(); | 112 selectCacheWithoutManifest(); |
| 110 return false; // the navigation will be restarted | 113 return false; // the navigation will be restarted |
| 111 } | 114 } |
| 112 | 115 |
| 113 // Its a 'master' entry thats already in the cache. | 116 // Its a 'master' entry thats already in the cache. |
| 114 backend_->SelectCache(host_id_, main_response_url_, | 117 backend_->SelectCache(host_id_, main_response_url_, |
| 115 main_response_.appCacheID(), | 118 main_response_.appCacheID(), |
| 116 manifest_gurl); | 119 manifest_gurl); |
| 117 return true; | 120 return true; |
| 118 } | 121 } |
| 119 | 122 |
| 120 void WebApplicationCacheHostImpl::didReceiveResponseForMainResource( | 123 void WebApplicationCacheHostImpl::didReceiveResponseForMainResource( |
| 121 const WebURLResponse& response) { | 124 const WebURLResponse& response) { |
| 122 main_response_ = response; | 125 main_response_ = response; |
| 123 main_response_url_ = main_response_.url(); | 126 main_response_url_ = main_response_.url(); |
| 124 is_in_http_family_ = main_response_url_.SchemeIs("http") || | 127 is_in_http_family_ = main_response_url_.SchemeIs("http") || |
| 125 main_response_url_.SchemeIs("https"); | 128 main_response_url_.SchemeIs("https"); |
| 126 if ((main_response_.appCacheID() != kNoCacheId) || !is_in_http_family_) | 129 if ((main_response_.appCacheID() != kNoCacheId) || !is_in_http_family_) |
| 127 should_capture_main_response_ = NO; | 130 should_capture_main_response_ = NO; |
| 128 } | 131 } |
| 129 | 132 |
| 130 void WebApplicationCacheHostImpl::didReceiveDataForMainResource( | 133 void WebApplicationCacheHostImpl::didReceiveDataForMainResource( |
| 131 const char* data, int len) { | 134 const char* data, int len) { |
| 135 if (should_capture_main_response_ == NO) |
| 136 return; |
| 132 // TODO(michaeln): write me | 137 // TODO(michaeln): write me |
| 133 } | 138 } |
| 134 | 139 |
| 135 void WebApplicationCacheHostImpl::didFinishLoadingMainResource(bool success) { | 140 void WebApplicationCacheHostImpl::didFinishLoadingMainResource(bool success) { |
| 141 if (should_capture_main_response_ == NO) |
| 142 return; |
| 136 // TODO(michaeln): write me | 143 // TODO(michaeln): write me |
| 137 } | 144 } |
| 138 | 145 |
| 139 WebApplicationCacheHost::Status WebApplicationCacheHostImpl::status() { | 146 WebApplicationCacheHost::Status WebApplicationCacheHostImpl::status() { |
| 140 // We're careful about the status value to avoid race conditions. | 147 // We're careful about the status value to avoid race conditions. |
| 141 // | 148 // |
| 142 // Generally the webappcachehost sends an async stream of messages to the | 149 // Generally the webappcachehost sends an async stream of messages to the |
| 143 // backend, and receives an asyncronous stream of events from the backend. | 150 // backend, and receives an asyncronous stream of events from the backend. |
| 144 // In the backend, all operations are serialized and as state changes | 151 // In the backend, all operations are serialized and as state changes |
| 145 // 'events' are streamed out to relevant parties. In particular the | 152 // 'events' are streamed out to relevant parties. In particular the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 164 | 171 |
| 165 bool WebApplicationCacheHostImpl::startUpdate() { | 172 bool WebApplicationCacheHostImpl::startUpdate() { |
| 166 return backend_->StartUpdate(host_id_); | 173 return backend_->StartUpdate(host_id_); |
| 167 } | 174 } |
| 168 | 175 |
| 169 bool WebApplicationCacheHostImpl::swapCache() { | 176 bool WebApplicationCacheHostImpl::swapCache() { |
| 170 return backend_->SwapCache(host_id_); | 177 return backend_->SwapCache(host_id_); |
| 171 } | 178 } |
| 172 | 179 |
| 173 } // appcache namespace | 180 } // appcache namespace |
| OLD | NEW |