firefox – NPP_NewStream:本地文件的可搜索设置为0(false)

我正在尝试使用流功能实现NPAPI插件(NP_SEEK
NPN_RequestRead).无论我尝试什么,布尔NPBool可查找总是设置为0(假).

我从本地文件的命令行启动firefox(Debian上的iceweasel):

$iceweasel test1.html

如果我将gdb附加到npapi插件,这就是我所看到的:

(gdb) 
#2  0x00007f7e9da54e14 in mozilla::plugins::BrowserStreamChild::StreamConstructed (this=0x7f7e925cf310, mimeType=..., seekable=<optimized out>, stype=<optimized out>)
    at /tmp/buildd/iceweasel-24.6.0esr/dom/plugins/ipc/BrowserStreamChild.cpp:62
62      &mStream, seekable, stype);
(gdb) 
#3  0x00007f7e9da5688e in mozilla::plugins::PluginInstanceChild::AnswerPBrowserStreamConstructor (this=<optimized out>, aActor=<optimized out>, url=..., 
    length=<optimized out>, lastmodified=<optimized out>, notifyData=<optimized out>, headers=..., mimeType=..., seekable=@0x7fff25ed51df: false, rv=0x7fff25ed51e0, 
    stype=0x7fff25ed51e2) at /tmp/buildd/iceweasel-24.6.0esr/dom/plugins/ipc/PluginInstanceChild.cpp:2285
2285              ->StreamConstructed(mimeType, seekable, stype);
(gdb) p seekable
$1 = (const bool &) @0x7fff25ed51df: false
(gdb) up
#4  0x00007f7e9da8f77f in mozilla::plugins::PPluginInstanceChild::OnCallReceived (this=0x7f7e925f2c00, __msg=..., __reply=@0x7fff25ed5470: 0x0)
    at /tmp/buildd/iceweasel-24.6.0esr/build-xulrunner/ipc/ipdl/PPluginInstanceChild.cpp:2479
warning: Source file is more recent than executable.
2479                if ((!(AnswerPBrowserStreamConstructor(actor, url, length, lastmodified, notifyData, headers, mimeType, seekable, (&(rv)), (&(stype)))))) {
(gdb) list -
2469                if ((!(actor))) {
2470                    return MsgValueError;
2471                }
2472                (actor)->mId = RegisterID(actor, (__handle).mId);
2473                (actor)->mManager = this;
2474                (actor)->mChannel = mChannel;
2475                (mManagedPBrowserStreamChild).InsertElementSorted(actor);
2476                (actor)->mState = mozilla::plugins::PBrowserStream::__Start;
2477    
2478                int32_t __id = mId;
(gdb) list -
2459                    FatalError("Error deserializing 'bool'");
2460                    return MsgValueError;
2461                }
2462                (__msg).EndRead(__iter);
2463                if ((!(PPluginInstance::Transition(mState, Trigger(Trigger::Send, PPluginInstance::Msg_PBrowserStreamConstructor__ID), (&(mState)))))) {
2464                    NS_WARNING("bad state transition!");
2465                }
2466                NPError rv;
2467                uint16_t stype;
2468                actor = AllocPBrowserStream(url, length, lastmodified, notifyData, headers, mimeType, seekable, (&(rv)), (&(stype)));
(gdb) list -
2449                }
2450                if ((!(Read((&(headers)), (&(__msg)), (&(__iter)))))) {
2451                    FatalError("Error deserializing 'nsCString'");
2452                    return MsgValueError;
2453                }
2454                if ((!(Read((&(mimeType)), (&(__msg)), (&(__iter)))))) {
2455                    FatalError("Error deserializing 'nsCString'");
2456                    return MsgValueError;
2457                }
2458                if ((!(Read((&(seekable)), (&(__msg)), (&(__iter)))))) {
(gdb) up
#5  0x00007f7e9da868f0 in mozilla::plugins::PPluginModuleChild::OnCallReceived (this=<optimized out>, __msg=..., __reply=@0x7fff25ed5470: 0x0)
    at /tmp/buildd/iceweasel-24.6.0esr/build-xulrunner/ipc/ipdl/PPluginModuleChild.cpp:1023
warning: Source file is more recent than executable.
1023            return (__routed)->OnCallReceived(__msg, __reply);
(gdb) list -
1013    PPluginModuleChild::OnCallReceived(
1014            const Message& __msg,
1015            Message*& __reply)
1016    {
1017        int32_t __route = (__msg).routing_id();
1018        if ((MSG_ROUTING_CONTROL) != (__route)) {
1019            ChannelListener* __routed = Lookup(__route);
1020            if ((!(__routed))) {
1021                return MsgRouteError;
1022            }
(gdb) bt

如果我将test1.html复制到/ var / www,然后指向http://localhost/test1.html,一切都按预期工作.

不过documentation提到了

seekable
Boolean indicating whether the stream is seekable:
true: Seekable. Stream supports random access through calls to NPN_RequestRead (for example, local files or HTTP servers that support byte-range requests).

最佳答案 文件是完全撒谎.

> NPP_NewStream调用中的可搜索标志

>起源于OnStartBinding
>调用nsPluginStreamListenerPeer::IsSeekable
>只返回nsPluginStreamListenerPeer :: mSeekable.

> mSeekable唯一设置为真的时间是(source)

>流是http(https,spdy)
> http响应没有Content-Encoding
> http响应提供Content-Length.
> http响应具有Accept-Ranges:bytes(不支持省略标头)

>对于所有其他流类型(包括file://)和不符合要求的http流,可搜索标志因此始终为false.

此外,NPN_RequestRead是only implemented for http streams,但实际上并不关心可搜索,并且实际上不检查服务器是否返回206.

结论

您只能将NP_SEEKstreams与http(https,spdy)一起使用.这就是为什么东西来自http:// localhost,而不是来自本地文件(file://).

点赞