Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Draft implementation of chrome.tabs.duplicate, #7458. #359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions atom/common/api/resources/tabs_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
ipc.send('chrome-tabs-create', responseId, createProperties)
})

apiFunctions.setHandleRequest('duplicate', function (tabId, cb) {
var responseId = ipc.guid()
cb && ipc.once('chrome-tabs-duplicate-response-' + responseId, function (evt, dtab, error) {
if (error) {
lastError.run('tabs.duplicate', error, '', () => { cb(null) })
} else {
cb(dtab)
}
})
ipc.send('chrome-tabs-duplicate', responseId, tabId)
})

apiFunctions.setHandleRequest('executeScript', function (tabId, details, cb) {
var responseId = ipc.guid()
tabId = tabId || -2
Expand Down
33 changes: 33 additions & 0 deletions lib/browser/api/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ const createTab = function (createProperties, cb) {
}
}

const duplicateTab = function (tabId, cb) {
try {
let tab = getWebContentsForTab(tabId)
// XXX What to do if not there?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set error to 'chrome.tabs.duplicate could not find tabId ' + tabId - I haven't actually verified that message against Chrome, but that would be consistent with the others

tab._clone(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use clone instead of _clone. _clone is an internal method that is only meant to be used by web-contents.js

(dtab) => {
if (dtab) {
cb(dtab)
} else {
cb(null, 'An unexpected error occurred')
}
}
)
} catch (e) {
console.error(e)
cb(null, 'An unexpected error occurred: ' + e.message)
}
}

const removeTabs = function (tabIds) {
for (let tabId of tabIds) {
var tabContents = getWebContentsForTab(tabId)
Expand Down Expand Up @@ -475,6 +494,20 @@ ipcMain.on('chrome-tabs-create', function (evt, responseId, createProperties) {
}
})

ipcMain.on('chrome-tabs-duplicate', function (evt, responseId, tabId) {
const cb = (dtab, error) => {
if (!evt.sender.isDestroyed()) {
let dtabValue = error ? null : dtab.tabValue()
evt.sender.send('chrome-tabs-duplicate-response-' + responseId, dtabValue, error)
}
}
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need both try/catch blocks (duplicateTab and this one)?

duplicateTab(tabId, cb)
} catch (e) {
cb(null, e.message)
}
})

ipcMain.on('chrome-tabs-remove', function (evt, responseId, tabIds) {
let senderTabId = evt.sender.getId()
tabIds = Array.isArray(tabIds) ? tabIds : [tabIds]
Expand Down