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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerLinkResource.cpp

Issue 1781783002: Implement support for link type serviceworker in link elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uppercase W in runtime feature name Created 4 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/serviceworkers/ServiceWorkerLinkResource.h"
6
7 #include "core/dom/Document.h"
8 #include "core/frame/LocalFrame.h"
9 #include "core/html/HTMLLinkElement.h"
10 #include "core/loader/FrameLoaderClient.h"
11 #include "modules/serviceworkers/NavigatorServiceWorker.h"
12 #include "modules/serviceworkers/ServiceWorkerContainer.h"
13 #include "public/platform/Platform.h"
14 #include "public/platform/WebScheduler.h"
15
16 namespace blink {
17
18 namespace {
19
20 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe gistrationCallbacks {
21 public:
22 explicit RegistrationCallback(LinkLoaderClient* client) : m_client(client) { }
23 ~RegistrationCallback() override {}
24
25 void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) o verride
26 {
27 Platform::current()->currentThread()->scheduler()->timerTaskRunner()->po stTask(BLINK_FROM_HERE, bind(&LinkLoaderClient::linkLoaded, m_client));
28 }
29
30 void onError(const WebServiceWorkerError& error) override
31 {
32 Platform::current()->currentThread()->scheduler()->timerTaskRunner()->po stTask(BLINK_FROM_HERE, bind(&LinkLoaderClient::linkLoadingErrored, m_client));
33 }
34
35 private:
36 WTF_MAKE_NONCOPYABLE(RegistrationCallback);
37
38 RawPtrWillBePersistent<LinkLoaderClient> m_client;
39 };
40
41 }
42
43 PassOwnPtrWillBeRawPtr<ServiceWorkerLinkResource> ServiceWorkerLinkResource::cre ate(HTMLLinkElement* owner)
44 {
45 return adoptPtrWillBeNoop(new ServiceWorkerLinkResource(owner));
46 }
47
48 ServiceWorkerLinkResource::~ServiceWorkerLinkResource()
49 {
50 }
51
52 void ServiceWorkerLinkResource::process()
53 {
54 if (!m_owner || !m_owner->document().frame())
55 return;
56
57 if (!m_owner->shouldLoadLink())
58 return;
59
60 Document& document = m_owner->document();
61
62 KURL scriptURL = m_owner->href();
63
64 String scope = m_owner->scope();
65 KURL scopeURL;
66 if (scope.isNull())
67 scopeURL = KURL(scriptURL, "./");
68 else
69 scopeURL = document.completeURL(scope);
70 scopeURL.removeFragmentIdentifier();
71
72 TrackExceptionState exceptionState;
73
74 NavigatorServiceWorker::serviceWorker(&document, *document.frame()->domWindo w()->navigator(), exceptionState)->registerServiceWorkerImpl(&document, scriptUR L, scopeURL, adoptPtr(new RegistrationCallback(m_owner)));
75 }
76
77 bool ServiceWorkerLinkResource::hasLoaded() const
78 {
79 return false;
80 }
81
82 void ServiceWorkerLinkResource::ownerRemoved()
83 {
84 process();
85 }
86
87 ServiceWorkerLinkResource::ServiceWorkerLinkResource(HTMLLinkElement* owner)
88 : LinkResource(owner)
89 {
90 }
91
92 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698