Open Bug 1651506 Opened 4 years ago Updated 2 years ago

viewType of browserAction/pageAction popups is not "popup" but "tab" - runtime.getViews({type: "popup"}) is broken

Categories

(GeckoView :: Extensions, defect, P3)

Unspecified
All

Tracking

(Not tracked)

People

(Reporter: robwu, Unassigned)

Details

Attachments

(1 file)

While looking at the patches for bug 1650897, I noticed that the code used context?.currentWindow?.moduleManager.settings.isPopup to check if an ExtensionPageContextParent is a browser action popup.
I wanted to suggest context?.viewType == "popup" instead, but surprisingly this did not work, because .viewType is "tab".

The user-visible effect is that extensions cannot get the expected DOM window when they call browser.extension.getViews({type: "popup"}).

On desktop, viewType is set as follows:

  1. When <browser> is created: browser.setAttribute("webextension-view-type", "popup"); is called at browser/components/extensions/ExtensionPopups.jsm.
  2. Before the popup URL is loaded, ExtensionParent.apiManager.emit("extension-browser-inserted", browser); in ExtensionPopups.jsm.
  3. which sends viewType down the the popup via _onExtensionBrowser in ExtensionParent.jsm.
  4. which is used to initialize the extension global in the child at ExtensionProcessScript.jsm
  5. A bit later, when the extension page is loading, an ExtensionPageContextChild is constructed using the above viewType (defaulting to "tab") in ExtensionPageChild.jsm.
  6. When an extension API is dereferenced by the extension code, an ExtensionPageContextParent is constructed in the parent with details directly given by the child. This is the context that you will be seeing here.

To get viewType to work as intended, similarly to desktop, you need to call initialize it. Untested, but based on reading code I would expect this:

let browser = window.browser;
browser.setAttribute("webextension-view-type", "popup");
ExtensionParent.apiManager.emit("extension-browser-inserted", browser);

... BEFORE loading the popup.

popup is loaded here: https://searchfox.org/mozilla-central/rev/85ae3b911d5fcabd38ef315725df32e25edef83b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/WebExtension.java#1399-1400
and the setting change is received+forwarded here: https://searchfox.org/mozilla-central/rev/85ae3b911d5fcabd38ef315725df32e25edef83b/mobile/android/chrome/geckoview/geckoview.js#251-258

so I suppose that adding an onSettingsUpdate method in GeckoViewWebExtension.jsm with the above code can fix this bug.

As a unit test, open a browserAction popup, and from the background script call browser.extension.getViews({type: "popup"}) and verify that it returned the popup's DOM window.

Severity: -- → S4
Priority: -- → P3
Assignee: nobody → ankushduacodes
Status: NEW → ASSIGNED

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: ankushduacodes → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: