use NavHistoryService visit's transitionType to enhance the webNavigation transition types and qualifiers

NEW
Unassigned

Status

()

Toolkit
WebExtensions: Request Handling
P5
normal
a year ago
7 months ago

People

(Reporter: rpl, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [webNavigation]triaged)

(Reporter)

Description

a year ago
The WebExtension WebNavigation API contains in some of its events (onCommitted and onHistoryStateUpdated), information that are usually related to the history tracking.

A subset of the needed information are already tracked on Firefox:

- the PlacesUIUtils.jsm asks the NavHistoryService to mark a visited urls as typed, bookmarks or link, which means the user clicked on a link
  - https://dxr.mozilla.org/mozilla-central/source/browser/components/places/PlacesUIUtils.jsm#519
  - https://dxr.mozilla.org/mozilla-central/source/browser/components/places/PlacesUIUtils.jsm#530
  - https://dxr.mozilla.org/mozilla-central/source/browser/components/places/PlacesUIUtils.jsm#540

- the NavHistoryService receives this information and send it to a list of NavHistoryObservers
  https://dxr.mozilla.org/mozilla-central/source/toolkit/components/places/History.cpp#661

Unfortunately, a NavHistoryObserver's onVisit method receives the visit information too late to be able to use it to detect the transitionType on webNavigation event related to a sub-frame (which will help us to be able to differentiate a manual_subframe from the default auto_subframe transitionType)
(Reporter)

Updated

a year ago
Whiteboard: [webNavigation]
(Reporter)

Comment 1

a year ago
After trying to detect this visit information from a registered NavHistoryObserver didn't worked with iframes, 
as an experiment, with the goal of getting a picture of the issue and its potential solutions, I've added a new "early-mark-visit" event notified using the ObserverService, in the PlacesUIUtils.jsm methods linked above (but obviously doing something similar directly from the NavHistoryService will work too), e.g.:

>   markPageAsTyped: function PUIU_markPageAsTyped(aURL) {
>+    Services.obs.notifyObservers(null, "early-mark-visit", "typed");
>     PlacesUtils.history.markPageAsTyped(this.createFixedURI(aURL));
>   },
>  
>   markPageAsFollowedBookmark: function PUIU_markPageAsFollowedBookmark(aURL) {
>+    Services.obs.notifyObservers(null, "early-mark-visit", "bookmark");
>     PlacesUtils.history.markPageAsFollowedBookmark(this.createFixedURI(aURL));
>   },
>  
>   markPageAsFollowedLink: function PUIU_markPageAsFollowedLink(aURL) {
>+    Services.obs.notifyObservers(null, "early-mark-visit", "link");
>     PlacesUtils.history.markPageAsFollowedLink(this.createFixedURI(aURL));
>   },
> 

And then using that "early-mark-visit" to get the necessary info associated to the most current selected tab:

>var NavHistoryListener = {
>  init() {
>    Services.obs.addObserver(this, "early-mark-visit", false);
>  },
>
>  uninit() {
>    Services.obs.removeObserver(this, "early-mark-visit", false);
>  },
>
>  observe: function observe(aSubject, aTopic, aData) {
>    let tabTransitionData = {};
>
>    switch (aData) {
>      case "typed":
>        tabTransitionData.typed = true;
>        break;
>      case "bookmark":
>        tabTransitionData.bookmark = true;
>        break;
>      case "link":
>        tabTransitionData.link = true;
>        break;
>    }
>
>    // Push the information into the internal webNavigation recentTabTransition tracker, 
>     // associate for the current selected tab
>    WebNavigationManager.pushRecentTabTransitionData(tabTransitionData);
>  },
>};

Updated

a year ago
Whiteboard: [webNavigation] → [webNavigation]triaged
(Reporter)

Updated

a year ago
Depends on: 1263723

Updated

7 months ago
Component: WebExtensions: Untriaged → WebExtensions: Request Handling
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.