1 /* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #include "config.h" 27 #include "WebCookieManagerProxy.h" 28 29 #include "SecurityOriginData.h" 30 #include "WebCookieManagerMessages.h" 31 #include "WebContext.h" 32 #include "WebSecurityOrigin.h" 33 34 namespace WebKit { 35 36 PassRefPtr<WebCookieManagerProxy> WebCookieManagerProxy::create(WebContext* context) 37 { 38 return adoptRef(new WebCookieManagerProxy(context)); 39 } 40 41 WebCookieManagerProxy::WebCookieManagerProxy(WebContext* context) 42 : m_webContext(context) 43 { 44 } 45 46 WebCookieManagerProxy::~WebCookieManagerProxy() 47 { 48 } 49 50 void WebCookieManagerProxy::invalidate() 51 { 52 invalidateCallbackMap(m_arrayCallbacks); 53 invalidateCallbackMap(m_httpCookieAcceptPolicyCallbacks); 54 } 55 56 bool WebCookieManagerProxy::shouldTerminate(WebProcessProxy*) const 57 { 58 return m_arrayCallbacks.isEmpty() && m_httpCookieAcceptPolicyCallbacks.isEmpty(); 59 } 60 61 void WebCookieManagerProxy::initializeClient(const WKCookieManagerClient* client) 62 { 63 m_client.initialize(client); 64 } 65 66 void WebCookieManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) 67 { 68 didReceiveWebCookieManagerProxyMessage(connection, messageID, arguments); 69 } 70 71 void WebCookieManagerProxy::getHostnamesWithCookies(PassRefPtr<ArrayCallback> prpCallback) 72 { 73 ASSERT(m_webContext); 74 75 RefPtr<ArrayCallback> callback = prpCallback; 76 uint64_t callbackID = callback->callbackID(); 77 m_arrayCallbacks.set(callbackID, callback.release()); 78 79 // FIXME (Multi-WebProcess): Cookies shouldn't be stored in the web process. 80 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::GetHostnamesWithCookies(callbackID)); 81 } 82 83 void WebCookieManagerProxy::didGetHostnamesWithCookies(const Vector<String>& hostnameList, uint64_t callbackID) 84 { 85 RefPtr<ArrayCallback> callback = m_arrayCallbacks.take(callbackID); 86 if (!callback) { 87 // FIXME: Log error or assert. 88 return; 89 } 90 91 size_t hostnameCount = hostnameList.size(); 92 Vector<RefPtr<APIObject> > hostnames(hostnameCount); 93 94 for (size_t i = 0; i < hostnameCount; ++i) 95 hostnames[i] = WebString::create(hostnameList[i]); 96 97 callback->performCallbackWithReturnValue(ImmutableArray::adopt(hostnames).get()); 98 } 99 100 void WebCookieManagerProxy::deleteCookiesForHostname(const String& hostname) 101 { 102 ASSERT(m_webContext); 103 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::DeleteCookiesForHostname(hostname)); 104 } 105 106 void WebCookieManagerProxy::deleteAllCookies() 107 { 108 ASSERT(m_webContext); 109 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::DeleteAllCookies()); 110 } 111 112 void WebCookieManagerProxy::startObservingCookieChanges() 113 { 114 ASSERT(m_webContext); 115 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges()); 116 } 117 118 void WebCookieManagerProxy::stopObservingCookieChanges() 119 { 120 ASSERT(m_webContext); 121 m_webContext->sendToAllProcesses(Messages::WebCookieManager::StopObservingCookieChanges()); 122 } 123 124 void WebCookieManagerProxy::cookiesDidChange() 125 { 126 m_client.cookiesDidChange(this); 127 } 128 129 void WebCookieManagerProxy::setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) 130 { 131 ASSERT(m_webContext); 132 #if PLATFORM(MAC) 133 persistHTTPCookieAcceptPolicy(policy); 134 #endif 135 136 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::SetHTTPCookieAcceptPolicy(policy)); 137 } 138 139 void WebCookieManagerProxy::getHTTPCookieAcceptPolicy(PassRefPtr<HTTPCookieAcceptPolicyCallback> prpCallback) 140 { 141 ASSERT(m_webContext); 142 143 RefPtr<HTTPCookieAcceptPolicyCallback> callback = prpCallback; 144 145 uint64_t callbackID = callback->callbackID(); 146 m_httpCookieAcceptPolicyCallbacks.set(callbackID, callback.release()); 147 148 // FIXME (Multi-WebProcess): Cookies shouldn't be stored in the web process. 149 m_webContext->sendToAllProcessesRelaunchingThemIfNecessary(Messages::WebCookieManager::GetHTTPCookieAcceptPolicy(callbackID)); 150 } 151 152 void WebCookieManagerProxy::didGetHTTPCookieAcceptPolicy(uint32_t policy, uint64_t callbackID) 153 { 154 RefPtr<HTTPCookieAcceptPolicyCallback> callback = m_httpCookieAcceptPolicyCallbacks.take(callbackID); 155 if (!callback) { 156 // FIXME: Log error or assert. 157 return; 158 } 159 160 callback->performCallbackWithReturnValue(policy); 161 } 162 163 } // namespace WebKit 164