diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 21:46:31 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 21:46:31 +0000 |
commit | f430b57130adff68db69f340c68b6afe5746edc5 (patch) | |
tree | 3c1e56173a34f7ea652ebe6c450c22ba9ddce0ae /webkit | |
parent | 8177d9bbcda50fdba18f19f131024a4704c376f8 (diff) | |
download | chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.zip chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.tar.gz chromium_src-f430b57130adff68db69f340c68b6afe5746edc5.tar.bz2 |
Retrofit the pre-existing appache message dispatching with the new WebKit APIs and concrete classes defined in our new appcache library, and get rid of the old files.
There are many files in the CL, mostly to pickup constant values now defined in our new appcache library, and to reflect a terminilogy change (from 'context' to 'host').
TEST=some existing unit tests apply
BUG=none
Review URL: http://codereview.chromium.org/170003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
25 files changed, 602 insertions, 146 deletions
diff --git a/webkit/appcache/appcache_backend_impl.cc b/webkit/appcache/appcache_backend_impl.cc new file mode 100644 index 0000000..c59fc6d --- /dev/null +++ b/webkit/appcache/appcache_backend_impl.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/appcache/appcache_backend_impl.h" + +#include "base/logging.h" +#include "webkit/appcache/web_application_cache_host_impl.h" + +namespace appcache { + +AppCacheBackendImpl::~AppCacheBackendImpl() { + // TODO(michaeln): if (service_) service_->UnregisterFrontend(frontend_); +} + +void AppCacheBackendImpl::Initialize(AppCacheService* service, + AppCacheFrontend* frontend) { + DCHECK(!service_ && !frontend_ && frontend); // DCHECK(service) + service_ = service; + frontend_ = frontend; + // TODO(michaeln): service_->RegisterFrontend(frontend_); +} + +void AppCacheBackendImpl::RegisterHost(int host_id) { + // TODO(michaeln): plumb to service +} + +void AppCacheBackendImpl::UnregisterHost(int host_id) { + // TODO(michaeln): plumb to service +} + +void AppCacheBackendImpl::SelectCache( + int host_id, + const GURL& document_url, + const int64 cache_document_was_loaded_from, + const GURL& manifest_url) { + // TODO(michaeln): plumb to service + frontend_->OnCacheSelected(host_id, kNoCacheId, UNCACHED); +} + +void AppCacheBackendImpl::MarkAsForeignEntry( + int host_id, + const GURL& document_url, + int64 cache_document_was_loaded_from) { + // TODO(michaeln): plumb to service +} + +Status AppCacheBackendImpl::GetStatus(int host_id) { + // TODO(michaeln): plumb to service + return UNCACHED; +} + +bool AppCacheBackendImpl::StartUpdate(int host_id) { + // TODO(michaeln): plumb to service + return false; +} + +bool AppCacheBackendImpl::SwapCache(int host_id) { + // TODO(michaeln): plumb to service + return false; +} + +} // namespace appcache
\ No newline at end of file diff --git a/webkit/appcache/appcache_backend_impl.h b/webkit/appcache/appcache_backend_impl.h new file mode 100644 index 0000000..93a7083 --- /dev/null +++ b/webkit/appcache/appcache_backend_impl.h @@ -0,0 +1,41 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ +#define WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ + +#include "webkit/appcache/appcache_interfaces.h" + +namespace appcache { + +class AppCacheService; + +class AppCacheBackendImpl : public AppCacheBackend { + public: + AppCacheBackendImpl() : service_(NULL), frontend_(NULL) {} + ~AppCacheBackendImpl(); + + void Initialize(AppCacheService* service, + AppCacheFrontend* frontend); + + virtual void RegisterHost(int host_id); + virtual void UnregisterHost(int host_id); + virtual void SelectCache(int host_id, + const GURL& document_url, + const int64 cache_document_was_loaded_from, + const GURL& manifest_url); + virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from); + virtual Status GetStatus(int host_id); + virtual bool StartUpdate(int host_id); + virtual bool SwapCache(int host_id); + + private: + AppCacheService* service_; + AppCacheFrontend* frontend_; +}; + +} // namespace + +#endif // WEBKIT_APPCACHE_APPCACHE_BACKEND_IMPL_H_ diff --git a/webkit/appcache/appcache_frontend_impl.cc b/webkit/appcache/appcache_frontend_impl.cc new file mode 100644 index 0000000..a0ef05e --- /dev/null +++ b/webkit/appcache/appcache_frontend_impl.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/appcache/appcache_frontend_impl.h" +#include "webkit/appcache/web_application_cache_host_impl.h" + +namespace appcache { + +// Inline helper to keep the lines shorter and unwrapped. +inline WebApplicationCacheHostImpl* GetHost(int id) { + return WebApplicationCacheHostImpl::FromId(id); +} + +void AppCacheFrontendImpl::OnCacheSelected(int host_id, int64 cache_id , + Status status) { + WebApplicationCacheHostImpl* host = GetHost(host_id); + if (host) + host->OnCacheSelected(cache_id, status); +} + +void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids, + Status status) { + for (std::vector<int>::const_iterator i = host_ids.begin(); + i != host_ids.end(); ++i) { + WebApplicationCacheHostImpl* host = GetHost(*i); + if (host) + host->OnStatusChanged(status); + } +} + +void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, + EventID event_id) { + for (std::vector<int>::const_iterator i = host_ids.begin(); + i != host_ids.end(); ++i) { + WebApplicationCacheHostImpl* host = GetHost(*i); + if (host) + host->OnEventRaised(event_id); + } +} + +} // namespace appcache diff --git a/webkit/appcache/appcache_frontend_impl.h b/webkit/appcache/appcache_frontend_impl.h new file mode 100644 index 0000000..e4ed922 --- /dev/null +++ b/webkit/appcache/appcache_frontend_impl.h @@ -0,0 +1,25 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_APPCACHE_APPCACHE_FRONTEND_IMPL_H_ +#define WEBKIT_APPCACHE_APPCACHE_FRONTEND_IMPL_H_ + +#include <vector> +#include "webkit/appcache/appcache_interfaces.h" + +namespace appcache { + +class AppCacheFrontendImpl : public AppCacheFrontend { + public: + virtual void OnCacheSelected(int host_id, int64 cache_id , + Status status); + virtual void OnStatusChanged(const std::vector<int>& host_ids, + Status status); + virtual void OnEventRaised(const std::vector<int>& host_ids, + EventID event_id); +}; + +} // namespace + +#endif // WEBKIT_APPCACHE_APPCACHE_FRONTEND_IMPL_H_ diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc new file mode 100644 index 0000000..bd73879 --- /dev/null +++ b/webkit/appcache/appcache_interfaces.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/appcache/appcache_interfaces.h" +#include "webkit/api/public/WebApplicationCacheHost.h" + +using WebKit::WebApplicationCacheHost; + +namespace appcache { + +// Ensure that enum values never get out of sync with the +// ones declared for use within the WebKit api + +COMPILE_ASSERT((int)WebApplicationCacheHost::Uncached == + (int)UNCACHED, Uncached); +COMPILE_ASSERT((int)WebApplicationCacheHost::Idle == + (int)IDLE, Idle); +COMPILE_ASSERT((int)WebApplicationCacheHost::Checking == + (int)CHECKING, Checking); +COMPILE_ASSERT((int)WebApplicationCacheHost::Downloading == + (int)DOWNLOADING, Downloading); +COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReady == + (int)UPDATE_READY, UpdateReady); +COMPILE_ASSERT((int)WebApplicationCacheHost::Obsolete == + (int)OBSOLETE, Obsolete); +COMPILE_ASSERT((int)WebApplicationCacheHost::CheckingEvent == + (int)CHECKING_EVENT, CheckingEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::ErrorEvent == + (int)ERROR_EVENT, ErrorEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::NoUpdateEvent == + (int)NO_UPDATE_EVENT, NoUpdateEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::DownloadingEvent == + (int)DOWNLOADING_EVENT, DownloadingEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::ProgressEvent == + (int)PROGRESS_EVENT, ProgressEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::UpdateReadyEvent == + (int)UPDATE_READY_EVENT, UpdateReadyEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::CachedEvent == + (int)CACHED_EVENT, CachedEvent); +COMPILE_ASSERT((int)WebApplicationCacheHost::ObsoleteEvent == + (int)OBSOLETE_EVENT, ObsoleteEvent); + +} // namespace diff --git a/webkit/appcache/appcache_interfaces.h b/webkit/appcache/appcache_interfaces.h new file mode 100644 index 0000000..ee63633 --- /dev/null +++ b/webkit/appcache/appcache_interfaces.h @@ -0,0 +1,75 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ +#define WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ + +#include <vector> +#include "base/basictypes.h" + +class GURL; + +namespace appcache { + +// Defines constants, types, and abstract classes used in the main +// process and in child processes. + +static const int kNoHostId = 0; +static const int64 kNoCacheId = 0; +static const int64 kUnknownCacheId = -1; + +enum Status { + UNCACHED, + IDLE, + CHECKING, + DOWNLOADING, + UPDATE_READY, + OBSOLETE +}; + +enum EventID { + CHECKING_EVENT, + ERROR_EVENT, + NO_UPDATE_EVENT, + DOWNLOADING_EVENT, + PROGRESS_EVENT, + UPDATE_READY_EVENT, + CACHED_EVENT, + OBSOLETE_EVENT +}; + +// Interface used by backend to talk to frontend. +class AppCacheFrontend { + public: + virtual void OnCacheSelected(int host_id, int64 cache_id , + Status status) = 0; + virtual void OnStatusChanged(const std::vector<int>& host_ids, + Status status) = 0; + virtual void OnEventRaised(const std::vector<int>& host_ids, + EventID event_id) = 0; + + virtual ~AppCacheFrontend() {} +}; + +// Interface used by frontend to talk to backend. +class AppCacheBackend { + public: + virtual void RegisterHost(int host_id) = 0; + virtual void UnregisterHost(int host_id) = 0; + virtual void SelectCache(int host_id, + const GURL& document_url, + const int64 cache_document_was_loaded_from, + const GURL& manifest_url) = 0; + virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, + int64 cache_document_was_loaded_from) = 0; + virtual Status GetStatus(int host_id) = 0; + virtual bool StartUpdate(int host_id) = 0; + virtual bool SwapCache(int host_id) = 0; + + virtual ~AppCacheBackend() {} +}; + +} // namespace + +#endif // WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ diff --git a/webkit/appcache/web_application_cache_host_impl.cc b/webkit/appcache/web_application_cache_host_impl.cc new file mode 100644 index 0000000..02a698f --- /dev/null +++ b/webkit/appcache/web_application_cache_host_impl.cc @@ -0,0 +1,172 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/appcache/web_application_cache_host_impl.h" + +#include "base/compiler_specific.h" +#include "base/id_map.h" +#include "webkit/api/public/WebURL.h" +#include "webkit/api/public/WebURLRequest.h" +#include "webkit/api/public/WebURLResponse.h" + +using WebKit::WebApplicationCacheHost; +using WebKit::WebApplicationCacheHostClient; +using WebKit::WebURLRequest; +using WebKit::WebURL; +using WebKit::WebURLResponse; + +namespace appcache { + +static IDMap<WebApplicationCacheHostImpl> all_hosts; + +WebApplicationCacheHostImpl* WebApplicationCacheHostImpl::FromId(int id) { + return all_hosts.Lookup(id); +} + +WebApplicationCacheHostImpl::WebApplicationCacheHostImpl( + WebApplicationCacheHostClient* client, + AppCacheBackend* backend) + : client_(client), + backend_(backend), + ALLOW_THIS_IN_INITIALIZER_LIST(host_id_(all_hosts.Add(this))), + has_status_(false), + status_(UNCACHED), + has_cached_status_(false), + cached_status_(UNCACHED), + is_in_http_family_(false), + should_capture_main_response_(MAYBE) { + DCHECK(client && backend && (host_id_ != kNoHostId)); + + backend_->RegisterHost(host_id_); +} + +WebApplicationCacheHostImpl::~WebApplicationCacheHostImpl() { + backend_->UnregisterHost(host_id_); +} + +void WebApplicationCacheHostImpl::OnCacheSelected(int64 selected_cache_id, + appcache::Status status) { + status_ = status; + has_status_ = true; +} + +void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { + if (has_status_) + status_ = status; +} + +void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { + client_->notifyEventListener(static_cast<EventID>(event_id)); +} + +void WebApplicationCacheHostImpl::willStartMainResourceRequest( + WebURLRequest& request) { + request.setAppCacheContextID(host_id_); +} + +void WebApplicationCacheHostImpl::willStartSubResourceRequest( + WebURLRequest& request) { + request.setAppCacheContextID(host_id_); +} + +void WebApplicationCacheHostImpl::selectCacheWithoutManifest() { + // Reset any previous status values we've received from the backend + // since we're now selecting a new cache. + has_status_ = false; + has_cached_status_ = false; + should_capture_main_response_ = NO; + backend_->SelectCache(host_id_, main_response_url_, + main_response_.appCacheID(), + GURL()); +} + +bool WebApplicationCacheHostImpl::selectCacheWithManifest( + const WebURL& manifest_url) { + // Reset any previous status values we've received from the backend + // since we're now selecting a new cache. + has_status_ = false; + has_cached_status_ = false; + + // Check for new 'master' entries. + if (main_response_.appCacheID() == kNoCacheId) { + should_capture_main_response_ = is_in_http_family_ ? YES : NO; + backend_->SelectCache(host_id_, main_response_url_, + kNoCacheId, manifest_url); + return true; + } + + // Check for 'foreign' entries. + // TODO(michaeln): add manifestUrl() accessor to WebURLResponse, + // for now we don't really detect 'foreign' entries. + // TODO(michaeln): put an == operator on WebURL? + GURL manifest_gurl(manifest_url); + GURL main_response_manifest_gurl(manifest_url); // = mainResp.manifestUrl() + if (main_response_manifest_gurl != manifest_gurl) { + backend_->MarkAsForeignEntry(host_id_, main_response_url_, + main_response_.appCacheID()); + selectCacheWithoutManifest(); + return false; // the navigation will be restarted + } + + // Its a 'master' entry thats already in the cache. + backend_->SelectCache(host_id_, main_response_url_, + main_response_.appCacheID(), + manifest_gurl); + return true; +} + +void WebApplicationCacheHostImpl::didReceiveResponseForMainResource( + const WebURLResponse& response) { + main_response_ = response; + main_response_url_ = main_response_.url(); + is_in_http_family_ = main_response_url_.SchemeIs("http") || + main_response_url_.SchemeIs("https"); + if ((main_response_.appCacheID() != kNoCacheId) || !is_in_http_family_) + should_capture_main_response_ = NO; +} + +void WebApplicationCacheHostImpl::didReceiveDataForMainResource( + const char* data, int len) { + // TODO(michaeln): write me +} + +void WebApplicationCacheHostImpl::didFinishLoadingMainResource(bool success) { + // TODO(michaeln): write me +} + +WebApplicationCacheHost::Status WebApplicationCacheHostImpl::status() { + // We're careful about the status value to avoid race conditions. + // + // Generally the webappcachehost sends an async stream of messages to the + // backend, and receives an asyncronous stream of events from the backend. + // In the backend, all operations are serialized and as state changes + // 'events' are streamed out to relevant parties. In particular the + // 'SelectCache' message is async. Regular page loading and navigation + // involves two non-blocking ipc calls: RegisterHost + SelectCache. + // + // However, the page can call the scriptable API in advance of a cache + // selection being complete (and/or in advance of the webappcachehost having + // received the event about completion). In that case, we force an end-to-end + // fetch of the 'status' value, and cache that value seperately from the + // value we receive via the async event stream. We'll use that cached value + // until cache selection is complete. + if (has_status_) + return static_cast<WebApplicationCacheHost::Status>(status_); + + if (!has_cached_status_) { + cached_status_ = backend_->GetStatus(host_id_); + has_cached_status_ = true; + } + return static_cast<WebApplicationCacheHost::Status>(cached_status_); +} + +bool WebApplicationCacheHostImpl::startUpdate() { + return backend_->StartUpdate(host_id_); +} + +bool WebApplicationCacheHostImpl::swapCache() { + return backend_->SwapCache(host_id_); +} + +} // appcache namespace diff --git a/webkit/appcache/web_application_cache_host_impl.h b/webkit/appcache/web_application_cache_host_impl.h new file mode 100644 index 0000000..dbc00f1 --- /dev/null +++ b/webkit/appcache/web_application_cache_host_impl.h @@ -0,0 +1,64 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ +#define WEBKIT_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ + +#include "googleurl/src/gurl.h" +#include "webkit/api/public/WebApplicationCacheHostClient.h" +#include "webkit/api/public/WebURLResponse.h" +#include "webkit/appcache/appcache_interfaces.h" + +namespace appcache { + +class WebApplicationCacheHostImpl : public WebKit::WebApplicationCacheHost { + public: + // Returns the host having given id or NULL if there is no such host. + static WebApplicationCacheHostImpl* FromId(int id); + + WebApplicationCacheHostImpl(WebKit::WebApplicationCacheHostClient* client, + AppCacheBackend* backend); + virtual ~WebApplicationCacheHostImpl(); + + int host_id() const { return host_id_; } + + void OnCacheSelected(int64 selected_cache_id, appcache::Status status); + void OnStatusChanged(appcache::Status); + void OnEventRaised(appcache::EventID); + + // WebApplicationCacheHost methods + virtual void willStartMainResourceRequest(WebKit::WebURLRequest&); + virtual void willStartSubResourceRequest(WebKit::WebURLRequest&); + virtual void selectCacheWithoutManifest(); + virtual bool selectCacheWithManifest(const WebKit::WebURL& manifestURL); + virtual void didReceiveResponseForMainResource(const WebKit::WebURLResponse&); + virtual void didReceiveDataForMainResource(const char* data, int len); + virtual void didFinishLoadingMainResource(bool success); + virtual WebKit::WebApplicationCacheHost::Status status(); + virtual bool startUpdate(); + virtual bool swapCache(); + + private: + enum ShouldCaptureMainResponse { + MAYBE, + YES, + NO + }; + + WebKit::WebApplicationCacheHostClient* client_; + AppCacheBackend* backend_; + int host_id_; + bool has_status_; + appcache::Status status_; + bool has_cached_status_; + appcache::Status cached_status_; + WebKit::WebURLResponse main_response_; + GURL main_response_url_; + bool is_in_http_family_; + ShouldCaptureMainResponse should_capture_main_response_; +}; + +} // namespace + +#endif // WEBKIT_APPCACHE_WEB_APPLICATION_CACHE_HOST_IMPL_H_ diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 5f739ba..5b6ef7e 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -13,7 +13,6 @@ #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" #include "webkit/glue/media/buffered_data_source.h" -#include "webkit/glue/webappcachecontext.h" namespace { diff --git a/webkit/glue/media/media_resource_loader_bridge_factory.cc b/webkit/glue/media/media_resource_loader_bridge_factory.cc index 6e239a4..03684c8 100644 --- a/webkit/glue/media/media_resource_loader_bridge_factory.cc +++ b/webkit/glue/media/media_resource_loader_bridge_factory.cc @@ -19,13 +19,13 @@ MediaResourceLoaderBridgeFactory::MediaResourceLoaderBridgeFactory( const std::string& frame_origin, const std::string& main_frame_origin, int origin_pid, - int app_cache_context_id, + int appcache_host_id, int32 routing_id) : referrer_(referrer), frame_origin_(frame_origin), main_frame_origin_(main_frame_origin), origin_pid_(origin_pid), - app_cache_context_id_(app_cache_context_id), + appcache_host_id_(appcache_host_id), routing_id_(routing_id) { } @@ -45,7 +45,7 @@ ResourceLoaderBridge* MediaResourceLoaderBridgeFactory::CreateBridge( load_flags, origin_pid_, ResourceType::MEDIA, - app_cache_context_id_, + appcache_host_id_, routing_id_); } diff --git a/webkit/glue/media/media_resource_loader_bridge_factory.h b/webkit/glue/media/media_resource_loader_bridge_factory.h index 453f655..6408949 100644 --- a/webkit/glue/media/media_resource_loader_bridge_factory.h +++ b/webkit/glue/media/media_resource_loader_bridge_factory.h @@ -21,7 +21,7 @@ class MediaResourceLoaderBridgeFactory { const std::string& frame_origin, const std::string& main_frame_origin, int origin_pid, - int app_cache_context_id, + int appcache_host_id, int32 routing_id); virtual ~MediaResourceLoaderBridgeFactory() {} @@ -67,7 +67,7 @@ class MediaResourceLoaderBridgeFactory { std::string main_frame_origin_; std::string headers_; int origin_pid_; - int app_cache_context_id_; + int appcache_host_id_; int32 routing_id_; }; diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 639aa5f..fd3be2f 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -10,7 +10,6 @@ #include "net/url_request/url_request_status.h" #include "webkit/glue/media/simple_data_source.h" #include "webkit/glue/resource_loader_bridge.h" -#include "webkit/glue/webappcachecontext.h" namespace { diff --git a/webkit/glue/resource_loader_bridge.cc b/webkit/glue/resource_loader_bridge.cc index 2d26f2a..fd8eee3 100644 --- a/webkit/glue/resource_loader_bridge.cc +++ b/webkit/glue/resource_loader_bridge.cc @@ -3,15 +3,15 @@ // found in the LICENSE file. #include "webkit/glue/resource_loader_bridge.h" -#include "webkit/glue/webappcachecontext.h" +#include "webkit/appcache/appcache_interfaces.h" #include "net/http/http_response_headers.h" namespace webkit_glue { ResourceLoaderBridge::ResponseInfo::ResponseInfo() { content_length = -1; - app_cache_id = WebAppCacheContext::kNoAppCacheId; + appcache_id = appcache::kNoCacheId; } ResourceLoaderBridge::ResponseInfo::~ResponseInfo() { diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h index 07245fd..302a1be 100644 --- a/webkit/glue/resource_loader_bridge.h +++ b/webkit/glue/resource_loader_bridge.h @@ -67,8 +67,12 @@ class ResourceLoaderBridge { // Content length if available. -1 if not available int64 content_length; - // The appcache this response was loaded from, or kNoAppCacheId. - int64 app_cache_id; + // The appcache this response was loaded from, or kNoCacheId. + int64 appcache_id; + + // The manifest url of the appcache this response was loaded from. + // Note: this value is only populated for main resource requests. + GURL appcache_manifest_url; }; // See the SyncLoad method declared below. (The name of this struct is not @@ -157,7 +161,7 @@ class ResourceLoaderBridge { // request_type indicates if the current request is the main frame load, a // sub-frame load, or a sub objects load. // - // app_cache_context_id identifies that app cache context this request is + // appcache_host_id identifies that appcache host this request is // associated with. // // routing_id passed to this function allows it to be associated with a @@ -172,7 +176,7 @@ class ResourceLoaderBridge { int load_flags, int requestor_pid, ResourceType::Type request_type, - int app_cache_context_id, + int appcache_host_id, int routing_id); // Call this method before calling Start() to append a chunk of binary data diff --git a/webkit/glue/unittest_test_server.h b/webkit/glue/unittest_test_server.h index 583abf9..1033b1c 100644 --- a/webkit/glue/unittest_test_server.h +++ b/webkit/glue/unittest_test_server.h @@ -5,8 +5,8 @@ #ifndef WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ #define WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ +#include "webkit/appcache/appcache_interfaces.h" #include "webkit/glue/resource_loader_bridge.h" -#include "webkit/glue/webappcachecontext.h" #include "net/base/load_flags.h" #include "net/url_request/url_request_unittest.h" @@ -49,7 +49,7 @@ class UnittestTestServer : public HTTPTestServer { net::LOAD_NORMAL, 0, ResourceType::SUB_RESOURCE, - WebAppCacheContext::kNoAppCacheContextId, + appcache::kNoHostId, 0)); EXPECT_TRUE(loader.get()); diff --git a/webkit/glue/webappcachecontext.cc b/webkit/glue/webappcachecontext.cc deleted file mode 100644 index 6092a26..0000000 --- a/webkit/glue/webappcachecontext.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/glue/webappcachecontext.h" - -namespace { - -WebAppCacheContext::WebAppCacheFactoryProc factory_proc = NULL; - -class NoopWebAppCacheContext : public WebAppCacheContext { - public: - virtual int GetContextID() { return kNoAppCacheContextId; } - virtual int64 GetAppCacheID() { return kNoAppCacheId; } - virtual void Initialize(ContextType context_type, - WebAppCacheContext* opt_parent) {} - virtual void SelectAppCacheWithoutManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from) {} - virtual void SelectAppCacheWithManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from, - const GURL& manifest_url) {} - -}; - -} // namespace - -const int WebAppCacheContext::kNoAppCacheContextId = 0; -const int64 WebAppCacheContext::kNoAppCacheId = 0; -const int64 WebAppCacheContext::kUnknownAppCacheId = -1; - -WebAppCacheContext* WebAppCacheContext::Create() { - if (factory_proc) - return factory_proc(); - return new NoopWebAppCacheContext(); -} - -void WebAppCacheContext::SetFactory(WebAppCacheFactoryProc proc) { - factory_proc = proc; -} diff --git a/webkit/glue/webappcachecontext.h b/webkit/glue/webappcachecontext.h deleted file mode 100644 index 5d2fc53..0000000 --- a/webkit/glue/webappcachecontext.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_WEBAPPCACHECONTEXT_H_ -#define WEBKIT_GLUE_WEBAPPCACHECONTEXT_H_ - -#include "base/basictypes.h" - -class GURL; - -// This class is used in child processes, renderers and workers. -// -// An AppCacheContext corresponds with what html5 refers to as a -// "browsing context". Conceptually, each frame or worker represents -// a unique context. This class is used in child processes (renderers -// and workers) to inform the browser process of new frames and workers, and -// to keep track of which appcache is selected for each context. Resource -// requests contain the context id so the browser process can identify -// which context a request came from. As new documents are committed into a -// frame, the cache selection algorithm is initiated by calling one of the -// SelectAppCache methods. -// -// Each WebAppCacheContext is assigned a unique id within its child process. -// These ids are made globally unique by pairing them with a child process -// id within the browser process. -// -// WebFrameImpl has a scoped ptr to one of these as a data member. -// TODO(michaeln): integrate with WebWorkers -class WebAppCacheContext { - public: - enum ContextType { - MAIN_FRAME = 0, - CHILD_FRAME, - DEDICATED_WORKER - }; - - static const int kNoAppCacheContextId; // = 0; - static const int64 kNoAppCacheId; // = 0; - static const int64 kUnknownAppCacheId; // = -1; - - // Factory method called internally by webkit_glue to create a concrete - // instance of this class. If SetFactory has been called, the factory - // function provided there is used to create a new instance, otherwise - // a noop implementation is returned. - static WebAppCacheContext* Create(); - - typedef WebAppCacheContext* (*WebAppCacheFactoryProc)(void); - static void SetFactory(WebAppCacheFactoryProc factory_proc); - - // Unique id within the child process housing this context - virtual int GetContextID() = 0; - - // Which appcache is associated with the context. There are windows of - // time where the appcache is not yet known, the return value is - // kUnknownAppCacheId in that case. - virtual int64 GetAppCacheID() = 0; - - // The following methods result in async messages being sent to the - // browser process. The initialize method tells the browser process about - // the existance of this context, its type and its id. The select methods - // tell the browser process to initiate the cache selection algorithm for - // the context. - virtual void Initialize(ContextType context_type, - WebAppCacheContext* opt_parent) = 0; - virtual void SelectAppCacheWithoutManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from) = 0; - virtual void SelectAppCacheWithManifest( - const GURL& document_url, - int64 cache_document_was_loaded_from, - const GURL& manifest_url) = 0; - - virtual ~WebAppCacheContext() {} -}; - -#endif // WEBKIT_GLUE_WEBAPPCACHECONTEXT_H_ diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index 706e957..fd1f34e 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -150,7 +150,9 @@ void PopulateURLResponse( response->setTextEncodingName(StdStringToWebString(info.charset)); response->setExpectedContentLength(info.content_length); response->setSecurityInfo(info.security_info); - response->setAppCacheID(info.app_cache_id); + response->setAppCacheID(info.appcache_id); + // TODO(michaeln): + // response->setAppCacheManifestUrl(info.appcache_manifest_url); const net::HttpResponseHeaders* headers = info.headers; if (!headers) diff --git a/webkit/tools/test_shell/simple_appcache_system.h b/webkit/tools/test_shell/simple_appcache_system.h new file mode 100644 index 0000000..6f53524 --- /dev/null +++ b/webkit/tools/test_shell/simple_appcache_system.h @@ -0,0 +1,25 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ +#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ + +#include "webkit/appcache/appcache_backend_impl.h" +#include "webkit/appcache/appcache_frontend_impl.h" + +class SimpleAppCacheSystem { + public: + void Initialize() { + backend_impl_.Initialize(NULL, &frontend_impl_); + } + + appcache::AppCacheBackend* backend() { return &backend_impl_; } + appcache::AppCacheFrontend* frontend() { return &frontend_impl_; } + + private: + appcache::AppCacheBackendImpl backend_impl_; + appcache::AppCacheFrontendImpl frontend_impl_; +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index e1137f8..c27f061 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -46,8 +46,8 @@ #include "net/http/http_response_headers.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" +#include "webkit/appcache/appcache_interfaces.h" #include "webkit/glue/resource_loader_bridge.h" -#include "webkit/glue/webappcachecontext.h" #include "webkit/tools/test_shell/test_shell_request_context.h" using webkit_glue::ResourceLoaderBridge; @@ -101,7 +101,7 @@ struct RequestParams { GURL referrer; std::string headers; int load_flags; - int app_cache_context_id; + int appcache_host_id; scoped_refptr<net::UploadData> upload; }; @@ -376,7 +376,8 @@ class RequestProxy : public URLRequest::Delegate, info->request_time = request->request_time(); info->response_time = request->response_time(); info->headers = request->response_headers(); - info->app_cache_id = WebAppCacheContext::kNoAppCacheId; + info->appcache_id = appcache::kNoCacheId; + // TODO(michaeln): info->appcache_manifest_url = GURL(); request->GetMimeType(&info->mime_type); request->GetCharset(&info->charset); info->content_length = request->GetExpectedContentSize(); @@ -468,7 +469,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { const GURL& referrer, const std::string& headers, int load_flags, - int app_cache_context_id) + int appcache_host_id) : params_(new RequestParams), proxy_(NULL) { params_->method = method; @@ -477,7 +478,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { params_->referrer = referrer; params_->headers = headers; params_->load_flags = load_flags; - params_->app_cache_context_id = app_cache_context_id; + params_->appcache_host_id = appcache_host_id; } virtual ~ResourceLoaderBridgeImpl() { @@ -611,11 +612,11 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create( int load_flags, int requestor_pid, ResourceType::Type request_type, - int app_cache_context_id, + int appcache_host_id, int routing_id) { return new ResourceLoaderBridgeImpl(method, url, first_party_for_cookies, referrer, headers, load_flags, - app_cache_context_id); + appcache_host_id); } // Issue the proxy resolve request on the io thread, and wait diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index eadd0b0..ef688dc 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -63,6 +63,7 @@ 'mock_webclipboard_impl.cc', 'mock_webclipboard_impl.h', 'resource.h', + 'simple_appcache_system.h', 'simple_clipboard_impl.cc', 'simple_resource_loader_bridge.cc', 'simple_resource_loader_bridge.h', diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index 9c758c7..2727d6b 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -16,6 +16,7 @@ #include "webkit/api/public/WebStorageNamespace.h" #include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" +#include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/glue/simple_webmimeregistry_impl.h" #include "webkit/glue/webclipboard_impl.h" #include "webkit/glue/webkit_glue.h" @@ -23,6 +24,7 @@ #include "webkit/extensions/v8/gears_extension.h" #include "webkit/extensions/v8/interval_extension.h" #include "webkit/tools/test_shell/mock_webclipboard_impl.h" +#include "webkit/tools/test_shell/simple_appcache_system.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "v8/include/v8.h" @@ -40,6 +42,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { WebKit::enableV8SingleThreadMode(); WebKit::registerExtension(extensions_v8::GearsExtension::Get()); WebKit::registerExtension(extensions_v8::IntervalExtension::Get()); + appcache_system_.Initialize(); // Load libraries for media and enable the media player. FilePath module_path; @@ -144,10 +147,17 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { return WebKit::WebStorageNamespace::createSessionStorageNamespace(); } + virtual WebKit::WebApplicationCacheHost* createApplicationCacheHost( + WebKit::WebApplicationCacheHostClient* client) { + return new appcache::WebApplicationCacheHostImpl( + client, appcache_system_.backend()); + } + private: webkit_glue::SimpleWebMimeRegistryImpl mime_registry_; MockWebClipboardImpl mock_clipboard_; webkit_glue::WebClipboardImpl real_clipboard_; + SimpleAppCacheSystem appcache_system_; }; #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_ diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 279949a..74916a1 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -32,11 +32,11 @@ #include "webkit/api/public/WebURLError.h" #include "webkit/api/public/WebURLRequest.h" #include "webkit/api/public/WebURLResponse.h" +#include "webkit/appcache/appcache_interfaces.h" #include "webkit/glue/glue_serialize.h" #include "webkit/glue/media/buffered_data_source.h" #include "webkit/glue/media/media_resource_loader_bridge_factory.h" #include "webkit/glue/media/simple_data_source.h" -#include "webkit/glue/webappcachecontext.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/webkit_glue.h" @@ -197,7 +197,7 @@ WebKit::WebMediaPlayer* TestWebViewDelegate::CreateWebMediaPlayer( "null", // frame origin "null", // main_frame_origin base::GetCurrentProcId(), - WebAppCacheContext::kNoAppCacheContextId, + appcache::kNoHostId, 0); factory->AddFactory(webkit_glue::BufferedDataSource::CreateFactory( MessageLoop::current(), bridge_factory)); diff --git a/webkit/tools/test_shell/test_worker/test_worker_main.cc b/webkit/tools/test_shell/test_worker/test_worker_main.cc index aefbccb..02eaf32 100644 --- a/webkit/tools/test_shell/test_worker/test_worker_main.cc +++ b/webkit/tools/test_shell/test_worker/test_worker_main.cc @@ -157,7 +157,7 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create( int load_flags, int requestor_pid, ResourceType::Type request_type, - int app_cache_context_id, + int appcache_host_id, int routing_id) { return NULL; } diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 3204dcc..c228e47 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1232,11 +1232,20 @@ 'msvs_guid': '0B945915-31A7-4A07-A5B5-568D737A39B1', 'dependencies': [ '../build/temp_gyp/googleurl.gyp:googleurl', + 'webkit', ], 'sources': [ # This list contains all .h and .cc in appcache except for test code. + 'appcache/appcache_backend_impl.cc', + 'appcache/appcache_backend_impl.h', + 'appcache/appcache_frontend_impl.cc', + 'appcache/appcache_frontend_impl.h', + 'appcache/appcache_interfaces.cc', + 'appcache/appcache_interfaces.h', 'appcache/manifest_parser.cc', 'appcache/manifest_parser.h', + 'appcache/web_application_cache_host_impl.cc', + 'appcache/web_application_cache_host_impl.h', ], }, { @@ -1399,8 +1408,6 @@ 'glue/webaccessibilitymanager.h', 'glue/webaccessibilitymanager_impl.cc', 'glue/webaccessibilitymanager_impl.h', - 'glue/webappcachecontext.cc', - 'glue/webappcachecontext.h', 'glue/webclipboard_impl.cc', 'glue/webclipboard_impl.h', 'glue/webcursor.cc', |