| 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/ForeignFetchEvent.h" | 5 #include "modules/serviceworkers/ForeignFetchEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ToV8.h" | 7 #include "bindings/core/v8/ToV8.h" |
| 8 #include "bindings/core/v8/V8HiddenValue.h" | 8 #include "bindings/core/v8/V8HiddenValue.h" |
| 9 #include "modules/fetch/Request.h" | 9 #include "modules/fetch/Request.h" |
| 10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ForeignFetchRespondWithObserver* respondWithObserver, | 57 ForeignFetchRespondWithObserver* respondWithObserver, |
| 58 WaitUntilObserver* waitUntilObserver) | 58 WaitUntilObserver* waitUntilObserver) |
| 59 : ExtendableEvent(type, initializer, waitUntilObserver), | 59 : ExtendableEvent(type, initializer, waitUntilObserver), |
| 60 m_observer(respondWithObserver) { | 60 m_observer(respondWithObserver) { |
| 61 if (initializer.hasOrigin()) | 61 if (initializer.hasOrigin()) |
| 62 m_origin = initializer.origin(); | 62 m_origin = initializer.origin(); |
| 63 if (initializer.hasRequest()) { | 63 if (initializer.hasRequest()) { |
| 64 m_request = initializer.request(); | 64 m_request = initializer.request(); |
| 65 ScriptState::Scope scope(scriptState); | 65 ScriptState::Scope scope(scriptState); |
| 66 m_request = initializer.request(); | 66 m_request = initializer.request(); |
| 67 v8::Local<v8::Value> request = toV8(m_request, scriptState); | 67 v8::Local<v8::Value> request = ToV8(m_request, scriptState); |
| 68 v8::Local<v8::Value> event = toV8(this, scriptState); | 68 v8::Local<v8::Value> event = ToV8(this, scriptState); |
| 69 if (event.IsEmpty()) { | 69 if (event.IsEmpty()) { |
| 70 // |toV8| can return an empty handle when the worker is terminating. | 70 // |toV8| can return an empty handle when the worker is terminating. |
| 71 // We don't want the renderer to crash in such cases. | 71 // We don't want the renderer to crash in such cases. |
| 72 // TODO(yhirano): Replace this branch with an assertion when the | 72 // TODO(yhirano): Replace this branch with an assertion when the |
| 73 // graceful shutdown mechanism is introduced. | 73 // graceful shutdown mechanism is introduced. |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 DCHECK(event->IsObject()); | 76 DCHECK(event->IsObject()); |
| 77 // Sets a hidden value in order to teach V8 the dependency from | 77 // Sets a hidden value in order to teach V8 the dependency from |
| 78 // the event to the request. | 78 // the event to the request. |
| 79 V8HiddenValue::setHiddenValue( | 79 V8HiddenValue::setHiddenValue( |
| 80 scriptState, event.As<v8::Object>(), | 80 scriptState, event.As<v8::Object>(), |
| 81 V8HiddenValue::requestInFetchEvent(scriptState->isolate()), request); | 81 V8HiddenValue::requestInFetchEvent(scriptState->isolate()), request); |
| 82 // From the same reason as above, setHiddenValue can return false. | 82 // From the same reason as above, setHiddenValue can return false. |
| 83 // TODO(yhirano): Add an assertion that it returns true once the | 83 // TODO(yhirano): Add an assertion that it returns true once the |
| 84 // graceful shutdown mechanism is introduced. | 84 // graceful shutdown mechanism is introduced. |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 DEFINE_TRACE(ForeignFetchEvent) { | 88 DEFINE_TRACE(ForeignFetchEvent) { |
| 89 visitor->trace(m_observer); | 89 visitor->trace(m_observer); |
| 90 visitor->trace(m_request); | 90 visitor->trace(m_request); |
| 91 ExtendableEvent::trace(visitor); | 91 ExtendableEvent::trace(visitor); |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |