Chromium Code Reviews| 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); | |
|
haraken
2016/06/01 12:16:59
Given that both objects have wrappers, can we use
| |
| 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. | |
| 77 return; | |
| 78 } | |
| 79 DCHECK(event->IsObject()); | |
| 80 // Sets an hidden value in order to teach V8 the dependency from | |
|
haraken
2016/06/01 12:16:59
a hidden value
yhirano
2016/06/03 02:09:45
Done.
| |
| 81 // the event to the request. | |
| 82 V8HiddenValue::setHiddenValue(scriptState, event.As<v8::Object>(), V8Hid denValue::requestInFetchEvent(scriptState->isolate()), request); | |
|
haraken
2016/06/01 12:16:59
yukishiino@ is replacing V8HiddenValue with V8Priv
yhirano
2016/06/01 12:22:51
Does it work with M52? If this CL fixes crashes, I
Yuki
2016/06/02 04:51:12
No, V8PrivateProperty gets supported since M53. P
| |
| 83 // As written above, we don't check the return value. | |
| 84 // TODO(yhirano): Add an assertion. | |
| 85 } | |
| 68 } | 86 } |
| 69 | 87 |
| 70 DEFINE_TRACE(FetchEvent) | 88 DEFINE_TRACE(FetchEvent) |
| 71 { | 89 { |
| 72 visitor->trace(m_observer); | 90 visitor->trace(m_observer); |
| 73 visitor->trace(m_request); | 91 visitor->trace(m_request); |
| 74 ExtendableEvent::trace(visitor); | 92 ExtendableEvent::trace(visitor); |
| 75 } | 93 } |
| 76 | 94 |
| 77 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |