Skip to content

Commit

Permalink
[embedlite] Retranslate async messages to global and content frame me…
Browse files Browse the repository at this point in the history
…ssage managers

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@jolla.com>
  • Loading branch information
rojkov committed Oct 29, 2015
1 parent 9eb3c27 commit 31b632f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
32 changes: 32 additions & 0 deletions embedding/embedlite/modules/EmbedFrame.cpp
@@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "EmbedFrame.h"

EmbedFrame::EmbedFrame()
{
}

EmbedFrame::~EmbedFrame()
{
}

NS_IMPL_ISUPPORTS(EmbedFrame, nsIEmbedFrame)

NS_IMETHODIMP
EmbedFrame::GetContentWindow(nsIDOMWindow** aWindow)
{
nsCOMPtr<nsIDOMWindow> window = mWindow;
window.forget(aWindow);
return NS_OK;
}

NS_IMETHODIMP
EmbedFrame::GetMessageManager(nsIContentFrameMessageManager** aMessageManager)
{
nsCOMPtr<nsIContentFrameMessageManager> mm = mMessageManager;
mm.forget(aMessageManager);
return NS_OK;
}
27 changes: 27 additions & 0 deletions embedding/embedlite/modules/EmbedFrame.h
@@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef EMBEDFRAME_H
#define EMBEDFRAME_H

#include "nsIEmbedFrame.h"
#include "nsCOMPtr.h"

class EmbedFrame : public nsIEmbedFrame
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEMBEDFRAME

EmbedFrame();

nsCOMPtr<nsIDOMWindow> mWindow;
nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;

private:
virtual ~EmbedFrame();
};

#endif
18 changes: 18 additions & 0 deletions embedding/embedlite/modules/nsIEmbedFrame.idl
@@ -0,0 +1,18 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsIDOMWindow.idl"
#include "nsIMessageManager.idl"

interface nsIDOMWindow;
interface nsIContentFrameMessageManager;

[scriptable, uuid(48738828-adbe-4106-a453-0d6e0965d6f8)]
interface nsIEmbedFrame : nsISupports
{
readonly attribute nsIDOMWindow contentWindow;
readonly attribute nsIContentFrameMessageManager messageManager;
};
2 changes: 2 additions & 0 deletions embedding/embedlite/moz.build
Expand Up @@ -19,6 +19,7 @@ FINAL_LIBRARY = 'xul'
XPIDL_SOURCES += [
'embedshared/EmbedLiteViewIface.idl',
'modules/nsIEmbedAppService.idl',
'modules/nsIEmbedFrame.idl',
'modules/nsIEmbedLiteJSON.idl',
'utils/nsIEmbedBrowserChromeListener.idl',
]
Expand Down Expand Up @@ -67,6 +68,7 @@ UNIFIED_SOURCES += [
'embedthread/EmbedLiteAppThreadParent.cpp',
'embedthread/EmbedLiteViewThreadChild.cpp',
'embedthread/EmbedLiteWindowThreadChild.cpp',
'modules/EmbedFrame.cpp',
'modules/EmbedLiteAppService.cpp',
'modules/EmbedLiteJSON.cpp',
'utils/DirProvider.cpp',
Expand Down
17 changes: 17 additions & 0 deletions embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -31,6 +31,7 @@
#include "nsLayoutUtils.h"
#include "nsIDocumentInlines.h"
#include "APZCCallbackHelper.h"
#include "EmbedFrame.h"

static const char BEFORE_FIRST_PAINT[] = "before-first-paint";
static const char CANCEL_DEFAULT_PAN_ZOOM[] = "cancel-default-pan-zoom";
Expand Down Expand Up @@ -363,6 +364,22 @@ TabChildHelper::DoSendAsyncMessage(JSContext* aCx,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
nsCOMPtr<nsIMessageBroadcaster> globalIMessageManager =
do_GetService("@mozilla.org/globalmessagemanager;1");
nsRefPtr<nsFrameMessageManager> globalMessageManager =
static_cast<nsFrameMessageManager*>(globalIMessageManager.get());
nsRefPtr<nsFrameMessageManager> contentFrameMessageManager =
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());

nsCOMPtr<nsPIDOMWindow> pwindow = do_GetInterface(WebNavigation());
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(pwindow);
nsRefPtr<EmbedFrame> embedFrame = new EmbedFrame();
embedFrame->mWindow = window;
embedFrame->mMessageManager = mTabChildGlobal;
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
globalMessageManager->ReceiveMessage(embedFrame, aMessage, false, &aData, &cpows, aPrincipal, nullptr);
contentFrameMessageManager->ReceiveMessage(embedFrame, aMessage, false, &aData, &cpows, aPrincipal, nullptr);

if (!mView->HasMessageListener(aMessage)) {
LOGW("Message not registered msg:%s\n", NS_ConvertUTF16toUTF8(aMessage).get());
return true;
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/utils/WindowCreator.cpp
Expand Up @@ -12,6 +12,9 @@
#include <stdio.h>
#include "EmbedLiteViewChildIface.h"
#include "EmbedLiteAppChildIface.h"
#include "nsCOMPtr.h"
#include "nsIThread.h"
#include "nsThreadUtils.h" // for NS_GetCurrentThread

using namespace mozilla::embedlite;

Expand Down

0 comments on commit 31b632f

Please sign in to comment.