OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 14 matching lines...) Expand all Loading... | |
25 */ | 25 */ |
26 | 26 |
27 #include "core/events/PopStateEvent.h" | 27 #include "core/events/PopStateEvent.h" |
28 | 28 |
29 #include "bindings/core/v8/SerializedScriptValue.h" | 29 #include "bindings/core/v8/SerializedScriptValue.h" |
30 #include "core/frame/History.h" | 30 #include "core/frame/History.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 PopStateEvent::PopStateEvent() | 34 PopStateEvent::PopStateEvent() |
35 : serialized_state_(nullptr), history_(nullptr) {} | 35 : serialized_state_(nullptr), state_(this), history_(nullptr) {} |
36 | 36 |
37 PopStateEvent::PopStateEvent(const AtomicString& type, | 37 PopStateEvent::PopStateEvent(ScriptState* script_state, |
38 const AtomicString& type, | |
38 const PopStateEventInit& initializer) | 39 const PopStateEventInit& initializer) |
39 : Event(type, initializer), history_(nullptr) { | 40 : Event(type, initializer), state_(this), history_(nullptr) { |
40 if (initializer.hasState()) | 41 if (initializer.hasState()) { |
41 state_ = initializer.state(); | 42 world_ = RefPtr<DOMWrapperWorld>(script_state->World()); |
43 state_.Set(initializer.state().GetIsolate(), initializer.state().V8Value()); | |
44 } | |
42 } | 45 } |
43 | 46 |
44 PopStateEvent::PopStateEvent(PassRefPtr<SerializedScriptValue> serialized_state, | 47 PopStateEvent::PopStateEvent(PassRefPtr<SerializedScriptValue> serialized_state, |
45 History* history) | 48 History* history) |
46 : Event(EventTypeNames::popstate, false, true), | 49 : Event(EventTypeNames::popstate, false, true), |
47 serialized_state_(std::move(serialized_state)), | 50 serialized_state_(std::move(serialized_state)), |
51 state_(this), | |
48 history_(history) {} | 52 history_(history) {} |
49 | 53 |
50 PopStateEvent::~PopStateEvent() {} | 54 PopStateEvent::~PopStateEvent() {} |
51 | 55 |
56 ScriptValue PopStateEvent::state(ScriptState* script_state) const { | |
57 if (state_.IsEmpty()) | |
58 return ScriptValue(); | |
59 | |
60 v8::Isolate* isolate = script_state->GetIsolate(); | |
61 if (world_->GetWorldId() != script_state->World().GetWorldId()) { | |
62 v8::Local<v8::Value> value = state_.NewLocal(isolate); | |
63 RefPtr<SerializedScriptValue> serialized = | |
64 SerializedScriptValue::SerializeAndSwallowExceptions(isolate, value); | |
65 return ScriptValue(script_state, serialized->Deserialize(isolate)); | |
haraken
2017/05/02 04:44:32
What happens if:
1) an isolated world stores stat
bashi
2017/05/02 05:08:52
Yeah, that's a valid concern when we remove custom
| |
66 } | |
67 return ScriptValue(script_state, state_.NewLocal(isolate)); | |
68 } | |
69 | |
52 PopStateEvent* PopStateEvent::Create() { | 70 PopStateEvent* PopStateEvent::Create() { |
53 return new PopStateEvent; | 71 return new PopStateEvent; |
54 } | 72 } |
55 | 73 |
56 PopStateEvent* PopStateEvent::Create( | 74 PopStateEvent* PopStateEvent::Create( |
57 PassRefPtr<SerializedScriptValue> serialized_state, | 75 PassRefPtr<SerializedScriptValue> serialized_state, |
58 History* history) { | 76 History* history) { |
59 return new PopStateEvent(std::move(serialized_state), history); | 77 return new PopStateEvent(std::move(serialized_state), history); |
60 } | 78 } |
61 | 79 |
62 PopStateEvent* PopStateEvent::Create(const AtomicString& type, | 80 PopStateEvent* PopStateEvent::Create(ScriptState* script_state, |
81 const AtomicString& type, | |
63 const PopStateEventInit& initializer) { | 82 const PopStateEventInit& initializer) { |
64 return new PopStateEvent(type, initializer); | 83 return new PopStateEvent(script_state, type, initializer); |
65 } | 84 } |
66 | 85 |
67 const AtomicString& PopStateEvent::InterfaceName() const { | 86 const AtomicString& PopStateEvent::InterfaceName() const { |
68 return EventNames::PopStateEvent; | 87 return EventNames::PopStateEvent; |
69 } | 88 } |
70 | 89 |
71 DEFINE_TRACE(PopStateEvent) { | 90 DEFINE_TRACE(PopStateEvent) { |
72 visitor->Trace(history_); | 91 visitor->Trace(history_); |
73 Event::Trace(visitor); | 92 Event::Trace(visitor); |
74 } | 93 } |
75 | 94 |
95 DEFINE_TRACE_WRAPPERS(PopStateEvent) { | |
96 visitor->TraceWrappers(state_); | |
97 Event::TraceWrappers(visitor); | |
98 } | |
99 | |
76 } // namespace blink | 100 } // namespace blink |
OLD | NEW |