2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <ewk_ipc_message.h>
24 #include "common/logger.h"
25 #include "common/string_utils.h"
26 #include "common/application_data.h"
27 #include "common/resource_manager.h"
28 #include "common/locale_manager.h"
29 #include "bundle/runtime_ipc_client.h"
30 #include "bundle/extension_renderer_controller.h"
33 class BundleGlobalData {
35 static BundleGlobalData* GetInstance() {
36 static BundleGlobalData instance;
39 void Initialize(const std::string& app_id) {
40 app_data_.reset(new ApplicationData(app_id));
41 app_data_->LoadManifestData();
42 locale_manager_.reset(new LocaleManager);
43 locale_manager_->EnableAutoUpdate(true);
44 if (app_data_->widget_info() != NULL &&
45 !app_data_->widget_info()->default_locale().empty()) {
46 locale_manager_->SetDefaultLocale(
47 app_data_->widget_info()->default_locale());
49 resource_manager_.reset(new ResourceManager(app_data_.get(),
50 locale_manager_.get()));
51 resource_manager_->set_base_resource_path(
52 app_data_->application_path());
55 ResourceManager* resource_manager() {
56 return resource_manager_.get();
61 ~BundleGlobalData() {}
62 std::unique_ptr<ResourceManager> resource_manager_;
63 std::unique_ptr<LocaleManager> locale_manager_;
64 std::unique_ptr<ApplicationData> app_data_;
68 extern "C" void DynamicSetWidgetInfo(const char* tizen_id) {
69 LOGGER(DEBUG) << "InjectedBundle::DynamicSetWidgetInfo !!" << tizen_id;
71 wrt::BundleGlobalData::GetInstance()->Initialize(tizen_id);
74 extern "C" void DynamicPluginStartSession(const char* tizen_id,
75 v8::Handle<v8::Context> context,
79 const char* /*theme*/,
80 const char* base_url) {
81 LOGGER(DEBUG) << "InjectedBundle::DynamicPluginStartSession !!" << tizen_id;
82 if (base_url == NULL || wrt::utils::StartsWith(base_url, "http")) {
83 LOGGER(ERROR) << "External url not allowed plugin loading.";
87 // Initialize RuntimeIPCClient
88 wrt::RuntimeIPCClient* rc = wrt::RuntimeIPCClient::GetInstance();
89 rc->set_routing_id(routing_handle);
91 // Initialize ExtensionRendererController
92 wrt::ExtensionRendererController& controller =
93 wrt::ExtensionRendererController::GetInstance();
94 controller.InitializeExtensions(uuid);
95 controller.DidCreateScriptContext(context);
98 extern "C" void DynamicPluginStopSession(
99 const char* tizen_id, v8::Handle<v8::Context> context) {
100 LOGGER(DEBUG) << "InjectedBundle::DynamicPluginStopSession !!" << tizen_id;
102 wrt::ExtensionRendererController& controller =
103 wrt::ExtensionRendererController::GetInstance();
104 controller.WillReleaseScriptContext(context);
107 extern "C" void DynamicUrlParsing(
108 std::string* old_url, std::string* new_url, const char* /*tizen_id*/) {
109 auto res_manager = wrt::BundleGlobalData::GetInstance()->resource_manager();
110 if (res_manager == NULL) {
111 LOGGER(ERROR) << "Widget Info was not set, Resource Manager is NULL";
115 *new_url = res_manager->GetLocalizedPath(*old_url);
118 extern "C" void DynamicDatabaseAttach(int /*attach*/) {
119 // LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!";
122 extern "C" void DynamicOnIPCMessage(const Ewk_IPC_Wrt_Message_Data& data) {
123 LOGGER(DEBUG) << "InjectedBundle::DynamicOnIPCMessage !!";
124 wrt::RuntimeIPCClient* rc = wrt::RuntimeIPCClient::GetInstance();
125 rc->HandleMessageFromRuntime(&data);
128 extern "C" void DynamicPreloading() {
129 // LOGGER(DEBUG) << "InjectedBundle::DynamicPreloading !!";