Home | History | Annotate | Download | only in service_worker
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
      6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
      7 
      8 #include "content/browser/service_worker/service_worker_request_handler.h"
      9 
     10 namespace net {
     11 class NetworkDelegate;
     12 class URLRequest;
     13 }
     14 
     15 namespace content {
     16 
     17 class ServiceWorkerRegistration;
     18 class ServiceWorkerURLRequestJob;
     19 
     20 // A request handler derivative used to handle requests from
     21 // controlled documents.
     22 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
     23     : public ServiceWorkerRequestHandler {
     24  public:
     25   ServiceWorkerControlleeRequestHandler(
     26       base::WeakPtr<ServiceWorkerContextCore> context,
     27       base::WeakPtr<ServiceWorkerProviderHost> provider_host,
     28       base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context,
     29       ResourceType::Type resource_type);
     30   virtual ~ServiceWorkerControlleeRequestHandler();
     31 
     32   // Called via custom URLRequestJobFactory.
     33   virtual net::URLRequestJob* MaybeCreateJob(
     34       net::URLRequest* request,
     35       net::NetworkDelegate* network_delegate) OVERRIDE;
     36 
     37  private:
     38   typedef ServiceWorkerControlleeRequestHandler self;
     39 
     40   // For main resource case.
     41   void PrepareForMainResource(const GURL& url);
     42   void DidLookupRegistrationForMainResource(
     43       ServiceWorkerStatusCode status,
     44       const scoped_refptr<ServiceWorkerRegistration>& registration);
     45 
     46   // For sub resource case.
     47   void PrepareForSubResource();
     48 
     49   scoped_refptr<ServiceWorkerURLRequestJob> job_;
     50   base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_;
     51 
     52   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler);
     53 };
     54 
     55 }  // namespace content
     56 
     57 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
     58