Upstream version 11.39.244.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / xwalk_path_helper.cc
1 // Copyright (c) 2014 Intel Corporation. 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.
4
5 #include "xwalk/runtime/browser/android/xwalk_path_helper.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_weak_ref.h"
9 #include "base/bind.h"
10 #include "jni/XWalkPathHelper_jni.h"
11 #include "xwalk/extensions/common/xwalk_extension.h"
12 #include "xwalk/runtime/browser/xwalk_browser_main_parts.h"
13 #include "xwalk/runtime/browser/xwalk_content_browser_client.h"
14
15 namespace xwalk {
16
17 typedef std::map<std::string, base::FilePath> VirtualRootMap;
18 VirtualRootMap XWalkPathHelper::virtual_root_map_;
19
20 VirtualRootMap XWalkPathHelper::GetVirtualRootMap() {
21   return virtual_root_map_;
22 }
23
24 void XWalkPathHelper::SetDirectory(const std::string& virtualRoot,
25                                    const std::string& path) {
26   virtual_root_map_[virtualRoot] =
27       base::FilePath::FromUTF8Unsafe(path);
28 }
29
30 static void SetDirectory(JNIEnv* env, jclass clazz,
31     jstring virtualRoot, jstring path) {
32   const char* strVirtualRoot = env->GetStringUTFChars(virtualRoot, NULL);
33   const char* strPath = env->GetStringUTFChars(path, NULL);
34   XWalkPathHelper::SetDirectory(
35       std::string(strVirtualRoot), std::string(strPath));
36   env->ReleaseStringUTFChars(virtualRoot, strVirtualRoot);
37   env->ReleaseStringUTFChars(path, strPath);
38 }
39
40 bool RegisterXWalkPathHelper(JNIEnv* env) {
41   return RegisterNativesImpl(env);
42 }
43
44 }  // namespace xwalk