Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_request_handler.cc
index 7b615b3..300ea00 100644 (file)
 #include "content/browser/service_worker/service_worker_registration.h"
 #include "content/browser/service_worker/service_worker_url_request_job.h"
 #include "content/browser/service_worker/service_worker_utils.h"
+#include "content/common/resource_request_body.h"
 #include "content/common/service_worker/service_worker_types.h"
+#include "net/base/net_util.h"
 #include "net/url_request/url_request.h"
 #include "net/url_request/url_request_interceptor.h"
-#include "webkit/browser/blob/blob_storage_context.h"
+#include "storage/browser/blob/blob_storage_context.h"
 
 namespace content {
 
@@ -42,13 +44,11 @@ class ServiceWorkerRequestInterceptor
   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());
+// This is work around to avoid hijacking CORS preflight.
+// TODO(horo): Remove this check when we implement "HTTP fetch" correctly.
+// http://fetch.spec.whatwg.org/#concept-http-fetch
+bool IsMethodSupportedForServiceWroker(const std::string& method) {
+  return method != "OPTIONS";
 }
 
 }  // namespace
@@ -56,11 +56,14 @@ bool IsSchemeAndMethodSupportedForAppCache(const net::URLRequest* request) {
 void ServiceWorkerRequestHandler::InitializeHandler(
     net::URLRequest* request,
     ServiceWorkerContextWrapper* context_wrapper,
-    webkit_blob::BlobStorageContext* blob_storage_context,
+    storage::BlobStorageContext* blob_storage_context,
     int process_id,
     int provider_id,
-    ResourceType resource_type) {
-  if (!IsSchemeAndMethodSupportedForAppCache(request)) {
+    bool skip_service_worker,
+    ResourceType resource_type,
+    scoped_refptr<ResourceRequestBody> body) {
+  if (!request->url().SchemeIsHTTPOrHTTPS() ||
+      !IsMethodSupportedForServiceWroker(request->method())) {
     return;
   }
 
@@ -74,9 +77,15 @@ void ServiceWorkerRequestHandler::InitializeHandler(
   if (!provider_host || !provider_host->IsContextAlive())
     return;
 
+  if (skip_service_worker) {
+    if (ServiceWorkerUtils::IsMainResourceType(resource_type))
+      provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url()));
+    return;
+  }
+
   scoped_ptr<ServiceWorkerRequestHandler> handler(
-      provider_host->CreateRequestHandler(resource_type,
-                                          blob_storage_context->AsWeakPtr()));
+      provider_host->CreateRequestHandler(
+          resource_type, blob_storage_context->AsWeakPtr(), body));
   if (!handler)
     return;
 
@@ -101,7 +110,7 @@ ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() {
 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
     base::WeakPtr<ServiceWorkerContextCore> context,
     base::WeakPtr<ServiceWorkerProviderHost> provider_host,
-    base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context,
+    base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
     ResourceType resource_type)
     : context_(context),
       provider_host_(provider_host),