1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
#define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/id_map.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/renderer/service_worker/service_worker_cache_storage_dispatcher.h"
#include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerClientFocusCallback.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerSkipWaitingCallbacks.h"
namespace blink {
struct WebCircularGeofencingRegion;
struct WebCrossOriginServiceWorkerClient;
class WebServiceWorkerContextProxy;
}
namespace IPC {
class Message;
}
namespace content {
struct CrossOriginServiceWorkerClient;
class EmbeddedWorkerContextClient;
struct PlatformNotificationData;
// TODO(kinuko): This should implement WebServiceWorkerContextClient
// rather than having EmbeddedWorkerContextClient implement it.
// See the header comment in embedded_worker_context_client.h for the
// potential EW/SW layering concerns.
class ServiceWorkerScriptContext {
public:
ServiceWorkerScriptContext(
EmbeddedWorkerContextClient* embedded_context,
blink::WebServiceWorkerContextProxy* proxy);
~ServiceWorkerScriptContext();
void OnMessageReceived(const IPC::Message& message);
void DidHandleActivateEvent(int request_id,
blink::WebServiceWorkerEventResult);
void DidHandleInstallEvent(int request_id,
blink::WebServiceWorkerEventResult result);
void DidHandleFetchEvent(int request_id,
ServiceWorkerFetchEventResult result,
const ServiceWorkerResponse& response);
void DidHandleNotificationClickEvent(
int request_id,
blink::WebServiceWorkerEventResult result);
void DidHandlePushEvent(int request_id,
blink::WebServiceWorkerEventResult result);
void DidHandleSyncEvent(int request_id);
void DidHandleCrossOriginConnectEvent(int request_id, bool accept_connection);
void GetClientDocuments(
blink::WebServiceWorkerClientsCallbacks* callbacks);
void PostMessageToDocument(
int client_id,
const base::string16& message,
scoped_ptr<blink::WebMessagePortChannelArray> channels);
void PostCrossOriginMessageToClient(
const blink::WebCrossOriginServiceWorkerClient& client,
const base::string16& message,
scoped_ptr<blink::WebMessagePortChannelArray> channels);
void FocusClient(int client_id,
blink::WebServiceWorkerClientFocusCallback* callback);
void SkipWaiting(blink::WebServiceWorkerSkipWaitingCallbacks* callbacks);
// Send a message to the browser. Takes ownership of |message|.
void Send(IPC::Message* message);
// Get routing_id for sending message to the ServiceWorkerVersion
// in the browser process.
int GetRoutingID() const;
blink::WebServiceWorkerCacheStorage* cache_storage() {
return cache_storage_dispatcher_.get();
}
private:
typedef IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>
ClientsCallbacksMap;
typedef IDMap<blink::WebServiceWorkerClientFocusCallback, IDMapOwnPointer>
FocusClientCallbacksMap;
typedef IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>
SkipWaitingCallbacksMap;
void OnActivateEvent(int request_id);
void OnInstallEvent(int request_id, int active_version_id);
void OnFetchEvent(int request_id, const ServiceWorkerFetchRequest& request);
void OnSyncEvent(int request_id);
void OnNotificationClickEvent(
int request_id,
const std::string& notification_id,
const PlatformNotificationData& notification_data);
void OnPushEvent(int request_id, const std::string& data);
void OnGeofencingEvent(int request_id,
blink::WebGeofencingEventType event_type,
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region);
void OnCrossOriginConnectEvent(int request_id,
const CrossOriginServiceWorkerClient& client);
void OnPostMessage(const base::string16& message,
const std::vector<int>& sent_message_port_ids,
const std::vector<int>& new_routing_ids);
void OnCrossOriginMessageToWorker(
const CrossOriginServiceWorkerClient& client,
const base::string16& message,
const std::vector<int>& sent_message_port_ids,
const std::vector<int>& new_routing_ids);
void OnDidGetClientDocuments(
int request_id, const std::vector<ServiceWorkerClientInfo>& clients);
void OnFocusClientResponse(int request_id, bool result);
void OnDidSkipWaiting(int request_id);
scoped_ptr<ServiceWorkerCacheStorageDispatcher> cache_storage_dispatcher_;
// Not owned; embedded_context_ owns this.
EmbeddedWorkerContextClient* embedded_context_;
// Not owned; this object is destroyed when proxy_ becomes invalid.
blink::WebServiceWorkerContextProxy* proxy_;
// Used for incoming messages from the browser for which an outgoing response
// back to the browser is expected, the id must be sent back with the
// response.
int current_request_id_;
// Pending callbacks for GetClientDocuments().
ClientsCallbacksMap pending_clients_callbacks_;
// Pending callbacks for FocusClient().
FocusClientCallbacksMap pending_focus_client_callbacks_;
// Pending callbacks for SkipWaiting().
SkipWaitingCallbacksMap pending_skip_waiting_callbacks_;
// Capture timestamps for UMA
std::map<int, base::TimeTicks> activate_start_timings_;
std::map<int, base::TimeTicks> fetch_start_timings_;
std::map<int, base::TimeTicks> install_start_timings_;
std::map<int, base::TimeTicks> notification_click_start_timings_;
std::map<int, base::TimeTicks> push_start_timings_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptContext);
};
} // namespace content
#endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CONTEXT_H_
|