|
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "base/basictypes.h" |
|
7 |
|
8 #include "assert.h" |
|
9 #include "ANPBase.h" |
|
10 #include <android/log.h> |
|
11 #include "nsNPAPIPluginInstance.h" |
|
12 #include "AndroidBridge.h" |
|
13 #include "nsNPAPIPlugin.h" |
|
14 #include "PluginPRLibrary.h" |
|
15 |
|
16 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args) |
|
17 #define ASSIGN(obj, name) (obj)->name = anp_system_##name |
|
18 |
|
19 const char* |
|
20 anp_system_getApplicationDataDirectory(NPP instance) |
|
21 { |
|
22 static const char *dir = nullptr; |
|
23 static const char *privateDir = nullptr; |
|
24 |
|
25 bool isPrivate = false; |
|
26 |
|
27 if (!dir) { |
|
28 dir = getenv("ANDROID_PLUGIN_DATADIR"); |
|
29 } |
|
30 |
|
31 if (!privateDir) { |
|
32 privateDir = getenv("ANDROID_PLUGIN_DATADIR_PRIVATE"); |
|
33 } |
|
34 |
|
35 if (!instance) { |
|
36 return dir; |
|
37 } |
|
38 |
|
39 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
40 if (pinst && NS_SUCCEEDED(pinst->IsPrivateBrowsing(&isPrivate)) && isPrivate) { |
|
41 return privateDir; |
|
42 } |
|
43 |
|
44 return dir; |
|
45 } |
|
46 |
|
47 const char* |
|
48 anp_system_getApplicationDataDirectory() |
|
49 { |
|
50 return anp_system_getApplicationDataDirectory(nullptr); |
|
51 } |
|
52 |
|
53 jclass anp_system_loadJavaClass(NPP instance, const char* classNameStr) |
|
54 { |
|
55 LOG("%s", __PRETTY_FUNCTION__); |
|
56 |
|
57 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
58 mozilla::PluginPRLibrary* lib = static_cast<mozilla::PluginPRLibrary*>(pinst->GetPlugin()->GetLibrary()); |
|
59 |
|
60 NS_ConvertUTF8toUTF16 className(classNameStr); |
|
61 |
|
62 nsCString libNameUtf8; |
|
63 lib->GetLibraryPath(libNameUtf8); |
|
64 NS_ConvertUTF8toUTF16 libName(libNameUtf8); |
|
65 |
|
66 return mozilla::widget::android::GeckoAppShell::LoadPluginClass(className, libName); |
|
67 } |
|
68 |
|
69 void anp_system_setPowerState(NPP instance, ANPPowerState powerState) |
|
70 { |
|
71 nsNPAPIPluginInstance* pinst = nsNPAPIPluginInstance::GetFromNPP(instance); |
|
72 |
|
73 if (pinst) { |
|
74 pinst->SetWakeLock(powerState == kScreenOn_ANPPowerState); |
|
75 } |
|
76 } |
|
77 |
|
78 void InitSystemInterface(ANPSystemInterfaceV0 *i) { |
|
79 _assert(i->inSize == sizeof(*i)); |
|
80 ASSIGN(i, getApplicationDataDirectory); |
|
81 ASSIGN(i, loadJavaClass); |
|
82 } |
|
83 |
|
84 void InitSystemInterfaceV1(ANPSystemInterfaceV1 *i) { |
|
85 _assert(i->inSize == sizeof(*i)); |
|
86 ASSIGN(i, getApplicationDataDirectory); |
|
87 ASSIGN(i, loadJavaClass); |
|
88 ASSIGN(i, setPowerState); |
|
89 } |
|
90 |
|
91 void InitSystemInterfaceV2(ANPSystemInterfaceV2 *i) { |
|
92 _assert(i->inSize == sizeof(*i)); |
|
93 ASSIGN(i, getApplicationDataDirectory); |
|
94 ASSIGN(i, loadJavaClass); |
|
95 ASSIGN(i, setPowerState); |
|
96 } |