Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #include "base/basictypes.h"
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"
16 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
17 #define ASSIGN(obj, name) (obj)->name = anp_system_##name
19 const char*
20 anp_system_getApplicationDataDirectory(NPP instance)
21 {
22 static const char *dir = nullptr;
23 static const char *privateDir = nullptr;
25 bool isPrivate = false;
27 if (!dir) {
28 dir = getenv("ANDROID_PLUGIN_DATADIR");
29 }
31 if (!privateDir) {
32 privateDir = getenv("ANDROID_PLUGIN_DATADIR_PRIVATE");
33 }
35 if (!instance) {
36 return dir;
37 }
39 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
40 if (pinst && NS_SUCCEEDED(pinst->IsPrivateBrowsing(&isPrivate)) && isPrivate) {
41 return privateDir;
42 }
44 return dir;
45 }
47 const char*
48 anp_system_getApplicationDataDirectory()
49 {
50 return anp_system_getApplicationDataDirectory(nullptr);
51 }
53 jclass anp_system_loadJavaClass(NPP instance, const char* classNameStr)
54 {
55 LOG("%s", __PRETTY_FUNCTION__);
57 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
58 mozilla::PluginPRLibrary* lib = static_cast<mozilla::PluginPRLibrary*>(pinst->GetPlugin()->GetLibrary());
60 NS_ConvertUTF8toUTF16 className(classNameStr);
62 nsCString libNameUtf8;
63 lib->GetLibraryPath(libNameUtf8);
64 NS_ConvertUTF8toUTF16 libName(libNameUtf8);
66 return mozilla::widget::android::GeckoAppShell::LoadPluginClass(className, libName);
67 }
69 void anp_system_setPowerState(NPP instance, ANPPowerState powerState)
70 {
71 nsNPAPIPluginInstance* pinst = nsNPAPIPluginInstance::GetFromNPP(instance);
73 if (pinst) {
74 pinst->SetWakeLock(powerState == kScreenOn_ANPPowerState);
75 }
76 }
78 void InitSystemInterface(ANPSystemInterfaceV0 *i) {
79 _assert(i->inSize == sizeof(*i));
80 ASSIGN(i, getApplicationDataDirectory);
81 ASSIGN(i, loadJavaClass);
82 }
84 void InitSystemInterfaceV1(ANPSystemInterfaceV1 *i) {
85 _assert(i->inSize == sizeof(*i));
86 ASSIGN(i, getApplicationDataDirectory);
87 ASSIGN(i, loadJavaClass);
88 ASSIGN(i, setPowerState);
89 }
91 void InitSystemInterfaceV2(ANPSystemInterfaceV2 *i) {
92 _assert(i->inSize == sizeof(*i));
93 ASSIGN(i, getApplicationDataDirectory);
94 ASSIGN(i, loadJavaClass);
95 ASSIGN(i, setPowerState);
96 }