1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include <ewk_ipc_message.h>
12 #include "common/logger.h"
13 #include "common/string_utils.h"
14 #include "common/application_data.h"
15 #include "common/resource_manager.h"
16 #include "common/locale_manager.h"
17 #include "bundle/runtime_ipc_client.h"
18 #include "bundle/extension_renderer_controller.h"
21 class BundleGlobalData {
23 static BundleGlobalData* GetInstance() {
24 static BundleGlobalData instance;
27 void Initialize(const std::string& app_id) {
28 app_data_.reset(new ApplicationData(app_id));
29 app_data_->LoadManifestData();
30 locale_manager_.reset(new LocaleManager);
31 locale_manager_->EnableAutoUpdate(true);
32 if (app_data_->widget_info() != NULL &&
33 !app_data_->widget_info()->default_locale().empty()) {
34 locale_manager_->SetDefaultLocale(
35 app_data_->widget_info()->default_locale());
37 resource_manager_.reset(new ResourceManager(app_data_.get(),
38 locale_manager_.get()));
39 resource_manager_->set_base_resource_path(
40 app_data_->application_path());
43 ResourceManager* resource_manager() {
44 return resource_manager_.get();
49 ~BundleGlobalData() {}
50 std::unique_ptr<ResourceManager> resource_manager_;
51 std::unique_ptr<LocaleManager> locale_manager_;
52 std::unique_ptr<ApplicationData> app_data_;
56 extern "C" void DynamicSetWidgetInfo(const char* tizen_id) {
57 LOGGER(DEBUG) << "InjectedBundle::DynamicSetWidgetInfo !!" << tizen_id;
59 wrt::BundleGlobalData::GetInstance()->Initialize(tizen_id);
62 extern "C" void DynamicPluginStartSession(const char* tizen_id,
63 v8::Handle<v8::Context> context,
67 const char* /*theme*/,
68 const char* base_url) {
69 LOGGER(DEBUG) << "InjectedBundle::DynamicPluginStartSession !!" << tizen_id;
70 if (base_url == NULL || wrt::utils::StartsWith(base_url, "http")) {
71 LOGGER(ERROR) << "External url not allowed plugin loading.";
75 // Initialize RuntimeIPCClient
76 wrt::RuntimeIPCClient* rc = wrt::RuntimeIPCClient::GetInstance();
77 rc->set_routing_id(routing_handle);
79 // Initialize ExtensionRendererController
80 wrt::ExtensionRendererController& controller =
81 wrt::ExtensionRendererController::GetInstance();
82 controller.InitializeExtensions(uuid);
83 controller.DidCreateScriptContext(context);
86 extern "C" void DynamicPluginStopSession(
87 const char* tizen_id, v8::Handle<v8::Context> context) {
88 LOGGER(DEBUG) << "InjectedBundle::DynamicPluginStopSession !!" << tizen_id;
90 wrt::ExtensionRendererController& controller =
91 wrt::ExtensionRendererController::GetInstance();
92 controller.WillReleaseScriptContext(context);
95 extern "C" void DynamicUrlParsing(
96 std::string* old_url, std::string* new_url, const char* /*tizen_id*/) {
97 auto res_manager = wrt::BundleGlobalData::GetInstance()->resource_manager();
98 if (res_manager == NULL) {
99 LOGGER(ERROR) << "Widget Info was not set, Resource Manager is NULL";
103 *new_url = res_manager->GetLocalizedPath(*old_url);
106 extern "C" void DynamicDatabaseAttach(int /*attach*/) {
107 // LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!";
110 extern "C" void DynamicOnIPCMessage(const Ewk_IPC_Wrt_Message_Data& data) {
111 LOGGER(DEBUG) << "InjectedBundle::DynamicOnIPCMessage !!";
112 wrt::RuntimeIPCClient* rc = wrt::RuntimeIPCClient::GetInstance();
113 rc->HandleMessageFromRuntime(&data);
116 extern "C" void DynamicPreloading() {
117 // LOGGER(DEBUG) << "InjectedBundle::DynamicPreloading !!";