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 "MessageID.h" 31 #include "WebIconDatabaseMessages.h" 32 #include "WebProcess.h" 33 #include <WebCore/SharedBuffer.h> 34 #include <wtf/text/WTFString.h> 35 36 using namespace WebCore; 37 38 namespace WebKit { 39 40 WebIconDatabaseProxy::~WebIconDatabaseProxy() 41 { 42 } 43 44 WebIconDatabaseProxy::WebIconDatabaseProxy(WebProcess* process) 45 : m_isEnabled(false) 46 , m_process(process) 47 { 48 } 49 50 bool WebIconDatabaseProxy::isEnabled() const 51 { 52 return m_isEnabled; 53 } 54 55 void WebIconDatabaseProxy::setEnabled(bool enabled) 56 { 57 if (enabled == m_isEnabled) 58 return; 59 60 m_isEnabled = enabled; 61 setGlobalIconDatabase(enabled ? this : 0); 62 } 63 64 65 void WebIconDatabaseProxy::retainIconForPageURL(const String& pageURL) 66 { 67 m_process->connection()->send(Messages::WebIconDatabase::RetainIconForPageURL(pageURL), 0); 68 } 69 70 void WebIconDatabaseProxy::releaseIconForPageURL(const String& pageURL) 71 { 72 m_process->connection()->send(Messages::WebIconDatabase::ReleaseIconForPageURL(pageURL), 0); 73 } 74 75 Image* WebIconDatabaseProxy::synchronousIconForPageURL(const String& pageURL, const IntSize& size) 76 { 77 CoreIPC::DataReference result; 78 if (!m_process->connection()->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 86 String 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 93 bool 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 100 IconLoadDecision WebIconDatabaseProxy::synchronousLoadDecisionForIconURL(const String& iconURL, DocumentLoader* 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 107 bool WebIconDatabaseProxy::supportsAsynchronousMode() 108 { 109 return true; 110 } 111 112 void 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->connection()->send(Messages::WebIconDatabase::GetLoadDecisionForIconURL(iconURL, id), 0); 118 } 119 120 void 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 127 void WebIconDatabaseProxy::iconDataForIconURL(const String& iconURL, PassRefPtr<WebCore::IconDataCallback> callback) 128 { 129 } 130 131 void WebIconDatabaseProxy::setIconURLForPageURL(const String& iconURL, const String& pageURL) 132 { 133 m_process->connection()->send(Messages::WebIconDatabase::SetIconURLForPageURL(iconURL, pageURL), 0); 134 } 135 136 void 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->connection()->send(Messages::WebIconDatabase::SetIconDataForIconURL(data, iconURL), 0); 140 } 141 142 void WebIconDatabaseProxy::urlImportFinished() 143 { 144 } 145 146 void WebIconDatabaseProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) 147 { 148 didReceiveWebIconDatabaseProxyMessage(connection, messageID, arguments); 149 } 150 151 } // namespace WebKit 152