1 /* 2 * Copyright (C) 2010, 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 "WebPlatformStrategies.h" 28 29 #if USE(PLATFORM_STRATEGIES) 30 31 #include "PluginInfoStore.h" 32 #include "WebContextMessages.h" 33 #include "WebCookieManager.h" 34 #include "WebCoreArgumentCoders.h" 35 #include "WebProcess.h" 36 #include <WebCore/Page.h> 37 38 #if USE(CF) 39 #include <wtf/RetainPtr.h> 40 #endif 41 42 using namespace WebCore; 43 44 namespace WebKit { 45 46 void WebPlatformStrategies::initialize() 47 { 48 DEFINE_STATIC_LOCAL(WebPlatformStrategies, platformStrategies, ()); 49 setPlatformStrategies(&platformStrategies); 50 } 51 52 WebPlatformStrategies::WebPlatformStrategies() 53 : m_pluginCacheIsPopulated(false) 54 , m_shouldRefreshPlugins(false) 55 { 56 } 57 58 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy() 59 { 60 return this; 61 } 62 63 PluginStrategy* WebPlatformStrategies::createPluginStrategy() 64 { 65 return this; 66 } 67 68 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy() 69 { 70 return this; 71 } 72 73 // CookiesStrategy 74 75 void WebPlatformStrategies::notifyCookiesChanged() 76 { 77 WebCookieManager::shared().dispatchCookiesDidChange(); 78 } 79 80 // PluginStrategy 81 82 void WebPlatformStrategies::refreshPlugins() 83 { 84 m_cachedPlugins.clear(); 85 m_pluginCacheIsPopulated = false; 86 m_shouldRefreshPlugins = true; 87 88 populatePluginCache(); 89 } 90 91 void WebPlatformStrategies::getPluginInfo(const WebCore::Page*, Vector<WebCore::PluginInfo>& plugins) 92 { 93 populatePluginCache(); 94 plugins = m_cachedPlugins; 95 } 96 97 void WebPlatformStrategies::populatePluginCache() 98 { 99 if (m_pluginCacheIsPopulated) 100 return; 101 102 ASSERT(m_cachedPlugins.isEmpty()); 103 104 Vector<PluginInfo> plugins; 105 106 // FIXME: Should we do something in case of error here? 107 WebProcess::shared().connection()->sendSync(Messages::WebContext::GetPlugins(m_shouldRefreshPlugins), 108 Messages::WebContext::GetPlugins::Reply(plugins), 0); 109 110 m_cachedPlugins.swap(plugins); 111 112 m_shouldRefreshPlugins = false; 113 m_pluginCacheIsPopulated = true; 114 } 115 116 // VisitedLinkStrategy 117 118 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash linkHash) 119 { 120 return WebProcess::shared().isLinkVisited(linkHash); 121 } 122 123 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash linkHash) 124 { 125 WebProcess::shared().addVisitedLink(linkHash); 126 } 127 128 } // namespace WebKit 129 130 #endif // USE(PLATFORM_STRATEGIES) 131