API Reference

KERNEL.* APIs

Methods:

 KERNEL.currentID()

Returns unique application id.

Returns: String Unique application ID

 

KERNEL.currentVersion()

Returns current extension version.

Returns: String Extension version

 

KERNEL.builderVersion()

Returns string that contains builder version number.

Returns: String Builder version

 

KERNEL.backgroundMode()

Returns boolean value: "true" if the code is executed on the background and "false" if on the foreground.

Returns: Boolean Is this code running in the background

KERNEL.browserInfo

This object contains information about current browser environment.

Properties:

KERNEL.browserInfo.browser

Contains browser type string ["Chrome", "Firefox", "Explorer", "Opera", "Safari"]

 

KERNEL.browserInfo.version

Contains browser version number.

 

KERNEL.browserInfo.compatibility

Contains compatibility version number. This property makes sense only for Internet Explorer, for all other browsers it contains -1.

KERNEL.browserInfo.OS

Contains string OS ["Mac", "Windows", "Linux"]

KERNEL.browserInfo.nativeInfo

Contains current userAgent string.

KERNEL.JSON

Standard JavaScript object, it’s recommended to use KERNEL.JSON instead of native JSON object, because some websites could override window.JSON by manual implementation. By the way, if the native JSON implementation is available this object will be copied of the native implementation.

Methods:

KERNEL.JSON.stringify(value [, replacer [, space]])

Converts a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if the replacer array is specified. For more information see JSON.stringify()

value Object  
replacer Various If a function, transforms values and properties encountered while stringifying; if an array, specifies the set of properties included in objects in the final string.
space String Causes the resulting string to be pretty-printed.
Returns: String Passed object in the JSON format

 

KERNEL.JSON.parse(value [, reciver])

Parses a string as JSON, optionally transforming the value produced by parsing. For more information see JSON.parce()

KERNEL.Deferred

  • Deferred.prototype.addCallback(func)
  • Deferred.prototype.addErrback(func)
  • Deferred.prototype.addBoth(func)
  • Deferred.prototype.addCallbacks(callback, errback)
  • Deferred.prototype.callback([result])
  • Deferred.prototype.errback([result])

You should know that all these functions do not support the additional arguments.

How it works you could read here: http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html

Our implementation supports these functions, but for all listed functions the additional arguments were not supported (like it is in MochiKit).

KERNEL.Events

Subscription for events, sending messages. These functions organize the interaction between background and foreground. You can use one-time messages or context-base events interaction.

Methods:

KERNEL.Events.addListener(type, callback)

Subscribes callback to recieve specified type of incoming message.

type String Unique id of message type which we want to receive
callback Function

 Callback function like this:function (type, data, target, source){...};

type String Unique id of message that actually received
data Object Data which has been passed
target Integer Always the same as current context UID
source Integer Unique id of source context.

 

KERNEL.Events.sendMessage(type, data, [target])

Passes one-time message to desirable context.

type String Unique id of message type which will be passed
data Object Data to be sent to the other context.
target Integer Unique id of target context*.

*You can use context id (0 for the background scripts or tab id for the foreground scripts. Also you can use -1 as an UID for sending to all existing tabs. If this argument isn’t specified the message will be sent by following rules:

  • From the background script this message will be sent to all running foreground scripts. This will take the same effect as if you use -1
  • From the foreground script this message will be sent to the background script.

KERNEL.Events.addEventListener(type, callback)

Subscribes callback to recieve specified type of incoming events.

 

type String Unique id of event type which we want to receive
callback Function

 Callback function like this:function (event){...};

event EventObject  Event which has been passed

 

KERNEL.Events.dispatchEvent(type, data, target [, callback])

Passes event to desirable context.

type String Unique id of event type which will be passed
data Object

Data to be sent to the other context.

target Integer

Unique id of target context.

callback Function

Callback function like this:

function (event){...};

event EventObject Event which will be passed as the answer of current event

KERNEL.Storage

This object provide APIs to storing information between browser sessions. It provides the same functionality as the localStorage API with the following key differences:

  • both code parts (background and foreground) may accesses this API without any restriction;

Methods:

KERNEL.Storage.getValue(name, default)

Returns stored item by name.

name String Stored object name
default Object Default return value
Returns: Object Stored object data or default value if object doesn’t exist

 

KERNEL.Storage.setValue(name, value)

Save item into storage with specified name.

name String Storing object name
value Object Storing object

 

KERNEL.Storage.addListener(name, callback)

Subscribes specified callback to change event for specified stored object name.

name String Stored object name
callback Function

Callback function like this:

function (new, old){...};

new Object New object value
old Object Old object value

KERNEL.Request

This function provides API to make cross-domain XMLHttpRequest. Available in both code parts.

KERNEL.Request(type, url [, details])

This function creates new deferred object for specified request.

 

type String Desired request type, only "POST" and "GET" request types are allowed
url String Desired request url.
details Object

Additional request details

headers Object Key-Value pairs of headers
statuses Array of Integers Allowed as complete response statuses, all another response statuses will throw error. By default only 200 and 304 are allowed as complete
data Object or String If data is a string then data will be passed "as is" to the server, otherwise if data is an object, all data will be URI Encoded
timeout Integer Request timeout, in the milliseconds. By default is 10000
user String Credentials to use for simple authorization (if any)
pass String Credentials to use for simple authorization (if any)
Returns: KERNEL.Deffered

Deferred object for retrieving response result

KERNEL.Tabs

This API provides you with several functions and events for interaction with native browser tabs. All major functions are available only in the background code.

Methods:

KERNEL.Tabs.getCurrentUid()

This function provides you with information about current tab id (same as context id). Available only in the foreground.

Returns: Integer Current context id

 

KERNEL.Tabs.getTabInfo(uid)

This function provides you with information about specified content id

Returns: Object

Object that contains available information

url String Current tab url
active Boolean This field will be true for active tab and false for not active.

 

KERNEL.Tabs.getActiveTab()

This function returns latest active tab id.

Returns: Integer

Current active tab’s id.

 

KERNEL.Tabs.openTab(url, [active [, pinned [, callback]]])

This function opens the new tab with specified properties.

 

url String

Opens the tab with specified URL

active Boolean

If this argument is true then opened tabs will become active

pinned Boolean

If this argument is true then opened tabs will be code pinned*.

callback Function

Callback function like this:

function (id){...};

id Integer Id of opened tab**.

* You should know that this feature is not supported in the Internet Explorer.

** Also, in many cases this callback will be called early then opened tab will be ready to interaction, so you shouldn’t use this value immediately.

KERNEL.Tabs.addListener(type, handler)

This function subscribes event handler to the specified event type.

type String

Desired tab event type*

handler Function

Callback function like this:

function (type, uid){...};

type String Actual event type*. 
uid Integer Events source tab

*Supported following tab’s event types

open Tab opened, this event doesn’t mean that tab is loaded
navigate Tab navigated, this event is sent when tab is navigated
close Tab closed
activate This event means that the specified tab becomes active

KERNEL.File

Methods:

KERNEl.File.prepareFilePath(path)

This method provides you with real URL for access to your extension files. Do not store returned value between browser session. Also, this method available only in the background.

path String

Desired file path

Returns: String

Real file path for this session

All paths passing on this method should use the following sheme:

ab://module_name/path

In this scheme you can see several parts:

ab Mandatory scheme name, always uses "ab"
module_name Modules name which contains desired file
path Relative file path from File folder of target module.

You can embed any type of content, but you should remember that some files cannot be used in your extension. For example, different browsers have different restrictions for using embedded Flash content (swf files). Also, if you want to use some type of content you should be sure that this type of content can be used in all target platforms.

 

KENREL.File.getContent(path)

This method provides you with access to read internal extension’s file.

path String

Internal file path

Returns: KERNEL.Deffered

Deferred object for retrieving response result

KERNEL.Localization

This api provides you with infrastructure to implement internationalization across your extension.Unfortunately this API works as an asynchronous module for improving extension loading time.

Methods:

KERNEL.Localization.getLocalized(messgae)

This method returns localized string for specified message. As source locale uses current browser local.

message String

Desired message name

Returns: String

Localized message string

 

KERNEL.Localization.currentLocal()

This method returns current browser local name.

Returns: String

Current browser locale

 

KERNEL.Localization.defaultLocal()

This method returns default project local name.

Returns: String

Default project local name

 

KERNEL.Localization.callOnReady(callback)

This method provides opportunity to register onReady callback for localization API.

 

callback Function

 

KERNEL.Actions

This API provides several events which will be dispatched when something happens. You can use any internal events or use this API to dispatch/handle custom events. Never try to dispatch internal events, it may be unexpected for other modules.

Default event types:

 That events are available only in the background

buttonClick Happens when user click on toolbar button
popupShown Happens when pop-up window has been opened
popupHidden Happens when pop-up window has been closed

That events are available only in the foreground

backgroundDisconnected Happens when extension has been disabled or removed. This is very important for extensions with UI because for users it will be confusing that extension UI still exists on pages that were loaded earlier.

Methods:

KERNEL.Actions.addListener(type, callback)

Subscribe specified callback function for specified event type

type String

Event type

callback Function

Callback function like this:

function (type, data){...};

type String Dispatched event type
data Object Additional data, if available

 

KERNEL.Actions.exec(type, data)

Dispatche specified event type with additional data

type String

Event type

data Object

Additional data

KERNEL.Popup

Methods:

KERNEL.Popup.hide()

Closes pop-up window if it has been opened early.

KERNEL.Popup.resize(width, height)

Changes popup window size. You can use it anytime, no matter is pop-up window showed or closed.

 

width Integer

Pop-up window width

height Integer

Pop-up window height

  

KERNEL.Popup.getCurrentSize()

Returns current pop-up windows size, no matter is pop-up window showed or closed.

Returns: Object

Object, that contains information about current pop-up window size:

width Integer Pop-up window width
height Integer Pop-up window height

KERNEL.Button

You should know that all of these functions will have no effect in the Internet Explorer.

Methods:

In the background:

KERNEL.Button.setBadge(text, [tabId])

In the foreground:

KERNEL.Button.setBadge(text)

Specifies button badge text for specified tabId. If tabId is not specified, then it will be used by following rules:

  • If function has been invoked from the background code: specified text will be set for all tabs.
  • If function has been invoked from the foreground code: specified text will be set for current tab.

Specified text must contain only digits and cannot be longer then 4 characters. If user specified text that contains only "0" then badge will be removed from button.

text String

Button badge text:

tabId Integer  

KERNEL.Button.setImage(imagePath)

Changes button image. Specified imagePath should be prepared firstly by the KERNEL.File.prepareFilePath, also you can use only embedded image file.

imagePath String

 

KERNEL.Button.setTooltip(text)

Changes button tooltip.

text String

 

 

$AB.KERNEL.XML

Methods:

stringify : function (object);

parse : function (string);

$AB.KERNEL.XML.stringify(object)

Returning string

$AB.KERNEL.XML.parse(string)

Modifying the input string into XMLObject.

$AB.KERNEL.Base64

Bundle for working with Base64 for coding and decoding of information.

$AB.KERNEL.Base64.encode

The $AB.KERNEL.Base64.encode () function encodes a Base64.

Syntax:

var strEncodeBase64 = $AB.KERNEL.Base64.encode (strValue);

Parameters:

strValue is a string. The string is to be encoded.

StrEncodeBase64 is a string encoded.

Example:

function foo() {                                        
    var uri="http://test.com/my test.asp?name=ståle&car=saab";
    var base64_encode = $AB.KERNEL.Base64.encode (uri);
    alert(base64_encode);
    alert($AB.KERNEL.Base64.decode(base64_encode));                                                
}

$AB.KERNEL.Base64.decode

The $AB.KERNEL.Base64.decode() function decodes a Base64.

Syntax

var strDecodeBase64 = $AB.KERNEL.Base64.decode (strValue);

Parameters:

strValue is a string. The string is to be decoded.

StrDecodeBase64 is a string decoded.

Example:

function foo() {                                        
    var uri="http://test.com/my test.asp?name=stale&car=saab";
    var base64_encode = $AB.KERNEL.Base64.encode (uri);
    alert(base64_encode);
    alert($AB.KERNEL.Base64.decode(base64_encode));                                  
}

 $AB.KERNEL.Request

Method for handling cross-domain requests.

$AB.KERNEL.Request(type, url, arguments) : deffered object;

Parameters:

type - request type GET or POST;

url - the address the request will be sent to;

arguments - set of the transferred arguments;

Returns deffered object.

Example:

var request = new $AB.KERNEL.Request("GET", "www.example.com/api", {});
request.addCallback(function(response) {
        alert(“Response from server: ” + response);
});
request.addErrback(function(error) {
        alert(“Error: “ + error);
});

$AB.KERNEL.URI

Coding/ decoding URL. Analogue to "codeURIComponent" function.

Methods:

  • $AB.KERNEL.URI.encodeURIComponent;
  • $AB.KERNEL.URI.decodeURIComponent;
  • $AB.KERNEL.URI.escape;
  • $AB.KERNEL.URI.unescape.

$AB.KERNEL.URI.encodeURIComponent

The $AB.KERNEL.URI.encodeURIComponent() function encodes a URI component. This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $#

Syntax:

var strEncodeUri = $AB.KERNEL.URI.encodeURIComponent(uri);

Parameters:

uri is a string. The URI to be encoded.

StrEncodeUri is a string encoded uri.

Example:

function foo() {                                        
    var uri="http://test.com/my test.asp?name=ståle&car=saab";
    alert($AB.KERNEL.URI.encodeURIComponent(uri));
}

$AB.KERNEL.URI.decodeURIComponent

The $AB.KERNEL.URI.decodeURIComponent() function decodes a URI component.

Syntax:

var strDecodeUri = $AB.KERNEL.URI.decodeURIComponent(uri);

Parameters:

uri is a string. The URI to be decoded.

StrDecodeUri is a string decoded uri.

Example:

function foo() {                                                
    var uri="http://test.com/my test.asp?name=ståle&car=saab";
    var uri_encode = $AB.KERNEL.URI.encodeURIComponent(uri);
    alert(uri_encode);
    alert($AB.KERNEL.URI.decodeURIComponent(uri_encode));                                   
}      

$AB.KERNEL.URI.escape doesn’t encode symbols @*/+, the call is executed like encodeURIComponent

  • $AB.KERNEL.URI.unescape - function decodes an encoded string.