#include "content/browser/service_worker/service_worker_request_handler.h"
+#include <string>
+
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/browser/service_worker/service_worker_utils.h"
#include "content/common/service_worker/service_worker_types.h"
#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_interceptor.h"
+#include "webkit/browser/blob/blob_storage_context.h"
namespace content {
int kUserDataKey; // Key value is not important.
class ServiceWorkerRequestInterceptor
- : public net::URLRequestJobFactory::ProtocolHandler {
+ : public net::URLRequestInterceptor {
public:
ServiceWorkerRequestInterceptor() {}
virtual ~ServiceWorkerRequestInterceptor() {}
- virtual net::URLRequestJob* MaybeCreateJob(
+ virtual net::URLRequestJob* MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
ServiceWorkerRequestHandler* handler =
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
};
+bool IsMethodSupportedForAppCache(const std::string& method) {
+ return (method == "GET") || (method == "HEAD");
+}
+
+bool IsSchemeAndMethodSupportedForAppCache(const net::URLRequest* request) {
+ return request->url().SchemeIsHTTPOrHTTPS() &&
+ IsMethodSupportedForAppCache(request->method());
+}
+
} // namespace
void ServiceWorkerRequestHandler::InitializeHandler(
net::URLRequest* request,
ServiceWorkerContextWrapper* context_wrapper,
+ webkit_blob::BlobStorageContext* blob_storage_context,
int process_id,
int provider_id,
- ResourceType::Type resource_type) {
- if (!ServiceWorkerUtils::IsFeatureEnabled())
+ ResourceType resource_type) {
+ if (!IsSchemeAndMethodSupportedForAppCache(request)) {
return;
+ }
if (!context_wrapper || !context_wrapper->context() ||
provider_id == kInvalidServiceWorkerProviderId) {
ServiceWorkerProviderHost* provider_host =
context_wrapper->context()->GetProviderHost(process_id, provider_id);
- if (!provider_host)
+ if (!provider_host || !provider_host->IsContextAlive())
return;
scoped_ptr<ServiceWorkerRequestHandler> handler(
- provider_host->CreateRequestHandler(resource_type));
+ provider_host->CreateRequestHandler(resource_type,
+ blob_storage_context->AsWeakPtr()));
if (!handler)
return;
request->GetUserData(&kUserDataKey));
}
-scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
+scoped_ptr<net::URLRequestInterceptor>
ServiceWorkerRequestHandler::CreateInterceptor() {
- return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
+ return scoped_ptr<net::URLRequestInterceptor>(
new ServiceWorkerRequestInterceptor);
}
ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
base::WeakPtr<ServiceWorkerContextCore> context,
base::WeakPtr<ServiceWorkerProviderHost> provider_host,
- ResourceType::Type resource_type)
+ base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context,
+ ResourceType resource_type)
: context_(context),
provider_host_(provider_host),
+ blob_storage_context_(blob_storage_context),
resource_type_(resource_type) {
}