"renderer/render_view_observer_efl.h",
"wrt/dynamicplugin.cc",
"wrt/dynamicplugin.h",
+ "wrt/v8widget.cc",
+ "wrt/v8widget.h",
+ "wrt/wrtwidget.cc",
+ "wrt/wrtwidget.h",
+ "wrt/wrt_dynamicplugin.cc",
+ "wrt/wrt_dynamicplugin.h",
"wrt/wrt_file_protocol_handler.cc",
"wrt/wrt_file_protocol_handler.h",
"wrt/wrt_widget_host.cc",
"wrt/wrt_widget_host.h",
- "wrt/wrtwidget.cc",
- "wrt/wrtwidget.h",
]
# FIXME: ewk_bringup definition should be removed.
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kInjectedBundlePath)) {
- wrt_widget_.reset(new WrtWidget);
- thread->AddObserver(wrt_widget_->GetObserver());
- wrt_url_parser_.reset(new WrtUrlParseImpl(wrt_widget_.get()));
-
- std::string tizen_app_id = command_line.GetSwitchValueASCII(
- switches::kTizenAppId);
- std::string theme = command_line.GetSwitchValueASCII(
- switches::kWidgetTheme);
- std::string encoded_bundle = command_line.GetSwitchValueASCII(
- switches::kWidgetEncodedBundle);
- std::string scale = command_line.GetSwitchValueASCII(
- switches::kWidgetScale);
+ std::string tizen_app_id =
+ command_line.GetSwitchValueASCII(switches::kTizenAppId);
+
+ WrtWidget* wrt_widget = new WrtWidget;
+ widget_.reset(wrt_widget);
+ thread->AddObserver(wrt_widget->GetObserver());
+ wrt_url_parser_.reset(new WrtUrlParseImpl(wrt_widget));
+
+ std::string theme =
+ command_line.GetSwitchValueASCII(switches::kWidgetTheme);
+ std::string encoded_bundle =
+ command_line.GetSwitchValueASCII(switches::kWidgetEncodedBundle);
+ std::string scale =
+ command_line.GetSwitchValueASCII(switches::kWidgetScale);
double scale_factor = 0;
base::StringToDouble(scale, &scale_factor);
- wrt_widget_->SetWidgetInfo(tizen_app_id, scale_factor,
- theme, encoded_bundle);
+ wrt_widget->SetWidgetInfo(tizen_app_id, scale_factor, theme,
+ encoded_bundle);
}
render_thread_observer_.reset(new RenderThreadObserverEfl(this));
#endif
}
-void ContentRendererClientEfl::WillSendRequest(
- blink::WebLocalFrame* frame,
- ui::PageTransition transition_type,
- const blink::WebURL& url,
- const url::Origin* initiator_origin,
- GURL* new_url,
- bool* attach_same_site_cookies) {
- if (wrt_widget_) {
- wrt_widget_->ParseUrl(url, *new_url);
- } else {
- *new_url = url;
- }
-}
+void ContentRendererClientEfl::WillSendRequest(blink::WebLocalFrame* frame,
+ ui::PageTransition transition_type,
+ const blink::WebURL& url,
+ const url::Origin* initiator_origin,
+ GURL* new_url,
+ bool* attach_same_site_cookies) {}
void ContentRendererClientEfl::DidCreateScriptContext(
blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int world_id) {
- const content::RenderView* render_view =
- content::RenderView::FromWebView(frame->View());
- if (wrt_widget_)
- wrt_widget_->StartSession(
- context, render_view->GetRoutingID(),
- frame->ToWebLocalFrame()->GetDocument().BaseURL().GetString().Utf8());
+ const content::RenderView* render_view = content::RenderView::FromWebView(
+ frame->View());
+ if (widget_) {
+ widget_->StartSession(context, render_view->GetRoutingID(),
+ frame->ToWebLocalFrame()
+ ->GetDocument()
+ .BaseURL()
+ .GetString()
+ .Utf8()
+ .c_str());
+ }
}
void ContentRendererClientEfl::WillReleaseScriptContext(
blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int world_id) {
- if (wrt_widget_)
- wrt_widget_->StopSession(context);
+ if (widget_)
+ widget_->StopSession(context);
}
bool ContentRendererClientEfl::HandleNavigation(
class Ewk_Wrt_Message_Data;
+class V8Widget;
class WrtUrlParseImpl;
-class WrtWidget;
-class ContentRendererClientEfl : public content::ContentRendererClient
-{
+class ContentRendererClientEfl : public content::ContentRendererClient {
public:
ContentRendererClientEfl();
~ContentRendererClientEfl();
private:
static void ApplyCustomMobileSettings(blink::WebView*);
- std::unique_ptr<WrtWidget> wrt_widget_;
+ std::unique_ptr<V8Widget> widget_;
std::unique_ptr<WrtUrlParseImpl> wrt_url_parser_;
std::unique_ptr<RenderThreadObserverEfl> render_thread_observer_;
std::unique_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
#include "net/url_request/url_request_intercepting_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "network_delegate_efl.h"
+#include "wrt/wrt_file_protocol_handler.h"
using net::SQLitePersistentCookieStore;
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
DCHECK(set_protocol);
+ // TODO(is46.kim): It's better to use |FileProtocolHandler| instead of
+ // |WrtFileProtocolHandler| when switches::kInjectedBundlePath is disabled.
+ // But the switch is appended later than here.
+ // Use WrtFileProtocolHandler for File URI scheme.
set_protocol = job_factory->SetProtocolHandler(
url::kFileScheme,
- base::WrapUnique(new net::FileProtocolHandler(
+ base::WrapUnique(new net::WrtFileProtocolHandler(
base::CreateTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})
#include "common/content_switches_efl.h"
namespace {
-const char* const VERSION_FUNCTION = "DynamicPluginVersion";
const char* const START_SESSION_FUNCTION = "DynamicPluginStartSession";
const char* const STOP_SESSION_FUNCTION = "DynamicPluginStopSession";
-const char* const URL_PARSING_FUNCTION = "DynamicUrlParsing";
-const char* const SET_WIDGET_INFO_FUNCTION = "DynamicSetWidgetInfo";
-const char* const DATABASE_ATTACH_FUNCTION = "DynamicDatabaseAttach";
-
-typedef void (*startSessionFun)(const char* tizen_app_id,
- v8::Handle<v8::Context> context,
- int routingHandle,
- const char* baseURL);
-typedef void (*startSessionFun_v0)(const char* tizen_app_id,
- v8::Handle<v8::Context> context,
- int routingHandle,
- double scaleFactor,
- const char* encodedBundle,
- const char* theme,
- const char* baseURL);
+const char* const VERSION_FUNCTION = "DynamicPluginVersion";
}
DynamicPlugin::DynamicPlugin()
- : m_handle(0),
- m_version(0),
- m_startSession(0),
- m_stopSession(0),
- m_parseURL(0),
- m_setWidgetInfo(0),
- m_databaseAttach(0) {
- const base::CommandLine& commandLine = *base::CommandLine::ForCurrentProcess();
+ : handle_(0),
+ version_(0),
+ version_function_(0),
+ start_session_(0),
+ stop_session_(0) {
+ const base::CommandLine& commandLine =
+ *base::CommandLine::ForCurrentProcess();
std::string injectedBundlePath =
commandLine.GetSwitchValueASCII(switches::kInjectedBundlePath);
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";
+ handle_ = dlopen(injectedBundlePath.c_str(), RTLD_LAZY);
+ if (!handle_) {
+ LOG(ERROR) << "No handle to " << injectedBundlePath.c_str() << " "
+ << dlerror() << "\n";
return;
}
- unsigned int (*versionFunction)(void);
- *reinterpret_cast<void **>(&versionFunction) = dlsym(m_handle, VERSION_FUNCTION);
- if (versionFunction) {
- m_version = versionFunction();
- if (m_version != 0 && m_version != 1) {
- LOG(ERROR) << "Unknown plugin version: " << m_version << "!\n";
+ *reinterpret_cast<void**>(&version_function_) =
+ dlsym(handle_, VERSION_FUNCTION);
+ if (!version_function_) {
+ LOG(ERROR) << "No " << VERSION_FUNCTION << " symbol found!\n";
+ } else {
+ version_ = version_function_();
+ if (version_ != 0 && version_ != 1) {
+ LOG(ERROR) << "Unknown plugin version: " << version_ << "!\n";
return;
}
}
- m_startSession = dlsym(m_handle, START_SESSION_FUNCTION);
- if (!m_startSession) {
+ *reinterpret_cast<void**>(&start_session_) =
+ dlsym(handle_, START_SESSION_FUNCTION);
+ if (!start_session_)
LOG(ERROR) << "No " << START_SESSION_FUNCTION << " symbol found!\n";
- }
- *reinterpret_cast<void **>(&m_stopSession) = dlsym(m_handle, STOP_SESSION_FUNCTION);
- if (!m_stopSession) {
+ *reinterpret_cast<void**>(&stop_session_) =
+ dlsym(handle_, STOP_SESSION_FUNCTION);
+ if (!stop_session_)
LOG(ERROR) << "No " << STOP_SESSION_FUNCTION << " symbol found!\n";
- }
- *reinterpret_cast<void **>(&m_parseURL) = dlsym(m_handle, URL_PARSING_FUNCTION);
- if (!m_parseURL) {
- LOG(ERROR) << "No " << URL_PARSING_FUNCTION << " symbol found!\n";
- }
- *reinterpret_cast<void **>(&m_setWidgetInfo) = dlsym(m_handle, SET_WIDGET_INFO_FUNCTION);
- if (!m_setWidgetInfo) {
- LOG(ERROR) << "No " << SET_WIDGET_INFO_FUNCTION << " symbol found!";
- }
- *reinterpret_cast<void **>(&m_databaseAttach) = dlsym(m_handle, DATABASE_ATTACH_FUNCTION);
- if (!m_databaseAttach) {
- LOG(ERROR) << "No " << DATABASE_ATTACH_FUNCTION << " symbol found!\n";
- return;
- }
- *reinterpret_cast<void **>(&m_onIPCMessage) = dlsym(m_handle, "DynamicOnIPCMessage");
- if (!m_onIPCMessage) {
- LOG(ERROR) << "No DynamicOnIPCMessage symbol found!\n";
- }
- m_databaseAttach(1);
}
-void DynamicPlugin::startSession(const char* tizen_app_id,
+void DynamicPlugin::StartSession(const char* session_id,
v8::Handle<v8::Context> context,
- int routingHandle,
- double scaleFactor,
- const char* encodedBundle,
- const char* theme,
- const char* baseURL) {
- if (!m_startSession || !m_databaseAttach)
+ int routing_handle,
+ const void* session_blob) {
+ if (!start_session_)
return;
- switch (m_version) {
- case 0: {
- auto startSession_v0 = reinterpret_cast<startSessionFun_v0>(m_startSession);
- startSession_v0(tizen_app_id, context, routingHandle, scaleFactor,
- encodedBundle, theme, baseURL);
- break; }
- case 1: {
- auto startSession = reinterpret_cast<startSessionFun>(m_startSession);
- startSession(tizen_app_id, context, routingHandle, baseURL);
- break; }
- default:
- return;
- }
-}
-void DynamicPlugin::stopSession(const char* tizen_app_id,
- v8::Handle<v8::Context> context) {
- if (!m_stopSession || !m_databaseAttach)
- return;
- m_stopSession(tizen_app_id, context);
+ start_session_(session_id, context, routing_handle, session_blob);
}
-void DynamicPlugin::parseURL(std::string* old_url,
- std::string* new_url,
- const char* tizen_app_id) {
- if (!m_parseURL || !m_databaseAttach)
+void DynamicPlugin::StopSession(const char* session_id,
+ v8::Handle<v8::Context> context) {
+ if (!stop_session_)
return;
- m_parseURL(old_url, new_url, tizen_app_id);
-}
-void DynamicPlugin::setWidgetInfo(const std::string& tizen_app_id) {
- if (!m_setWidgetInfo)
- return;
- m_setWidgetInfo(tizen_app_id.c_str());
+ stop_session_(session_id, context);
}
DynamicPlugin::~DynamicPlugin() {
- if (m_databaseAttach)
- m_databaseAttach(0);
- if (m_handle)
- dlclose(m_handle);
+ if (handle_)
+ dlclose(handle_);
}
DynamicPlugin& DynamicPlugin::instance() {
return dynamicPlugin;
}
-void DynamicPlugin::messageReceived(const Ewk_Wrt_Message_Data& data) {
- if (!m_onIPCMessage)
- return;
-
- m_onIPCMessage(data);
-}
-// Copyright 2014 Samsung Electronics. All rights reserved.
+// 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 DYNAMICPLUGIN_H
-#define DYNAMICPLUGIN_H
+#ifndef EWK_EFL_INTEGRATION_WRT_DYNAMICPLUGIN_H_
+#define EWK_EFL_INTEGRATION_WRT_DYNAMICPLUGIN_H_
#include <string>
+#include "base/macros.h"
#include "v8/include/v8.h"
+typedef unsigned int (*VersionFunction)(void);
-class Ewk_Wrt_Message_Data;
+typedef void (*StartSessionFunction)(const char* session_id,
+ v8::Handle<v8::Context> context,
+ int routing_handle,
+ const void* session_blob);
-typedef void (*stopSessionFun)(const char* tizen_app_id,
- v8::Handle<v8::Context> context);
-typedef void (*onIPCMessageFun)(
- const Ewk_Wrt_Message_Data& data);
-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);
+typedef void (*StopSessionFunction)(const char* session_id,
+ v8::Handle<v8::Context> context);
class DynamicPlugin {
public:
- void startSession(const char* tizen_app_id,
+ void StartSession(const char* session_id,
v8::Handle<v8::Context> context,
- int routingHandle,
- double scaleFactor,
- const char* encodedBundle,
- const char* theme,
- const char* baseURL);
- void stopSession(const char* tizen_app_id,
- v8::Handle<v8::Context> context);
- void parseURL(std::string* old_url, std::string* new_url, const char* tizen_app_id);
- void setWidgetInfo(const std::string& tizen_app_id);
- void messageReceived(const Ewk_Wrt_Message_Data& data);
-
- ~DynamicPlugin();
+ int routing_handle,
+ const void* session_blob);
+ void StopSession(const char* session_id, v8::Handle<v8::Context> context);
+
+ virtual ~DynamicPlugin();
static DynamicPlugin& instance();
- private:
+ protected:
DynamicPlugin();
DynamicPlugin(const DynamicPlugin&);
DynamicPlugin& operator=(const DynamicPlugin&);
- void* m_handle;
- unsigned int m_version;
- void* m_startSession;
- stopSessionFun m_stopSession;
- parseUrlFun m_parseURL;
- setWidgetInfoFun m_setWidgetInfo;
- databaseAttachFun m_databaseAttach;
- onIPCMessageFun m_onIPCMessage;
+ void* handle_;
+ unsigned int version_;
+ VersionFunction version_function_;
+ StartSessionFunction start_session_;
+ StopSessionFunction stop_session_;
};
-#endif // DYNAMICPLUGIN_H
+#endif // EWK_EFL_INTEGRATION_WRT_DYNAMICPLUGIN_H_
--- /dev/null
+// Copyright 2014-2018, 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/v8widget.h"
+
+#include "base/logging.h"
+#include "wrt/dynamicplugin.h"
+#include "wrt/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) {
+ if (id_.empty())
+ return false;
+
+ 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());
+ if (!s_new_url.empty()) {
+ new_url = GURL(s_new_url);
+ return true;
+ }
+
+ return false;
+}
+
+void V8Widget::StopSession(v8::Handle<v8::Context> context) {
+ if (!id_.empty() && !context.IsEmpty()) {
+ if (type_ == V8Widget::Type::WRT)
+ WrtDynamicPlugin::instance().StopSession(id_.c_str(), context);
+ }
+}
+
+void V8Widget::StartSession(v8::Handle<v8::Context> context,
+ int routing_handle,
+ const void* session_blob) {
+ if (!id_.empty() && !context.IsEmpty()) {
+ if (type_ == V8Widget::Type::WRT)
+ NOTREACHED();
+ }
+}
--- /dev/null
+// Copyright 2014-2018 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 EWK_EFL_INTEGRATION_WRT_V8WIDGET_H_
+#define EWK_EFL_INTEGRATION_WRT_V8WIDGET_H_
+
+#include <string>
+
+#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<v8::Context>,
+ int routing_handle,
+ const void* session_blob);
+
+ virtual void StopSession(v8::Handle<v8::Context>);
+
+ bool ParseUrl(const GURL& url, GURL& new_url);
+
+ protected:
+ std::string id_;
+ Type type_;
+};
+
+#endif // EWK_EFL_INTEGRATION_WRT_V8WIDGET_H_
--- /dev/null
+// 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/wrt_dynamicplugin.h"
+
+#include <dlfcn.h>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "common/content_switches_efl.h"
+
+namespace {
+const char* const URL_PARSING_FUNCTION = "DynamicUrlParsing";
+const char* const SET_WIDGET_INFO_FUNCTION = "DynamicSetWidgetInfo";
+const char* const DATABASE_ATTACH_FUNCTION = "DynamicDatabaseAttach";
+
+typedef void (*StartSessionFun_v0)(const char* tizen_app_id,
+ v8::Handle<v8::Context> context,
+ int routing_handle,
+ double scale_factor,
+ const char* encoded_bundle,
+ const char* theme,
+ const char* baseURL);
+} // namespace
+
+WrtDynamicPlugin::WrtDynamicPlugin()
+ : DynamicPlugin(),
+ parseURL_(0),
+ set_widget_info_(0),
+ database_attach_(0),
+ on_IPC_message_(0) {
+ *reinterpret_cast<void**>(&parseURL_) = dlsym(handle_, URL_PARSING_FUNCTION);
+ if (!parseURL_)
+ LOG(ERROR) << "No " << URL_PARSING_FUNCTION << " symbol found!\n";
+
+ *reinterpret_cast<void**>(&set_widget_info_) =
+ dlsym(handle_, SET_WIDGET_INFO_FUNCTION);
+ if (!set_widget_info_)
+ LOG(ERROR) << "No " << SET_WIDGET_INFO_FUNCTION << " symbol found!";
+
+ *reinterpret_cast<void**>(&database_attach_) =
+ dlsym(handle_, DATABASE_ATTACH_FUNCTION);
+ if (!database_attach_) {
+ LOG(ERROR) << "No " << DATABASE_ATTACH_FUNCTION << " symbol found!\n";
+ return;
+ }
+
+ *reinterpret_cast<void**>(&on_IPC_message_) =
+ dlsym(handle_, "DynamicOnIPCMessage");
+ if (!on_IPC_message_)
+ LOG(ERROR) << "No DynamicOnIPCMessage symbol found!\n";
+ database_attach_(1);
+}
+
+void WrtDynamicPlugin::StartSession(const char* tizen_app_id,
+ v8::Handle<v8::Context> context,
+ int routing_handle,
+ double scale_factor,
+ const char* encoded_bundle,
+ const char* theme,
+ const char* baseURL) {
+ if (!start_session_ || !database_attach_)
+ return;
+ switch (version_) {
+ case 0: {
+ auto startSession_v0 =
+ reinterpret_cast<StartSessionFun_v0>(start_session_);
+ startSession_v0(tizen_app_id, context, routing_handle, scale_factor,
+ encoded_bundle, theme, baseURL);
+ break;
+ }
+ case 1: {
+ DynamicPlugin::StartSession(tizen_app_id, context, routing_handle,
+ baseURL);
+ break;
+ }
+ default:
+ return;
+ }
+}
+
+void WrtDynamicPlugin::StopSession(const char* tizen_app_id,
+ v8::Handle<v8::Context> context) {
+ if (!stop_session_ || !database_attach_)
+ return;
+
+ DynamicPlugin::StopSession(tizen_app_id, context);
+}
+
+void WrtDynamicPlugin::ParseURL(std::string* old_url,
+ std::string* new_url,
+ const char* tizen_app_id) {
+ if (!parseURL_ || !database_attach_)
+ return;
+
+ parseURL_(old_url, new_url, tizen_app_id);
+}
+
+void WrtDynamicPlugin::SetWidgetInfo(const std::string& tizen_app_id) {
+ if (!set_widget_info_)
+ return;
+
+ set_widget_info_(tizen_app_id.c_str());
+}
+
+WrtDynamicPlugin::~WrtDynamicPlugin() {
+ if (database_attach_)
+ database_attach_(0);
+}
+
+WrtDynamicPlugin& WrtDynamicPlugin::instance() {
+ static WrtDynamicPlugin dynamicPlugin;
+ return dynamicPlugin;
+}
+
+void WrtDynamicPlugin::MessageReceived(const Ewk_Wrt_Message_Data& data) {
+ if (!on_IPC_message_)
+ return;
+
+ on_IPC_message_(data);
+}
--- /dev/null
+// 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 EWK_EFL_INTEGRATION_WRT_WRT_DYNAMICPLUGIN_H_
+#define EWK_EFL_INTEGRATION_WRT_WRT_DYNAMICPLUGIN_H_
+
+#include <string>
+#include <vector>
+#include "v8/include/v8.h"
+#include "wrt/dynamicplugin.h"
+
+struct Ewk_Wrt_Message_Data;
+
+typedef void (*OnIPCMessageFun)(const Ewk_Wrt_Message_Data& data);
+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 database_attach);
+
+class WrtDynamicPlugin : public DynamicPlugin {
+ public:
+ void StartSession(const char* tizen_app_id,
+ v8::Handle<v8::Context> context,
+ int routing_handle,
+ double scale_factor,
+ const char* encoded_bundle,
+ const char* theme,
+ const char* baseURL);
+ void StopSession(const char* tizen_app_id, v8::Handle<v8::Context> context);
+
+ void ParseURL(std::string* old_url,
+ std::string* new_url,
+ const char* tizen_app_id);
+
+ void SetWidgetInfo(const std::string& tizen_app_id);
+ void MessageReceived(const Ewk_Wrt_Message_Data& data);
+
+ static WrtDynamicPlugin& instance();
+ ~WrtDynamicPlugin() override;
+
+ private:
+ WrtDynamicPlugin();
+
+ ParseUrlFun parseURL_;
+ SetWidgetInfoFun set_widget_info_;
+ DatabaseAttachFun database_attach_;
+ OnIPCMessageFun on_IPC_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(WrtDynamicPlugin);
+};
+
+#endif // EWK_EFL_INTEGRATION_WRT_WRT_DYNAMICPLUGIN_H_
#include "wrt_file_protocol_handler.h"
-#include <string>
-
-#include "base/files/file_path.h"
-#include "base/memory/weak_ptr.h"
-//#include "base/threading/sequenced_worker_pool.h"
-#include "content/public/browser/browser_thread.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/base/net_errors.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 "url/url_util.h"
-#include "wrt/dynamicplugin.h"
-#include "wrt/wrt_widget_host.h"
+#include "net/url_request/url_request_simple_job.h"
-using content::BrowserThread;
+#include "wrt/wrt_dynamicplugin.h"
-namespace {
-class WrtURLRequestJob : public net::URLRequestFileJob {
- public:
- WrtURLRequestJob(net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- const base::FilePath& file_path,
- const scoped_refptr<base::TaskRunner>& file_task_runner)
- : net::URLRequestFileJob(
- request, network_delegate, file_path, file_task_runner),
- weak_factory_(this) {
- }
+namespace net {
- virtual void Start() {
- // TODO(z.kostrzewa) This should be resolved by adding WrtFileProtocolHandler
- // only for WRT-originated launch (see url_request_context_getter_efl.cc)
- if (WrtWidgetHost::Get()->InWrt()) {
- // Load WRT injected bundle here to be able access WRT's URL parsing.
- // It is not possible to ask the render process to do the URL parsing as
- // some resource requests are requested via sync messages from the render
- // process. In such case the render process blocks and is unable to
- // process the URL parsing request.
- // Loading WRT's injected bundle in the browser process is potentially
- // dagerous as it expects to be loaded in the render process.
- std::string old_url = request()->url().possibly_invalid_spec();
- std::string s_new_url;
- std::string tizen_app_id = WrtWidgetHost::Get()->TizenAppId();
- DynamicPlugin::instance().parseURL(
- &old_url, &s_new_url, tizen_app_id.c_str());
- OnUrlRetrieved(GURL(s_new_url));
- } else {
- URLRequestFileJob::Start();
- }
+class WrtURLRequestDataJob : public URLRequestSimpleJob {
+ public:
+ WrtURLRequestDataJob(URLRequest* request,
+ NetworkDelegate* network_delegate,
+ const GURL& data_url)
+ : URLRequestSimpleJob(request, network_delegate) {
+ data_url_ = data_url;
}
- // TODO(z.kostrzewa) Shouldn't it be forwarded to a different thread?
- void OnUrlRetrieved(const GURL& url) {
- net::FileURLToFilePath(url, &file_path_);
- if (file_path_.empty())
- NotifyHeadersComplete();
- else
- URLRequestFileJob::Start();
- }
+ int GetData(std::string* mime_type,
+ std::string* charset,
+ std::string* data,
+ const CompletionCallback& callback) const override;
private:
- virtual ~WrtURLRequestJob() {}
-
- base::WeakPtrFactory<WrtURLRequestJob> weak_factory_;
+ ~WrtURLRequestDataJob() override {}
+ GURL data_url_;
};
-class WrtFileProtocolHandler :
- public net::URLRequestJobFactory::ProtocolHandler {
- public:
- explicit WrtFileProtocolHandler(
- const scoped_refptr<base::TaskRunner>& file_task_runner);
- virtual ~WrtFileProtocolHandler();
- virtual net::URLRequestJob* MaybeCreateJob(
- net::URLRequest* request, net::NetworkDelegate* network_delegate) const;
- virtual bool IsSafeRedirectTarget(const GURL& location) const;
+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;
- private:
- const scoped_refptr<base::TaskRunner> file_task_runner_;
- DISALLOW_COPY_AND_ASSIGN(WrtFileProtocolHandler);
-};
+ return URLRequestDataJob::BuildResponse(data_url_, mime_type, charset, data,
+ nullptr);
+}
-WrtFileProtocolHandler::WrtFileProtocolHandler(
- const scoped_refptr<base::TaskRunner>& file_task_runner)
- : file_task_runner_(file_task_runner) {}
+bool WrtFileProtocolHandler::GetWrtParsedUrl(const GURL& url,
+ GURL& parsed_url) const {
+ static std::string tizen_app_id =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kTizenAppId);
+ if (tizen_app_id.empty())
+ return false;
+
+ 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());
+ if (!parsed_url_str.empty()) {
+ parsed_url = GURL(parsed_url_str);
+ return true;
+ }
+ return false;
+}
-WrtFileProtocolHandler::~WrtFileProtocolHandler() {}
+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();
+ }
-net::URLRequestJob* WrtFileProtocolHandler::MaybeCreateJob(
- net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
base::FilePath file_path;
- const bool is_file = net::FileURLToFilePath(request->url(), &file_path);
+ const bool is_file = FileURLToFilePath(parsed_url, &file_path);
// Check file access permissions.
// FIXME: The third parameter of net::URLRequestErrorJob sould be
// absolute_path.
if (!network_delegate ||
- !network_delegate->CanAccessFile(*request, file_path, file_path)) {
- return new net::URLRequestErrorJob(request, network_delegate, net::ERR_ACCESS_DENIED);
- }
+ !network_delegate->CanAccessFile(*request, file_path, 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
// 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 net::URLRequestFileDirJob(request, network_delegate, file_path);
- }
+ if (is_file && file_path.EndsWithSeparator() && file_path.IsAbsolute())
+ return new URLRequestFileDirJob(request, network_delegate, file_path);
- // Use WRT file request job for all non-directories (including invalid
+ // Use a regular file request job for all non-directories (including invalid
// file names).
- return new WrtURLRequestJob(request,
- network_delegate,
- file_path,
- file_task_runner_);
+ return new URLRequestFileJob(request, network_delegate, file_path,
+ file_task_runner_);
}
-bool WrtFileProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
- return false;
-}
} // namespace
#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<base::TaskRunner>& file_task_runner)
+ : file_task_runner_(file_task_runner) {}
+ ~WrtFileProtocolHandler() override {}
+ URLRequestJob* MaybeCreateJob(
+ URLRequest* request,
+ NetworkDelegate* network_delegate) const override;
+ bool IsSafeRedirectTarget(const GURL& location) const override {
+ return false;
+ }
+
+ private:
+ bool GetWrtParsedUrl(const GURL& url, GURL& parsed_url) const;
+
+ const scoped_refptr<base::TaskRunner> file_task_runner_;
+ DISALLOW_COPY_AND_ASSIGN(WrtFileProtocolHandler);
+};
+
+} // namespace net
+
#endif // WRT_FILE_PROTOCOL_HANDLER
#include "common/render_messages_ewk.h"
#include "content/public/renderer/render_thread.h"
#include "ipc/ipc_sync_channel.h"
-#include "wrt/dynamicplugin.h"
+#include "wrt/wrt_dynamicplugin.h"
-// TODO(z.kostrzewa) Why it can't be implemented as IPC::ChannelProxy::MessageFilter (?)
+// 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 {
};
WrtWidget::WrtWidget()
- : observer_(new WrtRenderThreadObserver(this)) {
+ : V8Widget(V8Widget::Type::WRT),
+ scale_(0),
+ observer_(new WrtRenderThreadObserver(this)) {
+ DCHECK(content::RenderThread::Get())
+ << "WrtWidget must be constructed on the render thread";
}
WrtWidget::~WrtWidget() {
}
void WrtWidget::SetWidgetInfo(const std::string& tizen_app_id,
- double scaleFactor,
+ double scale_factor,
const std::string& theme,
- const std::string& encodedBundle) {
- tizen_app_id_ = tizen_app_id;
- scale_ = scaleFactor;
+ const std::string& encoded_bundle) {
+ id_ = tizen_app_id;
+ scale_ = scale_factor;
theme_ = theme;
- encodedBundle_ = encodedBundle;
- DynamicPlugin::instance().setWidgetInfo(tizen_app_id_);
+ encoded_bundle_ = encoded_bundle;
+ WrtDynamicPlugin::instance().SetWidgetInfo(id_);
}
bool WrtWidget::IsWidgetInfoSet() const {
- return !tizen_app_id_.empty();
-}
-
-void WrtWidget::ParseUrl(const GURL& url, GURL& new_url) {
- if (!tizen_app_id_.empty()) {
- std::string old_url = url.possibly_invalid_spec();
- std::string s_new_url;
- DynamicPlugin::instance().parseURL(&old_url, &s_new_url, tizen_app_id_.c_str());
- if (s_new_url.empty())
- new_url = url;
- else
- new_url = GURL(s_new_url);
- } else {
- new_url = url;
- }
+ return !id_.empty();
}
void WrtWidget::StartSession(v8::Handle<v8::Context> context,
- int routingHandle,
- const std::string& baseURL) {
- if (!tizen_app_id_.empty() && !context.IsEmpty()) {
- DynamicPlugin::instance().startSession(tizen_app_id_.c_str(),
- context,
- routingHandle,
- scale_,
- encodedBundle_.c_str(),
- theme_.c_str(),
- baseURL.c_str());
- }
-}
-
-void WrtWidget::StopSession(v8::Handle<v8::Context> context) {
- if (!tizen_app_id_.empty() && !context.IsEmpty()) {
- DynamicPlugin::instance().stopSession(tizen_app_id_.c_str(), context);
+ int routing_handle,
+ const void* session_blob) {
+ if (!id_.empty() && !context.IsEmpty()) {
+ WrtDynamicPlugin::instance().StartSession(
+ id_.c_str(), context, routing_handle, scale_, encoded_bundle_.c_str(),
+ theme_.c_str(), reinterpret_cast<const char*>(session_blob));
}
}
void WrtWidget::MessageReceived(const Ewk_Wrt_Message_Data& data) {
- if (!tizen_app_id_.empty())
- DynamicPlugin::instance().messageReceived(data);
+ if (!id_.empty())
+ WrtDynamicPlugin::instance().MessageReceived(data);
}
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WRTWIDGET_H
-#define WRTWIDGET_H
+#ifndef EWK_EFL_INTEGRATION_WRT_WRTWIDGET_H_
+#define EWK_EFL_INTEGRATION_WRT_WRTWIDGET_H_
#include <string>
#include "content/public/renderer/render_thread_observer.h"
#include "url/gurl.h"
-#include "v8/include/v8.h"
+#include "wrt/v8widget.h"
class Ewk_Wrt_Message_Data;
class WrtRenderThreadObserver;
// Have to be created on the RenderThread.
-class WrtWidget {
+class WrtWidget : public V8Widget {
public:
WrtWidget();
- ~WrtWidget();
+ ~WrtWidget() override;
content::RenderThreadObserver* GetObserver();
void MessageReceived(const Ewk_Wrt_Message_Data& data);
- void ParseUrl(const GURL& url, GURL& new_url);
-
void StartSession(v8::Handle<v8::Context>,
- int routingHandle,
- const std::string& baseURL);
-
- void StopSession(v8::Handle<v8::Context>);
+ int routing_handle,
+ const void* session_blob) override;
private:
double scale_;
- std::string encodedBundle_;
+ std::string encoded_bundle_;
std::string theme_;
- std::string tizen_app_id_;
WrtRenderThreadObserver* observer_;
};
-#endif // WRTWIDGET_H
+#endif // EWK_EFL_INTEGRATION_WRT_WRTWIDGET_H_