const char* theme);
void dispatchJavaScriptEvent(CustomEventType eventType, void* data);
-
};
-
JSPageSession::Impl::Impl(const PluginContainerSupportPtr& support) :
- m_sessionStarted(false)
+ m_widgetHandle(0),
+ m_context(NULL),
+ m_sessionStarted(false),
+ m_objectExplorer(NULL)
{
-// DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+ // DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
LogDebug("Initializing Page Session");
m_pluginsSupport = support;
// explicit call to keep singleton's lifetime until calling destructor.
-// JsFunctionManagerSingleton::Instance();
-// JavaScriptInterfaceSingleton::Instance();
+ // JsFunctionManagerSingleton::Instance();
+ // JavaScriptInterfaceSingleton::Instance();
}
JSPageSession::Impl::~Impl()
{
- if(m_sessionStarted)
- {
+ if (m_sessionStarted) {
LogError("Must stop widget session before exit!");
stopSession();
}
LogInfo("Install Plugin '" << library->GetFileName());
-
- if(!library)
- {
+ if (!library) {
LogError("Loading library failed");
return false;
}
LogInfo("Installing requested widget features...");
std::list<std::string> allowedFeatures =
- m_pluginsSupport->getAllowedFeatures(m_widgetHandle);
+ m_pluginsSupport->getAllowedFeatures(m_widgetHandle);
PluginContainerSupport::PluginsList allowedPlugins;
auto plugin = m_pluginsSupport->getPluginForFeature(*feature);
ImplementedObjectsList implObjs =
PluginDAOReadOnly::
- getImplementedObjectsForPluginHandle(plugin->Handle.Get());
+ getImplementedObjectsForPluginHandle(plugin->Handle.Get());
FOREACH(obj, implObjs)
{
LogDebug("Processing object: " << *obj);
/* This can be optimalized, but would need extra data in database.
- There should be a list of features that are allowed to be
- installed at widget start */
+ * There should be a list of features that are allowed to be
+ * installed at widget start */
if (obj->find(".") == obj->rfind(".")) {
allowedPlugins.push_back(plugin);
LogWarning("Plugin will be added: "
LogError("Session not started");
return false;
}
-// //TODO here may be a bug. if plugin contains feature rejected and accepted
-// LogInfo("Installing feature : " << widgetFeature.name);
-// if (widgetFeature.rejected) {
-// LogWarning("This api-feature was rejected");
-// return;
-// }
-//
-// auto plugin = m_pluginsSupport->getPluginModelById(pluginHandle);
-// if (!plugin) {
-// LogError("Failed to load plugin. plugin handle: " << pluginHandle);
-// return false;
-// }
+ // //TODO here may be a bug. if plugin contains feature rejected and
+ // accepted
+ // LogInfo("Installing feature : " << widgetFeature.name);
+ // if (widgetFeature.rejected) {
+ // LogWarning("This api-feature was rejected");
+ // return;
+ // }
+ //
+ // auto plugin = m_pluginsSupport->getPluginModelById(pluginHandle);
+ // if (!plugin) {
+ // LogError("Failed to load plugin. plugin handle: " <<
+ // pluginHandle);
+ // return false;
+ // }
m_pluginsSupport->registerPluginModel(pluginHandle);
return installPluginOnDemand(
- m_pluginsSupport->getPluginModelById(pluginHandle),
- parentObject,
- context);
+ m_pluginsSupport->getPluginModelById(pluginHandle),
+ parentObject,
+ context);
}
bool JSPageSession::Impl::installPluginOnDemand(PluginModelPtr plugin,
- JavaScriptObject& parentObject,
- JSGlobalContextRef context)
+ JavaScriptObject& parentObject,
+ JSGlobalContextRef context)
{
Assert(plugin && "Plugin Model is NULL");
auto library = loadLibrary(plugin);
LogInfo("Install Plugin '" << library->GetFileName());
- if(!library)
- {
+ if (!library) {
LogError("Loading library failed");
return false;
}
- if(!(parentObject.instance))
- {
+ if (!(parentObject.instance)) {
LogError("NULL pointer value");
return false;
}
JSObjectPtr parent(new JSObject(parentObject.instance));
- if (!parent->getObject())
- {
+ if (!parent->getObject()) {
LogError("NULL pointer value");
assert(false);
return false;
parent,
context);
- if(!installationStatus)
- {
- LogError("Object Registration failed : " << (*it)->getName()
- << "; Parent object name: " << parentObject.name);
+ if (!installationStatus) {
+ LogError(
+ "Object Registration failed : " << (*it)->getName()
+ <<
+ "; Parent object name: " << parentObject.name);
return false;
}
}
}
void JSPageSession::Impl::setCustomProperties(double scaleFactor,
- const char* encodedBundle,
- const char* theme)
+ const char* encodedBundle,
+ const char* theme)
{
- LogInfo("set properties of window object " << scaleFactor << ", "
- << encodedBundle << ", " << theme);
+ LogInfo(
+ "set properties of window object " << scaleFactor << ", "
+ << encodedBundle << ", " <<
+ theme);
m_objectExplorer->getWindowPropertySupport()
->setScaleToNavigatorProperty(scaleFactor);
->setThemeToNavigatorProperty(theme);
}
-void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType, void* data)
+void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType,
+ void* data)
{
// Check if session is already started
if (!m_sessionStarted) {
{
LogInfo("Entered");
- std::string DIR_PATH = "/usr/etc/wrt/injected-javascript";
+ std::string DIR_PATH = "/usr/etc/wrt/injected-javascript";
std::string JS_EXTENSION = ".js";
DIR *dir = opendir(DIR_PATH.c_str());
if (!dir) {
- LogError("opendir(\"" << DIR_PATH << "\") error!" );
+ LogError("opendir(\"" << DIR_PATH << "\") error!");
return;
}
- struct dirent* libdir;
+ int return_code;
+ struct dirent libdir;
+ struct dirent* result;
std::list<std::string> jsFiles;
// make file list from DIR_PATH
- while ((libdir = readdir(dir)) != 0)
- {
- if (strncmp(libdir->d_name, ".", 2) == 0 ||
- strncmp(libdir->d_name, "..", 3) == 0)
+ for (return_code = readdir_r(dir, &libdir, &result);
+ result != NULL && return_code == 0;
+ return_code = readdir_r(dir, &libdir, &result)) {
+ if (strncmp(libdir.d_name, ".", 2) == 0 ||
+ strncmp(libdir.d_name, "..", 3) == 0)
{
continue;
}
std::string filepath = DIR_PATH;
filepath += "/";
- filepath += libdir->d_name;
+ filepath += libdir.d_name;
std::string lowercase = filepath;
std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
towlower);
- if( lowercase.rfind(JS_EXTENSION) == std::string::npos ||
+ if (lowercase.rfind(JS_EXTENSION) == std::string::npos ||
lowercase.length() !=
lowercase.rfind(JS_EXTENSION) + JS_EXTENSION.length() )
{
LogInfo("Added : " << filepath);
jsFiles.push_back(filepath);
}
+ if (0 != return_code)
+ LogError("Error while reading directory.");
closedir(dir);
-
FOREACH(it, jsFiles)
{
LogDebug("load file : " << (*it));
std::string content;
std::ifstream fin(it->c_str());
- while(fin.good())
- {
+ while (fin.good()) {
string line;
std::getline(fin, line);
content += line + "\n";
fin.close();
// execute
- if(!content.empty())
- {
+ if (!content.empty()) {
JSValueRef exception = NULL;
JSStringRef script =
JSStringCreateWithUTF8CString(content.c_str());
JSStringRelease(script);
- if(exception)
- {
+ if (exception) {
LogDebug("Exception Occured while injecting javascript "
- "file. : " << *it);
+ "file. : " << *it);
JSStringRef exceptionJSString =
JSValueToStringCopy(m_context, exception, NULL);
exceptionString, size);
LogDebug("Exception : " << exceptionString);
- delete [] exceptionString;
+ delete[] exceptionString;
JSStringRelease(exceptionJSString);
- }
+ }
}
}
}
void JSPageSession::Impl::startSession(int widgetHandle,
- JSGlobalContextRef context,
- double scaleFactor,
- const char* encodedBundle,
- const char* theme)
+ JSGlobalContextRef context,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
{
LogInfo("Starting widget session...");
LogInfo("Widget session stopped.");
}
-
void JSPageSession::Impl::unloadPluginsFromSession()
{
LogDebug("Unload plugins from session");
m_objectExplorer = NULL;
}
-
-
-
void JSPageSession::Impl::performLibrariesUnload()
{
#if 0
PluginPtr JSPageSession::Impl::loadLibrary(PluginModelPtr& pluginModel)
{
PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
- if (!pluginLib)
- {
+ if (!pluginLib) {
std::string path = pluginModel->LibraryPath.Get() +
- std::string(LIBRARY_PATH_SEPARATOR) +
- pluginModel->LibraryName.Get();
+ std::string(LIBRARY_PATH_SEPARATOR) +
+ pluginModel->LibraryName.Get();
pluginLib = Plugin::LoadFromFile(path);
- if (!pluginLib)
- {
+ if (!pluginLib) {
LogError("Loading library failed");
- } else
- {
+ } else {
pluginModel->LibraryInstance.Set(pluginLib);
LogDebug("On widget start");
pluginLib->OnFrameLoad(*context);
}
}
- }
- else
- {
+ } else {
LogDebug("Get from LibraryInstance");
LogDebug("On widget start");
// This is first time for this plugin, start widget Session
return pluginLib;
}
-
void JSPageSession::Impl::loadFrame(JSGlobalContextRef context)
{
LogDebug("Load a frame");
m_objectExplorer->unloadFrame(context);
}
-
void JSPageSession::startSession(int widgetHandle,
- JSGlobalContextRef ctx,
- double scaleFactor,
- const char* encodedBundle,
- const char* theme)
+ JSGlobalContextRef ctx,
+ double scaleFactor,
+ const char* encodedBundle,
+ const char* theme)
{
m_impl->startSession(widgetHandle, ctx, scaleFactor, encodedBundle, theme);
}
}
void JSPageSession::setCustomProperties(double scaleFactor,
- const char* encodedBundle,
- const char* theme)
+ const char* encodedBundle,
+ const char* theme)
{
m_impl->setCustomProperties(scaleFactor, encodedBundle, theme);
}
-void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType, void* data)
+void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType,
+ void* data)
{
m_impl->dispatchJavaScriptEvent(eventType, data);
}
}
JSPageSession::JSPageSession(const PluginContainerSupportPtr& containerSupport)
- : m_impl(new JSPageSession::Impl(containerSupport))
-{
-}
+ :
+ m_impl(new JSPageSession::Impl(containerSupport))
+{}
JSPageSession::~JSPageSession()
-{
-}
+{}