dom/plugins/base/android/ANPSystem.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/base/android/ANPSystem.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "base/basictypes.h"
    1.10 +
    1.11 +#include "assert.h"
    1.12 +#include "ANPBase.h"
    1.13 +#include <android/log.h>
    1.14 +#include "nsNPAPIPluginInstance.h"
    1.15 +#include "AndroidBridge.h"
    1.16 +#include "nsNPAPIPlugin.h"
    1.17 +#include "PluginPRLibrary.h"
    1.18 +
    1.19 +#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
    1.20 +#define ASSIGN(obj, name)   (obj)->name = anp_system_##name
    1.21 +
    1.22 +const char*
    1.23 +anp_system_getApplicationDataDirectory(NPP instance)
    1.24 +{
    1.25 +  static const char *dir = nullptr;
    1.26 +  static const char *privateDir = nullptr;
    1.27 +
    1.28 +  bool isPrivate = false;
    1.29 +
    1.30 +  if (!dir) {
    1.31 +    dir = getenv("ANDROID_PLUGIN_DATADIR");
    1.32 +  }
    1.33 +
    1.34 +  if (!privateDir) {
    1.35 +    privateDir = getenv("ANDROID_PLUGIN_DATADIR_PRIVATE");
    1.36 +  }
    1.37 +
    1.38 +  if (!instance) {
    1.39 +    return dir;
    1.40 +  }
    1.41 +
    1.42 +  nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    1.43 +  if (pinst && NS_SUCCEEDED(pinst->IsPrivateBrowsing(&isPrivate)) && isPrivate) {
    1.44 +    return privateDir;
    1.45 +  }
    1.46 +
    1.47 +  return dir;
    1.48 +}
    1.49 +
    1.50 +const char*
    1.51 +anp_system_getApplicationDataDirectory()
    1.52 +{
    1.53 +  return anp_system_getApplicationDataDirectory(nullptr);
    1.54 +}
    1.55 +
    1.56 +jclass anp_system_loadJavaClass(NPP instance, const char* classNameStr)
    1.57 +{
    1.58 +  LOG("%s", __PRETTY_FUNCTION__);
    1.59 +
    1.60 +  nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    1.61 +  mozilla::PluginPRLibrary* lib = static_cast<mozilla::PluginPRLibrary*>(pinst->GetPlugin()->GetLibrary());
    1.62 +
    1.63 +  NS_ConvertUTF8toUTF16 className(classNameStr);
    1.64 +
    1.65 +  nsCString libNameUtf8;
    1.66 +  lib->GetLibraryPath(libNameUtf8);
    1.67 +  NS_ConvertUTF8toUTF16 libName(libNameUtf8);
    1.68 +
    1.69 +  return mozilla::widget::android::GeckoAppShell::LoadPluginClass(className, libName);
    1.70 +}
    1.71 +
    1.72 +void anp_system_setPowerState(NPP instance, ANPPowerState powerState)
    1.73 +{
    1.74 +  nsNPAPIPluginInstance* pinst = nsNPAPIPluginInstance::GetFromNPP(instance);
    1.75 +
    1.76 +  if (pinst) {
    1.77 +    pinst->SetWakeLock(powerState == kScreenOn_ANPPowerState);
    1.78 +  }
    1.79 +}
    1.80 +
    1.81 +void InitSystemInterface(ANPSystemInterfaceV0 *i) {
    1.82 +  _assert(i->inSize == sizeof(*i));
    1.83 +  ASSIGN(i, getApplicationDataDirectory);
    1.84 +  ASSIGN(i, loadJavaClass);
    1.85 +}
    1.86 +
    1.87 +void InitSystemInterfaceV1(ANPSystemInterfaceV1 *i) {
    1.88 +  _assert(i->inSize == sizeof(*i));
    1.89 +  ASSIGN(i, getApplicationDataDirectory);
    1.90 +  ASSIGN(i, loadJavaClass);
    1.91 +  ASSIGN(i, setPowerState);
    1.92 +}
    1.93 +
    1.94 +void InitSystemInterfaceV2(ANPSystemInterfaceV2 *i) {
    1.95 +  _assert(i->inSize == sizeof(*i));
    1.96 +  ASSIGN(i, getApplicationDataDirectory);
    1.97 +  ASSIGN(i, loadJavaClass);
    1.98 +  ASSIGN(i, setPowerState);
    1.99 +}

mercurial