Changeset 53710 in webkit


Ignore:
Timestamp:
Jan 22, 2010 12:33:41 PM (14 years ago)
Author:
jorlow@chromium.org
Message:

2010-01-21 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Darin Fisher.

The Chromium WebKit API needs to expose storage event related data
https://bugs.webkit.org/show_bug.cgi?id=33985

setItem and removeItem on WebStorageArea need to expose what the previous
value was for the key being modified. Clear needs to return whether it
actually cleared anything.

  • public/WebStorageArea.h: (WebKit::WebStorageArea::setItem): (WebKit::WebStorageArea::removeItem): (WebKit::WebStorageArea::clear):
  • src/StorageAreaProxy.cpp: (WebCore::StorageAreaProxy::StorageAreaProxy): (WebCore::StorageAreaProxy::setItem): (WebCore::StorageAreaProxy::removeItem): (WebCore::StorageAreaProxy::clear): (WebCore::StorageAreaProxy::storageEvent):
  • src/StorageAreaProxy.h:
  • src/StorageNamespaceProxy.cpp: (WebCore::StorageNamespace::localStorageNamespace): (WebCore::StorageNamespace::sessionStorageNamespace): (WebCore::StorageNamespaceProxy::StorageNamespaceProxy): (WebCore::StorageNamespaceProxy::copy): (WebCore::StorageNamespaceProxy::storageArea):
  • src/StorageNamespaceProxy.h:
  • src/WebStorageAreaImpl.cpp: (WebKit::WebStorageAreaImpl::setItem): (WebKit::WebStorageAreaImpl::removeItem): (WebKit::WebStorageAreaImpl::clear):
  • src/WebStorageAreaImpl.h:

2010-01-21 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Darin Fisher.

The Chromium WebKit API needs to expose storage event related data
https://bugs.webkit.org/show_bug.cgi?id=33985

This change is not visible to layoutTests/web pages.

  • storage/StorageArea.h:
  • storage/StorageAreaImpl.cpp: (WebCore::StorageAreaImpl::setItem): return the old value (WebCore::StorageAreaImpl::removeItem): return the old value (WebCore::StorageAreaImpl::clear): return whether there was anything to clear
  • storage/StorageAreaImpl.h:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53709 r53710  
     12010-01-21  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        The Chromium WebKit API needs to expose storage event related data
     6        https://bugs.webkit.org/show_bug.cgi?id=33985
     7
     8        This change is not visible to layoutTests/web pages.
     9
     10        * storage/StorageArea.h:
     11        * storage/StorageAreaImpl.cpp:
     12        (WebCore::StorageAreaImpl::setItem): return the old value
     13        (WebCore::StorageAreaImpl::removeItem): return the old value
     14        (WebCore::StorageAreaImpl::clear): return whether there was anything to clear
     15        * storage/StorageAreaImpl.h:
     16
    1172010-01-22  Adele Peterson  <adele@apple.com>
    218
  • trunk/WebCore/storage/StorageArea.h

    r48939 r53710  
    5151        virtual String key(unsigned index) const = 0;
    5252        virtual String getItem(const String& key) const = 0;
    53         virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) = 0;
    54         virtual void removeItem(const String& key, Frame* sourceFrame) = 0;
    55         virtual void clear(Frame* sourceFrame) = 0;
     53        virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame) = 0;
     54        virtual String removeItem(const String& key, Frame* sourceFrame) = 0;
     55        virtual bool clear(Frame* sourceFrame) = 0;
    5656        virtual bool contains(const String& key) const = 0;
    5757    };
  • trunk/WebCore/storage/StorageAreaImpl.cpp

    r50581 r53710  
    129129}
    130130
    131 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
     131String StorageAreaImpl::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
    132132{
    133133    ASSERT(!m_isShutdown);
     
    137137    if (privateBrowsingEnabled(frame)) {
    138138        ec = QUOTA_EXCEEDED_ERR;
    139         return;
     139        return String();
    140140    }
    141141
     
    148148    if (quotaException) {
    149149        ec = QUOTA_EXCEEDED_ERR;
    150         return;
     150        return oldValue;
    151151    }
    152152
    153153    if (oldValue == value)
    154         return;
     154        return oldValue;
    155155
    156156    if (m_storageAreaSync)
    157157        m_storageAreaSync->scheduleItemForSync(key, value);
    158158    StorageEventDispatcher::dispatch(key, oldValue, value, m_storageType, m_securityOrigin.get(), frame);
    159 }
    160 
    161 void StorageAreaImpl::removeItem(const String& key, Frame* frame)
     159    return oldValue;
     160}
     161
     162String StorageAreaImpl::removeItem(const String& key, Frame* frame)
    162163{
    163164    ASSERT(!m_isShutdown);
     
    165166
    166167    if (privateBrowsingEnabled(frame))
    167         return;
     168        return String();
    168169
    169170    String oldValue;
     
    173174
    174175    if (oldValue.isNull())
    175         return;
     176        return oldValue;
    176177
    177178    if (m_storageAreaSync)
    178179        m_storageAreaSync->scheduleItemForSync(key, String());
    179180    StorageEventDispatcher::dispatch(key, oldValue, String(), m_storageType, m_securityOrigin.get(), frame);
    180 }
    181 
    182 void StorageAreaImpl::clear(Frame* frame)
     181    return oldValue;
     182}
     183
     184bool StorageAreaImpl::clear(Frame* frame)
    183185{
    184186    ASSERT(!m_isShutdown);
     
    186188
    187189    if (privateBrowsingEnabled(frame))
    188         return;
     190        return false;
    189191
    190192    if (!m_storageMap->length())
    191         return;
     193        return false;
    192194
    193195    unsigned quota = m_storageMap->quota();
     
    197199        m_storageAreaSync->scheduleClear();
    198200    StorageEventDispatcher::dispatch(String(), String(), String(), m_storageType, m_securityOrigin.get(), frame);
     201    return true;
    199202}
    200203
  • trunk/WebCore/storage/StorageAreaImpl.h

    r50581 r53710  
    4949        virtual String key(unsigned index) const;
    5050        virtual String getItem(const String& key) const;
    51         virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
    52         virtual void removeItem(const String& key, Frame* sourceFrame);
    53         virtual void clear(Frame* sourceFrame);
     51        virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
     52        virtual String removeItem(const String& key, Frame* sourceFrame);
     53        virtual bool clear(Frame* sourceFrame);
    5454        virtual bool contains(const String& key) const;
    5555
  • trunk/WebKit/chromium/ChangeLog

    r53705 r53710  
     12010-01-21  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        The Chromium WebKit API needs to expose storage event related data
     6        https://bugs.webkit.org/show_bug.cgi?id=33985
     7
     8        setItem and removeItem on WebStorageArea need to expose what the previous
     9        value was for the key being modified.  Clear needs to return whether it
     10        actually cleared anything.
     11
     12        * public/WebStorageArea.h:
     13        (WebKit::WebStorageArea::setItem):
     14        (WebKit::WebStorageArea::removeItem):
     15        (WebKit::WebStorageArea::clear):
     16        * src/StorageAreaProxy.cpp:
     17        (WebCore::StorageAreaProxy::StorageAreaProxy):
     18        (WebCore::StorageAreaProxy::setItem):
     19        (WebCore::StorageAreaProxy::removeItem):
     20        (WebCore::StorageAreaProxy::clear):
     21        (WebCore::StorageAreaProxy::storageEvent):
     22        * src/StorageAreaProxy.h:
     23        * src/StorageNamespaceProxy.cpp:
     24        (WebCore::StorageNamespace::localStorageNamespace):
     25        (WebCore::StorageNamespace::sessionStorageNamespace):
     26        (WebCore::StorageNamespaceProxy::StorageNamespaceProxy):
     27        (WebCore::StorageNamespaceProxy::copy):
     28        (WebCore::StorageNamespaceProxy::storageArea):
     29        * src/StorageNamespaceProxy.h:
     30        * src/WebStorageAreaImpl.cpp:
     31        (WebKit::WebStorageAreaImpl::setItem):
     32        (WebKit::WebStorageAreaImpl::removeItem):
     33        (WebKit::WebStorageAreaImpl::clear):
     34        * src/WebStorageAreaImpl.h:
     35
    1362010-01-21  Darin Fisher  <darin@chromium.org>
    237
  • trunk/WebKit/chromium/public/WebStorageArea.h

    r50688 r53710  
    3333
    3434#include "WebCommon.h"
     35#include "WebString.h"
    3536
    3637namespace WebKit {
    3738
    38 class WebString;
    3939class WebURL;
    4040
     
    6161    // the StorageArea would have exceeded its quota. The value is NOT set when there's
    6262    // an exception.  url is the url that should be used if a storage event fires.
    63     virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException) = 0;
     63    // FIXME: The following is a hack to keep Chromium compiling until the other half is landed.  Remove soon.
     64    virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, bool& quotaException) // Deprecated.
     65    {
     66        WebString oldValue;
     67        setItem(key, newValue, url, quotaException, oldValue);
     68    }
     69    virtual void setItem(const WebString& key, const WebString& newValue, const WebURL& url, bool& quotaException, WebString& oldValue)
     70    {
     71        setItem(key, newValue, url, quotaException);
     72    }
    6473
    6574    // Remove the value associated with a particular key.  url is the url that should be used
    6675    // if a storage event fires.
    67     virtual void removeItem(const WebString& key, const WebURL& url) = 0;
     76    // FIXME: The following is a hack to keep Chromium compiling until the other half is landed.  Remove soon.
     77    virtual void removeItem(const WebString& key, const WebURL& url) // Deprecated.
     78    {
     79        WebString oldValue;
     80        removeItem(key, url, oldValue);
     81    }
     82    virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue)
     83    {
     84        removeItem(key, url);
     85    }
    6886
    6987    // Clear all key/value pairs.  url is the url that should be used if a storage event fires.
    70     virtual void clear(const WebURL& url) = 0;
     88    // FIXME: The following is a hack to keep Chromium compiling until the other half is landed.  Remove soon.
     89    virtual void clear(const WebURL& url) // Deprecated.
     90    {
     91        bool somethingCleared;
     92        clear(url, somethingCleared);
     93    }
     94    virtual void clear(const WebURL& url, bool& somethingCleared)
     95    {
     96        clear(url);
     97    }
    7198};
    7299
  • trunk/WebKit/chromium/src/StorageAreaProxy.cpp

    r50746 r53710  
    11/*
    22 * Copyright (C) 2009 Google Inc. All Rights Reserved.
     3 *           (C) 2008 Apple Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2930#if ENABLE(DOM_STORAGE)
    3031
     32#include "DOMWindow.h"
    3133#include "Document.h"
     34#include "EventNames.h"
    3235#include "ExceptionCode.h"
    3336#include "Frame.h"
     37#include "Page.h"
     38#include "PageGroup.h"
    3439#include "SecurityOrigin.h"
    3540#include "StorageAreaImpl.h"
     41#include "StorageEvent.h"
    3642
    3743#include "WebStorageArea.h"
     
    4147namespace WebCore {
    4248
    43 StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea)
     49StorageAreaProxy::StorageAreaProxy(WebKit::WebStorageArea* storageArea, StorageType storageType)
    4450    : m_storageArea(storageArea)
     51    , m_storageType(storageType)
    4552{
    4653}
     
    6572}
    6673
    67 void StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
     74String StorageAreaProxy::setItem(const String& key, const String& value, ExceptionCode& ec, Frame* frame)
    6875{
    6976    bool quotaException = false;
    70     m_storageArea->setItem(key, value, frame->document()->url(), quotaException);
     77    WebKit::WebString oldValue;
     78    m_storageArea->setItem(key, value, frame->document()->url(), quotaException, oldValue);
    7179    ec = quotaException ? QUOTA_EXCEEDED_ERR : 0;
     80    String oldValueString = oldValue;
     81    if (oldValueString != value)
     82        storageEvent(key, oldValue, value, m_storageType, frame->document()->securityOrigin(), frame);
     83    return oldValue;
    7284}
    7385
    74 void StorageAreaProxy::removeItem(const String& key, Frame* frame)
     86String StorageAreaProxy::removeItem(const String& key, Frame* frame)
    7587{
    76     m_storageArea->removeItem(key, frame->document()->url());
     88    WebKit::WebString oldValue;
     89    m_storageArea->removeItem(key, frame->document()->url(), oldValue);
     90    if (!oldValue.isNull())
     91        storageEvent(key, oldValue, String(), m_storageType, frame->document()->securityOrigin(), frame);
     92    return oldValue;
    7793}
    7894
    79 void StorageAreaProxy::clear(Frame* frame)
     95bool StorageAreaProxy::clear(Frame* frame)
    8096{
    81     m_storageArea->clear(frame->document()->url());
     97    bool clearedSomething;
     98    m_storageArea->clear(frame->document()->url(), clearedSomething);
     99    if (clearedSomething)
     100        storageEvent(String(), String(), String(), m_storageType, frame->document()->securityOrigin(), frame);
     101    return clearedSomething;
    82102}
    83103
     
    87107}
    88108
     109// Copied from WebCore/storage/StorageEventDispatcher.cpp out of necessity.  It's probably best to keep it current.
     110void StorageAreaProxy::storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Frame* sourceFrame)
     111{
     112    Page* page = sourceFrame->page();
     113    if (!page)
     114        return;
     115
     116    // We need to copy all relevant frames from every page to a vector since sending the event to one frame might mutate the frame tree
     117    // of any given page in the group or mutate the page group itself.
     118    Vector<RefPtr<Frame> > frames;
     119    if (storageType == SessionStorage) {
     120        // Send events only to our page.
     121        for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
     122            if (frame->document()->securityOrigin()->equal(securityOrigin))
     123                frames.append(frame);
     124        }
     125
     126        for (unsigned i = 0; i < frames.size(); ++i)
     127            frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->sessionStorage()));
     128    } else {
     129        // Send events to every page.
     130        const HashSet<Page*>& pages = page->group().pages();
     131        HashSet<Page*>::const_iterator end = pages.end();
     132        for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) {
     133            for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
     134                if (frame->document()->securityOrigin()->equal(securityOrigin))
     135                    frames.append(frame);
     136            }
     137        }
     138
     139        for (unsigned i = 0; i < frames.size(); ++i)
     140            frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->localStorage()));
     141    }
     142}
     143
    89144} // namespace WebCore
    90145
  • trunk/WebKit/chromium/src/StorageAreaProxy.h

    r50746 r53710  
    3535namespace WebCore {
    3636
     37class Frame;
     38class SecurityOrigin;
     39
    3740class StorageAreaProxy : public StorageArea {
    3841public:
    39     StorageAreaProxy(WebKit::WebStorageArea* storageArea);
     42    StorageAreaProxy(WebKit::WebStorageArea*, StorageType);
    4043    virtual ~StorageAreaProxy();
    4144
     
    4447    virtual String key(unsigned index) const;
    4548    virtual String getItem(const String& key) const;
    46     virtual void setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
    47     virtual void removeItem(const String& key, Frame* sourceFrame);
    48     virtual void clear(Frame* sourceFrame);
     49    virtual String setItem(const String& key, const String& value, ExceptionCode& ec, Frame* sourceFrame);
     50    virtual String removeItem(const String& key, Frame* sourceFrame);
     51    virtual bool clear(Frame* sourceFrame);
    4952    virtual bool contains(const String& key) const;
    5053
    5154private:
     55    void storageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*, Frame* sourceFrame);
     56
    5257    OwnPtr<WebKit::WebStorageArea> m_storageArea;
     58    StorageType m_storageType;
    5359};
    5460
  • trunk/WebKit/chromium/src/StorageNamespaceProxy.cpp

    r53321 r53710  
    4545PassRefPtr<StorageNamespace> StorageNamespace::localStorageNamespace(const String& path, unsigned quota)
    4646{
    47     return adoptRef(new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota)));
     47    return adoptRef(new StorageNamespaceProxy(WebKit::webKitClient()->createLocalStorageNamespace(path, quota), LocalStorage));
    4848}
    4949
     
    5252    WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(page->chrome()->client());
    5353    WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client();
    54     return adoptRef(new StorageNamespaceProxy(webViewClient->createSessionStorageNamespace()));
     54    return adoptRef(new StorageNamespaceProxy(webViewClient->createSessionStorageNamespace(), SessionStorage));
    5555}
    5656
    57 StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace)
     57StorageNamespaceProxy::StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace, StorageType storageType)
    5858    : m_storageNamespace(storageNamespace)
     59    , m_storageType(storageType)
    5960{
    6061}
     
    6667PassRefPtr<StorageNamespace> StorageNamespaceProxy::copy()
    6768{
    68     return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy()));
     69    return adoptRef(new StorageNamespaceProxy(m_storageNamespace->copy(), m_storageType));
    6970}
    7071
    7172PassRefPtr<StorageArea> StorageNamespaceProxy::storageArea(PassRefPtr<SecurityOrigin> origin)
    7273{
    73     return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString())));
     74    return adoptRef(new StorageAreaProxy(m_storageNamespace->createStorageArea(origin->toString()), m_storageType));
    7475}
    7576
  • trunk/WebKit/chromium/src/StorageNamespaceProxy.h

    r50746 r53710  
    2929#if ENABLE(DOM_STORAGE)
    3030
     31#include "StorageArea.h"
    3132#include "StorageNamespace.h"
    3233
     
    3738class StorageNamespaceProxy : public StorageNamespace {
    3839public:
    39     StorageNamespaceProxy(WebKit::WebStorageNamespace* storageNamespace);
     40    StorageNamespaceProxy(WebKit::WebStorageNamespace*, StorageType);
    4041    virtual ~StorageNamespaceProxy();
    4142    virtual PassRefPtr<StorageArea> storageArea(PassRefPtr<SecurityOrigin>);
     
    4647private:
    4748    OwnPtr<WebKit::WebStorageNamespace> m_storageNamespace;
     49    StorageType m_storageType;
    4850};
    4951
  • trunk/WebKit/chromium/src/WebStorageAreaImpl.cpp

    r50723 r53710  
    6767}
    6868
    69 void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException)
     69void WebStorageAreaImpl::setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue)
    7070{
    7171    int exceptionCode = 0;
    7272
    7373    ScopedStorageEventURL scope(url);
    74     m_storageArea->setItem(key, value, exceptionCode, 0);
     74    oldValue = m_storageArea->setItem(key, value, exceptionCode, 0);
    7575
    7676    if (exceptionCode) {
     
    8181}
    8282
    83 void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url)
     83void WebStorageAreaImpl::removeItem(const WebString& key, const WebURL& url, WebString& oldValue)
    8484{
    8585    ScopedStorageEventURL scope(url);
    86     m_storageArea->removeItem(key, 0);
     86    oldValue = m_storageArea->removeItem(key, 0);
    8787}
    8888
    89 void WebStorageAreaImpl::clear(const WebURL& url)
     89void WebStorageAreaImpl::clear(const WebURL& url, bool& somethingCleared)
    9090{
    9191    ScopedStorageEventURL scope(url);
    92     m_storageArea->clear(0);
     92    somethingCleared = m_storageArea->clear(0);
    9393}
    9494
  • trunk/WebKit/chromium/src/WebStorageAreaImpl.h

    r50723 r53710  
    4646    virtual WebString key(unsigned index);
    4747    virtual WebString getItem(const WebString& key);
    48     virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException);
    49     virtual void removeItem(const WebString& key, const WebURL& url);
    50     virtual void clear(const WebURL& url);
     48    virtual void setItem(const WebString& key, const WebString& value, const WebURL& url, bool& quotaException, WebString& oldValue);
     49    virtual void removeItem(const WebString& key, const WebURL& url, WebString& oldValue);
     50    virtual void clear(const WebURL& url, bool& somethingCleared);
    5151
    5252    // For storage events in single-process mode and test shell.
Note: See TracChangeset for help on using the changeset viewer.