| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "bindings/core/v8/SerializedScriptValue.h" | 33 #include "bindings/core/v8/SerializedScriptValue.h" |
| 34 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 34 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 35 #include "bindings/core/v8/V8HiddenValue.h" | 35 #include "bindings/core/v8/V8HiddenValue.h" |
| 36 #include "bindings/core/v8/V8History.h" | 36 #include "bindings/core/v8/V8History.h" |
| 37 #include "core/events/PopStateEvent.h" | 37 #include "core/events/PopStateEvent.h" |
| 38 #include "core/frame/History.h" | 38 #include "core/frame/History.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 // Save the state value to a hidden attribute in the V8PopStateEvent, and return
it, for convenience. | 42 // Save the state value to a hidden attribute in the V8PopStateEvent, and return |
| 43 // it, for convenience. |
| 43 static v8::Local<v8::Value> cacheState(ScriptState* scriptState, | 44 static v8::Local<v8::Value> cacheState(ScriptState* scriptState, |
| 44 v8::Local<v8::Object> popStateEvent, | 45 v8::Local<v8::Object> popStateEvent, |
| 45 v8::Local<v8::Value> state) { | 46 v8::Local<v8::Value> state) { |
| 46 V8HiddenValue::setHiddenValue(scriptState, popStateEvent, | 47 V8HiddenValue::setHiddenValue(scriptState, popStateEvent, |
| 47 V8HiddenValue::state(scriptState->isolate()), | 48 V8HiddenValue::state(scriptState->isolate()), |
| 48 state); | 49 state); |
| 49 return state; | 50 return state; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void V8PopStateEvent::stateAttributeGetterCustom( | 53 void V8PopStateEvent::stateAttributeGetterCustom( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 if (event->serializedState()) | 70 if (event->serializedState()) |
| 70 result = event->serializedState()->deserialize(); | 71 result = event->serializedState()->deserialize(); |
| 71 else | 72 else |
| 72 result = event->state().v8ValueFor(scriptState); | 73 result = event->state().v8ValueFor(scriptState); |
| 73 if (result.IsEmpty()) | 74 if (result.IsEmpty()) |
| 74 result = v8::Null(info.GetIsolate()); | 75 result = v8::Null(info.GetIsolate()); |
| 75 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); | 76 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); |
| 76 return; | 77 return; |
| 77 } | 78 } |
| 78 | 79 |
| 79 // There's no cached value from a previous invocation, nor a state value was p
rovided by the | 80 // There's no cached value from a previous invocation, nor a state value was |
| 80 // event, but there is a history object, so first we need to see if the state
object has been | 81 // provided by the event, but there is a history object, so first we need to |
| 81 // deserialized through the history object already. | 82 // see if the state object has been deserialized through the history object |
| 82 // The current history state object might've changed in the meantime, so we ne
ed to take care | 83 // already. |
| 83 // of using the correct one, and always share the same deserialization with hi
story.state. | 84 // The current history state object might've changed in the meantime, so we |
| 85 // need to take care of using the correct one, and always share the same |
| 86 // deserialization with history.state. |
| 84 | 87 |
| 85 bool isSameState = history->isSameAsCurrentState(event->serializedState()); | 88 bool isSameState = history->isSameAsCurrentState(event->serializedState()); |
| 86 | 89 |
| 87 if (isSameState) { | 90 if (isSameState) { |
| 88 v8::Local<v8::Value> v8HistoryValue = | 91 v8::Local<v8::Value> v8HistoryValue = |
| 89 toV8(history, info.Holder(), info.GetIsolate()); | 92 toV8(history, info.Holder(), info.GetIsolate()); |
| 90 if (v8HistoryValue.IsEmpty()) | 93 if (v8HistoryValue.IsEmpty()) |
| 91 return; | 94 return; |
| 92 v8::Local<v8::Object> v8History = v8HistoryValue.As<v8::Object>(); | 95 v8::Local<v8::Object> v8History = v8HistoryValue.As<v8::Object>(); |
| 93 if (!history->stateChanged()) { | 96 if (!history->stateChanged()) { |
| 94 result = V8HiddenValue::getHiddenValue( | 97 result = V8HiddenValue::getHiddenValue( |
| 95 scriptState, v8History, V8HiddenValue::state(info.GetIsolate())); | 98 scriptState, v8History, V8HiddenValue::state(info.GetIsolate())); |
| 96 if (!result.IsEmpty()) { | 99 if (!result.IsEmpty()) { |
| 97 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); | 100 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); |
| 98 return; | 101 return; |
| 99 } | 102 } |
| 100 } | 103 } |
| 101 result = event->serializedState()->deserialize(info.GetIsolate()); | 104 result = event->serializedState()->deserialize(info.GetIsolate()); |
| 102 V8HiddenValue::setHiddenValue(scriptState, v8History, | 105 V8HiddenValue::setHiddenValue(scriptState, v8History, |
| 103 V8HiddenValue::state(info.GetIsolate()), | 106 V8HiddenValue::state(info.GetIsolate()), |
| 104 result); | 107 result); |
| 105 } else { | 108 } else { |
| 106 result = event->serializedState()->deserialize(info.GetIsolate()); | 109 result = event->serializedState()->deserialize(info.GetIsolate()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); | 112 v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result)); |
| 110 } | 113 } |
| 111 | 114 |
| 112 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |