Commit Graph

70 Commits

Author SHA1 Message Date
tophf
9163a856f6 lazify and fix refreshAllTabs 2017-06-27 12:39:51 +03:00
tophf
7443a4cb89 ensure BG is initialized in onBackgroundReady() 2017-06-18 17:04:13 +03:00
tophf
fba85b36cc promisify chrome.tabs.query as queryTabs() 2017-06-17 13:00:10 +03:00
tophf
b4e00cd892 Lazify notifyAllTabs() and injectCS()
* notifyAllTabs: the active tab gets notified immediately, the rest lazily
* notifyAllTabs + injectCS: don't notify lazy-loaded tabs in FF
2017-06-17 09:33:32 +03:00
tophf
6df2392132 FF bug workaround for tabs.query with moz-extension:// 2017-06-06 10:33:45 +03:00
tophf
be9cfe072d openURL should not redirect incognito NTP to chrome URLs 2017-06-03 16:57:52 +03:00
tophf
cec649e0ee openURL should not open own pages in incognito tabs
We're using the default "spanning mode" which doesn't support it
2017-06-03 16:52:58 +03:00
tophf
26f84c5852 play safe in *Safe() as BG gets defined only in .then 2017-05-23 22:31:40 +03:00
Jeremy Schomery
daaac972fe fixes https://github.com/schomery/stylish-chrome/issues/52#issuecomment-302394702 2017-05-19 11:53:04 +04:30
tophf
acc4d83b9d promisify DB access 2017-04-26 01:36:08 +03:00
tophf
f9e90f9cd0 code cosmetics: simplify debounce() 2017-04-23 23:05:36 +03:00
tophf
fdc15d24d9 try to avoid setBadgeText errors 2017-04-23 23:05:35 +03:00
tophf
2e60af40f0 refactor bg updater; add prefs.subscribe() 2017-04-21 15:52:22 +03:00
tophf
aa5fc9f640 notify USO earlier in install.js by relaying xhr 2017-04-20 04:52:13 +03:00
tophf
3b3ed6543e code cosmetics: RX_SUPPORTED_URLS -> URLS.supported 2017-04-18 12:47:19 +03:00
tophf
01d59192a3 Chrome 49 fixup for updateIcon 2017-04-18 12:47:03 +03:00
tophf
1649a262cd Don't double-notify own pages 2017-04-18 12:46:39 +03:00
tophf
42f7b11bac broadcast only meta for styleUpdated/styleAdded
apply/popup/manage use only meta for these two methods,
editor may need the full code but can fetch it directly,
so we send just the meta to avoid spamming lots of tabs with huge styles
2017-04-18 12:46:36 +03:00
tophf
1749057b91 Explainer for stylusUnavailableForURL message
We don't mention the G+ iframe on CWS stylable only when "Out of process iframes" feature is enabled which can be set manually via chrome://flags/#enable-site-per-process. It's still in development and is known to break some sites, which is why it's not enabled by default.
2017-04-18 12:46:35 +03:00
tophf
279149b8b8 refactor deepCopy & deepMerge 2017-04-18 12:46:34 +03:00
tophf
5c8d1950a7 Isolate storage.js in background context
To prevent cross-page leaks we need to create/copy prefs and cachedStyles inside the background page context.

* storage.js is now used only in the background page

* messaging.js now contains less bg-specific methods and more common methods. Added saveStyleSafe, deleteStyleSafe which automatically invoke onRuntimeMessage of the current page or just handleUpdate/handleDelete when notify:false

* prefs.js with 'prefs' for background and UI pages: separate objects because a UI page may load before the background page and it can read prefs from localStorage/sync/defaults
2017-04-18 12:46:34 +03:00
tophf
257fda4d1d updateIcon: use the old flow to avoid "no tab" errors 2017-04-18 12:46:33 +03:00
tophf
2bb7d31042 fixups for Opera/Vivaldi/Firefox-compatibility 2017-04-18 12:46:32 +03:00
tophf
fcb149ae21 limit broadcast area of prefChanged in notifyAllTabs 2017-04-18 12:46:31 +03:00
tophf
ee93f8a876 Set openerTabId to return to original tab on closing 2017-04-18 12:46:29 +03:00
tophf
26802e36df Optimize startup: coalesce & debounce prefs.set
Previously prefs.set broadcast many messages per each changed pref value to all open tabs, background page, popups. This lead to repeated and needless updates of various things like the toolbar icon, reapplying of styles, and whatnot. It could easily take more than 100ms on an average computer with many tabs open.

Now we debounce the broadcast & sync.set and coalesce all values in one object which is then sent just once per destination.
2017-04-18 12:46:28 +03:00
tophf
f8d13d8dec Remove code:false mode; show sloppy regexps in popup
* Now that our own pages retrieve the styles directly via getStylesSafe the only 0.001% of cases where code:false would be needed (the browser is starting up with some of the tabs showing our built-in pages like editor or manage) is not worth optimizing for.

* According to CSS4 @document specification the entire URL must match. Stylish-for-Chrome implemented it incorrectly since the very beginning. We detect styles that abuse the bug by finding the sections that would have been applied by Stylish but not by us as we follow the spec. Additionally we'll check for invalid regexps.
2017-04-18 12:46:28 +03:00
tophf
1bf23046d5 updateIcon: code cosmetics 2017-04-18 12:46:28 +03:00
tophf
db8526b50b In Vivaldi setBadgeText must follow setBadgeBackgroundColor 2017-04-18 12:46:28 +03:00
tophf
668e3a7b56 ignoreChromeError -> messaging; use it in editor's menu update 2017-04-18 12:46:27 +03:00
tophf
64c830caa9 webNavigation.onReferenceFragmentUpdated instead of tabs.onUpdated
Also send a Do-It-Yourself to our built-in pages to fetch the styles directly which is faster because IPC messaging JSON-ifies everything internally
2017-04-18 12:46:25 +03:00
tophf
d32ad30f8f webNavigation.getFrame may return null on overridden pages, fix a3401b05 2017-04-18 12:46:25 +03:00
tophf
54ab65989d Simplify configureCommands; focus an existing tab
Instead of isolating the deoptimization trigger:
https://github.com/petkaantonov/bluebird/wiki/Optimization-killers
2017-04-18 12:46:25 +03:00
tophf
1166fd9d3b openURL fix for opera:// URLs 2017-04-18 12:46:24 +03:00
tophf
a2ea1bb1d9 openURL: handle urls with # 2017-04-18 12:46:24 +03:00
tophf
ac4a420e2b ESLint: customize the rules; fix the issues 2017-04-18 12:46:23 +03:00
tophf
657db366c9 openURL: refactor to open/switch to URL 2017-04-18 12:46:23 +03:00
tophf
4936426fa3 dom.js: extract common DOM functions 2017-04-18 12:46:22 +03:00
tophf
a6c3424b53 Move images into a separate directory 2017-04-18 12:46:22 +03:00
tophf
80130797ce Refactor contextMenus and commands 2017-04-18 12:43:30 +03:00
tophf
07bee69359 Fix deoptimization triggers 2017-04-18 12:43:30 +03:00
tophf
2f4da37fdb Refactor and speed up popup & manager
Popup:
* Enforce 200-800px range for the popup width option

Manage:
* faster search via cachedStyles.byId
* faster restoration of search results on history nav
* style name is clickable and opens the editor
* animated highlight of style element on update/add/save
* expandable extra applies-to targets
* remember scroll position on normal history navigation
* boz-sizing in #header, also in editor
* applies-to targets use structured markup
* get*Tab*, enableStyle and deleteStyle are promisified
2017-04-18 12:43:29 +03:00
tophf
f4e689721a Improve style caching, cache requests too, add code:false mode
Previously, when a cache was invalidated and every tab/iframe issued a getStyles request, we previous needlessly accessed IndexedDB for each of these requests. It happened because 1) the global cachedStyles was created only at the end of the async DB-reading, 2) and each style record is retrieved asynchronously so the single threaded JS engine interleaved all these operations. It could easily span a few seconds when many tabs are open and you have like 100 styles.

Now, in getStyles: all requests issued while cachedStyles is being populated are queued and invoked at the end.

Now, in filterStyles: all requests are cached using the request's options combined in a string as a key. It also helps on each navigation because we monitor page loading process at different stages: before, when committed, history traversal, requesting applicable styles by a content script. Icon badge update also may issue a copy of the just issued request by one of the navigation listeners.

Now, the caches are invalidated smartly: style add/update/delete/toggle only purges filtering cache, and modifies style cache in-place without re-reading the entire IndexedDB.

Now, code:false mode for manage page that only needs style meta. It reduces the transferred message size 10-100 times thus reducing the overhead caused by to internal JSON-fication in the extensions API.

Also fast&direct getStylesSafe for own pages; code cosmetics
2017-04-18 12:43:28 +03:00
tophf
66a1c17847 Fix cascaded ternary condition 2017-03-19 02:00:03 +03:00
Jeremy Schomery
0e6c5e35ac Path for configureCommands is chosen based on user's browser (Opera incomatibility) 2017-03-16 17:14:35 +03:30
tophf
31a24717b4 Use chrome.tabs.query instead of 2-tier window+tabs 2017-03-16 13:32:13 +03:00
tophf
e658255c36 Reinject content scripts on install/update/enabling the extension
The injection code also runs outside of onInstalled event so we check first if a content script belonging to our execution context "generation" is already injected. This can happen on browser startup: the background page is loaded in several seconds after the normal web page tabs are loaded with our content script(s) already injected. The check itself is simply a "ping" message to each tab that should return true if the content script is alive and kicking.
2017-03-16 13:32:12 +03:00
tophf
34cd025487 Use Object.assign instead of shallowMerge 2017-03-16 13:32:12 +03:00
tophf
913df00f35 Don't notify normal tabs if style contents hasn't changed 2017-03-16 13:32:12 +03:00
tophf
38006847f7 Don't apply styles until import is finished 2017-03-16 13:32:12 +03:00