Commit a2821926 authored by brizental's avatar brizental Committed by Pier Angelo Vendrame
Browse files

Bug 2051440 - Replace omni.ja URI parsing in GetApkURI with a direct JNI...

Bug 2051440 - Replace omni.ja URI parsing in GetApkURI with a direct JNI call.r=ohall,necko-reviewers,geckoview-reviewers,jesup,nalexander

Differential Revision: https://phabricator.services.mozilla.com/D309470
parent 7fa9b602
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1426,6 +1426,11 @@ public class GeckoAppShell {
    }
  }

  @WrapForJNI
  public static String getPackageResourcePath() {
    return getApplicationContext().getPackageResourcePath();
  }

  @WrapForJNI(calledFrom = "any")
  public static int getAudioOutputFramesPerBuffer() {
    if (BuildConfig.DEBUG_BUILD && isIsolatedProcess()) {
+10 −23
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@
#include "nsNetUtil.h"
#include "nsURLHelper.h"

#ifdef MOZ_WIDGET_ANDROID
#  include "mozilla/java/GeckoAppShellWrappers.h"
#endif

using mozilla::LogLevel;
using mozilla::dom::ContentParent;

@@ -67,29 +71,12 @@ nsresult nsResProtocolHandler::Init() {

#ifdef ANDROID
nsresult nsResProtocolHandler::GetApkURI(nsACString& aResult) {
  nsCString::const_iterator start, iter;
  mGREURI.BeginReading(start);
  mGREURI.EndReading(iter);
  nsCString::const_iterator start_iter = start;

  // This is like jar:jar:file://path/to/apk/base.apk!/path/to/omni.ja!/
  bool found = FindInReadable("!/"_ns, start_iter, iter);
  NS_ENSURE_TRUE(found, NS_ERROR_UNEXPECTED);

  // like jar:jar:file://path/to/apk/base.apk!/
  const nsDependentCSubstring& withoutPath = Substring(start, iter);
  NS_ENSURE_TRUE(withoutPath.Length() >= 4, NS_ERROR_UNEXPECTED);

  // Let's make sure we're removing what we expect to remove
  NS_ENSURE_TRUE(Substring(withoutPath, 0, 4).EqualsLiteral("jar:"),
                 NS_ERROR_UNEXPECTED);

  // like jar:file://path/to/apk/base.apk!/
  aResult = ToNewCString(Substring(withoutPath, 4));

  // Remove the trailing /
  NS_ENSURE_TRUE(aResult.Length() >= 1, NS_ERROR_UNEXPECTED);
  aResult.Truncate(aResult.Length() - 1);
  mozilla::jni::String::LocalRef path =
      mozilla::java::GeckoAppShell::GetPackageResourcePath();
  if (!path) {
    return NS_ERROR_UNEXPECTED;
  }
  aResult = "jar:file://"_ns + path->ToCString() + "!"_ns;
  return NS_OK;
}
#endif