npWindow->window 在 NPP_SetWindow 函数中给出 0 值,Mac 上 Safari 浏览器的插件 [英] npWindow->window gives 0 value in NPP_SetWindow function, plugin for Safari browser on Mac

查看:90
本文介绍了npWindow->window 在 NPP_SetWindow 函数中给出 0 值,Mac 上 Safari 浏览器的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个在 windows 上的 firefox 中运行良好的插件,现在正在移植到 Mac 上的 safari.我们正在使用Xcode进行开发.我们希望在 safari 浏览器中有一个可以显示视频的窗口.我阅读了有关 NPP_SetWindow 函数中使用的 NSwindow 的代码,如下所示:

A plugin, which works fine in firefox on windows, is being now ported to safari on Mac. we are using Xcode for development. we want a window in safari browser over which a video can be displayed. I read a code regarding NSwindow being used in NPP_SetWindow function as following:

NPError NPP_SetWindow(NPP instance, NPWindow* npWindow)
{
// Get a Cocoa window reference of the browser window
NP_CGContext* npContext = (NP_CGContext*)npWindow->window;
WindowRef window = npContext->window;
NSWindow* browserWindow = [[[NSWindow alloc] initWithWindowRef:window] autorelease];

// Get a Cocoa reference of my carbon window
// yourCarbonWindow should be replaced with the window handle of the carbon
// window that should be tied to the Safari window.
NSWindow* myWindow = [[[NSWindow alloc] initWithWindowRef:yourCarbonWindow] autorelease];

// Now create a parent child relationship
[browserWindow addChildWindow:myWindow ordered:NSWindowAbove];
}

但问题是 npWindow->window 没有携带任何值.用printf检查时,显示0值,表示未初始化或NULL.

But the problem is that npWindow->window is not carrying any value. When checked with printf, it shows 0 value, means it was not initialized or NULL.

但在 Firefox 中,它具有一定的价值.有人能告诉我如何在 Safari 中获取 NSWindow 或者问题出在哪里吗?碳窗的概念是什么?

But in Firefox it was carrying some value. Could someone please tell how to get a NSWindow in Safari or where might be the problem ? And what is this concept of Carbon window?

推荐答案

现代版本的 Safari 不支持 Carbon 事件模型(这是您的代码片段使用的),仅支持 Cocoa 事件模型,并且根据文档,该事件模型中的窗口引用为空.

Modern versions of Safari don't support the Carbon event model (which is what your code snippet is using), only the Cocoa event model, and per the documentation the window ref is null in that event model.

很长一段时间以来,直接在窗口上乱搞一直是 NPAPI 插件(至少在 Mac 上)中的一种反模式,而对于 64 位和进程外插件,这已变得不可能;NSWindow 不在您的插件进程中,因此您无法获得指向它的指针.您应该在 API 建立的上下文或图层(取决于您的绘图模型)中进行绘图,而不是尝试显示您自己的子窗口.

Mucking around with the window directly has been an anti-pattern in NPAPI plugins (at least on Mac) for quite a while, and with 64-bit and out-of-process plugins it has become impossible; the NSWindow isn't in your plugin's process, so you can't get a pointer to it. You should be drawing into the context or layer (depending on your drawing model) established by the API, rather than trying to show your own child window.

这篇关于npWindow->window 在 NPP_SetWindow 函数中给出 0 值,Mac 上 Safari 浏览器的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆