Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Observe prefs and control webextension startup and shutdown via a pref #2397

Merged
merged 1 commit into from Mar 20, 2017

Conversation

ianb
Copy link
Contributor

@ianb ianb commented Mar 15, 2017

For handoff to @6a68

browser.runtime.onMessage.addListener(handleMessage);
});
} else if ((! start) && webExtensionStarted) {
// pass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, this is where shutdown should occur

// aSubject is the nsIPrefBranch we're observing (after appropriate QI)
// aData is the name of the pref that's been changed (relative to aSubject)
if (aData == "userdisabled" || aData == "systemdisabled") {
handleStartup();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about observing the Telemetry pref here, but it's not that easy – there's no way to initiate a message from bootstrap.js to the webextension. So I think the current logic for the telemetry pref is good as it is.

@jaredhirsch jaredhirsch force-pushed the enabling-pref branch 4 times, most recently from 66d553f to c020dcc Compare March 17, 2017 04:02
Components.utils.import("resource://gre/modules/Services.jsm");
const { EmbeddedExtensionManager } = Components.utils.import("resource://gre/modules/LegacyExtensionsUtils.jsm");

const prefs = Services.prefs;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/travis/build/mozilla-services/pageshot/addon/bootstrap.js
  15:15  error  'Services' is not defined  no-undef
  78:19  error  'Services' is not defined  no-undef

Not sure if we need to tweak the ESLint envs, or just manually add another globals to appease the ESLint gods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been generous adding /* globals */ to my code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianb: "I've been generous adding /* globals */ to my code"

I've noticed. We can also add them to the root .eslintrc.yml file, or even add nested .eslintrc.yml files, so you don't have to shotgun a small manifesto of global vars at the top of each file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are like pretend import statements!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, thanks @pdehaan. Updated globals.

@jaredhirsch
Copy link
Member

@ianb Would you mind giving this branch a try? It seems to be totally working for me.

Cases to try out:

  • start without the extensions.pageshot.userdisabled pref set, then toggle it on and off a few times
  • start with userdisabled set to false (should check the pref, then init the webextension)
  • start with userdisabled set to true, verify it's not loaded, then toggle the pref and verify it works

Then, same three cases for extensions.pageshot.systemdisabled.

If this seems to be working for you as well, feel free to review now, and I'll plan to squash before merging.

Copy link
Contributor Author

@ianb ianb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this, and systemdisabled didn't work, because of bad boolean logic per my comment. Otherwise things seemed to work well.

const ADDON_ID = "pageshot@mozilla.org";
const TELEMETRY_PREF = "toolkit.telemetry.enabled";
const USER_ENABLE_PREF = "extensions.pageshot.userdisabled";
const SYSTEM_ENABLE_PREF = "extensions.pageshot.systemdisabled";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is my fault, but these variables have a really bad name – ENABLE when in fact they are DISABLE

prefs.getPrefType(SYSTEM_ENABLE_PREF) &&
prefs.getBoolPref(SYSTEM_ENABLE_PREF)
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably my fault too, but the expression here is incorrect. I think it's (! USER_ENABLE_PREF) || SYSTEM_ENABLE_PREF – as a result setting extensions.pageshot.systemdisabled to true forces Page Shot on rather than off.

@jaredhirsch
Copy link
Member

thanks for looking! I'll fixup the logic

@jaredhirsch jaredhirsch changed the title WIP, observe prefs and control webextension startup and shutdown via a pref Observe prefs and control webextension startup and shutdown via a pref Mar 18, 2017
@jaredhirsch jaredhirsch force-pushed the enabling-pref branch 5 times, most recently from a7ca371 to b28d687 Compare March 18, 2017 06:11
Other changes:

* Fix #2370, unset deviceId pref set by old addon.

* Update Promise rejection / Error handling to match behavior
  documented in the addons-related Gecko code.
@jaredhirsch
Copy link
Member

@ianb Mind taking another look? Fixed up the disable check logic, did a general cleanup pass, and squashed everything into one commit. Hopefully bootstrap.js will get through Firefox review without too many problems :-P

Note that I renamed the user pref to just extensions.pageshot.disabled, because the system-disabled pref will be gone within a few weeks of launch, so calling it user-disabled seemed unnecessary.

@ianb ianb merged commit cd33c8a into master Mar 20, 2017
@ianb ianb deleted the enabling-pref branch March 20, 2017 19:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants