summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/WebPreferences.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-13 12:51:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commitd441d6f39bb846989d95bcf5caf387b42414718d (patch)
treee367e64a75991c554930278175d403c072de6bb8 /Source/WebKit2/UIProcess/WebPreferences.cpp
parent0060b2994c07842f4c59de64b5e3e430525c4b90 (diff)
downloadqtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebKit2/UIProcess/WebPreferences.cpp')
-rw-r--r--Source/WebKit2/UIProcess/WebPreferences.cpp63
1 files changed, 59 insertions, 4 deletions
diff --git a/Source/WebKit2/UIProcess/WebPreferences.cpp b/Source/WebKit2/UIProcess/WebPreferences.cpp
index bbc2380d1..4768f28bf 100644
--- a/Source/WebKit2/UIProcess/WebPreferences.cpp
+++ b/Source/WebKit2/UIProcess/WebPreferences.cpp
@@ -26,10 +26,16 @@
#include "config.h"
#include "WebPreferences.h"
+#include "WebContext.h"
#include "WebPageGroup.h"
+#include <wtf/ThreadingPrimitives.h>
namespace WebKit {
+// FIXME: Manipulating this variable is not thread safe.
+// Instead of tracking private browsing state as a boolean preference, we should let the client provide storage sessions explicitly.
+static unsigned privateBrowsingPageGroupCount;
+
WebPreferences::WebPreferences()
{
platformInitializeStore();
@@ -42,24 +48,39 @@ WebPreferences::WebPreferences(const String& identifier)
}
WebPreferences::WebPreferences(const WebPreferences& other)
- : APIObject()
- , m_store(other.m_store)
+ : m_store(other.m_store)
{
platformInitializeStore();
}
WebPreferences::~WebPreferences()
{
+ ASSERT(m_pageGroups.isEmpty());
}
void WebPreferences::addPageGroup(WebPageGroup* pageGroup)
{
- m_pageGroups.add(pageGroup);
+ bool didAddPageGroup = m_pageGroups.add(pageGroup).isNewEntry;
+ if (didAddPageGroup && privateBrowsingEnabled()) {
+ if (!privateBrowsingPageGroupCount)
+ WebContext::willStartUsingPrivateBrowsing();
+ ++privateBrowsingPageGroupCount;
+ }
}
void WebPreferences::removePageGroup(WebPageGroup* pageGroup)
{
- m_pageGroups.remove(pageGroup);
+ HashSet<WebPageGroup*>::iterator iter = m_pageGroups.find(pageGroup);
+ if (iter == m_pageGroups.end())
+ return;
+
+ m_pageGroups.remove(iter);
+
+ if (privateBrowsingEnabled()) {
+ --privateBrowsingPageGroupCount;
+ if (!privateBrowsingPageGroupCount)
+ WebContext::willStopUsingPrivateBrowsing();
+ }
}
void WebPreferences::update()
@@ -76,6 +97,11 @@ void WebPreferences::updateStringValueForKey(const String& key, const String& va
void WebPreferences::updateBoolValueForKey(const String& key, bool value)
{
+ if (key == WebPreferencesKey::privateBrowsingEnabledKey()) {
+ updatePrivateBrowsingValue(value);
+ return;
+ }
+
platformUpdateBoolValueForKey(key, value);
update(); // FIXME: Only send over the changed key and value.
}
@@ -98,6 +124,30 @@ void WebPreferences::updateFloatValueForKey(const String& key, float value)
update(); // FIXME: Only send over the changed key and value.
}
+void WebPreferences::updatePrivateBrowsingValue(bool value)
+{
+ platformUpdateBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey(), value);
+
+ unsigned pageGroupsChanged = m_pageGroups.size();
+ if (!pageGroupsChanged)
+ return;
+
+ if (value) {
+ if (!privateBrowsingPageGroupCount)
+ WebContext::willStartUsingPrivateBrowsing();
+ privateBrowsingPageGroupCount += pageGroupsChanged;
+ }
+
+ update(); // FIXME: Only send over the changed key and value.
+
+ if (!value) {
+ ASSERT(privateBrowsingPageGroupCount >= pageGroupsChanged);
+ privateBrowsingPageGroupCount -= pageGroupsChanged;
+ if (!privateBrowsingPageGroupCount)
+ WebContext::willStopUsingPrivateBrowsing();
+ }
+}
+
#define DEFINE_PREFERENCE_GETTER_AND_SETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
void WebPreferences::set##KeyUpper(const Type& value) \
{ \
@@ -116,4 +166,9 @@ FOR_EACH_WEBKIT_PREFERENCE(DEFINE_PREFERENCE_GETTER_AND_SETTERS)
#undef DEFINE_PREFERENCE_GETTER_AND_SETTERS
+bool WebPreferences::anyPageGroupsAreUsingPrivateBrowsing()
+{
+ return privateBrowsingPageGroupCount;
+}
+
} // namespace WebKit