| 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), state_(this), history_(nullptr) {} | 35     : serialized_state_(nullptr), history_(nullptr) {} | 
| 36 | 36 | 
| 37 PopStateEvent::PopStateEvent(ScriptState* script_state, | 37 PopStateEvent::PopStateEvent(const AtomicString& type, | 
| 38                              const AtomicString& type, |  | 
| 39                              const PopStateEventInit& initializer) | 38                              const PopStateEventInit& initializer) | 
| 40     : Event(type, initializer), state_(this), history_(nullptr) { | 39     : Event(type, initializer), history_(nullptr) { | 
| 41   if (initializer.hasState()) { | 40   if (initializer.hasState()) | 
| 42     world_ = RefPtr<DOMWrapperWorld>(script_state->World()); | 41     state_ = initializer.state(); | 
| 43     state_.Set(initializer.state().GetIsolate(), initializer.state().V8Value()); |  | 
| 44   } |  | 
| 45 } | 42 } | 
| 46 | 43 | 
| 47 PopStateEvent::PopStateEvent(PassRefPtr<SerializedScriptValue> serialized_state, | 44 PopStateEvent::PopStateEvent(PassRefPtr<SerializedScriptValue> serialized_state, | 
| 48                              History* history) | 45                              History* history) | 
| 49     : Event(EventTypeNames::popstate, false, true), | 46     : Event(EventTypeNames::popstate, false, true), | 
| 50       serialized_state_(std::move(serialized_state)), | 47       serialized_state_(std::move(serialized_state)), | 
| 51       state_(this), |  | 
| 52       history_(history) {} | 48       history_(history) {} | 
| 53 | 49 | 
| 54 PopStateEvent::~PopStateEvent() {} | 50 PopStateEvent::~PopStateEvent() {} | 
| 55 | 51 | 
| 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)); |  | 
| 66   } |  | 
| 67   return ScriptValue(script_state, state_.NewLocal(isolate)); |  | 
| 68 } |  | 
| 69 |  | 
| 70 PopStateEvent* PopStateEvent::Create() { | 52 PopStateEvent* PopStateEvent::Create() { | 
| 71   return new PopStateEvent; | 53   return new PopStateEvent; | 
| 72 } | 54 } | 
| 73 | 55 | 
| 74 PopStateEvent* PopStateEvent::Create( | 56 PopStateEvent* PopStateEvent::Create( | 
| 75     PassRefPtr<SerializedScriptValue> serialized_state, | 57     PassRefPtr<SerializedScriptValue> serialized_state, | 
| 76     History* history) { | 58     History* history) { | 
| 77   return new PopStateEvent(std::move(serialized_state), history); | 59   return new PopStateEvent(std::move(serialized_state), history); | 
| 78 } | 60 } | 
| 79 | 61 | 
| 80 PopStateEvent* PopStateEvent::Create(ScriptState* script_state, | 62 PopStateEvent* PopStateEvent::Create(const AtomicString& type, | 
| 81                                      const AtomicString& type, |  | 
| 82                                      const PopStateEventInit& initializer) { | 63                                      const PopStateEventInit& initializer) { | 
| 83   return new PopStateEvent(script_state, type, initializer); | 64   return new PopStateEvent(type, initializer); | 
| 84 } | 65 } | 
| 85 | 66 | 
| 86 const AtomicString& PopStateEvent::InterfaceName() const { | 67 const AtomicString& PopStateEvent::InterfaceName() const { | 
| 87   return EventNames::PopStateEvent; | 68   return EventNames::PopStateEvent; | 
| 88 } | 69 } | 
| 89 | 70 | 
| 90 DEFINE_TRACE(PopStateEvent) { | 71 DEFINE_TRACE(PopStateEvent) { | 
| 91   visitor->Trace(history_); | 72   visitor->Trace(history_); | 
| 92   Event::Trace(visitor); | 73   Event::Trace(visitor); | 
| 93 } | 74 } | 
| 94 | 75 | 
| 95 DEFINE_TRACE_WRAPPERS(PopStateEvent) { |  | 
| 96   visitor->TraceWrappers(state_); |  | 
| 97   Event::TraceWrappers(visitor); |  | 
| 98 } |  | 
| 99 |  | 
| 100 }  // namespace blink | 76 }  // namespace blink | 
| OLD | NEW | 
|---|