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

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: Add logging error handler 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/WebString.h" 45 #include "public/platform/WebString.h"
46 #include "public/platform/WebURL.h" 46 #include "public/platform/WebURL.h"
47 47
48 using WebKit::WebServiceWorkerProvider;
49 using WebKit::WebString;
50
48 namespace WebCore { 51 namespace WebCore {
49 52
50 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator) 53 NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator)
51 : m_navigator(navigator) 54 : m_navigator(navigator)
52 { 55 {
53 } 56 }
54 57
55 NavigatorServiceWorker::~NavigatorServiceWorker() 58 NavigatorServiceWorker::~NavigatorServiceWorker()
56 { 59 {
57 } 60 }
58 61
59 const char* NavigatorServiceWorker::supplementName() 62 const char* NavigatorServiceWorker::supplementName()
60 { 63 {
61 return "NavigatorServiceWorker"; 64 return "NavigatorServiceWorker";
62 } 65 }
63 66
67 WebServiceWorkerProvider* NavigatorServiceWorker::serviceWorkerProvider()
68 {
69 if (!m_provider) {
70 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
71 // FIXME: This is temporarily hooked up here until we hook up to the loa ding process.
72 m_provider = adoptPtr(client->createServiceWorkerProvider(this));
michaeln 2013/10/07 20:09:54 I'm glad my comments made sense and you bought tha
73 }
74 return m_provider.get();
75 }
76
64 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator) 77 NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator)
65 { 78 {
66 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator); 79 NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator);
67 if (!supplement) { 80 if (!supplement) {
68 supplement = new NavigatorServiceWorker(navigator); 81 supplement = new NavigatorServiceWorker(navigator);
69 provideTo(navigator, supplementName(), adoptPtr(supplement)); 82 provideTo(navigator, supplementName(), adoptPtr(supplement));
70 } 83 }
71 return supplement; 84 return supplement;
72 } 85 }
73 86
74 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es) 87 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* context, Navigator* navigator, const String& pattern, const String& url, Exc eptionState& es)
75 { 88 {
76 return from(navigator)->registerServiceWorker(context, pattern, url, es); 89 return from(navigator)->registerServiceWorker(context, pattern, url, es);
77 } 90 }
78 91
79
80 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es) 92 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte xt* scriptExecutionContext, const String& pattern, const String& scriptSrc, Exce ptionState& es)
81 { 93 {
82 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 94 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
83 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
84 // WTF? Surely there's a better way to resolve a url? 95 // WTF? Surely there's a better way to resolve a url?
85 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc); 96 KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc);
86 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry();
87 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 97 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
88 98
89 if (peer) 99 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider();
90 peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapt er(resolver, scriptExecutionContext)); 100 if (provider)
101 provider->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseA dapter(resolver, scriptExecutionContext));
91 else 102 else
92 resolver->reject(PassRefPtr<ServiceWorker>(0)); 103 resolver->reject(PassRefPtr<ServiceWorker>(0));
93 // call here? 104 // call here?
94 return resolver->promise(); 105 return resolver->promise();
95 } 106 }
96 107
97 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es) 108 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es)
98 { 109 {
99 return from(navigator)->unregisterServiceWorker(context, pattern, es); 110 return from(navigator)->unregisterServiceWorker(context, pattern, es);
100 } 111 }
101 112
102 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es) 113 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es)
103 { 114 {
104 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 115 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
105 FrameLoaderClient* client = m_navigator->frame()->loader()->client(); 116 FrameLoaderClient* client = m_navigator->frame()->loader()->client();
106 WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry(); 117 WebKit::WebServiceWorkerProvider* provider = serviceWorkerProvider();
107 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 118 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
108 if (peer) 119 if (provider)
109 peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolv er, scriptExecutionContext)); 120 provider->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(re solver, scriptExecutionContext));
110 else 121 else
111 resolver->reject(PassRefPtr<ServiceWorker>(0)); 122 resolver->reject(PassRefPtr<ServiceWorker>(0));
112 return resolver->promise(); 123 return resolver->promise();
113 } 124 }
114 125
126 void NavigatorServiceWorker::didFailToStart(const WebString& message)
127 {
128 // FIXME: Move this to a handler that can forward this to the dev console.
129 LOG_ERROR("Service worker failed to start: %s", message.utf8().data());
130 }
131
115 } // namespace WebCore 132 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/NavigatorServiceWorker.h ('k') | Source/web/FrameLoaderClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698