Fix invalid licenses
[platform/framework/web/crosswalk-tizen.git] / src / bundle / injected_bundle.cc
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <unistd.h>
18 #include <v8.h>
19 #include <ewk_ipc_message.h>
20 #include <Ecore.h>
21 #include <string>
22 #include <memory>
23
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"
31
32 namespace wrt {
33 class BundleGlobalData {
34  public :
35   static BundleGlobalData* GetInstance() {
36     static BundleGlobalData instance;
37     return &instance;
38   }
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());
48     }
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());
53   }
54
55   ResourceManager* resource_manager() {
56     return resource_manager_.get();
57   }
58
59  private:
60   BundleGlobalData() {}
61   ~BundleGlobalData() {}
62   std::unique_ptr<ResourceManager> resource_manager_;
63   std::unique_ptr<LocaleManager> locale_manager_;
64   std::unique_ptr<ApplicationData> app_data_;
65 };
66 }  //  namespace wrt
67
68 extern "C" void DynamicSetWidgetInfo(const char* tizen_id) {
69   LOGGER(DEBUG) << "InjectedBundle::DynamicSetWidgetInfo !!" << tizen_id;
70   ecore_init();
71   wrt::BundleGlobalData::GetInstance()->Initialize(tizen_id);
72 }
73
74 extern "C" void DynamicPluginStartSession(const char* tizen_id,
75                                           v8::Handle<v8::Context> context,
76                                           int routing_handle,
77                                           double /*scale*/,
78                                           const char* uuid,
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.";
84     return;
85   }
86
87   // Initialize RuntimeIPCClient
88   wrt::RuntimeIPCClient* rc = wrt::RuntimeIPCClient::GetInstance();
89   rc->set_routing_id(routing_handle);
90
91   // Initialize ExtensionRendererController
92   wrt::ExtensionRendererController& controller =
93       wrt::ExtensionRendererController::GetInstance();
94   controller.InitializeExtensions(uuid);
95   controller.DidCreateScriptContext(context);
96 }
97
98 extern "C" void DynamicPluginStopSession(
99     const char* tizen_id, v8::Handle<v8::Context> context) {
100   LOGGER(DEBUG) << "InjectedBundle::DynamicPluginStopSession !!" << tizen_id;
101
102   wrt::ExtensionRendererController& controller =
103       wrt::ExtensionRendererController::GetInstance();
104   controller.WillReleaseScriptContext(context);
105 }
106
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";
112     *new_url = *old_url;
113     return;
114   }
115   *new_url = res_manager->GetLocalizedPath(*old_url);
116 }
117
118 extern "C" void DynamicDatabaseAttach(int /*attach*/) {
119   // LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!";
120 }
121
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);
126 }
127
128 extern "C" void DynamicPreloading() {
129   // LOGGER(DEBUG) << "InjectedBundle::DynamicPreloading !!";
130 }