本文介绍了在Cocoa WebView中阻止Flash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Cocoa应用程序中,我想防止Flash加载到WebView,并让用户决定是否应该为每个页面显示Flash。 (这是通过ClickToFlash插件或Safari扩展已经可用的相同的行为)捆绑任何这些扩展可能不是一个选项,因为许可问题。)

In my Cocoa app, I want to prevent Flash from loading in a WebView, and let the user decide if the Flash should be shown for each page. (That's the same behavior already available through the ClickToFlash plugin or Safari extension. Bundling any of those extensions is probably not an option because of licensing issues.)

Flash我想避免是从嵌入式JavaScript生成的专门设计,以防止容易的闪存阻塞,所以我不能过滤原始HTML包含Flash对象。

Unfortunately most of the Flash I'm trying to avoid is generated from embedded JavaScript specifically designed to prevent easy flash blocking, so I cannot filter the raw HTML for inclusion of Flash objects.

我无法为我的WebView禁用JavaScript,因为当JavaScript关闭时,我想显示的页面看起来完全不同。

Also, I cannot disable JavaScript for my WebView, as the page I want to display looks completely different when JavaScript is turned off.

有一个通知/挂钩我可以用来修改

Is there a notification/hook I can use to modify the page DOM after JavaScript has been executed, but before the Flash plugin is loaded?

或者我应该追求不同的方向吗?

Or should I pursue a different direction?

感谢,
Ilja

Thanks,Ilja

推荐答案

理想情况下,您只需定义自己的WebKit插件处理 application / shockwave-flash MIME类型,并使您的插件无需任何操作。

Ideally, you would just define your own WebKit plug-in that handles the application/shockwave-flash MIME type and make your plug-in do nothing.

不幸的是没有办法控制多个WebKit插件的所有注册相同MIME类型的优先级。 WebKit插件的加载顺序是完全随机和任意的,因此您不能保证您的插件将处理Flash对象而不是Flash插件。

However, there is unfortunately no way to control the priority of multiple WebKit plug-ins that all register for the same MIME type. The loading order of WebKit plug-ins is totally random and arbitrary, so you cannot guarantee that your plug-in will handle the Flash object instead of the Flash plug-in.

我发现的唯一方法是子类 WebView 并覆盖私有方法 -_ pluginForMIMEType: like所以:

The only way around this that I've found is to subclass WebView and override the private method -_pluginForMIMEType: like so:

@class WebBasePluginPackage;

@interface WebView ( MyFlashPluginHack )
- (WebBasePluginPackage *)_pluginForMIMEType:(NSString *)MIMEType;
@end

@implementation MyWebView

- (WebBasePluginPackage *)_pluginForMIMEType:(NSString *)MIMEType
{
    if ( [MIMEType isEqualToString:@"application/x-shockwave-flash"] )
    {
        return [super _pluginForMIMEType:@"application/my-plugin-type"];
    }
        else
    {
        return [super _pluginForMIMEType:MIMEType];
    }
}

@end

你只需要创建一个自定义的WebKit插件来处理application / my-plugin-type,并让该插件根本不做。

Then you just need to create a custom WebKit plugin to handle "application/my-plugin-type" and have that plug-in do nothing at all.

这篇关于在Cocoa WebView中阻止Flash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:24