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 "WebIconDatabaseProxy.h" 28 29#include "DataReference.h" 30#include "WebIconDatabaseMessages.h" 31#include "WebIconDatabaseProxyMessages.h" 32#include "WebProcess.h" 33#include <WebCore/SharedBuffer.h> 34#include <wtf/text/WTFString.h> 35 36using namespace WebCore; 37 38namespace WebKit { 39 40WebIconDatabaseProxy::~WebIconDatabaseProxy() 41{ 42} 43 44WebIconDatabaseProxy::WebIconDatabaseProxy(WebProcess* process) 45 : m_isEnabled(false) 46 , m_process(process) 47{ 48 m_process->addMessageReceiver(Messages::WebIconDatabaseProxy::messageReceiverName(), this); 49} 50 51bool WebIconDatabaseProxy::isEnabled() const 52{ 53 return m_isEnabled; 54} 55 56void WebIconDatabaseProxy::setEnabled(bool enabled) 57{ 58 if (enabled == m_isEnabled) 59 return; 60 61 m_isEnabled = enabled; 62 setGlobalIconDatabase(enabled ? this : 0); 63} 64 65void WebIconDatabaseProxy::retainIconForPageURL(const String& pageURL) 66{ 67 m_process->parentProcessConnection()->send(Messages::WebIconDatabase::RetainIconForPageURL(pageURL), 0); 68} 69 70void WebIconDatabaseProxy::releaseIconForPageURL(const String& pageURL) 71{ 72 m_process->parentProcessConnection()->send(Messages::WebIconDatabase::ReleaseIconForPageURL(pageURL), 0); 73} 74 75Image* WebIconDatabaseProxy::synchronousIconForPageURL(const String& pageURL, const IntSize& /*size*/) 76{ 77 CoreIPC::DataReference result; 78 if (!m_process->parentProcessConnection()->sendSync(Messages::WebIconDatabase::SynchronousIconDataForPageURL(pageURL), Messages::WebIconDatabase::SynchronousIconDataForPageURL::Reply(result), 0)) 79 return 0; 80 81 // FIXME: Return Image created with the above data. 82 return 0; 83} 84 85 86String WebIconDatabaseProxy::synchronousIconURLForPageURL(const String& /*pageURL*/) 87{ 88 // FIXME: This needs to ask the UI process for the iconURL, but it can't do so synchronously because it will slow down page loading. 89 // The parts in WebCore that need this data will have to be changed to work asycnchronously. 90 return String(); 91} 92 93bool WebIconDatabaseProxy::synchronousIconDataKnownForIconURL(const String& /*iconURL*/) 94{ 95 // FIXME: This needs to ask the UI process for the iconURL, but it can't do so synchronously because it will slow down page loading. 96 // The parts in WebCore that need this data will have to be changed to work asycnchronously. 97 return false; 98} 99 100IconLoadDecision WebIconDatabaseProxy::synchronousLoadDecisionForIconURL(const String& /*iconURL*/, DocumentLoader*) 101{ 102 // FIXME: This needs to ask the UI process for the iconURL, but it can't do so synchronously because it will slow down page loading. 103 // The parts in WebCore that need this data will have to be changed to work asycnchronously. 104 return IconLoadNo; 105} 106 107bool WebIconDatabaseProxy::supportsAsynchronousMode() 108{ 109 return true; 110} 111 112void WebIconDatabaseProxy::loadDecisionForIconURL(const String& iconURL, PassRefPtr<WebCore::IconLoadDecisionCallback> callback) 113{ 114 uint64_t id = callback->callbackID(); 115 m_iconLoadDecisionCallbacks.add(id, callback); 116 117 m_process->parentProcessConnection()->send(Messages::WebIconDatabase::GetLoadDecisionForIconURL(iconURL, id), 0); 118} 119 120void WebIconDatabaseProxy::receivedIconLoadDecision(int decision, uint64_t callbackID) 121{ 122 RefPtr<WebCore::IconLoadDecisionCallback> callback = m_iconLoadDecisionCallbacks.take(callbackID); 123 if (callback) 124 callback->performCallback(static_cast<WebCore::IconLoadDecision>(decision)); 125} 126 127void WebIconDatabaseProxy::iconDataForIconURL(const String& /*iconURL*/, PassRefPtr<WebCore::IconDataCallback>) 128{ 129} 130 131void WebIconDatabaseProxy::setIconURLForPageURL(const String& iconURL, const String& pageURL) 132{ 133 m_process->parentProcessConnection()->send(Messages::WebIconDatabase::SetIconURLForPageURL(iconURL, pageURL), 0); 134} 135 136void WebIconDatabaseProxy::setIconDataForIconURL(PassRefPtr<SharedBuffer> iconData, const String& iconURL) 137{ 138 CoreIPC::DataReference data(reinterpret_cast<const uint8_t*>(iconData ? iconData->data() : 0), iconData ? iconData->size() : 0); 139 m_process->parentProcessConnection()->send(Messages::WebIconDatabase::SetIconDataForIconURL(data, iconURL), 0); 140} 141 142void WebIconDatabaseProxy::urlImportFinished() 143{ 144} 145 146} // namespace WebKit 147