Commit e14b1f9c authored by Alex Catarineu's avatar Alex Catarineu Committed by Matthew Finkel
Browse files

Bug 28822: Convert onboarding to webextension

parent 25e349ce
Loading
Loading
Loading
Loading
+33 −26
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ function openTorTab(aURL, aFrameScript) {
  let win = Services.wm.getMostRecentWindow('navigator:browser');
  if (win) {
    let tabBrowser = win.gBrowser;
    let tab = tabBrowser.addTab(aURL);
    let triggeringPrincipal = Services.scriptSecurityManager.createNullPrincipal({});
    let tab = tabBrowser.addTab(aURL, { triggeringPrincipal });
    tabBrowser.selectedTab = tab;

    if (aFrameScript) {
@@ -234,18 +235,24 @@ function observe(subject, topic, data) {
  }
}

function install(aData, aReason) {}

function uninstall(aData, aReason) {}

function startup(aData, aReason) {
this.onboarding = class extends ExtensionAPI {
  onStartup() {
    resProto.setSubstitutionWithFlags(RESOURCE_HOST,
                                    Services.io.newURI("chrome/content/", null, aData.resourceURI),
      Services.io.newURI("chrome/content/", null, this.extension.rootURI),
      resProto.ALLOW_CONTENT_ACCESS);

  // Cache startup data which contains stuff like the version number, etc.
  // so we can use it when we init the telemetry
  startupData = aData;
    if (this.extension.rootURI instanceof Ci.nsIJARURI) {
      this.manifest = this.extension.rootURI.JARFile.QueryInterface(Ci.nsIFileURL).file;
    } else if (this.extension.rootURI instanceof Ci.nsIFileURL) {
      this.manifest = this.extension.rootURI.file;
    }

    if (this.manifest) {
      Components.manager.addBootstrappedManifestLocation(this.manifest);
    } else {
      Cu.reportError("Cannot find onboarding chrome.manifest for registring translated strings");
    }

    // Only start Onboarding when the browser UI is ready
    if (Services.startup.startingUp) {
      Services.obs.addObserver(observe, BROWSER_READY_NOTIFICATION);
@@ -256,13 +263,13 @@ function startup(aData, aReason) {
    }
  }

function shutdown(aData, aReason) {
  onShutdown() {
    resProto.setSubstitution(RESOURCE_HOST, null);

  startupData = null;
    // Stop waiting for browser to be ready
    if (waitingForBrowserReady) {
      Services.obs.removeObserver(observe, BROWSER_READY_NOTIFICATION);
    }
    syncTourChecker.uninit();
  }
};
+8 −0
Original line number Diff line number Diff line
/* eslint-env webextensions */

"use strict";

browser.runtime.onUpdateAvailable.addListener(details => {
  // By listening to but ignoring this event, any updates will
  // be delayed until the next browser restart.
});
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -8,12 +8,12 @@

var EXPORTED_SYMBOLS = ["Onboarding"];

ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

const ONBOARDING_CSS_URL = "resource://onboarding/onboarding.css";
const TORBUTTON_BUNDLE_URI = "chrome://torbutton/locale/browserOnboarding.properties";
const TORBROWSER_WELCOME_TOUR_NAME_KEY = "onboarding.tour-tor-welcome";
const BUNDLE_URI = "chrome://onboarding/locale/onboarding.properties";
const BUNDLE_URI = "chrome://torbutton/locale/onboarding.properties";
const UITOUR_JS_URI = "resource://onboarding/lib/UITour-lib.js";
const TOUR_AGENT_JS_URI = "resource://onboarding/onboarding-tour-agent.js";
const BRAND_SHORT_NAME = Services.strings
@@ -897,6 +897,7 @@ class Onboarding {
    const kOnionURL = "https://3g2upl4pq6kufc4m.onion/";  // DuckDuckGo
    let handledTourActionClick = false;
    switch (id) {
      case "onboarding-overlay-button-icon":
      case "onboarding-overlay-button":
        this.telemetry({
          type: "onboarding-logo-click",
@@ -1725,7 +1726,7 @@ class Onboarding {
      let tooltipStringId = Services.prefs.getStringPref(tooltipStringPrefId, defaultTourStringId);
      tooltip = this._bundle.formatStringFromName(tooltipStringId, [BRAND_SHORT_NAME], 1);
    } catch (e) {
      Cu.reportError(`the provided ${tooltipStringPrefId} string is in wrong format `, e);
      Cu.reportError(e);
      // fallback to defaultTourStringId to proceed
      tooltip = this._bundle.formatStringFromName(defaultTourStringId, [BRAND_SHORT_NAME], 1);
    }
+1 −2
Original line number Diff line number Diff line
@@ -23,8 +23,7 @@ if (Services.prefs.getBoolPref("browser.onboarding.enabled", false)) {

    let window = evt.target.defaultView;
    let location = window.location.href;
    if (location == ABOUT_NEWTAB_URL || location == ABOUT_HOME_URL ||
      location == ABOUT_WELCOME_URL || location == ABOUT_TOR_URL) {
    if (location == ABOUT_TOR_URL) {
      // We just want to run tests as quickly as possible
      // so in the automation test, we don't do `requestIdleCallback`.
      if (Cu.isInAutomation) {
+0 −28
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!--  This Source Code Form is subject to the terms of the Mozilla Public
   -  License, v. 2.0. If a copy of the MPL was not distributed with this
   -  file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

#filter substitution

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>onboarding@mozilla.org</em:id>
    <em:name>Photon onboarding</em:name>
    <em:description>Photon onboarding</em:description>
    <em:version>1.0</em:version>
    <em:bootstrap>true</em:bootstrap>
    <em:type>2</em:type>
    <em:multiprocessCompatible>true</em:multiprocessCompatible>

    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <!--Firefox-->
        <em:minVersion>@MOZ_APP_VERSION@</em:minVersion>
        <em:maxVersion>@MOZ_APP_MAXVERSION@</em:maxVersion>
      </Description>
    </em:targetApplication>
    <em:strictCompatibility>false</em:strictCompatibility>
  </Description>
</RDF>
Loading