Changeset 107058 in webkit


Ignore:
Timestamp:
Feb 8, 2012 2:39:13 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add state attribute to history's dom interface.
https://bugs.webkit.org/show_bug.cgi?id=76035

Patch by Pablo Flouret <pablof@motorola.com> on 2012-02-08
Reviewed by Kentaro Hara.

Source/WebCore:

Tests: fast/loader/stateobjects/state-attribute-object-types.html

fast/loader/stateobjects/state-attribute-only-one-deserialization.html

  • bindings/js/JSHistoryCustom.cpp:

(WebCore::JSHistory::state):
(WebCore):
(WebCore::JSHistory::pushState):
(WebCore::JSHistory::replaceState):

  • bindings/v8/custom/V8HistoryCustom.cpp:

(WebCore::V8History::stateAccessorGetter):
(WebCore):
(WebCore::V8History::pushStateCallback):
(WebCore::V8History::replaceStateCallback):

  • page/History.cpp:

(WebCore::History::History):
(WebCore::History::state):
(WebCore):
(WebCore::History::stateInternal):
(WebCore::History::stateChanged):

  • page/History.h:

(History):

  • page/History.idl:

LayoutTests:

  • fast/dom/Window/window-appendages-cleared-expected.txt:
  • fast/loader/stateobjects/state-attribute-object-types-expected.txt: Added.
  • fast/loader/stateobjects/state-attribute-object-types.html: Added.
  • fast/loader/stateobjects/state-attribute-only-one-deserialization-expected.txt: Added.
  • fast/loader/stateobjects/state-attribute-only-one-deserialization.html: Added.
Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r107057 r107058  
     12012-02-08  Pablo Flouret  <pablof@motorola.com>
     2
     3        Add state attribute to history's dom interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=76035
     5
     6        Reviewed by Kentaro Hara.
     7
     8        * fast/dom/Window/window-appendages-cleared-expected.txt:
     9        * fast/loader/stateobjects/state-attribute-object-types-expected.txt: Added.
     10        * fast/loader/stateobjects/state-attribute-object-types.html: Added.
     11        * fast/loader/stateobjects/state-attribute-only-one-deserialization-expected.txt: Added.
     12        * fast/loader/stateobjects/state-attribute-only-one-deserialization.html: Added.
     13
    1142012-02-08  Nikolas Zimmermann  <nzimmermann@rim.com>
    215
  • trunk/LayoutTests/fast/dom/Window/window-appendages-cleared-expected.txt

    r100164 r107058  
    55PASS history.pushState == "LEFTOVER" is false
    66PASS history.replaceState == "LEFTOVER" is false
     7PASS history.state == "LEFTOVER" is false
    78PASS location.assign == "LEFTOVER" is false
    89PASS location.hash == "LEFTOVER" is false
  • trunk/Source/WebCore/ChangeLog

    r107057 r107058  
     12012-02-08  Pablo Flouret  <pablof@motorola.com>
     2
     3        Add state attribute to history's dom interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=76035
     5
     6        Reviewed by Kentaro Hara.
     7
     8        Tests: fast/loader/stateobjects/state-attribute-object-types.html
     9               fast/loader/stateobjects/state-attribute-only-one-deserialization.html
     10
     11        * bindings/js/JSHistoryCustom.cpp:
     12        (WebCore::JSHistory::state):
     13        (WebCore):
     14        (WebCore::JSHistory::pushState):
     15        (WebCore::JSHistory::replaceState):
     16        * bindings/v8/custom/V8HistoryCustom.cpp:
     17        (WebCore::V8History::stateAccessorGetter):
     18        (WebCore):
     19        (WebCore::V8History::pushStateCallback):
     20        (WebCore::V8History::replaceStateCallback):
     21        * page/History.cpp:
     22        (WebCore::History::History):
     23        (WebCore::History::state):
     24        (WebCore):
     25        (WebCore::History::stateInternal):
     26        (WebCore::History::stateChanged):
     27        * page/History.h:
     28        (History):
     29        * page/History.idl:
     30
    1312012-02-08  Nikolas Zimmermann  <nzimmermann@rim.com>
    232
  • trunk/Source/WebCore/bindings/js/JSHistoryCustom.cpp

    r106618 r107058  
    165165}
    166166
     167JSValue JSHistory::state(ExecState *exec) const
     168{
     169    History* history = static_cast<History*>(impl());
     170
     171    JSValue cachedValue = m_state.get();
     172    if (!cachedValue.isEmpty() && !history->stateChanged())
     173        return cachedValue;
     174
     175    SerializedScriptValue* serialized = history->state();
     176    JSValue result = serialized ? serialized->deserialize(exec, globalObject(), 0) : jsNull();
     177    const_cast<JSHistory*>(this)->m_state.set(exec->globalData(), this, result);
     178    return result;
     179}
     180
    167181JSValue JSHistory::pushState(ExecState* exec)
    168182{
     
    186200    setDOMException(exec, ec);
    187201
     202    m_state.clear();
     203
    188204    return jsUndefined();
    189205}
     
    210226    setDOMException(exec, ec);
    211227
     228    m_state.clear();
     229
    212230    return jsUndefined();
    213231}
  • trunk/Source/WebCore/bindings/v8/custom/V8HistoryCustom.cpp

    r101118 r107058  
    4242namespace WebCore {
    4343
     44v8::Handle<v8::Value> V8History::stateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     45{
     46    INC_STATS("DOM.History.state");
     47    History* history = V8History::toNative(info.Holder());
     48
     49    v8::Handle<v8::String> propertyName = v8::String::NewSymbol("state");
     50    v8::Handle<v8::Value> value = info.Holder()->GetHiddenValue(propertyName);
     51
     52    if (!value.IsEmpty() && !history->stateChanged())
     53        return value;
     54
     55    SerializedScriptValue* serialized = history->state();
     56    value = serialized ? serialized->deserialize() : v8::Handle<v8::Value>(v8::Null());
     57    info.Holder()->SetHiddenValue(propertyName, value);
     58
     59    return value;
     60}
     61
    4462v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args)
    4563{
     
    6381    History* history = V8History::toNative(args.Holder());
    6482    history->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec);
     83    args.Holder()->DeleteHiddenValue(v8::String::NewSymbol("state"));
    6584    return throwError(ec);
    6685}
     
    87106    History* history = V8History::toNative(args.Holder());
    88107    history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec);
     108    args.Holder()->DeleteHiddenValue(v8::String::NewSymbol("state"));
    89109    return throwError(ec);
    90110}
  • trunk/Source/WebCore/page/History.cpp

    r104380 r107058  
    4343History::History(Frame* frame)
    4444    : DOMWindowProperty(frame)
     45    , m_lastStateObjectRequested(0)
    4546{
    4647}
     
    5354        return 0;
    5455    return m_frame->page()->backForward()->count();
     56}
     57
     58SerializedScriptValue* History::state()
     59{
     60    m_lastStateObjectRequested = stateInternal();
     61    return m_lastStateObjectRequested;
     62}
     63
     64SerializedScriptValue* History::stateInternal() const
     65{
     66    if (!m_frame)
     67        return 0;
     68
     69    if (HistoryItem* historyItem = m_frame->loader()->history()->currentItem())
     70        return historyItem->stateObject();
     71
     72    return 0;
     73}
     74
     75bool History::stateChanged() const
     76{
     77    return m_lastStateObjectRequested != stateInternal();
    5578}
    5679
  • trunk/Source/WebCore/page/History.h

    r104380 r107058  
    4545
    4646    unsigned length() const;
     47    SerializedScriptValue* state();
     48    bool stateChanged() const;
    4749    void back();
    4850    void forward();
     
    6365
    6466    KURL urlForState(const String& url);
     67
     68    SerializedScriptValue* stateInternal() const;
     69
     70    SerializedScriptValue* m_lastStateObjectRequested;
    6571};
    6672
  • trunk/Source/WebCore/page/History.idl

    r107051 r107058  
    3838    ] History {
    3939        readonly attribute unsigned long length;
     40        readonly attribute [CachedAttribute, Custom] SerializedScriptValue state;
    4041
    4142        [DoNotCheckDomainSecurity, CallWith=ScriptExecutionContext] void back();
Note: See TracChangeset for help on using the changeset viewer.