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

Side by Side Diff: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp

Issue 2168513004: [DO NOT COMMIT] ServiceWorker: First touch of mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove an unnecessary file Created 4 years, 4 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/ServiceWorkerGlobalScopeClientImpl.h" 31 #include "web/ServiceWorkerGlobalScopeClientImpl.h"
32 32
33 #include "modules/fetch/Response.h" 33 #include "modules/fetch/Response.h"
34 #include "modules/serviceworkers/FetchEvent.h"
35 #include "modules/serviceworkers/ForeignFetchEvent.h"
36 #include "modules/serviceworkers/WaitUntilObserver.h"
37 #include "platform/heap/ThreadState.h"
38 #include "public/platform/ServiceRegistry.h"
34 #include "public/platform/WebURL.h" 39 #include "public/platform/WebURL.h"
40 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
35 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" 41 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
36 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" 42 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
37 #include <memory> 43 #include <memory>
38 44
45 namespace {
46 void printIsMainThread_internal(const char* pretty_function, int line) {
47 LOG(ERROR) << "[" << pretty_function << ":" << line << "] "
48 << ((blink::ThreadState::current()->isMainThread()) ? "true" : "fal se");
49 }
50 }
51 #define printIsMainThread() printIsMainThread_internal(__PRETTY_FUNCTION__, __LI NE__)
52 #define cerrWithHeader() LOG(ERROR) << "[" << __PRETTY_FUNCTION__ << ":" << __LI NE__ << "] "
53
54
39 namespace blink { 55 namespace blink {
40 56
41 ServiceWorkerGlobalScopeClient* ServiceWorkerGlobalScopeClientImpl::create(WebSe rviceWorkerContextClient& client) 57 ServiceWorkerGlobalScopeClient* ServiceWorkerGlobalScopeClientImpl::create(WebSe rviceWorkerContextClient& client)
42 { 58 {
59 printIsMainThread();
43 return new ServiceWorkerGlobalScopeClientImpl(client); 60 return new ServiceWorkerGlobalScopeClientImpl(client);
44 } 61 }
45 62
46 ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl() 63 ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl()
47 { 64 {
65 printIsMainThread();
66 }
67
68 void ServiceWorkerGlobalScopeClientImpl::dispose()
69 {
70 printIsMainThread();
71 m_clientBinding->Close();
72 m_hostProcess.reset();
48 } 73 }
49 74
50 void ServiceWorkerGlobalScopeClientImpl::getClient(const WebString& id, WebServi ceWorkerClientCallbacks* callbacks) 75 void ServiceWorkerGlobalScopeClientImpl::getClient(const WebString& id, WebServi ceWorkerClientCallbacks* callbacks)
51 { 76 {
52 m_client.getClient(id, callbacks); 77 m_client.getClient(id, callbacks);
53 } 78 }
54 79
55 void ServiceWorkerGlobalScopeClientImpl::getClients(const WebServiceWorkerClient QueryOptions& options, WebServiceWorkerClientsCallbacks* callbacks) 80 void ServiceWorkerGlobalScopeClientImpl::getClients(const WebServiceWorkerClient QueryOptions& options, WebServiceWorkerClientsCallbacks* callbacks)
56 { 81 {
57 m_client.getClients(options, callbacks); 82 m_client.getClients(options, callbacks);
(...skipping 12 matching lines...) Expand all
70 void ServiceWorkerGlobalScopeClientImpl::clearCachedMetadata(const WebURL& url) 95 void ServiceWorkerGlobalScopeClientImpl::clearCachedMetadata(const WebURL& url)
71 { 96 {
72 m_client.clearCachedMetadata(url); 97 m_client.clearCachedMetadata(url);
73 } 98 }
74 99
75 WebURL ServiceWorkerGlobalScopeClientImpl::scope() const 100 WebURL ServiceWorkerGlobalScopeClientImpl::scope() const
76 { 101 {
77 return m_client.scope(); 102 return m_client.scope();
78 } 103 }
79 104
105 void ServiceWorkerGlobalScopeClientImpl::didInitializeContext(ServiceWorkerGloba lScope* parent) {
106 // This should be reclaimed on the worker thread
107 ThreadState::current()->registerPreFinalizer(this);
108 printIsMainThread();
109 m_parent = parent;
110 m_clientBinding.reset(new mojo::Binding<mojom::blink::ServiceWorkerGlobalSco peClient>(this));
111 m_client.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_hostPro cess));
112 m_hostProcess->SetClient(m_clientBinding->CreateInterfacePtrAndBind());
113 }
114
80 void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, Web ServiceWorkerEventResult result) 115 void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, Web ServiceWorkerEventResult result)
81 { 116 {
82 m_client.didHandleActivateEvent(eventID, result); 117 m_client.didHandleActivateEvent(eventID, result);
83 } 118 }
84 119
85 void ServiceWorkerGlobalScopeClientImpl::didHandleExtendableMessageEvent(int eve ntID, WebServiceWorkerEventResult result) 120 void ServiceWorkerGlobalScopeClientImpl::didHandleExtendableMessageEvent(int eve ntID, WebServiceWorkerEventResult result)
86 { 121 {
87 m_client.didHandleExtendableMessageEvent(eventID, result); 122 m_client.didHandleExtendableMessageEvent(eventID, result);
88 } 123 }
89 124
90 void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID) 125 void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID)
91 { 126 {
127 if (m_fetchCallbacks.contains(responseID)) {
128 LOG(ERROR) << "MOJOMOJOMOJO respond: fallback";
129 auto callback = m_fetchCallbacks.take(responseID);
130 callback.Run(false, nullptr);
131 return;
132 }
133
92 m_client.respondToFetchEvent(responseID); 134 m_client.respondToFetchEvent(responseID);
93 } 135 }
94 136
95 void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID, con st WebServiceWorkerResponse& response) 137 void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID, con st WebServiceWorkerResponse& response)
96 { 138 {
97 m_client.respondToFetchEvent(responseID, response); 139 if (m_fetchCallbacks.contains(responseID)) {
140 LOG(ERROR) << "MOJOMOJOMOJO respond: response";
141 auto callback = m_fetchCallbacks.take(responseID);
142 auto mojoResponse = mojom::blink::ServiceWorkerResponse::New();
143 mojoResponse->url = response.url().string();
144 mojoResponse->status_code = response.status();
145 mojoResponse->status_text = response.statusText();
146 mojoResponse->blob_uuid = response.blobUUID();
147 mojoResponse->blob_size = response.blobSize();
148 mojoResponse->stream_url = response.streamURL().string();
149 callback.Run(true, std::move(mojoResponse));
150 return;
151 }
152
153 m_client.respondToFetchEvent(responseID, response);
98 } 154 }
99 155
100 void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int eventFinishID, WebServiceWorkerEventResult result) 156 void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int eventFinishID, WebServiceWorkerEventResult result)
101 { 157 {
102 m_client.didHandleFetchEvent(eventFinishID, result); 158 m_hostProcess->DidHandleSimpleEvent(eventFinishID, result);
159 // m_client.didHandleFetchEvent(eventFinishID, result);
103 } 160 }
104 161
105 void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventI D, WebServiceWorkerEventResult result) 162 void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventI D, WebServiceWorkerEventResult result)
106 { 163 {
107 m_client.didHandleInstallEvent(installEventID, result); 164 m_client.didHandleInstallEvent(installEventID, result);
108 } 165 }
109 166
110 void ServiceWorkerGlobalScopeClientImpl::didHandleNotificationClickEvent(int eve ntID, WebServiceWorkerEventResult result) 167 void ServiceWorkerGlobalScopeClientImpl::didHandleNotificationClickEvent(int eve ntID, WebServiceWorkerEventResult result)
111 { 168 {
112 m_client.didHandleNotificationClickEvent(eventID, result); 169 m_client.didHandleNotificationClickEvent(eventID, result);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void ServiceWorkerGlobalScopeClientImpl::navigate(const WebString& clientUUID, c onst WebURL& url, WebServiceWorkerClientCallbacks* callback) 212 void ServiceWorkerGlobalScopeClientImpl::navigate(const WebString& clientUUID, c onst WebURL& url, WebServiceWorkerClientCallbacks* callback)
156 { 213 {
157 m_client.navigate(clientUUID, url, callback); 214 m_client.navigate(clientUUID, url, callback);
158 } 215 }
159 216
160 void ServiceWorkerGlobalScopeClientImpl::registerForeignFetchScopes(const WebVec tor<WebURL>& subScopes, const WebVector<WebSecurityOrigin>& origins) 217 void ServiceWorkerGlobalScopeClientImpl::registerForeignFetchScopes(const WebVec tor<WebURL>& subScopes, const WebVector<WebSecurityOrigin>& origins)
161 { 218 {
162 m_client.registerForeignFetchScopes(subScopes, origins); 219 m_client.registerForeignFetchScopes(subScopes, origins);
163 } 220 }
164 221
222 void ServiceWorkerGlobalScopeClientImpl::DispatchPingEvent(const WTF::String& me ssage)
223 {
224 LOG(ERROR) << __PRETTY_FUNCTION__;
225 return;
226 }
227
228 void ServiceWorkerGlobalScopeClientImpl::DispatchFetchEvent(int responseID, int eventFinishID, mojom::blink::ServiceWorkerFetchRequestPtr mojoRequest, const Dis patchFetchEventCallback& callback) {
229 LOG(ERROR) << "(request: " << mojoRequest->url.getString().ascii().data() << ")";
230
231 m_fetchCallbacks.set(responseID, callback);
232
233 WebServiceWorkerRequest webRequest;
234 ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptS tate());
235 WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGloba lScope(), WaitUntilObserver::Fetch, eventFinishID);
236 RespondWithObserver* respondWithObserver = RespondWithObserver::create(worke rGlobalScope(), responseID, webRequest.url(), webRequest.mode(), webRequest.fram eType(), webRequest.requestContext(), waitUntilObserver);
237 Request* request = Request::create(workerGlobalScope()->scriptController()-> getScriptState(), webRequest);
238 request->getHeaders()->setGuard(Headers::ImmutableGuard);
239 FetchEventInit eventInit;
240 eventInit.setCancelable(true);
241 eventInit.setRequest(request);
242 eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webReq uest.clientId());
243 eventInit.setIsReload(webRequest.isReload());
244 FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptContr oller()->getScriptState(), EventTypeNames::fetch, eventInit, respondWithObserver , waitUntilObserver);
245 waitUntilObserver->willDispatchEvent();
246 DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetc hEvent);
247 respondWithObserver->didDispatchEvent(dispatchResult);
248 // false is okay because waitUntil for fetch event doesn't care about the
249 // promise rejection or an uncaught runtime script error.
250 waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
251 }
252
253
165 ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(WebServic eWorkerContextClient& client) 254 ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(WebServic eWorkerContextClient& client)
166 : m_client(client) 255 : m_client(client)
167 { 256 {
168 } 257 }
169 258
259 mojom::blink::ServiceWorkerGlobalScopeHostPtr& ServiceWorkerGlobalScopeClientImp l::hostProcess()
260 {
261 if (!m_hostProcess) {
262 m_client.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_hos tProcess));
263 m_hostProcess->SetClient(m_clientBinding->CreateInterfacePtrAndBind());
264 }
265 return m_hostProcess;
266 }
267
268 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeClientImpl::workerGlobalScope( )
269 {
270 return m_parent.get();
271 }
272
170 } // namespace blink 273 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698