mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
Differential Revision: https://phabricator.services.mozilla.com/D128815
This commit is contained in:
parent
cc5ddd2ed5
commit
c7a4bab1b6
@ -50,8 +50,6 @@ FINAL_TARGET_FILES.actors += [
|
||||
"BrowserTabParent.jsm",
|
||||
"ClickHandlerChild.jsm",
|
||||
"ClickHandlerParent.jsm",
|
||||
"ContentMetaChild.jsm",
|
||||
"ContentMetaParent.jsm",
|
||||
"ContentSearchChild.jsm",
|
||||
"ContentSearchParent.jsm",
|
||||
"ContextMenuChild.jsm",
|
||||
|
@ -6093,6 +6093,17 @@
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
|
||||
this.addEventListener("pageinfo", event => {
|
||||
let browser = event.originalTarget;
|
||||
let tab = this.getTabForBrowser(browser);
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { url, description, previewImageURL } = event.detail;
|
||||
this.setPageInfo(url, description, previewImageURL);
|
||||
});
|
||||
},
|
||||
|
||||
setSuccessor(aTab, successorTab) {
|
||||
|
@ -400,22 +400,6 @@ let JSWINDOWACTORS = {
|
||||
allFrames: true,
|
||||
},
|
||||
|
||||
// Collects description and icon information from meta tags.
|
||||
ContentMeta: {
|
||||
parent: {
|
||||
moduleURI: "resource:///actors/ContentMetaParent.jsm",
|
||||
},
|
||||
|
||||
child: {
|
||||
moduleURI: "resource:///actors/ContentMetaChild.jsm",
|
||||
events: {
|
||||
DOMMetaAdded: {},
|
||||
},
|
||||
},
|
||||
|
||||
messageManagerGroups: ["browsers"],
|
||||
},
|
||||
|
||||
ContentSearch: {
|
||||
parent: {
|
||||
moduleURI: "resource:///actors/ContentSearchParent.jsm",
|
||||
|
@ -901,6 +901,7 @@ package org.mozilla.geckoview {
|
||||
method @UiThread default public void onMetaViewportFitChange(@NonNull GeckoSession, @NonNull String);
|
||||
method @UiThread default public void onPaintStatusReset(@NonNull GeckoSession);
|
||||
method @UiThread default public void onPointerIconChange(@NonNull GeckoSession, @NonNull PointerIcon);
|
||||
method @UiThread default public void onPreviewImage(@NonNull GeckoSession, @NonNull String);
|
||||
method @UiThread default public void onShowDynamicToolbar(@NonNull GeckoSession);
|
||||
method @Nullable @UiThread default public GeckoResult<SlowScriptResponse> onSlowScript(@NonNull GeckoSession, @NonNull String);
|
||||
method @UiThread default public void onTitleChange(@NonNull GeckoSession, @Nullable String);
|
||||
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>MetaTags</title>
|
||||
<meta property="twitter:description" content="twitter:description" />
|
||||
<meta property="og:description" content="og:description" />
|
||||
<meta name="description" content="description" />
|
||||
<meta name="unknown:tag" content="unknown:tag" />
|
||||
<meta property="og:image" content="https://test.com/og-image.jpg" />
|
||||
<meta property="twitter:image" content="https://test.com/twitter-image.jpg" />
|
||||
<meta property="og:image:url" content="https://test.com/og-image-url" />
|
||||
<meta name="thumbnail" content="https://test.com/thumbnail.jpg" />
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
@ -53,6 +53,7 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
|
||||
const val INVALID_URI = "not a valid uri"
|
||||
const val LINKS_HTML_PATH = "/assets/www/links.html"
|
||||
const val LOREM_IPSUM_HTML_PATH = "/assets/www/loremIpsum.html"
|
||||
const val METATAGS_PATH = "/assets/www/metatags.html"
|
||||
const val MOUSE_TO_RELOAD_HTML_PATH = "/assets/www/mouseToReload.html"
|
||||
const val NEW_SESSION_CHILD_HTML_PATH = "/assets/www/newSession_child.html"
|
||||
const val NEW_SESSION_HTML_PATH = "/assets/www/newSession.html"
|
||||
|
@ -274,6 +274,16 @@ class ContentDelegateTest : BaseSessionTest() {
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun previewImage() {
|
||||
mainSession.loadTestPath(METATAGS_PATH)
|
||||
mainSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onPreviewImage(session: GeckoSession, previewImageUrl: String) {
|
||||
assertThat("Preview image should match", previewImageUrl, equalTo("https://test.com/og-image-url"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun viewportFit() {
|
||||
mainSession.loadTestPath(VIEWPORT_PATH)
|
||||
mainSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate {
|
||||
|
@ -377,6 +377,7 @@ public class GeckoSession {
|
||||
"GeckoView:WebAppManifest",
|
||||
"GeckoView:FirstContentfulPaint",
|
||||
"GeckoView:PaintStatusReset",
|
||||
"GeckoView:PreviewImage",
|
||||
}) {
|
||||
@Override
|
||||
public void handleMessage(
|
||||
@ -431,6 +432,8 @@ public class GeckoSession {
|
||||
delegate.onFirstContentfulPaint(GeckoSession.this);
|
||||
} else if ("GeckoView:PaintStatusReset".equals(event)) {
|
||||
delegate.onPaintStatusReset(GeckoSession.this);
|
||||
} else if ("GeckoView:PreviewImage".equals(event)) {
|
||||
delegate.onPreviewImage(GeckoSession.this, message.getString("previewImageUrl"));
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -2859,6 +2862,16 @@ public class GeckoSession {
|
||||
@UiThread
|
||||
default void onTitleChange(@NonNull final GeckoSession session, @Nullable final String title) {}
|
||||
|
||||
/**
|
||||
* A preview image was discovered in the content after the content loaded.
|
||||
*
|
||||
* @param session The GeckoSession that initiated the callback.
|
||||
* @param previewImageUrl The preview image URL sent from the content.
|
||||
*/
|
||||
@UiThread
|
||||
default void onPreviewImage(
|
||||
@NonNull final GeckoSession session, @NonNull final String previewImageUrl) {}
|
||||
|
||||
/**
|
||||
* A page has requested focus. Note that window.focus() in content will not result in this being
|
||||
* called.
|
||||
|
@ -26,6 +26,8 @@ exclude: true
|
||||
protection permissions in private browsing).
|
||||
- Deprecated [`GeckoRuntimeSettings.Builder.enterpiseRootsEnabled`][95.7] due to typo.
|
||||
- Added [`GeckoRuntimeSettings.Builder.enterpriseRootsEnabled`][95.8] to replace [`GeckoRuntimeSettings.Builder.enterpiseRootsEnabled`][95.7].
|
||||
- Added [`GeckoSession.ContentDelegate.onPreviewImage()`][95.9] to notify
|
||||
the application of a preview image URL.
|
||||
|
||||
[95.1]: {{javadoc_uri}}/GeckoSession.ContentDelegate.html#onPointerIconChange-org.mozilla.geckoview.GeckoSession-android.view.PointerIcon-
|
||||
[95.2]: {{javadoc_uri}/ContentBlockingController.html
|
||||
@ -35,6 +37,7 @@ exclude: true
|
||||
[95.6]: {{javadoc_uri}/StorageController.html#setPrivateBrowsingPermanentPermission-org.mozilla.geckoview.GeckoSession.PermissionDelegate.ContentPermission-int-
|
||||
[95.7]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#enterpiseRootsEnabled-boolean-
|
||||
[95.8]: {{javadoc_uri}}/GeckoRuntimeSettings.Builder.html#enterpriseRootsEnabled-boolean-
|
||||
[95.9]: {{javadoc_uri}}/GeckoSession.ContentDelegate.html#onPreviewImage-org.mozilla.geckoview.GeckoSession-java.lang.String-
|
||||
|
||||
## v94
|
||||
- Extended [`Autocomplete`][78.7] API to support credit card saving.
|
||||
@ -1069,4 +1072,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]: efde9e11f6249cf145903d7c6e317d5c17be8d1e
|
||||
[api-version]: d44de923c2ba7fb152398b9001d26b4ed2689138
|
||||
|
@ -56,6 +56,7 @@ class GeckoViewContent extends GeckoViewModule {
|
||||
|
||||
this.window.addEventListener("DOMWindowClose", this);
|
||||
this.window.addEventListener("pagetitlechanged", this);
|
||||
this.window.addEventListener("pageinfo", this);
|
||||
|
||||
Services.obs.addObserver(this, "oop-frameloader-crashed");
|
||||
Services.obs.addObserver(this, "ipc:content-shutdown");
|
||||
@ -80,6 +81,7 @@ class GeckoViewContent extends GeckoViewModule {
|
||||
|
||||
this.window.removeEventListener("DOMWindowClose", this);
|
||||
this.window.removeEventListener("pagetitlechanged", this);
|
||||
this.window.removeEventListener("pageinfo", this);
|
||||
|
||||
Services.obs.removeObserver(this, "oop-frameloader-crashed");
|
||||
Services.obs.removeObserver(this, "ipc:content-shutdown");
|
||||
@ -208,6 +210,14 @@ class GeckoViewContent extends GeckoViewModule {
|
||||
type: "GeckoView:DOMWindowClose",
|
||||
});
|
||||
break;
|
||||
case "pageinfo":
|
||||
if (aEvent.detail.previewImageURL) {
|
||||
this.eventDispatcher.sendRequest({
|
||||
type: "GeckoView:PreviewImage",
|
||||
previewImageUrl: aEvent.detail.previewImageURL,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,14 +11,16 @@ class ContentMetaParent extends JSWindowActorParent {
|
||||
if (message.name == "Meta:SetPageInfo") {
|
||||
let browser = this.manager.browsingContext.top.embedderElement;
|
||||
if (browser) {
|
||||
let gBrowser = browser.ownerGlobal.gBrowser;
|
||||
if (gBrowser) {
|
||||
gBrowser.setPageInfo(
|
||||
message.data.url,
|
||||
message.data.description,
|
||||
message.data.previewImageURL
|
||||
);
|
||||
}
|
||||
let event = new browser.ownerGlobal.CustomEvent("pageinfo", {
|
||||
bubbles: true,
|
||||
cancelable: false,
|
||||
detail: {
|
||||
url: message.data.url,
|
||||
description: message.data.description,
|
||||
previewImageURL: message.data.previewImageURL,
|
||||
},
|
||||
});
|
||||
browser.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,8 @@ FINAL_TARGET_FILES.actors += [
|
||||
"BackgroundThumbnailsChild.jsm",
|
||||
"BrowserElementChild.jsm",
|
||||
"BrowserElementParent.jsm",
|
||||
"ContentMetaChild.jsm",
|
||||
"ContentMetaParent.jsm",
|
||||
"ControllersChild.jsm",
|
||||
"ControllersParent.jsm",
|
||||
"DateTimePickerChild.jsm",
|
||||
|
@ -189,6 +189,21 @@ let JSWINDOWACTORS = {
|
||||
allFrames: true,
|
||||
},
|
||||
|
||||
ContentMeta: {
|
||||
parent: {
|
||||
moduleURI: "resource://gre/actors/ContentMetaParent.jsm",
|
||||
},
|
||||
|
||||
child: {
|
||||
moduleURI: "resource://gre/actors/ContentMetaChild.jsm",
|
||||
events: {
|
||||
DOMMetaAdded: {},
|
||||
},
|
||||
},
|
||||
|
||||
messageManagerGroups: ["browsers"],
|
||||
},
|
||||
|
||||
Controllers: {
|
||||
parent: {
|
||||
moduleURI: "resource://gre/actors/ControllersParent.jsm",
|
||||
|
Loading…
x
Reference in New Issue
Block a user