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.
5 #include "extension/extension.h"
10 #include "common/logger.h"
11 #include "extension/extension_adapter.h"
12 #include "extension/xwalk/XW_Extension.h"
16 Extension::Extension(const std::string& path, ExtensionDelegate* delegate)
17 : initialized_(false),
20 use_trampoline_(true),
22 created_instance_callback_(NULL),
23 destroyed_instance_callback_(NULL),
24 shutdown_callback_(NULL),
25 handle_msg_callback_(NULL),
26 handle_sync_msg_callback_(NULL) {
29 Extension::~Extension() {
33 if (shutdown_callback_)
34 shutdown_callback_(xw_extension_);
35 ExtensionAdapter::GetInstance()->UnregisterExtension(this);
38 bool Extension::Initialize() {
42 void* handle = dlopen(library_path_.c_str(), RTLD_LAZY);
44 LOGGER(ERROR) << "Error loading extension '"
45 << library_path_ << "' : " << dlerror();
49 XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
50 dlsym(handle, "XW_Initialize"));
52 LOGGER(ERROR) << "Error loading extension '" << library_path_
53 << "' : couldn't get XW_Initialize function.";
58 ExtensionAdapter* adapter = ExtensionAdapter::GetInstance();
59 xw_extension_ = adapter->GetNextXWExtension();
60 adapter->RegisterExtension(this);
62 int ret = initialize(xw_extension_, ExtensionAdapter::GetInterface);
64 LOGGER(ERROR) << "Error loading extension '" << library_path_
65 << "' : XW_Initialize() returned error value.";
74 ExtensionInstance* Extension::CreateInstance() {
75 ExtensionAdapter* adapter = ExtensionAdapter::GetInstance();
76 XW_Instance xw_instance = adapter->GetNextXWInstance();
77 return new ExtensionInstance(this, xw_instance);
80 void Extension::GetRuntimeVariable(const char* key, char* value,
83 delegate_->GetRuntimeVariable(key, value, value_len);
86 int Extension::CheckAPIAccessControl(const char* /*api_name*/) {
91 int Extension::RegisterPermissions(const char* /*perm_table*/) {