| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/appcache_request_handler.h" | 5 #include "webkit/appcache/appcache_request_handler.h" |
| 6 | 6 |
| 7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
| 8 #include "net/url_request/url_request_job.h" | 8 #include "net/url_request/url_request_job.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 | 10 |
| 11 namespace appcache { | 11 namespace appcache { |
| 12 | 12 |
| 13 // AppCacheRequestHandler ----------------------------------------------------- | 13 // AppCacheRequestHandler ----------------------------------------------------- |
| 14 | 14 |
| 15 static bool IsHttpOrHttpsGetOrEquivalent(URLRequest* request) { | 15 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host, |
| 16 return false; // TODO(michaeln): write me | 16 bool is_main_resource) |
| 17 : is_main_request_(is_main_resource), host_(host) { |
| 18 DCHECK(host_); |
| 19 host_->AddObserver(this); |
| 17 } | 20 } |
| 18 | 21 |
| 19 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host) | 22 AppCacheRequestHandler::~AppCacheRequestHandler() { |
| 20 : is_main_request_(true), cache_id_(kNoCacheId), | 23 if (host_) |
| 21 host_(host->AsWeakPtr()), service_(host->service()) { | 24 host_->RemoveObserver(this); |
| 22 } | |
| 23 | |
| 24 AppCacheRequestHandler::AppCacheRequestHandler(AppCache* cache) | |
| 25 : is_main_request_(false), cache_id_(kNoCacheId), | |
| 26 cache_(cache), service_(cache->service()) { | |
| 27 } | 25 } |
| 28 | 26 |
| 29 void AppCacheRequestHandler::GetExtraResponseInfo( | 27 void AppCacheRequestHandler::GetExtraResponseInfo( |
| 30 int64* cache_id, GURL* manifest_url) { | 28 int64* cache_id, GURL* manifest_url) { |
| 31 // TODO(michaeln): If this is a main request and it was retrieved from | 29 // TODO(michaeln): If this is a main request and it was retrieved from |
| 32 // an appcache, ensure that appcache survives the frame navigation. The | 30 // an appcache, ensure that appcache survives the frame navigation. The |
| 33 // AppCacheHost should hold reference to that cache to prevent it from | 31 // AppCacheHost should hold reference to that cache to prevent it from |
| 34 // being dropped from the in-memory collection of AppCaches. When cache | 32 // being dropped from the in-memory collection of AppCaches. When cache |
| 35 // selection occurs, that extra reference should be dropped. Perhaps | 33 // selection occurs, that extra reference should be dropped. Perhaps |
| 36 // maybe: if (is_main) host->LoadCacheOfMainResource(cache_id); | 34 // maybe: if (is_main) host->LoadCacheOfMainResource(cache_id); |
| 37 } | 35 } |
| 38 | 36 |
| 39 URLRequestJob* AppCacheRequestHandler::MaybeLoadResource(URLRequest* request) { | 37 URLRequestJob* AppCacheRequestHandler::MaybeLoadResource(URLRequest* request) { |
| 40 if (!IsHttpOrHttpsGetOrEquivalent(request)) | 38 // 6.9.7 Changes to the networking model |
| 39 // If the resource is not to be fetched using the HTTP GET mechanism or |
| 40 // equivalent ... then fetch the resource normally |
| 41 if (!host_ || !IsSchemeAndMethodSupported(request)) |
| 41 return NULL; | 42 return NULL; |
| 42 // TODO(michaeln): write me | 43 // TODO(michaeln): write me |
| 43 return NULL; | 44 return NULL; |
| 44 } | 45 } |
| 45 | 46 |
| 46 URLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( | 47 URLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( |
| 47 URLRequest* request, const GURL& location) { | 48 URLRequest* request, const GURL& location) { |
| 48 if (!IsHttpOrHttpsGetOrEquivalent(request)) | 49 if (!host_ || !IsSchemeAndMethodSupported(request)) |
| 49 return NULL; | 50 return NULL; |
| 50 // TODO(michaeln): write me | 51 // TODO(michaeln): write me |
| 51 return NULL; | 52 return NULL; |
| 52 } | 53 } |
| 53 | 54 |
| 54 URLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 55 URLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
| 55 URLRequest* request) { | 56 URLRequest* request) { |
| 56 if (!IsHttpOrHttpsGetOrEquivalent(request)) | 57 if (!host_ || !IsSchemeAndMethodSupported(request)) |
| 57 return NULL; | 58 return NULL; |
| 58 // TODO(michaeln): write me | 59 // TODO(michaeln): write me |
| 59 return NULL; | 60 return NULL; |
| 60 } | 61 } |
| 61 | 62 |
| 63 void AppCacheRequestHandler::OnCacheSelectionComplete(AppCacheHost* host) { |
| 64 DCHECK(host == host_); |
| 65 // TODO(michaeln): write me |
| 66 } |
| 67 |
| 68 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { |
| 69 host_ = NULL; |
| 70 // TODO(michaeln): write me |
| 71 } |
| 72 |
| 62 } // namespace appcache | 73 } // namespace appcache |
| 63 | 74 |
| OLD | NEW |