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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerRegistration.cpp

Issue 469273002: ServiceWorker: Fix ServiceWorkerRegistration object handling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerRegistration.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "ServiceWorkerRegistration.h" 6 #include "ServiceWorkerRegistration.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 deleteIfNoExistingOwner(serviceWorker); 81 deleteIfNoExistingOwner(serviceWorker);
82 return; 82 return;
83 } 83 }
84 m_active = ServiceWorker::from(executionContext(), serviceWorker); 84 m_active = ServiceWorker::from(executionContext(), serviceWorker);
85 } 85 }
86 86
87 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak e(ScriptPromiseResolver* resolver, WebType* registration) 87 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak e(ScriptPromiseResolver* resolver, WebType* registration)
88 { 88 {
89 if (!registration) 89 if (!registration)
90 return nullptr; 90 return nullptr;
91 return getOrCreate(resolver->scriptState()->executionContext(), adoptPtr(reg istration)); 91 return getOrCreate(resolver->scriptState()->executionContext(), registration );
92 } 92 }
93 93
94 void ServiceWorkerRegistration::dispose(WebType* registration) 94 void ServiceWorkerRegistration::dispose(WebType* registration)
95 { 95 {
96 delete registration; 96 delete registration;
97 } 97 }
98 98
99 String ServiceWorkerRegistration::scope() const 99 String ServiceWorkerRegistration::scope() const
100 { 100 {
101 return m_outerRegistration->scope().string(); 101 return m_outerRegistration->scope().string();
(...skipping 14 matching lines...) Expand all
116 scopeURL.removeFragmentIdentifier(); 116 scopeURL.removeFragmentIdentifier();
117 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) { 117 if (!scope().isEmpty() && !documentOrigin->canRequest(scopeURL)) {
118 resolver->reject(DOMException::create(SecurityError, "Can only unregiste r for scopes in the document's origin.")); 118 resolver->reject(DOMException::create(SecurityError, "Can only unregiste r for scopes in the document's origin."));
119 return promise; 119 return promise;
120 } 120 }
121 121
122 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und efinedValue, ServiceWorkerError>(resolver)); 122 m_provider->unregisterServiceWorker(scopeURL, new CallbackPromiseAdapter<Und efinedValue, ServiceWorkerError>(resolver));
123 return promise; 123 return promise;
124 } 124 }
125 125
126 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get OrCreate(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistra tion> outerRegistration) 126 PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::get OrCreate(ExecutionContext* executionContext, WebServiceWorkerRegistration* outer Registration)
127 { 127 {
128 if (!outerRegistration) 128 if (!outerRegistration)
129 return nullptr; 129 return nullptr;
130 130
131 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy(); 131 WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy();
132 if (proxy) { 132 if (proxy) {
133 ServiceWorkerRegistration* existingRegistration = *proxy; 133 ServiceWorkerRegistration* existingRegistration = *proxy;
134 if (existingRegistration) { 134 if (existingRegistration) {
135 ASSERT(existingRegistration->executionContext() == executionContext) ; 135 ASSERT(existingRegistration->executionContext() == executionContext) ;
136 return existingRegistration; 136 return existingRegistration;
137 } 137 }
138 } 138 }
139 139
140 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeR efCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerR egistration)); 140 RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeR efCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, adoptP tr(outerRegistration)));
141 registration->suspendIfNeeded(); 141 registration->suspendIfNeeded();
142 return registration.release(); 142 return registration.release();
143 } 143 }
144 144
145 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) 145 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration)
146 : ActiveDOMObject(executionContext) 146 : ActiveDOMObject(executionContext)
147 , WebServiceWorkerRegistrationProxy(this) 147 , WebServiceWorkerRegistrationProxy(this)
148 , m_outerRegistration(outerRegistration) 148 , m_outerRegistration(outerRegistration)
149 , m_provider(0) 149 , m_provider(0)
150 { 150 {
151 ASSERT(m_outerRegistration); 151 ASSERT(m_outerRegistration);
152 ScriptWrappable::init(this); 152 ScriptWrappable::init(this);
153 153
154 if (!executionContext) 154 if (!executionContext)
155 return; 155 return;
156 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) 156 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext))
157 m_provider = client->provider(); 157 m_provider = client->provider();
158 m_outerRegistration->setProxy(this); 158 m_outerRegistration->setProxy(this);
159 } 159 }
160 160
161 void ServiceWorkerRegistration::trace(Visitor* visitor) 161 void ServiceWorkerRegistration::trace(Visitor* visitor)
162 { 162 {
163 visitor->trace(m_installing); 163 visitor->trace(m_installing);
164 visitor->trace(m_waiting); 164 visitor->trace(m_waiting);
165 visitor->trace(m_active); 165 visitor->trace(m_active);
166 EventTargetWithInlineData::trace(visitor); 166 EventTargetWithInlineData::trace(visitor);
167 } 167 }
168 168
169 } // namespace blink 169 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerRegistration.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698