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

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

Issue 130693010: Rename NavigatorServiceWorkerInterface to ServiceWorkerContainer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 #include "config.h" 30 #include "config.h"
31 #include "modules/serviceworkers/NavigatorServiceWorkerInterface.h" 31 #include "modules/serviceworkers/ServiceWorkerContainer.h"
32 32
33 #include "RuntimeEnabledFeatures.h" 33 #include "RuntimeEnabledFeatures.h"
34 #include "bindings/v8/CallbackPromiseAdapter.h" 34 #include "bindings/v8/CallbackPromiseAdapter.h"
35 #include "bindings/v8/ScriptPromiseResolver.h" 35 #include "bindings/v8/ScriptPromiseResolver.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/frame/Frame.h" 38 #include "core/frame/Frame.h"
39 #include "core/loader/FrameLoaderClient.h" 39 #include "core/loader/FrameLoaderClient.h"
40 #include "modules/serviceworkers/RegistrationOptionList.h" 40 #include "modules/serviceworkers/RegistrationOptionList.h"
41 #include "modules/serviceworkers/ServiceWorker.h" 41 #include "modules/serviceworkers/ServiceWorker.h"
42 #include "modules/serviceworkers/ServiceWorkerError.h" 42 #include "modules/serviceworkers/ServiceWorkerError.h"
43 #include "public/platform/WebServiceWorkerProvider.h" 43 #include "public/platform/WebServiceWorkerProvider.h"
44 #include "public/platform/WebServiceWorkerProviderClient.h" 44 #include "public/platform/WebServiceWorkerProviderClient.h"
45 #include "public/platform/WebString.h" 45 #include "public/platform/WebString.h"
46 #include "public/platform/WebURL.h" 46 #include "public/platform/WebURL.h"
47 47
48 using blink::WebServiceWorkerProvider; 48 using blink::WebServiceWorkerProvider;
49 49
50 namespace WebCore { 50 namespace WebCore {
51 51
52 PassRefPtr<NavigatorServiceWorkerInterface> NavigatorServiceWorkerInterface::cre ate() 52 PassRefPtr<ServiceWorkerContainer> ServiceWorkerContainer::create()
53 { 53 {
54 return adoptRef(new NavigatorServiceWorkerInterface()); 54 return adoptRef(new ServiceWorkerContainer());
55 } 55 }
56 56
57 NavigatorServiceWorkerInterface::~NavigatorServiceWorkerInterface() 57 ServiceWorkerContainer::~ServiceWorkerContainer()
58 { 58 {
59 } 59 }
60 60
61 ScriptPromise NavigatorServiceWorkerInterface::registerServiceWorker(ExecutionCo ntext* executionContext, const String& url, const Dictionary& dictionary) 61 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ExecutionContext* ex ecutionContext, const String& url, const Dictionary& dictionary)
62 { 62 {
63 RegistrationOptionList options(dictionary); 63 RegistrationOptionList options(dictionary);
64 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 64 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
65 ScriptPromise promise = ScriptPromise::createPending(executionContext); 65 ScriptPromise promise = ScriptPromise::createPending(executionContext);
66 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext); 66 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext);
67 67
68 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 68 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
69 KURL patternURL = executionContext->completeURL(options.scope); 69 KURL patternURL = executionContext->completeURL(options.scope);
70 if (!documentOrigin->canRequest(patternURL)) { 70 if (!documentOrigin->canRequest(patternURL)) {
71 resolver->reject(DOMError::create(SecurityError, "Can only register for patterns in the document's origin.")); 71 resolver->reject(DOMError::create(SecurityError, "Can only register for patterns in the document's origin."));
72 return promise; 72 return promise;
73 } 73 }
74 74
75 KURL scriptURL = executionContext->completeURL(url); 75 KURL scriptURL = executionContext->completeURL(url);
76 if (!documentOrigin->canRequest(scriptURL)) { 76 if (!documentOrigin->canRequest(scriptURL)) {
77 resolver->reject(DOMError::create(SecurityError, "Script must be in docu ment's origin.")); 77 resolver->reject(DOMError::create(SecurityError, "Script must be in docu ment's origin."));
78 return promise; 78 return promise;
79 } 79 }
80 80
81 ensureProvider(executionContext)->registerServiceWorker(patternURL, scriptUR L, new CallbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, execu tionContext)); 81 ensureProvider(executionContext)->registerServiceWorker(patternURL, scriptUR L, new CallbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, execu tionContext));
82 return promise; 82 return promise;
83 } 83 }
84 84
85 ScriptPromise NavigatorServiceWorkerInterface::unregisterServiceWorker(Execution Context* executionContext, const String& pattern) 85 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext* executionContext, const String& pattern)
86 { 86 {
87 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 87 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
88 ScriptPromise promise = ScriptPromise::createPending(executionContext); 88 ScriptPromise promise = ScriptPromise::createPending(executionContext);
89 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext); 89 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext);
90 90
91 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); 91 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
92 KURL patternURL = executionContext->completeURL(pattern); 92 KURL patternURL = executionContext->completeURL(pattern);
93 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { 93 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) {
94 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo r patterns in the document's origin.")); 94 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo r patterns in the document's origin."));
95 95
96 return promise; 96 return promise;
97 } 97 }
98 98
99 ensureProvider(executionContext)->unregisterServiceWorker(patternURL, new Ca llbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionConte xt)); 99 ensureProvider(executionContext)->unregisterServiceWorker(patternURL, new Ca llbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionConte xt));
100 return promise; 100 return promise;
101 } 101 }
102 102
103 NavigatorServiceWorkerInterface::NavigatorServiceWorkerInterface() 103 ServiceWorkerContainer::ServiceWorkerContainer()
104 { 104 {
105 ScriptWrappable::init(this); 105 ScriptWrappable::init(this);
106 } 106 }
107 107
108 WebServiceWorkerProvider* NavigatorServiceWorkerInterface::ensureProvider(Execut ionContext* executionContext) 108 WebServiceWorkerProvider* ServiceWorkerContainer::ensureProvider(ExecutionContex t* executionContext)
109 { 109 {
110 if (!m_provider) { 110 if (!m_provider) {
111 // FIXME: This is temporarily hooked up here until we hook up to the loa ding process, or should be replaced with an interface that is dedicated for scri pting. 111 // FIXME: This is temporarily hooked up here until we hook up to the loa ding process, or should be replaced with an interface that is dedicated for scri pting.
112 m_provider = toDocument(executionContext)->frame()->loader().client()->c reateServiceWorkerProvider(nullptr); 112 m_provider = toDocument(executionContext)->frame()->loader().client()->c reateServiceWorkerProvider(nullptr);
113 } 113 }
114 return m_provider.get(); 114 return m_provider.get();
115 } 115 }
116 116
117 } // namespace WebCore 117 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.h ('k') | Source/modules/serviceworkers/ServiceWorkerContainer.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698