// TODO(sngn.lee) : It should be declare in common header
const char* kKeyNameBack = "back";
+ const char* kConsoleLogEnableKey = "WRT_CONSOLE_LOG_ENABLE";
+ const char* kConsoleMessageLogTag = "ConsoleMessage";
+
const char* kAppControlEventScript = \
"var __event = document.createEvent(\"CustomEvent\");\n"
"__event.initCustomEvent(\"appcontrol\", true, true);\n"
}
}
+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) {
+ int dlog_level = DLOG_DEBUG;
+ switch (level) {
+ case EWK_CONSOLE_MESSAGE_LEVEL_WARNING:
+ dlog_level = DLOG_WARN;
+ break;
+ case EWK_CONSOLE_MESSAGE_LEVEL_ERROR:
+ dlog_level = DLOG_ERROR;
+ break;
+ default:
+ dlog_level = DLOG_DEBUG;
+ break;
+ }
+ LOG_(LOG_ID_MAIN, dlog_level, kConsoleMessageLogTag, "%s", msg.c_str());
+ }
+}
+
void WebApplication::OnLoadStart(WebView* view) {
LoggerD("LoadStart");
}
bool lock,
int preferred_rotation);
virtual void OnHardwareKey(WebView* view, const std::string& keyname);
+ virtual void OnConsoleMessage(const std::string& msg, int level);
virtual void OnLoadStart(WebView* view);
virtual void OnLoadFinished(WebView* view);
#include <ewk_chromium.h>
#include <functional>
+#include <sstream>
#include "runtime/native_window.h"
orientation_lock_callback,
this);
+ auto console_message_callback = [](void* user_data,
+ Evas_Object*,
+ void* event_info) {
+ WebView* self = static_cast<WebView*>(user_data);
+ if (!self->listener_) {
+ return;
+ }
+ Ewk_Console_Message* msg = static_cast<Ewk_Console_Message*>(event_info);
+ unsigned int line_number = ewk_console_message_line_get(msg);
+
+ std::stringstream buf;
+ if (line_number) {
+ buf << ewk_console_message_source_get(msg) << ":";
+ buf << line_number << ":";
+ }
+ buf << ewk_console_message_text_get(msg);
+ int level = ewk_console_message_level_get(msg);
+ self->listener_->OnConsoleMessage(buf.str(), level);
+ };
+ // console log
+ evas_object_smart_callback_add(ewk_view_,
+ "console,message",
+ console_message_callback,
+ this);
+
// rotation support
ewk_view_orientation_send(ewk_view_, ToWebRotation(window_->rotation()));
rotation_handler_id_ = window_->AddRotationHandler(
WebView* /*view*/,
bool /*lock*/,
int /*preferred_rotation*/) {}
+ virtual void OnConsoleMessage(const std::string& /*msg*/, int /*level*/) {}
};
WebView(wrt::NativeWindow* window, Ewk_Context* context);