objective-c - WebView 中的插件对象被破坏?

标签 objective-c cocoa plugins webkit webview

这是我的情况:

我编写了一个简单的网络浏览器。一旦我了解了概念并弄清楚如何在特定选项卡上执行操作,选项卡式浏览就很容易开始工作。它运行良好,并且在大多数情况下都非常可靠。

但是有一个问题困扰着我,我无法找出其原因。

假设我打开一个新标签页并导航到 YouTube。我单击视频并加载 Flash 播放器。视频播放并且一切正常。我现在创建另一个新选项卡并导航到某个网站。 YouTube 播放器的音频完全停止。

当我切换回 YouTube 选项卡时,页面仍然会原样存在,只是播放器必须完全重新加载,就像我刚刚重新加载页面一样。这似乎也适用于其他插件类型。

这是什么原因造成的?

垃圾收集未启用,据我所知,我正在正确创建 WebView 。我是否在整个过程中遗漏了一些愚蠢而简单的小事情?

最佳答案

- (void)setHostWindow:(NSWindow *)hostWindow WebView 上的方法可能就是您正在寻找的。

每当封闭窗口的样式掩码发生更改时,我都会在 WebView 重新加载中遇到与 Flash 相同的问题。将调用转接至 setStyleMask已修复问题,如下:

NSWindow *hostWindow = [[NSWindow alloc] init];
[self.webView setHostWindow:hostWindow];
[[self windowForSheet] setStyleMask:styleMask];
[self.webView setHostWindow:nil];
[hostWindow release];

The documentation for the method不是很好,但它确实明确指出在 NSTabView 中包含 WebView 作为用例之一:

This method sets the receiver’s host window to hostWindow. Your application should only use this method if a web view is going to be removed from its window temporarily, and you want the web view to continue operating (for example, you don’t want to interrupt a load in progress). Since the receiver retains hostWindow, it is your responsibility to set the host window to nil before closing the window to avoid a retain loop.

For example, you might invoke this method if you attach a web view to an NSTabView object (as in a tabbed browser implementation). The NSTabView object takes views out of the window when they are not in the active tab, so you need to invoke this method before the web view is removed from its window. If you don't invoke this method, plug-ins will stop operating when the web view is removed from its window.

关于objective-c - WebView 中的插件对象被破坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5307423/

相关文章:

ios - 指向用户的指针字段需要一个指针值 Parse.com

ios - 无法为自定义 NSObject 赋值

cocoa - 空选择器发送到 NSMutableArray 中的第一项

java - 使用 Gradle 的 JAR 中的 META-INF/服务

c++ - 反向代理的典型架构是什么?

objective-c - 苹果手机 : responder chain in UIScrollView

objective-c - 为什么在我的代码之后没有将注释添加到 map 上?

Objective-C:从 NSString 生成 NSArray

objective-c - 如何在 Sparkle 中签署您的更新

java - 使用 Maven 插件 Web.xml 未包含在 War 中