2011-09-08 4 views
1

나는 시스템과 상호 작용하는 일부 권한있는 JavaScript 코드와 함께 chromeless 애플리케이션을 가지고 있습니다. 이제 서버에 호스팅 된 애플리케이션과 함께 특권 JavaScript (jsctypes)를 매시업하고 싶습니다. 원격 애플리케이션은 Iframe에로드되고 chromeless 애플리케이션과 원격 애플리케이션 간의 상호 작용은 html5 postMessage를 통해 발생합니다.iframe 교차 도메인 통신 및 chromeless 도메인

부모가 포함 된 Iframe에 메시지를 게시하고 e.origin이 "resource : \ app" 인 Iframe에서 성공적으로 수신하는 반면 iframe에서 resource.domain으로 window.parent로 postMessage를 보내려고하면 : 응용 프로그램 부모에서의 onMessage 리스너가 실행에

레이아웃

,

를 호출되지 않습니다> 크롬 예 \ testapp를 \ index.html을 XUL 응용 프로그램은 크롬 빌드 폴더에 생성되고 다음이 표시됩니다. 어떤 도움을 주시면 감사

  var onmessage = function(e) { 
       alert("message"); 
      } 
      if(typeof window.addEventListener != 'undefined') { 
       window.addEventListener('message', onmessage, false); 
      } 
      else if(typeof window.attachEvent != 'undefined') { 
       window.attachEvent('onmessage', onmessage); 
       } 

학부모의 onMessage

[Code] 
var sendMessage = function(){ 
     var iframe = window.parent; 
     iframe.postMessage("test","resouce://app"); 
    }; 

    [/Code] 

Iframe에

내부

 
+-----------------------------------Chromeless----+ 
|             | 
| --- MessageToIframeButton      | 
|             | 
| +--------------------------Iframe--+   | 
| |Msg Recvd from: resource://app |   | 
| |(this is the message from parent) |   | 
| |         |   | 
| | _TxtBox_sendMessage   |   | 
| |         |   | 
| |         |   | 
| |         |   | 
| +----------------------------------+   | 
| Msg Recvd:          | 
|             | 
+-------------------------------------------------+ 

PostMessage를!

팔란, 나는 사용자 정의 이벤트를 사용하여 크로스 도메인 통신을 구현하려하지만 Priviliged 된 index.html에서

성공하지 못했습니다 [무 크롬 예 \ testapp를 \ index.html을] :

 var myExtension = { 
      myListener: function(evt) { 
      alert("Received from web page: " + 
      evt.target.getAttribute("attribute1")); 
     } 
     } 
document.addEventListener("MyExtensionEvent", function(e) {myExtension.myListener(e); }, false, true); // The last value is a Mozilla-specific value to indicate untrusted content is allowed to trigger the event. 
    //content.addEventListener("MyExtensionEvent", function(e) {myExtension.myListener(e); }, false, true); //Also tried with content. 

에서 원격 응용 프로그램 iframe이 remote.html : 버튼의 클릭에 ,

var element = document.createElement("MyExtensionDataElement"); 
element.setAttribute("attribute1", "foobar"); 
document.documentElement.appendChild(element); 

var evt = document.createEvent("Events"); 
evt.initEvent("MyExtensionEvent", true, false); 
element.dispatchEvent(evt); 

트리거 된 이벤트 수행하는 권한을 부모 도메인에 있지 거품 iframe 자체에 eventListener가 추가되면 전달 된 이벤트가 수신되고 마찬가지로 맞춤 이벤트가 권한있는 컨텍스트 (index.html)에서 생성 된 경우 부모 창은 알림을 받지만 계층 구조 간에는 전달되지 않습니다. 나는 기본적인 것을 놓치고 있는가 ??

+0

iframe에서 '*'및 postMessage로 도메인을 설정하면 메시지는 부모 창이 아니라 Iframe에서 수신합니다. – Yeshvanthni

+0

동일한 샘플 html 페이지 (도메인이 '*'로 설정된 경우)는 firefox에서 파일을 열거 나 Chromeless 배치를 실행하고 브라우저에서 html 파일을 열 때 부모 창에 메시지를 게시합니다.이 경우 파일과 동일하며 권한이 부여 된 것입니다 javascript가 실행되지 않거나 XULaplication처럼 동작하지 않습니다. – Yeshvanthni

+0

[link] http : // stackoverflow가 원인입니다.coz/questions/5463429/모질라에서 크롬을 사용하지 않는 top-from-take-over-in-mozilla. Iframe 상단 창을 만드는 동작. ?? – Yeshvanthni

답변

2

Prevent target="_top" from taking over UI in Mozilla Chromeless에 링크하면 원격 응용 프로그램을로드 한 프레임이 콘텐츠 프레임입니다 (확실히 있어야 함). 즉, 권한이 부여 된 코드와 내용 사이에 보안 경계가 설정되며 특히 최상위 수준 인 것처럼 보이며 권한있는 문서에 액세스 할 수 없습니다 (확인하기 쉽고 프레임 코드에 alert(window == window.parent) 추가) . 이 모든 것은 보안 측면에서 의미가 있지만, 통신용으로는 postMessage()을 사용하는 것이 불가능 함을 의미합니다.

https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages에 설명 된 다소 난처한 통신 방법이 있습니다. 보안 경계를 안전하게 통과 할 수 있다는 이점이 있습니다.

+0

고맙습니다. 창! = 창. 부모님. 창을 열었습니다. 위치, 창. 부모님. 위치, 창, 부모님, 위치 및 모든 위치가 Iframe 위치를 가리키는 것 같습니다. 맞춤 이벤트가 효과가 있기를 바랍니다. 시도 후 다시 게시됩니다. – Yeshvanthni

관련 문제