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