OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/serviceworkers/ServiceWorkerLinkResource.h" | 5 #include "modules/serviceworkers/ServiceWorkerLinkResource.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/DOMWindow.h" | 10 #include "core/frame/DOMWindow.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 ->TimerTaskRunner() | 46 ->TimerTaskRunner() |
47 ->PostTask(BLINK_FROM_HERE, | 47 ->PostTask(BLINK_FROM_HERE, |
48 WTF::Bind(&LinkLoaderClient::LinkLoadingErrored, client_)); | 48 WTF::Bind(&LinkLoaderClient::LinkLoadingErrored, client_)); |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 WTF_MAKE_NONCOPYABLE(RegistrationCallback); | 52 WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
53 | 53 |
54 Persistent<LinkLoaderClient> client_; | 54 Persistent<LinkLoaderClient> client_; |
55 }; | 55 }; |
56 } | 56 } // namespace |
57 | 57 |
58 ServiceWorkerLinkResource* ServiceWorkerLinkResource::Create( | 58 ServiceWorkerLinkResource* ServiceWorkerLinkResource::Create( |
59 HTMLLinkElement* owner) { | 59 HTMLLinkElement* owner) { |
60 return new ServiceWorkerLinkResource(owner); | 60 return new ServiceWorkerLinkResource(owner); |
61 } | 61 } |
62 | 62 |
63 ServiceWorkerLinkResource::~ServiceWorkerLinkResource() {} | 63 ServiceWorkerLinkResource::~ServiceWorkerLinkResource() {} |
64 | 64 |
65 void ServiceWorkerLinkResource::Process() { | 65 void ServiceWorkerLinkResource::Process() { |
66 if (!owner_ || !owner_->GetDocument().GetFrame()) | 66 if (!owner_ || !owner_->GetDocument().GetFrame()) |
67 return; | 67 return; |
68 | 68 |
69 if (!owner_->ShouldLoadLink()) | 69 if (!owner_->ShouldLoadLink()) |
70 return; | 70 return; |
71 | 71 |
72 Document& document = owner_->GetDocument(); | 72 Document& document = owner_->GetDocument(); |
73 | 73 |
74 KURL script_url = owner_->Href(); | 74 KURL script_url = owner_->Href(); |
75 | 75 |
76 String scope = owner_->Scope(); | 76 String scope = owner_->Scope(); |
77 KURL scope_url; | 77 KURL scope_url; |
78 if (scope.IsNull()) | 78 if (scope.IsNull()) |
79 scope_url = KURL(script_url, "./"); | 79 scope_url = KURL(script_url, "./"); |
80 else | 80 else |
81 scope_url = document.CompleteURL(scope); | 81 scope_url = document.CompleteURL(scope); |
82 scope_url.RemoveFragmentIdentifier(); | 82 scope_url.RemoveFragmentIdentifier(); |
83 | 83 |
| 84 WebServiceWorkerUpdateViaCache update_via_cache = owner_->UpdateViaCache(); |
| 85 |
84 String error_message; | 86 String error_message; |
85 ServiceWorkerContainer* container = NavigatorServiceWorker::serviceWorker( | 87 ServiceWorkerContainer* container = NavigatorServiceWorker::serviceWorker( |
86 ToScriptStateForMainWorld(owner_->GetDocument().GetFrame()), | 88 ToScriptStateForMainWorld(owner_->GetDocument().GetFrame()), |
87 *document.GetFrame()->DomWindow()->navigator(), error_message); | 89 *document.GetFrame()->DomWindow()->navigator(), error_message); |
88 | 90 |
89 if (!container) { | 91 if (!container) { |
90 document.AddConsoleMessage(ConsoleMessage::Create( | 92 document.AddConsoleMessage(ConsoleMessage::Create( |
91 kJSMessageSource, kErrorMessageLevel, | 93 kJSMessageSource, kErrorMessageLevel, |
92 "Cannot register service worker with <link> element. " + | 94 "Cannot register service worker with <link> element. " + |
93 error_message)); | 95 error_message)); |
94 WTF::MakeUnique<RegistrationCallback>(owner_)->OnError( | 96 WTF::MakeUnique<RegistrationCallback>(owner_)->OnError( |
95 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, | 97 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, |
96 error_message)); | 98 error_message)); |
97 return; | 99 return; |
98 } | 100 } |
99 | 101 |
100 container->RegisterServiceWorkerImpl( | 102 container->RegisterServiceWorkerImpl( |
101 &document, script_url, scope_url, | 103 &document, script_url, scope_url, update_via_cache, |
102 WTF::MakeUnique<RegistrationCallback>(owner_)); | 104 WTF::MakeUnique<RegistrationCallback>(owner_)); |
103 } | 105 } |
104 | 106 |
105 bool ServiceWorkerLinkResource::HasLoaded() const { | 107 bool ServiceWorkerLinkResource::HasLoaded() const { |
106 return false; | 108 return false; |
107 } | 109 } |
108 | 110 |
109 void ServiceWorkerLinkResource::OwnerRemoved() { | 111 void ServiceWorkerLinkResource::OwnerRemoved() { |
110 Process(); | 112 Process(); |
111 } | 113 } |
112 | 114 |
113 ServiceWorkerLinkResource::ServiceWorkerLinkResource(HTMLLinkElement* owner) | 115 ServiceWorkerLinkResource::ServiceWorkerLinkResource(HTMLLinkElement* owner) |
114 : LinkResource(owner) {} | 116 : LinkResource(owner) {} |
115 | 117 |
116 } // namespace blink | 118 } // namespace blink |
OLD | NEW |