From: k2.nagaraju Date: Thu, 5 Apr 2018 14:44:03 +0000 (+0530) Subject: IPC bring up and removing ewk dependency to support webdevice API. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e2f189e3b5d49c98f44ff11b11ec58201712423a;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git IPC bring up and removing ewk dependency to support webdevice API. - Modified the exising xwalk extension server and client to work in multiprocess - related patch https://review.tizen.org/gerrit/#/c/173694/ Change-Id: I5675b9fc3f2aad7d477b8a7dd60a3639e3d9b757 Signed-off-by: k2.nagaraju --- diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index f840690..32e6ecf 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -148,9 +148,10 @@ void AtomMainDelegate::PreSandboxStartup() { #if defined(OS_TIZEN) LOG (ERROR) << "Set Injected bundle path to engine"; - command_line->AppendSwitchASCII("injected-bundle-path","/usr/lib/libxwalk_injected_bundle.so"); - std::vector cmdAgrs = atom::AtomCommandLine::argv(); - std::string app_id = cmdAgrs[1]; + command_line->AppendSwitchASCII( + "injected-bundle-path","/usr/lib/libxwalk_injected_bundle.so"); + std::string app_id = common::CommandLine::ForCurrentProcess()-> + GetAppIdFromCommandLine("/usr/bin/wrt"); command_line->AppendSwitchASCII("widget-id",app_id); #endif diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc index a14e842..ad61e2d 100644 --- a/atom/app/runtime.cc +++ b/atom/app/runtime.cc @@ -42,4 +42,4 @@ std::unique_ptr Runtime::MakeRuntime(content::ContentMainParams *params //} } -} // namespace runtime \ No newline at end of file +} // namespace runtime diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc index e89b1dd..b63ef51 100644 --- a/atom/browser/api/atom_api_pwrt.cc +++ b/atom/browser/api/atom_api_pwrt.cc @@ -54,7 +54,7 @@ bool PWRT::isTizenWebApp() { void PWRT::Log(const std::string& message) { std::string output = "[JS LOG] " + message; - dlog_print(DLOG_INFO, "WRT", output.c_str()); + dlog_print(DLOG_ERROR, "WRT", output.c_str()); } // static diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 8c473c5..8474a5b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -4,6 +4,7 @@ #include "atom/browser/api/atom_api_web_contents.h" +#include #include #include @@ -77,6 +78,10 @@ #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/display/screen.h" +#if defined(USE_EFL) +#include "tizen/extensions/common/xwalk_extension_server.h" +#endif + #if !defined(OS_MACOSX) && !defined(USE_EFL) #include "ui/aura/window.h" #endif @@ -434,7 +439,8 @@ bool WebContents::DidAddMessageToConsole(content::WebContents* source, int32_t line_no, const base::string16& source_id) { if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) { - return false; + LOG(ERROR) << "Console Message : " << message << ", source:" << source_id << " (" << line_no << ")"; + return true; } else { Emit("console-message", level, message, line_no, source_id); return true; @@ -897,6 +903,33 @@ void WebContents::DevToolsClosed() { Emit("devtools-closed"); } +void WebContents::OnWrtPluginMessage(const Wrt_Message_Data& data) { + Wrt_Message_Data tmp = data; + HandleWrtPluginMessage(&tmp); +} + +void WebContents::OnWrtPluginSyncMessage(const Wrt_Message_Data& data, + IPC::Message* reply) { + Wrt_Message_Data tmp = data; + HandleWrtPluginMessage(&tmp); + EwkHostMsg_WrtSyncMessage::WriteReplyParams(reply, tmp.value); + Send(reply); +} + +void WebContents::HandleWrtPluginMessage(Wrt_Message_Data* msg) { + Eina_Stringshare* msg_type = msg->GetType(); + +#define TYPE_BEGIN(x) (!strncmp(msg_type, x, strlen(x))) +#define TYPE_IS(x) (!strcmp(msg_type, x)) + + if (TYPE_BEGIN("xwalk://")) { + auto extension_server = extensions::XWalkExtensionServer::GetInstance(); + extension_server->HandleIPCMessage(msg); + } else { + // implement in future + } +} + bool WebContents::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebContents, message) @@ -907,7 +940,8 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { OnSetTemporaryZoomLevel) IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_GetZoomLevel, OnGetZoomLevel) - + IPC_MESSAGE_HANDLER(EwkHostMsg_WrtMessage, OnWrtPluginMessage) + IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_WrtSyncMessage, OnWrtPluginSyncMessage) // FIXME: Disable OnCursorChange due to stach_chk_fail crash. // IPC_MESSAGE_HANDLER_CODE(ViewHostMsg_SetCursor, OnCursorChange, // handled = false) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1301ed1..4407b3c 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -18,6 +18,7 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/common/favicon_url.h" #include "native_mate/handle.h" +#include "tizen/common/wrt_message_data.h" #include "ui/gfx/image/image.h" namespace blink { @@ -217,7 +218,10 @@ class WebContents : public mate::TrackableObject, v8::Local Debugger(v8::Isolate* isolate); WebContentsZoomController* GetZoomController() { return zoom_controller_; } - + void OnWrtPluginMessage(const Wrt_Message_Data& data); + void OnWrtPluginSyncMessage(const Wrt_Message_Data& data, + IPC::Message* reply); + void HandleWrtPluginMessage(Wrt_Message_Data* msg); protected: WebContents(v8::Isolate* isolate, content::WebContents* web_contents, diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 77c3212..ebbd54a 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -215,7 +215,12 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches( static const char* const kCommonSwitchNames[] = { switches::kStandardSchemes, switches::kEnableSandbox, - switches::kSecureSchemes + switches::kSecureSchemes, + switches::kInjectedBundlePath, + switches::kTizenAppId, + switches::kWidgetScale, + switches::kWidgetTheme, + switches::kWidgetEncodedBundle }; command_line->CopySwitchesFrom( *base::CommandLine::ForCurrentProcess(), diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index ef945d9..cffc9df 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -9,6 +9,7 @@ #include "base/values.h" #include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" +#include "tizen/common/wrt_message_data.h" #include "ui/gfx/ipc/gfx_param_traits.h" // The message starter should be declared in ipc/ipc_message_start.h. Since @@ -21,6 +22,13 @@ IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion) IPC_STRUCT_TRAITS_MEMBER(bounds) IPC_STRUCT_TRAITS_END() +IPC_STRUCT_TRAITS_BEGIN(Wrt_Message_Data) + IPC_STRUCT_TRAITS_MEMBER(type) + IPC_STRUCT_TRAITS_MEMBER(value) + IPC_STRUCT_TRAITS_MEMBER(id) + IPC_STRUCT_TRAITS_MEMBER(reference_id) +IPC_STRUCT_TRAITS_END() + IPC_MESSAGE_ROUTED2(AtomViewHostMsg_Message, base::string16 /* channel */, base::ListValue /* arguments */) @@ -49,3 +57,21 @@ IPC_SYNC_MESSAGE_ROUTED1_1(AtomViewHostMsg_SetTemporaryZoomLevel, // Sent by renderer to get the zoom level. IPC_SYNC_MESSAGE_ROUTED0_1(AtomViewHostMsg_GetZoomLevel, double /* result */) + +IPC_MESSAGE_ROUTED1(EwkHostMsg_WrtMessage, + Wrt_Message_Data /* data */) + +IPC_MESSAGE_CONTROL1(WrtMsg_SendWrtMessage, + Wrt_Message_Data /* data */) + +IPC_MESSAGE_CONTROL2(WrtMsg_ParseUrl, + int, // result: request_id + GURL) // result: url + +IPC_MESSAGE_CONTROL2(WrtMsg_ParseUrlResponse, + int, // result: request_id + GURL) // result: url + +IPC_SYNC_MESSAGE_ROUTED1_1(EwkHostMsg_WrtSyncMessage, + Wrt_Message_Data /* data */, + std::string /*result*/) diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 2f1c036..a2b394e 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -182,6 +182,13 @@ const char kWidevineCdmPath[] = "widevine-cdm-path"; // Widevine CDM version. const char kWidevineCdmVersion[] = "widevine-cdm-version"; +const char kInjectedBundlePath[] = "injected-bundle-path"; +// Widget Info +const char kTizenAppId[] = "widget-id"; +const char kWidgetScale[] = "widget-scale"; +const char kWidgetTheme[] = "widget-theme"; +const char kWidgetEncodedBundle[] = "widget-encoded-bundle"; + } // namespace switches } // namespace atom diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 69e7af0..6aecbf8 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -97,6 +97,11 @@ extern const char kNodeIntegrationInWorker[]; extern const char kWidevineCdmPath[]; extern const char kWidevineCdmVersion[]; +extern const char kInjectedBundlePath[]; +extern const char kTizenAppId[]; +extern const char kWidgetScale[]; +extern const char kWidgetTheme[]; +extern const char kWidgetEncodedBundle[]; } // namespace switches } // namespace atom diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 1a9343e..77b5eb0 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -9,6 +9,11 @@ #if defined(USE_EFL) #include "atom/common/atom_command_line.h" +#include "base/strings/string_number_conversions.h" +#include "content/common/wrt/wrt_url_parse.h" +#include "content/public/renderer/render_thread.h" +#include "content/public/renderer/render_view.h" +#include "third_party/WebKit/public/web/WebView.h" #endif #include "atom_natives.h" // NOLINT: This file is generated with js2c @@ -53,6 +58,22 @@ const char** StringVectorToArgArray( } // namespace +class WrtUrlParseImpl : public content::WrtUrlParseBase { + public: + WrtUrlParseImpl(WrtWidget* wrt_widget) : wrt_widget_(wrt_widget) {} + GURL parseUrl(const GURL& old_url) const override { + if (!wrt_widget_->IsWidgetInfoSet()) + return old_url; + GURL new_url; + bool is_decrypted_file = false; + wrt_widget_->ParseUrl(old_url, new_url, is_decrypted_file); + return new_url; + } + + private: + WrtWidget* wrt_widget_; +}; + AtomRendererClient::AtomRendererClient() : node_integration_initialized_(false), node_bindings_(NodeBindings::Create(NodeBindings::RENDERER)), @@ -74,6 +95,24 @@ void AtomRendererClient::RenderThreadStarted() { base::CommandLine::StringVector argv = command_line->argv(); const char** c_argv = StringVectorToArgArray(argv); atom::AtomCommandLine::Init(argv.size(), c_argv); + std::string tizen_app_id = command_line->GetSwitchValueASCII( + "widget-id"); + + WrtWidget* wrt_widget = new WrtWidget; + if (wrt_widget == nullptr) { + return; + } + widget_.reset(wrt_widget); + content::RenderThread* thread = content::RenderThread::Get(); + thread->AddObserver(wrt_widget->GetObserver()); + wrt_url_parser_.reset(new WrtUrlParseImpl(wrt_widget)); + std::string theme = command_line->GetSwitchValueASCII("widget-theme"); + std::string encoded_bundle = command_line->GetSwitchValueASCII("widget-encoded-bundle"); + std::string scale = command_line->GetSwitchValueASCII("widget-scale"); + double scale_factor = 0; + base::StringToDouble(scale, &scale_factor); + wrt_widget->SetWidgetInfo(tizen_app_id, scale_factor, theme, + encoded_bundle); #endif OverrideNodeArrayBuffer(); RendererClientBase::RenderThreadStarted(); @@ -140,6 +179,13 @@ void AtomRendererClient::DidCreateScriptContext( // Give the node loop a run to make sure everything is ready. node_bindings_->RunMessageLoop(); } +#if defined(USE_EFL) + if (widget_) { + const content::RenderView* render_view = render_frame->GetRenderView(); + widget_->StartSession(context, render_view->GetRoutingID(), + render_frame->GetWebFrame()->document().baseURL().string().utf8().c_str()); + } +#endif } void AtomRendererClient::WillReleaseScriptContext( @@ -160,6 +206,10 @@ void AtomRendererClient::WillReleaseScriptContext( // Destroy the node environment. node::FreeEnvironment(env); atom_bindings_->EnvironmentDestroyed(env); +#if defined(USE_EFL) + if (widget_) + widget_->StopSession(context); +#endif } bool AtomRendererClient::ShouldFork(blink::WebLocalFrame* frame, diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index c9ffb29..0e623b5 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -9,11 +9,13 @@ #include #include "atom/renderer/renderer_client_base.h" +#include "tizen/wrt/wrtwidget.h" namespace atom { class AtomBindings; class NodeBindings; +class WrtUrlParseImpl; class AtomRendererClient : public RendererClientBase { public: @@ -41,7 +43,8 @@ class AtomRendererClient : public RendererClientBase { MANUAL_ENABLE_IFRAME, DISABLE, }; - + std::unique_ptr widget_; + std::unique_ptr wrt_url_parser_; // content::ContentRendererClient: void RenderThreadStarted() override; void RenderFrameCreated(content::RenderFrame*) override; diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index 7f48f8b..bafe82b 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -140,7 +140,8 @@ mkdir -p %{buildroot}%{extension_path} install -p -m 644 %{_out}/lib/libxwalk_extension_shared.so %{buildroot}%{_libdir} # xwalk_injected_bundle install -p -m 755 %{_out}/lib/libxwalk_injected_bundle.so %{buildroot}%{_libdir} - +# wrt chromium shared +install -p -m 644 %{_out}/lib/libchromium_wrt_shared.so %{buildroot}%{_libdir} %post # Owner account can't write /opt/usr/home/owner/data/org.tizen.electron-efl # which is created in 'install'. So we should copy resources in 'post'. @@ -173,3 +174,4 @@ rm -fr %{buildroot} %attr(644,root,root) %{_libdir}/libwrt_common.so %attr(644,root,root) %{_libdir}/libxwalk_extension_shared.so %attr(644,root,root) %{_libdir}/libxwalk_injected_bundle.so +%attr(644,root,root) %{_libdir}/libchromium_wrt_shared.so diff --git a/tizen/build/common.gypi b/tizen/build/common.gypi index 5f90ec5..8b70ac2 100644 --- a/tizen/build/common.gypi +++ b/tizen/build/common.gypi @@ -50,4 +50,4 @@ '-L./lib', ], }, -} \ No newline at end of file +} diff --git a/tizen/common/common.gyp b/tizen/common/common.gyp index dfc2494..be5a8ec 100644 --- a/tizen/common/common.gyp +++ b/tizen/common/common.gyp @@ -34,6 +34,8 @@ 'resource_manager.cc', 'platform_info.h', 'platform_info.cc', + 'wrt_message_data.h', + 'wrt_message_data.cc', ], 'cflags': [ '-fvisibility=default', @@ -49,6 +51,7 @@ 'capi-system-info', 'cynara-client', 'dlog', + 'elementary', 'uuid', 'libwebappenc', 'manifest-parser', diff --git a/tizen/common/wrt_message_data.cc b/tizen/common/wrt_message_data.cc new file mode 100644 index 0000000..7b60902 --- /dev/null +++ b/tizen/common/wrt_message_data.cc @@ -0,0 +1,38 @@ +#include "wrt_message_data.h" + +Wrt_Message_Data::Wrt_Message_Data() {} + +Wrt_Message_Data::~Wrt_Message_Data() {} + +Eina_Stringshare* Wrt_Message_Data::GetType() const { + return eina_stringshare_add(type.c_str()); +} + +void Wrt_Message_Data::SetType(const char* val) { + type = val; +} + +Eina_Stringshare* Wrt_Message_Data::GetValue() const { + return eina_stringshare_add(value.c_str()); +} + +void Wrt_Message_Data::SetValue(const char* val) { + value = val; +} + +Eina_Stringshare* Wrt_Message_Data::GetId() const { + return eina_stringshare_add(id.c_str()); +} + +void Wrt_Message_Data::SetId(const char* val) { + id = val; +} + +Eina_Stringshare* Wrt_Message_Data::GetReferenceId() const { + return eina_stringshare_add(reference_id.c_str()); +} + +void Wrt_Message_Data::SetReferenceId(const char* val) { + reference_id = val; +} + diff --git a/tizen/common/wrt_message_data.h b/tizen/common/wrt_message_data.h new file mode 100644 index 0000000..81e7213 --- /dev/null +++ b/tizen/common/wrt_message_data.h @@ -0,0 +1,26 @@ +#ifndef WRT_MESSAGE_DATA_H +#define WRT_MESSAGE_DATA_H + +#include +#include + +struct Wrt_Message_Data { + std::string type; + std::string value; + std::string id; + std::string reference_id; + + Wrt_Message_Data(); + ~Wrt_Message_Data(); + const Eina_Stringshare* GetType() const; + void SetType(const char* val); + const Eina_Stringshare* GetValue() const; + void SetValue(const char* val); + const Eina_Stringshare* GetId() const; + void SetId(const char* val); + const Eina_Stringshare* GetReferenceId() const; + void SetReferenceId(const char* val); +}; + +#endif // WRT_MESSAGE_DATA_H + diff --git a/tizen/extensions/common/constants.cc b/tizen/extensions/common/constants.cc index cfc9fa4..0010130 100644 --- a/tizen/extensions/common/constants.cc +++ b/tizen/extensions/common/constants.cc @@ -25,6 +25,6 @@ const char kMethodSendSyncMessage[] = "xwalk://SendSyncMessage"; const char kMethodPostMessage[] = "xwalk://PostMessage"; const char kMethodGetAPIScript[] = "xwalk://GetAPIScript"; const char kMethodPostMessageToJS[] = "xwalk://PostMessageToJS"; - +const char kMethodLoadUserExtensions[] = "xwalk://LoadUserExtensions"; } // namespace extensions diff --git a/tizen/extensions/common/constants.h b/tizen/extensions/common/constants.h index 588f09b..2da2e20 100644 --- a/tizen/extensions/common/constants.h +++ b/tizen/extensions/common/constants.h @@ -26,6 +26,7 @@ extern const char kMethodSendSyncMessage[]; extern const char kMethodPostMessage[]; extern const char kMethodGetAPIScript[]; extern const char kMethodPostMessageToJS[]; +extern const char kMethodLoadUserExtensions[]; } // namespace extensions diff --git a/tizen/extensions/common/xwalk_extension_instance.cc b/tizen/extensions/common/xwalk_extension_instance.cc index c86bb59..7c6ffba 100644 --- a/tizen/extensions/common/xwalk_extension_instance.cc +++ b/tizen/extensions/common/xwalk_extension_instance.cc @@ -5,6 +5,7 @@ #include "extensions/common/xwalk_extension_instance.h" +#include "common/logger.h" #include "extensions/common/xwalk_extension_adapter.h" #include "extensions/public/XW_Extension_SyncMessage.h" diff --git a/tizen/extensions/common/xwalk_extension_server.cc b/tizen/extensions/common/xwalk_extension_server.cc index fc50396..3cf0acd 100644 --- a/tizen/extensions/common/xwalk_extension_server.cc +++ b/tizen/extensions/common/xwalk_extension_server.cc @@ -8,11 +8,14 @@ #include +#include "atom/common/api/api_messages.h" #include "common/logger.h" #include "common/profiler.h" #include "common/string_utils.h" +#include "content/public/browser/render_process_host.h" #include "extensions/common/constants.h" #include "extensions/common/xwalk_extension_manager.h" +#include "wrt/wrt_widget_host.h" namespace extensions { @@ -29,10 +32,6 @@ XWalkExtensionServer::XWalkExtensionServer() { XWalkExtensionServer::~XWalkExtensionServer() { } -void XWalkExtensionServer::SetupIPC(Ewk_Context* ewk_context) { - ewk_context_ = ewk_context; -} - void XWalkExtensionServer::Preload() { manager_.PreloadExtensions(); } @@ -76,7 +75,6 @@ std::string XWalkExtensionServer::GetAPIScript( std::string XWalkExtensionServer::CreateInstance( const std::string& extension_name) { std::string instance_id; - auto extensions = manager_.extensions(); auto it = extensions.find(extension_name); if (it != extensions.end()) { @@ -85,14 +83,12 @@ std::string XWalkExtensionServer::CreateInstance( instance_id = common::utils::GenerateUUID(); instance->SetPostMessageCallback( [this, instance_id](const std::string& msg) { - Ewk_IPC_Wrt_Message_Data* ans = ewk_ipc_wrt_message_data_new(); - ewk_ipc_wrt_message_data_type_set(ans, kMethodPostMessageToJS); - ewk_ipc_wrt_message_data_id_set(ans, instance_id.c_str()); - ewk_ipc_wrt_message_data_value_set(ans, msg.c_str()); - if (!ewk_ipc_wrt_message_send(ewk_context_, ans)) { - LOGGER(ERROR) << "Failed to send response"; - } - ewk_ipc_wrt_message_data_del(ans); + Wrt_Message_Data* ans = new Wrt_Message_Data(); + ans->SetType(kMethodPostMessageToJS); + ans->SetId(instance_id.c_str()); + ans->SetValue(msg.c_str()); + WrtWidgetHost::Get()->SendWrtMessage(*ans); + delete ans; }); instances_[instance_id] = instance; @@ -103,21 +99,16 @@ std::string XWalkExtensionServer::CreateInstance( } else { LOGGER(ERROR) << "No such extension '" << extension_name << "'"; } + LOGGER(ERROR) << instance_id; return instance_id; } -void XWalkExtensionServer::HandleIPCMessage(Ewk_IPC_Wrt_Message_Data* data) { +void XWalkExtensionServer::HandleIPCMessage(Wrt_Message_Data* data) { if (!data) { LOGGER(ERROR) << "Invalid parameter. data is NULL."; return; } - - if (!ewk_context_) { - LOGGER(WARN) << "IPC is not ready yet."; - return; - } - - Eina_Stringshare* msg_type = ewk_ipc_wrt_message_data_type_get(data); + Eina_Stringshare* msg_type = data->GetType(); #define TYPE_IS(x) (!strcmp(msg_type, x)) if (TYPE_IS(kMethodGetExtensions)) { @@ -138,27 +129,27 @@ void XWalkExtensionServer::HandleIPCMessage(Ewk_IPC_Wrt_Message_Data* data) { #undef TYPE_IS } -void XWalkExtensionServer::HandleGetExtensions(Ewk_IPC_Wrt_Message_Data* data) { +void XWalkExtensionServer::HandleGetExtensions(Wrt_Message_Data* data) { Json::Value reply = GetExtensions(); Json::FastWriter writer; std::string reply_str = writer.write(reply); - ewk_ipc_wrt_message_data_value_set(data, reply_str.c_str()); + data->SetValue(reply_str.c_str()); } void XWalkExtensionServer::HandleCreateInstance( - Ewk_IPC_Wrt_Message_Data* data) { - Eina_Stringshare* extension_name = ewk_ipc_wrt_message_data_value_get(data); + Wrt_Message_Data* data) { + Eina_Stringshare* extension_name = data->GetValue(); std::string instance_id = CreateInstance(extension_name); - ewk_ipc_wrt_message_data_value_set(data, instance_id.c_str()); + data->SetValue(instance_id.c_str()); eina_stringshare_del(extension_name); } void XWalkExtensionServer::HandleDestroyInstance( - Ewk_IPC_Wrt_Message_Data* data) { - Eina_Stringshare* instance_id = ewk_ipc_wrt_message_data_id_get(data); + Wrt_Message_Data* data) { + Eina_Stringshare* instance_id = data->GetId(); auto it = instances_.find(instance_id); if (it != instances_.end()) { @@ -173,12 +164,12 @@ void XWalkExtensionServer::HandleDestroyInstance( } void XWalkExtensionServer::HandlePostMessageToNative( - Ewk_IPC_Wrt_Message_Data* data) { - Eina_Stringshare* instance_id = ewk_ipc_wrt_message_data_id_get(data); + Wrt_Message_Data* data) { + Eina_Stringshare* instance_id = data->GetId(); auto it = instances_.find(instance_id); if (it != instances_.end()) { - Eina_Stringshare* msg = ewk_ipc_wrt_message_data_value_get(data); + Eina_Stringshare* msg = data->GetValue(); XWalkExtensionInstance* instance = it->second; instance->HandleMessage(msg); eina_stringshare_del(msg); @@ -190,19 +181,19 @@ void XWalkExtensionServer::HandlePostMessageToNative( } void XWalkExtensionServer::HandleSendSyncMessageToNative( - Ewk_IPC_Wrt_Message_Data* data) { - Eina_Stringshare* instance_id = ewk_ipc_wrt_message_data_id_get(data); + Wrt_Message_Data* data) { + Eina_Stringshare* instance_id = data->GetId(); auto it = instances_.find(instance_id); if (it != instances_.end()) { - Eina_Stringshare* msg = ewk_ipc_wrt_message_data_value_get(data); + Eina_Stringshare* msg = data->GetValue(); XWalkExtensionInstance* instance = it->second; std::string reply; instance->SetSendSyncReplyCallback([&reply](const std::string& msg) { reply = msg; }); instance->HandleSyncMessage(msg); - ewk_ipc_wrt_message_data_value_set(data, reply.c_str()); + data->SetValue(reply.c_str()); eina_stringshare_del(msg); } else { LOGGER(ERROR) << "No such instance '" << instance_id << "'"; @@ -212,12 +203,12 @@ void XWalkExtensionServer::HandleSendSyncMessageToNative( } void XWalkExtensionServer::HandleGetAPIScript( - Ewk_IPC_Wrt_Message_Data* data) { - Eina_Stringshare* extension_name = ewk_ipc_wrt_message_data_value_get(data); + Wrt_Message_Data* data) { + Eina_Stringshare* extension_name = data->GetValue(); std::string api = GetAPIScript(extension_name); - ewk_ipc_wrt_message_data_value_set(data, api.c_str()); + data->SetValue(api.c_str()); eina_stringshare_del(extension_name); } diff --git a/tizen/extensions/common/xwalk_extension_server.h b/tizen/extensions/common/xwalk_extension_server.h index 3cd67bf..7a45752 100644 --- a/tizen/extensions/common/xwalk_extension_server.h +++ b/tizen/extensions/common/xwalk_extension_server.h @@ -5,13 +5,11 @@ #ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_ #define XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_ -#include -#include #include #include #include - +#include "common/wrt_message_data.h" #include "extensions/common/xwalk_extension_manager.h" #include "extensions/common/xwalk_extension_instance.h" @@ -21,13 +19,12 @@ class XWalkExtensionServer { public: static XWalkExtensionServer* GetInstance(); - void SetupIPC(Ewk_Context* ewk_context); void Preload(); Json::Value GetExtensions(); std::string GetAPIScript(const std::string& extension_name); std::string CreateInstance(const std::string& extension_name); - void HandleIPCMessage(Ewk_IPC_Wrt_Message_Data* data); + void HandleIPCMessage(Wrt_Message_Data* data); void Shutdown(); void LoadUserExtensions(const std::string app_path); @@ -36,17 +33,15 @@ class XWalkExtensionServer { XWalkExtensionServer(); virtual ~XWalkExtensionServer(); - void HandleGetExtensions(Ewk_IPC_Wrt_Message_Data* data); - void HandleCreateInstance(Ewk_IPC_Wrt_Message_Data* data); - void HandleDestroyInstance(Ewk_IPC_Wrt_Message_Data* data); - void HandlePostMessageToNative(Ewk_IPC_Wrt_Message_Data* data); - void HandleSendSyncMessageToNative(Ewk_IPC_Wrt_Message_Data* data); - void HandleGetAPIScript(Ewk_IPC_Wrt_Message_Data* data); + void HandleGetExtensions(Wrt_Message_Data* data); + void HandleCreateInstance(Wrt_Message_Data* data); + void HandleDestroyInstance(Wrt_Message_Data* data); + void HandlePostMessageToNative(Wrt_Message_Data* data); + void HandleSendSyncMessageToNative(Wrt_Message_Data* data); + void HandleGetAPIScript(Wrt_Message_Data* data); typedef std::map InstanceMap; - Ewk_Context* ewk_context_; - XWalkExtensionManager manager_; InstanceMap instances_; diff --git a/tizen/extensions/extensions.gyp b/tizen/extensions/extensions.gyp index 165271b..163361d 100644 --- a/tizen/extensions/extensions.gyp +++ b/tizen/extensions/extensions.gyp @@ -45,6 +45,15 @@ 'elementary', ], }, + 'include_dirs': [ + '.', + '../..', + '<(libchromiumcontent_src_dir)', + '<(SHARED_INTERMEDIATE_DIR)', + '<(libchromiumcontent_src_dir)/gen', + '<(libchromiumcontent_src_dir)/third_party/skia/include/config', + '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + ], 'direct_dependent_settings': { # 'libraries': [ # '-lxwalk_extension_shared', diff --git a/tizen/extensions/renderer/runtime_ipc_client.cc b/tizen/extensions/renderer/runtime_ipc_client.cc index 6b96828..f64676b 100644 --- a/tizen/extensions/renderer/runtime_ipc_client.cc +++ b/tizen/extensions/renderer/runtime_ipc_client.cc @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "extensions/renderer/runtime_ipc_client.h" #include "extensions/renderer/xwalk_extension_renderer_controller.h" +#include "atom/common/api/api_messages.h" #include "common/logger.h" #include "common/profiler.h" #include "common/string_utils.h" +#include "content/public/renderer/render_view.h" namespace extensions { @@ -112,17 +115,16 @@ void RuntimeIPCClient::SendMessage(v8::Handle context, return; } - Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new(); - ewk_ipc_wrt_message_data_type_set(msg, type.c_str()); - ewk_ipc_wrt_message_data_id_set(msg, id.c_str()); - ewk_ipc_wrt_message_data_reference_id_set(msg, ref_id.c_str()); - ewk_ipc_wrt_message_data_value_set(msg, value.c_str()); - - if (!ewk_ipc_plugins_message_send(routing_id, msg)) { - LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc."; - } - - ewk_ipc_wrt_message_data_del(msg); + Wrt_Message_Data* msg = new Wrt_Message_Data(); + msg->SetType(type.c_str()); + msg->SetId(id.c_str()); + msg->SetValue(value.c_str()); + msg->SetReferenceId(ref_id.c_str()); + content::RenderView* render_view = + content::RenderView::FromRoutingID(routing_id); + render_view->Send( + new EwkHostMsg_WrtMessage(render_view->GetRoutingID(), *msg)); + delete msg; } std::string RuntimeIPCClient::SendSyncMessage(v8::Handle context, @@ -149,23 +151,20 @@ std::string RuntimeIPCClient::SendSyncMessage(v8::Handle context, return std::string(); } - Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new(); - ewk_ipc_wrt_message_data_type_set(msg, type.c_str()); - ewk_ipc_wrt_message_data_id_set(msg, id.c_str()); - ewk_ipc_wrt_message_data_reference_id_set(msg, ref_id.c_str()); - ewk_ipc_wrt_message_data_value_set(msg, value.c_str()); - - if (!ewk_ipc_plugins_sync_message_send(routing_id, msg)) { - LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc."; - ewk_ipc_wrt_message_data_del(msg); - return std::string(); - } - - Eina_Stringshare* msg_value = ewk_ipc_wrt_message_data_value_get(msg); + Wrt_Message_Data* msg = new Wrt_Message_Data(); + msg->SetType(type.c_str()); + msg->SetId(id.c_str()); + msg->SetValue(value.c_str()); + msg->SetReferenceId(ref_id.c_str()); + content::RenderView* render_view = + content::RenderView::FromRoutingID(routing_id); + render_view->Send( + new EwkHostMsg_WrtSyncMessage(render_view->GetRoutingID(), *msg, &msg->value)); + Eina_Stringshare* msg_value = msg->GetValue(); std::string result(msg_value); eina_stringshare_del(msg_value); - ewk_ipc_wrt_message_data_del(msg); + delete msg; return result; } @@ -182,30 +181,27 @@ void RuntimeIPCClient::SendAsyncMessage(v8::Handle context, std::string msg_id = common::utils::GenerateUUID(); - Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new(); - ewk_ipc_wrt_message_data_id_set(msg, msg_id.c_str()); - ewk_ipc_wrt_message_data_type_set(msg, type.c_str()); - ewk_ipc_wrt_message_data_value_set(msg, value.c_str()); - - if (!ewk_ipc_plugins_message_send(routing_id, msg)) { - LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc."; - ewk_ipc_wrt_message_data_del(msg); - return; - } - + Wrt_Message_Data* msg = new Wrt_Message_Data(); + msg->SetType(type.c_str()); + msg->SetId(msg_id.c_str()); + msg->SetValue(value.c_str()); + content::RenderView* render_view = + content::RenderView::FromRoutingID(routing_id); + render_view->Send( + new EwkHostMsg_WrtMessage(render_view->GetRoutingID(), *msg)); callbacks_[msg_id] = callback; - ewk_ipc_wrt_message_data_del(msg); + delete msg; } void RuntimeIPCClient::HandleMessageFromRuntime( - const Ewk_IPC_Wrt_Message_Data* msg) { + const Wrt_Message_Data* msg) { if (msg == NULL) { LOGGER(ERROR) << "received message is NULL"; return; } - Eina_Stringshare* msg_refid = ewk_ipc_wrt_message_data_reference_id_get(msg); + Eina_Stringshare* msg_refid = msg->GetReferenceId(); if (msg_refid == NULL || !strcmp(msg_refid, "")) { if (msg_refid) eina_stringshare_del(msg_refid); @@ -220,8 +216,8 @@ void RuntimeIPCClient::HandleMessageFromRuntime( return; } - Eina_Stringshare* msg_type = ewk_ipc_wrt_message_data_type_get(msg); - Eina_Stringshare* msg_value = ewk_ipc_wrt_message_data_value_get(msg); + Eina_Stringshare* msg_type = msg->GetType(); + Eina_Stringshare* msg_value = msg->GetValue(); ReplyCallback func = it->second; if (func) { diff --git a/tizen/extensions/renderer/runtime_ipc_client.h b/tizen/extensions/renderer/runtime_ipc_client.h index 7f94fb3..8f40d16 100644 --- a/tizen/extensions/renderer/runtime_ipc_client.h +++ b/tizen/extensions/renderer/runtime_ipc_client.h @@ -18,12 +18,11 @@ #define XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_ #include -#include -#include #include #include #include +#include "common/wrt_message_data.h" namespace extensions { @@ -83,7 +82,7 @@ class RuntimeIPCClient { const std::string& type, const std::string& value, ReplyCallback callback); - void HandleMessageFromRuntime(const Ewk_IPC_Wrt_Message_Data* msg); + void HandleMessageFromRuntime(const Wrt_Message_Data* msg); int GetRoutingId(v8::Handle context); diff --git a/tizen/extensions/renderer/xwalk_extension_client.cc b/tizen/extensions/renderer/xwalk_extension_client.cc index 383473f..d113269 100644 --- a/tizen/extensions/renderer/xwalk_extension_client.cc +++ b/tizen/extensions/renderer/xwalk_extension_client.cc @@ -6,15 +6,17 @@ #include "extensions/renderer/xwalk_extension_client.h" #include +#include #include #include -#include #include +#include "base/command_line.h" #include "common/logger.h" #include "common/profiler.h" #include "common/string_utils.h" +#include "content/public/common/content_switches.h" #include "extensions/common/constants.h" #include "extensions/common/xwalk_extension_server.h" #include "extensions/renderer/runtime_ipc_client.h" @@ -40,14 +42,22 @@ XWalkExtensionClient::~XWalkExtensionClient() { extension_apis_.clear(); } -void XWalkExtensionClient::Initialize() { +void XWalkExtensionClient::Initialize(v8::Handle context) { SCOPE_PROFILE(); if (!extension_apis_.empty()) { return; } - - XWalkExtensionServer* server = XWalkExtensionServer::GetInstance(); - Json::Value reply = server->GetExtensions(); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + Json::Value reply; + if (command_line->HasSwitch(switches::kSingleProcess)) { + XWalkExtensionServer* server = XWalkExtensionServer::GetInstance(); + reply = server->GetExtensions(); + } else { + RuntimeIPCClient* ipc = RuntimeIPCClient::GetInstance(); + std::string extension_info =ipc->SendSyncMessage(context, kMethodGetExtensions, "", ""); + Json::Reader reader; + reader.parse(extension_info, reply, false); + } for (auto it = reply.begin(); it != reply.end(); ++it) { ExtensionCodePoints* codepoint = new ExtensionCodePoints; Json::Value entry_points = (*it)["entry_points"]; @@ -62,13 +72,20 @@ void XWalkExtensionClient::Initialize() { std::string XWalkExtensionClient::CreateInstance( v8::Handle context, const std::string& extension_name, InstanceHandler* handler) { - void* ret = ecore_main_loop_thread_safe_call_sync( - CreateInstanceInMainloop, - static_cast(const_cast(extension_name.data()))); - std::string* sp = static_cast(ret); - std::string instance_id = *sp; - delete sp; - + std::string instance_id; + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kSingleProcess)) { + void* ret = ecore_main_loop_thread_safe_call_sync( + CreateInstanceInMainloop, + static_cast(const_cast(extension_name.data()))); + std::string* sp = static_cast(ret); + instance_id = *sp; + delete sp; + } else { + RuntimeIPCClient* ipc = RuntimeIPCClient::GetInstance(); + instance_id =ipc->SendSyncMessage( + context, kMethodCreateInstance, "", extension_name.data()); + } handlers_[instance_id] = handler; return instance_id; } @@ -105,8 +122,16 @@ std::string XWalkExtensionClient::SendSyncMessageToNative( std::string XWalkExtensionClient::GetAPIScript( v8::Handle context, const std::string& extension_name) { - XWalkExtensionServer* server = XWalkExtensionServer::GetInstance(); - return server->GetAPIScript(extension_name); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kSingleProcess)) { + XWalkExtensionServer* server = XWalkExtensionServer::GetInstance(); + return server->GetAPIScript(extension_name); + } else { + RuntimeIPCClient* ipc = RuntimeIPCClient::GetInstance(); + std::string reply = ipc->SendSyncMessage( + context, kMethodGetAPIScript, "", extension_name.data()); + return reply; + } } void XWalkExtensionClient::OnReceivedIPCMessage( diff --git a/tizen/extensions/renderer/xwalk_extension_client.h b/tizen/extensions/renderer/xwalk_extension_client.h index 5b98ee9..7cb0c11 100644 --- a/tizen/extensions/renderer/xwalk_extension_client.h +++ b/tizen/extensions/renderer/xwalk_extension_client.h @@ -28,7 +28,7 @@ class XWalkExtensionClient { XWalkExtensionClient(); virtual ~XWalkExtensionClient(); - void Initialize(); + void Initialize(v8::Handle context); std::string CreateInstance(v8::Handle context, const std::string& extension_name, diff --git a/tizen/extensions/renderer/xwalk_extension_renderer_controller.cc b/tizen/extensions/renderer/xwalk_extension_renderer_controller.cc index 6c8dd11..982ab23 100644 --- a/tizen/extensions/renderer/xwalk_extension_renderer_controller.cc +++ b/tizen/extensions/renderer/xwalk_extension_renderer_controller.cc @@ -80,7 +80,7 @@ void XWalkExtensionRendererController::DidCreateScriptContext( "objecttools", std::unique_ptr(new ObjectToolsModule)); - extensions_client_->Initialize(); + extensions_client_->Initialize(context); CreateExtensionModules(extensions_client_.get(), module_system); module_system->Initialize(); @@ -100,14 +100,14 @@ void XWalkExtensionRendererController::WillReleaseScriptContext( } void XWalkExtensionRendererController::OnReceivedIPCMessage( - const Ewk_IPC_Wrt_Message_Data* data) { + const Wrt_Message_Data* data) { - Eina_Stringshare* type = ewk_ipc_wrt_message_data_type_get(data); + Eina_Stringshare* type = data->GetType(); #define TYPE_BEGIN(x) (!strncmp(type, x, strlen(x))) if (TYPE_BEGIN("xwalk://")) { - Eina_Stringshare* id = ewk_ipc_wrt_message_data_id_get(data); - Eina_Stringshare* msg = ewk_ipc_wrt_message_data_value_get(data); + Eina_Stringshare* id = data->GetId(); + Eina_Stringshare* msg = data->GetValue(); extensions_client_->OnReceivedIPCMessage(id, msg); eina_stringshare_del(id); eina_stringshare_del(msg); @@ -121,7 +121,7 @@ void XWalkExtensionRendererController::OnReceivedIPCMessage( } void XWalkExtensionRendererController::InitializeExtensionClient() { - extensions_client_->Initialize(); +// extensions_client_->Initialize(); } void XWalkExtensionRendererController::LoadUserExtensions( diff --git a/tizen/extensions/renderer/xwalk_extension_renderer_controller.h b/tizen/extensions/renderer/xwalk_extension_renderer_controller.h index 95e3145..8fe5ff4 100644 --- a/tizen/extensions/renderer/xwalk_extension_renderer_controller.h +++ b/tizen/extensions/renderer/xwalk_extension_renderer_controller.h @@ -6,12 +6,11 @@ #ifndef XWALK_EXTENSIONS_RENDERER_XWALK_EXTENSION_RENDERER_CONTROLLER_H_ #define XWALK_EXTENSIONS_RENDERER_XWALK_EXTENSION_RENDERER_CONTROLLER_H_ -#include -#include #include #include #include +#include "common/wrt_message_data.h" namespace extensions { @@ -25,7 +24,7 @@ class XWalkExtensionRendererController { void DidCreateScriptContext(v8::Handle context); void WillReleaseScriptContext(v8::Handle context); - void OnReceivedIPCMessage(const Ewk_IPC_Wrt_Message_Data* data); + void OnReceivedIPCMessage(const Wrt_Message_Data* data); void InitializeExtensionClient(); void LoadUserExtensions(const std::string app_path); diff --git a/tizen/renderer/injected_bundle.cc b/tizen/renderer/injected_bundle.cc index a030975..cce38e6 100644 --- a/tizen/renderer/injected_bundle.cc +++ b/tizen/renderer/injected_bundle.cc @@ -15,8 +15,6 @@ */ #include -#include -#include #include #include #include @@ -30,6 +28,7 @@ #include "common/profiler.h" #include "common/resource_manager.h" #include "common/string_utils.h" +#include "common/wrt_message_data.h" #include "extensions/renderer/runtime_ipc_client.h" #include "extensions/renderer/widget_module.h" #include "extensions/renderer/xwalk_extension_renderer_controller.h" @@ -173,7 +172,7 @@ extern "C" void DynamicDatabaseAttach(int /*attach*/) { // LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!"; } -extern "C" void DynamicOnIPCMessage(const Ewk_IPC_Wrt_Message_Data& data) { +extern "C" void DynamicOnIPCMessage(const Wrt_Message_Data& data) { SCOPE_PROFILE(); extensions::XWalkExtensionRendererController& controller = extensions::XWalkExtensionRendererController::GetInstance(); diff --git a/tizen/wrt/chromium_wrt.gyp b/tizen/wrt/chromium_wrt.gyp new file mode 100644 index 0000000..4680117 --- /dev/null +++ b/tizen/wrt/chromium_wrt.gyp @@ -0,0 +1,55 @@ +{ + 'includes':[ + '../build/common.gypi', + ], + 'targets': [ + { + 'target_name': 'chromium_wrt_shared', + 'type': 'shared_library', + 'sources': [ + "dynamicplugin.cc", + "dynamicplugin.h", + "v8widget.cc", + "v8widget.h", + "wrtwidget.cc", + "wrtwidget.h", + "wrt_dynamicplugin.cc", + "wrt_dynamicplugin.h", + "wrt_file_protocol_handler.cc", + "wrt_file_protocol_handler.h", + "wrt_widget_host.cc", + "wrt_widget_host.h", + ], + 'cflags': [ + '-fvisibility=default', + ], + 'variables': { + 'packages': [ + 'chromium-efl', + 'elementary', + ], + }, + 'include_dirs': [ + '.', + '../', + '../..', + '../tizen', + '<(libchromiumcontent_src_dir)', + '<(SHARED_INTERMEDIATE_DIR)', + '<(libchromiumcontent_src_dir)/gen', + '<(libchromiumcontent_src_dir)/third_party/skia/include/config', + '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + ], + 'direct_dependent_settings': { +# 'libraries': [ +# '-lchromium_wrt_shared', +# ], + 'variables': { + 'packages': [ + 'jsoncpp', + ], + }, + }, + }, # end of target 'xwalk_extension_static' + ], # end of targets +} diff --git a/tizen/wrt/dynamicplugin.cc b/tizen/wrt/dynamicplugin.cc new file mode 100644 index 0000000..9512d3e --- /dev/null +++ b/tizen/wrt/dynamicplugin.cc @@ -0,0 +1,89 @@ +// Copyright 2014 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "dynamicplugin.h" + +#include + +#include "base/command_line.h" +#include "base/logging.h" + +namespace { +const char* const VERSION_FUNCTION = "DynamicPluginVersion"; +const char* const START_SESSION_FUNCTION = "DynamicPluginStartSession"; +const char* const STOP_SESSION_FUNCTION = "DynamicPluginStopSession"; +} + +DynamicPlugin::DynamicPlugin() + : m_handle_(0), + m_version_(0), + m_versionFunction_(0), + m_startSession_(0), + m_stopSession_(0) { + const base::CommandLine& commandLine = + *base::CommandLine::ForCurrentProcess(); + std::string injectedBundlePath = + commandLine.GetSwitchValueASCII("injected-bundle-path"); + if (injectedBundlePath.empty()) { + return; + } + m_handle_ = dlopen(injectedBundlePath.c_str(), RTLD_LAZY); + if (!m_handle_) { + LOG(ERROR) << "No handle to " << injectedBundlePath.c_str() << " " + << dlerror() << "\n"; + return; + } + + *reinterpret_cast(&m_versionFunction_) = + dlsym(m_handle_, VERSION_FUNCTION); + if (!m_versionFunction_) { + LOG(ERROR) << "No " << VERSION_FUNCTION << " symbol found!\n"; + } else { + m_version_ = m_versionFunction_(); + if (m_version_ != 0 && m_version_ != 1) { + LOG(ERROR) << "Unknown plugin version: " << m_version_ << "!\n"; + return; + } + } + + *reinterpret_cast(&m_startSession_) = + dlsym(m_handle_, START_SESSION_FUNCTION); + if (!m_startSession_) { + LOG(ERROR) << "No " << START_SESSION_FUNCTION << " symbol found!\n"; + } + *reinterpret_cast(&m_stopSession_) = + dlsym(m_handle_, STOP_SESSION_FUNCTION); + if (!m_stopSession_) { + LOG(ERROR) << "No " << STOP_SESSION_FUNCTION << " symbol found!\n"; + } +} + +void DynamicPlugin::startSession(const char* sessionId, + v8::Handle context, + int routingHandle, + const void* sessionBlob) { + if (!m_startSession_) + return; + + m_startSession_(sessionId, context, routingHandle, sessionBlob); +} + +void DynamicPlugin::stopSession(const char* sessionId, + v8::Handle context) { + if (!m_stopSession_) + return; + + m_stopSession_(sessionId, context); +} + +DynamicPlugin::~DynamicPlugin() { + if (m_handle_) + dlclose(m_handle_); +} + +DynamicPlugin& DynamicPlugin::instance() { + static DynamicPlugin dynamicPlugin; + return dynamicPlugin; +} + diff --git a/tizen/wrt/dynamicplugin.h b/tizen/wrt/dynamicplugin.h new file mode 100644 index 0000000..46a1963 --- /dev/null +++ b/tizen/wrt/dynamicplugin.h @@ -0,0 +1,46 @@ +// Copyright 2014, 2016 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_DYNAMICPLUGIN_H_ +#define WRT_DYNAMICPLUGIN_H_ + +#include +#include "base/macros.h" +#include "v8/include/v8.h" + +typedef unsigned int (*versionFunction)(void); + +typedef void (*startSessionFunction)(const char* sessionId, + v8::Handle context, + int routingHandle, + const void* sessionBlob); + +typedef void (*stopSessionFunction)(const char* sessionId, + v8::Handle context); + +class DynamicPlugin { + public: + void startSession(const char* sessionId, + v8::Handle context, + int routingHandle, + const void* sessionBlob); + void stopSession(const char* sessionId, v8::Handle context); + + virtual ~DynamicPlugin(); + + static DynamicPlugin& instance(); + + protected: + DynamicPlugin(); + DynamicPlugin(const DynamicPlugin&); + DynamicPlugin& operator=(const DynamicPlugin&); + + void* m_handle_; + unsigned int m_version_; + versionFunction m_versionFunction_; + startSessionFunction m_startSession_; + stopSessionFunction m_stopSession_; +}; + +#endif // WRT_DYNAMICPLUGIN_H_ diff --git a/tizen/wrt/v8widget.cc b/tizen/wrt/v8widget.cc new file mode 100644 index 0000000..ef721b8 --- /dev/null +++ b/tizen/wrt/v8widget.cc @@ -0,0 +1,92 @@ +// Copyright 2014, 2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "v8widget.h" + +#include "base/logging.h" +#include "dynamicplugin.h" +#if defined(OS_TIZEN_TV_PRODUCT) +#include "wrt/hbbtv_dynamicplugin.h" +#endif +#include "wrt_dynamicplugin.h" + +V8Widget::V8Widget(Type type) : type_(type) {} + +V8Widget::~V8Widget() {} + +void V8Widget::SetId(const std::string& id) { + id_ = id; +} + +V8Widget::Type V8Widget::GetType() const { + return type_; +} + +bool V8Widget::ParseUrl(const GURL& url, + GURL& new_url, + bool& is_decrypted_file) { + if (!id_.empty()) { + std::string old_url = url.possibly_invalid_spec(); + std::string s_new_url; + if (type_ == V8Widget::Type::WRT) + WrtDynamicPlugin::instance().parseURL(&old_url, &s_new_url, id_.c_str(), + &is_decrypted_file); + +#if defined(OS_TIZEN_TV_PRODUCT) + if (type_ == V8Widget::Type::HBBTV) + HbbTVDynamicPlugin::instance().parseURL(&old_url, &s_new_url, id_.c_str(), + &is_decrypted_file); +#endif + + if (!s_new_url.empty()) { + new_url = GURL(s_new_url); + return true; + } + } + return false; +} + +#if defined(OS_TIZEN_TV_PRODUCT) +bool V8Widget::GetFileDecryptedDataBuffer(const GURL& url, + std::vector* data) { + if (!id_.empty()) { + std::string str_url = url.possibly_invalid_spec(); + if (type_ == V8Widget::Type::WRT) + return WrtDynamicPlugin::instance().getFileDecryptedDataBuffer(&str_url, + data); + + if (type_ == V8Widget::Type::HBBTV) + return HbbTVDynamicPlugin::instance().getFileDecryptedDataBuffer(&str_url, + data); + } + return false; +} +#endif + +void V8Widget::StopSession(v8::Handle context) { + if (!id_.empty() && !context.IsEmpty()) { + if (type_ == V8Widget::Type::WRT) + WrtDynamicPlugin::instance().stopSession(id_.c_str(), context); + +#if defined(OS_TIZEN_TV_PRODUCT) + if (type_ == V8Widget::Type::HBBTV) + HbbTVDynamicPlugin::instance().stopSession(id_.c_str(), context); +#endif + } +} + +void V8Widget::StartSession(v8::Handle context, + int routingHandle, + const void* sessionBlob) { + if (!id_.empty() && !context.IsEmpty()) { + if (type_ == V8Widget::Type::WRT) + NOTREACHED(); + +#if defined(OS_TIZEN_TV_PRODUCT) + if (type_ == V8Widget::Type::HBBTV) + HbbTVDynamicPlugin::instance().startSession(id_.c_str(), context, + routingHandle, sessionBlob); +#endif + } +} diff --git a/tizen/wrt/v8widget.h b/tizen/wrt/v8widget.h new file mode 100644 index 0000000..2b843a3 --- /dev/null +++ b/tizen/wrt/v8widget.h @@ -0,0 +1,41 @@ +// Copyright 2014, 2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_V8WIDGET_H_ +#define WRT_V8WIDGET_H_ + +#include + +#include "content/public/renderer/render_thread_observer.h" +#include "url/gurl.h" +#include "v8/include/v8.h" + +// Have to be created on the RenderThread. +class V8Widget { + public: + enum class Type { HBBTV, WRT }; + + explicit V8Widget(Type type); + virtual ~V8Widget() = 0; + + void SetId(const std::string& id); + Type GetType() const; + + virtual void StartSession(v8::Handle, + int routingHandle, + const void* sessionBlob); + + virtual void StopSession(v8::Handle); + + bool ParseUrl(const GURL& url, GURL& new_url, bool& is_decrypted_file); + +#if defined(OS_TIZEN_TV_PRODUCT) + bool GetFileDecryptedDataBuffer(const GURL& url, std::vector* data); +#endif + protected: + std::string id_; + Type type_; +}; + +#endif // WRT_V8WIDGET_H_ diff --git a/tizen/wrt/wrt_dynamicplugin.cc b/tizen/wrt/wrt_dynamicplugin.cc new file mode 100644 index 0000000..68cf087 --- /dev/null +++ b/tizen/wrt/wrt_dynamicplugin.cc @@ -0,0 +1,164 @@ +// Copyright 2014 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "wrt_dynamicplugin.h" + +#include + +#include "base/command_line.h" +#include "base/logging.h" + +namespace { +const char* const URL_PARSING_FUNCTION = "DynamicUrlParsing"; +const char* const SET_WIDGET_INFO_FUNCTION = "DynamicSetWidgetInfo"; +const char* const DATABASE_ATTACH_FUNCTION = "DynamicDatabaseAttach"; +#if defined(OS_TIZEN_TV_PRODUCT) +const char* const TVURL_PARSING_FUNCTION = "DynamicTVUrlParsing"; +const char* const GET_FILEDECRYPTED_DATABUFFER = + "DynamicGetFileDecryptedDataBuffer"; +#endif + +typedef void (*startSessionFun_v0)(const char* tizen_app_id, + v8::Handle context, + int routingHandle, + double scaleFactor, + const char* encodedBundle, + const char* theme, + const char* baseURL); +} // namespace + +WrtDynamicPlugin::WrtDynamicPlugin() + : DynamicPlugin(), + m_parseURL_(0), + m_setWidgetInfo_(0), + m_databaseAttach_(0), +#if defined(OS_TIZEN_TV_PRODUCT) + m_getFileDecryptedDataBuffer_(0), + m_parseTVURL_(0), +#endif + m_onIPCMessage_(0) { + *reinterpret_cast(&m_parseURL_) = + dlsym(m_handle_, URL_PARSING_FUNCTION); + if (!m_parseURL_) { + LOG(ERROR) << "No " << URL_PARSING_FUNCTION << " symbol found!\n"; + } + *reinterpret_cast(&m_setWidgetInfo_) = + dlsym(m_handle_, SET_WIDGET_INFO_FUNCTION); + if (!m_setWidgetInfo_) { + LOG(ERROR) << "No " << SET_WIDGET_INFO_FUNCTION << " symbol found!"; + } + *reinterpret_cast(&m_databaseAttach_) = + dlsym(m_handle_, DATABASE_ATTACH_FUNCTION); + if (!m_databaseAttach_) { + LOG(ERROR) << "No " << DATABASE_ATTACH_FUNCTION << " symbol found!\n"; + return; + } + *reinterpret_cast(&m_onIPCMessage_) = + dlsym(m_handle_, "DynamicOnIPCMessage"); + if (!m_onIPCMessage_) { + LOG(ERROR) << "No DynamicOnIPCMessage symbol found!\n"; + } + m_databaseAttach_(1); + +#if defined(OS_TIZEN_TV_PRODUCT) + *reinterpret_cast(&m_parseTVURL_) = + dlsym(m_handle_, TVURL_PARSING_FUNCTION); + if (!m_parseTVURL_) { + LOG(ERROR) << "No " << TVURL_PARSING_FUNCTION << " symbol found!\n"; + } + *reinterpret_cast(&m_getFileDecryptedDataBuffer_) = + dlsym(m_handle_, GET_FILEDECRYPTED_DATABUFFER); + if (!m_getFileDecryptedDataBuffer_) { + LOG(ERROR) << "No " << GET_FILEDECRYPTED_DATABUFFER << " symbol found!\n"; + } +#endif +} + +void WrtDynamicPlugin::startSession(const char* tizen_app_id, + v8::Handle context, + int routingHandle, + double scaleFactor, + const char* encodedBundle, + const char* theme, + const char* baseURL) { + if (!m_startSession_ || !m_databaseAttach_) + return; + switch (m_version_) { + case 0: { + auto startSession_v0 = + reinterpret_cast(m_startSession_); + startSession_v0(tizen_app_id, context, routingHandle, scaleFactor, + encodedBundle, theme, baseURL); + break; + } + case 1: { + DynamicPlugin::startSession(tizen_app_id, context, routingHandle, + baseURL); + break; + } + default: + return; + } +} + +void WrtDynamicPlugin::stopSession(const char* tizen_app_id, + v8::Handle context) { + if (!m_stopSession_ || !m_databaseAttach_) + return; + DynamicPlugin::stopSession(tizen_app_id, context); +} + +void WrtDynamicPlugin::parseURL(std::string* old_url, + std::string* new_url, + const char* tizen_app_id, + bool* is_decrypted_file) { +#if defined(OS_TIZEN_TV_PRODUCT) + if (!m_databaseAttach_) + return; + if (m_parseTVURL_) { + m_parseTVURL_(old_url, new_url, tizen_app_id, is_decrypted_file); + return; + } + if (m_parseURL_) { + m_parseURL_(old_url, new_url, tizen_app_id); + *is_decrypted_file = false; + } +#else + if (!m_parseURL_ || !m_databaseAttach_) + return; + m_parseURL_(old_url, new_url, tizen_app_id); +#endif +} + +#if defined(OS_TIZEN_TV_PRODUCT) +bool WrtDynamicPlugin::getFileDecryptedDataBuffer(const std::string* url, + std::vector* data) { + if (!m_getFileDecryptedDataBuffer_) + return false; + return m_getFileDecryptedDataBuffer_(url, data); +} +#endif + +void WrtDynamicPlugin::setWidgetInfo(const std::string& tizen_app_id) { + if (!m_setWidgetInfo_) + return; + m_setWidgetInfo_(tizen_app_id.c_str()); +} + +WrtDynamicPlugin::~WrtDynamicPlugin() { + if (m_databaseAttach_) + m_databaseAttach_(0); +} + +WrtDynamicPlugin& WrtDynamicPlugin::instance() { + static WrtDynamicPlugin dynamicPlugin; + return dynamicPlugin; +} + +void WrtDynamicPlugin::messageReceived(const Wrt_Message_Data& data) { + if (!m_onIPCMessage_) + return; + + m_onIPCMessage_(data); +} diff --git a/tizen/wrt/wrt_dynamicplugin.h b/tizen/wrt/wrt_dynamicplugin.h new file mode 100644 index 0000000..9554b4d --- /dev/null +++ b/tizen/wrt/wrt_dynamicplugin.h @@ -0,0 +1,71 @@ +// Copyright 2014 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_WRT_DYNAMICPLUGIN_H_ +#define WRT_WRT_DYNAMICPLUGIN_H_ + +#include +#include +#include "dynamicplugin.h" +#include "v8/include/v8.h" +#include "common/wrt_message_data.h" + +typedef void (*onIPCMessageFun)(const Wrt_Message_Data& data); +#if defined(OS_TIZEN_TV_PRODUCT) +typedef void (*TVParseUrlFun)(std::string* old_url, + std::string* new_url, + const char* tizen_app_id, + bool* is_decrypted_file); +typedef bool (*getFileDecryptedDataBufferFun)(const std::string* url, + std::vector* data); +#endif +typedef void (*parseUrlFun)(std::string* old_url, + std::string* new_url, + const char* tizen_app_id); +typedef void (*setWidgetInfoFun)(const char* tizen_app_id); +typedef void (*databaseAttachFun)(int databaseAttach); + +class WrtDynamicPlugin : public DynamicPlugin { + public: + void startSession(const char* tizen_app_id, + v8::Handle context, + int routingHandle, + double scaleFactor, + const char* encodedBundle, + const char* theme, + const char* baseURL); + void stopSession(const char* tizen_app_id, v8::Handle context); + + void parseURL(std::string* old_url, + std::string* new_url, + const char* tizen_app_id, + bool* is_decrypted_file); + +#if defined(OS_TIZEN_TV_PRODUCT) + bool getFileDecryptedDataBuffer(const std::string* url, + std::vector* data); +#endif + + void setWidgetInfo(const std::string& tizen_app_id); + void messageReceived(const Wrt_Message_Data& data); + + static WrtDynamicPlugin& instance(); + ~WrtDynamicPlugin() override; + + private: + WrtDynamicPlugin(); + + parseUrlFun m_parseURL_; + setWidgetInfoFun m_setWidgetInfo_; + databaseAttachFun m_databaseAttach_; +#if defined(OS_TIZEN_TV_PRODUCT) + getFileDecryptedDataBufferFun m_getFileDecryptedDataBuffer_; + TVParseUrlFun m_parseTVURL_; +#endif + onIPCMessageFun m_onIPCMessage_; + + DISALLOW_COPY_AND_ASSIGN(WrtDynamicPlugin); +}; + +#endif // WRT_WRT_DYNAMICPLUGIN_H_ diff --git a/tizen/wrt/wrt_file_protocol_handler.cc b/tizen/wrt/wrt_file_protocol_handler.cc new file mode 100644 index 0000000..5a8ba30 --- /dev/null +++ b/tizen/wrt/wrt_file_protocol_handler.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2014,2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "wrt_file_protocol_handler.h" + +#include "base/command_line.h" +//#include "common/content_switches_efl.h" +#include "content/public/common/content_client.h" +#include "content/public/renderer/content_renderer_client.h" +#include "net/base/filename_util.h" +#include "net/url_request/url_request_data_job.h" +#include "net/url_request/url_request_error_job.h" +#include "net/url_request/url_request_file_dir_job.h" +#include "net/url_request/url_request_file_job.h" +#include "net/url_request/url_request_simple_job.h" +#include "wrt_dynamicplugin.h" + +namespace net { + +class WrtURLRequestDataJob : public URLRequestSimpleJob { + public: + /* LCOV_EXCL_START */ + WrtURLRequestDataJob(URLRequest* request, + NetworkDelegate* network_delegate, + const GURL& data_url) + : URLRequestSimpleJob(request, network_delegate) { + data_url_ = data_url; + } + /* LCOV_EXCL_STOP */ + + int GetData(std::string* mime_type, + std::string* charset, + std::string* data, + const CompletionCallback& callback) const override; + + private: + ~WrtURLRequestDataJob() override {} // LCOV_EXCL_LINE + GURL data_url_; +}; + +/* LCOV_EXCL_START */ +int WrtURLRequestDataJob::GetData(std::string* mime_type, + std::string* charset, + std::string* data, + const CompletionCallback& callback) const { + if (!data_url_.is_valid()) + return ERR_INVALID_URL; + + return URLRequestDataJob::BuildResponse(data_url_, mime_type, charset, data, + nullptr); +} + +bool WrtFileProtocolHandler::GetWrtParsedUrl(const GURL& url, + GURL& parsed_url) const { + static std::string tizen_app_id = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + "widget-id"); + if (!tizen_app_id.empty()) { + bool is_decrypted_file; + std::string url_str = url.possibly_invalid_spec(); + std::string parsed_url_str; + WrtDynamicPlugin::instance().parseURL( + &url_str, &parsed_url_str, tizen_app_id.c_str(), &is_decrypted_file); + if (!parsed_url_str.empty()) { + parsed_url = GURL(parsed_url_str); + return true; + } + } + return false; +} +/* LCOV_EXCL_STOP */ + +URLRequestJob* WrtFileProtocolHandler::MaybeCreateJob( + URLRequest* request, + NetworkDelegate* network_delegate) const { + GURL parsed_url; + if (GetWrtParsedUrl(request->url(), parsed_url)) { + // Data URI scheme for WRT encryption content + if (parsed_url.SchemeIs(url::kDataScheme)) + return new WrtURLRequestDataJob(request, network_delegate, parsed_url); + } else + parsed_url = request->url(); + + base::FilePath file_path; + const bool is_file = FileURLToFilePath(parsed_url, &file_path); + + // Check file access permissions. + if (!network_delegate || + !network_delegate->CanAccessFile(*request, file_path)) { + return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED); + } + + // We need to decide whether to create URLRequestFileJob for file access or + // URLRequestFileDirJob for directory access. To avoid accessing the + // filesystem, we only look at the path string here. + // The code in the URLRequestFileJob::Start() method discovers that a path, + // which doesn't end with a slash, should really be treated as a directory, + // and it then redirects to the URLRequestFileDirJob. + if (is_file && file_path.EndsWithSeparator() && file_path.IsAbsolute()) { + return new URLRequestFileDirJob(request, network_delegate, file_path); + } + + // Use a regular file request job for all non-directories (including invalid + // file names). + return new URLRequestFileJob(request, network_delegate, file_path, + file_task_runner_); +} + +} // namespace diff --git a/tizen/wrt/wrt_file_protocol_handler.h b/tizen/wrt/wrt_file_protocol_handler.h new file mode 100644 index 0000000..6fab49f --- /dev/null +++ b/tizen/wrt/wrt_file_protocol_handler.h @@ -0,0 +1,46 @@ +// Copyright (c) 2014,2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_FILE_PROTOCOL_HANDLER +#define WRT_FILE_PROTOCOL_HANDLER + +#include "base/memory/ref_counted.h" +#include "net/url_request/url_request_job_factory.h" + +class GURL; + +namespace base { +class TaskRunner; +} + +namespace net { + +class NetworkDelegate; +class URLRequestJob; + +class WrtFileProtocolHandler + : public URLRequestJobFactory::ProtocolHandler { + public: + explicit WrtFileProtocolHandler( + const scoped_refptr& file_task_runner) + : file_task_runner_(file_task_runner) {} + ~WrtFileProtocolHandler() override {} + URLRequestJob* MaybeCreateJob( + URLRequest* request, + NetworkDelegate* network_delegate) const override; + /* LCOV_EXCL_START */ + bool IsSafeRedirectTarget(const GURL& location) const override { + return false; + } + /* LCOV_EXCL_STOP */ + + private: + bool GetWrtParsedUrl(const GURL& url, GURL& parsed_url) const; + const scoped_refptr file_task_runner_; + DISALLOW_COPY_AND_ASSIGN(WrtFileProtocolHandler); +}; + +} // namespace net + +#endif // WRT_FILE_PROTOCOL_HANDLER diff --git a/tizen/wrt/wrt_widget_host.cc b/tizen/wrt/wrt_widget_host.cc new file mode 100644 index 0000000..d33c513 --- /dev/null +++ b/tizen/wrt/wrt_widget_host.cc @@ -0,0 +1,164 @@ +// Copyright (c) 2014,2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "wrt_widget_host.h" + +#include "base/lazy_instance.h" +//#include "common/render_messages_ewk.h" +#include "atom/common/api/api_messages.h" +#include "content/public/browser/browser_message_filter.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/resource_request_info.h" +//#include "ipc/ipc_message_macros.h" +//#include "ipc_message_start_ewk.h" +#include "net/url_request/url_request.h" +#include "url/gurl.h" + +namespace { +// TODO(z.kostrzewa) I would prefer not make it a singleton, check out +// if it can't be a member of ContentMainDelegateEfl (but keep the static +// getter, maybe?). +base::LazyInstance > g_wrt_widget_host = + LAZY_INSTANCE_INITIALIZER; + +bool SendToAllRenderers(IPC::Message* message) { + bool result = false; + content::RenderProcessHost::iterator it = + content::RenderProcessHost::AllHostsIterator(); + while (!it.IsAtEnd()) { + if (it.GetCurrentValue()->Send(new IPC::Message(*message))) + result = true; + it.Advance(); + } + delete message; + return result; +} + +bool SendToRenderer(int renderer_id, IPC::Message* message) { + return content::RenderProcessHost::FromID(renderer_id)->Send(message); +} +} + +class WrtWidgetHostMessageFilter : public content::BrowserMessageFilter { + public: + explicit WrtWidgetHostMessageFilter(WrtWidgetHost* wrt_widget_host); + + private: + ~WrtWidgetHostMessageFilter() override {} + bool OnMessageReceived(const IPC::Message& message) override; + + WrtWidgetHost* wrt_widget_host_; +}; + +WrtWidgetHostMessageFilter::WrtWidgetHostMessageFilter( + WrtWidgetHost* wrt_widget_host) + : content::BrowserMessageFilter(ShellMsgStart), + wrt_widget_host_(wrt_widget_host) { +} + +bool WrtWidgetHostMessageFilter::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WrtWidgetHostMessageFilter, message) + IPC_MESSAGE_FORWARD(WrtMsg_ParseUrlResponse, wrt_widget_host_, WrtWidgetHost::OnUrlRetrieved) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +WrtWidgetHost* WrtWidgetHost::Get() { + // TODO(z.kostrzewa) LazyInstance is thread-safe but creating + // WrtWidgetHost is not - make it thread-safe. + if (!g_wrt_widget_host.Get().get()) + g_wrt_widget_host.Get().reset(new WrtWidgetHost); + return g_wrt_widget_host.Get().get(); +} + +WrtWidgetHost::WrtWidgetHost() + : message_filter_(new WrtWidgetHostMessageFilter(this)) { +} + +WrtWidgetHost::~WrtWidgetHost() {} + +void WrtWidgetHost::GetUrlForRequest( + net::URLRequest* request, + base::Callback callback) { + // TODO(z.kostrzewa) Check on which thread(s) callbacks_ is touched + // and provide synchronization if required (either via a lock or + // by assuring that it is referenced only on one thread) + int callback_id = callback_id_generator_.GetNext(); + callbacks_[callback_id] = callback; + + int renderer_id, frame_id; + if (content::ResourceRequestInfo::GetRenderFrameForRequest(request, &renderer_id, + &frame_id)) + if (SendToRenderer(renderer_id, new WrtMsg_ParseUrl(callback_id, request->url()))) + return; + + callbacks_.erase(callback_id); + callback.Run(GURL()); +} + +void WrtWidgetHost::SendWrtMessage( + const Wrt_Message_Data& message) { + SendToAllRenderers(new WrtMsg_SendWrtMessage(message)); +} + +// It's only used by the wrt_file_protocol_handler which is not going to be used in the future +// Candidate for deletion. +bool WrtWidgetHost::InWrt() const { + return false; +} + +// It's only used by the wrt_file_protocol_handler which is not going to be used in the future +// Candidate for deletion. +std::string WrtWidgetHost::TizenAppId() const { +#if defined(OS_TIZEN_TV_PRODUCT) + return tizen_app_id_; +#else + return std::string(); +#endif +} + +void WrtWidgetHost::OnUrlRetrieved(int callback_id, const GURL& url) { + callbacks_type::iterator it = callbacks_.find(callback_id); + if (callbacks_.end() == it) + return; + + callbacks_type::mapped_type callback = it->second; + callbacks_.erase(callback_id); + callback.Run(url); +} + +#if defined(OS_TIZEN_TV_PRODUCT) +void WrtWidgetHost::SetTizenAppId(const std::string& tizen_app_id) { + tizen_app_id_ = tizen_app_id; +} + +bool WrtWidgetHost::ShouldAllowRequest(const net::URLRequest& request) { + if (tizen_app_id_.empty() || !check_accessiable_path_callback_) + return true; + + return check_accessiable_path_callback_->TriggerCallback(request.url().spec(), + tizen_app_id_); +} + +bool EwkCheckAccessiablePathCallback::TriggerCallback( + const std::string& url_spec, + const std::string& tizen_app_id) const { + if (!callback_) + return true; + + Eina_Bool result = + (*callback_)(tizen_app_id.c_str(), url_spec.c_str(), user_data_); + return result == EINA_TRUE; +} + +void WrtWidgetHost::SetCheckAccessiablePathCallback( + Ewk_Context_Check_Accessible_Path_Callback callback, + void* user_data) { + check_accessiable_path_callback_.reset( + new EwkCheckAccessiablePathCallback(callback, user_data)); +} +#endif + diff --git a/tizen/wrt/wrt_widget_host.h b/tizen/wrt/wrt_widget_host.h new file mode 100644 index 0000000..11161da --- /dev/null +++ b/tizen/wrt/wrt_widget_host.h @@ -0,0 +1,89 @@ +// Copyright (c) 2014,2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_HOST_H +#define WRT_HOST_H + +#include +#include + +#include "base/atomic_sequence_num.h" +#include "base/callback.h" +#include "content/public/browser/browser_message_filter.h" +#include "common/wrt_message_data.h" +#if defined(OS_TIZEN_TV_PRODUCT) +#include "public/ewk_context_product.h" +#endif + +namespace net { +class URLRequest; +} + +class GURL; + +class WrtWidgetHostMessageFilter; + +#if defined(OS_TIZEN_TV_PRODUCT) +class EwkCheckAccessiablePathCallback { + public: + EwkCheckAccessiablePathCallback( + Ewk_Context_Check_Accessible_Path_Callback callback, + void* user_data) + : callback_(callback), user_data_(user_data) {} + bool TriggerCallback(const std::string& url_spec, + const std::string& tizen_app_id) const; + + private: + Ewk_Context_Check_Accessible_Path_Callback callback_; + void* user_data_; +}; +#endif + +class WrtWidgetHost { + public: + static WrtWidgetHost* Get(); + + ~WrtWidgetHost(); + + void GetUrlForRequest(net::URLRequest* request, + base::Callback callback); + + void SendWrtMessage(const Wrt_Message_Data& message); + + bool InWrt() const; + + std::string TizenAppId() const; + +#if defined(OS_TIZEN_TV_PRODUCT) + void SetTizenAppId(const std::string& tizen_app_id); + bool ShouldAllowRequest(const net::URLRequest& request); + + void SetCheckAccessiablePathCallback( + Ewk_Context_Check_Accessible_Path_Callback callback, + void* user_data); +#endif + + private: + friend class WrtWidgetHostMessageFilter; + + typedef std::map > callbacks_type; + + WrtWidgetHost(); + + void OnUrlRetrieved(int callback_id, const GURL& url); + + scoped_refptr message_filter_; + base::AtomicSequenceNumber callback_id_generator_; + callbacks_type callbacks_; + +#if defined(OS_TIZEN_TV_PRODUCT) + std::string tizen_app_id_; + std::unique_ptr check_accessiable_path_callback_; +#endif + + DISALLOW_COPY_AND_ASSIGN(WrtWidgetHost); +}; + + +#endif diff --git a/tizen/wrt/wrtwidget.cc b/tizen/wrt/wrtwidget.cc new file mode 100644 index 0000000..6c877c6 --- /dev/null +++ b/tizen/wrt/wrtwidget.cc @@ -0,0 +1,97 @@ +// Copyright 2014, 2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "wrtwidget.h" + +//#include "common/render_messages_ewk.h" +#include "atom/common/api/api_messages.h" +#include "content/public/renderer/render_thread.h" +#include "ipc/ipc_sync_channel.h" +#include "wrt_dynamicplugin.h" + +// TODO(z.kostrzewa) +// Why it can't be implemented as IPC::ChannelProxy::MessageFilter (?) +// Tried that and it seems that Observer starts receiving messages earlier than +// MessageFilter what is crucial for message that sets widget handle +class WrtRenderThreadObserver : public content::RenderThreadObserver { + public: + explicit WrtRenderThreadObserver(WrtWidget* wrt_widget) + : wrt_widget_(wrt_widget), + channel_(content::RenderThread::Get()->GetChannel()) + { } + + bool OnControlMessageReceived(const IPC::Message& message) override { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WrtRenderThreadObserver, message) + IPC_MESSAGE_FORWARD(WrtMsg_SendWrtMessage, wrt_widget_, WrtWidget::MessageReceived) + IPC_MESSAGE_HANDLER(WrtMsg_ParseUrl, ParseUrl) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; + } + + private: + void ParseUrl(int request_id, const GURL& url) { + GURL response; + bool is_decrypted_file = false; + wrt_widget_->ParseUrl(url, response, is_decrypted_file); + Send(new WrtMsg_ParseUrlResponse(request_id, response)); + } + + void Send(IPC::Message* message) { + if (channel_) + channel_->Send(message); + else + delete message; + } + + WrtWidget* wrt_widget_; + IPC::SyncChannel* channel_; +}; + +WrtWidget::WrtWidget() + : V8Widget(V8Widget::Type::WRT), + scale_(0), + observer_(new WrtRenderThreadObserver(this)) { + DCHECK(content::RenderThread::Get()) + << "WrtWidget must be constructed on the render thread"; +} + +WrtWidget::~WrtWidget() { + delete observer_; +} + +content::RenderThreadObserver* WrtWidget::GetObserver() { + return observer_; +} + +void WrtWidget::SetWidgetInfo(const std::string& tizen_app_id, + double scaleFactor, + const std::string& theme, + const std::string& encodedBundle) { + id_ = tizen_app_id; + scale_ = scaleFactor; + theme_ = theme; + encodedBundle_ = encodedBundle; + WrtDynamicPlugin::instance().setWidgetInfo(id_); +} + +bool WrtWidget::IsWidgetInfoSet() const { + return !id_.empty(); +} + +void WrtWidget::StartSession(v8::Handle context, + int routingHandle, + const void* sessionBlob) { + if (!id_.empty() && !context.IsEmpty()) { + WrtDynamicPlugin::instance().startSession( + id_.c_str(), context, routingHandle, scale_, encodedBundle_.c_str(), + theme_.c_str(), reinterpret_cast(sessionBlob)); + } +} + +void WrtWidget::MessageReceived(const Wrt_Message_Data& data) { + if (!id_.empty()) + WrtDynamicPlugin::instance().messageReceived(data); +} diff --git a/tizen/wrt/wrtwidget.h b/tizen/wrt/wrtwidget.h new file mode 100644 index 0000000..28af8cb --- /dev/null +++ b/tizen/wrt/wrtwidget.h @@ -0,0 +1,45 @@ +// Copyright 2014, 2015 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WRT_WRTWIDGET_H_ +#define WRT_WRTWIDGET_H_ + +#include + +#include "content/public/renderer/render_thread_observer.h" +#include "url/gurl.h" +#include "v8widget.h" +#include "common/wrt_message_data.h" + +class WrtRenderThreadObserver; + +// Have to be created on the RenderThread. +class WrtWidget : public V8Widget { + public: + WrtWidget(); + ~WrtWidget() override; + + content::RenderThreadObserver* GetObserver(); + + void SetWidgetInfo(const std::string& tizen_app_id, + double scaleFactor, + const std::string& theme, + const std::string& encodedBundle); + + bool IsWidgetInfoSet() const; + + void MessageReceived(const Wrt_Message_Data& data); + + void StartSession(v8::Handle, + int routingHandle, + const void* sessionBlob) override; + + private: + double scale_; + std::string encodedBundle_; + std::string theme_; + WrtRenderThreadObserver* observer_; +}; + +#endif // WRT_WRTWIDGET_H_ diff --git a/vendor/brightray/browser/browser_context.cc b/vendor/brightray/browser/browser_context.cc index 4ab07e4..2f709bb 100644 --- a/vendor/brightray/browser/browser_context.cc +++ b/vendor/brightray/browser/browser_context.cc @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. +#if defined(OS_TIZEN) +#include +#endif + #include "browser/browser_context.h" #include "browser/media/media_device_id_salt.h" @@ -40,6 +44,10 @@ using content::BrowserThread; namespace brightray { namespace { +#if defined(OS_TIZEN) +const char* const kDynamicPreloading = "DynamicPreloading"; +typedef void (*DynamicPreloading)(void); +#endif // Convert string to lower case and escape it. std::string MakePartitionName(const std::string& input) { @@ -105,16 +113,43 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) MakePartitionName(partition))); content::BrowserContext::Initialize(this, path_); - browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr(); -#if defined(OS_TIZEN) + auto command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch("injected-bundle-path")) { std::string injected_bundle_path = command_line->GetSwitchValueASCII("injected-bundle-path"); +#if defined(OS_TIZEN) + if (command_line->HasSwitch(switches::kSingleProcess)) { + // Preload injected bundle on here for process pool, + // because the zygote process doesn't exist in single process mode. + // The loaded handle must be closed on termination. + injected_bundle_handle_ = + dlopen(injected_bundle_path.c_str(), RTLD_LAZY); + if (!injected_bundle_handle_) { + LOG(ERROR) << "No handle to " << injected_bundle_path.c_str() + << " error " << dlerror(); + return; + } + + DynamicPreloading dp = reinterpret_cast( + dlsym(injected_bundle_handle_, kDynamicPreloading)); + if (dp) { + dp(); + } else { + LOG(ERROR) << "Fail to load symbol '" + << kDynamicPreloading + << "', error " << dlerror(); + } + } else { +#endif + //content::ZygoteHandle *handle = content::GetGenericZygote(); + //*handle->LoadInjectedBundlePath(injected_bundle_path); (*content::GetGenericZygote())-> LoadInjectedBundlePath(injected_bundle_path); - } +#if defined(OS_TIZEN) + } #endif + } } BrowserContext::~BrowserContext() { diff --git a/vendor/brightray/browser/browser_context.h b/vendor/brightray/browser/browser_context.h index 498fe99..f09b6f1 100644 --- a/vendor/brightray/browser/browser_context.h +++ b/vendor/brightray/browser/browser_context.h @@ -123,6 +123,10 @@ class BrowserContext : public base::RefCounted, base::FilePath path_; bool in_memory_; +#if defined(OS_TIZEN) + void* injected_bundle_handle_; +#endif + DevToolsNetworkControllerHandle network_controller_handle_; std::unique_ptr resource_context_; diff --git a/vendor/brightray/vendor/libchromiumcontent/src/base/trace_event/trace_event.h b/vendor/brightray/vendor/libchromiumcontent/src/base/trace_event/trace_event.h index f1a577f..0718f10 100644 --- a/vendor/brightray/vendor/libchromiumcontent/src/base/trace_event/trace_event.h +++ b/vendor/brightray/vendor/libchromiumcontent/src/base/trace_event/trace_event.h @@ -24,7 +24,7 @@ #include "base/trace_event/trace_log.h" #include "build/build_config.h" -#if defined(USE_EFL) +#if 0//defined(USE_EFL) #include "base/trace_event/ttrace.h" #endif diff --git a/wrt.gyp b/wrt.gyp index 6ea31d4..54377cf 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -15,6 +15,7 @@ '<(DEPTH)/tizen/loader/loader.gyp:wrt-loader', '<(DEPTH)/tizen/extensions/extensions.gyp:xwalk_extension_shared', '<(DEPTH)/tizen/renderer/injected_bundle.gyp:xwalk_injected_bundle', + '<(DEPTH)/tizen/wrt/chromium_wrt.gyp:chromium_wrt_shared', '<(DEPTH)/efl/build/system.gyp:ecore', '<(DEPTH)/efl/build/system.gyp:launchpad', '<(DEPTH)/efl/build/system.gyp:capi-appfw-application', @@ -104,6 +105,7 @@ ], 'include_dirs': [ '.', + 'tizen', 'chromium_src', 'vendor/brightray', 'vendor/native_mate',