dom/plugins/base/android/ANPSystem.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial