Skip to content

Commit

Permalink
Switch to AppChild base
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Dec 15, 2014
1 parent 0990dc1 commit 1b42f3f
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 208 deletions.
174 changes: 6 additions & 168 deletions embedding/embedlite/embedprocess/EmbedLiteAppProcessChild.cpp
Expand Up @@ -40,9 +40,14 @@ using namespace mozilla::layers;
namespace mozilla {
namespace embedlite {

EmbedLiteAppProcessChild* EmbedLiteAppProcessChild::sSingleton;
EmbedLiteAppProcessChild*
EmbedLiteAppProcessChild::GetSingleton()
{
return static_cast<EmbedLiteAppProcessChild*>(EmbedLiteAppBaseChild::GetInstance());
}

EmbedLiteAppProcessChild::EmbedLiteAppProcessChild()
: EmbedLiteAppBaseChild(nullptr)
{
LOGT();
nsDebugImpl::SetMultiprocessMode("Child");
Expand Down Expand Up @@ -78,8 +83,6 @@ EmbedLiteAppProcessChild::Init(MessageLoop* aIOLoop,
SetTransport(aChannel);
#endif

NS_ASSERTION(!sSingleton, "only one ContentChild per child");

// Once we start sending IPC messages, we need the thread manager to be
// initialized so we can deal with the responses. Do that here before we
// try to construct the crash reporter.
Expand All @@ -91,7 +94,6 @@ EmbedLiteAppProcessChild::Init(MessageLoop* aIOLoop,
if (!Open(aChannel, aParentHandle, aIOLoop)) {
return false;
}
sSingleton = this;

return true;
}
Expand Down Expand Up @@ -120,64 +122,6 @@ EmbedLiteAppProcessChild::InitXPCOM()
unused << SendInitialized();
}

nsresult
EmbedLiteAppProcessChild::InitAppService()
{
LOGT();

nsCOMPtr<nsIComponentRegistrar> cr;
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

nsCOMPtr<nsIComponentManager> cm;
rv = NS_GetComponentManager (getter_AddRefs (cm));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

{
nsCOMPtr<nsIFactory> f = new mozilla::GenericFactory(EmbedLiteAppServiceConstructor);
if (!f) {
NS_WARNING("Unable to create factory for component");
return NS_ERROR_FAILURE;
}

nsCID appCID = NS_EMBED_LITE_APP_SERVICE_CID;
rv = cr->RegisterFactory(appCID, NS_EMBED_LITE_APP_SERVICE_CLASSNAME,
NS_EMBED_LITE_APP_CONTRACTID, f);
}

{
nsCOMPtr<nsIFactory> f = new mozilla::GenericFactory(EmbedLiteJSONConstructor);
if (!f) {
NS_WARNING("Unable to create factory for component");
return NS_ERROR_FAILURE;
}

nsCID appCID = NS_IEMBEDLITEJSON_IID;
rv = cr->RegisterFactory(appCID, NS_EMBED_LITE_JSON_SERVICE_CLASSNAME,
NS_EMBED_LITE_JSON_CONTRACTID, f);
}

return NS_OK;
}

void
EmbedLiteAppProcessChild::InitWindowWatcher()
{
// create an nsWindowCreator and give it to the WindowWatcher service
nsCOMPtr<nsIWindowCreator> creator(new WindowCreator(this));
if (!creator) {
LOGE("Out of memory");
return;
}
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
if (!wwatch) {
LOGE("Fail to get watcher service");
return;
}
LOGT("Created window watcher!");
wwatch->SetWindowCreator(creator);
}

void
EmbedLiteAppProcessChild::ActorDestroy(ActorDestroyReason aWhy)
{
Expand Down Expand Up @@ -206,112 +150,6 @@ EmbedLiteAppProcessChild::AllocPEmbedLiteViewChild(const uint32_t& id, const uin
return view;
}

bool
EmbedLiteAppProcessChild::DeallocPEmbedLiteViewChild(PEmbedLiteViewChild* actor)
{
LOGT();
EmbedLiteViewProcessChild* p = static_cast<EmbedLiteViewProcessChild*>(actor);
p->Release();
return true;
}

/*---------------------------------*/

EmbedLiteViewChildIface*
EmbedLiteAppProcessChild::GetViewByID(uint32_t aId)
{
LOGNI();
return nullptr;
}

EmbedLiteViewChildIface*
EmbedLiteAppProcessChild::GetViewByChromeParent(nsIWebBrowserChrome* aParent)
{
LOGNI();
return nullptr;
}

bool EmbedLiteAppProcessChild::CreateWindow(const uint32_t& parentId, const nsCString& uri, const uint32_t& chromeFlags, const uint32_t& contextFlags, uint32_t* createdID, bool* cancel)
{
LOGNI();
return false;
}

/*---------------------------------*/

bool
EmbedLiteAppProcessChild::RecvPreDestroy()
{
LOGT();
SendReadyToShutdown();
return true;
}

bool
EmbedLiteAppProcessChild::RecvSetBoolPref(const nsCString& aName, const bool& aValue)
{
LOGC("EmbedPrefs", "n:%s, v:%i", aName.get(), aValue);
return true;
}

bool EmbedLiteAppProcessChild::RecvSetCharPref(const nsCString& aName, const nsCString& aValue)
{
LOGC("EmbedPrefs", "n:%s, v:%s", aName.get(), aValue.get());
return true;
}

bool EmbedLiteAppProcessChild::RecvSetIntPref(const nsCString& aName, const int& aValue)
{
LOGC("EmbedPrefs", "n:%s, v:%i", aName.get(), aValue);
return true;
}

bool
EmbedLiteAppProcessChild::RecvLoadGlobalStyleSheet(const nsCString& uri, const bool& aEnable)
{
return true;
}

bool EmbedLiteAppProcessChild::RecvLoadComponentManifest(const nsCString& manifest)
{
return true;
}

bool
EmbedLiteAppProcessChild::RecvObserve(const nsCString& topic, const nsString& data)
{
LOGT("topic:%s", topic.get());
return true;
}

bool
EmbedLiteAppProcessChild::RecvAddObserver(const nsCString& topic)
{
LOGT("topic:%s", topic.get());
return true;
}

bool
EmbedLiteAppProcessChild::RecvRemoveObserver(const nsCString& topic)
{
LOGT("topic:%s", topic.get());
return true;
}

bool
EmbedLiteAppProcessChild::RecvAddObservers(const InfallibleTArray<nsCString>& observers)
{
LOGT();
return true;
}

bool
EmbedLiteAppProcessChild::RecvRemoveObservers(const InfallibleTArray<nsCString>& observers)
{
LOGT();
return true;
}

} // namespace embedlite
} // namespace mozilla

42 changes: 5 additions & 37 deletions embedding/embedlite/embedprocess/EmbedLiteAppProcessChild.h
Expand Up @@ -6,21 +6,18 @@
#ifndef MOZ_APP_EMBED_PROCESS_CHILD_H
#define MOZ_APP_EMBED_PROCESS_CHILD_H

#include "mozilla/embedlite/PEmbedLiteAppChild.h" // for PEmbedLiteAppChild
#include "mozilla/embedlite/EmbedLiteAppChildIface.h"
#include "mozilla/embedlite/EmbedLiteAppBaseChild.h"

namespace mozilla {
namespace embedlite {

class EmbedLiteViewChildIface;
class EmbedLiteAppProcessChild : public PEmbedLiteAppChild,
public EmbedLiteAppChildIface
class EmbedLiteAppProcessChild : public EmbedLiteAppBaseChild
{
public:
EmbedLiteAppProcessChild();
virtual ~EmbedLiteAppProcessChild();
nsrefcnt AddRef() { return 1; }
nsrefcnt Release() { return 1; }

static EmbedLiteAppProcessChild* GetSingleton();

bool Init(MessageLoop* aIOLoop,
base::ProcessHandle aParentHandle,
Expand All @@ -37,49 +34,20 @@ class EmbedLiteAppProcessChild : public PEmbedLiteAppChild,
nsCString vendor;
};

static EmbedLiteAppProcessChild* GetSingleton() {
return sSingleton;
}

const AppInfo& GetAppInfo() {
return mAppInfo;
}

/*--------------------------------*/
virtual EmbedLiteViewChildIface* GetViewByID(uint32_t aId);
virtual EmbedLiteViewChildIface* GetViewByChromeParent(nsIWebBrowserChrome* aParent);
virtual bool CreateWindow(const uint32_t& parentId, const nsCString& uri, const uint32_t& chromeFlags, const uint32_t& contextFlags, uint32_t* createdID, bool* cancel);


protected:
// Embed API ipdl interface
virtual bool RecvSetBoolPref(const nsCString&, const bool&) MOZ_OVERRIDE;
virtual bool RecvSetCharPref(const nsCString&, const nsCString&) MOZ_OVERRIDE;
virtual bool RecvSetIntPref(const nsCString&, const int&) MOZ_OVERRIDE;
virtual bool RecvLoadGlobalStyleSheet(const nsCString&, const bool&) MOZ_OVERRIDE;
virtual bool RecvLoadComponentManifest(const nsCString&) MOZ_OVERRIDE;
virtual PEmbedLiteViewChild* AllocPEmbedLiteViewChild(const uint32_t&, const uint32_t& parentId, const bool& isPrivateWindow) MOZ_OVERRIDE;

// IPDL protocol impl
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;

virtual bool RecvPreDestroy() MOZ_OVERRIDE;
virtual bool RecvObserve(const nsCString& topic,
const nsString& data) MOZ_OVERRIDE;
virtual bool RecvAddObserver(const nsCString&) MOZ_OVERRIDE;
virtual bool RecvRemoveObserver(const nsCString&) MOZ_OVERRIDE;
virtual bool RecvAddObservers(const InfallibleTArray<nsCString>& observers) MOZ_OVERRIDE;
virtual bool RecvRemoveObservers(const InfallibleTArray<nsCString>& observers) MOZ_OVERRIDE;

virtual PEmbedLiteViewChild* AllocPEmbedLiteViewChild(const uint32_t&, const uint32_t& parentId, const bool& isPrivateWindow) MOZ_OVERRIDE;
virtual bool DeallocPEmbedLiteViewChild(PEmbedLiteViewChild*) MOZ_OVERRIDE;

private:
void QuickExit();
void InitWindowWatcher();
nsresult InitAppService();

AppInfo mAppInfo;
static EmbedLiteAppProcessChild* sSingleton;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteAppProcessChild);
};
Expand Down
7 changes: 4 additions & 3 deletions embedding/embedlite/embedshared/EmbedLiteAppBaseChild.h
Expand Up @@ -9,14 +9,14 @@
#include "mozilla/embedlite/PEmbedLiteAppChild.h" // for PEmbedLiteAppChild
#include "nsIObserver.h" // for nsIObserver
#include "EmbedLiteAppChildIface.h"
#include "EmbedLiteViewBaseChild.h"

class EmbedLiteAppService;
class nsIWebBrowserChrome;

namespace mozilla {
namespace embedlite {

class EmbedLiteViewBaseChild;
class EmbedLiteAppBaseChild : public PEmbedLiteAppChild,
public nsIObserver,
public EmbedLiteAppChildIface
Expand Down Expand Up @@ -57,13 +57,14 @@ class EmbedLiteAppBaseChild : public PEmbedLiteAppChild,
protected:
MessageLoop* mParentLoop;
std::map<uint32_t, EmbedLiteViewBaseChild*> mWeakViewMap;

private:
void InitWindowWatcher();
nsresult InitAppService();

private:
friend class EmbedLiteViewBaseChild;
friend class EmbedLiteViewThreadChild;
friend class EmbedLiteViewProcessChild;
friend class EmbedLiteAppProcessChild;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteAppBaseChild);
};
Expand Down
45 changes: 45 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadChild.cpp
@@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 "EmbedLog.h"
#include "EmbedLiteAppThreadChild.h"

namespace mozilla {
namespace embedlite {

static EmbedLiteAppThreadChild* sAppThreadChild = nullptr;

EmbedLiteAppThreadChild*
EmbedLiteAppThreadChild::GetInstance()
{
return sAppThreadChild;
}

EmbedLiteAppThreadChild::EmbedLiteAppThreadChild(MessageLoop* aParentLoop)
: EmbedLiteAppBaseChild(aParentLoop)
{
LOGT();
sAppThreadChild = this;
}

EmbedLiteAppThreadChild::~EmbedLiteAppThreadChild()
{
LOGT();
sAppThreadChild = nullptr;
}

PEmbedLiteViewChild*
EmbedLiteAppThreadChild::AllocPEmbedLiteViewChild(const uint32_t& id, const uint32_t& parentId, const bool& isPrivateWindow)
{
LOGT("id:%u, parentId:%u", id, parentId);
EmbedLiteViewThreadChild* view = new EmbedLiteViewThreadChild(id, parentId, isPrivateWindow);
mWeakViewMap[id] = view;
view->AddRef();
return view;
}

} // namespace embedlite
} // namespace mozilla

32 changes: 32 additions & 0 deletions embedding/embedlite/embedthread/EmbedLiteAppThreadChild.h
@@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 MOZ_APP_EMBED_THREAD_CHILD_H
#define MOZ_APP_EMBED_THREAD_CHILD_H

#include "EmbedLiteAppBaseChild.h"

namespace mozilla {
namespace embedlite {

class EmbedLiteAppThreadChild : public EmbedLiteAppBaseChild
{
public:
EmbedLiteAppThreadChild(MessageLoop* aParentLoop);
static EmbedLiteAppThreadChild* GetInstance();

protected:
virtual ~EmbedLiteAppThreadChild();

virtual PEmbedLiteViewChild* AllocPEmbedLiteViewChild(const uint32_t&, const uint32_t& parentId, const bool& isPrivateWindow) MOZ_OVERRIDE;

private:
DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteAppThreadChild);
};

} // namespace embedlite
} // namespace mozilla

#endif // MOZ_APP_EMBED_THREAD_CHILD_H

0 comments on commit 1b42f3f

Please sign in to comment.