Commit 10600496 authored by Calixte's avatar Calixte
Browse files

Bug 1833093 - Add suport for Nimbus in pdf.js with GeckoView...

Bug 1833093 - Add suport for Nimbus in pdf.js with GeckoView r=geckoview-reviewers,pdfjs-reviewers,marco,amejiamarmol,ohall

Differential Revision: https://phabricator.services.mozilla.com/D178045
parent 0af92a8d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -988,6 +988,7 @@ package org.mozilla.geckoview {
    method @UiThread default public void onFirstContentfulPaint(@NonNull GeckoSession);
    method @UiThread default public void onFocusRequest(@NonNull GeckoSession);
    method @UiThread default public void onFullScreen(@NonNull GeckoSession, boolean);
    method @AnyThread @Nullable default public JSONObject onGetNimbusFeature(@NonNull GeckoSession, @NonNull String);
    method @UiThread default public void onKill(@NonNull GeckoSession);
    method @UiThread default public void onMetaViewportFitChange(@NonNull GeckoSession, @NonNull String);
    method @UiThread default public void onPaintStatusReset(@NonNull GeckoSession);
+35 −0
Original line number Diff line number Diff line
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

package org.mozilla.geckoview.test

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.hamcrest.Matchers.equalTo
import org.json.JSONObject
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSession.ContentDelegate

@RunWith(AndroidJUnit4::class)
@MediumTest
class NimbusTest : BaseSessionTest() {

    @Test
    fun withPdfJS() {
        mainSession.loadTestPath(TRACEMONKEY_PDF_PATH)

        sessionRule.waitUntilCalled(object : ContentDelegate {
            override fun onGetNimbusFeature(session: GeckoSession, featureId: String): JSONObject? {
                assertThat(
                    "Feature id should match",
                    featureId,
                    equalTo("pdfjs")
                )
                return null
            }
        })
    }
}
+29 −1
Original line number Diff line number Diff line
@@ -521,7 +521,8 @@ public class GeckoSession {
            "GeckoView:PreviewImage",
            "GeckoView:CookieBannerEvent:Detected",
            "GeckoView:CookieBannerEvent:Handled",
            "GeckoView:SavePdf"
            "GeckoView:SavePdf",
            "GeckoView:GetNimbusFeature"
          }) {
        @Override
        public void handleMessage(
@@ -594,6 +595,19 @@ public class GeckoSession {
              return;
            }
            delegate.onExternalResponse(GeckoSession.this, response);
          } else if ("GeckoView:GetNimbusFeature".equals(event)) {
            final String featureId = message.getString("featureId");
            final JSONObject res = delegate.onGetNimbusFeature(GeckoSession.this, featureId);
            if (res == null) {
              callback.sendError("No Nimbus data for the feature " + featureId);
              return;
            }
            try {
              callback.sendSuccess(GeckoBundle.fromJSONObject(res));
            } catch (final JSONException e) {
              callback.sendError(
                  "No Nimbus data for the feature " + featureId + ": conversion failed.");
            }
          }
        }
      };
@@ -3621,6 +3635,20 @@ public class GeckoSession {
     */
    @AnyThread
    default void onCookieBannerHandled(@NonNull final GeckoSession session) {}

    /**
     * This method is called when GeckoView is requesting a specific Nimbus feature in using message
     * `GeckoView:GetNimbusFeature`.
     *
     * @param session GeckoSession that initiated the callback.
     * @param featureId Nimbus feature id of the collected data.
     * @return A {@link JSONObject} with the feature.
     */
    @AnyThread
    default @Nullable JSONObject onGetNimbusFeature(
        @NonNull final GeckoSession session, @NonNull final String featureId) {
      return null;
    }
  }

  public interface SelectionActionDelegate {
+3 −1
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@ exclude: true
  ([bug 1824083]({{bugzilla}}1824083))
- Add [`onPrintWithStatus`][115.3] to retrieve additional printing status information.
- Added new [`GeckoPrintException`][115.4] errors of `ERROR_NO_ACTIVITY_CONTEXT` and `ERROR_NO_ACTIVITY_CONTEXT_DELEGATE`
- Added [`GeckoSession.ContentDelegate.onGetNimbusFeature`][115.5]

[115.1]: {{javadoc_uri}}/SessionPdfFileSaver.html#createResponse(byte[], String, String, boolean, boolean)
[115.2]: {{javadoc_uri}}/GeckoDisplay.NewSurfaceProvider.html
[115.3]: {{javadoc_uri}}/GeckoSession.PrintDelegate.html#onPrintWithStatus
[115.4]: {{javadoc_uri}}/GeckoSession.GeckoPrintException.html
[115.5]: {{javadoc_uri}}/GeckoSession.ContentDelegate.html#onGetNimbusFeature(org.mozilla.geckoview.GeckoSession)

## v114
- Add [`SessionPdfFileSaver.createResponse`][114.1] to response of saving PDF.
@@ -1368,4 +1370,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
[65.25]: {{javadoc_uri}}/GeckoResult.html

[api-version]: 206323452b40602d20d42c3e73aa88647da74696
[api-version]: cf897ca76efac25bbe2b17bb3a0a47d6f94a6bdb
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ export class GeckoViewPdfjsChild extends GeckoViewActorChild {
        this.dispatchEvent(aMsg.data.type, detail);
        break;
      }
      case "PDFJS:Child:getNimbus":
        Services.obs.notifyObservers(aMsg.data, "pdfjs-getNimbus");
        break;
    }
  }
}
Loading