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.
17 #include "extension/extension.h"
22 #include "common/logger.h"
23 #include "extension/extension_adapter.h"
24 #include "extension/xwalk/XW_Extension.h"
28 Extension::Extension(const std::string& path, ExtensionDelegate* delegate)
29 : initialized_(false),
32 use_trampoline_(true),
34 created_instance_callback_(NULL),
35 destroyed_instance_callback_(NULL),
36 shutdown_callback_(NULL),
37 handle_msg_callback_(NULL),
38 handle_sync_msg_callback_(NULL) {
41 Extension::~Extension() {
45 if (shutdown_callback_)
46 shutdown_callback_(xw_extension_);
47 ExtensionAdapter::GetInstance()->UnregisterExtension(this);
50 bool Extension::Initialize() {
54 void* handle = dlopen(library_path_.c_str(), RTLD_LAZY);
56 LOGGER(ERROR) << "Error loading extension '"
57 << library_path_ << "' : " << dlerror();
61 XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
62 dlsym(handle, "XW_Initialize"));
64 LOGGER(ERROR) << "Error loading extension '" << library_path_
65 << "' : couldn't get XW_Initialize function.";
70 ExtensionAdapter* adapter = ExtensionAdapter::GetInstance();
71 xw_extension_ = adapter->GetNextXWExtension();
72 adapter->RegisterExtension(this);
74 int ret = initialize(xw_extension_, ExtensionAdapter::GetInterface);
76 LOGGER(ERROR) << "Error loading extension '" << library_path_
77 << "' : XW_Initialize() returned error value.";
86 ExtensionInstance* Extension::CreateInstance() {
87 ExtensionAdapter* adapter = ExtensionAdapter::GetInstance();
88 XW_Instance xw_instance = adapter->GetNextXWInstance();
89 return new ExtensionInstance(this, xw_instance);
92 void Extension::GetRuntimeVariable(const char* key, char* value,
95 delegate_->GetRuntimeVariable(key, value, value_len);
98 int Extension::CheckAPIAccessControl(const char* /*api_name*/) {
103 int Extension::RegisterPermissions(const char* /*perm_table*/) {