static NativeWindow* CreateNativeWindow() {
// TODO(wy80.choi) : consider other type of native window.
NativeWindow* window = new NativeAppWindow();
-
- window->Initialize();
return window;
}
} // namespace
Runtime::Runtime()
- : application_(NULL) {
+ : application_(NULL),
+ native_window_(NULL) {
}
Runtime::~Runtime() {
if (application_) {
delete application_;
}
+ if (native_window_) {
+ delete native_window_;
+ }
}
bool Runtime::OnCreate() {
std::string appid = CommandLine::ForCurrentProcess()->appid();
- application_ = new WebApplication(appid);
- if (!application_) {
- LoggerE("WebApplication couldn't be created.");
- return false;
- }
- application_->set_terminator([](){ ui_app_exit(); });
// Process First Launch
native_window_ = CreateNativeWindow();
- application_->Initialize(native_window_);
+ application_ = new WebApplication(native_window_, appid);
+ application_->set_terminator([](){ ui_app_exit(); });
return true;
}
}
void Runtime::OnPause() {
- if (application_->initialized()) {
+ if (application_->launched()) {
application_->Suspend();
}
}
void Runtime::OnResume() {
- if (application_->initialized()) {
+ if (application_->launched()) {
application_->Resume();
}
}
void Runtime::OnAppControl(app_control_h app_control) {
std::unique_ptr<AppControl> appcontrol(new AppControl(app_control));
- if (application_->initialized()) {
+ if (application_->launched()) {
// Process AppControl
application_->AppControl(std::move(appcontrol));
} else {
} // namespace wrt
int main(int argc, char* argv[]) {
- // Initalize CommandLineParser
+ // Initialize CommandLineParser
wrt::CommandLine::Init(argc, argv);
ewk_init();
#include <vector>
#include <map>
-#include "common/message_types.h"
+#include "common/logger.h"
#include "common/command_line.h"
+#include "common/string_utils.h"
#include "runtime/native_window.h"
#include "runtime/web_view.h"
#include "runtime/vibration_manager.h"
-#include "common/logger.h"
#include "runtime/app_control.h"
#include "runtime/locale_manager.h"
#include "runtime/application_data.h"
const char* kDebugKey = "debug";
const char* kPortKey = "port";
+ // TODO(wy80.choi): consider 64bits system.
+ const char* kInjectedBundlePath = "/usr/lib/libwrt-injected-bundle.so";
const char* kAppControlEventScript = \
"(function(){"
namespace wrt {
-WebApplication::WebApplication(const std::string& appid)
- : initialized_(false),
- appid_(appid),
- ewk_context_(ewk_context_new()),
- locale_manager_(new LocaleManager()),
- app_data_(new ApplicationData(appid)),
+WebApplication::WebApplication(
+ NativeWindow* window, const std::string& appid)
+ : launched_(false),
debug_mode_(false),
- terminator_(NULL) {
- // app_data_path
- std::unique_ptr<char, decltype(std::free)*>
- path {app_get_data_path(), std::free};
- app_data_path_ = path.get();
-
- // extension_server
- extension_server_ = new ExtensionServer(ewk_context_);
+ ewk_context_(NULL),
+ window_(NULL) {
+ std::unique_ptr<ApplicationData> appdata_ptr(new ApplicationData(appid));
+ Initialize(window, std::move(appdata_ptr));
}
-WebApplication::WebApplication(std::unique_ptr<ApplicationData> app_data)
- : initialized_(false),
- appid_(app_data->app_id()),
- ewk_context_(ewk_context_new()),
- locale_manager_(new LocaleManager()),
- app_data_(std::move(app_data)),
+WebApplication::WebApplication(
+ NativeWindow* window, std::unique_ptr<ApplicationData> app_data)
+ : launched_(false),
debug_mode_(false),
- terminator_(NULL) {
- // app_data_path
- std::unique_ptr<char, decltype(std::free)*>
- path {app_get_data_path(), std::free};
- app_data_path_ = path.get();
-
- // extension_server
- extension_server_ = new ExtensionServer(ewk_context_);
+ ewk_context_(NULL),
+ window_(NULL) {
+ Initialize(window, std::move(app_data));
}
WebApplication::~WebApplication() {
- ewk_context_delete(ewk_context_);
- if (extension_server_)
- delete extension_server_;
+ if (ewk_context_)
+ ewk_context_delete(ewk_context_);
}
-bool WebApplication::Initialize(NativeWindow* window) {
+bool WebApplication::Initialize(
+ NativeWindow* window, std::unique_ptr<ApplicationData> app_data) {
+
+ // NativeWindow
window_ = window;
- // start extension server
- if (extension_server_)
- extension_server_->Start();
+ // Application Id / Data
+ appid_ = app_data->app_id();
+ app_data_ = std::move(app_data);
+ std::unique_ptr<char, decltype(std::free)*>
+ path {app_get_data_path(), std::free};
+ app_data_path_ = path.get();
+
+ // Ewk Context
+ ewk_context_ =
+ ewk_context_new_with_injected_bundle_path(kInjectedBundlePath);
+
+ // Locale Manager
+ locale_manager_ = std::unique_ptr<LocaleManager>(new LocaleManager());
+
+ // UUID
+ uuid_ = utils::GenerateUUID();
// ewk setting
ewk_context_cache_model_set(ewk_context_, EWK_CACHE_MODEL_DOCUMENT_BROWSER);
}
void WebApplication::Launch(std::unique_ptr<wrt::AppControl> appcontrol) {
- initialized_ = true;
WebView* view = new WebView(window_, ewk_context_);
view->SetEventListener(this);
// in Wearable, webkit can render contents before show window
// but Mobile, webkit can't render contents before show window
window_->Show();
+
+ launched_ = true;
}
void WebApplication::AppControl(std::unique_ptr<wrt::AppControl> appcontrol) {
delete view;
}
-
void WebApplication::OnReceivedWrtMessage(
WebView* /*view*/,
Ewk_IPC_Wrt_Message_Data* message) {
-
- Eina_Stringshare* msg_type = ewk_ipc_wrt_message_data_type_get(message);
-
- #define START_WITHS(x, s) (strncmp(x, s, strlen(s)) == 0)
-
- if (START_WITHS(msg_type, message_types::kExtensionTypePrefix)) {
- extension_server_->HandleWrtMessage(message);
- }
-
- // TODO(wy80.choi): handle other message type?
- // changeUserAgent, clearAllCookie, GetWindowID, hide, exit, blockedUrl
-
-
- #undef START_WITHS
+ // TODO(wy80.choi) : Handle messages from injected bundle?
+ // ex. SendRuntimeMessage to hide / exit application.
}
void WebApplication::OnOrientationLock(WebView* view,
#include <functional>
#include "runtime/web_view.h"
-#include "extension/extension_server.h"
class Ewk_Context;
class WebApplication : public WebView::EventListener {
public:
- explicit WebApplication(const std::string& appid);
- explicit WebApplication(std::unique_ptr<ApplicationData> app_data);
+ explicit WebApplication(NativeWindow* window, const std::string& appid);
+ explicit WebApplication(NativeWindow* window,
+ std::unique_ptr<ApplicationData> app_data);
virtual ~WebApplication();
void AppControl(std::unique_ptr<wrt::AppControl> appcontrol);
void Resume();
void Suspend();
- bool Initialize(NativeWindow* window);
std::string data_path() const { return app_data_path_; }
- bool initialized() const { return initialized_; }
void set_terminator(std::function<void(void)> terminator)
{ terminator_ = terminator; }
+ bool launched() const { return launched_; }
virtual void OnCreatedNewWebView(WebView* view, WebView* new_view);
virtual void OnClosedWebView(WebView * view);
virtual void OnLowMemory();
virtual bool OnContextMenuDisabled(WebView* view);
+ std::string uuid() const { return uuid_; }
+
private:
+ bool Initialize(NativeWindow* window,
+ std::unique_ptr<ApplicationData> app_data);
+
void ClearViewStack();
void SendAppControlEvent();
void LaunchInspector(wrt::AppControl* appcontrol);
- bool initialized_;
- std::string appid_;
+ bool launched_;
+ bool debug_mode_;
Ewk_Context* ewk_context_;
NativeWindow* window_;
- ExtensionServer* extension_server_;
- std::list<WebView*> view_stack_;
+ std::string appid_;
std::string app_data_path_;
+ std::string uuid_;
+ std::list<WebView*> view_stack_;
std::unique_ptr<LocaleManager> locale_manager_;
std::unique_ptr<ApplicationData> app_data_;
- bool debug_mode_;
std::function<void(void)> terminator_;
};