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
This commit is contained in:
parent
ce2492c305
commit
42f7b11bac
18
edit.js
18
edit.js
|
@ -12,6 +12,9 @@ var useHistoryBack; // use browser history back when "back to manage" is click
|
||||||
var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain", regexps: "regexp"};
|
var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain", regexps: "regexp"};
|
||||||
var CssToProperty = {"url": "urls", "url-prefix": "urlPrefixes", "domain": "domains", "regexp": "regexps"};
|
var CssToProperty = {"url": "urls", "url-prefix": "urlPrefixes", "domain": "domains", "regexp": "regexps"};
|
||||||
|
|
||||||
|
// if background page hasn't been loaded yet, increase the chances it has before DOMContentLoaded
|
||||||
|
onBackgroundReady();
|
||||||
|
|
||||||
// make querySelectorAll enumeration code readable
|
// make querySelectorAll enumeration code readable
|
||||||
["forEach", "some", "indexOf", "map"].forEach(function(method) {
|
["forEach", "some", "indexOf", "map"].forEach(function(method) {
|
||||||
NodeList.prototype[method]= Array.prototype[method];
|
NodeList.prototype[method]= Array.prototype[method];
|
||||||
|
@ -246,9 +249,8 @@ function initCodeMirror() {
|
||||||
return options.map(function(opt) { return "<option>" + opt + "</option>"; }).join("");
|
return options.map(function(opt) { return "<option>" + opt + "</option>"; }).join("");
|
||||||
}
|
}
|
||||||
var themeControl = document.getElementById("editor.theme");
|
var themeControl = document.getElementById("editor.theme");
|
||||||
var bg = chrome.extension.getBackgroundPage();
|
if (BG && BG.codeMirrorThemes) {
|
||||||
if (bg && bg.codeMirrorThemes) {
|
themeControl.innerHTML = optionsHtmlFromArray(BG.codeMirrorThemes);
|
||||||
themeControl.innerHTML = optionsHtmlFromArray(bg.codeMirrorThemes);
|
|
||||||
} else {
|
} else {
|
||||||
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
|
// Chrome is starting up and shows our edit.html, but the background page isn't loaded yet
|
||||||
themeControl.innerHTML = optionsHtmlFromArray([theme == "default" ? t("defaultTheme") : theme]);
|
themeControl.innerHTML = optionsHtmlFromArray([theme == "default" ? t("defaultTheme") : theme]);
|
||||||
|
@ -1822,7 +1824,15 @@ function onRuntimeMessage(request) {
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case "styleUpdated":
|
case "styleUpdated":
|
||||||
if (styleId && styleId == request.style.id && request.reason != 'editSave') {
|
if (styleId && styleId == request.style.id && request.reason != 'editSave') {
|
||||||
initWithStyle(request);
|
if ((request.style.sections[0] || {}).code === null) {
|
||||||
|
// the code-less style came from notifyAllTabs
|
||||||
|
onBackgroundReady().then(() => {
|
||||||
|
request.style = BG.cachedStyles.byId.get(request.style.id);
|
||||||
|
initWithStyle(request);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initWithStyle(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "styleDeleted":
|
case "styleDeleted":
|
||||||
|
|
11
messaging.js
11
messaging.js
|
@ -32,19 +32,22 @@ if (!BG || BG != window) {
|
||||||
|
|
||||||
function notifyAllTabs(msg) {
|
function notifyAllTabs(msg) {
|
||||||
const originalMessage = msg;
|
const originalMessage = msg;
|
||||||
if (msg.codeIsUpdated === false && msg.style) {
|
if (msg.method == 'styleUpdated' || msg.method == '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
|
||||||
msg = Object.assign({}, msg, {
|
msg = Object.assign({}, msg, {
|
||||||
style: getStyleWithNoCode(msg.style)
|
style: getStyleWithNoCode(msg.style)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const affectsAll = !msg.affects || msg.affects.all;
|
const affectsAll = !msg.affects || msg.affects.all;
|
||||||
const affectsOwnOrigin = !affectsAll && (msg.affects.editor || msg.affects.manager);
|
const affectsOwnOriginOnly = !affectsAll && (msg.affects.editor || msg.affects.manager);
|
||||||
const affectsTabs = affectsAll || affectsOwnOrigin;
|
const affectsTabs = affectsAll || affectsOwnOriginOnly;
|
||||||
const affectsIcon = affectsAll || msg.affects.icon;
|
const affectsIcon = affectsAll || msg.affects.icon;
|
||||||
const affectsPopup = affectsAll || msg.affects.popup;
|
const affectsPopup = affectsAll || msg.affects.popup;
|
||||||
if (affectsTabs || affectsIcon) {
|
if (affectsTabs || affectsIcon) {
|
||||||
// list all tabs including chrome-extension:// which can be ours
|
// list all tabs including chrome-extension:// which can be ours
|
||||||
chrome.tabs.query(affectsOwnOrigin ? {url: URLS.ownOrigin + '*'} : {}, tabs => {
|
chrome.tabs.query(affectsOwnOriginOnly ? {url: URLS.ownOrigin + '*'} : {}, tabs => {
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
if (affectsTabs || URLS.optionsUI.includes(tab.url)) {
|
if (affectsTabs || URLS.optionsUI.includes(tab.url)) {
|
||||||
chrome.tabs.sendMessage(tab.id, msg);
|
chrome.tabs.sendMessage(tab.id, msg);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user