Safari 5.1 npapi 问题

发布于 2024-11-30 04:42:07 字数 1122 浏览 0 评论 0原文

几天来,我一直在尝试解决以下问题,阅读了我在网上找到的有关 mac 上 npapi 的所有内容。

目标是拥有一个适用于 safari 和 firefox(mac) 的 npapi 插件。 我的软件(我不能为此专门重写,有大约 45000 行 C 代码)是基于附加到 NSDocument 的 NSView...

我有一个基于 webkit 版本的插件,我必须扔掉它(感谢 Apple!)基于相同的 NSView。

我有一个 npapi 版本插件,可以在 Firefox 上正常运行。在这个 npapi 插件中,我采用了 Carbon 窗口引用,并基于此创建了一个 NSWindow: NSWindow *browserWindow = [[[NSWindow alloc] initWithWindowRef:wind]autorelease];

我把 NSView 放在这个窗口上,这样就可以了。

现在的问题是我不能在 safari 上做同样的事情。

看附图,窗户不是Safari的窗户! firefox 窗口位于 safari 窗口和我的插件窗口之间

我尝试了多种方法...但不起作用。 可可的咕噜能告诉我哪里做错了吗?或者这是一个已知问题?

NPError NPP_SetWindow(NPP实例,NPWindow*窗口){

NP_CGContext *ctx =窗口->窗口; void *wind = ctx->窗口;

... 在 NSView 初始化函数中:

NSWindow *browserWindow = [[NSWindow alloc] initWithWindowRef:wind];
self = [super initWithFrame:frame];
if( self )
{
    [browserWindow makeFirstResponder: self];
    [self  setNextResponder: nil];
    [browserWindow setContentView:self];
    [self webPlugInInitialize];// my own initializing
}
return self;

Since several days I am trying to resolve the folowing issue, reading all I found around the web about npapi on mac.

The goal is to have a npapi plugin which works for safari and firefox(mac).
My software (that I can not rewrite specialy for this purpose hase about 45000 lines of C code) is based on a NSView attached to a NSDocument....

I have a webkit version based plugin that I must trash (thanks to Apple!) based to the same NSView.

I have a npapi version plugin which works fine on firefox. In this npapi plugin, I take the carbon window ref, I make a NSWindow based on that:
NSWindow *browserWindow = [[[NSWindow alloc] initWithWindowRef:wind]autorelease];

and I put my NSView on this window and that works.

Now the pb is that I can not do the same thing on safari.

Look at attached picture, the window is not in the safari's window!
the firefox window is between safari's window and my plugin window

I tryed several ways... it dose not work.
Can a cocoa's gourou says where I am making something wrong? or is this a known issue?

NPError NPP_SetWindow(NPP instance, NPWindow* window){

NP_CGContext *ctx = window->window;
void *wind = ctx->window;

...
in the NSView init function:

NSWindow *browserWindow = [[NSWindow alloc] initWithWindowRef:wind];
self = [super initWithFrame:frame];
if( self )
{
    [browserWindow makeFirstResponder: self];
    [self  setNextResponder: nil];
    [browserWindow setContentView:self];
    [self webPlugInInitialize];// my own initializing
}
return self;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淑女气质 2024-12-07 04:42:07

在 Safari 5.1 中,网页渲染不是由 Safari 本身完成,而是在不同的进程上完成,以增强安全性。打开活动监视器,您会看到名为“Safari Web Process”或类似名称的后台进程。

因此,您不能也不应该基于可在 NPAPI 插件中获取的 Carbon 窗口引用创建 NSWindow
阅读 Apple 自己的文档 关于这一点。您应该请求核心图形绘制方法,然后 NP_CGContextWindowRef 字段应该有一个 NSWindow*,而不是 Carbon 窗口引用。

In Safari 5.1, the web rendering is not done by Safari itself, but on a different process to enhance security. Open up the Activity Monitor, and you see that background process called "Safari Web Process" or something like that.

So, you can't and shouldn't create NSWindow based on the Carbon window ref which can be obtained within NPAPI plugin.
Read Apple's own documentation on this point. You should request the core graphics drawing method, and then the WindowRef field of NP_CGContext should have a NSWindow*, not the Carbon window ref.

桜花祭 2024-12-07 04:42:07

如果它可以在 Firefox 上运行,那就完全令人震惊并且完全不受支持。它可以在 Firefox 4 及更高版本中使用吗?

如果您绝对必须使用 NSView,我知道在插件中执行此操作的唯一方法是将 NSView 渲染到您的 CGContext 中。请记住,在具有 Cocoa 事件系统的较新 NPAPI 浏览器中,您将 CGContextRef 作为绘制事件的一部分获得;要请求绘制事件,您可以调用 NPN_InvalidateWindow。

FireBreath 有一个 完全实验性且不完全功能的将 NSView(特别是 WebView)渲染到 CGContextRef 中的示例,您可以将其视为示例。

除了使用 CGContextRef 之外,您唯一的选择是使用 CALayer;如果你能找到一种方法来制作 NSWindow 或 NSView ,那你可能没问题,但我不知道是否有。有人建议将 CALayer 设置为 NSView 的渲染层可能可行。无论哪种方式,您很可能都必须转发所有事件,因为您基本上是在屏幕外视图中托管 NSView。

别搞错了;不支持在浏览器中获取 NSView 的方法。从来没有——人们使用的方法不受支持,并且依赖于特定于浏览器的 API 实现。当您使用类似的东西时,您可以可靠地预期它们最终会损坏,例如在本例中。有关绘图模型的更多信息,您可以阅读 Stuart Morgan 的博客文章关于这个主题,请查看 FireBreath mac 绘图模型文档,或阅读 Cocoa 事件模型规范

If it works on Firefox, that's totally shocking and completely unsupported. Does it work in Firefox 4 and later?

If you absolutely have to use an NSView, the only way that I know to do it in a plugin is to render the NSView into your CGContext. Keep in mind that in newer NPAPI browsers with the Cocoa event system you get the CGContextRef as part of the draw event; to request a draw event you can call NPN_InvalidateWindow.

FireBreath has a completely experimental and not-fully-functional example of rendering an NSView (ans specifically a WebView) into a CGContextRef that you could look at as an example.

Other than using a CGContextRef your only other choice is to use a CALayer; if you can find a way to make a NSWindow or NSView in that you could be okay, but I don't know if there is one. Someone suggested that setting the CALayer as the rendering layer for the NSView might work. Either way you'll most likely have to forward all the events since you are basically hosting the NSView in an offscreen view.

Make no mistake; there is no supported way to get an NSView in the browser. There never has been -- methods that people have used were unsupported and depended on browser-specific implementations of the API. When you use things like that, you can reliably expect them to eventually break, such as in this case. For more information on the drawing models, you could read Stuart Morgan's blog post on the subject, check out the FireBreath mac drawing model docs, or read the Cocoa event model spec.

梦年海沫深 2024-12-07 04:42:07

鉴于您从“获取 Carbon 窗口参考”开始,您的方法注定会失败,因为它基于 Carbon 事件模型(不仅如此,还对其内部实现细节进行了假设)。任何在 64 位系统上运行 Firefox 的人都必须在 32 位模式下手动重新启动 Firefox,才能让您的 hack 生效,即便如此,它也只能在 Firefox 完全删除 Carbon 支持(计划在可预见的未来)之前起作用。

正如其他答案所说,你出错的地方是你的整个方法完全不受支持,事实上它曾经作为 NPAPI 插件工作是幸运的。您根本无法在 NPAPI 插件中直接使用 NSView。

Given that you start with "take the carbon window ref", your approach is doomed, because it is based on the Carbon event model (and not just that, but assumptions about its internal implementation details). Anyone running Firefox on a 64-bit system will have to manually restart Firefox in 32-bit mode for your hack to work, and even then it will only work until Firefox completely removes Carbon support (which is planned for the foreseeable future).

As the other answers said, where you are going wrong is that your whole approach is completely unsupported, and the fact that it ever worked at all as an NPAPI plugin was luck. You simply cannot use an NSView directly in an NPAPI plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文