1 /* 2 * Copyright (C) 2010 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 "InjectedBundle.h" 28 29 #include "WKBundleAPICast.h" 30 #include "WKBundleInitialize.h" 31 #include <wtf/RetainPtr.h> 32 #include <wtf/text/CString.h> 33 #include <wtf/text/WTFString.h> 34 35 using namespace WebCore; 36 37 namespace WebKit { 38 39 bool InjectedBundle::load(APIObject* initializationUserData) 40 { 41 if (m_sandboxExtension) { 42 if (!m_sandboxExtension->consume()) { 43 fprintf(stderr, "InjectedBundle::load failed - Could not consume bundle sandbox extension for [%s].\n", m_path.utf8().data()); 44 return false; 45 } 46 47 m_sandboxExtension = 0; 48 } 49 50 RetainPtr<CFStringRef> injectedBundlePathStr(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(m_path.characters()), m_path.length())); 51 if (!injectedBundlePathStr) { 52 fprintf(stderr, "InjectedBundle::load failed - Could not create the path string.\n"); 53 return false; 54 } 55 56 RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false)); 57 if (!bundleURL) { 58 fprintf(stderr, "InjectedBundle::load failed - Could not create the url from the path string.\n"); 59 return false; 60 } 61 62 m_platformBundle = CFBundleCreate(0, bundleURL.get()); 63 if (!m_platformBundle) { 64 fprintf(stderr, "InjectedBundle::load failed - Could not create the bundle.\n"); 65 return false; 66 } 67 68 if (!CFBundleLoadExecutable(m_platformBundle)) { 69 fprintf(stderr, "InjectedBundle::load failed - Could not load the executable from the bundle.\n"); 70 return false; 71 } 72 73 WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize"))); 74 if (!initializeFunction) { 75 fprintf(stderr, "InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n"); 76 return false; 77 } 78 79 initializeFunction(toAPI(this), toAPI(initializationUserData)); 80 return true; 81 } 82 83 void InjectedBundle::activateMacFontAscentHack() 84 { 85 } 86 87 } // namespace WebKit 88