开发者

OS X: How to alter WebKit's plugin search path?

开发者 https://www.devze.com 2023-04-04 03:55 出处:网络
I have a developed a browser-like Mac Desktop app which uses WebKit to render web content. My app links against the standard system WebKit framework (it does not bundle a private WebKit framework).

I have a developed a browser-like Mac Desktop app which uses WebKit to render web content.

My app links against the standard system WebKit framework (it does not bundle a private WebKit framework).

However, I would like to bundle a private Flash plugin in my app bundle. When my app runs, I would like WebKit to prefer the private Flash plugin in my bundle over any other Flash plugin on the system.

How can I alter WebKit's plugin search path such that my app will load my priv开发者_Python百科ate Flash plugin bundled with my app?


I don't believe there is a public, documented method for doing this.

Take a look at the WebView source code, in particular at the "WebPluginDatabase.mm" source file, to get a sense for how the plugin paths are evaluated and what priority is given to plugins found in various locations. By defauilt, it appears the search path goes in this order:

  1. ~/Library/Internet Plug-Ins
  2. /Library/Internet Plug-Ins
  3. App Bundle's plug-ins folder

So by design, any plugin you include in your app's bundle will, by default be superseded by a version found in the user or system library folder.

If using undocumented SPI is an option, I see there is a method on WebView.mm that essentially overrides the list of plugin paths, calling through to appropriate configuration on the WebPluginDatabase singleton:

- (void)_setAdditionalWebPlugInPaths:(NSArray *)newPaths
{
    if (!_private->pluginDatabase)
        _private->pluginDatabase = [[WebPluginDatabase alloc] init];

    [_private->pluginDatabase setPlugInPaths:newPaths];
    [_private->pluginDatabase refresh];
}

On the topic of SPI-based solutions, another Stack Overflow question has an answer that describes overriding a private WebView method to provide a specific plugin based on MIME type:

Prevent Flash in Cocoa WebView

This gives me another idea that may be suitable for your purposes. Since you are in charge of the whole browsing experience, you might consider altering all the HTML code that is presented in your browser, scanning for and modifying any content that is normally tied to the Flash plugin, and changing it to invoke a custom MIME type or whatever to get your "DitchenFlash" to load instead ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消