Implement debug mode
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 20 Apr 2015 03:55:32 +0000 (12:55 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 21 Apr 2015 05:18:54 +0000 (14:18 +0900)
Change-Id: I1ddb00d550aba2a511b02993f20c1aa187b15fd7

src/runtime/web_application.cc
src/runtime/web_application.h

index a0bb01a..007e6bf 100755 (executable)
@@ -8,6 +8,9 @@
 #include <ewk_chromium.h>
 #include <algorithm>
 #include <memory>
+#include <sstream>
+#include <vector>
+#include <map>
 
 #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<char, decltype(std::free)*>
     path {app_get_data_path(), std::free};
@@ -69,7 +77,8 @@ WebApplication::WebApplication(std::unique_ptr<ApplicationData> 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<char, decltype(std::free)*>
     path {app_get_data_path(), std::free};
@@ -151,6 +160,11 @@ void WebApplication::Launch(std::unique_ptr<wrt::AppControl> 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<wrt::AppControl> 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<std::string, std::vector<std::string>> data;
+  data[kPortKey] = { ss.str() };
+  appcontrol->Reply(data);
+}
 
 }  // namespace wrt
index 2e31eb9..7e1bb09 100755 (executable)
@@ -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<LocaleManager> locale_manager_;
   std::unique_ptr<ApplicationData> app_data_;
+  bool debug_mode_;
 };
 
 }  // namespace wrt