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

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

Issue 26078002: Rename WebServiceWorkerRegistry to WebServiceWorkerProvider (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Insert origin url into requests Created 7 years, 2 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 23 matching lines...) Expand all
34 #include "V8ServiceWorker.h" 34 #include "V8ServiceWorker.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/loader/DocumentLoader.h" 37 #include "core/loader/DocumentLoader.h"
38 #include "core/loader/FrameLoaderClient.h" 38 #include "core/loader/FrameLoaderClient.h"
39 #include "core/page/Frame.h" 39 #include "core/page/Frame.h"
40 #include "core/page/Navigator.h" 40 #include "core/page/Navigator.h"
41 #include "core/workers/SharedWorker.h" 41 #include "core/workers/SharedWorker.h"
42 #include "modules/serviceworkers/CallbackPromiseAdapter.h" 42 #include "modules/serviceworkers/CallbackPromiseAdapter.h"
43 #include "modules/serviceworkers/ServiceWorker.h" 43 #include "modules/serviceworkers/ServiceWorker.h"
44 #include "public/platform/WebServiceWorkerRegistry.h" 44 #include "public/platform/WebServiceWorkerProvider.h"
45 #include "public/platform/WebServiceWorkerProviderClient.h"
45 #include "public/platform/WebString.h" 46 #include "public/platform/WebString.h"
46 #include "public/platform/WebURL.h" 47 #include "public/platform/WebURL.h"
47 48
49 using WebKit::WebServiceWorkerProvider;
50 using WebKit::WebString;
51
48 namespace WebCore { 52 namespace WebCore {
49 53
50 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) 54 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator)
51 : m_navigator(navigator) 55 : m_navigator(navigator)
52 { 56 {
53 } 57 }
54 58
55 NavigatorServiceWorker::~NavigatorServiceWorker() 59 NavigatorServiceWorker::~NavigatorServiceWorker()
56 { 60 {
57 } 61 }
58 62
59 const char* NavigatorServiceWorker::supplementName() 63 const char* NavigatorServiceWorker::supplementName()
60 { 64 {
61 return "NavigatorServiceWorker"; 65 return "NavigatorServiceWorker";
62 } 66 }
63 67
68 WebServiceWorkerProvider* NavigatorServiceWorker::serviceWorkerProvider()
69 {
70 if (!m_provider) {
71 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
abarth-chromium 2013/10/10 03:44:02 m_navigator->frame() can be null. What should we
alecflett 2013/10/10 23:03:36 Done.
72 // FIXME: This is temporarily hooked up here until we hook up to the loa ding process.
73 m_provider = adoptPtr(client->createServiceWorkerProvider(0));
abarth-chromium 2013/10/10 03:44:02 We shouldn't be calling adoptPtr here. Isntead, w
alecflett 2013/10/10 23:03:36 Done.
74 }
75 return m_provider.get();
76 }
77
64 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) 78 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator)
65 { 79 {
66 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); 80 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator);
67 if (!supplement) { 81 if (!supplement) {
68 supplement = new NavigatorServiceWorker(navigator); 82 supplement = new NavigatorServiceWorker(navigator);
69 provideTo(navigator, supplementName(), adoptPtr(supplement)); 83 provideTo(navigator, supplementName(), adoptPtr(supplement));
70 } 84 }
71 return supplement; 85 return supplement;
72 } 86 }
73 87
74 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es) 88 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es)
75 { 89 {
76 return from(navigator)->registerServiceWorker(context, pattern, url, es); 90 return from(navigator)->registerServiceWorker(context, pattern, url, es);
77 } 91 }
78 92
79
80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es) 93 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es)
81 { 94 {
82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 95 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
83 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
84 // WTF? Surely there's a better way to resolve a url? 96 // WTF? Surely there's a better way to resolve a url?
85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); 97 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc);
86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry();
87 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 98 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
88 99
89 if (peer) 100 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider();
90 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt er(resolver, scriptExecutionContext)); 101 if (provider)
102 provider->registerServiceWorker(scriptExecutionContext->url(), pattern, scriptUrl, new CallbackPromiseAdapter(resolver, scriptExecutionContext));
abarth-chromium 2013/10/10 03:44:02 Why are you passing in the scriptExecutionContext-
91 else 103 else
92 resolver->reject(PassRefPtr<ServiceWorker>(0)); 104 resolver->reject(PassRefPtr<ServiceWorker>(0));
93 // call here? 105 // call here?
94 return resolver->promise(); 106 return resolver->promise();
95 } 107 }
96 108
97 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es) 109 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es)
98 { 110 {
99 return from(navigator)->unregisterServiceWorker(context, pattern, es); 111 return from(navigator)->unregisterServiceWorker(context, pattern, es);
100 } 112 }
101 113
102 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es) 114 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es)
103 { 115 {
104 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 116 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
105 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); 117 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
106 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); 118 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider();
107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 119 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
108 if (peer) 120 if (provider)
109 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv er, scriptExecutionContext)); 121 provider->unregisterServiceWorker(scriptExecutionContext->url(), pattern , new CallbackPromiseAdapter(resolver, scriptExecutionContext));
abarth-chromium 2013/10/10 03:44:02 Again, why are you using the |scriptExecutionConte
110 else 122 else
111 resolver->reject(PassRefPtr<ServiceWorker>(0)); 123 resolver->reject(PassRefPtr<ServiceWorker>(0));
112 return resolver->promise(); 124 return resolver->promise();
113 } 125 }
114 126
115 } // namespace WebCore 127 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698