From 807805628fd299b5030cf290736b0ee4a6bd922a Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Mon, 20 Apr 2015 12:55:32 +0900 Subject: [PATCH] Implement debug mode Change-Id: I1ddb00d550aba2a511b02993f20c1aa187b15fd7 --- src/runtime/web_application.cc | 37 +++++++++++++++++++++++++++++++------ src/runtime/web_application.h | 2 ++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/runtime/web_application.cc b/src/runtime/web_application.cc index a0bb01a..007e6bf 100755 --- a/src/runtime/web_application.cc +++ b/src/runtime/web_application.cc @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "common/message_types.h" #include "common/command_line.h" @@ -26,6 +29,10 @@ namespace { const char* kConsoleLogEnableKey = "WRT_CONSOLE_LOG_ENABLE"; const char* kConsoleMessageLogTag = "ConsoleMessage"; + const char* kDebugKey = "debug"; + const char* kPortKey = "port"; + + const char* kAppControlEventScript = \ "(function(){" "var __event = document.createEvent(\"CustomEvent\");\n" @@ -54,7 +61,8 @@ WebApplication::WebApplication(const std::string& appid) appid_(appid), ewk_context_(ewk_context_new()), locale_manager_(new LocaleManager()), - app_data_(new ApplicationData(appid)) { + app_data_(new ApplicationData(appid)), + debug_mode_(false) { // app_data_path std::unique_ptr path {app_get_data_path(), std::free}; @@ -69,7 +77,8 @@ WebApplication::WebApplication(std::unique_ptr app_data) appid_(app_data->app_id()), ewk_context_(ewk_context_new()), locale_manager_(new LocaleManager()), - app_data_(std::move(app_data)) { + app_data_(std::move(app_data)), + debug_mode_(false) { // app_data_path std::unique_ptr path {app_get_data_path(), std::free}; @@ -151,6 +160,11 @@ void WebApplication::Launch(std::unique_ptr appcontrol) { EVAS_CALLBACK_RESIZE, callback, NULL); + if (appcontrol->data(kDebugKey) == "true") { + debug_mode_ = true; + LaunchInspector(appcontrol.get()); + } + // TODO(sngn.lee): check the below code location. // in Wearable, webkit can render contents before show window // but Mobile, webkit can't render contents before show window @@ -174,6 +188,11 @@ void WebApplication::AppControl(std::unique_ptr appcontrol) { // Send Event SendAppControlEvent(); } + + if (!debug_mode_ && appcontrol->data(kDebugKey) == "true") { + debug_mode_ = true; + LaunchInspector(appcontrol.get()); + } window_->Active(); } @@ -315,8 +334,7 @@ void WebApplication::OnLanguageChanged() { void WebApplication::OnConsoleMessage(const std::string& msg, int level) { static bool enabled = (getenv(kConsoleLogEnableKey) != NULL); - // TODO(sngn.lee): check debug mode - if (true/*debug mode*/ || enabled) { + if (debug_mode_ || enabled) { int dlog_level = DLOG_DEBUG; switch (level) { case EWK_CONSOLE_MESSAGE_LEVEL_WARNING: @@ -348,7 +366,14 @@ void WebApplication::OnRendered(WebView* view) { LoggerD("Rendered"); } - - +void WebApplication::LaunchInspector(wrt::AppControl* appcontrol) { + unsigned int port = + ewk_context_inspector_server_start(ewk_context_, 0); + std::stringstream ss; + ss << port; + std::map> data; + data[kPortKey] = { ss.str() }; + appcontrol->Reply(data); +} } // namespace wrt diff --git a/src/runtime/web_application.h b/src/runtime/web_application.h index 2e31eb9..7e1bb09 100755 --- a/src/runtime/web_application.h +++ b/src/runtime/web_application.h @@ -54,6 +54,7 @@ class WebApplication : public WebView::EventListener { private: void ClearViewStack(); void SendAppControlEvent(); + void LaunchInspector(wrt::AppControl* appcontrol); bool initialized_; std::string appid_; @@ -64,6 +65,7 @@ class WebApplication : public WebView::EventListener { std::string app_data_path_; std::unique_ptr locale_manager_; std::unique_ptr app_data_; + bool debug_mode_; }; } // namespace wrt -- 2.7.4