Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorker.cpp

Issue 1701843002: ServiceWorker: Implement 'source' and 'origin' attributes of ExtendableMessageEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_focus_into_utils
Patch Set: fix oilpan build Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "modules/serviceworkers/ServiceWorker.h" 31 #include "modules/serviceworkers/ServiceWorker.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/MessagePort.h" 35 #include "core/dom/MessagePort.h"
36 #include "core/events/Event.h" 36 #include "core/events/Event.h"
37 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
38 #include "modules/EventTargetModules.h" 38 #include "modules/EventTargetModules.h"
39 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
39 #include "public/platform/WebMessagePortChannel.h" 40 #include "public/platform/WebMessagePortChannel.h"
40 #include "public/platform/WebString.h" 41 #include "public/platform/WebString.h"
41 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h" 42 #include "public/platform/modules/serviceworker/WebServiceWorkerState.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 const AtomicString& ServiceWorker::interfaceName() const 46 const AtomicString& ServiceWorker::interfaceName() const
46 { 47 {
47 return EventTargetNames::ServiceWorker; 48 return EventTargetNames::ServiceWorker;
48 } 49 }
49 50
50 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt ate) 51 void ServiceWorker::postMessage(ExecutionContext* context, PassRefPtr<Serialized ScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionSt ate)
51 { 52 {
53 if (!m_provider) {
54 exceptionState.throwDOMException(InvalidStateError, "Failed to post a me ssage: No associated provider is available.");
55 return;
56 }
falken 2016/03/02 09:02:48 Instead of keeping track of m_provider, would it b
nhiroki 2016/03/02 09:57:12 Good point. Changed!
57
52 // Disentangle the port in preparation for sending it to the remote context. 58 // Disentangle the port in preparation for sending it to the remote context.
53 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con text, ports, exceptionState); 59 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con text, ports, exceptionState);
54 if (exceptionState.hadException()) 60 if (exceptionState.hadException())
55 return; 61 return;
56 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) { 62 if (m_handle->serviceWorker()->state() == WebServiceWorkerStateRedundant) {
57 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in redundant state."); 63 exceptionState.throwDOMException(InvalidStateError, "ServiceWorker is in redundant state.");
58 return; 64 return;
59 } 65 }
60 66
61 if (message->containsTransferableArrayBuffer()) 67 if (message->containsTransferableArrayBuffer())
62 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni ngMessageLevel, "ServiceWorker cannot send an ArrayBuffer as a transferable obje ct yet. See http://crbug.com/511119")); 68 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni ngMessageLevel, "ServiceWorker cannot send an ArrayBuffer as a transferable obje ct yet. See http://crbug.com/511119"));
63 69
64 WebString messageString = message->toWireString(); 70 WebString messageString = message->toWireString();
65 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo rtChannelArray(channels.release()); 71 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo rtChannelArray(channels.release());
66 m_handle->serviceWorker()->postMessage(messageString, webChannels.leakPtr()) ; 72 m_handle->serviceWorker()->postMessage(m_provider, messageString, webChannel s.leakPtr());
67 } 73 }
68 74
69 void ServiceWorker::internalsTerminate() 75 void ServiceWorker::internalsTerminate()
70 { 76 {
71 m_handle->serviceWorker()->terminate(); 77 m_handle->serviceWorker()->terminate();
72 } 78 }
73 79
74 void ServiceWorker::dispatchStateChangeEvent() 80 void ServiceWorker::dispatchStateChangeEvent()
75 { 81 {
76 this->dispatchEvent(Event::create(EventTypeNames::statechange)); 82 this->dispatchEvent(Event::create(EventTypeNames::statechange));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return getOrCreate(executionContext, handle); 115 return getOrCreate(executionContext, handle);
110 } 116 }
111 117
112 bool ServiceWorker::hasPendingActivity() const 118 bool ServiceWorker::hasPendingActivity() const
113 { 119 {
114 if (!executionContext()) 120 if (!executionContext())
115 return false; 121 return false;
116 return m_handle->serviceWorker()->state() != WebServiceWorkerStateRedundant; 122 return m_handle->serviceWorker()->state() != WebServiceWorkerStateRedundant;
117 } 123 }
118 124
125 void ServiceWorker::contextDestroyed()
126 {
127 m_provider = nullptr;
128 }
129
119 ServiceWorker* ServiceWorker::getOrCreate(ExecutionContext* executionContext, Pa ssOwnPtr<WebServiceWorker::Handle> handle) 130 ServiceWorker* ServiceWorker::getOrCreate(ExecutionContext* executionContext, Pa ssOwnPtr<WebServiceWorker::Handle> handle)
120 { 131 {
121 if (!handle) 132 if (!handle)
122 return nullptr; 133 return nullptr;
123 134
124 ServiceWorker* existingWorker = static_cast<ServiceWorker*>(handle->serviceW orker()->proxy()); 135 ServiceWorker* existingWorker = static_cast<ServiceWorker*>(handle->serviceW orker()->proxy());
125 if (existingWorker) { 136 if (existingWorker) {
126 ASSERT(existingWorker->executionContext() == executionContext); 137 ASSERT(existingWorker->executionContext() == executionContext);
127 return existingWorker; 138 return existingWorker;
128 } 139 }
129 140
130 return new ServiceWorker(executionContext, handle); 141 return new ServiceWorker(executionContext, handle);
131 } 142 }
132 143
133 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<WebS erviceWorker::Handle> handle) 144 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<WebS erviceWorker::Handle> handle)
134 : AbstractWorker(executionContext) 145 : AbstractWorker(executionContext)
135 , m_handle(handle) 146 , m_handle(handle)
147 , m_provider(nullptr)
136 { 148 {
137 ASSERT(m_handle); 149 ASSERT(m_handle);
150
151 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext))
152 m_provider = client->provider();
138 m_handle->serviceWorker()->setProxy(this); 153 m_handle->serviceWorker()->setProxy(this);
139 } 154 }
140 155
141 ServiceWorker::~ServiceWorker() 156 ServiceWorker::~ServiceWorker()
142 { 157 {
143 } 158 }
144 159
145 } // namespace blink 160 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698