1/* 2 * Copyright (C) 2013 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#import "config.h" 27#import "WKContextPrivateMac.h" 28 29#import "APIArray.h" 30#import "APINumber.h" 31#import "APIString.h" 32#import "ImmutableDictionary.h" 33#import "PluginInfoStore.h" 34#import "PluginInformation.h" 35#import "StringUtilities.h" 36#import "WKAPICast.h" 37#import "WKPluginInformation.h" 38#import "WKSharedAPICast.h" 39#import "WKStringCF.h" 40#import "WebContext.h" 41#import <WebKitSystemInterface.h> 42#import <wtf/RetainPtr.h> 43 44using namespace WebKit; 45 46bool WKContextIsPlugInUpdateAvailable(WKContextRef contextRef, WKStringRef plugInBundleIdentifierRef) 47{ 48#if PLATFORM(IOS) 49 return false; 50#else 51 return WKIsPluginUpdateAvailable((NSString *)adoptCF(WKStringCopyCFString(kCFAllocatorDefault, plugInBundleIdentifierRef)).get()); 52#endif 53} 54 55WKDictionaryRef WKContextCopyPlugInInfoForBundleIdentifier(WKContextRef contextRef, WKStringRef plugInBundleIdentifierRef) 56{ 57#if ENABLE(NETSCAPE_PLUGIN_API) 58 PluginModuleInfo plugin = toImpl(contextRef)->pluginInfoStore().findPluginWithBundleIdentifier(toWTFString(plugInBundleIdentifierRef)); 59 if (plugin.path.isNull()) 60 return 0; 61 62 RefPtr<ImmutableDictionary> dictionary = createPluginInformationDictionary(plugin); 63 return toAPI(dictionary.release().leakRef()); 64#else 65 return 0; 66#endif 67} 68 69void WKContextGetInfoForInstalledPlugIns(WKContextRef contextRef, WKContextGetInfoForInstalledPlugInsBlock block) 70{ 71#if ENABLE(NETSCAPE_PLUGIN_API) 72 Vector<PluginModuleInfo> plugins = toImpl(contextRef)->pluginInfoStore().plugins(); 73 74 Vector<RefPtr<API::Object>> pluginInfoDictionaries; 75 pluginInfoDictionaries.reserveInitialCapacity(plugins.size()); 76 77 for (const auto& plugin: plugins) 78 pluginInfoDictionaries.uncheckedAppend(createPluginInformationDictionary(plugin)); 79 80 RefPtr<API::Array> array = API::Array::create(WTF::move(pluginInfoDictionaries)); 81 82 toImpl(contextRef)->ref(); 83 dispatch_async(dispatch_get_main_queue(), ^() { 84 block(toAPI(array.get()), 0); 85 86 toImpl(contextRef)->deref(); 87 }); 88#endif 89} 90 91void WKContextResetHSTSHosts(WKContextRef context) 92{ 93 return toImpl(context)->resetHSTSHosts(); 94} 95 96 97 98void WKContextRegisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme) 99{ 100 WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme)); 101} 102 103void WKContextUnregisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme) 104{ 105 WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme)); 106} 107 108/* DEPRECATED - Please use constants from WKPluginInformation instead. */ 109 110WKStringRef WKPlugInInfoPathKey() 111{ 112 return WKPluginInformationPathKey(); 113} 114 115WKStringRef WKPlugInInfoBundleIdentifierKey() 116{ 117 return WKPluginInformationBundleIdentifierKey(); 118} 119 120WKStringRef WKPlugInInfoVersionKey() 121{ 122 return WKPluginInformationBundleVersionKey(); 123} 124 125WKStringRef WKPlugInInfoLoadPolicyKey() 126{ 127 return WKPluginInformationDefaultLoadPolicyKey(); 128} 129 130WKStringRef WKPlugInInfoUpdatePastLastBlockedVersionIsKnownAvailableKey() 131{ 132 return WKPluginInformationUpdatePastLastBlockedVersionIsKnownAvailableKey(); 133} 134 135WKStringRef WKPlugInInfoIsSandboxedKey() 136{ 137 return WKPluginInformationHasSandboxProfileKey(); 138} 139 140bool WKContextShouldBlockWebGL() 141{ 142 return WKShouldBlockWebGL(); 143} 144 145bool WKContextShouldSuggestBlockWebGL() 146{ 147 return WKShouldSuggestBlockingWebGL(); 148} 149