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

Side by Side Diff: Source/modules/serviceworkers/NavigatorServiceWorkerInterface.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
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30 #include "config.h"
31 #include "modules/serviceworkers/NavigatorServiceWorkerInterface.h"
32
33 #include "RuntimeEnabledFeatures.h"
34 #include "bindings/v8/CallbackPromiseAdapter.h"
35 #include "bindings/v8/ScriptPromiseResolver.h"
36 #include "core/dom/Document.h"
37 #include "core/dom/ExecutionContext.h"
38 #include "core/frame/Frame.h"
39 #include "core/loader/FrameLoaderClient.h"
40 #include "modules/serviceworkers/RegistrationOptionList.h"
41 #include "modules/serviceworkers/ServiceWorker.h"
42 #include "modules/serviceworkers/ServiceWorkerError.h"
43 #include "public/platform/WebServiceWorkerProvider.h"
44 #include "public/platform/WebServiceWorkerProviderClient.h"
45 #include "public/platform/WebString.h"
46 #include "public/platform/WebURL.h"
47
48 using blink::WebServiceWorkerProvider;
49
50 namespace WebCore {
51
52 PassRefPtr<NavigatorServiceWorkerInterface> NavigatorServiceWorkerInterface::cre ate()
53 {
54 return adoptRef(new NavigatorServiceWorkerInterface());
55 }
56
57 NavigatorServiceWorkerInterface::~NavigatorServiceWorkerInterface()
58 {
59 }
60
61 ScriptPromise NavigatorServiceWorkerInterface::registerServiceWorker(ExecutionCo ntext* executionContext, const String& url, const Dictionary& dictionary)
62 {
63 RegistrationOptionList options(dictionary);
64 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
65 ScriptPromise promise = ScriptPromise::createPending(executionContext);
66 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext);
67
68 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
69 KURL patternURL = executionContext->completeURL(options.scope);
70 if (!documentOrigin->canRequest(patternURL)) {
71 resolver->reject(DOMError::create(SecurityError, "Can only register for patterns in the document's origin."));
72 return promise;
73 }
74
75 KURL scriptURL = executionContext->completeURL(url);
76 if (!documentOrigin->canRequest(scriptURL)) {
77 resolver->reject(DOMError::create(SecurityError, "Script must be in docu ment's origin."));
78 return promise;
79 }
80
81 ensureProvider(executionContext)->registerServiceWorker(patternURL, scriptUR L, new CallbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, execu tionContext));
82 return promise;
83 }
84
85 ScriptPromise NavigatorServiceWorkerInterface::unregisterServiceWorker(Execution Context* executionContext, const String& pattern)
86 {
87 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
88 ScriptPromise promise = ScriptPromise::createPending(executionContext);
89 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, executionContext);
90
91 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
92 KURL patternURL = executionContext->completeURL(pattern);
93 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) {
94 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo r patterns in the document's origin."));
95
96 return promise;
97 }
98
99 ensureProvider(executionContext)->unregisterServiceWorker(patternURL, new Ca llbackPromiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionConte xt));
100 return promise;
101 }
102
103 NavigatorServiceWorkerInterface::NavigatorServiceWorkerInterface()
104 {
105 ScriptWrappable::init(this);
106 }
107
108 WebServiceWorkerProvider* NavigatorServiceWorkerInterface::ensureProvider(Execut ionContext* executionContext)
109 {
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.
112 m_provider = toDocument(executionContext)->frame()->loader().client()->c reateServiceWorkerProvider(nullptr);
113 }
114 return m_provider.get();
115 }
116
117 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698