Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions include/NativeJSRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

namespace JsRuntime {

extern std::string DEFAULT_USER_AGENT;

struct MemoryStruct
{
MemoryStruct()
Expand Down Expand Up @@ -125,12 +127,12 @@ namespace JsRuntime {
void setEnvForConsoleMode(ModuleSettings& moduleSettings);
bool runApplication(uint32_t id, std::string url);
bool runJavaScript(uint32_t id, std::string code);
uint32_t createApplication(ModuleSettings& moduleSettings, std::string userAgent) ;
uint32_t createApplication(ModuleSettings& moduleSettings, std::string userAgent = DEFAULT_USER_AGENT) ;
bool terminateApplication(uint32_t id);
std::list<ApplicationDetails> getApplications();
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
std::string getBaseUserAgent();
private:
private:
bool downloadFile(std::string& url, MemoryStruct& chunk);
void processDevConsoleRequests();
void runDeveloperConsole(ModuleSettings moduleSettings);
Expand All @@ -154,6 +156,7 @@ namespace JsRuntime {
std::map<uint32_t, ApplicationData> mContextMap;
std::vector<ApplicationRequest> gPendingRequests;
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
std::string mBaseUserAgent;
std::string mBaseUserAgent;

};
};
4 changes: 2 additions & 2 deletions src/JSRuntimeServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void JSRuntimeServer::onMessage(websocketpp::connection_hdl hdl, message_ptr msg
std::string options = jParams.getString("moduleSettings", error);
ModuleSettings moduleSettings;
moduleSettings.fromString(options);
uint32_t id = mRenderer->createApplication(moduleSettings, mRenderer->getBaseUserAgent());
uint32_t id = mRenderer->createApplication(moduleSettings);
mRenderer->runApplication(id, url);
std::ostringstream oss;
oss<< "ID : " << id;
Expand All @@ -237,7 +237,7 @@ void JSRuntimeServer::onMessage(websocketpp::connection_hdl hdl, message_ptr msg
}
ModuleSettings moduleSettings;
moduleSettings.fromString(options);
uint32_t id = mRenderer->createApplication(moduleSettings,mRenderer->getBaseUserAgent());
uint32_t id = mRenderer->createApplication(moduleSettings);
std::ostringstream oss;
oss<< "ID : " << id;
result = oss.str();
Expand Down
12 changes: 7 additions & 5 deletions src/NativeJSRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ using namespace JsRuntime;
rtThreadQueue* gUIThreadQueue = NULL;
#endif

namespace JsRuntime {
std::string DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15 ";
}

static size_t HeaderCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t downloadSize = size * nmemb;
Expand Down Expand Up @@ -92,7 +96,7 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi
return downloadSize;
}

NativeJSRenderer::NativeJSRenderer(std::string waylandDisplay): mEngine(nullptr), mRunning(true), mEnableTestFileDOMSupport(false), mEmbedThunderJS(false), mEmbedRdkWebBridge(false), mEnableWebSocketServer(false), mContextMap(), mEssosInitialized(false), mConsoleMode(false)
NativeJSRenderer::NativeJSRenderer(std::string waylandDisplay): mEngine(nullptr), mRunning(true), mEnableTestFileDOMSupport(false), mEmbedThunderJS(false), mEmbedRdkWebBridge(false), mEnableWebSocketServer(false), mContextMap(), mEssosInitialized(false), mConsoleMode(false), mBaseUserAgent(DEFAULT_USER_AGENT)
{
if (waylandDisplay.size() > 0)
{
Expand All @@ -104,9 +108,6 @@ NativeJSRenderer::NativeJSRenderer(std::string waylandDisplay): mEngine(nullptr)

const char* levelFromEnv = getenv("NATIVEJS_LOG_LEVEL");

//setting the base userAgent value
mBaseUserAgent = "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15 ";

// checking for ethan log env
#ifdef USE_ETHANLOG
NativeJSLogger::isEthanLogEnabled();
Expand Down Expand Up @@ -305,7 +306,8 @@ void NativeJSRenderer::createApplicationInternal(ApplicationRequest& appRequest)
std::stringstream uagent;
uagent << "window.navigator.userAgent = \"" << userAgent << "\";";
context->runScript(uagent.str().c_str(),true, userAgent, nullptr, true);


NativeJSLogger::log(INFO, "UserAgent set to : %s", userAgent.c_str());
NativeJSLogger::log(DEBUG, "Context created for ID: %d\n", id);
if (mExternalApplicationHandler) {
context->setExternalApplicationHandler(mExternalApplicationHandler);
Expand Down
2 changes: 1 addition & 1 deletion src/jsruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int main(int argc, char* argv[])

applicationThreads.emplace_back([renderer, url, &moduleSettings]() {
NativeJSLogger::log(INFO, "Application URL is %s\n", (url.size() ? url.c_str() : "empty"));
uint32_t id = renderer->createApplication(moduleSettings,renderer->getBaseUserAgent());
uint32_t id = renderer->createApplication(moduleSettings);
renderer->runApplication(id, url);
//renderer->runJavaScript(id,url);
#if defined(NATIVEJS_DEVELOPER_MODE)
Expand Down