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_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_ 6 #define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "content/common/content_export.h" 13 #include "third_party/WebKit/public/platform/WebServiceWorkerState.h" 14 #include "url/gurl.h" 15 16 // This file is to have common definitions that are to be shared by 17 // browser and child process. 18 19 namespace content { 20 21 // Indicates invalid request ID (i.e. the sender does not expect it gets 22 // response for the message) for messaging between browser process 23 // and embedded worker. 24 const static int kInvalidServiceWorkerRequestId = -1; 25 26 // Constants for invalid identifiers. 27 const static int kInvalidServiceWorkerHandleId = -1; 28 const static int kInvalidServiceWorkerProviderId = -1; 29 const static int64 kInvalidServiceWorkerRegistrationId = -1; 30 const static int64 kInvalidServiceWorkerVersionId = -1; 31 const static int64 kInvalidServiceWorkerResourceId = -1; 32 const static int64 kInvalidServiceWorkerResponseId = -1; 33 34 // To dispatch fetch request from browser to child process. 35 // TODO(kinuko): This struct will definitely need more fields and 36 // we'll probably want to have response struct/class too. 37 struct CONTENT_EXPORT ServiceWorkerFetchRequest { 38 ServiceWorkerFetchRequest(); 39 ServiceWorkerFetchRequest( 40 const GURL& url, 41 const std::string& method, 42 const std::map<std::string, std::string>& headers); 43 ~ServiceWorkerFetchRequest(); 44 45 GURL url; 46 std::string method; 47 std::map<std::string, std::string> headers; 48 }; 49 50 // Indicates how the service worker handled a fetch event. 51 enum ServiceWorkerFetchEventResult { 52 // Browser should fallback to native fetch. 53 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, 54 // Service worker provided a ServiceWorkerResponse. 55 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, 56 SERVICE_WORKER_FETCH_EVENT_LAST = SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE 57 }; 58 59 // Represents a response to a fetch. 60 struct CONTENT_EXPORT ServiceWorkerResponse { 61 ServiceWorkerResponse(); 62 ServiceWorkerResponse(int status_code, 63 const std::string& status_text, 64 const std::map<std::string, std::string>& headers, 65 const std::string& blob_uuid); 66 ~ServiceWorkerResponse(); 67 68 int status_code; 69 std::string status_text; 70 std::map<std::string, std::string> headers; 71 std::string blob_uuid; 72 }; 73 74 // Represents initialization info for a WebServiceWorker object. 75 struct CONTENT_EXPORT ServiceWorkerObjectInfo { 76 ServiceWorkerObjectInfo(); 77 int handle_id; 78 GURL scope; 79 GURL url; 80 blink::WebServiceWorkerState state; 81 }; 82 83 } // namespace content 84 85 #endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_ 86