| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/FetchEvent.h" | 5 #include "modules/serviceworkers/FetchEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ToV8.h" |
| 8 #include "bindings/core/v8/V8HiddenValue.h" |
| 7 #include "modules/fetch/Request.h" | 9 #include "modules/fetch/Request.h" |
| 8 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| 9 #include "wtf/RefPtr.h" | 11 #include "wtf/RefPtr.h" |
| 10 | 12 |
| 11 namespace blink { | 13 namespace blink { |
| 12 | 14 |
| 13 FetchEvent* FetchEvent::create() | 15 FetchEvent* FetchEvent::create() |
| 14 { | 16 { |
| 15 return new FetchEvent(); | 17 return new FetchEvent(); |
| 16 } | 18 } |
| 17 | 19 |
| 18 FetchEvent* FetchEvent::create(const AtomicString& type, const FetchEventInit& i
nitializer) | 20 FetchEvent* FetchEvent::create(ScriptState* scriptState, const AtomicString& typ
e, const FetchEventInit& initializer) |
| 19 { | 21 { |
| 20 return new FetchEvent(type, initializer, nullptr); | 22 return new FetchEvent(scriptState, type, initializer, nullptr); |
| 21 } | 23 } |
| 22 | 24 |
| 23 FetchEvent* FetchEvent::create(const AtomicString& type, const FetchEventInit& i
nitializer, RespondWithObserver* observer) | 25 FetchEvent* FetchEvent::create(ScriptState* scriptState, const AtomicString& typ
e, const FetchEventInit& initializer, RespondWithObserver* observer) |
| 24 { | 26 { |
| 25 return new FetchEvent(type, initializer, observer); | 27 return new FetchEvent(scriptState, type, initializer, observer); |
| 26 } | 28 } |
| 27 | 29 |
| 28 Request* FetchEvent::request() const | 30 Request* FetchEvent::request() const |
| 29 { | 31 { |
| 30 return m_request; | 32 return m_request; |
| 31 } | 33 } |
| 32 | 34 |
| 33 String FetchEvent::clientId() const | 35 String FetchEvent::clientId() const |
| 34 { | 36 { |
| 35 return m_clientId; | 37 return m_clientId; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 const AtomicString& FetchEvent::interfaceName() const | 52 const AtomicString& FetchEvent::interfaceName() const |
| 51 { | 53 { |
| 52 return EventNames::FetchEvent; | 54 return EventNames::FetchEvent; |
| 53 } | 55 } |
| 54 | 56 |
| 55 FetchEvent::FetchEvent() | 57 FetchEvent::FetchEvent() |
| 56 : m_isReload(false) | 58 : m_isReload(false) |
| 57 { | 59 { |
| 58 } | 60 } |
| 59 | 61 |
| 60 FetchEvent::FetchEvent(const AtomicString& type, const FetchEventInit& initializ
er, RespondWithObserver* observer) | 62 FetchEvent::FetchEvent(ScriptState* scriptState, const AtomicString& type, const
FetchEventInit& initializer, RespondWithObserver* observer) |
| 61 : ExtendableEvent(type, initializer) | 63 : ExtendableEvent(type, initializer) |
| 62 , m_observer(observer) | 64 , m_observer(observer) |
| 63 { | 65 { |
| 64 if (initializer.hasRequest()) | |
| 65 m_request = initializer.request(); | |
| 66 m_clientId = initializer.clientId(); | 66 m_clientId = initializer.clientId(); |
| 67 m_isReload = initializer.isReload(); | 67 m_isReload = initializer.isReload(); |
| 68 if (initializer.hasRequest()) { |
| 69 ScriptState::Scope scope(scriptState); |
| 70 m_request = initializer.request(); |
| 71 v8::Local<v8::Value> request = toV8(m_request, scriptState); |
| 72 v8::Local<v8::Value> event = toV8(this, scriptState); |
| 73 if (event.IsEmpty()) { |
| 74 // |toV8| can return an empty handle when the worker is terminating. |
| 75 // We don't want the renderer to crash in such cases. |
| 76 // TODO(yhirano): Replace this branch with an assertion when the |
| 77 // graceful shutdown mechanism is introduced. |
| 78 return; |
| 79 } |
| 80 DCHECK(event->IsObject()); |
| 81 // Sets a hidden value in order to teach V8 the dependency from |
| 82 // the event to the request. |
| 83 V8HiddenValue::setHiddenValue(scriptState, event.As<v8::Object>(), V8Hid
denValue::requestInFetchEvent(scriptState->isolate()), request); |
| 84 // From the same reason as above, setHiddenValue can return false. |
| 85 // TODO(yhirano): Add an assertion that it returns true once the |
| 86 // graceful shutdown mechanism is introduced. |
| 87 } |
| 68 } | 88 } |
| 69 | 89 |
| 70 DEFINE_TRACE(FetchEvent) | 90 DEFINE_TRACE(FetchEvent) |
| 71 { | 91 { |
| 72 visitor->trace(m_observer); | 92 visitor->trace(m_observer); |
| 73 visitor->trace(m_request); | 93 visitor->trace(m_request); |
| 74 ExtendableEvent::trace(visitor); | 94 ExtendableEvent::trace(visitor); |
| 75 } | 95 } |
| 76 | 96 |
| 77 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |