| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "bindings/core/v8/WorkerScriptController.h" | 34 #include "bindings/core/v8/WorkerScriptController.h" |
| 35 #include "core/dom/CrossThreadTask.h" | 35 #include "core/dom/CrossThreadTask.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/dom/MessagePort.h" | 38 #include "core/dom/MessagePort.h" |
| 39 #include "core/events/MessageEvent.h" | 39 #include "core/events/MessageEvent.h" |
| 40 #include "core/inspector/ConsoleMessage.h" | 40 #include "core/inspector/ConsoleMessage.h" |
| 41 #include "core/workers/WorkerGlobalScope.h" | 41 #include "core/workers/WorkerGlobalScope.h" |
| 42 #include "modules/geofencing/CircularGeofencingRegion.h" | 42 #include "modules/geofencing/CircularGeofencingRegion.h" |
| 43 #include "modules/geofencing/GeofencingEvent.h" | 43 #include "modules/geofencing/GeofencingEvent.h" |
| 44 #include "modules/notifications/NotificationEvent.h" |
| 44 #include "modules/push_messaging/PushEvent.h" | 45 #include "modules/push_messaging/PushEvent.h" |
| 45 #include "modules/serviceworkers/ExtendableEvent.h" | 46 #include "modules/serviceworkers/ExtendableEvent.h" |
| 46 #include "modules/serviceworkers/FetchEvent.h" | 47 #include "modules/serviceworkers/FetchEvent.h" |
| 47 #include "modules/serviceworkers/InstallEvent.h" | 48 #include "modules/serviceworkers/InstallEvent.h" |
| 48 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 49 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| 49 #include "modules/serviceworkers/WaitUntilObserver.h" | 50 #include "modules/serviceworkers/WaitUntilObserver.h" |
| 50 #include "platform/RuntimeEnabledFeatures.h" | 51 #include "platform/RuntimeEnabledFeatures.h" |
| 52 #include "public/platform/WebNotificationData.h" |
| 51 #include "public/platform/WebServiceWorkerEventResult.h" | 53 #include "public/platform/WebServiceWorkerEventResult.h" |
| 52 #include "public/platform/WebServiceWorkerRequest.h" | 54 #include "public/platform/WebServiceWorkerRequest.h" |
| 53 #include "public/web/WebSerializedScriptValue.h" | 55 #include "public/web/WebSerializedScriptValue.h" |
| 54 #include "public/web/WebServiceWorkerContextClient.h" | 56 #include "public/web/WebServiceWorkerContextClient.h" |
| 55 #include "web/WebEmbeddedWorkerImpl.h" | 57 #include "web/WebEmbeddedWorkerImpl.h" |
| 56 #include "wtf/Functional.h" | 58 #include "wtf/Functional.h" |
| 57 #include "wtf/PassOwnPtr.h" | 59 #include "wtf/PassOwnPtr.h" |
| 58 | 60 |
| 59 namespace blink { | 61 namespace blink { |
| 60 | 62 |
| 61 PassOwnPtr<ServiceWorkerGlobalScopeProxy> ServiceWorkerGlobalScopeProxy::create(
WebEmbeddedWorkerImpl& embeddedWorker, Document& document, WebServiceWorkerConte
xtClient& client) | 63 PassOwnPtr<ServiceWorkerGlobalScopeProxy> ServiceWorkerGlobalScopeProxy::create(
WebEmbeddedWorkerImpl& embeddedWorker, Document& document, WebServiceWorkerConte
xtClient& client) |
| 62 { | 64 { |
| 63 return adoptPtr(new ServiceWorkerGlobalScopeProxy(embeddedWorker, document,
client)); | 65 return adoptPtr(new ServiceWorkerGlobalScopeProxy(embeddedWorker, document,
client)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() | 68 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() |
| 67 { | 69 { |
| 68 } | 70 } |
| 69 | 71 |
| 70 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) | |
| 71 { | |
| 72 ASSERT(m_workerGlobalScope); | |
| 73 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::Install, eventID); | |
| 74 RefPtrWillBeRawPtr<Event> event(InstallEvent::create(EventTypeNames::install
, EventInit(), observer)); | |
| 75 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); | |
| 76 } | |
| 77 | |
| 78 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) | 72 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) |
| 79 { | 73 { |
| 80 ASSERT(m_workerGlobalScope); | 74 ASSERT(m_workerGlobalScope); |
| 81 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::Activate, eventID); | 75 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::Activate, eventID); |
| 82 RefPtrWillBeRawPtr<Event> event(ExtendableEvent::create(EventTypeNames::acti
vate, EventInit(), observer)); | 76 RefPtrWillBeRawPtr<Event> event(ExtendableEvent::create(EventTypeNames::acti
vate, EventInit(), observer)); |
| 83 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); | 77 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); |
| 84 } | 78 } |
| 85 | 79 |
| 86 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer
viceWorkerRequest& webRequest) | 80 void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID, const WebSer
viceWorkerRequest& webRequest) |
| 87 { | 81 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 observer->didDispatchEvent(); | 93 observer->didDispatchEvent(); |
| 100 } | 94 } |
| 101 | 95 |
| 102 void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof
encingEventType eventType, const WebString& regionID, const WebCircularGeofencin
gRegion& region) | 96 void ServiceWorkerGlobalScopeProxy::dispatchGeofencingEvent(int eventID, WebGeof
encingEventType eventType, const WebString& regionID, const WebCircularGeofencin
gRegion& region) |
| 103 { | 97 { |
| 104 ASSERT(m_workerGlobalScope); | 98 ASSERT(m_workerGlobalScope); |
| 105 const AtomicString& type = eventType == WebGeofencingEventTypeEnter ? EventT
ypeNames::geofenceenter : EventTypeNames::geofenceleave; | 99 const AtomicString& type = eventType == WebGeofencingEventTypeEnter ? EventT
ypeNames::geofenceenter : EventTypeNames::geofenceleave; |
| 106 m_workerGlobalScope->dispatchEvent(GeofencingEvent::create(type, regionID, C
ircularGeofencingRegion::create(regionID, region))); | 100 m_workerGlobalScope->dispatchEvent(GeofencingEvent::create(type, regionID, C
ircularGeofencingRegion::create(regionID, region))); |
| 107 } | 101 } |
| 108 | 102 |
| 103 void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) |
| 104 { |
| 105 ASSERT(m_workerGlobalScope); |
| 106 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::Install, eventID); |
| 107 RefPtrWillBeRawPtr<Event> event(InstallEvent::create(EventTypeNames::install
, EventInit(), observer)); |
| 108 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); |
| 109 } |
| 110 |
| 109 void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
e, const WebMessagePortChannelArray& webChannels) | 111 void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
e, const WebMessagePortChannelArray& webChannels) |
| 110 { | 112 { |
| 111 ASSERT(m_workerGlobalScope); | 113 ASSERT(m_workerGlobalScope); |
| 112 | 114 |
| 113 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(m_workerGlobalScope, webChannels); | 115 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::toMessagePortArray
(m_workerGlobalScope, webChannels); |
| 114 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); | 116 WebSerializedScriptValue value = WebSerializedScriptValue::fromString(messag
e); |
| 115 m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), val
ue)); | 117 m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), val
ue)); |
| 116 } | 118 } |
| 117 | 119 |
| 120 void ServiceWorkerGlobalScopeProxy::dispatchNotificationClickEvent(int eventID,
const WebNotificationData& data) |
| 121 { |
| 122 ASSERT(m_workerGlobalScope); |
| 123 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::NotificationClick, eventID); |
| 124 // FIXME: Initialize a Notification object based on |data|. |
| 125 NotificationEventInit eventInit; |
| 126 RefPtrWillBeRawPtr<Event> event(NotificationEvent::create(EventTypeNames::no
tificationclick, eventInit, observer)); |
| 127 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); |
| 128 } |
| 129 |
| 130 void ServiceWorkerGlobalScopeProxy::dispatchNotificationErrorEvent(int eventID,
const WebNotificationData& data) |
| 131 { |
| 132 ASSERT(m_workerGlobalScope); |
| 133 WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope,
WaitUntilObserver::NotificationError, eventID); |
| 134 // FIXME: Initialize a Notification object based on |data|. |
| 135 NotificationEventInit eventInit; |
| 136 RefPtrWillBeRawPtr<Event> event(NotificationEvent::create(EventTypeNames::no
tificationerror, eventInit, observer)); |
| 137 m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); |
| 138 } |
| 139 |
| 118 void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebStri
ng& data) | 140 void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebStri
ng& data) |
| 119 { | 141 { |
| 120 ASSERT(m_workerGlobalScope); | 142 ASSERT(m_workerGlobalScope); |
| 121 m_workerGlobalScope->dispatchEvent(PushEvent::create(EventTypeNames::push, d
ata)); | 143 m_workerGlobalScope->dispatchEvent(PushEvent::create(EventTypeNames::push, d
ata)); |
| 122 // TODO(mvanouwerkerk): Instead of calling didHandlePushEvent here, it | 144 // TODO(mvanouwerkerk): Instead of calling didHandlePushEvent here, it |
| 123 // should get called from WaitUntilObserver::decrementPendingActivity once | 145 // should get called from WaitUntilObserver::decrementPendingActivity once |
| 124 // the push event is hooked up to event.waitUntil (crbug.com/430888). | 146 // the push event is hooked up to event.waitUntil (crbug.com/430888). |
| 125 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->didHandlePushEven
t(eventID, WebServiceWorkerEventResultCompleted); | 147 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->didHandlePushEven
t(eventID, WebServiceWorkerEventResultCompleted); |
| 126 } | 148 } |
| 127 | 149 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 200 |
| 179 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy(WebEmbeddedWorkerIm
pl& embeddedWorker, Document& document, WebServiceWorkerContextClient& client) | 201 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy(WebEmbeddedWorkerIm
pl& embeddedWorker, Document& document, WebServiceWorkerContextClient& client) |
| 180 : m_embeddedWorker(embeddedWorker) | 202 : m_embeddedWorker(embeddedWorker) |
| 181 , m_document(document) | 203 , m_document(document) |
| 182 , m_client(client) | 204 , m_client(client) |
| 183 , m_workerGlobalScope(0) | 205 , m_workerGlobalScope(0) |
| 184 { | 206 { |
| 185 } | 207 } |
| 186 | 208 |
| 187 } // namespace blink | 209 } // namespace blink |
| OLD | NEW |