* limitations under the License.
*/
#include "wrt-client.h"
+#include <aul.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <appcore-efl.h>
+#include <appcore-common.h>
#include <cstdlib>
+#include <cstdio>
#include <string>
-#include <fstream>
-#include <iostream>
-#include <sys/stat.h>
-#include <sys/utsname.h>
-#include <unistd.h>
-#include <vconf.h>
-#include <dpl/optional.h>
-#include <dpl/scoped_free.h>
-#include <dpl/wrt-dao-ro/global_config.h>
-#include <dpl/localization/localization_utils.h>
+#include <dpl/log/log.h>
#include <dpl/optional_typedefs.h>
-#include <dpl/semaphore.h>
#include <dpl/exception.h>
-#include <signal.h>
#include <application_data.h>
-#include <window_data.h>
-
-using namespace WrtDB;
-
-namespace { // anonymous
-const char* PLUGIN_INSTALL_SEMAPHORE = "/.wrt_plugin_install_lock";
-const char* MACHINE_NAME_EMUL = "emulated"; // "arch_emulated"
-
-template<typename Predicate>
-DPL::OptionalInt findWidgetHandleForPredicate(const Predicate &predicate)
-{
- int count;
- int *handles;
-
- if (wrt_has_succeded(wrt_get_widget_list(&count, &handles))) {
- for (int i = 0; i < count; ++i) {
- wrt_widget_info *info;
-
- // Get widget infor for handle
- if (wrt_has_succeded(wrt_get_widget_info(handles[i], &info))) {
- if (predicate(info)) {
- // Free widget name
- wrt_free_widget_info(info);
-
- // Done
- return DPL::OptionalInt(handles[i]);
- }
-
- // Free widget info
- wrt_free_widget_info(info);
- } else {
- LogWarning("ReturnStatus::Faileded to get widget name");
- }
- }
-
- // Free list
- wrt_free_widget_list(handles);
- } else {
- LogWarning("ReturnStatus::Faileded to get widget handle list");
- }
-
- return DPL::OptionalInt::Null;
-}
-
-struct WidgetNamePredicate
-{
- private:
- std::string m_name;
-
- public:
- WidgetNamePredicate(const std::string &name) : m_name(name) {}
-
- bool operator()(wrt_widget_info *info) const
- {
- return info->name && m_name == info->name;
- }
-};
-
-struct WidgetGUIDPredicate
-{
- private:
- std::string m_guid;
-
- public:
- WidgetGUIDPredicate(const std::string &guid) : m_guid(guid) {}
-
- bool operator()(wrt_widget_info *info) const
- {
- return info->id && m_guid == info->id;
- }
-};
-
-DPL::OptionalInt findWidgetHandleForName(const std::string &widgetName)
-{
- return findWidgetHandleForPredicate(WidgetNamePredicate(widgetName));
-}
-
-DPL::OptionalInt findWidgetHandleForGUID(const std::string &widgetName)
-{
- return findWidgetHandleForPredicate(WidgetGUIDPredicate(widgetName));
-}
-
-struct PluginInstallerData
-{
- void* wrtClient;
- std::string pluginPath;
-};
-
-struct PluginUtils
-{
- struct FileState
- {
- enum Type
- {
- FILE_EXISTS,
- FILE_EXISTS_NOT_REGULAR,
- FILE_NOT_EXISTS,
- FILE_READ_DATA_ERROR
- };
- };
-
- static bool lockPluginInstallation()
- {
- Try {
- DPL::Semaphore lock(PLUGIN_INSTALL_SEMAPHORE);
- return true;
- }
- Catch(DPL::Semaphore::Exception::CreateFailed){
- LogError("create");
- return false;
- }
- Catch(DPL::Semaphore::Exception::Base){
- return false;
- }
- }
-
- static bool unlockPluginInstallation()
- {
- Try {
- DPL::Semaphore::Remove(PLUGIN_INSTALL_SEMAPHORE);
- return true;
- }
- Catch(DPL::Semaphore::Exception::Base){
- return false;
- }
- }
-
- static bool checkPluginInstallationRequired()
- {
- std::string installRequest =
- std::string(GlobalConfig::GetPluginInstallInitializerName());
-
- FileState::Type installationRequest = checkFile(installRequest);
-
- switch (installationRequest) {
- case FileState::FILE_EXISTS:
- return true;
- case FileState::FILE_NOT_EXISTS:
- return false;
- default:
- LogWarning("Opening installation request file failed");
- return false;
- }
- }
-
- static bool removeInstallationRequiredFlag()
- {
- std::string installRequest =
- std::string(GlobalConfig::GetPluginInstallInitializerName());
-
- return removeFile(installRequest);
- }
-
- //checks if file exists and is regular file
- static FileState::Type checkFile(const std::string& filename)
- {
- struct stat tmp;
-
- if (-1 == stat(filename.c_str(), &tmp)) {
- if (ENOENT == errno) {
- return FileState::FILE_NOT_EXISTS;
- }
- return FileState::FILE_READ_DATA_ERROR;
- } else if (!S_ISREG(tmp.st_mode)) {
- return FileState::FILE_EXISTS_NOT_REGULAR;
- }
- return FileState::FILE_EXISTS;
- }
-
- static bool removeFile(const std::string& filename)
- {
- if (0 != unlink(filename.c_str())) {
- return false;
- }
-
- return true;
- }
-};
-} // namespace anonymous
+#include <core_module.h>
+#include <localization_setting.h>
+#include <widget_deserialize_model.h>
+#include <EWebKit2.h>
+#include <dpl/localization/w3c_file_localization.h>
+#include <dpl/localization/LanguageTagsProvider.h>
+#include <popup-runner/PopupInvoker.h>
+#include <vconf.h>
+#include "auto_rotation_support.h"
+
+#include <process_pool.h>
+#include <process_pool_launchpad_util.h>
+
+#include "client_command_line_parser.h"
+#include "client_ide_support.h"
+#include "client_security_support.h"
+#include "client_service_support.h"
+#include "client_submode_support.h"
+
+//W3C PACKAGING enviroment variable name
+#define W3C_DEBUG_ENV_VARIABLE "DEBUG_LOAD_FINISH"
+
+// window signal callback
+const char *EDJE_SHOW_PROGRESS_SIGNAL = "show,progress,signal";
+const char *EDJE_HIDE_PROGRESS_SIGNAL = "hide,progress,signal";
+const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
+const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
+const std::string VIEWMODE_TYPE_WINDOWED = "windowed";
+char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
+const char* const BUNDLE_PATH = LIBDIR_PREFIX "/usr/lib/libwrt-injected-bundle.so";
+const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
+const unsigned int UID_ROOT = 0;
+
+// process pool
+const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
+static Ewk_Context* s_preparedEwkContext = NULL;
+static WindowData* s_preparedWindowData = NULL;
+static int app_argc = 0;
+static char** app_argv = NULL;
+
+// env
+const char* const HOME = "HOME";
+const char* const APP_HOME_PATH = "/opt/home/app";
+const char* const ROOT_HOME_PATH = "/opt/home/root";
WrtClient::WrtClient(int argc, char **argv) :
Application(argc, argv, "wrt-client", false),
DPL::TaskDecl<WrtClient>(this),
- m_packagePath(),
- m_handle(-1),
m_launched(false),
+ m_initializing(false),
m_initialized(false),
- m_sdkLauncherPid(0),
m_debugMode(false),
- m_debuggerPort(0),
- m_developerMode(false),
- m_complianceMode(false),
- m_numPluginsToInstall(0),
m_returnStatus(ReturnStatus::Succeeded),
- m_startupPluginInstallation(false)
+ m_widgetState(WidgetState::WidgetState_Stopped),
+ m_initialViewMode(VIEWMODE_TYPE_MAXIMIZED),
+ m_currentViewMode(VIEWMODE_TYPE_MAXIMIZED),
+ m_isWebkitFullscreen(false),
+ m_isFullscreenByPlatform(false),
+ m_submodeSupport(new ClientModule::SubmodeSupport())
{
Touch();
LogDebug("App Created");
void WrtClient::OnStop()
{
- LogInfo("Stopping Dummy Client");
+ LogDebug("Stopping Dummy Client");
}
-
void WrtClient::OnCreate()
{
- LogInfo("On Create");
+ LogDebug("On Create");
+ ADD_PROFILING_POINT("OnCreate callback", "point");
+ ewk_init();
}
-
void WrtClient::OnResume()
{
- wrt_resume_widget(m_handle, NULL, staticWrtResumeStatusCallback);
+ if (m_widgetState != WidgetState_Suspended) {
+ LogWarning("Widget is not suspended, resuming was skipped");
+ return;
+ }
+ m_widget->Resume();
+ m_widgetState = WidgetState_Running;
}
-
void WrtClient::OnPause()
{
- wrt_suspend_widget(m_handle, NULL, staticWrtSuspendStatusCallback);
+ if (m_widgetState != WidgetState_Running) {
+ LogWarning("Widget is not running to be suspended");
+ return;
+ }
+ if (m_submodeSupport->isNeedTerminateOnSuspend()) {
+ LogDebug("Current mode cannot support suspend");
+ elm_exit();
+ return;
+ }
+ m_widget->Suspend();
+ m_widgetState = WidgetState_Suspended;
}
void WrtClient::OnReset(bundle *b)
// bundle argument is freed after OnReset() is returned
// So bundle duplication is needed
ApplicationDataSingleton::Instance().setBundle(bundle_dup(b));
+ ApplicationDataSingleton::Instance().setEncodedBundle(b);
- if (m_launched == true) {
- wrt_reset_widget(m_handle, NULL, staticWrtResetStatusCallback);
+ if (true == m_initializing) {
+ LogDebug("can not handle reset event");
+ return;
+ }
+ if (true == m_launched) {
+ if (m_widgetState == WidgetState_Stopped) {
+ LogError("Widget is not running to be reset");
+ return;
+ }
+ m_widget->Reset();
+ m_widgetState = WidgetState_Running;
} else {
- setStep();
+ m_tizenId =
+ ClientModule::CommandLineParser::getTizenId(m_argc, m_argv);
+ if (m_tizenId.empty()) {
+ showHelpAndQuit();
+ } else {
+ setDebugMode(b);
+ setStep();
+ }
}
+
+ // low memory callback set
+ appcore_set_event_callback(
+ APPCORE_EVENT_LOW_MEMORY,
+ WrtClient::appcoreLowMemoryCallback,
+ this);
}
void WrtClient::OnTerminate()
{
LogDebug("Wrt Shutdown now");
- wrt_shutdown();
+ shutdownStep();
}
void WrtClient::showHelpAndQuit()
"options too.\n"
" -h, --help show this help\n"
" -l, --launch "
- "launch widget with given ID\n"
+ "launch widget with given tizen ID\n"
+ " -t, --tizen "
+ "launch widget with given tizen ID\n"
"\n");
Quit();
void WrtClient::setStep()
{
- LogInfo("setStep");
+ LogDebug("setStep");
AddStep(&WrtClient::initStep);
+ AddStep(&WrtClient::launchStep);
+ AddStep(&WrtClient::shutdownStep);
- std::string arg = m_argv[0];
+ m_initializing = true;
- if (arg.empty()) {
- return showHelpAndQuit();
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
+}
+
+void WrtClient::setDebugMode(bundle* b)
+{
+ m_debugMode = ClientModule::IDESupport::getDebugMode(b);
+ LogDebug("debug mode : " << m_debugMode);
+}
+
+void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
+{
+ LogDebug("Executing next step");
+ NextStep();
+}
+
+void WrtClient::initStep()
+{
+ LogDebug("");
+ if (WRT::CoreModuleSingleton::Instance().Init()) {
+ m_initialized = true;
+ } else {
+ m_returnStatus = ReturnStatus::Failed;
+ SwitchToStep(&WrtClient::shutdownStep);
}
- installNewPlugins();
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
+}
- setSdkLauncherDebugData();
+void WrtClient::loadFinishCallback(Evas_Object* webview)
+{
+ ADD_PROFILING_POINT("loadFinishCallback", "start");
- if (arg.find("wrt-dummy-client") != std::string::npos ||
- arg.find("wrt-client") != std::string::npos)
+ // Splash screen
+ if (m_splashScreen && m_splashScreen->isShowing())
{
- if (m_argc <= 1) {
- return showHelpAndQuit();
- }
+ m_splashScreen->stopSplashScreenBuffered();
+ }
- arg = m_argv[1];
+ LogDebug("Post result of launch");
- if (arg == "-h" || arg == "--help") {
- if (m_argc != 2) {
- return showHelpAndQuit();
- }
+ //w3c packaging test debug (message on 4>)
+ const char * makeScreen = getenv(W3C_DEBUG_ENV_VARIABLE);
+ if (makeScreen != NULL && strcmp(makeScreen, "1") == 0) {
+ FILE* doutput = fdopen(4, "w");
+ fprintf(doutput, "didFinishLoadForFrameCallback: ready\n");
+ fclose(doutput);
+ }
- // Just show help
- showHelpAndQuit();
- } else if (arg == "-l" || arg == "--launch") {
- if (m_argc != 3) {
- return showHelpAndQuit();
- }
+ if (webview) {
+ LogDebug("Launch succesfull");
- m_handle = atoi(m_argv[2]);
- AddStep(&WrtClient::launchStep);
- AddStep(&WrtClient::finalizeLaunchStep);
- AddStep(&WrtClient::killWidgetStep);
- } else {
- return showHelpAndQuit();
- }
+ m_launched = true;
+ m_initializing = false;
+ setlinebuf(stdout);
+ ADD_PROFILING_POINT("loadFinishCallback", "stop");
+ printf("launched\n");
+ fflush(stdout);
} else {
- // Launch widget based on application basename
- size_t pos = arg.find_last_of('/');
+ printf("failed\n");
- if (pos != std::string::npos) {
- arg = arg.erase(0, pos + 1);
- }
+ m_returnStatus = ReturnStatus::Failed;
+ //shutdownStep
+ DPL::Event::ControllerEventHandler<NextStepEvent>::
+ PostEvent(NextStepEvent());
+ }
- if (sscanf(arg.c_str(), "%i", &m_handle) != 1) {
- printf("failed: invalid widget handle\n");
- return showHelpAndQuit();
+ if (m_debugMode) {
+ unsigned int portNum =
+ ewk_view_inspector_server_start(m_widget->GetCurrentWebview(), 0);
+ LogDebug("Port for inspector : " << portNum);
+ bool ret = ClientModule::IDESupport::sendReply(
+ ApplicationDataSingleton::Instance().getBundle(),
+ portNum);
+ if (!ret) {
+ LogWarning("Fail to send reply");
}
+ }
- LogDebug("Widget Id: " << m_handle << " (" << arg << ")");
+ ApplicationDataSingleton::Instance().freeBundle();
+}
- AddStep(&WrtClient::launchStep);
- AddStep(&WrtClient::finalizeLaunchStep);
- AddStep(&WrtClient::killWidgetStep);
+void WrtClient::resetCallback(bool result)
+{
+ if (!result) {
+ LogDebug("Fail to handle reset event");
+ // free bundle data
+ ApplicationDataSingleton::Instance().freeBundle();
}
+}
- AddStep(&WrtClient::shutdownStep);
-
- DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
+void WrtClient::progressStartedCallback()
+{
+ if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
+ m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
+ {
+ m_windowData->signalEmit(Layer::MAIN_LAYOUT,
+ EDJE_SHOW_PROGRESS_SIGNAL,
+ "");
+ m_windowData->updateProgress(0);
+ }
}
-void WrtClient::setSdkLauncherDebugData()
+void WrtClient::loadProgressCallback(Evas_Object* /*webview*/, double value)
{
- LogDebug("setSdkLauncherDebugData");
+ if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
+ m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
+ {
+ m_windowData->updateProgress(value);
+ }
+}
- /* check bundle from sdk launcher */
- bundle *bundleFromSdkLauncher;
- bundleFromSdkLauncher = bundle_import_from_argv(m_argc, m_argv);
- const char *bundle_debug = bundle_get_val(bundleFromSdkLauncher, "debug");
- const char *bundle_pid = bundle_get_val(bundleFromSdkLauncher, "pid");
- if (bundle_debug != NULL && bundle_pid != NULL) {
- if (strcmp(bundle_debug, "true") == 0) {
- m_debugMode = true;
- m_sdkLauncherPid = atoi(bundle_pid);
- } else {
- m_debugMode = false;
- }
+void WrtClient::progressFinishCallback()
+{
+ if (m_settingList->getProgressBarPresence() == ProgressBar_Enable ||
+ m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
+ {
+ m_windowData->signalEmit(Layer::MAIN_LAYOUT,
+ EDJE_HIDE_PROGRESS_SIGNAL,
+ "");
}
}
-void WrtClient::OnEventReceived(const QuitEvent &/* event */)
+void WrtClient::webkitExitCallback()
{
- LogDebug("Quiting");
+ LogDebug("window close called, terminating app");
+ SwitchToStep(&WrtClient::shutdownStep);
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
+}
- if (m_launched) {
- LogDebug("Killing widgets first");
- SwitchToStep(&WrtClient::killWidgetStep);
- DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
- } else if (m_initialized) {
- LogDebug("Wrt Shutdown now");
- SwitchToStep(&WrtClient::shutdownStep);
- DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(NextStepEvent());
- } else {
- LogDebug("Quiting application");
- return Quit();
- }
+void WrtClient::webCrashCallback()
+{
+ LogError("webProcess crashed");
+ SwitchToStep(&WrtClient::shutdownStep);
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
}
-void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
+void WrtClient::enterFullscreenCallback(Evas_Object* /*obj*/,
+ bool isFullscreenByPlatform)
{
- LogDebug("Executing next step");
- NextStep();
+ // enter fullscreen
+ m_windowData->toggleFullscreen(true);
+ m_currentViewMode = VIEWMODE_TYPE_FULLSCREEN;
+ m_isWebkitFullscreen = true;
+ if (isFullscreenByPlatform) {
+ m_isFullscreenByPlatform = true;
+ }
}
-void WrtClient::initStep()
+void WrtClient::exitFullscreenCallback(Evas_Object* /*obj*/)
{
- wrt_init(this, staticWrtInitCallback);
+ // exit fullscreen
+ m_windowData->toggleFullscreen(false);
+ m_currentViewMode = m_initialViewMode;
+ m_isWebkitFullscreen = false;
+ m_isFullscreenByPlatform = false;
}
void WrtClient::launchStep()
{
+ ADD_PROFILING_POINT("launchStep", "start");
LogDebug("Launching widget ...");
- WrtClientUserData *userData = new WrtClientUserData;
- userData->This = this;
- userData->pid = new unsigned long(getpid());
- userData->debugMode = this->m_debugMode;
+ ADD_PROFILING_POINT("getRunnableWidgetObject", "start");
+ m_widget = WRT::CoreModuleSingleton::Instance()
+ .getRunnableWidgetObject(m_tizenId);
+ ADD_PROFILING_POINT("getRunnableWidgetObject", "stop");
- wrt_launch_widget(m_handle,
- userData->pid,
- NULL,
- userData,
- &staticWrtLaunchWidgetCallback);
-}
+ if (!m_widget) {
+ LogError("RunnableWidgetObject is NULL, stop launchStep");
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
+ return;
+ }
-void WrtClient::launchNameStep()
-{
- LogDebug("Launching name widget ...");
+ if (m_widgetState == WidgetState_Running) {
+ LogWarning("Widget already running, stop launchStep");
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
+ return;
+ }
- DPL::OptionalInt handle = findWidgetHandleForName(m_name);
+ if (m_widgetState == WidgetState_Authorizing) {
+ LogWarning("Widget already authorizing, stop launchStep");
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
+ return;
+ }
- if (!handle) {
- printf("failed: widget name not found\n");
+ m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
+ WrtDB::WidgetSettings widgetSettings;
+ m_dao->getWidgetSettings(widgetSettings);
+ m_settingList.reset(new WidgetSettingList(widgetSettings));
+ m_submodeSupport->initialize(DPL::FromASCIIString(m_tizenId));
- m_returnStatus = ReturnStatus::Failed;
- DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
- return;
+ DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
+ if (!defloc.IsNull()) {
+ LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
+ *defloc);
}
- WrtClientUserData *userData = new WrtClientUserData;
- userData->This = this;
- userData->pid = new unsigned long(getpid());
- userData->debugMode = this->m_debugMode;
+ setInitialViewMode();
- wrt_launch_widget(*handle,
- userData->pid,
- NULL,
- userData,
- &staticWrtLaunchWidgetCallback);
-}
+ /* remove language change callback */
+ /*
+ LocalizationSetting::SetLanguageChangedCallback(
+ languageChangedCallback, this);
+ */
-void WrtClient::launchGUIDStep()
-{
- LogDebug("Launching GUID widget ...");
+ ADD_PROFILING_POINT("CreateWindow", "start");
+ if (s_preparedWindowData == NULL) {
+ m_windowData.reset(new WindowData(static_cast<unsigned long>(getpid()), true));
+ } else {
+ m_windowData.reset(s_preparedWindowData);
+ s_preparedWindowData = NULL;
+ }
+ ADD_PROFILING_POINT("CreateWindow", "stop");
+ if (!m_windowData->initScreenReaderSupport(
+ m_settingList->getAccessibility() == Accessibility_Enable))
+ {
+ LogWarning("Fail to set screen reader support set");
+ }
- DPL::OptionalInt handle = findWidgetHandleForGUID(m_name);
+ // rotate window to initial value
+ setWindowInitialOrientation();
+ setCtxpopupItem();
- if (!handle) {
- printf("failed: widget GUID not found\n");
+ WRT::UserDelegatesPtr cbs(new WRT::UserDelegates);
- m_returnStatus = ReturnStatus::Failed;
- DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
+ ADD_PROFILING_POINT("Create splash screen", "start");
+ DPL::OptionalString splashImgSrc = m_dao->getSplashImgSrc();
+ if (!splashImgSrc.IsNull())
+ {
+ m_splashScreen.reset(
+ new SplashScreenSupport(
+ m_windowData->getEvasObject(Layer::WINDOW),
+ (DPL::ToUTF8String(*splashImgSrc)).c_str(),
+ m_currentViewMode != VIEWMODE_TYPE_FULLSCREEN,
+ m_settingList->getRotationValue() == Screen_Landscape));
+ m_splashScreen->startSplashScreen();
+ }
+ ADD_PROFILING_POINT("Create splash screen", "stop");
+
+ DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
+ if (!m_widget->PrepareView(
+ DPL::ToUTF8String(*startUrl),
+ m_windowData->getEvasObject(Layer::WINDOW),
+ s_preparedEwkContext))
+ {
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
return;
}
+ // send rotate information to ewk
+ setEwkInitialOrientation();
+
+ //you can't show window with splash screen before PrepareView
+ //ewk_view_add_with_context() in viewLogic breaks window
+ m_windowData->init();
+ m_windowData->postInit();
+
+#if X11
+ // sub-mode support
+ if (m_submodeSupport->isInlineMode()) {
+ if (m_submodeSupport->transientWindow(
+ elm_win_xwindow_get(
+ m_windowData->getEvasObject(Layer::WINDOW))))
+ {
+ LogDebug("Success to set submode");
+ } else {
+ LogWarning("Fail to set submode");
+ }
+ }
+#endif
+ m_windowData->smartCallbackAdd(Layer::FOCUS,
+ "focused",
+ focusedCallback,
+ this);
+ m_windowData->smartCallbackAdd(Layer::FOCUS,
+ "unfocused",
+ unfocusedCallback,
+ this);
+
+ WrtDB::WidgetLocalizedInfo localizedInfo =
+ W3CFileLocalization::getLocalizedInfo(m_dao);
+ std::string name = "";
+ if (!(localizedInfo.name.IsNull())) {
+ name = DPL::ToUTF8String(*(localizedInfo.name));
+ }
+ elm_win_title_set(m_windowData->getEvasObject(Layer::WINDOW),
+ name.c_str());
+
+ // window show
+ evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
- WrtClientUserData *userData = new WrtClientUserData;
- userData->This = this;
- userData->pid = new unsigned long(getpid());
- userData->debugMode = this->m_debugMode;
+ initializeWindowModes();
- wrt_launch_widget(*handle,
- userData->pid,
- NULL,
- userData,
- &staticWrtLaunchWidgetCallback);
+ m_widgetState = WidgetState_Authorizing;
+ if (!m_widget->CheckBeforeLaunch()) {
+ LogError("CheckBeforeLaunch failed, stop launchStep");
+ DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
+ NextStepEvent());
+ return;
+ }
+ LogDebug("Widget launch accepted. Entering running state");
+ m_widgetState = WidgetState_Running;
+
+ cbs->progressStarted = DPL::MakeDelegate(this, &WrtClient::progressStartedCallback);
+ cbs->progress = DPL::MakeDelegate(this, &WrtClient::loadProgressCallback);
+ cbs->progressFinish = DPL::MakeDelegate(this, &WrtClient::progressFinishCallback);
+ cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
+ cbs->reset = DPL::MakeDelegate(this, &WrtClient::resetCallback);
+ cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
+ cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
+ cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
+ cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
+ cbs->enterFullscreen = DPL::MakeDelegate(this, &WrtClient::enterFullscreenCallback);
+ cbs->exitFullscreen = DPL::MakeDelegate(this, &WrtClient::exitFullscreenCallback);
+ cbs->setOrientation = DPL::MakeDelegate(this, &WrtClient::setWindowOrientation);
+ cbs->hwkey = DPL::MakeDelegate(this, &WrtClient::hwkeyCallback);
+
+ m_widget->SetUserDelegates(cbs);
+ m_widget->Show();
+
+ ADD_PROFILING_POINT("launchStep", "stop");
}
-void WrtClient::killWidgetStep()
+void WrtClient::initializeWindowModes()
{
- LogDebug("Killing widget ...");
- wrt_kill_widget(m_handle, this, &staticWrtStatusCallback);
+ Assert(m_windowData);
+ bool backbutton =
+ (m_settingList->getBackButtonPresence() == BackButton_Enable ||
+ m_currentViewMode == VIEWMODE_TYPE_WINDOWED);
+ m_windowData->setViewMode(m_currentViewMode == VIEWMODE_TYPE_FULLSCREEN,
+ backbutton);
}
-void WrtClient::finalizeLaunchStep()
+Eina_Bool WrtClient::naviframeBackButtonCallback(void* data,
+ Elm_Object_Item* /*it*/)
{
- LogDebug("Finalizing Launching widget ...");
- m_launched = true;
+ LogDebug("BackButtonCallback");
+ Assert(data);
+
+ WrtClient* This = static_cast<WrtClient*>(data);
+ This->m_widget->Backward();
+ return EINA_FALSE;
}
-void WrtClient::shutdownStep()
+int WrtClient::appcoreLowMemoryCallback(void* /*data*/)
{
- LogDebug("Closing Wrt connection ...");
- wrt_shutdown();
- m_initialized = false;
- DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
+ LogDebug("appcoreLowMemoryCallback");
+ //WrtClient* This = static_cast<WrtClient*>(data);
+
+ // TODO call RunnableWidgetObject API regarding low memory
+ // The API should be implemented
+
+ // temporary solution because we have no way to get ewk_context from runnable object.
+ if (s_preparedEwkContext)
+ {
+ ewk_context_cache_clear(s_preparedEwkContext);
+ ewk_context_notify_low_memory(s_preparedEwkContext);
+ }
+
+ return 0;
}
-void WrtClient::setDeveloperModeStep()
+void WrtClient::setInitialViewMode(void)
{
- LogDebug("Set developer mode...");
- wrt_set_developer_mode(m_developerMode,
- &staticSetDeveloperModeCallback,
- this);
+ Assert(m_dao);
+ WrtDB::WindowModeList windowModes = m_dao->getWindowModes();
+ FOREACH(it, windowModes) {
+ std::string viewMode = DPL::ToUTF8String(*it);
+ switch(viewMode[0]) {
+ case 'f':
+ if (viewMode == VIEWMODE_TYPE_FULLSCREEN) {
+ m_initialViewMode = viewMode;
+ m_currentViewMode = m_initialViewMode;
+ break;
+ }
+ break;
+ case 'm':
+ if (viewMode == VIEWMODE_TYPE_MAXIMIZED) {
+ m_initialViewMode = viewMode;
+ m_currentViewMode = m_initialViewMode;
+ break;
+ }
+ break;
+ case 'w':
+ if (viewMode == VIEWMODE_TYPE_WINDOWED) {
+ m_initialViewMode = viewMode;
+ m_currentViewMode = m_initialViewMode;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
}
-void WrtClient::setComplianceModeStep()
+void WrtClient::setWindowInitialOrientation(void)
{
- LogDebug("Set compliance mode...");
- wrt_set_compliance_mode(m_complianceMode,
- &staticSetComplianceModeCallback,
- this);
+ Assert(m_windowData);
+ Assert(m_dao);
+
+ WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
+ if (rotationValue == Screen_Portrait) {
+ setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
+ } else if (rotationValue == Screen_Landscape) {
+ setWindowOrientation(OrientationAngle::Window::Landscape::PRIMARY);
+ } else if (rotationValue == Screen_AutoRotation) {
+ if (!AutoRotationSupport::setAutoRotation(
+ m_windowData->getEvasObject(Layer::WINDOW),
+ autoRotationCallback,
+ this))
+ {
+ LogError("Fail to set auto rotation");
+ }
+ } else {
+ setWindowOrientation(OrientationAngle::Window::Portrait::PRIMARY);
+ }
}
-void WrtClient::setComplianceImeiStep()
+void WrtClient::setWindowOrientation(int angle)
{
- LogDebug("Set compliance fake IMEI...");
- wrt_set_compliance_fake_imei(m_complianceIMEI.c_str(),
- &staticSetComplianceImeiCallback,
- this);
+ Assert(m_windowData);
+ m_windowData->setOrientation(angle);
}
-void WrtClient::setComplianceMeidStep()
+void WrtClient::unsetWindowOrientation(void)
{
- LogDebug("Set compliance fake MEID...");
- wrt_set_compliance_fake_meid(m_complianceMEID.c_str(),
- &staticSetComplianceMeidCallback,
- this);
+ Assert(m_windowData);
+ Assert(m_dao);
+
+ WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
+ if (rotationValue == Screen_AutoRotation) {
+ AutoRotationSupport::unsetAutoRotation(
+ m_windowData->getEvasObject(Layer::WINDOW),
+ autoRotationCallback);
+ }
}
-void WrtClient::queryListStep()
+void WrtClient::setEwkInitialOrientation(void)
{
- LogDebug("Query list...");
-
- int count;
- int *handles;
-
- printf("%3s%12s%32s%16s%64s%32s\n",
- "No", "ID", "Name", "Version", "GUID", "Package Name");
- printf("%3s%12s%32s%16s%64s%32s\n",
- "--", "--", "----", "-------", "----", "------------");
-
- if (wrt_has_succeded(wrt_get_widget_list(&count, &handles))) {
- for (int i = 0; i < count; ++i) {
- wrt_widget_info *info;
-
- // Get widget infor for handle
- WrtErrStatus status = wrt_get_widget_info(handles[i], &info);
- LogInfo("Status: " << status);
- if (wrt_has_succeded(status)) {
- printf("%3i%12i%32s%16s%64s%32s\n",
- i + 1,
- handles[i],
- !info->name ? "[NULL]" : info->name,
- !info->version ? "[NULL]" : info->version,
- !info->id ? "[NULL]" : info->id,
- !info->pkg_name ? "[NULL]" : info->pkg_name);
-
- // Free widget info
- wrt_free_widget_info(info);
- } else {
- LogWarning("ReturnStatus::Failed to get widget name");
- }
- }
-
- // Free list
- wrt_free_widget_list(handles);
+ Assert(m_widget);
+ Assert(m_dao);
+
+ WidgetSettingScreenLock rotationValue = m_settingList->getRotationValue();
+ if (rotationValue == Screen_Portrait) {
+ ewk_view_orientation_send(
+ m_widget->GetCurrentWebview(),
+ OrientationAngle::W3C::Portrait::PRIMARY);
+ } else if (rotationValue == Screen_Landscape) {
+ ewk_view_orientation_send(
+ m_widget->GetCurrentWebview(),
+ OrientationAngle::W3C::Landscape::PRIMARY);
+ } else if (rotationValue == Screen_AutoRotation) {
+ ewk_view_orientation_send(
+ m_widget->GetCurrentWebview(),
+ OrientationAngle::W3C::Portrait::PRIMARY);
} else {
- LogWarning("ReturnStatus::Failed to get widget handle list");
+ ewk_view_orientation_send(
+ m_widget->GetCurrentWebview(),
+ OrientationAngle::W3C::Portrait::PRIMARY);
}
+}
+
+void WrtClient::ExitCallback(void* data,
+ Evas_Object * /*obj*/,
+ void * /*event_info*/)
+{
+ LogInfo("ExitCallback");
+ Assert(data);
- DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
+ WrtClient* This = static_cast<WrtClient*>(data);
+
+ This->OnTerminate();
}
-void WrtClient::staticWrtInitCallback(WrtErrStatus status,
- void* userdata)
+void WrtClient::setCtxpopupItem(void)
{
- WrtClient *This = static_cast<WrtClient*>(userdata);
+ WindowData::CtxpopupItemDataList data;
+
+ // 1. share
+ WindowData::CtxpopupCallbackType shareCallback =
+ DPL::MakeDelegate(this, &WrtClient::ctxpopupShare);
+ WindowData::CtxpopupItemData shareData("Share",
+ std::string(),
+ shareCallback);
+
+ // 2. reload
+ WindowData::CtxpopupCallbackType reloadCallback =
+ DPL::MakeDelegate(this, &WrtClient::ctxpopupReload);
+ WindowData::CtxpopupItemData reloadData("Reload",
+ std::string(),
+ reloadCallback);
+
+ // 3. Open in browser
+ WindowData::CtxpopupCallbackType launchBrowserCallback =
+ DPL::MakeDelegate(this, &WrtClient::ctxpopupLaunchBrowser);
+ WindowData::CtxpopupItemData launchBrowserData("Open in browser",
+ std::string(),
+ launchBrowserCallback);
+ data.push_back(shareData);
+ data.push_back(reloadData);
+ data.push_back(launchBrowserData);
+ m_windowData->setCtxpopupItemData(data);
+}
- if (status == WRT_SUCCESS) {
- LogDebug("Init succesfull");
- This->m_initialized = true;
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
- NextStepEvent());
+void WrtClient::ctxpopupShare(void)
+{
+ LogDebug("share");
+#ifdef X11
+ const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
+ if (!url) {
+ LogError("url is empty");
+ return;
+ }
+ if (ClientModule::ServiceSupport::launchShareService(
+ elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
+ url))
+ {
+ LogDebug("success");
} else {
- LogError("Init unsuccesfull");
- This->m_returnStatus = ReturnStatus::Failed;
- This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
+ LogDebug("fail");
}
+ evas_object_smart_callback_add(m_windowData->m_win,
+ "delete,request",
+ &WrtClient::ExitCallback,
+ this);
+#endif
}
-void WrtClient::staticWrtLaunchWidgetCallback(void* /*canvas*/,
- int handle,
- WrtErrStatus status,
- const char* errorMsg,
- void* userdata)
+void WrtClient::ctxpopupReload(void)
{
- WrtClientUserData *userData = static_cast<WrtClientUserData*>(userdata);
-
- if (status == WRT_SUCCESS) {
- LogDebug("Launch succesfull");
-
- userData->This->m_handle = handle;
- userData->This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
- NextStepEvent());
+ LogDebug("reload");
+ ewk_view_reload(m_widget->GetCurrentWebview());
+}
- setlinebuf(stdout);
- printf("launched\n");
- fflush(stdout);
+void WrtClient::ctxpopupLaunchBrowser(void)
+{
+ LogDebug("launchBrowser");
+#ifdef X11
+ const char* url = ewk_view_url_get(m_widget->GetCurrentWebview());
+ if (!url) {
+ LogError("url is empty");
+ return;
+ }
+ if (ClientModule::ServiceSupport::launchViewService(
+ elm_win_xwindow_get(m_windowData->getEvasObject(Layer::WINDOW)),
+ url))
+ {
+ LogDebug("success");
} else {
- LogError("Launch unsuccesfull: " << errorMsg);
-
- printf("failed\n");
-
- userData->This->m_returnStatus = ReturnStatus::Failed;
- userData->This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(
- QuitEvent());
+ LogDebug("fail");
}
+#endif
+}
- if(userData->debugMode == EINA_TRUE)
+void WrtClient::hwkeyCallback(const std::string& key)
+{
+ if (m_settingList->getBackButtonPresence() == BackButton_Enable
+ || m_currentViewMode == VIEWMODE_TYPE_WINDOWED)
{
- LogDebug("Send RT signal to wrt-launcher(pid: "
- << userData->This->m_sdkLauncherPid << ", status: " << status);
- union sigval sv;
- /* send real time signal with result to wrt-launcher */
- if(status == WRT_SUCCESS)
- {
- LogDebug("userData->portnum : " << userData->portnum);
- sv.sival_int = userData->portnum;
+ // windowed UX - hosted application
+ if (key == KeyName::BACK) {
+ if (m_isWebkitFullscreen) {
+ // FIXME!!! This method has not yet landed in the tizen 3.0
+ // webkit-efl source tree
+ //ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
+ } else {
+ m_widget->Backward();
+ }
+ } else if (key == KeyName::MENU) {
+ // UX isn't confirmed
+ // m_windowData->showCtxpopup();
}
- else
- {
- sv.sival_int = -1;
+ } else {
+ // packaged application
+ if (key == KeyName::BACK) {
+ if (m_isFullscreenByPlatform) {
+ // FIXME!!! This method has not yet landed in the tizen 3.0
+ // webkit-efl source tree
+ //ewk_view_fullscreen_exit(m_widget->GetCurrentWebview());
+ }
}
- sigqueue(userData->This->m_sdkLauncherPid, SIGRTMIN, sv);
}
-
- ApplicationDataSingleton::Instance().freeBundle();
-
- delete userData->pid;
- delete userData;
}
-void WrtClient::staticWrtStatusCallback(int handle,
- WrtErrStatus status,
- void* userdata)
+void WrtClient::setLayout(Evas_Object* webview)
{
- WrtClient *This = static_cast<WrtClient*>(userdata);
+ LogDebug("add new webkit buffer to window");
+ Assert(webview);
+ m_windowData->setWebview(webview);
+ evas_object_show(webview);
+ evas_object_show(m_windowData->getEvasObject(Layer::WINDOW));
+}
- if (status == WRT_SUCCESS) {
- LogDebug("Status succesfull");
- This->m_handle = handle;
- This->m_launched = false;
+void WrtClient::unsetLayout(Evas_Object* webview)
+{
+ LogDebug("remove current webkit buffer from window");
+ Assert(webview);
+ evas_object_hide(webview);
+ m_windowData->unsetWebview();
+}
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
- NextStepEvent());
+void WrtClient::shutdownStep()
+{
+ LogDebug("Closing Wrt connection ...");
- return;
+ if (m_widget && m_widgetState) {
+ m_widgetState = WidgetState_Stopped;
+ m_widget->Hide();
+ // AutoRotation, focusCallback use m_widget pointer internally.
+ // It must be unset before m_widget is released.
+ m_submodeSupport->deinitialize();
+ unsetWindowOrientation();
+ m_windowData->smartCallbackDel(Layer::FOCUS,
+ "focused",
+ focusedCallback);
+ m_windowData->smartCallbackDel(Layer::FOCUS,
+ "unfocused",
+ unfocusedCallback);
+ m_widget.reset();
+ ewk_context_delete(s_preparedEwkContext);
+ WRT::CoreModuleSingleton::Instance().Terminate();
}
-
- // Failure
- LogWarning("Install failed!");
-
- This->m_returnStatus = ReturnStatus::Failed;
- This->DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
+ if (m_initialized) {
+ m_initialized = false;
+ }
+ m_windowData.reset();
+ Quit();
}
-void WrtClient::staticCloseWidgetCallback(int /*widgetHandle*/,
- void *data)
+void WrtClient::autoRotationCallback(void* data, Evas_Object* obj, void* /*event*/)
{
- WrtClient *This = static_cast<WrtClient*>(data);
+ LogDebug("entered");
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
- NextStepEvent());
+ Assert(data);
+ Assert(obj);
+
+ WrtClient* This = static_cast<WrtClient*>(data);
+ This->autoRotationSetOrientation(obj);
}
-void WrtClient::staticSetDeveloperModeCallback(void *userParam)
+void WrtClient::focusedCallback(void* data,
+ Evas_Object* /*obj*/,
+ void* /*eventInfo*/)
{
- WrtClient *This = static_cast<WrtClient *>(userParam);
-
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
- NextStepEvent());
+ LogDebug("entered");
+ Assert(data);
+ WrtClient* This = static_cast<WrtClient*>(data);
+ elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_TRUE);
}
-void WrtClient::staticSetComplianceModeCallback(void *userParam)
+void WrtClient::unfocusedCallback(void* data,
+ Evas_Object* /*obj*/,
+ void* /*eventInfo*/)
{
- Assert(userParam);
- WrtClient *This = static_cast<WrtClient *>(userParam);
-
- LogInfo("Compliance mode is " <<
- (This->m_complianceMode ? "enabled" : "disabled"));
-
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::
- PostEvent(NextStepEvent());
+ LogDebug("entered");
+ Assert(data);
+ WrtClient* This = static_cast<WrtClient*>(data);
+ elm_object_focus_set(This->m_widget->GetCurrentWebview(), EINA_FALSE);
}
-void WrtClient::staticSetComplianceImeiCallback(void *userParam)
+void WrtClient::autoRotationSetOrientation(Evas_Object* obj)
{
- Assert(userParam);
- WrtClient *This = static_cast<WrtClient *>(userParam);
-
- LogInfo("Compliance fake IMEI is " << This->m_complianceIMEI);
+ LogDebug("entered");
+ Assert(obj);
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::
- PostEvent(NextStepEvent());
+ AutoRotationSupport::setOrientation(obj, m_widget->GetCurrentWebview(),
+ (m_splashScreen) ? m_splashScreen.get(): NULL);
}
-void WrtClient::staticSetComplianceMeidCallback(void *userParam)
+int WrtClient::languageChangedCallback(void *data)
{
- Assert(userParam);
- WrtClient *This = static_cast<WrtClient *>(userParam);
+ LogDebug("Language Changed");
+ if (!data) {
+ return 0;
+ }
+ WrtClient* wrtClient = static_cast<WrtClient*>(data);
+ if (!(wrtClient->m_dao)) {
+ return 0;
+ }
- LogInfo("Compliance fake MEID is " << This->m_complianceMEID);
+ // reset function fetches system locales and recreates language tags
+ LanguageTagsProviderSingleton::Instance().resetLanguageTags();
+ // widget default locales are added to language tags below
+ DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
+ if (!defloc.IsNull()) {
+ LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
+ *defloc);
+ }
- This->DPL::Event::ControllerEventHandler<NextStepEvent>::
- PostEvent(NextStepEvent());
+ if (wrtClient->m_launched &&
+ wrtClient->m_widgetState != WidgetState_Stopped)
+ {
+ wrtClient->m_widget->ReloadStartPage();
+ }
+ return 0;
}
-void WrtClient::staticWrtResumeStatusCallback(int /*handle*/,
- WrtErrStatus status,
- void* /*userdata*/)
+void WrtClient::Quit()
{
- if (WRT_SUCCESS == status) {
- LogDebug("Resume succesfull");
- return;
- }
+ ewk_shutdown();
+ DPL::Application::Quit();
}
-void WrtClient::staticWrtSuspendStatusCallback(int /*handle*/,
- WrtErrStatus status,
- void* /*userdata*/)
+static Eina_Bool proces_pool_fd_handler(void* /*data*/, Ecore_Fd_Handler *handler)
{
- if (WRT_SUCCESS == status) {
- LogDebug("Suspend succesfull");
- return;
+ int fd = ecore_main_fd_handler_fd_get(handler);
+
+ if (fd == -1)
+ {
+ LogDebug("ECORE_FD_GET");
+ exit(-1);
}
-}
-void WrtClient::staticWrtResetStatusCallback(int /*handle*/,
- WrtErrStatus status,
- void* /*userdata*/)
-{
- if (WRT_SUCCESS == status) {
- LogDebug("Reset succesfull");
- return;
+ if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
+ {
+ LogDebug("ECORE_FD_ERROR");
+ close(fd);
+ exit(-1);
}
+
+ if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
+ {
+ LogDebug("ECORE_FD_READ");
+ {
+ app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+ int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
+ close(fd);
+
+ if (recv_ret == -1)
+ {
+ LogDebug("recv error!");
+ free(pkt);
+ exit(-1);
+ }
+
+ LogDebug("recv_ret : " << recv_ret << ", pkt->len : " << pkt->len);
+ ecore_main_fd_handler_del(handler);
+ process_pool_launchpad_main_loop(pkt, app_argv[0], &app_argc, &app_argv);
+ free(pkt);
+ }
+ ecore_main_loop_quit();
+ }
+
+ return ECORE_CALLBACK_CANCEL;
}
-void WrtClient::installNewPlugins()
+static void vconf_changed_handler(keynode_t* /*key*/, void* /*data*/)
{
- LogDebug("Install new plugins");
+ LogDebug("VCONFKEY_LANGSET vconf-key was changed!");
- if (!PluginUtils::checkPluginInstallationRequired()) {
- LogDebug("Plugin installation not required");
- return;
- }
+ // When system language is changed, the candidate process will be created again.
+ exit(-1);
+}
- m_startupPluginInstallation = true;
- system("wrt-installer -p");
+void set_env()
+{
+#ifndef TIZEN_PUBLIC
+ setenv("COREGL_FASTPATH", "1", 1);
+#endif
+ setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
+ setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
+ setenv("ELM_IMAGE_CACHE", "0", 1);
}
int main(int argc,
char *argv[])
{
- ADD_PROFILING_POINT("main-entered", "point");
-
- // Output on stdout will be flushed after every newline character,
- // even if it is redirected to a pipe. This is useful for running
- // from a script and parsing output.
- // (Standard behavior of stdlib is to use full buffering when
- // redirected to a pipe, which means even after an end of line
- // the output may not be flushed).
- setlinebuf(stdout);
-
- // set evas backend type
- // check current machine is target or emul
- struct utsname u;
- std::string backend = "gl";
- if (0 == uname(&u)) {
- if ((!u.machine) || (0 == strlen(u.machine))) {
- LogError("Fail to get machine name");
- } else {
- // If current machine is emul,
- // machine name include "<arch>_emulated"
- std::string machine = u.machine;
- LogDebug("machine name is [" << machine << "]");
- // find "emulated" string in the u.machine
- if (std::string::npos != machine.find(MACHINE_NAME_EMUL)) {
- LogDebug("Current machine is emul");
- backend = "x11";
- } else {
- //webkit accel needs to evas backend
- LogDebug("Set backend to gl");
- backend = "gl";
+ // process pool - store arg's value
+ app_argc = argc;
+ app_argv = argv;
+
+#ifndef X11
+ // Mesa does a bad job detecting the correct EGL
+ // platform to use, and ends up assuming that the
+ // wrt-client is using X
+ setenv("EGL_PLATFORM", "wayland", 1);
+#endif
+
+ UNHANDLED_EXCEPTION_HANDLER_BEGIN
+ {
+ ADD_PROFILING_POINT("main-entered", "point");
+
+ // Set log tagging
+ DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
+
+ // Set environment variables
+ set_env();
+
+ if (argc > 1 && argv[1] != NULL && !strcmp(argv[1], "-d"))
+ {
+ LogDebug("Entered dummy process mode");
+ sprintf(argv[0], "%s ",
+ DUMMY_PROCESS_PATH);
+
+ // Set 'root' home directory
+ setenv(HOME, ROOT_HOME_PATH, 1);
+
+ LogDebug("Prepare ewk_context");
+ appcore_set_i18n("wrt-client", NULL);
+ ewk_set_arguments(argc, argv);
+ setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
+ s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
+
+ if (s_preparedEwkContext == NULL)
+ {
+ LogDebug("Creating webkit context was failed!");
+ exit(-1);
+ }
+
+ int client_fd = __connect_process_pool_server();
+
+ if (client_fd == -1)
+ {
+ LogDebug("Connecting process_pool_server was failed!");
+ exit(-1);
}
+
+ // register language changed callback
+ vconf_notify_key_changed(VCONFKEY_LANGSET, vconf_changed_handler, NULL);
+
+ LogDebug("Prepare window_data");
+ // Temporarily change HOME path to app
+ // This change is needed for getting elementary profile
+ // /opt/home/app/.elementary/config/mobile/base.cfg
+ const char* backupEnv = getenv(HOME);
+ if (!backupEnv) {
+ // If getenv return "NULL", set empty string
+ backupEnv = "";
+ }
+ setenv(HOME, APP_HOME_PATH, 1);
+ LogDebug("elm_init()");
+ elm_init(argc, argv);
+ setenv(HOME, backupEnv, 1);
+
+ LogDebug("WindowData()");
+ s_preparedWindowData = new WindowData(static_cast<unsigned long>(getpid()));
+
+ Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
+ (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
+ proces_pool_fd_handler, NULL, NULL, NULL);
+
+ if (fd_handler == NULL)
+ {
+ LogDebug("fd_handler is NULL");
+ exit(-1);
+ }
+
+ setpriority(PRIO_PROCESS, 0, 0);
+
+ LogDebug("ecore_main_loop_begin()");
+ ecore_main_loop_begin();
+ LogDebug("ecore_main_loop_begin()_end");
+
+ // deregister language changed callback
+ vconf_ignore_key_changed(VCONFKEY_LANGSET, vconf_changed_handler);
+
+ std::string tizenId =
+ ClientModule::CommandLineParser::getTizenId(argc, argv);
+ ewk_context_message_post_to_injected_bundle(
+ s_preparedEwkContext,
+ MESSAGE_NAME_INITIALIZE,
+ tizenId.c_str());
+
}
- } else {
- perror("Fail to get machine name");
- }
+ else
+ {
+ // This code is to fork a web process without exec.
+ std::string tizenId =
+ ClientModule::CommandLineParser::getTizenId(argc, argv);
+
+ if (!tizenId.empty()) {
+ if (UID_ROOT == getuid()) {
+ // Drop root permission
+ // Only launch web application by console command case has root permission
+ if (!ClientModule::SecuritySupport::setAppPrivilege(tizenId)) {
+ LogError("Fail to set app privilege : [" << tizenId << "]");
+ exit(-1);
+ }
+ }
+
+ LogDebug("Launching by fork mode");
+ // Language env setup
+ appcore_set_i18n("wrt-client", NULL);
+ ewk_set_arguments(argc, argv);
+ setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
+ s_preparedEwkContext = ewk_context_new_with_injected_bundle_path(
+ BUNDLE_PATH);
+
+ if (s_preparedEwkContext == NULL)
+ {
+ LogDebug("Creating webkit context was failed!");
+ Wrt::Popup::PopupInvoker().showInfo("Error", "Creating webkit context was failed.", "OK");
+ exit(-1);
+ }
- if (!getenv("ELM_ENGINE")) {
- if (setenv("ELM_ENGINE", backend.c_str(), 1)) {
- LogDebug("Enable backend");
+ // plugin init
+ ewk_context_message_post_to_injected_bundle(
+ s_preparedEwkContext,
+ MESSAGE_NAME_INITIALIZE,
+ tizenId.c_str());
+ }
}
+
+ // Output on stdout will be flushed after every newline character,
+ // even if it is redirected to a pipe. This is useful for running
+ // from a script and parsing output.
+ // (Standard behavior of stdlib is to use full buffering when
+ // redirected to a pipe, which means even after an end of line
+ // the output may not be flushed).
+ setlinebuf(stdout);
+
+ WrtClient app(app_argc, app_argv);
+
+ ADD_PROFILING_POINT("Before appExec", "point");
+ int ret = app.Exec();
+ LogDebug("App returned: " << ret);
+ ret = app.getReturnStatus();
+ LogDebug("WrtClient returned: " << ret);
+ return ret;
}
- DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
- WrtClient app(argc, argv);
- int ret = app.Exec();
- LogDebug("App returned: " << ret);
- ret = app.getReturnStatus();
- LogDebug("WrtClient returned: " << ret);
- return ret;
+ UNHANDLED_EXCEPTION_HANDLER_END
}