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.
5 #ifndef CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
6 #define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
11 #include "base/basictypes.h"
12 #include "content/common/content_export.h"
13 #include "third_party/WebKit/public/platform/WebServiceWorkerState.h"
16 // This file is to have common definitions that are to be shared by
17 // browser and child process.
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;
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;
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(
41 const std::string& method,
42 const std::map<std::string, std::string>& headers);
43 ~ServiceWorkerFetchRequest();
47 std::map<std::string, std::string> headers;
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
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::string& method,
65 const std::map<std::string, std::string>& headers);
66 ~ServiceWorkerResponse();
69 std::string status_text;
71 std::map<std::string, std::string> headers;
74 // Represents initialization info for a WebServiceWorker object.
75 struct CONTENT_EXPORT ServiceWorkerObjectInfo {
76 ServiceWorkerObjectInfo();
80 blink::WebServiceWorkerState state;
83 } // namespace content
85 #endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_