Skip to content

Commit

Permalink
[FB] Private Componets | Remove private components & Apply MPL2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surapunoyousei committed Jun 17, 2024
1 parent 2a5754a commit 8ae8ee6
Show file tree
Hide file tree
Showing 29 changed files with 4,095 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "browser/locales/l10n-central"]
path = browser/locales/l10n-central
url = https://github.com/Floorp-Projects/Unified-l10n-central
[submodule "Floorp-private-components"]
path = Floorp-private-components
url = https://github.com/floorp-Projects/Floorp-private-components
1 change: 0 additions & 1 deletion Floorp-private-components
Submodule Floorp-private-components deleted from a50942
89 changes: 89 additions & 0 deletions browser/base/content/browser-UI-customizing-menu.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable no-undef */
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */

// This script adds a button & menu to customize toolbar mode.
// Remove addons button from toolbar toggle button.

export const gFloorpCustomizeMode = {
initialized: false,

init() {
if (this.initialized) {
return;
}

let elem = window.MozXULElement.parseXULToFragment(`
<checkbox id="customization-visibility-unified-extensions-button-checkbox" class="customizationmode-checkbox"
oncommand="gFloorpCustomizeMode.toggleUnifiedExtensionsButton(!this.checked)" data-l10n-id="floorp-customize-mode-unified-extensions-button"
/>`);
let enabled = !Services.prefs.getBoolPref(
"floorp.hide.unifiedExtensionsButtton",
false
);
gFloorpCustomizeMode.addElemToCustomizeModeArea(
elem,
enabled,
"customization-titlebar-visibility-checkbox",
"after",
0
);

this.initialized = true;
},
addElemToCustomizeModeArea(elem, enabled, targetId, type, retry) {
if (retry > 3) {
throw new Error(
`Retry count is over. targetId: ${targetId}, type: ${type}`
);
}

if (enabled) {
// If enabled == false, this code is not needed. On XUL needless attribute sould be removed.
elem.firstChild.setAttribute("checked", "true");
}

// This code is maybe failed if user doesn"t open customize mode. So we need to retry.
try {
let button = document.getElementById(targetId);
if (!button) {
throw new Error(
`targetElem is not found. targetId: ${targetId}, type: ${type}`
);
}
switch (type) {
case "before":
button.before(elem);
break;
case "after":
button.after(elem);
break;
default:
button.after(elem);
break;
}
} catch (e) {
let customizationContainer = document.getElementById("nav-bar");
let observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.target.getAttribute("customizing") == "true") {
gFloorpCustomizeMode.addElemToCustomizeModeArea(
elem,
enabled,
targetId,
type,
retry + 1
);
observer.disconnect();
}
});
});

let config = { attributes: true };
observer.observe(customizationContainer, config);
}
},

toggleUnifiedExtensionsButton(enabled) {
Services.prefs.setBoolPref("floorp.hide.unifiedExtensionsButtton", enabled);
},
};
49 changes: 49 additions & 0 deletions browser/base/content/browser-bms-window.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

/* Toolbars***************************************************************/

toolbar {
display: none !important;
}

#titlebar {
display: none !important;
}

/* Toolbar buttons *****************************************************/

#fxa-toolbar-menu-button {
display: none !important;
}

/* Back, Forward, Stop, Reload buttons should be shown *********************************/

#back-button {
display: inherit;
}

#forward-button {
display: inherit;
}

#stop-reload-button {
display: inherit;
}

/* Context menu ********************************************************/

#context-take-screenshot {
display: none !important;
}

#context-viewsource {
display: none !important;
}

#context-sep-screenshots {
display: none !important;
}

/* others *************************************************************/
#statuspanel {
display: none !important;
}
133 changes: 133 additions & 0 deletions browser/base/content/browser-bms-window.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */

import { BrowserManagerSidebarPanelWindowUtils } from "./modules/bms/BrowserManagerSidebarPanelWindowUtils.mjs";

export var gBmsWindow = {
_initialized: false,
currentURL: new URL(window.location.href),

get mainWindow() {
return document.getElementById("main-window");
},

get loadURL() {
return this.webapnelData.url;
},

get webpanelId() {
return this.currentURL.searchParams.get("floorpWebPanelId");
},

get userContextId() {
return this.webapnelData.usercontext ? this.webapnelData.usercontext : 0;
},

get userAgent() {
return this.webapnelData?.userAgent ? this.webapnelData.userAgent : false;
},

get webapnelData() {
let id = this.webpanelId;
let data = BrowserManagerSidebarPanelWindowUtils.BROWSER_SIDEBAR_DATA.data;
return data[id];
},

get isBmsWindow() {
return !!this.currentURL.searchParams.get("floorpWebPanelId");
},

init() {
if (this._initialized) {
return;
}

let webPanelId = new URL(window.location.href).searchParams.get(
"floorpWebPanelId"
);
if (!webPanelId) {
return;
}

// Against session restore issue
window.floorpWebPanelWindow = true;
window.SessionStore.promiseInitialized.then(() => {
this.createWebpanelWindow();
});

// finish initialization
this._initialized = true;
},

createWebpanelWindow() {
let webPanelId = this.currentURL.searchParams.get("floorpWebPanelId");
let userContextId = this.userContextId;
let userAgent = this.userAgent;
let loadURL = this.loadURL;

this.mainWindow.setAttribute("BSM-window", "true");
this.mainWindow.setAttribute("BMS-usercontextid", userContextId);
this.mainWindow.setAttribute("BMS-useragent", userAgent);
this.mainWindow.setAttribute("BMS-webpanelid", webPanelId);
window.bmsLoadedURI = loadURL;

// Remove "navigator:browser" from window-main attribute
this.mainWindow.setAttribute("windowtype", "navigator:webpanel");

// Tab modifications
window.gBrowser.loadURI(Services.io.newURI(loadURL), {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});

// Atribute modifications
window.gBrowser.selectedTab.setAttribute("BMS-webpanel-tab", "true");

// userContextId
if (userContextId != 0) {
window.setTimeout(() => {
BrowserManagerSidebarPanelWindowUtils.reopenInSelectContainer(
window,
webPanelId,
userContextId,
false
);
}, 0);
}

// Resolve the issue that open url by anoter application and that is not loaded on main window.
window.setTimeout(() => {
let tab = window.gBrowser.addTrustedTab("about:blank");
window.gBrowser.removeTab(tab);
}, 0);

// Windows moficiations
this.mainWindow.setAttribute(
"chromehidden",
"toolbar",
"menubar directories extrachrome chrome,location=yes,centerscreen,dialog=no,resizable=yes,scrollbars=yes"
);

const BMSSyleElement = document.createElement("style");
BMSSyleElement.textContent = `
@import url("chrome://floorp/content/browser-bms-window.css");
`;
document.head.appendChild(BMSSyleElement);

let setZoomLebelInterval = window.setInterval(() => {
if (window.closed) {
window.clearInterval(setZoomLebelInterval);
return;
}

this.setZoomLevel();
}, 100);
},

setZoomLevel() {
let zoomLevel = gBmsWindow.webapnelData.zoomLevel;
if (zoomLevel) {
window.ZoomManager.zoom = zoomLevel;
}
},
};

gBmsWindow.init();
Loading

0 comments on commit 8ae8ee6

Please sign in to comment.