Add Objective-C API for the InjectedBundle
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 04:12:20 +0000 (04:12 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 04:12:20 +0000 (04:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98222

Reviewed by Anders Carlsson.

Add skeleton of the Objective-C API for the InjectedBundle.

* WebKit2.xcodeproj/project.pbxproj:
Add new API files.

* WebProcess/InjectedBundle/API/mac: Added.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h: Added.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm: Added.
(-[WKWebProcessPlugIn _initWithPrincipalClassInstance:injectedBundle:]):
Initialization method for the WKWebProcessPlugIn object. This object will act as the WKBundleRef
object does in the C-SPI.
(+[WKWebProcessPlugIn _shared]):
Access the shared instance.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h: Added.

* WebProcess/InjectedBundle/InjectedBundle.h:
Store an NSBundle rather than a CFBundleRef as the platform bundle.

* WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp: Removed.
* WebProcess/InjectedBundle/mac/InjectedBundleMac.mm: Copied from Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp.
(WebKit::InjectedBundle::load):
If a principal class is provided and no WKBundleInitialize function is present in the bundle, use the principal class
as the initialization point. The principal class must conform to the WKWebProcessPlugIn protocol and if a
webProcessPlugInInitialize: method is present, it is called.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130245 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h
Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm [moved from Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp with 59% similarity]

index de611e2..fd5f82a 100644 (file)
@@ -1,3 +1,35 @@
+2012-10-02  Sam Weinig  <sam@webkit.org>
+
+        Add Objective-C API for the InjectedBundle
+        https://bugs.webkit.org/show_bug.cgi?id=98222
+
+        Reviewed by Anders Carlsson.
+
+        Add skeleton of the Objective-C API for the InjectedBundle.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add new API files.
+
+        * WebProcess/InjectedBundle/API/mac: Added.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h: Added.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm: Added.
+        (-[WKWebProcessPlugIn _initWithPrincipalClassInstance:injectedBundle:]):
+        Initialization method for the WKWebProcessPlugIn object. This object will act as the WKBundleRef
+        object does in the C-SPI.
+        (+[WKWebProcessPlugIn _shared]):
+        Access the shared instance.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h: Added.
+
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+        Store an NSBundle rather than a CFBundleRef as the platform bundle.
+
+        * WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp: Removed.
+        * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm: Copied from Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp.
+        (WebKit::InjectedBundle::load):
+        If a principal class is provided and no WKBundleInitialize function is present in the bundle, use the principal class
+        as the initialization point. The principal class must conform to the WKWebProcessPlugIn protocol and if a
+        webProcessPlugInInitialize: method is present, it is called. 
+
 2012-10-02  Dan Bernstein  <mitz@apple.com>
 
         Fixed a crash when the localization option is not passed to the web process.
index d329b30..77cfa34 100644 (file)
                BC1DFEA412B31F87005DF730 /* WebOpenPanelResultListenerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = BC1DFEA212B31F87005DF730 /* WebOpenPanelResultListenerProxy.h */; };
                BC204EE211C83E98008F3375 /* InjectedBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC204EE011C83E98008F3375 /* InjectedBundle.cpp */; };
                BC204EE311C83E98008F3375 /* InjectedBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = BC204EE111C83E98008F3375 /* InjectedBundle.h */; };
-               BC204EE611C83EA9008F3375 /* InjectedBundleMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC204EE511C83EA9008F3375 /* InjectedBundleMac.cpp */; };
+               BC204EE611C83EA9008F3375 /* InjectedBundleMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC204EE511C83EA9008F3375 /* InjectedBundleMac.mm */; };
                BC204EEE11C83EC8008F3375 /* WKBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC204EE911C83EC8008F3375 /* WKBundle.cpp */; };
                BC204EEF11C83EC8008F3375 /* WKBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = BC204EEA11C83EC8008F3375 /* WKBundle.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC204EF011C83EC8008F3375 /* WKBundleAPICast.h in Headers */ = {isa = PBXBuildFile; fileRef = BC204EEB11C83EC8008F3375 /* WKBundleAPICast.h */; };
                BC9585C812F095B800755821 /* WebGestureEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC9585C712F095B800755821 /* WebGestureEvent.cpp */; };
                BC963D6B113DD19200574BE2 /* WebPage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC963D6A113DD19200574BE2 /* WebPage.cpp */; };
                BC963D6E113DD1A500574BE2 /* WebPageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC963D6D113DD1A500574BE2 /* WebPageMac.mm */; };
+               BC989D81161A7E5D000D46D3 /* WKWebProcessPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC989D7F161A7E5B000D46D3 /* WKWebProcessPlugIn.mm */; };
+               BC989D82161A7E5D000D46D3 /* WKWebProcessPlugIn.h in Headers */ = {isa = PBXBuildFile; fileRef = BC989D80161A7E5C000D46D3 /* WKWebProcessPlugIn.h */; settings = {ATTRIBUTES = (Public, ); }; };
+               BC989D85161A9890000D46D3 /* WKWebProcessPlugInInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = BC989D84161A988F000D46D3 /* WKWebProcessPlugInInternal.h */; };
                BC9B38A110F538BE00443A15 /* WebFrameProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9B389F10F538BE00443A15 /* WebFrameProxy.h */; };
                BC9FA520160D3B430054DF9A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC3DE46815A91763008D26FC /* Foundation.framework */; };
                BC9FA522160D4A0C0054DF9A /* com.apple.WebKit.PluginProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E35150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb */; };
                BC1DFEA312B31F87005DF730 /* WebOpenPanelResultListenerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebOpenPanelResultListenerProxy.cpp; sourceTree = "<group>"; };
                BC204EE011C83E98008F3375 /* InjectedBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundle.cpp; sourceTree = "<group>"; };
                BC204EE111C83E98008F3375 /* InjectedBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundle.h; sourceTree = "<group>"; };
-               BC204EE511C83EA9008F3375 /* InjectedBundleMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMac.cpp; sourceTree = "<group>"; };
+               BC204EE511C83EA9008F3375 /* InjectedBundleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleMac.mm; sourceTree = "<group>"; };
                BC204EE911C83EC8008F3375 /* WKBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundle.cpp; sourceTree = "<group>"; };
                BC204EEA11C83EC8008F3375 /* WKBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundle.h; sourceTree = "<group>"; };
                BC204EEB11C83EC8008F3375 /* WKBundleAPICast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundleAPICast.h; sourceTree = "<group>"; };
                BC9585C712F095B800755821 /* WebGestureEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGestureEvent.cpp; sourceTree = "<group>"; };
                BC963D6A113DD19200574BE2 /* WebPage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPage.cpp; sourceTree = "<group>"; };
                BC963D6D113DD1A500574BE2 /* WebPageMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPageMac.mm; sourceTree = "<group>"; };
+               BC989D7F161A7E5B000D46D3 /* WKWebProcessPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebProcessPlugIn.mm; sourceTree = "<group>"; };
+               BC989D80161A7E5C000D46D3 /* WKWebProcessPlugIn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugIn.h; sourceTree = "<group>"; };
+               BC989D84161A988F000D46D3 /* WKWebProcessPlugInInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInInternal.h; sourceTree = "<group>"; };
                BC9B389F10F538BE00443A15 /* WebFrameProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFrameProxy.h; sourceTree = "<group>"; };
                BCA0EF7D12331E78007D3CFB /* WebUndoStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUndoStep.h; sourceTree = "<group>"; };
                BCA0EF7E12331E78007D3CFB /* WebUndoStep.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebUndoStep.cpp; sourceTree = "<group>"; };
                BC204EE411C83E9C008F3375 /* mac */ = {
                        isa = PBXGroup;
                        children = (
-                               BC204EE511C83EA9008F3375 /* InjectedBundleMac.cpp */,
+                               BC204EE511C83EA9008F3375 /* InjectedBundleMac.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                        isa = PBXGroup;
                        children = (
                                BC204EE811C83EB7008F3375 /* c */,
+                               BC989D4516181691000D46D3 /* mac */,
                        );
                        path = API;
                        sourceTree = "<group>";
                        path = mac;
                        sourceTree = "<group>";
                };
+               BC989D4516181691000D46D3 /* mac */ = {
+                       isa = PBXGroup;
+                       children = (
+                               BC989D7F161A7E5B000D46D3 /* WKWebProcessPlugIn.mm */,
+                               BC989D80161A7E5C000D46D3 /* WKWebProcessPlugIn.h */,
+                               BC989D84161A988F000D46D3 /* WKWebProcessPlugInInternal.h */,
+                       );
+                       path = mac;
+                       sourceTree = "<group>";
+               };
                BCAE9DED160C097400A33217 /* WebProcessServiceForWebKitDevelopment */ = {
                        isa = PBXGroup;
                        children = (
                                BC59548915C7868500FD1E3E /* WebKit2.h in Headers */,
                                BCDC308815FD6A8B006B6695 /* WebProcessInitialization.h in Headers */,
                                BCDC308C15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h in Headers */,
+                               BC989D82161A7E5D000D46D3 /* WKWebProcessPlugIn.h in Headers */,
+                               BC989D85161A9890000D46D3 /* WKWebProcessPlugInInternal.h in Headers */,
                                1A3EED0F161A535400AEB4F5 /* MessageReceiverMap.h in Headers */,
                                1A3EED12161A53D600AEB4F5 /* MessageReceiver.h in Headers */,
                        );
                                935EEBA3127761D3003322B8 /* InjectedBundleBackForwardListItem.cpp in Sources */,
                                BCEE7DC6128B645D009827DA /* InjectedBundleClient.cpp in Sources */,
                                BC498619124D10E200D834E1 /* InjectedBundleHitTestResult.cpp in Sources */,
-                               BC204EE611C83EA9008F3375 /* InjectedBundleMac.cpp in Sources */,
+                               BC204EE611C83EA9008F3375 /* InjectedBundleMac.mm in Sources */,
                                BC8147D612F66D31007B2C32 /* InjectedBundleNavigationAction.cpp in Sources */,
                                BC4BEEAC120A0A5F00FBA0C7 /* InjectedBundleNodeHandle.cpp in Sources */,
                                512935E31288D97800A4B695 /* InjectedBundlePageContextMenuClient.cpp in Sources */,
                                CD67D30E15C08F9A00843ADF /* InjectedBundlePageDiagnosticLoggingClient.cpp in Sources */,
                                BCDC308715FD6A8B006B6695 /* WebProcessInitialization.mm in Sources */,
                                BCDC308B15FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm in Sources */,
+                               BC989D81161A7E5D000D46D3 /* WKWebProcessPlugIn.mm in Sources */,
                                1A3EED0E161A535400AEB4F5 /* MessageReceiverMap.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.h
new file mode 100644 (file)
index 0000000..02982f9
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <WebKit2/WKBase.h>
+
+@class WKWebProcessPlugInController;
+
+@protocol WKWebProcessPlugIn <NSObject>
+@optional
+- (void)webProcessPlugInInitialize:(WKWebProcessPlugInController *)plugInController;
+@end
+
+WK_EXPORT
+@interface WKWebProcessPlugInController : NSObject {
+@private
+    void *_private;
+}
+
+@end
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugIn.mm
new file mode 100644 (file)
index 0000000..591ab26
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKWebProcessPlugIn.h"
+
+#import "InjectedBundle.h"
+#import "WKWebProcessPlugInInternal.h"
+#import <wtf/RetainPtr.h>
+
+struct WKWebProcessPlugInControllerData {
+    RetainPtr<id<WKWebProcessPlugIn> > _principalClassInstance;
+    RefPtr<WebKit::InjectedBundle> _injectedBundle;
+};
+
+@implementation WKWebProcessPlugInController (Internal)
+
+static WKWebProcessPlugInController *sharedInstance;
+
++ (WKWebProcessPlugInController *)_shared
+{
+    ASSERT_WITH_MESSAGE(sharedInstance, "+[WKWebProcessPlugIn _shared] called without first initializing it.");
+    return sharedInstance;
+}
+
+- (id)_initWithPrincipalClassInstance:(id<WKWebProcessPlugIn>)principalClassInstance injectedBundle:(WebKit::InjectedBundle*)injectedBundle
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _private = new WKWebProcessPlugInControllerData;
+    static_cast<WKWebProcessPlugInControllerData*>(_private)->_principalClassInstance = principalClassInstance;
+    static_cast<WKWebProcessPlugInControllerData*>(_private)->_injectedBundle = injectedBundle;
+
+    ASSERT_WITH_MESSAGE(!sharedInstance, "WKWebProcessPlugInController initialized multiple times.");
+    sharedInstance = self;
+
+    return self;
+}
+
+- (void)dealloc
+{
+    delete static_cast<WKWebProcessPlugInControllerData*>(_private);
+    [super dealloc];
+}
+
+@end
+
+@implementation WKWebProcessPlugInController
+
+@end
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInInternal.h
new file mode 100644 (file)
index 0000000..3922964
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WKWebProcessPlugIn.h"
+
+namespace WebKit {
+class InjectedBundle;
+}
+
+@interface WKWebProcessPlugInController (Internal)
+
++ (WKWebProcessPlugInController *)_shared;
+- (id)_initWithPrincipalClassInstance:(id<WKWebProcessPlugIn>)principalClassInstance injectedBundle:(WebKit::InjectedBundle*)injectedBundle;
+
+@end
index 1197256..4ff943a 100644 (file)
@@ -47,6 +47,10 @@ typedef struct _GModule GModule;
 #include <Eina.h>
 #endif
 
+#if PLATFORM(MAC)
+OBJC_CLASS NSBundle;
+#endif
+
 namespace CoreIPC {
     class ArgumentDecoder;
     class Connection;
@@ -56,7 +60,7 @@ namespace CoreIPC {
 namespace WebKit {
 
 #if PLATFORM(MAC)
-typedef CFBundleRef PlatformBundle;
+typedef NSBundle *PlatformBundle;
 #elif PLATFORM(WIN)
 typedef HMODULE PlatformBundle;
 #elif PLATFORM(QT)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "InjectedBundle.h"
+#import "config.h"
+#import "InjectedBundle.h"
 
-#include "WKBundleAPICast.h"
-#include "WKBundleInitialize.h"
-#include <stdio.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/WTFString.h>
+#import "WKBundleAPICast.h"
+#import "WKBundleInitialize.h"
+#import "WKWebProcessPlugInInternal.h"
+
+#import <Foundation/NSBundle.h>
+#import <stdio.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/text/CString.h>
+#import <wtf/text/WTFString.h>
 
 using namespace WebCore;
 
+@interface NSBundle (WKAppDetails)
+- (CFBundleRef)_cfBundle;
+@end
+
 namespace WebKit {
 
 bool InjectedBundle::load(APIObject* initializationUserData)
@@ -56,28 +63,51 @@ bool InjectedBundle::load(APIObject* initializationUserData)
     
     RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false));
     if (!bundleURL) {
-        WTFLogAlways("InjectedBundle::load failed - Could not create the url from the path string.\n");
+        WTFLogAlways("InjectedBundle::load failed - Could not create the url from the path string.");
         return false;
     }
 
-    m_platformBundle = CFBundleCreate(0, bundleURL.get());
+    m_platformBundle = [[NSBundle alloc] initWithURL:(NSURL *)bundleURL.get()];
     if (!m_platformBundle) {
-        WTFLogAlways("InjectedBundle::load failed - Could not create the bundle.\n");
+        WTFLogAlways("InjectedBundle::load failed - Could not create the bundle.");
         return false;
     }
         
-    if (!CFBundleLoadExecutable(m_platformBundle)) {
-        WTFLogAlways("InjectedBundle::load failed - Could not load the executable from the bundle.\n");
+    if (![m_platformBundle load]) {
+        WTFLogAlways("InjectedBundle::load failed - Could not load the executable from the bundle.");
         return false;
     }
 
-    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize")));
-    if (!initializeFunction) {
-        WTFLogAlways("InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n");
+    // First check to see if the bundle has a WKBundleInitialize function.
+    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName([m_platformBundle _cfBundle], CFSTR("WKBundleInitialize")));
+    if (initializeFunction) {
+        initializeFunction(toAPI(this), toAPI(initializationUserData));
+        return true;
+    }
+    
+    // Otherwise, look to see if the bundle has a principal class
+    Class principalClass = [m_platformBundle principalClass];
+    if (!principalClass) {
+        WTFLogAlways("InjectedBundle::load failed - No initialize function or principal class found in the bundle executable.");
         return false;
     }
 
-    initializeFunction(toAPI(this), toAPI(initializationUserData));
+    if (![principalClass conformsToProtocol:@protocol(WKWebProcessPlugIn)]) {
+        WTFLogAlways("InjectedBundle::load failed - Principal class does not conform to the WKWebProcessPlugIn protocol.");
+        return false;
+    }
+
+    id<WKWebProcessPlugIn> instance = (id<WKWebProcessPlugIn>)[[principalClass alloc] init];
+    if (!instance) {
+        WTFLogAlways("InjectedBundle::load failed - Could initialize an instance of the principal class.");
+        return false;
+    }
+
+    // Create the shared WKWebProcessPlugInController.
+    [[WKWebProcessPlugInController alloc] _initWithPrincipalClassInstance:instance injectedBundle:this];
+
+    if ([instance respondsToSelector:@selector(webProcessPlugInInitialize:)])
+        [instance webProcessPlugInInitialize:[WKWebProcessPlugInController _shared]];
     return true;
 }