2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebCookieManagerProxy.h"
29 #include "SecurityOriginData.h"
30 #include "WebCookieManagerMessages.h"
31 #include "WebContext.h"
32 #include "WebSecurityOrigin.h"
36 PassRefPtr<WebCookieManagerProxy> WebCookieManagerProxy::create(WebContext* context)
38 return adoptRef(new WebCookieManagerProxy(context));
41 WebCookieManagerProxy::WebCookieManagerProxy(WebContext* context)
42 : m_webContext(context)
46 WebCookieManagerProxy::~WebCookieManagerProxy()
50 void WebCookieManagerProxy::invalidate()
52 invalidateCallbackMap(m_arrayCallbacks);
53 invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks);
56 bool WebCookieManagerProxy::shouldTerminate(WebProcessProxy*) const
58 return m_arrayCallbacks.isEmpty() && m_httpCookieAcceptPolicyCallbacks.isEmpty();
61 void WebCookieManagerProxy::initializeClient(const WKCookieManagerClient* client)
63 m_client.initialize(client);
66 void WebCookieManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
68 didReceiveWebCookieManagerProxyMessage(connection, messageID, arguments);
71 void WebCookieManagerProxy::getHostnamesWithCookies(PassRefPtr<ArrayCallback> prpCallback)
75 RefPtr<ArrayCallback> callback = prpCallback;
76 uint64_t callbackID = callback->callbackID();
77 m_arrayCallbacks.set(callbackID, callback.release());
79 // FIXME (Multi-WebProcess): Cookies shouldn't be stored in the web process.
80 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(callbackID));
83 void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hostnameList, uint64_t callbackID)
85 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID);
87 // FIXME: Log error or assert.
91 size_t hostnameCount = hostnameList.size();
92 Vector<RefPtr<APIObject> > hostnames(hostnameCount);
94 for (size_t i = 0; i < hostnameCount; ++i)
95 hostnames[i] = WebString::create(hostnameList[i]);
97 callback->performCallbackWithReturnValue(ImmutableArray::adopt(hostnames).get());
100 void WebCookieManagerProxy::deleteCookiesForHostname(const String& hostname)
102 ASSERT(m_webContext);
103 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(hostname));
106 void WebCookieManagerProxy::deleteAllCookies()
108 ASSERT(m_webContext);
109 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::DeleteAllCookies());
112 void WebCookieManagerProxy::startObservingCookieChanges()
114 ASSERT(m_webContext);
115 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges());
118 void WebCookieManagerProxy::stopObservingCookieChanges()
120 ASSERT(m_webContext);
121 m_webContext->sendToAllProcesses(Messages::WebCookieManager::StopObservingCookieChanges());
124 void WebCookieManagerProxy::cookiesDidChange()
126 m_client.cookiesDidChange(this);
129 void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
131 ASSERT(m_webContext);
133 persistHTTPCookieAcceptPolicy(policy);
136 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy));
139 void WebCookieManagerProxy::getHTTPCookieAcceptPolicy(PassRefPtr<HTTPCookieAcceptPolicyCallback> prpCallback)
141 ASSERT(m_webContext);
143 RefPtr<HTTPCookieAcceptPolicyCallback> callback = prpCallback;
145 uint64_t callbackID = callback->callbackID();
146 m_httpCookieAcceptPolicyCallbacks.set(callbackID, callback.release());
148 // FIXME (Multi-WebProcess): Cookies shouldn't be stored in the web process.
149 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(callbackID));
152 void WebCookieManagerProxy::didGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID)
154 RefPtr<HTTPCookieAcceptPolicyCallback> callback = m_httpCookieAcceptPolicyCallbacks.take(callbackID);
156 // FIXME: Log error or assert.
160 callback->performCallbackWithReturnValue(policy);
163 } // namespace WebKit