Skip to content

Commit

Permalink
Squashed 'embedding/embedlite/' content from commit 4560773
Browse files Browse the repository at this point in the history
git-subtree-dir: embedding/embedlite
git-subtree-split: 4560773
  • Loading branch information
rainemak committed May 26, 2020
0 parents commit 28c09d1
Show file tree
Hide file tree
Showing 161 changed files with 17,923 additions and 0 deletions.
195 changes: 195 additions & 0 deletions EmbedInitGlue.h
@@ -0,0 +1,195 @@
/* -*- 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 EMBED_INIT_GLUE_H
#define EMBED_INIT_GLUE_H

#include <stdio.h>
#include "mozilla/embedlite/EmbedLiteAPI.h"

#include "nscore.h"

// getenv
#include <stdlib.h>
#include <iostream>

// XPCOMGlueStartup
#include "nsXPCOMGlue.h"

// XRE_ Functions
#include "nsXULAppAPI.h"

#if defined(XP_WIN)
#include <windows.h>
#include <stdlib.h>
#elif defined(XP_UNIX)
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif

#ifdef XP_MACOSX
#include "MacQuirks.h"
#endif

#ifdef WIN32
//TODO: make this file fully X platform
# include <windows.h>
# undef MAX_PATH
# define MAX_PATH _MAX_PATH
#else
# include <unistd.h>
# include <string.h>
# ifndef PATH_MAX
# define PATH_MAX 1024
# endif
# define MAX_PATH PATH_MAX
#endif

#define _NSR_TO_BOOL(_res) \
_res == NS_OK ? true : false;

#ifdef XRE_HAS_DLL_BLOCKLIST
XRE_SetupDllBlocklistType XRE_SetupDllBlocklist = 0;
#endif
XRE_GetEmbedLiteType XRE_GetEmbedLite = 0;
XRE_InitEmbedding2Type XRE_InitEmbedding2 = 0;
XRE_TermEmbeddingType XRE_TermEmbedding = 0;
XRE_NotifyProfileType XRE_NotifyProfile = 0;
XRE_LockProfileDirectoryType XRE_LockProfileDirectory = 0;
XRE_AddManifestLocationType XRE_AddManifestLocation = 0;
XRE_GetBinaryPathType XRE_GetBinaryPath = 0;

static inline bool IsLibXulInThePath(const char* path, std::string& xpcomPath)
{
xpcomPath = path;
#ifdef XP_UNIX
xpcomPath += "/libxul";
xpcomPath += MOZ_DLL_SUFFIX;
struct stat buf;
return !stat(xpcomPath.c_str(), &buf);
#else
xpcomPath += "/xul";
xpcomPath += MOZ_DLL_SUFFIX;
NS_ERROR("Not implemented file detection for windows");
return true;
#endif
}


bool LoadEmbedLite(int argc = 0, char** argv = 0)
{
if (XRE_GetEmbedLite) {
printf("EmbedLite already loaded\n");
return false;
}

NS_LogInit();

nsresult rv;
// find xpcom shared lib (uses GRE_HOME env var if set, current DIR, or executable binary path)
std::string xpcomPath;
char temp[MAX_PATH];
char* greHome = getenv("GRE_HOME");

if (!greHome) {
greHome = getenv("PWD");
#ifdef XP_WIN
#else
if (greHome) {
printf("greHome from PWD:%s\n", greHome);
}
#endif
} else {
printf("greHome from GRE_HOME:%s\n", greHome);
}
if (!greHome) {
printf("GRE_HOME is not defined\n");
return _NSR_TO_BOOL(NS_ERROR_FAILURE);
}
if (!IsLibXulInThePath(greHome, xpcomPath)) {
if (argv && argc) {
printf("libxul.so not in gre home or PWD:%s, check in executable path\n", greHome);
char* lastslash = strrchr(argv[0], '/');
size_t path_size = &lastslash[0] - argv[0];
strncpy(temp, argv[0], path_size);
temp[path_size] = 0;
greHome = &temp[0];
}
}
if (!IsLibXulInThePath(greHome, xpcomPath)) {
printf("libxul.so is not found, in %s\n", xpcomPath.c_str());
greHome = getenv("BUILD_GRE_HOME");
}

if (!IsLibXulInThePath(greHome, xpcomPath)) {
printf("libxul.so is not found, in %s return fail\n", xpcomPath.c_str());
return false;
}

#ifdef XP_UNIX
char* greHomeLeak = strdup(greHome);
setenv("GRE_HOME", greHomeLeak, 1);
setenv("MOZILLA_FIVE_HOME", greHomeLeak, 1);
setenv("XRE_LIBXPCOM_PATH", strdup(xpcomPath.c_str()), 1);
#elif defined XP_WIN
std::string homeStr("GRE_HOME=");
homeStr += greHome;
putenv(strdup(homeStr.c_str()));

homeStr = "MOZILLA_FIVE_HOME=";
homeStr += greHome;
putenv(strdup(homeStr.c_str()));

homeStr = "XRE_LIBXPCOM_PATH=";
homeStr += xpcomPath.c_str();
putenv(strdup(homeStr.c_str()));
#endif

#ifdef XP_MACOSX
TriggerQuirks();
#endif

{
XPCOMGlueEnablePreload();
}

// start the glue, i.e. load and link against xpcom shared lib
rv = XPCOMGlueStartup(xpcomPath.c_str());
if (NS_FAILED(rv)) {
printf("Could not start XPCOM glue:%s.\n", xpcomPath.c_str());
return _NSR_TO_BOOL(NS_ERROR_FAILURE);
}

// load XUL functions
nsDynamicFunctionLoad nsFuncs[] = {
{ "XRE_GetEmbedLite", (NSFuncPtr*)& XRE_GetEmbedLite },
#ifdef XRE_HAS_DLL_BLOCKLIST
{ "XRE_SetupDllBlocklist", (NSFuncPtr*)& XRE_SetupDllBlocklist },
#endif
{ "XRE_InitEmbedding2", (NSFuncPtr*)& XRE_InitEmbedding2},
{ "XRE_TermEmbedding", (NSFuncPtr*)& XRE_TermEmbedding},
{ "XRE_NotifyProfile", (NSFuncPtr*)& XRE_NotifyProfile},
{ "XRE_LockProfileDirectory", (NSFuncPtr*)& XRE_LockProfileDirectory},
{ "XRE_AddManifestLocation", (NSFuncPtr*)& XRE_AddManifestLocation},
{ "XRE_GetBinaryPath", (NSFuncPtr*)& XRE_GetBinaryPath},
{0, 0}
};

rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv)) {
printf("Could not load XUL functions.\n");
return _NSR_TO_BOOL(NS_ERROR_FAILURE);
}

#ifdef XRE_HAS_DLL_BLOCKLIST
XRE_SetupDllBlocklist();
#endif

return true;
}

#endif // EMBED_INIT_GLUE_H
73 changes: 73 additions & 0 deletions EmbedInputData.h
@@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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 mozilla_EmbedLite_EmbedInputData_h__
#define mozilla_EmbedLite_EmbedInputData_h__

#include <vector>

namespace mozilla {

namespace embedlite {

struct TouchPointF
{
TouchPointF(float x, float y)
: x(x)
, y(y)
{}

float x;
float y;
};

// Simplified wrapper for SingleTouchData of the InputData.h
struct TouchData
{
TouchData(int32_t identifier,
TouchPointF touchPoint,
float pressure)
: identifier(identifier)
, touchPoint(touchPoint)
, pressure(pressure)
{}

int32_t identifier;
TouchPointF touchPoint;
float pressure;
};

class EmbedTouchInput
{
public:
// Keep this sync with InputData.h
enum EmbedTouchType
{
MULTITOUCH_START,
MULTITOUCH_MOVE,
MULTITOUCH_END,
MULTITOUCH_CANCEL,

// Used as an upper bound for ContiguousEnumSerializer
MULTITOUCH_SENTINEL,
};

EmbedTouchInput(EmbedTouchType type, uint32_t timeStamp)
: type(type)
, timeStamp(timeStamp)
{}

EmbedTouchType type;
uint32_t timeStamp;

std::vector<TouchData> touches;
};

} // namespace embedlite
} // namespace mozilla

#endif // mozilla_EmbedLite_EmbedInputData_h__
20 changes: 20 additions & 0 deletions EmbedLiteAPI.h
@@ -0,0 +1,20 @@
/* -*- 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 EMBED_LITE_API_H
#define EMBED_LITE_API_H

#include "xrecore.h"

namespace mozilla {
namespace embedlite {
class EmbedLiteApp;
}
}

XRE_API(mozilla::embedlite::EmbedLiteApp*,
XRE_GetEmbedLite, ())

#endif // EMBED_LITE_API_H

0 comments on commit 28c09d1

Please sign in to comment.