This repository has been archived by the owner on Dec 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define Chrome's tabs.Tab type for onClicked event
- Loading branch information
Showing
7 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* (c) 2013 Rob Wu <[email protected]> | ||
* Conversion between Chrome tabs.Tab type and Firefox's addon SDK's Tab type | ||
* Distributed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
const tabs = require('sdk/tabs'); | ||
const { isPrivate } = require('sdk/private-browsing'); | ||
|
||
// Convert SDK's tab type to Chrome's | ||
function sdkTabToChrome(sdkTab) { | ||
return { | ||
id: sdkTab.id, | ||
index: sdkTab.index, | ||
// windowId: | ||
// openerTabId: | ||
highlighted: false, | ||
active: sdkTab.window.tabs.activeTab === sdkTab, | ||
pinned: sdkTab.isPinned, | ||
url: sdkTab.url, | ||
title: sdkTab.title, | ||
faviconUrl: sdkTab.favicon, | ||
// status: | ||
incognito: isPrivate(sdkTab) | ||
}; | ||
} | ||
|
||
// Get the SDK's tab for a given Chrome tab. | ||
function chromeTabToSdk(chromeTab) { | ||
var chromeTabId = chromeTab.id; | ||
for each (var sdkTab in tabs) { | ||
if (sdkTab.id === chromeTabId) { | ||
return sdkTab; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
exports.toChromeTab = sdkTabToChrome; | ||
exports.toFirefoxTab = chromeTabToSdk; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
"name": "browser-action", | ||
"description": "Create a browser action badge using the chrome.browserAction API syntax.", | ||
"keywords": ["browser-action", "badge", "toolbarwidget", "widget", "ui"], | ||
"author": "Rob Wu (https://rob.lekensteyn.nl/) <[email protected]>", | ||
"author": "Rob Wu (https://robwu.nl/) <[email protected]>", | ||
"dependencies": ["toolbarwidget"], | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
const tabs = require('sdk/tabs'); | ||
const chromeTabs = require('chrome-tabs-api'); | ||
|
||
exports['test '] = function(assert, done) { | ||
var url = 'data:text/html,' + encodeURIComponent('<title>Test</title>'); | ||
tabs.open({ | ||
url: url, | ||
onReady: function(tab) { | ||
assert.ok(tab, 'SDK Tab exists'); // Pre-requisite | ||
testSdkTab(tab); | ||
testSdkTab = function() {}; // Run once | ||
} | ||
}); | ||
function testSdkTab(tab) { | ||
var chromeTab = chromeTabs.toChromeTab(tab); | ||
assert.equal(tab.url, chromeTab.url, 'Tab\'s "url" property must be equal'); | ||
assert.equal(false, chromeTab.pinned, 'Tab\'s "pinned" property must be false'); | ||
var ffTab = chromeTabs.toFirefoxTab(chromeTab); | ||
assert.equal(tab, ffTab, 'toFirefoxTab(toChromeTab(tab)) === tab'); | ||
done(); | ||
} | ||
}; | ||
|
||
require('sdk/test').run(exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters