Commit 15f97af4 authored by weinig@apple.com's avatar weinig@apple.com

Add supplementability for WebContext

https://bugs.webkit.org/show_bug.cgi?id=105878

Reviewed by Dan Bernstein.

Add WebContextSupplement and convert WebApplicationCacheManagerProxy to it.

* UIProcess/API/C/WKContext.cpp:
(WKContextGetApplicationCacheManager):
* UIProcess/WebApplicationCacheManagerProxy.cpp:
(WebKit::WebApplicationCacheManagerProxy::supplementName):
(WebKit::WebApplicationCacheManagerProxy::WebApplicationCacheManagerProxy):
(WebKit::WebApplicationCacheManagerProxy::contextDestroyed):
(WebKit::WebApplicationCacheManagerProxy::processDidClose):
(WebKit::WebApplicationCacheManagerProxy::refWebContextSupplement):
(WebKit::WebApplicationCacheManagerProxy::derefWebContextSupplement):
(WebKit::WebApplicationCacheManagerProxy::getApplicationCacheOrigins):
(WebKit::WebApplicationCacheManagerProxy::deleteEntriesForOrigin):
(WebKit::WebApplicationCacheManagerProxy::deleteAllEntries):
* UIProcess/WebApplicationCacheManagerProxy.h:
(WebApplicationCacheManagerProxy):
* UIProcess/WebContext.cpp:
(WebKit::WebContext::WebContext):
(WebKit::WebContext::~WebContext):
(WebKit::WebContext::shouldTerminate):
(WebKit::WebContext::disconnectProcess):
* UIProcess/WebContext.h:
(WebKit::WebContext::supplement):
(WebKit::WebContext::addSupplement):
* UIProcess/WebContextSupplement.h: Added.
(WebKit::WebContextSupplement::WebContextSupplement):
(WebKit::WebContextSupplement::~WebContextSupplement):
(WebKit::WebContextSupplement::ref):
(WebKit::WebContextSupplement::deref):
(WebKit::WebContextSupplement::context):
(WebKit::WebContextSupplement::clearContext):
* WebKit2.xcodeproj/project.pbxproj:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@138599 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 07db8010
2012-12-30 Sam Weinig <sam@webkit.org>
Add supplementability for WebContext
https://bugs.webkit.org/show_bug.cgi?id=105878
Reviewed by Dan Bernstein.
Add WebContextSupplement and convert WebApplicationCacheManagerProxy to it.
* UIProcess/API/C/WKContext.cpp:
(WKContextGetApplicationCacheManager):
* UIProcess/WebApplicationCacheManagerProxy.cpp:
(WebKit::WebApplicationCacheManagerProxy::supplementName):
(WebKit::WebApplicationCacheManagerProxy::WebApplicationCacheManagerProxy):
(WebKit::WebApplicationCacheManagerProxy::contextDestroyed):
(WebKit::WebApplicationCacheManagerProxy::processDidClose):
(WebKit::WebApplicationCacheManagerProxy::refWebContextSupplement):
(WebKit::WebApplicationCacheManagerProxy::derefWebContextSupplement):
(WebKit::WebApplicationCacheManagerProxy::getApplicationCacheOrigins):
(WebKit::WebApplicationCacheManagerProxy::deleteEntriesForOrigin):
(WebKit::WebApplicationCacheManagerProxy::deleteAllEntries):
* UIProcess/WebApplicationCacheManagerProxy.h:
(WebApplicationCacheManagerProxy):
* UIProcess/WebContext.cpp:
(WebKit::WebContext::WebContext):
(WebKit::WebContext::~WebContext):
(WebKit::WebContext::shouldTerminate):
(WebKit::WebContext::disconnectProcess):
* UIProcess/WebContext.h:
(WebKit::WebContext::supplement):
(WebKit::WebContext::addSupplement):
* UIProcess/WebContextSupplement.h: Added.
(WebKit::WebContextSupplement::WebContextSupplement):
(WebKit::WebContextSupplement::~WebContextSupplement):
(WebKit::WebContextSupplement::ref):
(WebKit::WebContextSupplement::deref):
(WebKit::WebContextSupplement::context):
(WebKit::WebContextSupplement::clearContext):
* WebKit2.xcodeproj/project.pbxproj:
2012-12-31 Christophe Dumez <christophe.dumez@intel.com>
[EFL[WK2] Regression(r138574): Should not allocate memory in the fork
......@@ -28,6 +28,7 @@
#include "WKContextPrivate.h"
#include "WKAPICast.h"
#include "WebApplicationCacheManagerProxy.h"
#include "WebContext.h"
#include "WebURLRequest.h"
#include <wtf/PassRefPtr.h>
......@@ -188,7 +189,7 @@ WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef)
WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef contextRef)
{
return toAPI(toImpl(contextRef)->applicationCacheManagerProxy());
return toAPI(toImpl(contextRef)->supplement<WebApplicationCacheManagerProxy>());
}
WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef)
......
......@@ -34,22 +34,34 @@
namespace WebKit {
const AtomicString& WebApplicationCacheManagerProxy::supplementName()
{
DEFINE_STATIC_LOCAL(AtomicString, name, ("WebApplicationCacheManagerProxy", AtomicString::ConstructFromLiteral));
return name;
}
PassRefPtr<WebApplicationCacheManagerProxy> WebApplicationCacheManagerProxy::create(WebContext* context)
{
return adoptRef(new WebApplicationCacheManagerProxy(context));
}
WebApplicationCacheManagerProxy::WebApplicationCacheManagerProxy(WebContext* context)
: m_webContext(context)
: WebContextSupplement(context)
{
m_webContext->addMessageReceiver(Messages::WebApplicationCacheManagerProxy::messageReceiverName(), this);
context->addMessageReceiver(Messages::WebApplicationCacheManagerProxy::messageReceiverName(), this);
}
WebApplicationCacheManagerProxy::~WebApplicationCacheManagerProxy()
{
}
void WebApplicationCacheManagerProxy::invalidate()
void WebApplicationCacheManagerProxy::contextDestroyed()
{
invalidateCallbackMap(m_arrayCallbacks);
}
void WebApplicationCacheManagerProxy::processDidClose(WebProcessProxy*)
{
invalidateCallbackMap(m_arrayCallbacks);
}
......@@ -59,6 +71,16 @@ bool WebApplicationCacheManagerProxy::shouldTerminate(WebProcessProxy*) const
return m_arrayCallbacks.isEmpty();
}
void WebApplicationCacheManagerProxy::refWebContextSupplement()
{
APIObject::ref();
}
void WebApplicationCacheManagerProxy::derefWebContextSupplement()
{
APIObject::deref();
}
void WebApplicationCacheManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
{
didReceiveWebApplicationCacheManagerProxyMessage(connection, messageID, decoder);
......@@ -66,13 +88,16 @@ void WebApplicationCacheManagerProxy::didReceiveMessage(CoreIPC::Connection* con
void WebApplicationCacheManagerProxy::getApplicationCacheOrigins(PassRefPtr<ArrayCallback> prpCallback)
{
if (!context())
return;
RefPtr<ArrayCallback> callback = prpCallback;
uint64_t callbackID = callback->callbackID();
m_arrayCallbacks.set(callbackID, callback.release());
// FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess.
m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::GetApplicationCacheOrigins(callbackID));
context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::GetApplicationCacheOrigins(callbackID));
}
void WebApplicationCacheManagerProxy::didGetApplicationCacheOrigins(const Vector<SecurityOriginData>& originDatas, uint64_t callbackID)
......@@ -83,19 +108,25 @@ void WebApplicationCacheManagerProxy::didGetApplicationCacheOrigins(const Vector
void WebApplicationCacheManagerProxy::deleteEntriesForOrigin(WebSecurityOrigin* origin)
{
if (!context())
return;
SecurityOriginData securityOriginData;
securityOriginData.protocol = origin->protocol();
securityOriginData.host = origin->host();
securityOriginData.port = origin->port();
// FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess.
m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteEntriesForOrigin(securityOriginData));
context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteEntriesForOrigin(securityOriginData));
}
void WebApplicationCacheManagerProxy::deleteAllEntries()
{
if (!context())
return;
// FIXME (Multi-WebProcess): <rdar://problem/12239765> Make manipulating cache information work with per-tab WebProcess.
m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteAllEntries());
context()->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebApplicationCacheManager::DeleteAllEntries());
}
} // namespace WebKit
......@@ -30,6 +30,7 @@
#include "GenericCallback.h"
#include "ImmutableArray.h"
#include "MessageReceiver.h"
#include "WebContextSupplement.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
......@@ -41,28 +42,26 @@ namespace CoreIPC {
namespace WebKit {
struct SecurityOriginData;
class WebContext;
class WebProcessProxy;
class WebSecurityOrigin;
struct SecurityOriginData;
typedef GenericCallback<WKArrayRef> ArrayCallback;
class WebApplicationCacheManagerProxy : public APIObject, private CoreIPC::MessageReceiver {
class WebApplicationCacheManagerProxy : public APIObject, public WebContextSupplement, private CoreIPC::MessageReceiver {
public:
static const Type APIType = TypeApplicationCacheManager;
static const AtomicString& supplementName();
static PassRefPtr<WebApplicationCacheManagerProxy> create(WebContext*);
virtual ~WebApplicationCacheManagerProxy();
void invalidate();
void clearContext() { m_webContext = 0; }
void getApplicationCacheOrigins(PassRefPtr<ArrayCallback>);
void deleteEntriesForOrigin(WebSecurityOrigin*);
void deleteAllEntries();
bool shouldTerminate(WebProcessProxy*) const;
using APIObject::ref;
using APIObject::deref;
private:
explicit WebApplicationCacheManagerProxy(WebContext*);
......@@ -71,11 +70,17 @@ private:
void didGetApplicationCacheOrigins(const Vector<SecurityOriginData>&, uint64_t callbackID);
// WebContextSupplement
virtual void contextDestroyed() OVERRIDE;
virtual void processDidClose(WebProcessProxy*) OVERRIDE;
virtual bool shouldTerminate(WebProcessProxy*) const OVERRIDE;
virtual void refWebContextSupplement() OVERRIDE;
virtual void derefWebContextSupplement() OVERRIDE;
// CoreIPC::MessageReceiver
virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) OVERRIDE;
void didReceiveWebApplicationCacheManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
WebContext* m_webContext;
HashMap<uint64_t, RefPtr<ArrayCallback> > m_arrayCallbacks;
};
......
......@@ -38,6 +38,7 @@
#include "WebApplicationCacheManagerProxy.h"
#include "WebContextMessageKinds.h"
#include "WebContextMessages.h"
#include "WebContextSupplement.h"
#include "WebContextUserMessageCoders.h"
#include "WebCookieManagerProxy.h"
#include "WebCoreArgumentCoders.h"
......@@ -156,7 +157,6 @@ WebContext::WebContext(ProcessModel processModel, const String& injectedBundlePa
addMessageReceiver(CoreIPC::MessageKindTraits<WebContextLegacyMessage::Kind>::messageReceiverName(), this);
// NOTE: These sub-objects must be initialized after m_messageReceiverMap..
m_applicationCacheManagerProxy = WebApplicationCacheManagerProxy::create(this);
#if ENABLE(BATTERY_STATUS)
m_batteryManagerProxy = WebBatteryManagerProxy::create(this);
#endif
......@@ -179,7 +179,9 @@ WebContext::WebContext(ProcessModel processModel, const String& injectedBundlePa
#if USE(SOUP)
m_soupRequestManagerProxy = WebSoupRequestManagerProxy::create(this);
#endif
addSupplement<WebApplicationCacheManagerProxy>();
contexts().append(this);
addLanguageChangeObserver(this, languageChanged);
......@@ -209,8 +211,12 @@ WebContext::~WebContext()
m_messageReceiverMap.invalidate();
m_applicationCacheManagerProxy->invalidate();
m_applicationCacheManagerProxy->clearContext();
WebContextSupplementMap::const_iterator it = m_supplements.begin();
WebContextSupplementMap::const_iterator end = m_supplements.end();
for (; it != end; ++it) {
it->value->contextDestroyed();
it->value->clearContext();
}
#if ENABLE(BATTERY_STATUS)
m_batteryManagerProxy->invalidate();
......@@ -591,8 +597,13 @@ bool WebContext::shouldTerminate(WebProcessProxy* process)
if (!m_processTerminationEnabled)
return false;
if (!m_applicationCacheManagerProxy->shouldTerminate(process))
return false;
WebContextSupplementMap::const_iterator it = m_supplements.begin();
WebContextSupplementMap::const_iterator end = m_supplements.end();
for (; it != end; ++it) {
if (!it->value->shouldTerminate(process))
return false;
}
if (!m_cookieManagerProxy->shouldTerminate(process))
return false;
#if ENABLE(SQL_DATABASE)
......@@ -650,7 +661,11 @@ void WebContext::disconnectProcess(WebProcessProxy* process)
return;
}
m_applicationCacheManagerProxy->invalidate();
WebContextSupplementMap::const_iterator it = m_supplements.begin();
WebContextSupplementMap::const_iterator end = m_supplements.end();
for (; it != end; ++it)
it->value->processDidClose(process);
#if ENABLE(BATTERY_STATUS)
m_batteryManagerProxy->invalidate();
#endif
......
......@@ -44,6 +44,7 @@
#include "WebProcessProxy.h"
#include <WebCore/LinkHash.h>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
......@@ -57,7 +58,7 @@
namespace WebKit {
class DownloadProxy;
class WebApplicationCacheManagerProxy;
class WebContextSupplement;
class WebCookieManagerProxy;
class WebDatabaseManagerProxy;
class WebGeolocationManagerProxy;
......@@ -100,6 +101,18 @@ public:
static const Vector<WebContext*>& allContexts();
template <typename T>
T* supplement()
{
return static_cast<T*>(m_supplements.get(T::supplementName()).get());
}
template <typename T>
void addSupplement()
{
m_supplements.add(T::supplementName(), T::create(this));
}
void addMessageReceiver(CoreIPC::StringReference messageReceiverName, CoreIPC::MessageReceiver*);
void addMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID, CoreIPC::MessageReceiver*);
void removeMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID);
......@@ -200,7 +213,6 @@ public:
static HashSet<String, CaseFoldingHash> pdfAndPostScriptMIMETypes();
WebApplicationCacheManagerProxy* applicationCacheManagerProxy() const { return m_applicationCacheManagerProxy.get(); }
#if ENABLE(BATTERY_STATUS)
WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); }
#endif
......@@ -420,7 +432,6 @@ private:
bool m_memorySamplerEnabled;
double m_memorySamplerInterval;
RefPtr<WebApplicationCacheManagerProxy> m_applicationCacheManagerProxy;
#if ENABLE(BATTERY_STATUS)
RefPtr<WebBatteryManagerProxy> m_batteryManagerProxy;
#endif
......@@ -444,6 +455,9 @@ private:
RefPtr<WebSoupRequestManagerProxy> m_soupRequestManagerProxy;
#endif
typedef HashMap<AtomicString, RefPtr<WebContextSupplement> > WebContextSupplementMap;
WebContextSupplementMap m_supplements;
#if PLATFORM(WIN)
bool m_shouldPaintNativeControls;
#endif
......
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WebContextSupplement_h
#define WebContextSupplement_h
namespace WebKit {
class WebContext;
class WebProcessProxy;
class WebContextSupplement {
public:
WebContextSupplement(WebContext* context)
: m_context(context)
{
}
virtual ~WebContextSupplement()
{
}
void ref() { refWebContextSupplement(); }
void deref() { derefWebContextSupplement(); }
virtual void contextDestroyed() = 0;
virtual void processDidClose(WebProcessProxy*) = 0;
virtual bool shouldTerminate(WebProcessProxy*) const = 0;
WebContext* context() const { return m_context; }
void clearContext() { m_context = 0; }
private:
virtual void refWebContextSupplement() = 0;
virtual void derefWebContextSupplement() = 0;
WebContext* m_context;
};
} // namespace WebKit
#endif // WebContextSupplement_h
......@@ -966,6 +966,7 @@
BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF049E511FE20F600F86A58 /* WKBundlePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCF18638167D071E00A1A85A /* CacheModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCF18637167D071E00A1A85A /* CacheModel.cpp */; };
BCF4DE23168E4BD500C94AFC /* NetworkProcessSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF4DE22168E4BD500C94AFC /* NetworkProcessSupplement.h */; };
BCF4DE25168FA44800C94AFC /* WebContextSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF4DE24168FA44800C94AFC /* WebContextSupplement.h */; };
BCF505E71243047B005955AE /* PlatformCertificateInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF505E51243047B005955AE /* PlatformCertificateInfo.h */; };
BCF505E81243047B005955AE /* PlatformCertificateInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCF505E61243047B005955AE /* PlatformCertificateInfo.mm */; };
BCF50728124329AA005955AE /* WebCertificateInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF50726124329AA005955AE /* WebCertificateInfo.h */; };
......@@ -2242,6 +2243,7 @@
BCF04C8E11FF9F6E00F86A58 /* WebString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebString.h; sourceTree = "<group>"; };
BCF18637167D071E00A1A85A /* CacheModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheModel.cpp; sourceTree = "<group>"; };
BCF4DE22168E4BD500C94AFC /* NetworkProcessSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkProcessSupplement.h; path = Network/NetworkProcessSupplement.h; sourceTree = "<group>"; };
BCF4DE24168FA44800C94AFC /* WebContextSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextSupplement.h; sourceTree = "<group>"; };
BCF505E51243047B005955AE /* PlatformCertificateInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCertificateInfo.h; sourceTree = "<group>"; };
BCF505E61243047B005955AE /* PlatformCertificateInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformCertificateInfo.mm; sourceTree = "<group>"; };
BCF5068412431861005955AE /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
......@@ -3525,6 +3527,7 @@
BC4A62A614744EC6006C681A /* WebConnectionToWebProcess.h */,
BCB9E2421120DACA00A137E0 /* WebContext.cpp */,
BCB9E2411120DACA00A137E0 /* WebContext.h */,
BCF4DE24168FA44800C94AFC /* WebContextSupplement.h */,
BCEE7D0912846AED009827DA /* WebContext.messages.in */,
31A505F71680025500A930EB /* WebContextClient.cpp */,
31A505F81680025500A930EB /* WebContextClient.h */,
......@@ -5028,6 +5031,7 @@
31A505FA1680025500A930EB /* WebContextClient.h in Headers */,
BCE0E425168B7A280057E66A /* WebProcessSupplement.h in Headers */,
BCF4DE23168E4BD500C94AFC /* NetworkProcessSupplement.h in Headers */,
BCF4DE25168FA44800C94AFC /* WebContextSupplement.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment