Skip to content

Commit

Permalink
Added EmbedLiteAppIface in order to abstract embedliteApp from thread…
Browse files Browse the repository at this point in the history
… based IPC interface.
  • Loading branch information
tmeshkova committed Oct 4, 2014
1 parent 0b2c299 commit 72e6b4d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 19 deletions.
33 changes: 17 additions & 16 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -26,6 +26,7 @@
#include "EmbedLiteRenderTarget.h"

#include "EmbedLiteCompositorParent.h"
#include "EmbedLiteAppIface.h"

namespace mozilla {
namespace embedlite {
Expand Down Expand Up @@ -208,7 +209,7 @@ EmbedLiteApp::AddManifestLocation(const char* manifest)
if (!mAppParent) {
sComponentDirs.AppendElement(nsCString(manifest));
} else {
unused << mAppParent->SendLoadComponentManifest(nsDependentCString(manifest));
unused << mAppParent->LoadComponentManifest(manifest);
}
}

Expand All @@ -231,10 +232,12 @@ EmbedLiteApp::StartChildThread()

mAppParent = new EmbedLiteAppThreadParent();
mAppChild = new EmbedLiteAppThreadChild(mUILoop);
mozilla::ipc::MessageChannel* parentChannel = nullptr;
mAppParent->GetEmbedIPCChannel(&parentChannel);
MessageLoop::current()->PostTask(FROM_HERE,
NewRunnableMethod(mAppChild.get(),
&EmbedLiteAppThreadChild::Init,
mAppParent->GetIPCChannel()));
parentChannel));

return true;
}
Expand Down Expand Up @@ -279,8 +282,7 @@ EmbedLiteApp::Stop()
mDestroying = true;
} else if (!mDestroying) {
mDestroying = true;
mUILoop->PostTask(FROM_HERE,
NewRunnableMethod(mAppParent.get(), &EmbedLiteAppThreadParent::SendPreDestroy));
mAppParent->PreDestroy();
} else {
NS_ASSERTION(mUILoop, "Start was not called before stop");
mUILoop->DoQuit();
Expand All @@ -307,58 +309,58 @@ EmbedLiteApp::Stop()
void
EmbedLiteApp::SetBoolPref(const char* aName, bool aValue)
{
unused << mAppParent->SendSetBoolPref(nsDependentCString(aName), aValue);
unused << mAppParent->SetBoolPref(aName, aValue);
}

void
EmbedLiteApp::SetCharPref(const char* aName, const char* aValue)
{
unused << mAppParent->SendSetCharPref(nsDependentCString(aName), nsDependentCString(aValue));
unused << mAppParent->SetCharPref(aName, aValue);
}

void
EmbedLiteApp::SetIntPref(const char* aName, int aValue)
{
unused << mAppParent->SendSetIntPref(nsDependentCString(aName), aValue);
unused << mAppParent->SetIntPref(aName, aValue);
}

void
EmbedLiteApp::LoadGlobalStyleSheet(const char* aUri, bool aEnable)
{
LOGT();
unused << mAppParent->SendLoadGlobalStyleSheet(nsDependentCString(aUri), aEnable);
unused << mAppParent->LoadGlobalStyleSheet(aUri, aEnable);
}

void
EmbedLiteApp::SendObserve(const char* aMessageName, const char16_t* aMessage)
{
LOGT("topic:%s", aMessageName);
NS_ENSURE_TRUE(mAppParent, );
unused << mAppParent->SendObserve(nsDependentCString(aMessageName), aMessage ? nsDependentString((const char16_t*)aMessage) : nsString());
unused << mAppParent->Observe(aMessageName, (const char*)aMessage);
}

void
EmbedLiteApp::AddObserver(const char* aMessageName)
{
LOGT("topic:%s", aMessageName);
unused << mAppParent->SendAddObserver(nsDependentCString(aMessageName));
unused << mAppParent->AddObserver(aMessageName);
}

void
EmbedLiteApp::RemoveObserver(const char* aMessageName)
{
LOGT("topic:%s", aMessageName);
unused << mAppParent->SendRemoveObserver(nsDependentCString(aMessageName));
unused << mAppParent->RemoveObserver(aMessageName);
}

void EmbedLiteApp::AddObservers(nsTArray<nsCString>& observersList)
{
unused << mAppParent->SendAddObservers(observersList);
unused << mAppParent->AddObservers(observersList);
}

void EmbedLiteApp::RemoveObservers(nsTArray<nsCString>& observersList)
{
unused << mAppParent->SendRemoveObservers(observersList);
unused << mAppParent->RemoveObservers(observersList);
}

EmbedLiteView*
Expand All @@ -368,7 +370,7 @@ EmbedLiteApp::CreateView(uint32_t aParent)
mViewCreateID++;
EmbedLiteView* view = new EmbedLiteView(this, mViewCreateID, aParent);
mViews[mViewCreateID] = view;
unused << mAppParent->SendCreateView(mViewCreateID, aParent);
unused << mAppParent->CreateView(mViewCreateID, aParent);
return view;
}

Expand Down Expand Up @@ -417,8 +419,7 @@ EmbedLiteApp::ViewDestroyed(uint32_t id)
mViews.erase(it);
}
if (mDestroying && mViews.empty()) {
mUILoop->PostTask(FROM_HERE,
NewRunnableMethod(mAppParent.get(), &EmbedLiteAppThreadParent::SendPreDestroy));
mAppParent->PreDestroy();
}
}

Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/EmbedLiteApp.h
Expand Up @@ -12,6 +12,7 @@
#include <map>

class MessageLoop;
class EmbedLiteAppIface;

namespace mozilla {
namespace embedlite {
Expand Down Expand Up @@ -158,7 +159,7 @@ class EmbedLiteApp
EmbedLiteUILoop* mUILoop;

RefPtr<EmbedLiteSubThread> mSubThread;
RefPtr<EmbedLiteAppThreadParent> mAppParent;
RefPtr<EmbedLiteAppIface> mAppParent;
RefPtr<EmbedLiteAppThreadChild> mAppChild;

EmbedType mEmbedType;
Expand Down
32 changes: 32 additions & 0 deletions embedding/embedlite/embedhelpers/EmbedLiteAppIface.idl
@@ -0,0 +1,32 @@
/* -*- Mode: IDL; tab-width: 4; 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"

%{C++
#include "mozilla/ipc/MessageChannel.h"
template<class T> class nsTArray;
class nsCString;
%}
[ref] native nsStringTArrayRef(nsTArray<nsCString>);
[ptr] native MessageChannelPtr(mozilla::ipc::MessageChannel);

[scriptable, uuid(f7ec7953-4e68-4b75-9c0b-f2e539598699)]
interface EmbedLiteAppIface : nsISupports
{
void LoadComponentManifest([const] in string aPath);
void SetBoolPref([const] in string aName, in boolean aValue);
void SetCharPref([const] in string aName, in string aValue);
void SetIntPref([const] in string aName, in int32_t aValue);
void LoadGlobalStyleSheet([const] in string aName, in boolean aEnable);
void Observe([const] in string aName, in string aMessage);
void AddObserver([const] in string aName);
void RemoveObserver([const] in string aName);
void AddObservers([const] in nsStringTArrayRef aNames);
void RemoveObservers([const] in nsStringTArrayRef aNames);
void CreateView(in uint32_t aViewId, in uint32_t aParentId);
void PreDestroy();
void GetEmbedIPCChannel(out MessageChannelPtr aChannel);
};
95 changes: 95 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadParent.cpp
Expand Up @@ -19,6 +19,9 @@ namespace embedlite {

static EmbedLiteAppThreadParent* sAppThreadParent = nullptr;

/* Implementation file */
NS_IMPL_ISUPPORTS(EmbedLiteAppThreadParent, EmbedLiteAppIface)

EmbedLiteAppThreadParent::EmbedLiteAppThreadParent()
: mApp(EmbedLiteApp::GetInstance())
{
Expand Down Expand Up @@ -108,6 +111,98 @@ EmbedLiteAppThreadParent::RecvObserve(const nsCString& topic,
return true;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::LoadComponentManifest(const char* aPath)
{
unused << SendLoadComponentManifest(nsDependentCString(aPath));
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::SetBoolPref(const char* aName, bool aValue)
{
unused << SendSetBoolPref(nsDependentCString(aName), aValue);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::SetCharPref(const char* aName, const char * aValue)
{
unused << SendSetCharPref(nsDependentCString(aName), nsDependentCString(aValue));
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::SetIntPref(const char* aName, int32_t aValue)
{
unused << SendSetIntPref(nsDependentCString(aName), aValue);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::LoadGlobalStyleSheet(const char* aName, bool aEnable)
{
unused << SendLoadGlobalStyleSheet(nsDependentCString(aName), aEnable);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::Observe(const char* aName, const char* aMessage)
{
unused << SendObserve(nsDependentCString(aName), aMessage ? nsDependentString((const char16_t*)aMessage) : nsString());
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::AddObserver(const char* aMessageName)
{
unused << SendAddObserver(nsDependentCString(aMessageName));
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::RemoveObserver(const char* aMessageName)
{
unused << SendRemoveObserver(nsDependentCString(aMessageName));
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::AddObservers(const nsTArray<nsCString>& observersList)
{
unused << SendAddObservers(observersList);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::RemoveObservers(const nsTArray<nsCString>& observersList)
{
unused << SendRemoveObservers(observersList);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::CreateView(uint32_t aViewId, uint32_t aParentId)
{
unused << SendCreateView(aViewId, aParentId);
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::PreDestroy()
{
mApp->GetUILoop()->PostTask(FROM_HERE,
NewRunnableMethod(this, &EmbedLiteAppThreadParent::SendPreDestroy));
return NS_OK;
}

NS_IMETHODIMP
EmbedLiteAppThreadParent::GetEmbedIPCChannel(mozilla::ipc::MessageChannel* *aChannel)
{
*aChannel = GetIPCChannel();
return NS_OK;
}

} // namespace embedlite
} // namespace mozilla

8 changes: 6 additions & 2 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadParent.h
Expand Up @@ -7,15 +7,19 @@
#define MOZ_APP_EMBED_THREAD_PARENT_H

#include "mozilla/embedlite/PEmbedLiteAppParent.h"
#include "EmbedLiteAppIface.h"

namespace mozilla {
namespace embedlite {

class EmbedLiteApp;
class EmbedLiteAppThreadParent : public PEmbedLiteAppParent
class EmbedLiteAppThreadParent : public PEmbedLiteAppParent,
public EmbedLiteAppIface
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EmbedLiteAppThreadParent)
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_EMBEDLITEAPPIFACE

// IPDL
virtual bool
RecvInitialized();
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/moz.build
Expand Up @@ -13,6 +13,7 @@ FAIL_ON_WARNINGS = True
FINAL_LIBRARY = 'xul'

XPIDL_SOURCES += [
'embedhelpers/EmbedLiteAppIface.idl',
'embedhelpers/EmbedLiteViewIface.idl',
'modules/nsIEmbedAppService.idl',
'modules/nsIEmbedLiteJSON.idl',
Expand Down

0 comments on commit 72e6b4d

Please sign in to comment.