Commit Graph

134 Commits

Author SHA1 Message Date
Rob Wu
310ffdc115 Bug 1501375 - Clear primed listeners on extension shutdown r=aswan
In D9959 and D10954, the implementation of background page machinery
was updated so that the `build` method of `BackgroundPage` is
guaranteed to return eventually, without error. Even if the load of
the background page was interrupted by an extension shut down.

When an extension shuts down during start-up, primed listeners have
likely not been re-registered. To prevent interruption of startup
from causing the loss of persistent listeners, this commit changes
the implementation such that persistent listeners are only updated if
the background page was fully loaded.
Otherwise listeners are cleared from memory, but not unregistered.

Depends on D10954

Differential Revision: https://phabricator.services.mozilla.com/D17700
2019-02-20 21:53:08 +00:00
Luca Greco
a97f99ef29 Bug 1515817 - Check if contentWindow is a dead wrapper in the InnerWindowReference invalidate method. r=robwu
Differential Revision: https://phabricator.services.mozilla.com/D20185
2019-02-18 16:23:27 +00:00
Kris Maglione
856fa07b17 Bug 1514594: Part 3 - Change ChromeUtils.import API.
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8

This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:

  ChromeUtils.import("resource://gre/modules/Services.jsm");

is approximately the same as the following, in the new model:

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

Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs

This was done using the followng script:

https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16750
2019-01-17 10:18:31 -08:00
Kris Maglione
541a602618 Bug 1476032: Neuter StructuredCloneHolder objects after deserializing. r=aswan
Differential Revision: https://phabricator.services.mozilla.com/D17287
2019-01-22 13:01:22 -08:00
Jeff Walden
d8edda9a4c Bug 1492937 - Make the JS subscript loader load scripts exclusively as UTF-8, with no way to specify any other encoding, and adjust a bunch of existing tests to use UTF-8 directly, rather than Unicode escape sequences or similar. (This also changes the encoding of .sjs scripts and all mochitest-browser tests in the tree from Latin-1 to UTF-8.) r=yzen, r=MattN, r=jimb, r=kmag 2018-12-19 13:46:20 -08:00
Shane Caraveo
631fa5854e Bug 1345474 - Check incognito access for content scripts r=rpl
Depends on D4100

Differential Revision: https://phabricator.services.mozilla.com/D4109
2018-12-10 21:27:45 +00:00
Shane Caraveo
0cf35e1dd8 Bug 1345474 - Add policy flags to support incognito settings r=rpl,kmag
Differential Revision: https://phabricator.services.mozilla.com/D4100
2018-12-10 21:27:22 +00:00
Rob Wu
0c38805090 Bug 1280347 - Normalize local ExtensionErrors r=mixedpuppy
Normalize errors thrown by extension API implementations in content
processes to ensure that extension code can read the error message
if the error is an instance of ExtensionUtils.ExtensionError.

This code path is triggered in browser_ext_menus_replace.js and
browser_ext_menus_replace_menu_permissions.js.

Depends on D6625

Differential Revision: https://phabricator.services.mozilla.com/D6626
2018-09-27 08:21:06 +00:00
Zibi Braniecki
a968635d1d Bug 1491394 - Update callsites to use new mozILocaleService API. r=jfkthame
Depends on D5924

Differential Revision: https://phabricator.services.mozilla.com/D6339
2018-09-21 15:30:37 +00:00
Luca Greco
76fd9e7ffe Bug 1437864 - Save a copy of the Error and Promise globals from extension context before they can be redefined. r=zombie,mixedpuppy
MozReview-Commit-ID: ALNJDiBwZL7

Differential Revision: https://phabricator.services.mozilla.com/D4354
2018-09-12 16:46:06 +00:00
Bogdan Tara
5fef91f7a2 Backed out 4 changesets (bug 1437864, bug 1470466, bug 1437861) for Android xpcshell failures CLOSED TREE
Backed out changeset a6185abfc2f8 (bug 1470466)
Backed out changeset 82d60e34a977 (bug 1437864)
Backed out changeset 7634d9d14449 (bug 1437864)
Backed out changeset a92b6e069d7e (bug 1437861)
2018-09-12 00:57:00 +03:00
Luca Greco
ffd0a4985a Bug 1437864 - Save a copy of the Error and Promise globals from extension context before they can be redefined. r=zombie,mixedpuppy
MozReview-Commit-ID: ALNJDiBwZL7

Differential Revision: https://phabricator.services.mozilla.com/D4354
2018-09-11 10:08:03 +00:00
Rob Wu
5c1b33fbb2 Bug 1462121 - Improve reliability of context.contentWindow/active r=zombie
- Register pagehide/pageshow events in the system group and ignore
  synthetic events to avoid interference from web pages.
- Remove unused docShell member.
- Fix memory leak in bfcached windows, by ensuring that BaseContext
  instances can be GC'd when an extension is unloaded, even if the
  context is associated with a page in the bfcache.
- Ensure that context.contentWindow and context.active always have an
  accurate value.

The latter is achieved by moving all contentWindow tracking logic in a
new helper class "InnerWindowReference".

Differential Revision: https://phabricator.services.mozilla.com/D4072
2018-09-05 12:11:09 +00:00
shindli
4adffb0ff6 Backed out changeset 8d6a57caa626 (bug 1462121) for bc16 failures in browser_ext_getViews.js 2018-09-04 19:25:19 +03:00
Rob Wu
ce0392a1b7 Bug 1462121 - Improve reliability of context.contentWindow/active r=zombie
- Register pagehide/pageshow events in the system group and ignore
  synthetic events to avoid interference from web pages.
- Remove unused docShell member.
- Fix memory leak in bfcached windows, by ensuring that BaseContext
  instances can be GC'd when an extension is unloaded, even if the
  context is associated with a page in the bfcache.
- Ensure that context.contentWindow and context.active always have an
  accurate value.

The latter is achieved by moving all contentWindow tracking logic in a
new helper class "InnerWindowReference".

Differential Revision: https://phabricator.services.mozilla.com/D4072
2018-09-04 13:17:10 +00:00
Margareta Eliza Balazs
4e47eebb96 Backed out changeset e31d944d504b (bug 1462121) for mozbuild bustage in /builds/worker/workspace/build/src/toolkit/components/extensions/moz.build CLOSED TREE 2018-09-04 15:26:45 +03:00
Rob Wu
f1111b3510 Bug 1462121 - Improve reliability of context.contentWindow/active r=zombie
- Register pagehide/pageshow events in the system group and ignore
  synthetic events to avoid interference from web pages.
- Remove unused docShell member.
- Fix memory leak in bfcached windows, by ensuring that BaseContext
  instances can be GC'd when an extension is unloaded, even if the
  context is associated with a page in the bfcache.
- Ensure that context.contentWindow and context.active always have an
  accurate value.

The latter is achieved by moving all contentWindow tracking logic in a
new helper class "InnerWindowReference".

Differential Revision: https://phabricator.services.mozilla.com/D4072
2018-09-04 12:12:01 +00:00
Oriol Brufau
67b140d7db Bug 1474440 - Implement support for the 'onHighlighted' API for multiselect tabs r=mixedpuppy
MozReview-Commit-ID: 8aOmdj0AB3e
2018-07-28 13:15:55 +02:00
Boris Zbarsky
a93cf3d175 Bug 1479569 part 2. Use the new messageManager getter on docshell. r=kmag
I generally tried to preserve the behavior of consumers where they treated an
exception from getInterface(Ci.nsIContentFrameMessageManager) as a signal to use
some sort of fallback.

I did change the behavior of consumers that walked up to the root same-type
docshell before getting the message manager to just get it directly from the
docshell they have.  Please review those parts carefully, and let me know if you
want me to ask some subject area experts to review those.
2018-08-02 23:49:09 -04:00
Csoregi Natalia
5bd0ca7b64 Backed out 3 changesets (bug 1479569) for devtools/client/responsive.html failures. CLOSED TREE
Backed out changeset e123d0aa911c (bug 1479569)
Backed out changeset b828a58404e5 (bug 1479569)
Backed out changeset 97041ef8f311 (bug 1479569)
2018-08-03 10:39:12 +03:00
Boris Zbarsky
3344641137 Bug 1479569 part 2. Use the new messageManager getter on docshell. r=kmag
I generally tried to preserve the behavior of consumers where they treated an
exception from getInterface(Ci.nsIContentFrameMessageManager) as a signal to use
some sort of fallback.

I did change the behavior of consumers that walked up to the root same-type
docshell before getting the message manager to just get it directly from the
docshell they have.  Please review those parts carefully, and let me know if you
want me to ask some subject area experts to review those.
2018-08-02 23:49:09 -04:00
Kris Maglione
e97c582e3f Bug 1463291: Move docShell getter from Document to Window. r=bz
DocShells are associated with outer DOM Windows, rather than Documents, so
having the getter on the document is a bit odd to begin with. But it's also
considerably less convenient, since most of the times when we want a docShell
from JS, we're dealing most directly with a window, and have to detour through
the document to get it.

MozReview-Commit-ID: LUj1H9nG3QL
2018-05-21 16:58:23 -07:00
Narcis Beleuzu
749f83cc65 Backed out 2 changesets (bug 1463016, bug 1463291) for geckoview failures
Backed out changeset fcfb99baa0f0 (bug 1463291)
Backed out changeset 0d69b4fb1ed4 (bug 1463016)
2018-07-29 03:55:23 +03:00
Kris Maglione
6dcf46ad68 Bug 1463291: Move docShell getter from Document to Window. r=bz
DocShells are associated with outer DOM Windows, rather than Documents, so
having the getter on the document is a bit odd to begin with. But it's also
considerably less convenient, since most of the times when we want a docShell
from JS, we're dealing most directly with a window, and have to detour through
the document to get it.

MozReview-Commit-ID: LUj1H9nG3QL
2018-05-21 16:58:23 -07:00
Kris Maglione
bb663b9c15 Bug 1471102: Move more code out of ExtensionUtils.jsm. r=aswan
MozReview-Commit-ID: Fqlv5BRuuW8
2018-06-25 19:30:21 -07:00
Kris Maglione
0847e8227e Bug 1464548: Part 3 - Update callers to use defineLazyGlobalGetters. r=mccr8
MozReview-Commit-ID: 9APGewiDDYB
2018-05-25 17:02:29 -07:00
Andrew Swan
207ad9dc56 Bug 1467136 Ensure extension messaging cannot miss the startup event r=kmag
When a background page has a messaging listener but the background page
is started in response to something other than an extension message, we
were missing the background "startup" event.  Fix that by setting up the
listener earlier.

MozReview-Commit-ID: Cr58EyCoY6W
2018-06-06 13:58:43 -07:00
Andrew Swan
84ecc06250 Bug 1369841 Make browser.runtime.onMessage and onConnect persistent r=zombie
MozReview-Commit-ID: 4LdBeEERtsD
2018-05-29 17:40:53 -07:00
Andreea Pavel
6eb96b6639 Backed out changeset 5cd398cc6a4b (bug 1369841) for failing browser chrome at browser/components/extensions/test/browser/browser_ext_legacy_extension_context_contentscript.js on a CLOSED TREE 2018-06-03 00:48:16 +03:00
Andrew Swan
6eb7210624 Bug 1369841 Make browser.runtime.onMessage and onConnect persistent r=zombie
MozReview-Commit-ID: 4LdBeEERtsD
2018-05-29 17:40:53 -07:00
Andrew Swan
b1feeb96c8 Bug 1447551 Part 1: Fix some issues with persistent EventManagers r=kmag
- Un-lazify the startup promises in ext-toolkit.js since the
  manifest background property is handled asynchronously, so it
  races with startup and can miss the relevant events if it
  loses the race.
- Ensure that persistent events don't cause breakage when the
  background-delayed-startup preference is set to false.
- Add a wakeup() method to the fire object provided to primed
  listeners.  This method returns a Promise that resolves when
  the extension background page has started.  Events that need to
  do some work in the context of the extension can wait on the
  result of wakeup(), then continue processing after the background
  page is started, using fire.[a?]sync as normal.

MozReview-Commit-ID: HiYOguVdEQK
2018-04-20 16:09:13 -07:00
Kris Maglione
b3990a2d91 Bug 1456686: Part 1 - Fix unused and shadowed explicit imports. r=standard8
These issues were previously ignored due to the nature of our global import
rules. They need to be fixed before that rule can be updated.

MozReview-Commit-ID: DCChktTc5TW
2018-04-24 20:18:09 -07:00
Gurzau Raul
5bab245fc3 Backed out 2 changesets (bug 1447551) for failing on xpcshell/test_ext_webRequest_startup.js
Backed out changeset cbae9dd05293 (bug 1447551)
Backed out changeset 50a1ddd35664 (bug 1447551)
2018-04-25 12:49:05 +03:00
Andrew Swan
b50f743c88 Bug 1447551 Part 1: Fix some issues with persistent EventManagers r=kmag
- Un-lazify the startup promises in ext-toolkit.js since the
  manifest background property is handled asynchronously, so it
  races with startup and can miss the relevant events if it
  loses the race.
- Ensure that persistent events don't cause breakage when the
  background-delayed-startup preference is set to false.
- Add a wakeup() method to the fire object provided to primed
  listeners.  This method returns a Promise that resolves when
  the extension background page has started.  Events that need to
  do some work in the context of the extension can wait on the
  result of wakeup(), then continue processing after the background
  page is started, using fire.[a?]sync as normal.

MozReview-Commit-ID: HiYOguVdEQK
2018-04-20 16:09:13 -07:00
Kris Maglione
d380a39518 Bug 1452307: Remove support for old-style experiment API extensions. r=aswan
MozReview-Commit-ID: 5y48pMRQ5XW
2018-04-06 18:14:59 -07:00
Andrew Swan
71b430f70e Bug 1450388 Part 3: Implement persistent option for EventManager r=kmag
MozReview-Commit-ID: BtccacvzhE8
2018-03-30 16:38:42 -07:00
Andrew Swan
dfdaca71bf Bug 1450388 Part 1 Refactor EventManager r=kmag
As we add more behaviors to EventManager, the signature of the constructor
is going to get really clumsy.  Head that off by converting it to take a
general parameters object.

This introduces a compatibility problem for existing webextension experiments,
put in a backward-compatibility shim for now.

MozReview-Commit-ID: 72QDfiwRm5j
2018-03-14 14:52:44 -07:00
Kris Maglione
4c402a31f9 Bug 1451215: Run codespell on code. r=aswan
MozReview-Commit-ID: HIilZTKcQUY
2018-04-03 22:22:07 -07:00
Kris Maglione
a68a7b5ca9 Bug 1441333: Part 5 - Use proper async caller location in normalizeError. r=zombie
Currently, when we create an error object at the end of an aysnc operation, we
only get a useful caller location if async stacks are enabled.

This patch changes our behavior to use the saved caller location we've already
stored when creating an Error object based on a plain string message.

MozReview-Commit-ID: DDO0lAUHYRO
2018-03-01 16:39:08 -08:00
Kris Maglione
50e5efde7d Bug 1441333: Part 4 - Add caller location to async API errors. r=zombie
When we report errors generated by async API operations, they are currently
not tied to any relevant extension source location. Instead, the locations in
the error reports point to the location in the framework code which reported
the error, which makes things extremely difficult to diagnose.

This change saves the extension caller location at the beginning of async API
operations, and adds it to the error reports genearted by that operation. This
should give extension developers a useful starting point for debugging them.

MozReview-Commit-ID: AkknkKEosFt
2018-02-26 15:25:03 -08:00
Andrew Swan
1ca7c0ba65 Bug 1434076 Correct calls to getAPI() on wrong api manager r=kmag
MozReview-Commit-ID: ADrV9x8gXhc
2018-02-22 12:20:34 -08:00
Florian Quèze
f1a55f73f8 Bug 1440284 - change this.EXPORTED_SYMBOLS back to var EXPORTED_SYMBOLS in JS modules, r=mccr8. 2018-02-23 20:50:01 +01:00
Andrew McCreight
272cee1e65 Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG
2018-02-06 09:36:57 -08:00
Kris Maglione
0bb74efdf1 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl
2018-01-29 15:20:18 -08:00
Cosmin Sabou
f09d6d985d Backed out 3 changesets (bug 1431533) for Android mochitest failures on testEventDispatcher on a CLOSED TREE
Backed out changeset a1eca62826a1 (bug 1431533)
Backed out changeset 34c999fa006b (bug 1431533)
Backed out changeset e2674287e57f (bug 1431533)
2018-01-30 07:17:48 +02:00
Kris Maglione
fd67f090b2 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl
2018-01-29 15:20:18 -08:00
Brindusan Cristian
483ba301cb Backed out 2 changesets (bug 1431533) for ESlint failures on a CLOSED TREE
Backed out changeset 6e56f4c8843e (bug 1431533)
Backed out changeset 12fc4dee861c (bug 1431533)
2018-01-30 02:32:43 +02:00
Kris Maglione
683a97d172 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl
2018-01-29 15:20:18 -08:00
Kris Maglione
1046270983 Backed out 3 changesets (bug 1431533) for Android mochitest bustage. CLOSED TREE
MozReview-Commit-ID: 5ubE9EMQpZ9
2018-01-24 22:04:59 -08:00
Kris Maglione
50ace7f99d Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
MozReview-Commit-ID: 8V1ZT53ReiP
2018-01-24 15:48:47 -08:00