Skip to content

Commit 424674e

Browse files
trupthi1403trupthi1403
authored andcommitted
RDKEMW-7489: Adding Href support
Reason for change: Added Support for Random Num Generator, Local Storage class, Updated node-fetch file for header support Risks: Low Priority: P1
1 parent c170244 commit 424674e

15 files changed

Lines changed: 409 additions & 186 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* If not stated otherwise in this file or this component's LICENSE
3+
* file the following copyright and licenses apply:
4+
*
5+
* Copyright 2024 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
**/
19+
20+
#ifndef IEXTERNALAPPLICATION_HANDLER_H
21+
#define IEXTERNALAPPLICATION_HANDLER_H
22+
23+
#include <string>
24+
class IExternalApplicationHandler
25+
{
26+
public:
27+
virtual void runExternalApplication(std::string url, uint32_t id) = 0;
28+
};
29+
30+
#endif

include/JavaScriptContextBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <IJavaScriptContext.h>
3232
#include <IJavaScriptEngine.h>
3333
#include <ModuleSettings.h>
34+
#include <IExternalApplicationHandler.h>
35+
#include <memory>
3436

3537
//#include <JavaScriptCore/JavaScript.h>
3638

@@ -57,6 +59,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
5759
virtual void onKeyPress(struct JavaScriptKeyDetails& details);
5860
virtual void onKeyRelease(struct JavaScriptKeyDetails& details);
5961
ModuleSettings getModuleSettings();
62+
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
6063
protected:
6164
virtual void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress) = 0;
6265
virtual bool evaluateScript(const char* script, const char* name, const char *args, bool module=false) = 0;
@@ -70,6 +73,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
7073
bool mEmbedWebBridge;
7174
bool mEnableWebSockerServer;
7275
ModuleSettings mModuleSettings;
76+
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
7377
static std::string sModulesPath;
7478
static void populateModulesPath();
7579
};

include/NativeJSRenderer.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <memory>
2828
#include <IJavaScriptEngine.h>
2929
#include <IJavaScriptContext.h>
30+
#include <IExternalApplicationHandler.h>
3031
#include <ModuleSettings.h>
3132
#include <condition_variable>
3233
#include <list>
@@ -76,19 +77,19 @@ namespace JsRuntime {
7677
IJavaScriptContext* consoleContext = nullptr;
7778
ModuleSettings moduleSettings{};
7879
};
79-
80+
8081
struct ApplicationDetails{
8182
uint32_t id;
8283
std::string url;
8384
};
84-
85+
8586
enum RequestType{
8687
CREATE=0,
8788
RUN,
8889
TERMINATE,
8990
RUNSCRIPT
9091
};
91-
92+
9293
struct ApplicationRequest
9394
{
9495
ApplicationRequest(uint32_t id, RequestType requestType, std::string url="", bool enableHttp=false, bool enableXHR=false, bool enableWebSocket=false, bool enableWebSocketEnhanced=false, bool enableFetch=false, bool enableJSDOM=false, bool enableWindow=false, bool enablePlayer=false): mId(id), mRequestType(requestType), mUrl(url), mEnableHttp(enableHttp), mEnableXHR(enableXHR), mEnableWebSocket(enableWebSocket), mEnableWebSocketEnhanced(enableWebSocketEnhanced), mEnableFetch(enableFetch), mEnableJSDOM(enableJSDOM), mEnableWindow(enableWindow), mEnablePlayer(enablePlayer)
@@ -105,7 +106,7 @@ namespace JsRuntime {
105106
bool mEnableJSDOM;
106107
bool mEnableWindow;
107108
bool mEnablePlayer;
108-
};
109+
};
109110
struct ApplicationData{
110111
std::string url;
111112
IJavaScriptContext* context;
@@ -121,19 +122,20 @@ namespace JsRuntime {
121122
void run();
122123
void setEnvForConsoleMode(ModuleSettings& moduleSettings);
123124
bool runApplication(uint32_t id, std::string url);
124-
bool runJavaScript(uint32_t id, std::string code);
125-
uint32_t createApplication(ModuleSettings& moduleSettings) ;
125+
bool runJavaScript(uint32_t id, std::string code);
126+
uint32_t createApplication(ModuleSettings& moduleSettings) ;
126127
bool terminateApplication(uint32_t id);
127-
std::list<ApplicationDetails> getApplications();
128-
private:
129-
bool downloadFile(std::string& url, MemoryStruct& chunk);
128+
std::list<ApplicationDetails> getApplications();
129+
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
130+
private:
131+
bool downloadFile(std::string& url, MemoryStruct& chunk);
130132
void processDevConsoleRequests();
131133
void runDeveloperConsole(ModuleSettings moduleSettings);
132134
void createApplicationInternal(ApplicationRequest& appRequest);
133135
void runApplicationInternal(ApplicationRequest& appRequest);
134136
void terminateApplicationInternal(ApplicationRequest& appRequest);
135-
void runJavaScriptInternal(ApplicationRequest& appRequest);
136-
uint32_t createApplicationIdentifier();
137+
void runJavaScriptInternal(ApplicationRequest& appRequest);
138+
uint32_t createApplicationIdentifier();
137139
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
138140
IJavaScriptEngine* mEngine;
139141
bool mRunning;
@@ -145,13 +147,9 @@ namespace JsRuntime {
145147
bool mEnableWebSocketServer;
146148
bool mEssosInitialized;
147149
bool mConsoleMode;
148-
std::mutex mUserMutex;
150+
std::mutex mUserMutex;
149151
std::map<uint32_t, ApplicationData> mContextMap;
150-
std::vector<ApplicationRequest> gPendingRequests;
151-
};
152+
std::vector<ApplicationRequest> gPendingRequests;
153+
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
154+
};
152155
};
153-
154-
155-
156-
157-

include/jsc/JavaScriptContext.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "rtScriptJSCPrivate.h"
3737
#include <KeyListener.h>
3838
#include <KeyInput.h>
39-
4039
#include <rtHttpRequest.h>
4140
#include <JavaScriptCore/JavaScript.h>
4241
#ifdef ENABLE_JSRUNTIME_PLAYER
@@ -58,11 +57,11 @@ struct AAMPJSBindings
5857

5958
extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
6059

61-
struct PerformanceMetrics {
60+
struct PerformanceMetrics {
6261
double createApplicationStartTime=0.0;
6362
double createApplicationEndTime=0.0;
6463
double executionStartTime=0.0;
65-
double executionEndTime=0.0;
64+
double executionEndTime=0.0;
6665
double playbackStartTime=0.0;
6766
};
6867

@@ -75,12 +74,12 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
7574

7675
JavaScriptContext(JavaScriptContextFeatures& features, std::string url, IJavaScriptEngine* jsEngine);
7776
virtual ~JavaScriptContext();
78-
77+
7978
rtValue get(const char *name);
8079
rtError add(const char *name, rtValue const& val);
8180
bool has(const char *name);
8281
JSGlobalContextRef getContext() { return mContext; }
83-
82+
8483
virtual void onMetricsData (NetworkMetrics *net) override;
8584
rtMapObject* getNetworkMetricsData() const { return mNetworkMetricsData; }
8685
void dumpNetworkMetricData(NetworkMetrics *metrics, std::string appUrl);
@@ -91,6 +90,8 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
9190
void setAppdata(uint32_t id, const std::string& url);
9291
double getExecutionDuration() const;
9392

93+
void handleExternalApplication(const std::string& url);
94+
9495
private:
9596
bool evaluateScript(const char *script, const char *name, const char *args = nullptr, bool module = false);
9697
void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress);
@@ -117,6 +118,7 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
117118
rtRef<rtFunctionCallback> m_readBinaryBinding;
118119
rtRef<rtFunctionCallback> m_setVideoStartTimeBinding;
119120
rtRef<rtFunctionCallback> m_JSRuntimeDownloadMetrics;
120-
121+
rtRef<rtFunctionCallback> m_setExternalAppHandlerBinding;
122+
rtRef<rtFunctionCallback> m_getRandomValuesBinding;
121123
};
122124
#endif

include/jsc/JavaScriptUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ rtError rtHttpGetBinding(int numArgs, const rtValue* args, rtValue* result, void
7171
rtError rtReadBinaryBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
7272
rtError rtSetVideoStartTimeBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
7373
rtError rtJSRuntimeDownloadMetrics(int numArgs, const rtValue* args, rtValue* result, void* context);
74+
rtError rtSetExternalAppHandlerBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
75+
rtError rtGetRandomValuesBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
7476
JSValueRef requireCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);
7577

7678
#endif /* JAVASCRIPTMISC_H */

src/JavaScriptContextBase.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#ifdef ENABLE_ESSOS
2626
#include <EssosInstance.h>
2727
#endif
28-
#include <sys/stat.h>
28+
#include <sys/stat.h>
2929
#include <cstdlib>
3030

3131
std::string JavaScriptContextBase::sThunderJSCode = "";
3232
std::string JavaScriptContextBase::sWebBridgeCode = "";
33-
std::string JavaScriptContextBase::sModulesPath = "";
33+
std::string JavaScriptContextBase::sModulesPath = "";
3434

3535
JavaScriptContextFeatures::JavaScriptContextFeatures(bool embedThunderJS, bool embedWebBridge, bool enableWebSockerServer, ModuleSettings& moduleSettings):mEmbedThunderJS(embedThunderJS), mEmbedWebBridge(embedWebBridge), mEnableWebSockerServer(enableWebSockerServer), mModuleSettings(moduleSettings)
3636
{
@@ -125,7 +125,7 @@ bool JavaScriptContextBase::runScript(const char *script, bool isModule, std::st
125125
}
126126

127127
std::string JavaScriptContextBase::getUrl()
128-
{
128+
{
129129
return mApplicationUrl;
130130
}
131131

@@ -146,10 +146,11 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details)
146146

147147
ModuleSettings JavaScriptContextBase::getModuleSettings()
148148
{
149-
return mModuleSettings;
149+
return mModuleSettings;
150150
}
151151

152-
void JavaScriptContextBase::populateModulesPath(){
152+
void JavaScriptContextBase::populateModulesPath()
153+
{
153154
if(getenv("JSRUNTIME_MODULES_PATH"))
154155
{
155156
std::cout<<"JSRUNTIME_MODULES_PATH variable is set"<<std::endl;
@@ -164,3 +165,8 @@ void JavaScriptContextBase::populateModulesPath(){
164165
std::cout<<"Modules Path:"<<sModulesPath<<std::endl;
165166
return;
166167
}
168+
169+
void JavaScriptContextBase::setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler)
170+
{
171+
mExternalApplicationHandler = handler;
172+
}

0 commit comments

Comments
 (0)