- Revision
- 152273
- Author
- [email protected]
- Date
- 2013-07-01 17:08:56 -0700 (Mon, 01 Jul 2013)
Log Message
Clean up private browsing session tracking
https://bugs.webkit.org/show_bug.cgi?id=118266
<rdar://problem/13078036>
Reviewed by Brady Eidson.
Instead of counting API calls, we now watch actual WebPreferences objects.
* UIProcess/API/C/WKPreferences.cpp: (WKPreferencesSetPrivateBrowsingEnabled):
Removed code that used to notify WebContext. It's now done by WebPreferences.
* UIProcess/WebContext.h:
* UIProcess/WebContext.cpp:
(WebKit::WebContext::ensureNetworkProcess): Instead of counting the number of times
API was called, rely on WebPreferences tracking.
(WebKit::WebContext::willStartUsingPrivateBrowsing): Ditto. This function is
now only called when we detect a change in private browsing state.
(WebKit::WebContext::willStopUsingPrivateBrowsing): Ditto.
(WebKit::WebContext::createNewWebProcess): Tell the new process to create a private
browsing session if needed.
* UIProcess/WebPreferences.h:
* UIProcess/WebPreferences.cpp:
(WebKit::WebPreferences::addPageGroup): Count how many page groups use private
browsing, and notify WebContext when a session is needed. Note that we don't notify
WebContext about WebPreferences without any page groups, because it's likely
that preferences will be updated by the client before groups are associated.
(WebKit::WebPreferences::removePageGroup): Ditto.
(WebKit::WebPreferences::updateBoolValueForKey): Perform special handling for
private browsing mode changes.
(WebKit::WebPreferences::updatePrivateBrowsingValue): Notify WebContext when
it's time to create or destroy a private browsing session.
(WebKit::WebPreferences::anyPageGroupsAreUsingPrivateBrowsing): A getter for
WebContext to know when any page groups are in private browsing mode.
* WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::updatePreferences):
Don't create a private browsing session implicitly, UI process takes care of it.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (152272 => 152273)
--- trunk/Source/WebKit2/ChangeLog 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/ChangeLog 2013-07-02 00:08:56 UTC (rev 152273)
@@ -1,3 +1,43 @@
+2013-07-01 Alexey Proskuryakov <[email protected]>
+
+ Clean up private browsing session tracking
+ https://bugs.webkit.org/show_bug.cgi?id=118266
+ <rdar://problem/13078036>
+
+ Reviewed by Brady Eidson.
+
+ Instead of counting API calls, we now watch actual WebPreferences objects.
+
+ * UIProcess/API/C/WKPreferences.cpp: (WKPreferencesSetPrivateBrowsingEnabled):
+ Removed code that used to notify WebContext. It's now done by WebPreferences.
+
+ * UIProcess/WebContext.h:
+ * UIProcess/WebContext.cpp:
+ (WebKit::WebContext::ensureNetworkProcess): Instead of counting the number of times
+ API was called, rely on WebPreferences tracking.
+ (WebKit::WebContext::willStartUsingPrivateBrowsing): Ditto. This function is
+ now only called when we detect a change in private browsing state.
+ (WebKit::WebContext::willStopUsingPrivateBrowsing): Ditto.
+ (WebKit::WebContext::createNewWebProcess): Tell the new process to create a private
+ browsing session if needed.
+
+ * UIProcess/WebPreferences.h:
+ * UIProcess/WebPreferences.cpp:
+ (WebKit::WebPreferences::addPageGroup): Count how many page groups use private
+ browsing, and notify WebContext when a session is needed. Note that we don't notify
+ WebContext about WebPreferences without any page groups, because it's likely
+ that preferences will be updated by the client before groups are associated.
+ (WebKit::WebPreferences::removePageGroup): Ditto.
+ (WebKit::WebPreferences::updateBoolValueForKey): Perform special handling for
+ private browsing mode changes.
+ (WebKit::WebPreferences::updatePrivateBrowsingValue): Notify WebContext when
+ it's time to create or destroy a private browsing session.
+ (WebKit::WebPreferences::anyPageGroupsAreUsingPrivateBrowsing): A getter for
+ WebContext to know when any page groups are in private browsing mode.
+
+ * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::updatePreferences):
+ Don't create a private browsing session implicitly, UI process takes care of it.
+
2013-07-01 Timothy Hatcher <[email protected]>
Link to WebInspectorUI.framework at build time instead of soft linking.
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp (152272 => 152273)
--- trunk/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp 2013-07-02 00:08:56 UTC (rev 152273)
@@ -341,15 +341,6 @@
void WKPreferencesSetPrivateBrowsingEnabled(WKPreferencesRef preferencesRef, bool enabled)
{
- if (toImpl(preferencesRef)->privateBrowsingEnabled() == enabled)
- return;
-
- // Regardless of whether there are any open pages, we should tell WebContext, so that it could track browsing sessions.
- if (enabled)
- WebContext::willStartUsingPrivateBrowsing();
- else
- WebContext::willStopUsingPrivateBrowsing();
-
toImpl(preferencesRef)->setPrivateBrowsingEnabled(enabled);
}
Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (152272 => 152273)
--- trunk/Source/WebKit2/UIProcess/WebContext.cpp 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp 2013-07-02 00:08:56 UTC (rev 152273)
@@ -50,6 +50,7 @@
#include "WebNotificationManagerProxy.h"
#include "WebPluginSiteDataManager.h"
#include "WebPageGroup.h"
+#include "WebPreferences.h"
#include "WebMemorySampler.h"
#include "WebProcessCreationParameters.h"
#include "WebProcessMessages.h"
@@ -97,8 +98,6 @@
static const double sharedSecondaryProcessShutdownTimeout = 60;
-unsigned WebContext::m_privateBrowsingEnterCount;
-
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webContextCounter, ("WebContext"));
PassRefPtr<WebContext> WebContext::create(const String& injectedBundlePath)
@@ -373,10 +372,7 @@
if (!parameters.diskCacheDirectory.isEmpty())
SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle);
- // FIXME: We don't account for private browsing mode being enabled due to a persistent preference in any of active page groups.
- // This means that clients must re-enable private browsing mode through API on each launch, not relying on preferences.
- // If the client does not re-enable private browsing on next launch, NetworkProcess will crash.
- parameters.privateBrowsingEnabled = m_privateBrowsingEnterCount;
+ parameters.privateBrowsingEnabled = WebPreferences::anyPageGroupsAreUsingPrivateBrowsing();
parameters.cacheModel = m_cacheModel;
@@ -416,9 +412,6 @@
void WebContext::willStartUsingPrivateBrowsing()
{
- if (m_privateBrowsingEnterCount++)
- return;
-
const Vector<WebContext*>& contexts = allContexts();
for (size_t i = 0, count = contexts.size(); i < count; ++i) {
#if ENABLE(NETWORK_PROCESS)
@@ -431,11 +424,6 @@
void WebContext::willStopUsingPrivateBrowsing()
{
- // If the client asks to disable private browsing without enabling it first, it may be resetting a persistent preference,
- // so it is still necessary to destroy any existing private browsing session.
- if (m_privateBrowsingEnterCount && --m_privateBrowsingEnterCount)
- return;
-
const Vector<WebContext*>& contexts = allContexts();
for (size_t i = 0, count = contexts.size(); i < count; ++i) {
#if ENABLE(NETWORK_PROCESS)
@@ -562,6 +550,9 @@
injectedBundleInitializationUserData = m_injectedBundleInitializationUserData;
process->send(Messages::WebProcess::InitializeWebProcess(parameters, WebContextUserMessageEncoder(injectedBundleInitializationUserData.get())), 0);
+ if (WebPreferences::anyPageGroupsAreUsingPrivateBrowsing())
+ process->send(Messages::WebProcess::EnsurePrivateBrowsingSession(), 0);
+
m_processes.append(process);
if (m_processModel == ProcessModelSharedSecondaryProcess) {
Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (152272 => 152273)
--- trunk/Source/WebKit2/UIProcess/WebContext.h 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h 2013-07-02 00:08:56 UTC (rev 152273)
@@ -422,10 +422,6 @@
bool m_alwaysUsesComplexTextCodePath;
bool m_shouldUseFontSmoothing;
- // How many times an API call was used to enable the preference.
- // The variable can be 0 when private browsing is used if it's enabled due to a persistent preference.
- static unsigned m_privateBrowsingEnterCount;
-
// Messages that were posted before any pages were created.
// The client should use initialization messages instead, so that a restarted process would get the same state.
Vector<pair<String, RefPtr<APIObject>>> m_messagesToInjectedBundlePostedToEmptyContext;
Modified: trunk/Source/WebKit2/UIProcess/WebPreferences.cpp (152272 => 152273)
--- trunk/Source/WebKit2/UIProcess/WebPreferences.cpp 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/UIProcess/WebPreferences.cpp 2013-07-02 00:08:56 UTC (rev 152273)
@@ -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();
@@ -49,16 +55,32 @@
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()
@@ -75,6 +97,11 @@
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.
}
@@ -97,6 +124,30 @@
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) \
{ \
@@ -115,4 +166,9 @@
#undef DEFINE_PREFERENCE_GETTER_AND_SETTERS
+bool WebPreferences::anyPageGroupsAreUsingPrivateBrowsing()
+{
+ return privateBrowsingPageGroupCount;
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/WebPreferences.h (152272 => 152273)
--- trunk/Source/WebKit2/UIProcess/WebPreferences.h 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/UIProcess/WebPreferences.h 2013-07-02 00:08:56 UTC (rev 152273)
@@ -75,6 +75,8 @@
// Exposed for WebKitTestRunner use only.
void forceUpdate() { update(); }
+ static bool anyPageGroupsAreUsingPrivateBrowsing();
+
private:
WebPreferences();
explicit WebPreferences(const String&);
@@ -95,6 +97,8 @@
void platformUpdateDoubleValueForKey(const String& key, double value);
void platformUpdateFloatValueForKey(const String& key, float value);
+ void updatePrivateBrowsingValue(bool value);
+
HashSet<WebPageGroup*> m_pageGroups;
WebPreferencesStore m_store;
String m_identifier;
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (152272 => 152273)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2013-07-01 23:36:24 UTC (rev 152272)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2013-07-02 00:08:56 UTC (rev 152273)
@@ -2435,12 +2435,7 @@
settings->setLocalStorageEnabled(store.getBoolValueForKey(WebPreferencesKey::localStorageEnabledKey()));
settings->setXSSAuditorEnabled(store.getBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey()));
settings->setFrameFlatteningEnabled(store.getBoolValueForKey(WebPreferencesKey::frameFlatteningEnabledKey()));
-
- bool privateBrowsingEnabled = store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey());
- if (privateBrowsingEnabled)
- WebProcess::shared().ensurePrivateBrowsingSession();
- settings->setPrivateBrowsingEnabled(privateBrowsingEnabled);
-
+ settings->setPrivateBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey()));
settings->setDeveloperExtrasEnabled(store.getBoolValueForKey(WebPreferencesKey::developerExtrasEnabledKey()));
settings->setJavaScriptExperimentsEnabled(store.getBoolValueForKey(WebPreferencesKey::_javascript_ExperimentsEnabledKey()));
settings->setTextAreasAreResizable(store.getBoolValueForKey(WebPreferencesKey::textAreasAreResizableKey()));