Safari: fix vAPI.tabs.close() + cleanup

This commit is contained in:
Deathamns 2014-12-01 16:23:19 +01:00
parent 98464a56fe
commit c0e11d8182
10 changed files with 164 additions and 145 deletions

View File

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Author</key>
<string>Raymond Hill</string>
<key>Builder Version</key>
<string>534.57.2</string>
<key>CFBundleDisplayName</key>
<string>µBlock</string>
<key>CFBundleIdentifier</key>
<string>net.gorhill.uBlock</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>0.7.0.10</string>
<key>CFBundleVersion</key>
<string>1456132</string>
<key>Chrome</key>
<dict>
<key>Database Quota</key>
<real>52428800</real>
<key>Global Page</key>
<string>background.html</string>
<key>Popovers</key>
<array>
<dict>
<key>Filename</key>
<string>popup.html</string>
<key>Height</key>
<real>310</real>
<key>Identifier</key>
<string>popover</string>
<key>Width</key>
<real>180</real>
</dict>
</array>
<key>Toolbar Items</key>
<array>
<dict>
<key>Identifier</key>
<string>toolbarItem</string>
<key>Image</key>
<string>img/icon16.png</string>
<key>Label</key>
<string>µBlock</string>
<key>Popover</key>
<string>popover</string>
</dict>
</array>
</dict>
<key>Content</key>
<dict>
<key>Scripts</key>
<dict>
<key>End</key>
<array>
<string>js/contentscript-end.js</string>
</array>
<key>Start</key>
<array>
<string>js/vapi-client.js</string>
<string>js/contentscript-start.js</string>
</array>
</dict>
<key>Whitelist</key>
<array>
<string>http://*/*</string>
<string>https://*/*</string>
</array>
</dict>
<key>Description</key>
<string>Finally, an efficient blocker. Easy on CPU and memory.</string>
<key>ExtensionInfoDictionaryVersion</key>
<string>1.0</string>
<key>Permissions</key>
<dict>
<key>Website Access</key>
<dict>
<key>Include Secure Pages</key>
<true/>
<key>Level</key>
<string>All</string>
</dict>
</dict>
<!-- <key>Update Manifest URL</key>
<string>https://github.com/gorhill/uBlockupdate_safariextz.plist</string> -->
<key>Website</key>
<string>https://github.com/gorhill/uBlock</string>
</dict>
</plist>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>DefaultValue</key>
<false/>
<key>FalseValue</key>
<false/>
<key>Key</key>
<string>open_prefs</string>
<key>Secure</key>
<false/>
<key>Title</key>
<string>Click to see the Preferences</string>
<key>TrueValue</key>
<true/>
<key>Type</key>
<string>CheckBox</string>
</dict>
</array>
</plist>

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Author</key>
<string>Raymond Hill</string>
<key>Builder Version</key>
<string>534.57.2</string>
<key>CFBundleDisplayName</key>
<string>µBlock</string>
<key>CFBundleIdentifier</key>
<string>net.gorhill.uBlock</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>0.7.0.11</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>Chrome</key>
<dict>
<key>Database Quota</key>
<real>52428800</real>
<key>Global Page</key>
<string>background.html</string>
<key>Popovers</key>
<array>
<dict>
<key>Filename</key>
<string>popup.html</string>
<key>Height</key>
<real>310</real>
<key>Identifier</key>
<string>popover</string>
<key>Width</key>
<real>180</real>
</dict>
</array>
<key>Toolbar Items</key>
<array>
<dict>
<key>Identifier</key>
<string>toolbarItem</string>
<key>Image</key>
<string>img/icon16.png</string>
<key>Label</key>
<string>µBlock</string>
<key>Popover</key>
<string>popover</string>
</dict>
</array>
</dict>
<key>Content</key>
<dict>
<key>Scripts</key>
<dict>
<key>End</key>
<array>
<string>js/contentscript-end.js</string>
</array>
<key>Start</key>
<array>
<string>js/vapi-client.js</string>
<string>js/contentscript-start.js</string>
</array>
</dict>
<key>Whitelist</key>
<array>
<string>http://*/*</string>
<string>https://*/*</string>
</array>
</dict>
<key>Description</key>
<string>Finally, an efficient blocker. Easy on CPU and memory.</string>
<key>ExtensionInfoDictionaryVersion</key>
<string>1.0</string>
<key>Permissions</key>
<dict>
<key>Website Access</key>
<dict>
<key>Include Secure Pages</key>
<true/>
<key>Level</key>
<string>All</string>
</dict>
</dict>
<!-- <key>Update Manifest URL</key>
<string>https://github.com/gorhill/uBlockupdate_safariextz.plist</string> -->
<key>Website</key>
<string>https://github.com/gorhill/uBlock</string>
</dict>
</plist>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>DefaultValue</key>
<false/>
<key>FalseValue</key>
<false/>
<key>Key</key>
<string>open_prefs</string>
<key>Secure</key>
<false/>
<key>Title</key>
<string>Click to see the Preferences</string>
<key>TrueValue</key>
<true/>
<key>Type</key>
<string>CheckBox</string>
</dict>
</array>
</plist>

View File

@ -10,9 +10,9 @@
<key>Developer Identifier</key>
<string></string>
<key>CFBundleShortVersionString</key>
<string>0.7.0.10</string>
<string>0.7.0.11</string>
<key>CFBundleVersion</key>
<string>1456132</string>
<string>1</string>
<key>URL</key>
<string>https://.../uBlock.safariextz</string>
</dict>

View File

@ -132,6 +132,10 @@ vAPI.storage = {
callback();
},
getBytesInUse: function(keys, callback) {
if (typeof callback !== 'function') {
return;
}
var key, size = 0;
if (keys === null) {
@ -230,15 +234,16 @@ vAPI.tabs.get = function(tabId, callback) {
title: tab.title
});
};
// properties of the details object:
// url: 'URL', // the address that will be opened
// tabId: 1, // the tab is used if set, instead of creating a new one
// index: -1, // undefined: end of the list, -1: following tab, or after index
// active: false, // opens the tab in background - true and undefined: foreground
// select: true // if a tab is already opened with that url, then select it instead of opening a new one
/******************************************************************************/
// properties of the details object:
// url: 'URL', // the address that will be opened
// tabId: 1, // the tab is used if set, instead of creating a new one
// index: -1, // undefined: end of the list, -1: following tab, or after index
// active: false, // opens the tab in background - true and undefined: foreground
// select: true // if a tab is already opened with that url, then select it instead of opening a new one
vAPI.tabs.open = function(details) {
if (!details.url) {
return null;
@ -293,13 +298,19 @@ vAPI.tabs.open = function(details) {
/******************************************************************************/
vAPI.tabs.close = function(tab) {
if (!(tab instanceof SafariBrowserTab)) {
tab = this.stack[tab];
vAPI.tabs.close = function(tabIds) {
if (tabIds instanceof SafariBrowserTab) {
tabIds = this.getTabId(tabIds);
}
if (tab) {
tab.close();
if (!Array.isArray(tabIds)) {
tabIds = [tabIds];
}
for (var i = 0; i < tabIds.length; i++) {
if (this.stack[tabIds[i]]) {
this.stack[tabIds[i]].close();
}
}
};
@ -638,7 +649,11 @@ vAPI.net.registerListeners = function() {
return e.message;
};
safari.application.addEventListener('message', this.onBeforeRequest.callback, true);
safari.application.addEventListener(
'message',
this.onBeforeRequest.callback,
true
);
}
};

View File

@ -30,7 +30,7 @@
/******************************************************************************/
self.vAPI = self.vAPI || {};
self.vAPI.safari = true;
vAPI.safari = true;
/******************************************************************************/
@ -39,11 +39,15 @@ var messagingConnector = function(response) {
return;
}
var channels = vAPI.messaging.channels;
var channel, listener;
if ( response.broadcast === true ) {
for ( channel in vAPI.messaging.channels ) {
listener = vAPI.messaging.channels[channel].listener;
for ( channel in channels ) {
if ( channels.hasOwnProperty(channel) === false ) {
continue;
}
listener = channels[channel].listener;
if ( typeof listener === 'function' ) {
listener(response.msg);
}
@ -58,7 +62,7 @@ var messagingConnector = function(response) {
}
if ( !listener ) {
channel = vAPI.messaging.channels[response.portName];
channel = channels[response.portName];
listener = channel && channel.listener;
}
@ -171,9 +175,16 @@ vAPI.messaging = {
/******************************************************************************/
// content scripts are loaded into extension pages by default, but they shouldn't
vAPI.canExecuteContentScript = function() {
return /^https?:/.test(location.protocol);
};
if (location.protocol === "safari-extension:") {
/******************************************************************************/
// This file can be included into extensin pages,
// but the following code should run only in content pages.
if (location.protocol === 'safari-extension:') {
return;
}
@ -358,7 +369,7 @@ var onContextMenu = function(e) {
details.editable = details.tagName === 'textarea' || details.tagName === 'input';
if ('checked' in e.target) {
if (e.target.hasOwnProperty('checked')) {
details.checked = e.target.checked;
}
@ -366,7 +377,7 @@ var onContextMenu = function(e) {
details.linkUrl = e.target.href;
}
if ('src' in e.target) {
if (e.target.hasOwnProperty('src')) {
details.srcUrl = e.target.src;
if (details.tagName === 'img') {
@ -394,12 +405,6 @@ if (frameId === 0) {
/******************************************************************************/
self.vAPI.canExecuteContentScript = function() {
return /^https?:/.test(location.protocol);
};
/******************************************************************************/
})();
/******************************************************************************/

View File

@ -55,7 +55,6 @@ vAPI.download = function(details) {
a.dispatchEvent(new MouseEvent('click'));
return;
}
var messager = vAPI.messaging.channel('_download');
messager.send({
what: 'gotoURL',

View File

@ -16,7 +16,7 @@ cp -R src/_locales $DES/
cp src/*.html $DES/
cp src/img/icon_128.png $DES/Icon.png
cp platform/vapi-appinfo.js $DES/js/
cp meta/safariextz/*.js $DES/js/
cp meta/safariextz/Info.plist $DES/
cp meta/safariextz/Settings.plist $DES/
cp platform/safariextz/*.js $DES/js/
cp platform/safariextz/Info.plist $DES/
cp platform/safariextz/Settings.plist $DES/
echo "*** uBlock.safariextension: Package done."