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

Support extensions.%NAME%.userdisabled #2333

Closed
ghost opened this issue Mar 8, 2017 · 10 comments
Closed

Support extensions.%NAME%.userdisabled #2333

ghost opened this issue Mar 8, 2017 · 10 comments
Assignees

Comments

@ghost
Copy link

ghost commented Mar 8, 2017

%NAME% is simply whatever we decide to name this thing. Right now it's "pageshot".

#2332 is our high-level disable flag. No one should be messing with that flag (random power-user aside) -- it's entirely there to enable us to roll this out slowly with Shield.

This issue is about implementing the code that allows the user to disable Page Shot. Some details:

  • I'm suggesting using the flag extensions.pageshot.userdisabled but pick a different one if you like
  • The code should look for this flag pretty early on startup (could be right after the code in Support extensions.%NAME%.disabled #2332)
  • This code actually needs some UI in about:preferences. @johngruen where should this go and what should it look like?
@johngruen johngruen removed the needs:UX label Mar 9, 2017
@ghost ghost added this to the Page Shot in 54 milestone Mar 9, 2017
@jaredhirsch
Copy link
Member

I'm not sure about preferences UI for embedded webextensions. This also depends on whether we want users to see page shot in about:addons or not (I don't recall what the decision was there).

@andymckay, if we want to allow users to disable page shot (embedded webextension system addon), should we implement that UI using the webextension approach or the bootstrapped addon approach?

@andymckay
Copy link

Let's try to avoid writing more XUL and focus on the webExtension approach please.

Note that chrome_style for the settings page is landing in 55, sadly a release too late.

https://bugzilla.mozilla.org/show_bug.cgi?id=1275287

@jaredhirsch
Copy link
Member

jaredhirsch commented Mar 9, 2017

@andymckay sounds good to me! thanks :-)

@ianb
Copy link
Contributor

ianb commented Mar 9, 2017

If we want to disable the WebExtension entirely when the pref is off (by not calling .startup()), then I don't think we can use the WebExtension approach, can we? Also since the add-on won't appear in about:addons, there's no place for the preferences button.

@jaredhirsch
Copy link
Member

jaredhirsch commented Mar 15, 2017

TL;DR: yes, you can shutdown and restart embedded webextensions, but I'm not sure it's safe to do so

It turns out that embedded webextensions have an undocumented shutdown method. Here's how you shut down the webextension without shutting down the outer extension (we could do this in a pref listener):

const { EmbeddedExtensionManager } = Cu.import("resource://gre/modules/LegacyExtensionsUtils.jsm");
const webext = EmbeddedExtensionManager.getEmbeddedExtensionFor({id: 'pageshot@mozilla.org'});
webext.shutdown();

One problem here is that there's a bit of state that tracks whether the webextension has ever been started. To disable, then re-enable the webextension, we have to manually unset that state. This might be okay, if the addons team thinks these APIs are stable:

// re-enabling a shutdown embedded webextension:

// manually unset the 'started' state :-\
webext.started = false;
// retrigger startup
webext.startup();

I've tried toggling the webextension off and back on using these code snippets, and the toolbar button does appear and disappear, and the re-enabled webextension seems to take shots just fine. So, it seems ok in 54 today (currently dev edition).

The big question is whether we can trust this code to work in the future. I'll follow up with the addons team to figure this out.

@jaredhirsch
Copy link
Member

According to kmaglione, we should create a new instance, rather than restart a webextension that's been shutdown.

This is the snippet that should work, but I need to make sure the jar:file: URI creation bit is done properly:

/* how to safely shutdown the webext */
const { EmbeddedExtensionManager } = Cu.import("resource://gre/modules/LegacyExtensionsUtils.jsm");
const webext = EmbeddedExtensionManager.getEmbeddedExtensionFor({id: 'pageshot@mozilla.org'});
webext.shutdown();
// unlink the old webextension
EmbeddedExtensionManager.untrackEmbeddedExtension(webext);

/* how to safely lazily create a new webextension */
let pageshotAddon;
AddonManager.getAddonById('pageshot@mozilla.org', addon => { pageshotAddon = addon; });
// I dunno about this line, jarfile stuff is outside my comfort zone
const funkyURI = 'jar:' + pageshotAddon.getResourceURI().asciiSpec + '!/';
const resourceURI = Services.io.newURI(funkyURI);
// because the old one was unlinked, this get call spawns a new one,
// but fails if the resourceURI isn't passed in
const newWebext = EmbeddedExtensionManager.getEmbeddedExtensionFor({
  id: 'pageshot@mozilla.org',
  resourceURI: resourceURI
});
newWebext.startup(); // works

@jaredhirsch
Copy link
Member

My approach to building the jar URI seems to be correct, or at least, that same approach is used in some Firefox tests.

@jaredhirsch
Copy link
Member

I think self.id could be used in place of the addon's name, which would let this skate around any impending mass name changes.

@jaredhirsch
Copy link
Member

Hitting some super weird errors. It's surprisingly quite difficult to get the embedding bootstrapped extension to load properly; ./bin/run-addon --bootstrap does not seem to consistently work. I cannot figure out why.

I've tried doing jpm xpi, then loading the addon into a running Nightly profile, but jpm xpi outputs a file named null.xpi, so I suspect the generated xpi is not working quite right.

Anyhow, the code as written seems correct, but there are two recurring, intermittent bugs:

  • after setting userdisabled to true, then restarting, the toolbar button reappears
  • after setting userdisabled to true, then to false, the toolbar button reappears, but clicking it does nothing

When these two bugs occur, the profile seems to be in an odd state: I can't find bootstrap.js in the debugger (hence, can't debug the error). I don't know if this points to caching problems in the debugger, or some other weirdness. jpm xpi spitting out 'null.xpi' probably indicates I'm not building the addon correctly.

jaredhirsch pushed a commit that referenced this issue Mar 18, 2017
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 pushed a commit that referenced this issue Mar 18, 2017
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 pushed a commit that referenced this issue Mar 18, 2017
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 pushed a commit that referenced this issue Mar 18, 2017
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 pushed a commit that referenced this issue Mar 18, 2017
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.
@ianb ianb closed this as completed in b28d687 Mar 20, 2017
@johngruen
Copy link
Contributor

@6a68 Pref should go at the bottom of about:preferences#content

screen shot 2017-04-05 at 11 14 08 am

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants