Skip to content

Commit

Permalink
Merge pull request #137 from duckduckgo/shane/docs
Browse files Browse the repository at this point in the history
working on docs
  • Loading branch information
shakyShane committed Nov 30, 2023
2 parents 59dedf0 + 3d3ef9a commit 3f587e7
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 24 deletions.
59 changes: 47 additions & 12 deletions build/app/public/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10682,6 +10682,9 @@
}
};
BurnMessage = class extends Msg {
/**
* @param {import('../../../schema/__generated__/schema.types').FireOption} opts
*/
constructor(opts) {
super();
Object.assign(this, opts);
Expand All @@ -10690,6 +10693,9 @@
FetchBurnOptions = class extends Msg {
};
SetBurnDefaultOption = class extends Msg {
/**
* @param {import('../../../schema/__generated__/schema.types').FireOption['name']} name
*/
constructor(name) {
super();
this.defaultOption = name;
Expand Down Expand Up @@ -11021,10 +11027,12 @@
doBurn: () => doBurn,
fetch: () => fetch,
getBackgroundTabData: () => getBackgroundTabData,
getBurnOptions: () => getBurnOptions,
getPrivacyDashboardData: () => getPrivacyDashboardData,
openOptions: () => openOptions,
refreshAlias: () => refreshAlias,
search: () => search,
setBurnDefaultOption: () => setBurnDefaultOption,
setLists: () => setLists,
setup: () => setup,
submitBrokenSiteReport: () => submitBrokenSiteReport
Expand Down Expand Up @@ -11055,10 +11063,10 @@
return doBurn(message);
}
if (message instanceof FetchBurnOptions) {
return toExtensionMessage("getBurnOptions");
return getBurnOptions();
}
if (message instanceof SetBurnDefaultOption) {
return toExtensionMessage("setBurnDefaultOption", message);
return setBurnDefaultOption(message);
}
return new Promise((resolve) => {
window.chrome.runtime.sendMessage(message, (result) => {
Expand Down Expand Up @@ -11098,6 +11106,12 @@
async function openOptions() {
return toExtensionMessage("openOptions");
}
function getBurnOptions() {
return toExtensionMessage("getBurnOptions");
}
function setBurnDefaultOption(message) {
return toExtensionMessage("setBurnDefaultOption", message);
}
async function doBurn(message) {
const browsingDataPermissions = {
permissions: ["browsingData"]
Expand Down Expand Up @@ -12255,6 +12269,8 @@
onChangeRequestData: () => onChangeRequestData,
privacyDashboardOpenSettings: () => privacyDashboardOpenSettings,
privacyDashboardOpenUrlInNewTab: () => privacyDashboardOpenUrlInNewTab,
privacyDashboardSetPermission: () => privacyDashboardSetPermission,
privacyDashboardSetProtection: () => privacyDashboardSetProtection,
privacyDashboardSetSize: () => privacyDashboardSetSize,
privacyDashboardSubmitBrokenSiteReport: () => privacyDashboardSubmitBrokenSiteReport,
setup: () => setup2,
Expand Down Expand Up @@ -12302,6 +12318,17 @@
Object.assign(cookiePromptManagementStatus, parsed.data);
channel2?.send("updateTabData");
}
function privacyDashboardSetProtection(params) {
invariant(
window.webkit?.messageHandlers?.privacyDashboardSetProtection,
"webkit.messageHandlers.privacyDashboardSetProtection required"
);
window.webkit.messageHandlers.privacyDashboardSetProtection.postMessage(params);
}
function privacyDashboardSetPermission(params) {
invariant(window.webkit?.messageHandlers, "webkit.messageHandlers required");
window.webkit.messageHandlers.privacyDashboardSetPermission.postMessage(params);
}
async function fetch2(message) {
if (message instanceof SubmitBrokenSiteReportMessage) {
privacyDashboardSubmitBrokenSiteReport({
Expand All @@ -12319,12 +12346,9 @@
continue;
}
const isProtected = value === false;
invariant(window.webkit?.messageHandlers?.privacyDashboardSetProtection, "webkit.messageHandlers required");
window.webkit.messageHandlers.privacyDashboardSetProtection.postMessage({
isProtected,
eventOrigin: message.eventOrigin
});
privacyDashboardSetProtection({ eventOrigin: message.eventOrigin, isProtected });
}
return;
}
if (message instanceof OpenSettingsMessages) {
privacyDashboardOpenSettings({
Expand All @@ -12333,8 +12357,7 @@
return;
}
if (message instanceof UpdatePermissionMessage) {
invariant(window.webkit?.messageHandlers, "webkit.messageHandlers required");
window.webkit.messageHandlers.privacyDashboardSetPermission.postMessage({
privacyDashboardSetPermission({
permission: message.id,
value: message.value
});
Expand Down Expand Up @@ -12778,8 +12801,11 @@
// shared/js/browser/windows-communication.js
var windows_communication_exports = {};
__export(windows_communication_exports, {
AddToAllowListCommand: () => AddToAllowListCommand,
OpenInNewTab: () => OpenInNewTab,
OpenSettings: () => OpenSettings,
RemoveFromAllowListCommand: () => RemoveFromAllowListCommand,
SetPermissionCommand: () => SetPermissionCommand,
SetSize: () => SetSize,
SubmitBrokenSiteReport: () => SubmitBrokenSiteReport,
backgroundMessage: () => backgroundMessage4,
Expand Down Expand Up @@ -12834,14 +12860,14 @@
const isProtected = value === false;
const eventOrigin = message.eventOrigin;
if (isProtected) {
windowsPostMessage("RemoveFromAllowListCommand", { eventOrigin });
RemoveFromAllowListCommand(eventOrigin);
} else {
windowsPostMessage("AddToAllowListCommand", { eventOrigin });
AddToAllowListCommand(eventOrigin);
}
}
}
if (message instanceof UpdatePermissionMessage) {
windowsPostMessage("SetPermissionCommand", {
SetPermissionCommand({
permission: message.id,
value: message.value
});
Expand All @@ -12864,6 +12890,15 @@
function OpenSettings(args) {
windowsPostMessage("OpenSettings", args);
}
function SetPermissionCommand(args) {
windowsPostMessage("SetPermissionCommand", args);
}
function RemoveFromAllowListCommand(eventOrigin) {
windowsPostMessage("RemoveFromAllowListCommand", { eventOrigin });
}
function AddToAllowListCommand(eventOrigin) {
windowsPostMessage("AddToAllowListCommand", { eventOrigin });
}
function handleIncomingMessage(message) {
const parsed = eventShape.safeParse(message);
if (!parsed.success) {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/ios.spec-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ if (!process.env.CI) {
{ name: 'upgraded+secure', state: testDataStates['upgraded+secure'] },
{ name: 'google-off', state: testDataStates['google-off'] },
{ name: 'cnn', state: testDataStates.cnn },
{ name: 'allowlisted', state: testDataStates.allowlisted },
]
for (const { name, state } of states) {
test(name, async ({ page }) => {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions shared/js/browser/browser-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export async function fetch(message) {
return doBurn(message)
}
if (message instanceof FetchBurnOptions) {
return toExtensionMessage('getBurnOptions')
return getBurnOptions()
}
if (message instanceof SetBurnDefaultOption) {
return toExtensionMessage('setBurnDefaultOption', message)
return setBurnDefaultOption(message)
}
return new Promise((resolve) => {
// console.log('🚀 [OUTGOING]', JSON.stringify(message, null, 2))
Expand Down Expand Up @@ -198,6 +198,48 @@ export async function openOptions() {
return toExtensionMessage('openOptions')
}

/**
* @category Dashboard -> Extension Messages
* @return {Promise<import('../../../schema/__generated__/schema.types').FireButtonData>}
* @example
* ```javascript
* window.chrome.runtime.sendMessage({
* messageType: 'getBurnOptions',
* options: {}
* })
* ```
*/
export function getBurnOptions() {
return toExtensionMessage('getBurnOptions')
}

/**
* @category Dashboard -> Extension Messages
* @param {SetBurnDefaultOption} message
* @example
* ```javascript
* window.chrome.runtime.sendMessage({
* messageType: 'setBurnDefaultOption',
* options: {
* defaultOption: "CurrentSite"
* }
* })
* ```
*/
export function setBurnDefaultOption(message) {
return toExtensionMessage('setBurnDefaultOption', message)
}

/**
* @param {BurnMessage} message
* @category Dashboard -> Extension Messages
* @example
* ```javascript
* window.chrome.runtime.sendMessage({
* messageType: 'doBurn'
* })
* ```
*/
export async function doBurn(message) {
const browsingDataPermissions = {
permissions: ['browsingData'],
Expand Down
13 changes: 13 additions & 0 deletions shared/js/browser/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ export async function refreshAlias() {
*/
export function search(options) {}

/**
* This message will be sent when the permissions dropdown is used
*
* @param {{permission: string; value: string}} params
*/
export function setPermission(params) {}

class Msg {
toJSON() {
return {
Expand Down Expand Up @@ -341,6 +348,9 @@ export class OpenSettingsMessages extends Msg {
}

export class BurnMessage extends Msg {
/**
* @param {import('../../../schema/__generated__/schema.types').FireOption} opts
*/
constructor(opts) {
super()
Object.assign(this, opts)
Expand All @@ -350,6 +360,9 @@ export class BurnMessage extends Msg {
export class FetchBurnOptions extends Msg {}

export class SetBurnDefaultOption extends Msg {
/**
* @param {import('../../../schema/__generated__/schema.types').FireOption['name']} name
*/
constructor(name) {
super()
this.defaultOption = name
Expand Down
56 changes: 49 additions & 7 deletions shared/js/browser/macos-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,52 @@ export function onChangeConsentManaged(payload) {

// -----------------------------------------------------------------------------

/**
* This message will be sent when the toggle is pressed on, or off via:
* - The primary screen
* - The breakage form
*
* @param {import('../../../schema/__generated__/schema.types').SetProtectionParams} params
* @category Webkit Message Handlers
* @example
*
* This message handler is the equivalent of calling the following JavaScript.
*
* ```js
* window.webkit.messageHandlers.privacyDashboardSetProtection.postMessage({
* isProtected: true,
* eventOrigin: { screen: "primaryScreen" }
* })
* ```
*/
export function privacyDashboardSetProtection(params) {
invariant(
window.webkit?.messageHandlers?.privacyDashboardSetProtection,
'webkit.messageHandlers.privacyDashboardSetProtection required'
)
window.webkit.messageHandlers.privacyDashboardSetProtection.postMessage(params)
}

/**
* {@inheritDoc common.setPermission}
* @type {import("./common.js").setPermission}
* @category Webkit Message Handlers
* @example
*
* This message handler is the equivalent of calling the following JavaScript.
*
* ```js
* window.webkit.messageHandlers.privacyDashboardSetPermission.postMessage({
* permission: "camera",
* value: "grant"
* })
* ```
*/
export function privacyDashboardSetPermission(params) {
invariant(window.webkit?.messageHandlers, 'webkit.messageHandlers required')
window.webkit.messageHandlers.privacyDashboardSetPermission.postMessage(params)
}

/**
* @category Internal API
* @type {import("./common.js").fetcher}
Expand All @@ -211,12 +257,9 @@ async function fetch(message) {
// `allowlisted: true` means the user disabled protections.
// so `isProtected` is the opposite of `allowlisted`.
const isProtected = value === false
invariant(window.webkit?.messageHandlers?.privacyDashboardSetProtection, 'webkit.messageHandlers required')
window.webkit.messageHandlers.privacyDashboardSetProtection.postMessage({
isProtected,
eventOrigin: message.eventOrigin,
})
privacyDashboardSetProtection({ eventOrigin: message.eventOrigin, isProtected })
}
return
}
if (message instanceof OpenSettingsMessages) {
privacyDashboardOpenSettings({
Expand All @@ -226,8 +269,7 @@ async function fetch(message) {
}

if (message instanceof UpdatePermissionMessage) {
invariant(window.webkit?.messageHandlers, 'webkit.messageHandlers required')
window.webkit.messageHandlers.privacyDashboardSetPermission.postMessage({
privacyDashboardSetPermission({
permission: message.id,
value: message.value,
})
Expand Down

0 comments on commit 3f587e7

Please sign in to comment.