()
| 26335 | return _isunsafe; |
| 26336 | } |
| 26337 | function addPageScript() { |
| 26338 | var pageScriptText=function(messageID){ |
| 26339 | var frameID=Math.random(); |
| 26340 | var frames={ |
| 26341 | top:window.top, |
| 26342 | }; |
| 26343 | |
| 26344 | window.addEventListener('message',function(e){ |
| 26345 | var data=e.data; |
| 26346 | if( !data || !data.messageID || data.messageID != messageID )return;//通信ID认证 |
| 26347 | var source=e.source; |
| 26348 | if(source===window || source===unsafeWindow){//来自contentscript,发送出去,或者干嘛。 |
| 26349 | if(data.to){ |
| 26350 | data.from=frameID; |
| 26351 | frames[data.to].postMessage(data,'*'); |
| 26352 | }else{ |
| 26353 | switch(data.command){ |
| 26354 | case 'getIframeObject':{ |
| 26355 | var frameWindow=frames[data.windowId]; |
| 26356 | var iframes=document.getElementsByTagName('iframe'); |
| 26357 | var iframe; |
| 26358 | var targetIframe; |
| 26359 | for(var i=iframes.length-1 ; i>=0 ; i--){ |
| 26360 | iframe=iframes[i]; |
| 26361 | if(iframe.contentWindow===frameWindow){ |
| 26362 | targetIframe=iframe; |
| 26363 | break; |
| 26364 | }; |
| 26365 | }; |
| 26366 | var cusEvent=document.createEvent('CustomEvent'); |
| 26367 | cusEvent.initCustomEvent('pv-getIframeObject',false,false,targetIframe); |
| 26368 | document.dispatchEvent(cusEvent); |
| 26369 | }break; |
| 26370 | }; |
| 26371 | }; |
| 26372 | |
| 26373 | }else{//来自别的窗口的,contentscript可以直接接收,这里保存下来自的窗口的引用 |
| 26374 | frames[data.from]=source; |
| 26375 | }; |
| 26376 | },true) |
| 26377 | }; |
| 26378 | |
| 26379 | try{ |
| 26380 | if(isunsafe()){ |
| 26381 | pageScriptText(messageID); |
| 26382 | }else{ |
| 26383 | var pageScript=document.createElement('script'); |
| 26384 | pageScript.id = 'picviewer-page-script'; |
| 26385 | pageScript.textContent=createScript('(' + pageScriptText.toString() + ')('+ JSON.stringify(messageID) +')'); |
| 26386 | if(document.head)document.head.appendChild(pageScript); |
| 26387 | } |
| 26388 | }catch(e){ |
| 26389 | console.debug("addPageScript function failed", e); |
| 26390 | } |
| 26391 | } |
| 26392 | |
| 26393 | function clickToOpen(data){ |
| 26394 | var preventDefault = matchedRule.clickToOpen.preventDefault; |
no test coverage detected