Skip to content
Permalink
Browse files
Apply changes from storage events locally
https://bugs.webkit.org/show_bug.cgi?id=111502

Reviewed by Sam Weinig.

Source/WebCore:

Add and export a helper function for setting an item without taking
into account the quota for the map. Also, reindent StorageMap.h

* WebCore.exp.in:
* storage/StorageMap.cpp:
(WebCore::StorageMap::setItemIgnoringQuota):
(WebCore):
* storage/StorageMap.h:
(StorageMap):
(WebCore::StorageMap::quota):

Source/WebKit2:

* WebProcess/Storage/StorageAreaProxy.cpp:
(WebKit::StorageAreaProxy::StorageAreaProxy):
Store the security origin as a member variable.

(WebKit::StorageAreaProxy::dispatchStorageEvent):
Set the item and call the appropriate event dispatch function.

(WebKit::StorageAreaProxy::dispatchSessionStorageEvent):
(WebKit::StorageAreaProxy::dispatchLocalStorageEvent):
Add stubs.

* WebProcess/Storage/StorageAreaProxy.h:

Canonical link: https://commits.webkit.org/132040@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@147354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Apr 1, 2013
1 parent 55fad99 commit e012a867ddbffe656e971675d6b4061b819223fb
Showing 10 changed files with 127 additions and 28 deletions.
@@ -1,3 +1,21 @@
2013-03-05 Anders Carlsson <andersca@apple.com>

Apply changes from storage events locally
https://bugs.webkit.org/show_bug.cgi?id=111502

Reviewed by Sam Weinig.

Add and export a helper function for setting an item without taking
into account the quota for the map. Also, reindent StorageMap.h

* WebCore.exp.in:
* storage/StorageMap.cpp:
(WebCore::StorageMap::setItemIgnoringQuota):
(WebCore):
* storage/StorageMap.h:
(StorageMap):
(WebCore::StorageMap::quota):

2013-04-01 Benjamin Poulain <benjamin@webkit.org>

Remove a couple of malloc from ExceptionBase construction
@@ -85,6 +85,7 @@ __ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb
__ZN7WebCore10ScrollView24windowResizerRectChangedEv
__ZN7WebCore10ScrollView8addChildEN3WTF10PassRefPtrINS_6WidgetEEE
__ZN7WebCore10StorageMap11importItemsERKN3WTF7HashMapINS1_6StringES3_NS1_10StringHashENS1_10HashTraitsIS3_EES6_EE
__ZN7WebCore10StorageMap20setItemIgnoringQuotaERKN3WTF6StringES4_
__ZN7WebCore10StorageMap3keyEj
__ZN7WebCore10StorageMap6createEj
__ZN7WebCore10StorageMap7setItemERKN3WTF6StringES4_RS2_Rb
@@ -26,6 +26,8 @@
#include "config.h"
#include "StorageMap.h"

#include <wtf/TemporaryChange.h>

namespace WebCore {

PassRefPtr<StorageMap> StorageMap::create(unsigned quota)
@@ -140,6 +142,19 @@ PassRefPtr<StorageMap> StorageMap::setItem(const String& key, const String& valu
return 0;
}

PassRefPtr<StorageMap> StorageMap::setItemIgnoringQuota(const String& key, const String& value)
{
TemporaryChange<unsigned> quotaSizeChange(m_quotaSize, noQuota);

String oldValue;
bool quotaException;

RefPtr<StorageMap> map = setItem(key, value, oldValue, quotaException);
ASSERT(!quotaException);

return map.release();
}

PassRefPtr<StorageMap> StorageMap::removeItem(const String& key, String& oldValue)
{
// Implement copy-on-write semantics here. We're guaranteed that the only refs of StorageMaps belong to Storage objects
@@ -34,38 +34,39 @@

namespace WebCore {

class StorageMap : public RefCounted<StorageMap> {
public:
// Quota size measured in bytes.
static PassRefPtr<StorageMap> create(unsigned quotaSize);
class StorageMap : public RefCounted<StorageMap> {
public:
// Quota size measured in bytes.
static PassRefPtr<StorageMap> create(unsigned quotaSize);

unsigned length() const;
String key(unsigned index);
String getItem(const String&) const;
PassRefPtr<StorageMap> setItem(const String& key, const String& value, String& oldValue, bool& quota_exception);
PassRefPtr<StorageMap> removeItem(const String&, String& oldValue);
unsigned length() const;
String key(unsigned index);
String getItem(const String&) const;
PassRefPtr<StorageMap> setItem(const String& key, const String& value, String& oldValue, bool& quotaException);
PassRefPtr<StorageMap> setItemIgnoringQuota(const String& key, const String& value);
PassRefPtr<StorageMap> removeItem(const String&, String& oldValue);

bool contains(const String& key) const;
bool contains(const String& key) const;

void importItems(const HashMap<String, String>&);
void importItems(const HashMap<String, String>&);

unsigned quota() const { return m_quotaSize; }
unsigned quota() const { return m_quotaSize; }

static const unsigned noQuota = UINT_MAX;
static const unsigned noQuota = UINT_MAX;

private:
explicit StorageMap(unsigned quota);
PassRefPtr<StorageMap> copy();
void invalidateIterator();
void setIteratorToIndex(unsigned);
private:
explicit StorageMap(unsigned quota);
PassRefPtr<StorageMap> copy();
void invalidateIterator();
void setIteratorToIndex(unsigned);

HashMap<String, String> m_map;
HashMap<String, String>::iterator m_iterator;
unsigned m_iteratorIndex;
HashMap<String, String> m_map;
HashMap<String, String>::iterator m_iterator;
unsigned m_iteratorIndex;

unsigned m_quotaSize; // Measured in bytes.
unsigned m_currentLength; // Measured in UChars.
};
unsigned m_quotaSize; // Measured in bytes.
unsigned m_currentLength; // Measured in UChars.
};

} // namespace WebCore

@@ -1,3 +1,23 @@
2013-03-05 Anders Carlsson <andersca@apple.com>

Apply changes from storage events locally
https://bugs.webkit.org/show_bug.cgi?id=111502

Reviewed by Sam Weinig.

* WebProcess/Storage/StorageAreaProxy.cpp:
(WebKit::StorageAreaProxy::StorageAreaProxy):
Store the security origin as a member variable.

(WebKit::StorageAreaProxy::dispatchStorageEvent):
Set the item and call the appropriate event dispatch function.

(WebKit::StorageAreaProxy::dispatchSessionStorageEvent):
(WebKit::StorageAreaProxy::dispatchLocalStorageEvent):
Add stubs.

* WebProcess/Storage/StorageAreaProxy.h:

2013-04-01 Alexey Proskuryakov <ap@apple.com>

<rdar://problem/13490123> Sandbox extension tracking is incorrect when restoring a session
@@ -57,8 +57,9 @@ StorageAreaProxy::StorageAreaProxy(StorageNamespaceProxy* storageNamespaceProxy,
: m_storageNamespaceID(storageNamespaceProxy->storageNamespaceID())
, m_quotaInBytes(storageNamespaceProxy->quotaInBytes())
, m_storageAreaID(generateStorageAreaID())
, m_securityOrigin(securityOrigin)
{
WebProcess::shared().connection()->send(Messages::StorageManager::CreateStorageArea(m_storageAreaID, storageNamespaceProxy->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(securityOrigin.get())), 0);
WebProcess::shared().connection()->send(Messages::StorageManager::CreateStorageArea(m_storageAreaID, storageNamespaceProxy->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0);
WebProcess::shared().addMessageReceiver(Messages::StorageAreaProxy::messageReceiverName(), m_storageAreaID, this);
}

@@ -216,7 +217,16 @@ void StorageAreaProxy::dispatchStorageEvent(const String& key, const String& old
if (!shouldApplyChangesForKey(key))
return;

// FIXME: Implement this.
ASSERT(!key.isNull());
ASSERT(!newValue.isNull());

ASSERT(m_storageMap->hasOneRef());
m_storageMap->setItemIgnoringQuota(key, newValue);

if (storageType() == SessionStorage)
dispatchSessionStorageEvent(key, oldValue, newValue, urlString);
else
dispatchLocalStorageEvent(key, oldValue, newValue, urlString);
}

StorageType StorageAreaProxy::storageType() const
@@ -274,4 +284,18 @@ void StorageAreaProxy::resetValues()
m_pendingValueChanges.clear();
}

void StorageAreaProxy::dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
{
ASSERT(storageType() == SessionStorage);

// FIXME: Implement.
}

void StorageAreaProxy::dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
{
ASSERT(storageType() == LocalStorage);

// FIXME: Implement.
}

} // namespace WebKit
@@ -74,9 +74,14 @@ class StorageAreaProxy : public WebCore::StorageArea, private CoreIPC::MessageRe
void loadValuesIfNeeded();
void resetValues();

void dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
void dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);

uint64_t m_storageNamespaceID;
unsigned m_quotaInBytes;
uint64_t m_storageAreaID;

RefPtr<WebCore::SecurityOrigin> m_securityOrigin;
RefPtr<WebCore::StorageMap> m_storageMap;

HashCountedSet<String> m_pendingValueChanges;
@@ -52,7 +52,17 @@ StorageNamespaceProxy::~StorageNamespaceProxy()

PassRefPtr<StorageArea> StorageNamespaceProxy::storageArea(PassRefPtr<SecurityOrigin> securityOrigin)
{
return StorageAreaProxy::create(this, securityOrigin);
printf("%p - looking for storage area in %s\n", this, securityOrigin->toString().utf8().data());
HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaProxy> >::AddResult result = m_storageAreaMap.add(securityOrigin.get(), 0);
if (result.isNewEntry) {
result.iterator->value = StorageAreaProxy::create(this, securityOrigin);
printf("new entry!!\n");
} else {
printf("reusing!!\n");
}

printf("returning %p\n", result.iterator->value.get());
return result.iterator->value;
}

PassRefPtr<StorageNamespace> StorageNamespaceProxy::copy()
@@ -26,11 +26,14 @@
#ifndef StorageNamespaceProxy_h
#define StorageNamespaceProxy_h

#include <WebCore/SecurityOriginHash.h>
#include <WebCore/StorageArea.h>
#include <WebCore/StorageNamespace.h>
#include <wtf/HashMap.h>

namespace WebKit {

class StorageAreaProxy;
class WebPage;

class StorageNamespaceProxy : public WebCore::StorageNamespace {
@@ -54,6 +57,8 @@ class StorageNamespaceProxy : public WebCore::StorageNamespace {

uint64_t m_storageNamespaceID;
unsigned m_quotaInBytes;

HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaProxy> > m_storageAreaMap;
};

} // namespace WebKit
@@ -60,7 +60,7 @@
#endif

// FIXME: Remove this once it works well enough to be the default.
#define ENABLE_UI_PROCESS_STORAGE 0
#define ENABLE_UI_PROCESS_STORAGE 1

using namespace WebCore;

0 comments on commit e012a86

Please sign in to comment.