From a368c2253d24634c4dbc6467ec3ef2c047fed18c Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 07:30:30 +0200 Subject: [PATCH 01/15] Moved dynBookmarks to _dbm-2.5.x.js and turned into Adapter + added empty migration classes --- package-lock.json | 2 +- package.json | 2 +- src/js/lib/_dbm-2.5.x.js | 113 ++++++++++++++++++++++++++ src/js/lib/dynBookmarks.js | 109 ++++--------------------- src/js/migrations/_migration-2.6.0.js | 11 +++ src/js/migrations/_migrator.js | 8 ++ src/js/migrations/index.js | 8 ++ src/manifest.json | 2 +- 8 files changed, 157 insertions(+), 98 deletions(-) create mode 100644 src/js/lib/_dbm-2.5.x.js create mode 100644 src/js/migrations/_migration-2.6.0.js create mode 100644 src/js/migrations/_migrator.js create mode 100644 src/js/migrations/index.js diff --git a/package-lock.json b/package-lock.json index 266651a..9fb710c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "chrome-dynamic-bookmarks", - "version": "2.5.1", + "version": "2.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ccf896a..0d02f27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-dynamic-bookmarks", - "version": "2.5.1", + "version": "2.6.0", "description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.", "scripts": { "dev": "webpack --mode development", diff --git a/src/js/lib/_dbm-2.5.x.js b/src/js/lib/_dbm-2.5.x.js new file mode 100644 index 0000000..e2938e0 --- /dev/null +++ b/src/js/lib/_dbm-2.5.x.js @@ -0,0 +1,113 @@ +/** + * Collection of storage functions used in versions pre-2.6 + */ + +export const dynBookmarksPropName = "dynBookmarks"; + +/** + * finds dynBook object in hash map form: `{ bookmark_id: { regExp:String, history:[String] } }` + * @param {function} done - callback function called with `done(error, dynBook)` + */ +export function findAll(done) { + chrome.storage.sync.get([dynBookmarksPropName], result => { + if (chrome.runtime.lastError) { + done(chrome.runtime.lastError.message); + } else { + const dynBook = result[dynBookmarksPropName] || {}; + done(null, dynBook); + } + }); +} + +/** + * finds dynBook[id] in form `{regExp:String, history: [String]}` + * @param {string} id - id of dynamic bookmark + * @param {function} done - callback function called with `done(error, dynBookItem)` + */ +export function findById(id, done) { + findAll((err, dynBook) => { + if (err) done(err); + else done(null, dynBook[id]); + }); +} + +/** + * Updates dynamic bookmark with given id (creates one if it doesn't exist) + * @param {string} id - id of dynamic bookmark + * @param {object} options - `{regExp: String, history:[String]}` + * @param {function} done - (optional) callback function called with done(error, updatedDynBookItem) + */ +export function findByIdAndUpdate(id, options, done) { + findAll((err, dynBook) => { + if (err) { + if (typeof done == "function") { + done(err); + } else { + console.warn(err); + } + } else { + dynBook[id] = { + regExp: options.regExp || dynBook[id].regExp, + history: options.history || dynBook[id].history + }; + overwrite(dynBook, err => { + if (typeof done == "function") { + if (err) done(err); + else done(null, dynBook[id]); + } + }); + } + }); +} + +/** + * Overwrites dynamic bookmarks object from storage with `newDynBook`. + * `Warning`: This function is DANGEROUS! Potential data loss! + * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` + * @param {function} done - callback function called with done(error) + */ +export function overwrite(newDynBook, done) { + chrome.storage.sync.set({ [dynBookmarksPropName]: newDynBook }, () => { + if (typeof done == "function") { + if (chrome.runtime.lastError) { + done(chrome.runtime.lastError.message); + } else { + done(null); + } + } + }); +} + +/** + * Creates dynBookmark item and sets it into the storage + * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` + * @param {function} done - callback function called with (err, createdItem) + */ +export function create(props, done) { + if (!props.id || !props.regExp) { + done("id or regExp props are missing in dynBookmarks.create!"); + } + findByIdAndUpdate( + props.id, + { + regExp: props.regExp, + history: props.history || [] + }, + done + ); +} + +export function findByIdAndRemove(id, done) { + findAll((err, dynBook) => { + if (err) { + if (typeof done == "function") { + done(err); + } else { + console.warn(err); + } + } else if (dynBook[id]) { + delete dynBook[id]; + overwrite(dynBook, done); + } + }); +} diff --git a/src/js/lib/dynBookmarks.js b/src/js/lib/dynBookmarks.js index 51c44d6..7eaf7e8 100644 --- a/src/js/lib/dynBookmarks.js +++ b/src/js/lib/dynBookmarks.js @@ -1,109 +1,28 @@ -const dynBookmarksPropName = 'dynBookmarks'; - /** - * finds dynBook object in hash map form: `{ bookmark_id: { regExp:String, history:[String] } }` - * @param {function} done - callback function called with `done(error, dynBook)` + * Adapter */ +import * as dbm from "./_dbm-2.5.x"; + export function findAll(done) { - chrome.storage.sync.get([dynBookmarksPropName], (result) => { - if (chrome.runtime.lastError) { - done(chrome.runtime.lastError.message); - } else { - const dynBook = result[dynBookmarksPropName] || {}; - done(null, dynBook); - } - }); + dbm.findAll(done); } -/** - * finds dynBook[id] in form `{regExp:String, history: [String]}` - * @param {string} id - id of dynamic bookmark - * @param {function} done - callback function called with `done(error, dynBookItem)` - */ -export function findById(id, done) { - findAll((err, dynBook) => { - if (err) done(err); - else done(null, dynBook[id]); - }); +export function create(props, done) { + dbm.create(props, done); } -/** - * Updates dynamic bookmark with given id (creates one if it doesn't exist) - * @param {string} id - id of dynamic bookmark - * @param {object} options - `{regExp: String, history:[String]}` - * @param {function} done - (optional) callback function called with done(error, updatedDynBookItem) - */ -export function findByIdAndUpdate(id, options, done) { - findAll((err, dynBook) => { - if (err) { - if (typeof done == 'function') { - done(err); - } else { - console.warn(err); - } - } else { - dynBook[id] = { - regExp: options.regExp || dynBook[id].regExp, - history: options.history || dynBook[id].history - }; - overwrite(dynBook, (err) => { - if (typeof done == 'function') { - if (err) done(err); - else done(null, dynBook[id]); - } - }); - } - }); +export function findByIdAndRemove(id, done) { + dbm.findByIdAndRemove(id, done); } -/** - * Overwrites dynamic bookmarks object from storage with `newDynBook`. - * `Warning`: This function is DANGEROUS! Potential data loss! - * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` - * @param {function} done - callback function called with done(error) - */ -export function overwrite(newDynBook, done) { - chrome.storage.sync.set({ [dynBookmarksPropName]: newDynBook }, () => { - if (typeof done == 'function') { - if (chrome.runtime.lastError) { - done(chrome.runtime.lastError.message); - } else { - done(null); - } - } - }); +export function findByIdAndUpdate(id, options, done) { + dbm.findByIdAndUpdate(id, options, done); } -/** - * Creates dynBookmark item and sets it into the storage - * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` - * @param {function} done - callback function called with (err, createdItem) - */ -export function create(props, done) { - if (!props.id || !props.regExp) { - done('id or regExp props are missing in dynBookmarks.create!'); - } - findByIdAndUpdate( - props.id, - { - regExp: props.regExp, - history: props.history || [] - }, - done - ); +export function findById(id, done) { + dbm.findById(id, done); } -export function findByIdAndRemove(id, done) { - findAll((err, dynBook) => { - if (err) { - if (typeof done == 'function') { - done(err); - } else { - console.warn(err); - } - } else if (dynBook[id]) { - delete dynBook[id]; - overwrite(dynBook, done); - } - }); +export function overwrite(newDynBook, done) { + dbm.overwrite(newDynBook, done); } diff --git a/src/js/migrations/_migration-2.6.0.js b/src/js/migrations/_migration-2.6.0.js new file mode 100644 index 0000000..b02dbaa --- /dev/null +++ b/src/js/migrations/_migration-2.6.0.js @@ -0,0 +1,11 @@ +import { Migrator } from "./_migrator"; +import * as dbm_2_5 from "../lib/_dbm-2.5.x"; + +export class Migrator260 extends Migrator { + up() { + dbm_2_5.findAll((err, dynBook) => {}); + } + down() {} +} + +export default new Migrator260(); diff --git a/src/js/migrations/_migrator.js b/src/js/migrations/_migrator.js new file mode 100644 index 0000000..67972f4 --- /dev/null +++ b/src/js/migrations/_migrator.js @@ -0,0 +1,8 @@ +export class Migrator { + /**Execute migration */ + up = () => {}; + /**Undo migration */ + down = () => {}; +} + +export default Migrator; diff --git a/src/js/migrations/index.js b/src/js/migrations/index.js new file mode 100644 index 0000000..261ee0b --- /dev/null +++ b/src/js/migrations/index.js @@ -0,0 +1,8 @@ +import migrator_260 from "./_migration-2.6.0"; + +/** + * Used to migrate data to new storage when updating application + */ +export function migrate() { + migrator_260.up(); +} diff --git a/src/manifest.json b/src/manifest.json index 9974313..518c7c9 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Dynamic Bookmarks", "description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.", - "version": "2.4.3", + "version": "2.6.0", "permissions": ["tabs", "bookmarks", "storage"], "background": { "page": "background.html" From 348f8dca8a3f6cf93b0741c1ba9dcd0494c5b108 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 08:32:52 +0200 Subject: [PATCH 02/15] Added chrome.intellisense.js file which enables intellisense for chrome api on vscode --- src/js/chrome.intellisense.js | 5528 +++++++++++++++++ src/js/lib/dynBookmarks.js | 7 +- src/js/lib/{ => storage}/_dbm-2.5.x.js | 4 +- src/js/lib/storage/_dbm-2.6.0.js | 17 + src/js/lib/storage/_dbm-repository.js | 39 + .../storage/migrations/_migration-2.6.0.js | 18 + .../{ => lib/storage}/migrations/_migrator.js | 0 src/js/{ => lib/storage}/migrations/index.js | 0 src/js/migrations/_migration-2.6.0.js | 11 - 9 files changed, 5606 insertions(+), 18 deletions(-) create mode 100644 src/js/chrome.intellisense.js rename src/js/lib/{ => storage}/_dbm-2.5.x.js (97%) create mode 100644 src/js/lib/storage/_dbm-2.6.0.js create mode 100644 src/js/lib/storage/_dbm-repository.js create mode 100644 src/js/lib/storage/migrations/_migration-2.6.0.js rename src/js/{ => lib/storage}/migrations/_migrator.js (100%) rename src/js/{ => lib/storage}/migrations/index.js (100%) delete mode 100644 src/js/migrations/_migration-2.6.0.js diff --git a/src/js/chrome.intellisense.js b/src/js/chrome.intellisense.js new file mode 100644 index 0000000..210f1d8 --- /dev/null +++ b/src/js/chrome.intellisense.js @@ -0,0 +1,5528 @@ +var chrome = {}; +chrome.devtools = {}; +chrome.declarativeWebRequest = {}; +//#region Types +//#region Chrome.AccessibilityObject +chrome.AccessibilityObject = function () { + /// The type of this object, which determines the contents of 'details'. + /// The localized name of the object, like OK or Password. Do not rely on an exact string match because the text will be in the user's language and may change in the future. + /// The localized name of the context for the object, like the name of the surrounding toolbar or group of controls. + /// Other details like the state, depending on the type of object. + this.type = ""; + this.name = ""; + this.context = ""; + this.details = {}; +}; + +//#endregion +//#region Chrome.AlertInfo +chrome.AlertInfo = function () { + /// The message the alert is showing. + this.message = ""; +}; + +//#endregion +//#region Chrome.BlockingResponse +chrome.BlockingResponse = function () { + /// If true, the request is cancelled. Used in onBeforeRequest, this prevents the request from being sent. + /// Only used as a response to the onBeforeRequest event. If set, the original request is prevented from being sent and is instead redirected to the given URL. + /// Only used as a response to the onBeforeSendHeaders event. If set, the request is made with these request headers instead. + /// Only used as a response to the onHeadersReceived event. If set, the server is assumed to have responded with these response headers instead. Only return responseHeaders if you really want to modify the headers in order to limit the number of conflicts (only one extension may modify responseHeaders for each request). + /// Only used as a response to the onAuthRequired event. If set, the request is made using the supplied credentials. + this.cancel = true; + this.redirectUrl = ""; + this.requestHeaders = {}; + this.responseHeaders = {}; + this.authCredentials = {}; +}; + +//#endregion +//#region Chrome.BookmarkTreeNode +chrome.BookmarkTreeNode = function () { + /// The unique identifier for the node. IDs are unique within the current profile, and they remain valid even after the browser is restarted. + /// The id of the parent folder. Omitted for the root node. + /// The 0-based position of this node within its parent folder. + /// The URL navigated to when a user clicks the bookmark. Omitted for folders. + /// The text displayed for the node. + /// When this node was created, in milliseconds since the epoch (new Date(dateAdded)). + /// When the contents of this folder last changed, in milliseconds since the epoch. + /// An ordered list of children of this node. + this.id = ""; + this.parentId = ""; + this.index = {}; + this.url = ""; + this.title = ""; + this.dateAdded = 0; + this.dateGroupModified = 0; + this.children = {}; +}; + +//#endregion +//#region Chrome.Button +chrome.Button = function () { + this.update = function (iconPath, tooltipText, disabled) { + /// + /// Updates the attributes of the button. If some of the arguments are omitted or null, the corresponding attributes are not updated. + /// + /// Path to the new icon of the button. + /// Text shown as a tooltip when user hovers the mouse over the button. + /// Whether the button is disabled. + //No Callback + }; + +}; + +//#endregion +//#region Chrome.Cache +chrome.Cache = function () { + /// The size of the cache, in bytes. + /// The part of the cache that is utilized, in bytes. + this.size = 0; + this.liveSize = 0; +}; + +//#endregion +//#region Chrome.CancelRequest +chrome.CancelRequest = function () { + /// + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.CheckboxDetails +chrome.CheckboxDetails = function () { + /// True if this checkbox is checked. + this.isChecked = true; +}; + +//#endregion +//#region Chrome.ChromeSetting +chrome.ChromeSetting = function () { + this.get = function (details, callback) { + /// + /// Gets the value of a setting. + /// + /// Which setting to consider. + /// + callback({}); + }; + + this.set = function (details, callback) { + /// + /// Sets the value of a setting. + /// + /// Which setting to change. + /// Called at the completion of the set operation. + callback(); + }; + + this.clear = function (details, callback) { + /// + /// Clears the setting, restoring any default value. + /// + /// Which setting to clear. + /// Called at the completion of the clear operation. + callback(); + }; + +}; + +//#endregion +//#region Chrome.ChromeSettingsOverrides +chrome.ChromeSettingsOverrides = function () { + /// Settings to permit bookmarks user interface customization by extensions. + /// New value for the homepage. + /// A search engine + /// A new startup page to be added to the list. + this.bookmarks_ui = {}; + this.homepage = ""; + this.search_provider = {}; + this.startup_pages = {}; +}; + +//#endregion +//#region Chrome.ClearDataOptions +chrome.ClearDataOptions = function () { + /// Clear data accumulated on or after this date, represented in milliseconds since the epoch (accessible via the getTime method of the JavaScript Date object). If absent, defaults to 0 (which would remove all browsing data). + this.since = 0; +}; + +//#endregion +//#region Chrome.ClearDataTypeSet +chrome.ClearDataTypeSet = function () { + /// Websites' appcaches. + /// The partition's cache. Note: This clears the entire cache regardless of the age passed to clearData. + /// The partition's cookies. + /// The partition's download list. + /// Websites' filesystems. + /// The partition's stored form data. + /// The partition's history. + /// Websites' IndexedDB data. + /// Websites' local storage data. + /// Server-bound certificates. + /// Plugins' data. + /// Stored passwords. + /// Websites' WebSQL data. + this.appcache = true; + this.cache = true; + this.cookies = true; + this.downloads = true; + this.fileSystems = true; + this.formData = true; + this.history = true; + this.indexedDB = true; + this.localStorage = true; + this.serverBoundCertificates = true; + this.pluginData = true; + this.passwords = true; + this.webSQL = true; +}; + +//#endregion +//#region Chrome.ColorArray +chrome.ColorArray = function () { +}; + +//#endregion +//#region Chrome.ComboBoxDetails +chrome.ComboBoxDetails = function () { + /// The value of the combo box. + /// The number of items in the combo box's list. + /// The 0-based index of the current value, or -1 if the user entered a value not from the list. + this.value = ""; + this.itemCount = {}; + this.itemIndex = {}; +}; + +//#endregion +//#region Chrome.Command +chrome.Command = function () { + /// The name of the Extension Command + /// The Extension Command description + /// The shortcut active for this command, or blank if not active. + this.name = ""; + this.description = ""; + this.shortcut = ""; +}; + +//#endregion +//#region Chrome.ContentSetting +chrome.ContentSetting = function () { + this.clear = function (details, callback) { + /// + /// Clear all content setting rules set by this extension. + /// + /// + /// + callback(); + }; + + this.get = function (details, callback) { + /// + /// Gets the current content setting for a given pair of URLs. + /// + /// + /// + callback({}); + }; + + this.set = function (details, callback) { + /// + /// Applies a new content setting rule. + /// + /// + /// + callback(); + }; + + this.getResourceIdentifiers = function (callback) { + /// + /// + /// + /// + callback({}); + }; + +}; + +//#endregion +//#region Chrome.ContentWindow +chrome.ContentWindow = function () { + this.postMessage = function (message, targetOrigin) { + /// + ///

Posts a message to the embedded web content as long as the embedded content is displaying a page from the target origin. This method is available once the page has completed loading. Listen for the contentload event and then call the method.

The guest will be able to send replies to the embedder by posting message to event.source on the message event it receives.

This API is identical to the HTML5 postMessage API for communication between web pages. The embedder may listen for replies by adding a message event listener to its own frame.

+ ///
+ /// Message object to send to the guest. + /// Specifies what the origin of the guest window must be for the event to be dispatched. + //No Callback + }; + +}; + +//#endregion +//#region Chrome.Cookie +chrome.Cookie = function () { + /// The name of the cookie. + /// The value of the cookie. + /// The domain of the cookie (e.g. "www.google.com", "example.com"). + /// True if the cookie is a host-only cookie (i.e. a request's host must exactly match the domain of the cookie). + /// The path of the cookie. + /// True if the cookie is marked as Secure (i.e. its scope is limited to secure channels, typically HTTPS). + /// True if the cookie is marked as HttpOnly (i.e. the cookie is inaccessible to client-side scripts). + /// True if the cookie is a session cookie, as opposed to a persistent cookie with an expiration date. + /// The expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies. + /// The ID of the cookie store containing this cookie, as provided in getAllCookieStores(). + this.name = ""; + this.value = ""; + this.domain = ""; + this.hostOnly = true; + this.path = ""; + this.secure = true; + this.httpOnly = true; + this.session = true; + this.expirationDate = 0; + this.storeId = ""; +}; + +//#endregion +//#region Chrome.CookieStore +chrome.CookieStore = function () { + /// The unique identifier for the cookie store. + /// Identifiers of all the browser tabs that share this cookie store. + this.id = ""; + this.tabIds = {}; +}; + +//#endregion +//#region Chrome.DataTypeSet +chrome.DataTypeSet = function () { + /// Websites' appcaches. + /// The browser's cache. Note: when removing data, this clears the entire cache: it is not limited to the range you specify. + /// The browser's cookies. + /// The browser's download list. + /// Websites' file systems. + /// The browser's stored form data. + /// The browser's history. + /// Websites' IndexedDB data. + /// Websites' local storage data. + /// Server-bound certificates. + /// Plugins' data. + /// Stored passwords. + /// Websites' WebSQL data. + this.appcache = true; + this.cache = true; + this.cookies = true; + this.downloads = true; + this.fileSystems = true; + this.formData = true; + this.history = true; + this.indexedDB = true; + this.localStorage = true; + this.serverBoundCertificates = true; + this.pluginData = true; + this.passwords = true; + this.webSQL = true; +}; + +//#endregion +//#region Chrome.DataTypeSet +chrome.DataTypeSet = function () { + /// Websites' appcaches. + /// The browser's cookies. + /// Websites' file systems. + /// Websites' IndexedDB data. + /// Websites' local storage data. + /// Websites' WebSQL data. + this.appcache = true; + this.cookies = true; + this.fileSystems = true; + this.indexedDB = true; + this.localStorage = true; + this.webSQL = true; +}; + +//#endregion +//#region Chrome.Debuggee +chrome.Debuggee = function () { + /// The id of the tab which you intend to debug. + /// The id of the extension which you intend to debug. Attaching to an extension background page is only possible when 'enable-silent-debugging' flag is enabled on the target browser. + /// The opaque id of the debug target. + this.tabId = {}; + this.extensionId = ""; + this.targetId = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.AddRequestCookie +chrome.declarativeWebRequest.AddRequestCookie = function () { + /// + /// Cookie to be added to the request. No field may be undefined. + this.instanceType = ""; + this.cookie = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.AddResponseCookie +chrome.declarativeWebRequest.AddResponseCookie = function () { + /// + /// Cookie to be added to the response. The name and value need to be specified. + this.instanceType = ""; + this.cookie = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.AddResponseHeader +chrome.declarativeWebRequest.AddResponseHeader = function () { + /// + /// HTTP response header name. + /// HTTP response header value. + this.instanceType = ""; + this.name = ""; + this.value = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.EditRequestCookie +chrome.declarativeWebRequest.EditRequestCookie = function () { + /// + /// Filter for cookies that will be modified. All empty entries are ignored. + /// Attributes that shall be overridden in cookies that machted the filter. Attributes that are set to an empty string are removed. + this.instanceType = ""; + this.filter = {}; + this.modification = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.EditResponseCookie +chrome.declarativeWebRequest.EditResponseCookie = function () { + /// + /// Filter for cookies that will be modified. All empty entries are ignored. + /// Attributes that shall be overridden in cookies that machted the filter. Attributes that are set to an empty string are removed. + this.instanceType = ""; + this.filter = {}; + this.modification = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.FilterResponseCookie +chrome.declarativeWebRequest.FilterResponseCookie = function () { + /// Name of a cookie. + /// Value of a cookie, may be padded in double-quotes. + /// Value of the Expires cookie attribute. + /// Value of the Max-Age cookie attribute + /// Value of the Domain cookie attribute. + /// Value of the Path cookie attribute. + /// Existence of the Secure cookie attribute. + /// Existence of the HttpOnly cookie attribute. + /// Inclusive upper bound on the cookie lifetime (specified in seconds after current time). Only cookies whose expiration date-time is in the interval [now, now + ageUpperBound] fulfill this criterion. Session cookies and cookies whose expiration date-time is in the past do not meet the criterion of this filter. The cookie lifetime is calculated from either 'max-age' or 'expires' cookie attributes. If both are specified, 'max-age' is used to calculate the cookie lifetime. + /// Inclusive lower bound on the cookie lifetime (specified in seconds after current time). Only cookies whose expiration date-time is set to 'now + ageLowerBound' or later fulfill this criterion. Session cookies do not meet the criterion of this filter. The cookie lifetime is calculated from either 'max-age' or 'expires' cookie attributes. If both are specified, 'max-age' is used to calculate the cookie lifetime. + /// Filters session cookies. Session cookies have no lifetime specified in any of 'max-age' or 'expires' attributes. + this.name = ""; + this.value = ""; + this.expires = ""; + this.maxAge = 0; + this.domain = ""; + this.path = ""; + this.secure = ""; + this.httpOnly = ""; + this.ageUpperBound = {}; + this.ageLowerBound = {}; + this.sessionCookie = true; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.IgnoreRules +chrome.declarativeWebRequest.IgnoreRules = function () { + /// + /// If set, rules with a lower priority than the specified value are ignored. This boundary is not persisted, it affects only rules and their actions of the same network request stage. + /// If set, rules with the specified tag are ignored. This ignoring is not persisted, it affects only rules and their actions of the same network request stage. Note that rules are executed in descending order of their priorities. This action affects rules of lower priority than the current rule. Rules with the same priority may or may not be ignored. + this.instanceType = ""; + this.lowerPriorityThan = {}; + this.hasTag = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RedirectByRegEx +chrome.declarativeWebRequest.RedirectByRegEx = function () { + /// + /// A match pattern that may contain capture groups. Capture groups are referenced in the Perl syntax ($1, $2, ...) instead of the RE2 syntax (\1, \2, ...) in order to be closer to JavaScript Regular Expressions. + /// Destination pattern. + this.instanceType = ""; + this.from = ""; + this.to = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RedirectToEmptyDocument +chrome.declarativeWebRequest.RedirectToEmptyDocument = function () { + /// + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RedirectToTransparentImage +chrome.declarativeWebRequest.RedirectToTransparentImage = function () { + /// + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RemoveRequestCookie +chrome.declarativeWebRequest.RemoveRequestCookie = function () { + /// + /// Filter for cookies that will be removed. All empty entries are ignored. + this.instanceType = ""; + this.filter = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RemoveRequestHeader +chrome.declarativeWebRequest.RemoveRequestHeader = function () { + /// + /// HTTP request header name (case-insensitive). + this.instanceType = ""; + this.name = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RemoveResponseCookie +chrome.declarativeWebRequest.RemoveResponseCookie = function () { + /// + /// Filter for cookies that will be removed. All empty entries are ignored. + this.instanceType = ""; + this.filter = {}; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RemoveResponseHeader +chrome.declarativeWebRequest.RemoveResponseHeader = function () { + /// + /// HTTP request header name (case-insensitive). + /// HTTP request header value (case-insensitive). + this.instanceType = ""; + this.name = ""; + this.value = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.RequestCookie +chrome.declarativeWebRequest.RequestCookie = function () { + /// Name of a cookie. + /// Value of a cookie, may be padded in double-quotes. + this.name = ""; + this.value = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.ResponseCookie +chrome.declarativeWebRequest.ResponseCookie = function () { + /// Name of a cookie. + /// Value of a cookie, may be padded in double-quotes. + /// Value of the Expires cookie attribute. + /// Value of the Max-Age cookie attribute + /// Value of the Domain cookie attribute. + /// Value of the Path cookie attribute. + /// Existence of the Secure cookie attribute. + /// Existence of the HttpOnly cookie attribute. + this.name = ""; + this.value = ""; + this.expires = ""; + this.maxAge = 0; + this.domain = ""; + this.path = ""; + this.secure = ""; + this.httpOnly = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.SendMessageToExtension +chrome.declarativeWebRequest.SendMessageToExtension = function () { + /// + /// The value that will be passed in the message attribute of the dictionary that is passed to the event handler. + this.instanceType = ""; + this.message = ""; +}; + +//#endregion +//#region Chrome.declarativeWebRequest.SetRequestHeader +chrome.declarativeWebRequest.SetRequestHeader = function () { + /// + /// HTTP request header name. + /// HTTP request header value. + this.instanceType = ""; + this.name = ""; + this.value = ""; +}; + +//#endregion +//#region Chrome.DefaultSuggestResult +chrome.DefaultSuggestResult = function () { + /// The text that is displayed in the URL dropdown. Can contain XML-style markup for styling. The supported tags are 'url' (for a literal URL), 'match' (for highlighting text that matched what the user's query), and 'dim' (for dim helper text). The styles can be nested, eg. dimmed match. + /// An array of style ranges for the description, as provided by the extension. + /// An array of style ranges for the description, as provided by ToValue(). + this.description = ""; + this.descriptionStyles = {}; + this.descriptionStylesRaw = {}; +}; + +//#endregion +//#region Chrome.DesktopCaptureSourceType +chrome.DesktopCaptureSourceType = function () { +}; + +//#endregion +//#region Chrome.Details +chrome.Details = function () { +}; + +//#endregion +//#region Chrome.Device +chrome.Device = function () { + /// Represents all information about a foreign device. + /// A list of open window sessions for the foreign device, sorted from most recently to least recently modified session. + this.info = ""; + this.sessions = {}; +}; + +//#endregion +//#region Chrome.DialogController +chrome.DialogController = function () { + this.ok = function (response) { + /// + /// Accept the dialog. Equivalent to clicking OK in an alert, confirm, or prompt dialog. + /// + /// The response string to provide to the guest when accepting a prompt dialog. + //No Callback + }; + + this.cancel = function () { + /// + /// Reject the dialog. Equivalent to clicking Cancel in a confirm or prompt dialog. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.DOMWindow +chrome.DOMWindow = function () { +}; + +//#endregion +//#region Chrome.DownloadPermissionRequest +chrome.DownloadPermissionRequest = function () { + /// The HTTP request type (e.g. GET) associated with the download request. + /// The requested download URL. + this.requestMethod = ""; + this.url = ""; + this.allow = function () { + /// + /// Allow the permission request. + /// + //No Callback + }; + + this.deny = function () { + /// + /// Deny the permission request. This is the default behavior if allow is not called. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.ElementsPanel +chrome.ElementsPanel = function () { + this.createSidebarPane = function (title, callback) { + /// + /// Creates a pane within panel's sidebar. + /// + /// Text that is displayed in sidebar caption. + /// A callback invoked when the sidebar is created. + callback(new chrome.ExtensionSidebarPane()); + }; + +}; + +//#endregion +//#region Chrome.Event +chrome.Event = function () { + this.addListener = function (callback) { + /// + /// Registers an event listener callback to an event. + /// + /// Called when an event occurs. The parameters of this function depend on the type of event. + callback(); + }; + + this.removeListener = function (callback) { + /// + /// Deregisters an event listener callback from an event. + /// + /// Listener that shall be unregistered. + callback(); + }; + + this.hasListener = function (callback) { + /// + /// + /// Listener whose registration status shall be tested. + callback(); + return true; + }; + + this.hasListeners = function () { + /// + /// + //No Callback + return true; + }; + + this.addRules = function (eventName, webViewInstanceId, rules, callback) { + /// + /// Registers rules to handle events. + /// + /// Name of the event this function affects. + /// If provided, this is an integer that uniquely identfies the associated with this function call. + /// Rules to be registered. These do not replace previously registered rules. + /// Called with registered rules. + callback({}); + }; + + this.getRules = function (eventName, webViewInstanceId, ruleIdentifiers, callback) { + /// + /// Returns currently registered rules. + /// + /// Name of the event this function affects. + /// If provided, this is an integer that uniquely identfies the associated with this function call. + /// If an array is passed, only rules with identifiers contained in this array are returned. + /// Called with registered rules. + callback({}); + }; + + this.removeRules = function (eventName, webViewInstanceId, ruleIdentifiers, callback) { + /// + /// Unregisters currently registered rules. + /// + /// Name of the event this function affects. + /// If provided, this is an integer that uniquely identfies the associated with this function call. + /// If an array is passed, only rules with identifiers contained in this array are unregistered. + /// Called when rules were unregistered. + callback(); + }; + +}; + +//#endregion +//#region Chrome.ExtensionInfo +chrome.ExtensionInfo = function () { + /// The extension's unique identifier. + /// The name of this extension, app, or theme. + /// A short version of the name of this extension, app, or theme. + /// The description of this extension, app, or theme. + /// The version of this extension, app, or theme. + /// Whether this extension can be disabled or uninstalled by the user. + /// Whether it is currently enabled or disabled. + /// A reason the item is disabled. + /// True if this is an app. + /// The type of this extension, app, or theme. + /// The launch url (only present for apps). + /// The URL of the homepage of this extension, app, or theme. + /// The update URL of this extension, app, or theme. + /// Whether the extension, app, or theme declares that it supports offline. + /// The url for the item's options page, if it has one. + /// A list of icon information. Note that this just reflects what was declared in the manifest, and the actual image at that url may be larger or smaller than what was declared, so you might consider using explicit width and height attributes on img tags referencing these images. See the manifest documentation on icons for more details. + /// Returns a list of API based permissions. + /// Returns a list of host based permissions. + /// How the extension was installed. One of
admin: The extension was installed because of an administrative policy,
development: The extension was loaded unpacked in developer mode,
normal: The extension was installed normally via a .crx file,
sideload: The extension was installed by other software on the machine,
other: The extension was installed by other means.
+ this.id = ""; + this.name = ""; + this.shortName = ""; + this.description = ""; + this.version = ""; + this.mayDisable = true; + this.enabled = true; + this.disabledReason = ""; + this.isApp = true; + this.type = ""; + this.appLaunchUrl = ""; + this.homepageUrl = ""; + this.updateUrl = ""; + this.offlineEnabled = true; + this.optionsUrl = ""; + this.icons = {}; + this.permissions = {}; + this.hostPermissions = {}; + this.installType = ""; +}; + +//#endregion +//#region Chrome.ExtensionPanel +chrome.ExtensionPanel = function () { + this.createStatusBarButton = function (iconPath, tooltipText, disabled) { + /// + /// Appends a button to the status bar of the panel. + /// + /// Path to the icon of the button. The file should contain a 64x24-pixel image composed of two 32x24 icons. The left icon is used when the button is inactive; the right icon is displayed when the button is pressed. + /// Text shown as a tooltip when user hovers the mouse over the button. + /// Whether the button is disabled. + //No Callback + return new chrome.Button; + }; + +}; + +//#endregion +//#region Chrome.ExtensionSidebarPane +chrome.ExtensionSidebarPane = function () { + this.setHeight = function (height) { + /// + /// Sets the height of the sidebar. + /// + /// A CSS-like size specification, such as '100px' or '12ex'. + //No Callback + }; + + this.setExpression = function (expression, rootTitle, callback) { + /// + /// Sets an expression that is evaluated within the inspected page. The result is displayed in the sidebar pane. + /// + /// An expression to be evaluated in context of the inspected page. JavaScript objects and DOM nodes are displayed in an expandable tree similar to the console/watch. + /// An optional title for the root of the expression tree. + /// A callback invoked after the sidebar pane is updated with the expression evaluation results. + callback(); + }; + + this.setObject = function (jsonObject, rootTitle, callback) { + /// + /// Sets a JSON-compliant object to be displayed in the sidebar pane. + /// + /// An object to be displayed in context of the inspected page. Evaluated in the context of the caller (API client). + /// An optional title for the root of the expression tree. + /// A callback invoked after the sidebar is updated with the object. + callback(); + }; + + this.setPage = function (path) { + /// + /// Sets an HTML page to be displayed in the sidebar pane. + /// + /// Relative path of an extension page to display within the sidebar. + //No Callback + }; + +}; + +//#endregion +//#region Chrome.ExternallyConnectable +chrome.ExternallyConnectable = function () { + ///

The IDs of extensions or apps that are allowed to connect. If left empty or unspecified, no extensions or apps can connect.

The wildcard "*" will allow all extensions and apps to connect.

+ ///

The URL patterns for web pages that are allowed to connect. This does not affect content scripts. If left empty or unspecified, no web pages can connect.

Patterns cannot include wildcard domains nor subdomains of (effective) top level domains; *://google.com/* and http://*.chromium.org/* are valid, while <all_urls>, http://*/*, *://*.com/*, and even http://*.appspot.com/* are not.

+ /// If true, messages sent via ref:runtime.connect or ref:runtime.sendMessage will set ref:runtime.MessageSender.tlsChannelId if those methods request it to be. If false, ref:runtime.MessageSender.tlsChannelId will never be set under any circumstance. + this.ids = {}; + this.matches = {}; + this.accepts_tls_channel_id = true; +}; + +//#endregion +//#region Chrome.FileEntryInfo +chrome.FileEntryInfo = function () { + /// + /// + /// + /// + this.fileSystemName = ""; + this.fileSystemRoot = ""; + this.fileFullPath = ""; + this.fileIsDirectory = true; +}; + +//#endregion +//#region Chrome.FileHandlerExecuteEventDetails +chrome.FileHandlerExecuteEventDetails = function () { + /// Array of Entry instances representing files that are targets of this action (selected in ChromeOS file browser). + /// The ID of the tab that raised this event. Tab IDs are unique within a browser session. + this.entries = {}; + this.tab_id = {}; +}; + +//#endregion +//#region Chrome.Filter +chrome.Filter = function () { + /// The maximum number of entries to be fetched in the requested list. Omit this parameter to fetch the maximum number of entries (ref:MAX_SESSION_RESULTS). + this.maxResults = {}; +}; + +//#endregion +//#region Chrome.FontName +chrome.FontName = function () { + /// The font ID. + /// The display name of the font. + this.fontId = ""; + this.displayName = ""; +}; + +//#endregion +//#region Chrome.GenericFamily +chrome.GenericFamily = function () { +}; + +//#endregion +//#region Chrome.GeolocationPermissionRequest +chrome.GeolocationPermissionRequest = function () { + /// The URL of the frame requesting access to geolocation data. + this.url = ""; + this.allow = function () { + /// + /// Allow the permission request. + /// + //No Callback + }; + + this.deny = function () { + /// + /// Deny the permission request. This is the default behavior if allow is not called. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.HeaderFilter +chrome.HeaderFilter = function () { + /// Matches if the header name starts with the specified string. + /// Matches if the header name ends with the specified string. + /// Matches if the header name contains all of the specified strings. + /// Matches if the header name is equal to the specified string. + /// Matches if the header value starts with the specified string. + /// Matches if the header value ends with the specified string. + /// Matches if the header value contains all of the specified strings. + /// Matches if the header value is equal to the specified string. + this.namePrefix = ""; + this.nameSuffix = ""; + this.nameContains = {}; + this.nameEquals = ""; + this.valuePrefix = ""; + this.valueSuffix = ""; + this.valueContains = {}; + this.valueEquals = ""; +}; + +//#endregion +//#region Chrome.HistoryItem +chrome.HistoryItem = function () { + /// The unique identifier for the item. + /// The URL navigated to by a user. + /// The title of the page when it was last loaded. + /// When this page was last loaded, represented in milliseconds since the epoch. + /// The number of times the user has navigated to this page. + /// The number of times the user has navigated to this page by typing in the address. + this.id = ""; + this.url = ""; + this.title = ""; + this.lastVisitTime = 0; + this.visitCount = {}; + this.typedCount = {}; +}; + +//#endregion +//#region Chrome.HttpHeaders +chrome.HttpHeaders = function () { +}; + +//#endregion +//#region Chrome.IconInfo +chrome.IconInfo = function () { + /// A number representing the width and height of the icon. Likely values include (but are not limited to) 128, 48, 24, and 16. + /// The URL for this icon image. To display a grayscale version of the icon (to indicate that an extension is disabled, for example), append ?grayscale=true to the URL. + this.size = {}; + this.url = ""; +}; + +//#endregion +//#region Chrome.ImageDataType +chrome.ImageDataType = function () { +}; + +//#endregion +//#region Chrome.ImageDataType +chrome.ImageDataType = function () { +}; + +//#endregion +//#region Chrome.ImageDetails +chrome.ImageDetails = function () { + /// The format of the resulting image. Default is "jpeg". + /// When format is "jpeg", controls the quality of the resulting image. This value is ignored for PNG images. As quality is decreased, the resulting image will have more visual artifacts, and the number of bytes needed to store it will decrease. + this.format = ""; + this.quality = {}; +}; + +//#endregion +//#region Chrome.InjectDetails +chrome.InjectDetails = function () { + /// JavaScript or CSS code to inject. + /// JavaScript or CSS file to inject. + /// If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's false and is only injected into the top frame. + /// The soonest that the JavaScript or CSS will be injected into the tab. Defaults to "document_idle". + this.code = ""; + this.file = ""; + this.allFrames = true; + this.runAt = ""; +}; + +//#endregion +//#region Chrome.InjectDetails +chrome.InjectDetails = function () { + /// JavaScript or CSS code to inject. + /// JavaScript or CSS file to inject. + this.code = ""; + this.file = ""; +}; + +//#endregion +//#region Chrome.InputContext +chrome.InputContext = function () { + /// This is used to specify targets of text field operations. This ID becomes invalid as soon as onBlur is called. + /// Type of value this text field edits, (Text, Number, URL, etc) + this.contextID = {}; + this.type = ""; +}; + +//#endregion +//#region Chrome.KeyboardEvent +chrome.KeyboardEvent = function () { + /// One of keyup or keydown. + /// The ID of the request. + /// Value of the key being pressed + /// Value of the physical key being pressed. The value is not affected by current keyboard layout or modifier state. + /// Whether or not the ALT key is pressed. + /// Whether or not the CTRL key is pressed. + /// Whether or not the SHIFT key is pressed. + /// Whether or not the CAPS_LOCK is enabled. + this.type = ""; + this.requestId = ""; + this.key = ""; + this.code = ""; + this.altKey = true; + this.ctrlKey = true; + this.shiftKey = true; + this.capsLock = true; +}; + +//#endregion +//#region Chrome.LevelOfControl +chrome.LevelOfControl = function () { +}; + +//#endregion +//#region Chrome.ListBoxDetails +chrome.ListBoxDetails = function () { + /// The value of the list box. + /// The number of items in the list. + /// The 0-based index of the selected value, or -1 if no items are selected. + this.value = ""; + this.itemCount = {}; + this.itemIndex = {}; +}; + +//#endregion +//#region Chrome.LoadPluginPermissionRequest +chrome.LoadPluginPermissionRequest = function () { + /// The plugin's identifier string. + /// The plugin's display name. + this.identifier = ""; + this.name = ""; + this.allow = function () { + /// + /// Allow the permission request. This is the default behavior if deny is not called.. + /// + //No Callback + }; + + this.deny = function () { + /// + /// Deny the permission request. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.MediaPermissionRequest +chrome.MediaPermissionRequest = function () { + /// The URL of the frame requesting access to user media. + this.url = ""; + this.allow = function () { + /// + /// Allow the permission request. + /// + //No Callback + }; + + this.deny = function () { + /// + /// Deny the permission request. This is the default behavior if allow is not called. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.MenuDetails +chrome.MenuDetails = function () { +}; + +//#endregion +//#region Chrome.MenuItem +chrome.MenuItem = function () { + /// String that will be passed to callbacks referencing this MenuItem. + /// Text displayed in the menu for this item. + /// Enum representing if this item is: check, radio, or a separator. Radio buttons between separators are considered grouped. + /// Indicates this item is visible. + /// Indicates this item should be drawn with a check. + /// Indicates this item is enabled. + this.id = ""; + this.label = ""; + this.style = ""; + this.visible = true; + this.checked = true; + this.enabled = true; +}; + +//#endregion +//#region Chrome.MenuItemDetails +chrome.MenuItemDetails = function () { + /// True if this item opens a submenu. + /// The number of items in the menu. + /// The 0-based index of this menu item. + this.hasSubmenu = true; + this.itemCount = {}; + this.itemIndex = {}; +}; + +//#endregion +//#region Chrome.MessageSender +chrome.MessageSender = function () { + /// The ref:tabs.Tab which opened the connection, if any. This property will only be present when the connection was opened from a tab (including content scripts), and only if the receiver is an extension, not an app. + /// The ID of the extension or app that opened the connection, if any. + /// The URL of the page or frame that opened the connection, if any. This property will only be present when the connection was opened from a tab or content script. + /// The TLS channel ID of the web page that opened the connection, if requested by the extension or app, and if available. + this.tab = {}; + this.id = ""; + this.url = ""; + this.tlsChannelId = ""; +}; + +//#endregion +//#region Chrome.MostVisitedURL +chrome.MostVisitedURL = function () { + /// The most visited URL. + /// The title of the page + this.url = ""; + this.title = ""; +}; + +//#endregion +//#region Chrome.NewWindow +chrome.NewWindow = function () { + this.attach = function (webview) { + /// + /// Attach the requested target page to an existing webview element. + /// + /// The webview element to which the target page should be attached. + //No Callback + }; + + this.discard = function () { + /// + /// Cancel the new window request. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.OnClickData +chrome.OnClickData = function () { + /// The ID of the menu item that was clicked. + /// The parent ID, if any, for the item clicked. + /// One of 'image', 'video', or 'audio' if the context menu was activated on one of these types of elements. + /// If the element is a link, the URL it points to. + /// Will be present for elements with a 'src' URL. + /// The URL of the page where the menu item was clicked. This property is not set if the click occured in a context where there is no current page, such as in a launcher context menu. + /// The URL of the frame of the element where the context menu was clicked, if it was in a frame. + /// The text for the context selection, if any. + /// A flag indicating whether the element is editable (text input, textarea, etc.). + /// A flag indicating the state of a checkbox or radio item before it was clicked. + /// A flag indicating the state of a checkbox or radio item after it is clicked. + this.menuItemId = {}; + this.parentMenuItemId = {}; + this.mediaType = ""; + this.linkUrl = ""; + this.srcUrl = ""; + this.pageUrl = ""; + this.frameUrl = ""; + this.selectionText = ""; + this.editable = true; + this.wasChecked = true; + this.checked = true; +}; + +//#endregion +//#region Chrome.PacScript +chrome.PacScript = function () { + /// URL of the PAC file to be used. + /// A PAC script. + /// If true, an invalid PAC script will prevent the network stack from falling back to direct connections. Defaults to false. + this.url = ""; + this.data = ""; + this.mandatory = true; +}; + +//#endregion +//#region Chrome.PageStateMatcher +chrome.PageStateMatcher = function () { + /// Matches if the condition of the UrlFilter are fulfilled for the top-level URL of the page. + /// Matches if all of the CSS selectors in the array match displayed elements in a frame with the same origin as the page's main frame. All selectors in this array must be compound selectors to speed up matching. Note that listing hundreds of CSS selectors or CSS selectors that match hundreds of times per page can still slow down web sites. + /// + this.pageUrl = {}; + this.css = {}; + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.Permissions +chrome.Permissions = function () { + /// List of named permissions (does not include hosts or origins). Anything listed here must appear in the optional_permissions list in the manifest. + /// List of origin permissions. Anything listed here must be a subset of a host that appears in the optional_permissions list in the manifest. For example, if http://*.example.com/ or http://*/ appears in optional_permissions, you can request an origin of http://help.example.com/. Any path is ignored. + this.permissions = {}; + this.origins = {}; +}; + +//#endregion +//#region Chrome.PointerLockPermissionRequest +chrome.PointerLockPermissionRequest = function () { + /// Whether or not pointer lock was requested as a result of a user input gesture. + /// Whether or not the requesting frame was the most recent client to hold pointer lock. + /// The URL of the frame requesting pointer lock. + this.userGesture = true; + this.lastUnlockedBySelf = true; + this.url = ""; + this.allow = function () { + /// + /// Allow the permission request. + /// + //No Callback + }; + + this.deny = function () { + /// + /// Deny the permission request. This is the default behavior if allow is not called. + /// + //No Callback + }; + +}; + +//#endregion +//#region Chrome.Port +chrome.Port = function () { + /// + /// + /// + /// + /// + /// This property will only be present on ports passed to onConnect/onConnectExternal listeners. + this.name = ""; + this.disconnect = function () { + /// not documented + } + this.onDisconnect = { + addListener: function (callback) { + /// + /// + callback(); + } + }; + + this.onMessage = { + addListener: function (callback) { + /// + /// + callback(); + } + }; + + this.postMessage = function () { + /// not documented + } + this.sender = {}; +}; + +//#endregion +//#region Chrome.Process +chrome.Process = function () { + /// Unique ID of the process provided by the browser. + /// The ID of the process, as provided by the OS. + /// The type of process. + /// The profile which the process is associated with. + /// Array of Tab IDs that have a page rendered by this process. The list will be non-empty for renderer processes only. + /// The most recent measurement of the process CPU usage, between 0 and 100%. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent measurement of the process network usage, in bytes per second. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent measurement of the process private memory usage, in bytes. Only available when receiving the object as part of a callback from onUpdatedWithMemory or getProcessInfo with the includeMemory flag. + /// The most recent measurement of the process JavaScript allocated memory, in bytes. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent measurement of the process JavaScript memory used, in bytes. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent measurement of the process’s SQLite memory usage, in bytes. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent measurement of the process frames per second. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent information about the image cache for the process. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent information about the script cache for the process. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + /// The most recent information about the CSS cache for the process. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory. + this.id = {}; + this.osProcessId = {}; + this.type = ""; + this.profile = ""; + this.tabs = {}; + this.cpu = 0; + this.network = 0; + this.privateMemory = 0; + this.jsMemoryAllocated = 0; + this.jsMemoryUsed = 0; + this.sqliteMemory = 0; + this.fps = 0; + this.imageCache = {}; + this.scriptCache = {}; + this.cssCache = {}; +}; + +//#endregion +//#region Chrome.ProxyConfig +chrome.ProxyConfig = function () { + /// The proxy rules describing this configuration. Use this for 'fixed_servers' mode. + /// The proxy auto-config (PAC) script for this configuration. Use this for 'pac_script' mode. + /// 'direct' = Never use a proxy
'auto_detect' = Auto detect proxy settings
'pac_script' = Use specified PAC script
'fixed_servers' = Manually specify proxy servers
'system' = Use system proxy settings
+ this.rules = {}; + this.pacScript = {}; + this.mode = ""; +}; + +//#endregion +//#region Chrome.ProxyRules +chrome.ProxyRules = function () { + /// The proxy server to be used for all per-URL requests (that is http, https, and ftp). + /// The proxy server to be used for HTTP requests. + /// The proxy server to be used for HTTPS requests. + /// The proxy server to be used for FTP requests. + /// The proxy server to be used for everthing else or if any of the specific proxyFor... is not specified. + /// List of servers to connect to without a proxy server. + this.singleProxy = {}; + this.proxyForHttp = {}; + this.proxyForHttps = {}; + this.proxyForFtp = {}; + this.fallbackProxy = {}; + this.bypassList = {}; +}; + +//#endregion +//#region Chrome.ProxyServer +chrome.ProxyServer = function () { + /// The scheme (protocol) of the proxy server itself. Defaults to 'http'. + /// The URI of the proxy server. This must be an ASCII hostname (in Punycode format). IDNA is not supported, yet. + /// The port of the proxy server. Defaults to a port that depends on the scheme. + this.scheme = ""; + this.host = ""; + this.port = {}; +}; + +//#endregion +//#region Chrome.RadioButtonDetails +chrome.RadioButtonDetails = function () { + /// True if this radio button is checked. + /// The number of radio buttons in this group. + /// The 0-based index of this radio button in this group. + this.isChecked = true; + this.itemCount = {}; + this.itemIndex = {}; +}; + +//#endregion +//#region Chrome.RedirectRequest +chrome.RedirectRequest = function () { + /// + /// Destination to where the request is redirected. + this.instanceType = ""; + this.redirectUrl = ""; +}; + +//#endregion +//#region Chrome.RemovalOptions +chrome.RemovalOptions = function () { + /// Remove data accumulated on or after this date, represented in milliseconds since the epoch (accessible via the getTime method of the JavaScript Date object). If absent, defaults to 0 (which would remove all browsing data). + /// An object whose properties specify which origin types ought to be cleared. If this object isn't specified, it defaults to clearing only "unprotected" origins. Please ensure that you really want to remove application data before adding 'protectedWeb' or 'extensions'. + this.since = 0; + this.originTypes = {}; +}; + +//#endregion +//#region Chrome.RemovalOptions +chrome.RemovalOptions = function () { + /// Remove data accumulated on or after this date, represented in milliseconds since the epoch (accessible via the getTime method of the JavaScript Date object). If absent, defaults to 0 (which would remove all browsing data). + this.since = 0; +}; + +//#endregion +//#region Chrome.RequestFilter +chrome.RequestFilter = function () { + /// A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out. + /// A list of request types. Requests that cannot match any of the types will be filtered out. + /// + /// + this.urls = {}; + this.types = {}; + this.tabId = {}; + this.windowId = {}; +}; + +//#endregion +//#region Chrome.RequestMatcher +chrome.RequestMatcher = function () { + /// Matches if the conditions of the UrlFilter are fulfilled for the URL of the request. + /// Matches if the conditions of the UrlFilter are fulfilled for the 'first party' URL of the request. The 'first party' URL of a request, when present, can be different from the request's target URL, and describes what is considered 'first party' for the sake of third-party checks for cookies. + /// Matches if the request type of a request is contained in the list. Requests that cannot match any of the types will be filtered out. + /// Matches if the MIME media type of a response (from the HTTP Content-Type header) is contained in the list. + /// Matches if the MIME media type of a response (from the HTTP Content-Type header) is not contained in the list. + /// Matches if some of the request headers is matched by one of the HeaderFilters. + /// Matches if none of the request headers is matched by any of the HeaderFilters. + /// Matches if some of the response headers is matched by one of the HeaderFilters. + /// Matches if none of the response headers is matched by any of the HeaderFilters. + /// If set to true, matches requests that are subject to third-party cookie policies. If set to false, matches all other requests. + /// Contains a list of strings describing stages. Allowed values are 'onBeforeRequest', 'onBeforeSendHeaders', 'onHeadersReceived', 'onAuthRequired'. If this attribute is present, then it limits the applicable stages to those listed. Note that the whole condition is only applicable in stages compatible with all attributes. + /// + this.url = {}; + this.firstPartyForCookiesUrl = {}; + this.resourceType = {}; + this.contentType = {}; + this.excludeContentType = {}; + this.requestHeaders = {}; + this.excludeRequestHeaders = {}; + this.responseHeaders = {}; + this.excludeResponseHeaders = {}; + this.thirdPartyForCookies = true; + this.stages = {}; + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.Resource +chrome.Resource = function () { + /// The URL of the resource. + this.url = ""; + this.getContent = function (callback) { + /// + /// Gets the content of the resource. + /// + /// A function that receives resource content when the request completes. + callback("", ""); + }; + + this.setContent = function (content, commit, callback) { + /// + /// Sets the content of the resource. + /// + /// New content of the resource. Only resources with the text type are currently supported. + /// True if the user has finished editing the resource, and the new content of the resource should be persisted; false if this is a minor change sent in progress of the user editing the resource. + /// A function called upon request completion. + callback({}); + }; + +}; + +//#endregion +//#region Chrome.ResourceIdentifier +chrome.ResourceIdentifier = function () { + /// The resource identifier for the given content type. + /// A human readable description of the resource. + this.id = ""; + this.description = ""; +}; + +//#endregion +//#region Chrome.Rule +chrome.Rule = function () { + /// Optional identifier that allows referencing this rule. + /// Tags can be used to annotate rules and perform operations on sets of rules. + /// List of conditions that can trigger the actions. + /// List of actions that are triggered if one of the condtions is fulfilled. + /// Optional priority of this rule. Defaults to 100. + this.id = ""; + this.tags = {}; + this.conditions = {}; + this.actions = {}; + this.priority = {}; +}; + +//#endregion +//#region Chrome.ScriptCode +chrome.ScriptCode = function () { +}; + +//#endregion +//#region Chrome.Session +chrome.Session = function () { + /// The time when the window or tab was closed or modified, represented in milliseconds since the epoch. + /// The ref:tabs.Tab, if this entry describes a tab. Either this or ref:Session.window will be set. + /// The ref:windows.Window, if this entry describes a window. Either this or ref:Session.tab will be set. + this.lastModified = {}; + this.tab = {}; + this.window = {}; +}; + +//#endregion +//#region Chrome.ShowPageAction +chrome.ShowPageAction = function () { + /// + this.instanceType = ""; +}; + +//#endregion +//#region Chrome.SliderDetails +chrome.SliderDetails = function () { + /// The value of the slider as a string. + this.stringValue = ""; +}; + +//#endregion +//#region Chrome.SocketHostPatterns +chrome.SocketHostPatterns = function () { +}; + +//#endregion +//#region Chrome.sockets +chrome.sockets = function () { + /// The udp manifest property declares which sockets.udp operations an app can issue. + /// The tcp manifest property declares which sockets.tcp operations an app can issue. + /// The tcpServer manifest property declares which sockets.tcpServer operations an app can issue. + this.udp = {}; + this.tcp = {}; + this.tcpServer = {}; +}; + +//#endregion +//#region Chrome.StorageArea +chrome.StorageArea = function () { + this.get = function (keys, callback) { + /// + /// Gets one or more items from storage. + /// + /// A single key to get, list of keys to get, or a dictionary specifying default values (see description of the object). An empty list or object will return an empty result object. Pass in null to get the entire contents of storage. + /// Callback with storage items, or on failure (in which case ref:runtime.lastError will be set). + callback({}); + }; + + this.getBytesInUse = function (keys, callback) { + /// + /// Gets the amount of space (in bytes) being used by one or more items. + /// + /// A single key or list of keys to get the total usage for. An empty list will return 0. Pass in null to get the total usage of all of storage. + /// Callback with the amount of space being used by storage, or on failure (in which case ref:runtime.lastError will be set). + callback({}); + }; + + this.set = function (items, callback) { + /// + /// Sets multiple items. + /// + ///

An object which gives each key/value pair to update storage with. Any other key/value pairs in storage will not be affected.

Primitive values such as numbers will serialize as expected. Values with a typeof "object" and "function" will typically serialize to {}, with the exception of Array (serializes as expected), Date, and Regex (serialize using their String representation).

+ /// Callback on success, or on failure (in which case ref:runtime.lastError will be set). + callback(); + }; + + this.remove = function (keys, callback) { + /// + /// Removes one or more items from storage. + /// + /// A single key or a list of keys for items to remove. + /// Callback on success, or on failure (in which case ref:runtime.lastError will be set). + callback(); + }; + + this.clear = function (callback) { + /// + /// Removes all items from storage. + /// + /// Callback on success, or on failure (in which case ref:runtime.lastError will be set). + callback(); + }; + +}; + +//#endregion +//#region Chrome.StorageChange +chrome.StorageChange = function () { + /// The old value of the item, if there was an old value. + /// The new value of the item, if there is a new value. + this.oldValue = {}; + this.newValue = {}; +}; + +//#endregion +//#region Chrome.SuggestResult +chrome.SuggestResult = function () { + /// The text that is put into the URL bar, and that is sent to the extension when the user chooses this entry. + /// The text that is displayed in the URL dropdown. Can contain XML-style markup for styling. The supported tags are 'url' (for a literal URL), 'match' (for highlighting text that matched what the user's query), and 'dim' (for dim helper text). The styles can be nested, eg. dimmed match. + /// An array of style ranges for the description, as provided by the extension. + /// An array of style ranges for the description, as provided by ToValue(). + this.content = ""; + this.description = ""; + this.descriptionStyles = {}; + this.descriptionStylesRaw = {}; +}; + +//#endregion +//#region Chrome.Tab +chrome.Tab = function () { + /// The ID of the tab. Tab IDs are unique within a browser session. Under some circumstances a Tab may not be assigned an ID, for example when querying foreign tabs using the ref:sessions API, in which case a session ID may be present. + /// The zero-based index of the tab within its window. + /// The ID of the window the tab is contained within. + /// The ID of the tab that opened this tab, if any. This property is only present if the opener tab still exists. + /// Whether the tab is selected. + /// Whether the tab is highlighted. + /// Whether the tab is active in its window. (Does not necessarily mean the window is focused.) + /// Whether the tab is pinned. + /// The URL the tab is displaying. This property is only present if the extension's manifest includes the "tabs" permission. + /// The title of the tab. This property is only present if the extension's manifest includes the "tabs" permission. + /// The URL of the tab's favicon. This property is only present if the extension's manifest includes the "tabs" permission. It may also be an empty string if the tab is loading. + /// Either loading or complete. + /// Whether the tab is in an incognito window. + /// The width of the tab in pixels. + /// The height of the tab in pixels. + /// The session ID used to uniquely identify a Tab obtained from the ref:sessions API. + this.id = {}; + this.index = {}; + this.windowId = {}; + this.openerTabId = {}; + this.selected = true; + this.highlighted = true; + this.active = true; + this.pinned = true; + this.url = ""; + this.title = ""; + this.favIconUrl = ""; + this.status = ""; + this.incognito = true; + this.width = {}; + this.height = {}; + this.sessionId = ""; +}; + +//#endregion +//#region Chrome.TabDetails +chrome.TabDetails = function () { + /// The number of tabs in this group. + /// The 0-based index of this tab in this group. + this.itemCount = {}; + this.itemIndex = {}; +}; + +//#endregion +//#region Chrome.TargetInfo +chrome.TargetInfo = function () { + /// Target type. + /// Target id. + /// The tab id, defined if type == 'page'. + /// The extension id, defined if type = 'background_page'. + /// True if debugger is already attached. + /// Target page title. + /// Target URL. + /// Target favicon URL. + this.type = ""; + this.id = ""; + this.tabId = {}; + this.extensionId = ""; + this.attached = true; + this.title = ""; + this.url = ""; + this.faviconUrl = ""; +}; + +//#endregion +//#region Chrome.TextBoxDetails +chrome.TextBoxDetails = function () { + /// The value of the text box - the entered text. + /// True if this control contains password text whose contents should be obscured. + /// The index of the character where the selection starts, if this control contains editable text. + /// The index of the character where the selection ends, if this control contains editable text. + this.value = ""; + this.isPassword = true; + this.selectionStart = {}; + this.selectionEnd = {}; +}; + +//#endregion +//#region Chrome.TreeDetails +chrome.TreeDetails = function () { +}; + +//#endregion +//#region Chrome.TreeItemDetails +chrome.TreeItemDetails = function () { + /// The 0-based depth of this tree item. + /// The number of items in the current depth. + /// The 0-based index of this tree item at the current tree depth. + /// The number of children of the current tree item. + /// True if this if this tree item is expanded. + this.itemDepth = {}; + this.itemCount = {}; + this.itemIndex = {}; + this.childrenCount = {}; + this.isItemExpanded = true; +}; + +//#endregion +//#region Chrome.TtsEvent +chrome.TtsEvent = function () { + /// The type can be 'start' as soon as speech has started, 'word' when a word boundary is reached, 'sentence' when a sentence boundary is reached, 'marker' when an SSML mark element is reached, 'end' when the end of the utterance is reached, 'interrupted' when the utterance is stopped or interrupted before reaching the end, 'cancelled' when it's removed from the queue before ever being synthesized, or 'error' when any other error occurs. When pausing speech, a 'pause' event is fired if a particular utterance is paused in the middle, and 'resume' if an utterance resumes speech. Note that pause and resume events may not fire if speech is paused in-between utterances. + /// The index of the current character in the utterance. + /// The error description, if the event type is 'error'. + /// An ID unique to the calling function's context so that events can get routed back to the correct tts.speak call. + /// True if this is the final event that will be sent to this handler. + this.type = ""; + this.charIndex = 0; + this.errorMessage = ""; + this.srcId = 0; + this.isFinalEvent = true; +}; + +//#endregion +//#region Chrome.TtsVoice +chrome.TtsVoice = function () { + /// The name of the voice. + /// The language that this voice supports, in the form language-region. Examples: 'en', 'en-US', 'en-GB', 'zh-CN'. + /// This voice's gender. + /// If true, the synthesis engine is a remote network resource. It may be higher latency and may incur bandwidth costs. + /// The ID of the extension providing this voice. + /// All of the callback event types that this voice is capable of sending. + this.voiceName = ""; + this.lang = ""; + this.gender = ""; + this.remote = true; + this.extensionId = ""; + this.eventTypes = {}; +}; + +//#endregion +//#region Chrome.UploadData +chrome.UploadData = function () { + /// An ArrayBuffer with a copy of the data. + /// A string with the file's path and name. + this.bytes = {}; + this.file = ""; +}; + +//#endregion +//#region Chrome.UrlFilter +chrome.UrlFilter = function () { + /// Matches if the host name of the URL contains a specified string. To test whether a host name component has a prefix 'foo', use hostContains: '.foo'. This matches 'www.foobar.com' and 'foo.com', because an implicit dot is added at the beginning of the host name. Similarly, hostContains can be used to match against component suffix ('foo.') and to exactly match against components ('.foo.'). Suffix- and exact-matching for the last components need to be done separately using hostSuffix, because no implicit dot is added at the end of the host name. + /// Matches if the host name of the URL is equal to a specified string. + /// Matches if the host name of the URL starts with a specified string. + /// Matches if the host name of the URL ends with a specified string. + /// Matches if the path segment of the URL contains a specified string. + /// Matches if the path segment of the URL is equal to a specified string. + /// Matches if the path segment of the URL starts with a specified string. + /// Matches if the path segment of the URL ends with a specified string. + /// Matches if the query segment of the URL contains a specified string. + /// Matches if the query segment of the URL is equal to a specified string. + /// Matches if the query segment of the URL starts with a specified string. + /// Matches if the query segment of the URL ends with a specified string. + /// Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number. + /// Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number. + /// Matches if the URL (without fragment identifier) matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the RE2 syntax. + /// Matches if the URL without query segment and fragment identifier matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the RE2 syntax. + /// Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number. + /// Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number. + /// Matches if the scheme of the URL is equal to any of the schemes specified in the array. + /// Matches if the port of the URL is contained in any of the specified port lists. For example [80, 443, [1000, 1200]] matches all requests on port 80, 443 and in the range 1000-1200. + this.hostContains = ""; + this.hostEquals = ""; + this.hostPrefix = ""; + this.hostSuffix = ""; + this.pathContains = ""; + this.pathEquals = ""; + this.pathPrefix = ""; + this.pathSuffix = ""; + this.queryContains = ""; + this.queryEquals = ""; + this.queryPrefix = ""; + this.querySuffix = ""; + this.urlContains = ""; + this.urlEquals = ""; + this.urlMatches = ""; + this.originAndPathMatches = ""; + this.urlPrefix = ""; + this.urlSuffix = ""; + this.schemes = {}; + this.ports = {}; +}; + +//#endregion +//#region Chrome.VisitItem +chrome.VisitItem = function () { + /// The unique identifier for the item. + /// The unique identifier for this visit. + /// When this visit occurred, represented in milliseconds since the epoch. + /// The visit ID of the referrer. + /// The transition type for this visit from its referrer. + this.id = ""; + this.visitId = ""; + this.visitTime = 0; + this.referringVisitId = ""; + this.transition = ""; +}; + +//#endregion +//#region Chrome.WebRequestEventInteface +chrome.WebRequestEventInteface = function () { +}; + +//#endregion +//#region Chrome.Window +chrome.Window = function () { + /// The ID of the window. Window IDs are unique within a browser session. Under some circumstances a Window may not be assigned an ID, for example when querying windows using the ref:sessions API, in which case a session ID may be present. + /// Whether the window is currently the focused window. + /// The offset of the window from the top edge of the screen in pixels. Under some circumstances a Window may not be assigned top property, for example when querying closed windows from the ref:sessions API. + /// The offset of the window from the left edge of the screen in pixels. Under some circumstances a Window may not be assigned left property, for example when querying closed windows from the ref:sessions API. + /// The width of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned width property, for example when querying closed windows from the ref:sessions API. + /// The height of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned height property, for example when querying closed windows from the ref:sessions API. + /// Array of ref:tabs.Tab objects representing the current tabs in the window. + /// Whether the window is incognito. + /// The type of browser window this is. Under some circumstances a Window may not be assigned type property, for example when querying closed windows from the ref:sessions API. + /// The state of this browser window. Under some circumstances a Window may not be assigned state property, for example when querying closed windows from the ref:sessions API. + /// Whether the window is set to be always on top. + /// The session ID used to uniquely identify a Window obtained from the ref:sessions API. + this.id = {}; + this.focused = true; + this.top = {}; + this.left = {}; + this.width = {}; + this.height = {}; + this.tabs = {}; + this.incognito = true; + this.type = ""; + this.state = ""; + this.alwaysOnTop = true; + this.sessionId = ""; +}; + +//#endregion +//#endregion +//#region Chrome.app +chrome.app = {}; +chrome.app.getIsInstalled = function () { + /// + /// TODO + /// + //No Callback + return true; +}; + +chrome.app.installState = function (callback) { + /// + /// TODO + /// + /// + callback(""); +}; + +chrome.app.runningState = function () { + /// + /// TODO + /// + //No Callback + return ""; +}; + +chrome.app.getDetails = function () { + /// + /// TODO + /// + //No Callback + return new chrome.Details; +}; + +chrome.app.getDetailsForFrame = function (frame) { + /// + /// TODO + /// + /// TODO + //No Callback + return new chrome.Details; +}; + +//#endregion +//#region Chrome.bookmarks +chrome.bookmarks = {}; +chrome.bookmarks.get = function (idOrIdList, callback) { + /// + /// Retrieves the specified BookmarkTreeNode(s). + /// + /// A single string-valued id, or an array of string-valued ids + /// + callback({}); +}; + +chrome.bookmarks.getChildren = function (id, callback) { + /// + /// Retrieves the children of the specified BookmarkTreeNode id. + /// + /// + /// + callback({}); +}; + +chrome.bookmarks.getRecent = function (numberOfItems, callback) { + /// + /// Retrieves the recently added bookmarks. + /// + /// The maximum number of items to return. + /// + callback({}); +}; + +chrome.bookmarks.getTree = function (callback) { + /// + /// Retrieves the entire Bookmarks hierarchy. + /// + /// + callback({}); +}; + +chrome.bookmarks.getSubTree = function (id, callback) { + /// + /// Retrieves part of the Bookmarks hierarchy, starting at the specified node. + /// + /// The ID of the root of the subtree to retrieve. + /// + callback({}); +}; + +chrome.bookmarks.search = function (query, callback) { + /// + /// Searches for BookmarkTreeNodes matching the given query. Queries specified with an object produce BookmarkTreeNodes matching all specified properties. + /// + /// + /// + callback({}); +}; + +chrome.bookmarks.create = function (bookmark, callback) { + /// + /// Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it will be a folder. + /// + /// + /// + callback(new chrome.BookmarkTreeNode()); +}; + +chrome.bookmarks.move = function (id, destination, callback) { + /// + /// Moves the specified BookmarkTreeNode to the provided location. + /// + /// + /// + /// + callback(new chrome.BookmarkTreeNode()); +}; + +chrome.bookmarks.update = function (id, changes, callback) { + /// + /// Updates the properties of a bookmark or folder. Specify only the properties that you want to change; unspecified properties will be left unchanged. Note: Currently, only 'title' and 'url' are supported. + /// + /// + /// + /// + callback(new chrome.BookmarkTreeNode()); +}; + +chrome.bookmarks.remove = function (id, callback) { + /// + /// Removes a bookmark or an empty bookmark folder. + /// + /// + /// + callback(); +}; + +chrome.bookmarks.removeTree = function (id, callback) { + /// + /// Recursively removes a bookmark folder. + /// + /// + /// + callback(); +}; + +chrome.bookmarks.import = function (callback) { + /// + /// Imports bookmarks from a chrome html bookmark file + /// + /// + callback(); +}; + +chrome.bookmarks.export = function (callback) { + /// + /// Exports bookmarks to a chrome html bookmark file + /// + /// + callback(); +}; + +//#region Chrome.bookmarks Events +chrome.bookmarks.onCreated = { + addListener: function (callback) { + /// + /// Fired when a bookmark or folder is created. + /// + callback("", new chrome.BookmarkTreeNode()); + } +}; + +chrome.bookmarks.onRemoved = { + addListener: function (callback) { + /// + /// Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents. + /// + callback("", {}); + } +}; + +chrome.bookmarks.onChanged = { + addListener: function (callback) { + /// + /// Fired when a bookmark or folder changes. Note: Currently, only title and url changes trigger this. + /// + callback("", {}); + } +}; + +chrome.bookmarks.onMoved = { + addListener: function (callback) { + /// + /// Fired when a bookmark or folder is moved to a different parent folder. + /// + callback("", {}); + } +}; + +chrome.bookmarks.onChildrenReordered = { + addListener: function (callback) { + /// + /// Fired when the children of a folder have changed their order due to the order being sorted in the UI. This is not called as a result of a move(). + /// + callback("", {}); + } +}; + +chrome.bookmarks.onImportBegan = { + addListener: function (callback) { + /// + /// Fired when a bookmark import session is begun. Expensive observers should ignore onCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately. + /// + callback(); + } +}; + +chrome.bookmarks.onImportEnded = { + addListener: function (callback) { + /// + /// Fired when a bookmark import session is ended. + /// + callback(); + } +}; + +//#endregion +//#endregion +//#region Chrome.browserAction +chrome.browserAction = {}; +chrome.browserAction.setTitle = function (details) { + /// + /// Sets the title of the browser action. This shows up in the tooltip. + /// + /// + //No Callback +}; + +chrome.browserAction.getTitle = function (details, callback) { + /// + /// Gets the title of the browser action. + /// + /// + /// + callback(""); +}; + +chrome.browserAction.setIcon = function (details, callback) { + /// + /// Sets the icon for the browser action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the path or the imageData property must be specified. + /// + /// + /// + callback(); +}; + +chrome.browserAction.setPopup = function (details) { + /// + /// Sets the html document to be opened as a popup when the user clicks on the browser action's icon. + /// + /// + //No Callback +}; + +chrome.browserAction.getPopup = function (details, callback) { + /// + /// Gets the html document set as the popup for this browser action. + /// + /// + /// + callback(""); +}; + +chrome.browserAction.setBadgeText = function (details) { + /// + /// Sets the badge text for the browser action. The badge is displayed on top of the icon. + /// + /// + //No Callback +}; + +chrome.browserAction.getBadgeText = function (details, callback) { + /// + /// Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned. + /// + /// + /// + callback(""); +}; + +chrome.browserAction.setBadgeBackgroundColor = function (details) { + /// + /// Sets the background color for the badge. + /// + /// + //No Callback +}; + +chrome.browserAction.getBadgeBackgroundColor = function (details, callback) { + /// + /// Gets the background color of the browser action. + /// + /// + /// + callback(new chrome.ColorArray()); +}; + +chrome.browserAction.enable = function (tabId) { + /// + /// Enables the browser action for a tab. By default, browser actions are enabled. + /// + /// The id of the tab for which you want to modify the browser action. + //No Callback +}; + +chrome.browserAction.disable = function (tabId) { + /// + /// Disables the browser action for a tab. + /// + /// The id of the tab for which you want to modify the browser action. + //No Callback +}; + +chrome.browserAction.openPopup = function (callback) { + /// + /// Opens the extension popup window in the active window but does not grant tab permissions. + /// + /// + callback({}); +}; + +//#region Chrome.browserAction Events +chrome.browserAction.onClicked = { + addListener: function (callback) { + /// + /// Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup. + /// + callback(new chrome.tabs.Tab()); + } +}; + +//#endregion +//#endregion +//#region Chrome.browsingData +chrome.browsingData = {}; +chrome.browsingData.settings = function (callback) { + /// + /// Reports which types of data are currently selected in the 'Clear browsing data' settings UI. Note: some of the data types included in this API are not available in the settings UI, and some UI settings control more than one data type listed here. + /// + /// + callback({}); +}; + +chrome.browsingData.remove = function (options, dataToRemove, callback) { + /// + /// Clears various types of browsing data stored in a user's profile. + /// + /// + /// The set of data types to remove. + /// Called when deletion has completed. + callback(); +}; + +chrome.browsingData.removeAppcache = function (options, callback) { + /// + /// Clears websites' appcache data. + /// + /// + /// Called when websites' appcache data has been cleared. + callback(); +}; + +chrome.browsingData.removeCache = function (options, callback) { + /// + /// Clears the browser's cache. + /// + /// + /// Called when the browser's cache has been cleared. + callback(); +}; + +chrome.browsingData.removeCookies = function (options, callback) { + /// + /// Clears the browser's cookies and server-bound certificates modified within a particular timeframe. + /// + /// + /// Called when the browser's cookies and server-bound certificates have been cleared. + callback(); +}; + +chrome.browsingData.removeDownloads = function (options, callback) { + /// + /// Clears the browser's list of downloaded files (not the downloaded files themselves). + /// + /// + /// Called when the browser's list of downloaded files has been cleared. + callback(); +}; + +chrome.browsingData.removeFileSystems = function (options, callback) { + /// + /// Clears websites' file system data. + /// + /// + /// Called when websites' file systems have been cleared. + callback(); +}; + +chrome.browsingData.removeFormData = function (options, callback) { + /// + /// Clears the browser's stored form data (autofill). + /// + /// + /// Called when the browser's form data has been cleared. + callback(); +}; + +chrome.browsingData.removeHistory = function (options, callback) { + /// + /// Clears the browser's history. + /// + /// + /// Called when the browser's history has cleared. + callback(); +}; + +chrome.browsingData.removeIndexedDB = function (options, callback) { + /// + /// Clears websites' IndexedDB data. + /// + /// + /// Called when websites' IndexedDB data has been cleared. + callback(); +}; + +chrome.browsingData.removeLocalStorage = function (options, callback) { + /// + /// Clears websites' local storage data. + /// + /// + /// Called when websites' local storage has been cleared. + callback(); +}; + +chrome.browsingData.removePluginData = function (options, callback) { + /// + /// Clears plugins' data. + /// + /// + /// Called when plugins' data has been cleared. + callback(); +}; + +chrome.browsingData.removePasswords = function (options, callback) { + /// + /// Clears the browser's stored passwords. + /// + /// + /// Called when the browser's passwords have been cleared. + callback(); +}; + +chrome.browsingData.removeWebSQL = function (options, callback) { + /// + /// Clears websites' WebSQL data. + /// + /// + /// Called when websites' WebSQL databases have been cleared. + callback(); +}; + +//#endregion +//#region Chrome.commands +chrome.commands = {}; +chrome.commands.getAll = function (callback) { + /// + /// Returns all the registered extension commands for this extension and their shortcut (if active). + /// + /// Called to return the registered commands. + callback({}); +}; + +//#region Chrome.commands Events +chrome.commands.onCommand = { + addListener: function (callback) { + /// + /// Fired when a registered command is activated using a keyboard shortcut. + /// + callback(""); + } +}; + +//#endregion +//#endregion +//#region Chrome.contentSettings +chrome.contentSettings = {}; +//#endregion +//#region Chrome.contextMenus +chrome.contextMenus = {}; +chrome.contextMenus.create = function (createProperties, callback) { + /// + /// Creates a new context menu item. Note that if an error occurs during creation, you may not find out until the creation callback fires (the details will be in chrome.runtime.lastError). + /// + /// + /// Called when the item has been created in the browser. If there were any problems creating the item, details will be available in chrome.runtime.lastError. + callback(); + return {}; +}; + +chrome.contextMenus.update = function (id, updateProperties, callback) { + /// + /// Updates a previously created context menu item. + /// + /// The ID of the item to update. + /// The properties to update. Accepts the same values as the create function. + /// Called when the context menu has been updated. + callback(); +}; + +chrome.contextMenus.remove = function (menuItemId, callback) { + /// + /// Removes a context menu item. + /// + /// The ID of the context menu item to remove. + /// Called when the context menu has been removed. + callback(); +}; + +chrome.contextMenus.removeAll = function (callback) { + /// + /// Removes all context menu items added by this extension. + /// + /// Called when removal is complete. + callback(); +}; + +//#region Chrome.contextMenus Events +chrome.contextMenus.onClicked = { + addListener: function (callback) { + /// + /// Fired when a context menu item is clicked. + /// + callback(new chrome.OnClickData(), new chrome.tabs.Tab()); + } +}; + +//#endregion +//#endregion +//#region Chrome.cookies +chrome.cookies = {}; +chrome.cookies.get = function (details, callback) { + /// + /// Retrieves information about a single cookie. If more than one cookie of the same name exists for the given URL, the one with the longest path will be returned. For cookies with the same path length, the cookie with the earliest creation time will be returned. + /// + /// Details to identify the cookie being retrieved. + /// + callback(new chrome.Cookie()); +}; + +chrome.cookies.getAll = function (details, callback) { + /// + /// Retrieves all cookies from a single cookie store that match the given information. The cookies returned will be sorted, with those with the longest path first. If multiple cookies have the same path length, those with the earliest creation time will be first. + /// + /// Information to filter the cookies being retrieved. + /// + callback({}); +}; + +chrome.cookies.set = function (details, callback) { + /// + /// Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist. + /// + /// Details about the cookie being set. + /// + callback(new chrome.Cookie()); +}; + +chrome.cookies.remove = function (details, callback) { + /// + /// Deletes a cookie by name. + /// + /// Information to identify the cookie to remove. + /// + callback({}); +}; + +chrome.cookies.getAllCookieStores = function (callback) { + /// + /// Lists all existing cookie stores. + /// + /// + callback({}); +}; + +//#region Chrome.cookies Events +chrome.cookies.onChanged = { + addListener: function (callback) { + /// + /// Fired when a cookie is set or removed. As a special case, note that updating a cookie's properties is implemented as a two step process: the cookie to be updated is first removed entirely, generating a notification with "cause" of "overwrite" . Afterwards, a new cookie is written with the updated values, generating a second notification with "cause" "explicit". + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.debugger +chrome.debugger = {}; +chrome.debugger.attach = function (target, requiredVersion, callback) { + /// + /// Attaches debugger to the given target. + /// + /// Debugging target to which you want to attach. + /// Required debugging protocol version ("0.1"). One can only attach to the debuggee with matching major version and greater or equal minor version. List of the protocol versions can be obtained here. + /// Called once the attach operation succeeds or fails. Callback receives no arguments. If the attach fails, ref:runtime.lastError will be set to the error message. + callback(); +}; + +chrome.debugger.detach = function (target, callback) { + /// + /// Detaches debugger from the given target. + /// + /// Debugging target from which you want to detach. + /// Called once the detach operation succeeds or fails. Callback receives no arguments. If the detach fails, ref:runtime.lastError will be set to the error message. + callback(); +}; + +chrome.debugger.sendCommand = function (target, method, commandParams, callback) { + /// + /// Sends given command to the debugging target. + /// + /// Debugging target to which you want to send the command. + /// Method name. Should be one of the methods defined by the remote debugging protocol. + /// JSON object with request parameters. This object must conform to the remote debugging params scheme for given method. + /// Response body. If an error occurs while posting the message, the callback will be called with no arguments and ref:runtime.lastError will be set to the error message. + callback({}); +}; + +chrome.debugger.getTargets = function (callback) { + /// + /// Returns the list of available debug targets. + /// + /// + callback({}); +}; + +//#region Chrome.debugger Events +chrome.debugger.onEvent = { + addListener: function (callback) { + /// + /// Fired whenever debugging target issues instrumentation event. + /// + callback(new chrome.Debuggee(), "", {}); + } +}; + +chrome.debugger.onDetach = { + addListener: function (callback) { + /// + /// Fired when browser terminates debugging session for the tab. This happens when either the tab is being closed or Chrome DevTools is being invoked for the attached tab. + /// + callback(new chrome.Debuggee(), ""); + } +}; + +//#endregion +//#endregion +//#region Chrome.declarativeContent +chrome.declarativeContent = {}; +//#region Chrome.declarativeContent Events +chrome.declarativeContent.onPageChanged = { + addListener: function (callback) { + /// + /// + callback(); + } +}; + +//#endregion +//#endregion +//#region Chrome.declarativeWebRequest +chrome.declarativeWebRequest = {}; +//#region Chrome.declarativeWebRequest Events +chrome.declarativeWebRequest.onRequest = { + addListener: function (callback) { + /// + /// + callback(); + } +}; + +chrome.declarativeWebRequest.onMessage = { + addListener: function (callback) { + /// + /// Fired when a message is sent via ref:declarativeWebRequest.SendMessageToExtension from an action of the declarative web request API. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.desktopCapture +chrome.desktopCapture = {}; +chrome.desktopCapture.chooseDesktopMedia = function (sources, targetTab, callback) { + /// + /// Shows desktop media picker UI with the specified set of sources. + /// + /// Set of sources that should be shown to the user. + /// Optional tab for which the stream is created. If not specified then the resulting stream can be used only by the calling extension, otherwise the stream can be used only by the specified tab. If the tab's security origin changes before this function returns, the call may fail. + /// + callback(""); + return {}; +}; + +chrome.desktopCapture.cancelChooseDesktopMedia = function (desktopMediaRequestId) { + /// + /// Hides desktop media picker dialog shown by chooseDesktopMedia(). + /// + /// Id returned by chooseDesktopMedia() + //No Callback +}; + +//#endregion +//#region Chrome.events +chrome.events = {}; +//#endregion +//#region Chrome.experimental.accessibility +chrome.experimental.accessibility = {}; +chrome.experimental.accessibility.setAccessibilityEnabled = function (enabled) { + /// + /// Enables or disables the accessibility extension api. This must be set to true before event listeners or getFocusedControl will work. + /// + /// True if accessibility support should be enabled. + //No Callback +}; + +chrome.experimental.accessibility.setNativeAccessibilityEnabled = function (enabled) { + /// + /// Enables or disables native accessibility support. Once disabled, it is up to the calling extension to provide accessibility for web contents. + /// + /// True if native accessibility support should be enabled. + //No Callback +}; + +chrome.experimental.accessibility.getFocusedControl = function (callback) { + /// + /// Gets information about the currently focused control. + /// + /// + callback(new chrome.AccessibilityObject()); +}; + +chrome.experimental.accessibility.getAlertsForTab = function (tabId, callback) { + /// + /// Gets alerts being shown on the given tab. + /// + /// + /// + callback({}); +}; + +//#region Chrome.experimental.accessibility Events +chrome.experimental.accessibility.onWindowOpened = { + addListener: function (callback) { + /// + /// Fired when a window is opened. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onWindowClosed = { + addListener: function (callback) { + /// + /// Fired when a window is closed. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onControlFocused = { + addListener: function (callback) { + /// + /// Fired when a control is focused. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onControlAction = { + addListener: function (callback) { + /// + /// Fired when a control's action is taken, like pressing a button or toggling a checkbox. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onTextChanged = { + addListener: function (callback) { + /// + /// Fired when text changes in an editable text control. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onMenuOpened = { + addListener: function (callback) { + /// + /// Fired when a menu is opened. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onMenuClosed = { + addListener: function (callback) { + /// + /// Fired when a menu is closed. + /// + callback(new chrome.AccessibilityObject()); + } +}; + +chrome.experimental.accessibility.onChromeVoxLoadStateChanged = { + addListener: function (callback) { + /// + /// Fired ChromeVox load state changes. + /// + callback(true, true); + } +}; + +//#endregion +//#endregion +//#region Chrome.extension +chrome.extension = {}; +chrome.extension.sendRequest = function (extensionId, request, responseCallback) { + /// + /// Sends a single request to other listeners within the extension. Similar to ref:runtime.connect, but only sends a single request with an optional response. The ref:onRequest event is fired in each page of the extension. + /// + /// The extension ID of the extension you want to connect to. If omitted, default is your own extension. + /// + /// + //No Callback +}; + +chrome.extension.getURL = function (path) { + /// + /// Converts a relative path within an extension install directory to a fully-qualified URL. + /// + /// A path to a resource within an extension expressed relative to its install directory. + //No Callback + return ""; +}; + +chrome.extension.getViews = function (fetchProperties) { + /// + /// Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension. + /// + /// + //No Callback + return {}; +}; + +chrome.extension.getBackgroundPage = function () { + /// + /// Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page. + /// + //No Callback + return {}; +}; + +chrome.extension.getExtensionTabs = function (windowId) { + /// + /// Returns an array of the JavaScript 'window' objects for each of the tabs running inside the current extension. If windowId is specified, returns only the 'window' objects of tabs attached to the specified window. + /// + /// + //No Callback + return {}; +}; + +chrome.extension.isAllowedIncognitoAccess = function (callback) { + /// + /// Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox. + /// + /// + callback({}); +}; + +chrome.extension.isAllowedFileSchemeAccess = function (callback) { + /// + /// Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox. + /// + /// + callback({}); +}; + +chrome.extension.setUpdateUrlData = function (data) { + /// + /// Sets the value of the ap CGI parameter used in the extension's update URL. This value is ignored for extensions that are hosted in the Chrome Extension Gallery. + /// + /// + //No Callback +}; + +//#region Chrome.extension Events +chrome.extension.onRequest = { + addListener: function (callback) { + /// + /// Fired when a request is sent from either an extension process or a content script. + /// + callback({}, new chrome.runtime.MessageSender(), {}); + } +}; + +chrome.extension.onRequestExternal = { + addListener: function (callback) { + /// + /// Fired when a request is sent from another extension. + /// + callback({}, new chrome.runtime.MessageSender(), {}); + } +}; + +//#endregion +//#endregion +//#region Chrome.fileBrowserHandler +chrome.fileBrowserHandler = {}; +chrome.fileBrowserHandler.selectFile = function (selectionParams, callback) { + /// + /// Prompts user to select file path under which file should be saved. When the file is selected, file access permission required to use the file (read, write and create) are granted to the caller. The file will not actually get created during the function call, so function caller must ensure its existence before using it. The function has to be invoked with a user gesture. + /// + /// Parameters that will be used while selecting the file. + /// Function called upon completion. + callback({}); +}; + +//#region Chrome.fileBrowserHandler Events +chrome.fileBrowserHandler.onExecute = { + addListener: function (callback) { + /// + /// Fired when file system action is executed from ChromeOS file browser. + /// + callback("", new chrome.FileHandlerExecuteEventDetails()); + } +}; + +//#endregion +//#endregion +//#region Chrome.fileBrowserHandlerInternal +chrome.fileBrowserHandlerInternal = {}; +chrome.fileBrowserHandlerInternal.selectFile = function (selectionParams, callback) { + /// + /// Prompts user to select file path under which a new file will be created. If the user selects file, the file gets created or, if it already exists, truncated. The function has to be called with user gesture. + /// + /// Parameters that will be used to create new file. + /// Function called upon completion. + callback({}); +}; + +//#endregion +//#region Chrome.fontSettings +chrome.fontSettings = {}; +chrome.fontSettings.clearFont = function (details, callback) { + /// + /// Clears the font set by this extension, if any. + /// + /// + /// + callback(); +}; + +chrome.fontSettings.getFont = function (details, callback) { + /// + /// Gets the font for a given script and generic font family. + /// + /// + /// + callback({}); +}; + +chrome.fontSettings.setFont = function (details, callback) { + /// + /// Sets the font for a given script and generic font family. + /// + /// + /// + callback(); +}; + +chrome.fontSettings.getFontList = function (callback) { + /// + /// Gets a list of fonts on the system. + /// + /// + callback({}); +}; + +chrome.fontSettings.clearDefaultFontSize = function (details, callback) { + /// + /// Clears the default font size set by this extension, if any. + /// + /// This parameter is currently unused. + /// + callback(); +}; + +chrome.fontSettings.getDefaultFontSize = function (details, callback) { + /// + /// Gets the default font size. + /// + /// This parameter is currently unused. + /// + callback({}); +}; + +chrome.fontSettings.setDefaultFontSize = function (details, callback) { + /// + /// Sets the default font size. + /// + /// + /// + callback(); +}; + +chrome.fontSettings.clearDefaultFixedFontSize = function (details, callback) { + /// + /// Clears the default fixed font size set by this extension, if any. + /// + /// This parameter is currently unused. + /// + callback(); +}; + +chrome.fontSettings.getDefaultFixedFontSize = function (details, callback) { + /// + /// Gets the default size for fixed width fonts. + /// + /// This parameter is currently unused. + /// + callback({}); +}; + +chrome.fontSettings.setDefaultFixedFontSize = function (details, callback) { + /// + /// Sets the default size for fixed width fonts. + /// + /// + /// + callback(); +}; + +chrome.fontSettings.clearMinimumFontSize = function (details, callback) { + /// + /// Clears the minimum font size set by this extension, if any. + /// + /// This parameter is currently unused. + /// + callback(); +}; + +chrome.fontSettings.getMinimumFontSize = function (details, callback) { + /// + /// Gets the minimum font size. + /// + /// This parameter is currently unused. + /// + callback({}); +}; + +chrome.fontSettings.setMinimumFontSize = function (details, callback) { + /// + /// Sets the minimum font size. + /// + /// + /// + callback(); +}; + +//#region Chrome.fontSettings Events +chrome.fontSettings.onFontChanged = { + addListener: function (callback) { + /// + /// Fired when a font setting changes. + /// + callback({}); + } +}; + +chrome.fontSettings.onDefaultFontSizeChanged = { + addListener: function (callback) { + /// + /// Fired when the default font size setting changes. + /// + callback({}); + } +}; + +chrome.fontSettings.onDefaultFixedFontSizeChanged = { + addListener: function (callback) { + /// + /// Fired when the default fixed font size setting changes. + /// + callback({}); + } +}; + +chrome.fontSettings.onMinimumFontSizeChanged = { + addListener: function (callback) { + /// + /// Fired when the minimum font size setting changes. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.gcm +chrome.gcm = {}; +chrome.gcm.register = function (senderIds, callback) { + /// + /// Registers the application with GCM. The registration ID will be returned by the callback. If register is called again with the same list of senderIds, the same registration ID will be returned. + /// + /// A list of server IDs that are allowed to send messages to the application. It should contain at least one and no more than 100 sender IDs. + /// Function called when registration completes. It should check ref:runtime.lastError for error when registrationId is empty. + callback(""); +}; + +chrome.gcm.send = function (message, callback) { + /// + /// Sends a message according to its contents. + /// + /// A message to send to the other party via GCM. + /// A function called after the message is successfully queued for sending. ref:runtime.lastError should be checked, to ensure a message was sent without problems. + callback(""); +}; + +//#region Chrome.gcm Events +chrome.gcm.onMessage = { + addListener: function (callback) { + /// + /// Fired when a message is received through GCM. + /// + callback({}); + } +}; + +chrome.gcm.onMessagesDeleted = { + addListener: function (callback) { + /// + /// Fired when a GCM server had to delete messages to the application from its queue in order to manage its size. The app is expected to handle that case gracefully, e.g. by running a full sync with its server. + /// + callback(); + } +}; + +chrome.gcm.onSendError = { + addListener: function (callback) { + /// + /// Fired when it was not possible to send a message to the GCM server. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.history +chrome.history = {}; +chrome.history.search = function (query, callback) { + /// + /// Searches the history for the last visit time of each page matching the query. + /// + /// + /// + callback({}); +}; + +chrome.history.getVisits = function (details, callback) { + /// + /// Retrieves information about visits to a URL. + /// + /// + /// + callback({}); +}; + +chrome.history.addUrl = function (details, callback) { + /// + /// Adds a URL to the history at the current time with a transition type of "link". + /// + /// + /// + callback(); +}; + +chrome.history.deleteUrl = function (details, callback) { + /// + /// Removes all occurrences of the given URL from the history. + /// + /// + /// + callback(); +}; + +chrome.history.deleteRange = function (range, callback) { + /// + /// Removes all items within the specified date range from the history. Pages will not be removed from the history unless all visits fall within the range. + /// + /// + /// + callback(); +}; + +chrome.history.deleteAll = function (callback) { + /// + /// Deletes all items from the history. + /// + /// + callback(); +}; + +//#region Chrome.history Events +chrome.history.onVisited = { + addListener: function (callback) { + /// + /// Fired when a URL is visited, providing the HistoryItem data for that URL. This event fires before the page has loaded. + /// + callback(new chrome.HistoryItem()); + } +}; + +chrome.history.onVisitRemoved = { + addListener: function (callback) { + /// + /// Fired when one or more URLs are removed from the history service. When all visits have been removed the URL is purged from history. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.i18n +chrome.i18n = {}; +chrome.i18n.getAcceptLanguages = function (callback) { + /// + /// Gets the accept-languages of the browser. This is different from the locale used by the browser; to get the locale, use window.navigator.language. + /// + /// + callback({}); +}; + +chrome.i18n.getMessage = function (messageName, substitutions) { + /// + /// Gets the localized string for the specified message. If the message is missing, this method returns an empty string (''). If the format of the getMessage() call is wrong — for example, messageName is not a string or the substitutions array has more than 9 elements — this method returns undefined. + /// + /// The name of the message, as specified in the messages.json file. + /// Up to 9 substitution strings, if the message requires any. + //No Callback + return ""; +}; + +//#region Chrome.i18n Events +//#endregion +//#endregion +//#region Chrome.idle +chrome.idle = {}; +chrome.idle.queryState = function (detectionIntervalInSeconds, callback) { + /// + /// Returns "locked" if the system is locked, "idle" if the user has not generated any input for a specified number of seconds, or "active" otherwise. + /// + /// The system is considered idle if detectionIntervalInSeconds seconds have elapsed since the last user input detected. + /// + callback(""); +}; + +chrome.idle.setDetectionInterval = function (intervalInSeconds) { + /// + /// Sets the interval, in seconds, used to determine when the system is in an idle state for onStateChanged events. The default interval is 60 seconds. + /// + /// Threshold, in seconds, used to determine when the system is in an idle state. + //No Callback +}; + +//#region Chrome.idle Events +chrome.idle.onStateChanged = { + addListener: function (callback) { + /// + /// Fired when the system changes to an active, idle or locked state. The event fires with "locked" if the screen is locked or the screensaver activates, "idle" if the system is unlocked and the user has not generated any input for a specified number of seconds, and "active" when the user generates input on an idle system. + /// + callback(""); + } +}; + +//#endregion +//#endregion +//#region Chrome.infobars +chrome.infobars = {}; +chrome.infobars.show = function (details, callback) { + /// + /// Shows an infobar in the specified tab. The infobar will be closed automatically when the tab navigates. Use window.close() to close the infobar before then. + /// + /// + /// + callback(new chrome.windows.Window()); +}; + +//#endregion +//#region Chrome.input.ime +chrome.input.ime = {}; +chrome.input.ime.setComposition = function (parameters, callback) { + /// + /// Set the current composition. If this extension does not own the active IME, this fails. + /// + /// + /// Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set. + callback({}); +}; + +chrome.input.ime.clearComposition = function (parameters, callback) { + /// + /// Clear the current composition. If this extension does not own the active IME, this fails. + /// + /// + /// Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set. + callback({}); +}; + +chrome.input.ime.commitText = function (parameters, callback) { + /// + /// Commits the provided text to the current input. + /// + /// + /// Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set. + callback({}); +}; + +chrome.input.ime.sendKeyEvents = function (parameters, callback) { + /// + /// Sends the key events. This function is expected to be used by virtual keyboards. When key(s) on a virtual keyboard is pressed by a user, this function is used to propagate that event to the system. + /// + /// + /// Called when the operation completes. + callback(); +}; + +chrome.input.ime.hideInputView = function () { + /// + /// Hides the input view window, which is popped up automatically by system. If the input view window is already hidden, this function will do nothing. + /// + //No Callback +}; + +chrome.input.ime.setCandidateWindowProperties = function (parameters, callback) { + /// + /// Sets the properties of the candidate window. This fails if the extension doesn't own the active IME + /// + /// + /// Called when the operation completes. + callback({}); +}; + +chrome.input.ime.setCandidates = function (parameters, callback) { + /// + /// Sets the current candidate list. This fails if this extension doesn't own the active IME + /// + /// + /// Called when the operation completes. + callback({}); +}; + +chrome.input.ime.setCursorPosition = function (parameters, callback) { + /// + /// Set the position of the cursor in the candidate window. This is a no-op if this extension does not own the active IME. + /// + /// + /// Called when the operation completes + callback({}); +}; + +chrome.input.ime.setMenuItems = function (parameters, callback) { + /// + /// Adds the provided menu items to the language menu when this IME is active. + /// + /// + /// + callback(); +}; + +chrome.input.ime.updateMenuItems = function (parameters, callback) { + /// + /// Updates the state of the MenuItems specified + /// + /// + /// Called when the operation completes + callback(); +}; + +chrome.input.ime.deleteSurroundingText = function (parameters, callback) { + /// + /// Deletes the text around the caret. + /// + /// + /// Called when the operation completes. + callback(); +}; + +chrome.input.ime.keyEventHandled = function (requestId, response) { + /// + /// Indicates that the key event received by onKeyEvent is handled. This should only be called if the onKeyEvent listener is asynchronous. + /// + /// Request id of the event that was handled. This should come from keyEvent.requestId + /// True if the keystroke was handled, false if not + //No Callback +}; + +//#region Chrome.input.ime Events +chrome.input.ime.onActivate = { + addListener: function (callback) { + /// + /// This event is sent when an IME is activated. It signals that the IME will be receiving onKeyPress events. + /// + callback(""); + } +}; + +chrome.input.ime.onDeactivated = { + addListener: function (callback) { + /// + /// This event is sent when an IME is deactivated. It signals that the IME will no longer be receiving onKeyPress events. + /// + callback(""); + } +}; + +chrome.input.ime.onFocus = { + addListener: function (callback) { + /// + /// This event is sent when focus enters a text box. It is sent to all extensions that are listening to this event, and enabled by the user. + /// + callback(new chrome.InputContext()); + } +}; + +chrome.input.ime.onBlur = { + addListener: function (callback) { + /// + /// This event is sent when focus leaves a text box. It is sent to all extensions that are listening to this event, and enabled by the user. + /// + callback({}); + } +}; + +chrome.input.ime.onInputContextUpdate = { + addListener: function (callback) { + /// + /// This event is sent when the properties of the current InputContext change, such as the the type. It is sent to all extensions that are listening to this event, and enabled by the user. + /// + callback(new chrome.InputContext()); + } +}; + +chrome.input.ime.onKeyEvent = { + addListener: function (callback) { + /// + /// This event is sent if this extension owns the active IME. + /// + callback("", new chrome.KeyboardEvent()); + } +}; + +chrome.input.ime.onCandidateClicked = { + addListener: function (callback) { + /// + /// This event is sent if this extension owns the active IME. + /// + callback("", {}, ""); + } +}; + +chrome.input.ime.onMenuItemActivated = { + addListener: function (callback) { + /// + /// Called when the user selects a menu item + /// + callback("", ""); + } +}; + +chrome.input.ime.onSurroundingTextChanged = { + addListener: function (callback) { + /// + /// Called when the editable string around caret is changed or when the caret position is moved. The text length is limited to 100 characters for each back and forth direction. + /// + callback("", {}); + } +}; + +chrome.input.ime.onReset = { + addListener: function (callback) { + /// + /// This event is sent when chrome terminates ongoing text input session. + /// + callback(""); + } +}; + +//#endregion +//#endregion +//#region Chrome.management +chrome.management = {}; +chrome.management.getAll = function (callback) { + /// + /// Returns a list of information about installed extensions and apps. + /// + /// + callback({}); +}; + +chrome.management.get = function (id, callback) { + /// + /// Returns information about the installed extension, app, or theme that has the given ID. + /// + /// The ID from an item of ref:ExtensionInfo. + /// + callback(new chrome.ExtensionInfo()); +}; + +chrome.management.getPermissionWarningsById = function (id, callback) { + /// + /// Returns a list of permission warnings for the given extension id. + /// + /// The ID of an already installed extension. + /// + callback({}); +}; + +chrome.management.getPermissionWarningsByManifest = function (manifestStr, callback) { + /// + /// Returns a list of permission warnings for the given extension manifest string. Note: This function can be used without requesting the 'management' permission in the manifest. + /// + /// Extension manifest JSON string. + /// + callback({}); +}; + +chrome.management.setEnabled = function (id, enabled, callback) { + /// + /// Enables or disables an app or extension. + /// + /// This should be the id from an item of ref:ExtensionInfo. + /// Whether this item should be enabled or disabled. + /// + callback(); +}; + +chrome.management.uninstall = function (id, options, callback) { + /// + /// Uninstalls a currently installed app or extension. + /// + /// This should be the id from an item of ref:ExtensionInfo. + /// + /// + callback(); +}; + +chrome.management.uninstallSelf = function (options, callback) { + /// + /// Uninstalls the calling extension. Note: This function can be used without requesting the 'management' permission in the manifest. + /// + /// + /// + callback(); +}; + +chrome.management.launchApp = function (id, callback) { + /// + /// Launches an application. + /// + /// The extension id of the application. + /// + callback(); +}; + +//#region Chrome.management Events +chrome.management.onInstalled = { + addListener: function (callback) { + /// + /// Fired when an app or extension has been installed. + /// + callback(new chrome.ExtensionInfo()); + } +}; + +chrome.management.onUninstalled = { + addListener: function (callback) { + /// + /// Fired when an app or extension has been uninstalled. + /// + callback(""); + } +}; + +chrome.management.onEnabled = { + addListener: function (callback) { + /// + /// Fired when an app or extension has been enabled. + /// + callback(new chrome.ExtensionInfo()); + } +}; + +chrome.management.onDisabled = { + addListener: function (callback) { + /// + /// Fired when an app or extension has been disabled. + /// + callback(new chrome.ExtensionInfo()); + } +}; + +//#endregion +//#endregion +//#region Chrome.manifestTypes +chrome.manifestTypes = {}; +//#endregion +//#region Chrome.omnibox +chrome.omnibox = {}; +chrome.omnibox.sendSuggestions = function (requestId, suggestResults) { + /// + /// A callback passed to the onInputChanged event used for sending suggestions back to the browser. + /// + /// + /// An array of suggest results + //No Callback +}; + +chrome.omnibox.setDefaultSuggestion = function (suggestion) { + /// + /// Sets the description and styling for the default suggestion. The default suggestion is the text that is displayed in the first suggestion row underneath the URL bar. + /// + /// A partial SuggestResult object, without the 'content' parameter. + //No Callback +}; + +//#region Chrome.omnibox Events +chrome.omnibox.onInputStarted = { + addListener: function (callback) { + /// + /// User has started a keyword input session by typing the extension's keyword. This is guaranteed to be sent exactly once per input session, and before any onInputChanged events. + /// + callback(); + } +}; + +chrome.omnibox.onInputChanged = { + addListener: function (callback) { + /// + /// User has changed what is typed into the omnibox. + /// + callback("", {}); + } +}; + +chrome.omnibox.onInputEntered = { + addListener: function (callback) { + /// + /// User has accepted what is typed into the omnibox. + /// + callback("", ""); + } +}; + +chrome.omnibox.onInputCancelled = { + addListener: function (callback) { + /// + /// User has ended the keyword input session without accepting the input. + /// + callback(); + } +}; + +//#endregion +//#endregion +//#region Chrome.pageAction +chrome.pageAction = {}; +chrome.pageAction.show = function (tabId) { + /// + /// Shows the page action. The page action is shown whenever the tab is selected. + /// + /// The id of the tab for which you want to modify the page action. + //No Callback +}; + +chrome.pageAction.hide = function (tabId) { + /// + /// Hides the page action. + /// + /// The id of the tab for which you want to modify the page action. + //No Callback +}; + +chrome.pageAction.setTitle = function (details) { + /// + /// Sets the title of the page action. This is displayed in a tooltip over the page action. + /// + /// + //No Callback +}; + +chrome.pageAction.getTitle = function (details, callback) { + /// + /// Gets the title of the page action. + /// + /// + /// + callback(""); +}; + +chrome.pageAction.setIcon = function (details, callback) { + /// + /// Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the path or the imageData property must be specified. + /// + /// + /// + callback(); +}; + +chrome.pageAction.setPopup = function (details) { + /// + /// Sets the html document to be opened as a popup when the user clicks on the page action's icon. + /// + /// + //No Callback +}; + +chrome.pageAction.getPopup = function (details, callback) { + /// + /// Gets the html document set as the popup for this page action. + /// + /// + /// + callback(""); +}; + +//#region Chrome.pageAction Events +chrome.pageAction.onClicked = { + addListener: function (callback) { + /// + /// Fired when a page action icon is clicked. This event will not fire if the page action has a popup. + /// + callback(new chrome.tabs.Tab()); + } +}; + +//#endregion +//#endregion +//#region Chrome.pageActions +chrome.pageActions = {}; +chrome.pageActions.enableForTab = function (pageActionId, action) { + /// + /// Enables a page action for a particular tab+URL combination (makes its icon visible in the OmniBox when a certain URL is active in a given tab). The page action will automatically be disabled (its icon hidden) if the user navigates to a new URL or closes the tab. The action will also automatically be enabled/disabled as the user switches tabs. + /// + /// An extension can have multiple page actions specified in the manifest, each with a unique identifier. This string identifies which page action you want to enable (and must match a page action id declared in the manifest). + /// An object specifing what action should be applied to the page action. Contains the following properties: + //No Callback +}; + +chrome.pageActions.disableForTab = function (pageActionId, action) { + /// + /// Disables a page action for a particular tab+URL combination (makes its OmniBox page action icon hidden when a certain URL is active in a given tab). This can be useful to disable a page action before the user navigates away from a page containing an enabled page action. + /// + /// An extension can have multiple page actions specified in the manifest, each with a unique identifier. This string identifies which page action you want to disable (and must match a page action id declared in the manifest). + /// An object specifying what action should be applied to the page action. Contains the following properties: + //No Callback +}; + +//#region Chrome.pageActions Events +//#endregion +//#endregion +//#region Chrome.pageCapture +chrome.pageCapture = {}; +chrome.pageCapture.saveAsMHTML = function (details, callback) { + /// + /// Saves the content of the tab with given id as MHTML. + /// + /// + /// Called when the MHTML has been generated. + callback({}); +}; + +//#endregion +//#region Chrome.permissions +chrome.permissions = {}; +chrome.permissions.getAll = function (callback) { + /// + /// Gets the extension's current set of permissions. + /// + /// + callback(new chrome.Permissions()); +}; + +chrome.permissions.contains = function (permissions, callback) { + /// + /// Checks if the extension has the specified permissions. + /// + /// + /// + callback({}); +}; + +chrome.permissions.request = function (permissions, callback) { + /// + /// Requests access to the specified permissions. These permissions must be defined in the optional_permissions field of the manifest. If there are any problems requesting the permissions, ref:runtime.lastError will be set. + /// + /// + /// + callback({}); +}; + +chrome.permissions.remove = function (permissions, callback) { + /// + /// Removes access to the specified permissions. If there are any problems removing the permissions, ref:runtime.lastError will be set. + /// + /// + /// + callback({}); +}; + +//#region Chrome.permissions Events +chrome.permissions.onAdded = { + addListener: function (callback) { + /// + /// Fired when the extension acquires new permissions. + /// + callback(new chrome.Permissions()); + } +}; + +chrome.permissions.onRemoved = { + addListener: function (callback) { + /// + /// Fired when access to permissions has been removed from the extension. + /// + callback(new chrome.Permissions()); + } +}; + +//#endregion +//#endregion +//#region Chrome.privacy +chrome.privacy = {}; +//#endregion +//#region Chrome.processes +chrome.processes = {}; +chrome.processes.terminate = function (processId, callback) { + /// + /// Terminates the specified renderer process. Equivalent to visiting about:crash, but without changing the tab's URL. + /// + /// The ID of the process to be terminated. + /// + callback({}); +}; + +chrome.processes.getProcessIdForTab = function (tabId, callback) { + /// + /// Returns the ID of the renderer process for the specified tab. + /// + /// The ID of the tab for which the renderer process ID is to be returned. + /// + callback({}); +}; + +chrome.processes.getProcessInfo = function (processIds, includeMemory, callback) { + /// + /// Retrieves the process information for each process ID specified. + /// + /// The list of process IDs or single process ID for which to return the process information. An empty list indicates all processes are requested. + /// True if detailed memory usage is required. Note, collecting memory usage information incurs extra CPU usage and should only be queried for when needed. + /// Called when the processes information is collected. + callback({}); +}; + +//#region Chrome.processes Events +chrome.processes.onUpdated = { + addListener: function (callback) { + /// + /// Fired each time the Task Manager updates its process statistics, providing the dictionary of updated Process objects, indexed by process ID. + /// + callback({}); + } +}; + +chrome.processes.onUpdatedWithMemory = { + addListener: function (callback) { + /// + /// Fired each time the Task Manager updates its process statistics, providing the dictionary of updated Process objects, indexed by process ID. Identical to onUpdate, with the addition of memory usage details included in each Process object. Note, collecting memory usage information incurs extra CPU usage and should only be listened for when needed. + /// + callback({}); + } +}; + +chrome.processes.onCreated = { + addListener: function (callback) { + /// + /// Fired each time a process is created, providing the corrseponding Process object. + /// + callback(new chrome.Process()); + } +}; + +chrome.processes.onUnresponsive = { + addListener: function (callback) { + /// + /// Fired each time a process becomes unresponsive, providing the corrseponding Process object. + /// + callback(new chrome.Process()); + } +}; + +chrome.processes.onExited = { + addListener: function (callback) { + /// + /// Fired each time a process is terminated, providing the type of exit. + /// + callback({}, {}, {}); + } +}; + +//#endregion +//#endregion +//#region Chrome.proxy +chrome.proxy = {}; +//#region Chrome.proxy Events +chrome.proxy.onProxyError = { + addListener: function (callback) { + /// + /// Notifies about proxy errors. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.runtime +chrome.runtime = {}; +chrome.runtime.getBackgroundPage = function (callback) { + /// + /// Retrieves the JavaScript 'window' object for the background page running inside the current extension/app. If the background page is an event page, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set. + /// + /// + callback({}); +}; + +chrome.runtime.getManifest = function () { + /// + /// Returns details about the app or extension from the manifest. The object returned is a serialization of the full manifest file. + /// + //No Callback + return {}; +}; + +chrome.runtime.getURL = function (path) { + /// + /// Converts a relative path within an app/extension install directory to a fully-qualified URL. + /// + /// A path to a resource within an app/extension expressed relative to its install directory. + //No Callback + return ""; +}; + +chrome.runtime.setUninstallURL = function (url) { + /// + /// Sets the URL to be visited upon uninstallation. This may be used to clean up server-side data, do analytics, and implement surveys. Maximum 255 characters. + /// + /// + //No Callback +}; + +chrome.runtime.reload = function () { + /// + /// Reloads the app or extension. + /// + //No Callback +}; + +chrome.runtime.requestUpdateCheck = function (callback) { + /// + /// Requests an update check for this app/extension. + /// + /// + callback("", {}); +}; + +chrome.runtime.restart = function () { + /// + /// Restart the ChromeOS device when the app runs in kiosk mode. Otherwise, it's no-op. + /// + //No Callback +}; + +chrome.runtime.connect = function (extensionId, connectInfo) { + /// + /// Attempts to connect to other listeners within the extension/app (such as the background page), or other extensions/apps. This is useful for content scripts connecting to their extension processes. Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via ref:tabs.connect. + /// + /// The ID of the extension/app you want to connect to. If omitted, default is your own extension. + /// + //No Callback + return new chrome.Port; +}; + +chrome.runtime.connectNative = function (application) { + /// + /// Connects to a native application in the host machine. + /// + /// The name of the registered application to connect to. + //No Callback + return new chrome.Port; +}; + +chrome.runtime.sendMessage = function (extensionId, message, options, responseCallback) { + /// + /// Sends a single message to onMessage event listeners within the extension (or another extension/app). Similar to chrome.runtime.connect, but only sends a single message with an optional response. The ref:runtime.onMessage event is fired in each extension page of the extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, use ref:tabs.sendMessage. + /// + /// The extension ID of the extension you want to connect to. If omitted, default is your own extension. + /// + /// + /// + //No Callback +}; + +chrome.runtime.sendNativeMessage = function (application, message, responseCallback) { + /// + /// Send a single message to a native application. + /// + /// The name of the native messaging host. + /// The message that will be passed to the native messaging host. + /// + //No Callback +}; + +chrome.runtime.getPlatformInfo = function (callback) { + /// + /// Returns information about the current platform. + /// + /// Called with results + callback({}); +}; + +chrome.runtime.getPackageDirectoryEntry = function (callback) { + /// + /// Returns a DirectoryEntry for the package directory. + /// + /// + callback({}); +}; + +//#region Chrome.runtime Events +chrome.runtime.onStartup = { + addListener: function (callback) { + /// + /// Fired when a profile that has this extension installed first starts up. This event is not fired when an incognito profile is started, even if this extension is operating in 'split' incognito mode. + /// + callback(); + } +}; + +chrome.runtime.onInstalled = { + addListener: function (callback) { + /// + /// Fired when the extension is first installed, when the extension is updated to a new version, and when Chrome is updated to a new version. + /// + callback({}); + } +}; + +chrome.runtime.onSuspend = { + addListener: function (callback) { + /// + /// Sent to the event page just before it is unloaded. This gives the extension opportunity to do some clean up. Note that since the page is unloading, any asynchronous operations started while handling this event are not guaranteed to complete. If more activity for the event page occurs before it gets unloaded the onSuspendCanceled event will be sent and the page won't be unloaded. + /// + callback(); + } +}; + +chrome.runtime.onSuspendCanceled = { + addListener: function (callback) { + /// + /// Sent after onSuspend to indicate that the app won't be unloaded after all. + /// + callback(); + } +}; + +chrome.runtime.onUpdateAvailable = { + addListener: function (callback) { + /// + /// Fired when an update is available, but isn't installed immediately because the app is currently running. If you do nothing, the update will be installed the next time the background page gets unloaded, if you want it to be installed sooner you can explicitly call chrome.runtime.reload(). + /// + callback({}); + } +}; + +chrome.runtime.onBrowserUpdateAvailable = { + addListener: function (callback) { + /// + /// Fired when a Chrome update is available, but isn't installed immediately because a browser restart is required. + /// + callback(); + } +}; + +chrome.runtime.onConnect = { + addListener: function (callback) { + /// + /// Fired when a connection is made from either an extension process or a content script. + /// + callback(new chrome.Port()); + } +}; + +chrome.runtime.onConnectExternal = { + addListener: function (callback) { + /// + /// Fired when a connection is made from another extension. + /// + callback(new chrome.Port()); + } +}; + +chrome.runtime.onMessage = { + addListener: function (callback) { + /// + /// Fired when a message is sent from either an extension process or a content script. + /// + callback({}, new chrome.MessageSender(), {}); + } +}; + +chrome.runtime.onMessageExternal = { + addListener: function (callback) { + /// + /// Fired when a message is sent from another extension/app. Cannot be used in a content script. + /// + callback({}, new chrome.MessageSender(), {}); + } +}; + +chrome.runtime.onRestartRequired = { + addListener: function (callback) { + /// + /// Fired when an app or the device that it runs on needs to be restarted. The app should close all its windows at its earliest convenient time to let the restart to happen. If the app does nothing, a restart will be enforced after a 24-hour grace period has passed. Currently, this event is only fired for Chrome OS kiosk apps. + /// + callback(""); + } +}; + +//#endregion +//#endregion +//#region Chrome.scriptBadge +chrome.scriptBadge = {}; +chrome.scriptBadge.setPopup = function (details) { + /// + /// Sets the html document to be opened as a popup when the user clicks on the script badge's icon. + /// + /// + //No Callback +}; + +chrome.scriptBadge.getPopup = function (details, callback) { + /// + /// Gets the html document set as the popup for this script badge. + /// + /// + /// + callback(""); +}; + +chrome.scriptBadge.getAttention = function (details) { + /// + /// Brings the script badge to the attention of the user, imploring her to click. You should call this when you detect that you can do something to a particular tab. Do not call this for every tab. That's tacky. If the user clicks on the badge, the activeTab APIs become available. If the extension has already run on this tab, this call does nothing. + /// + /// + //No Callback +}; + +//#region Chrome.scriptBadge Events +chrome.scriptBadge.onClicked = { + addListener: function (callback) { + /// + /// Fired when a script badge icon is clicked. This event will not fire if the script badge has a popup. + /// + callback(new chrome.tabs.Tab()); + } +}; + +//#endregion +//#endregion +//#region Chrome.sessions +chrome.sessions = {}; +chrome.sessions.getRecentlyClosed = function (filter, callback) { + /// + /// Gets the list of recently closed tabs and/or windows. + /// + /// + /// + callback({}); +}; + +chrome.sessions.getDevices = function (filter, callback) { + /// + /// Retrieves all devices with synced sessions. + /// + /// + /// + callback({}); +}; + +chrome.sessions.restore = function (sessionId, callback) { + /// + /// Reopens a ref:windows.Window or ref:tabs.Tab, with an optional callback to run when the entry has been restored. + /// + /// The ref:windows.Window.sessionId, or ref:tabs.Tab.sessionId to restore. + /// + callback(new chrome.Session()); +}; + +//#endregion +//#region Chrome.storage +chrome.storage = {}; +//#region Chrome.storage Events +chrome.storage.onChanged = { + addListener: function (callback) { + /// + /// Fired when one or more items change. + /// + callback({}, ""); + } +}; + +//#endregion +//#region Chrome.storage Properties +chrome.storage.sync = new chrome.StorageArea(); +chrome.storage.local = new chrome.StorageArea(); +chrome.storage.managed = new chrome.StorageArea(); + +//#endregion +//#endregion +//#region Chrome.tabs +chrome.tabs = {}; +chrome.tabs.get = function (tabId, callback) { + /// + /// Retrieves details about the specified tab. + /// + /// + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.getCurrent = function (callback) { + /// + /// Gets the tab that this script call is being made from. May be undefined if called from a non-tab context (for example: a background page or popup view). + /// + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.connect = function (tabId, connectInfo) { + /// + /// Connects to the content script(s) in the specified tab. The ref:runtime.onConnect event is fired in each content script running in the specified tab for the current extension. For more details, see Content Script Messaging. + /// + /// + /// + //No Callback + return new chrome.runtime.Port; +}; + +chrome.tabs.sendRequest = function (tabId, request, responseCallback) { + /// + /// Sends a single request to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The ref:extension.onRequest event is fired in each content script running in the specified tab for the current extension. + /// + /// + /// + /// + //No Callback +}; + +chrome.tabs.sendMessage = function (tabId, message, responseCallback) { + /// + /// Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The ref:runtime.onMessage event is fired in each content script running in the specified tab for the current extension. + /// + /// + /// + /// + //No Callback +}; + +chrome.tabs.getSelected = function (windowId, callback) { + /// + /// Gets the tab that is selected in the specified window. + /// + /// Defaults to the current window. + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.getAllInWindow = function (windowId, callback) { + /// + /// Gets details about all tabs in the specified window. + /// + /// Defaults to the current window. + /// + callback({}); +}; + +chrome.tabs.create = function (createProperties, callback) { + /// + /// Creates a new tab. + /// + /// + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.duplicate = function (tabId, callback) { + /// + /// Duplicates a tab. + /// + /// The ID of the tab which is to be duplicated. + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.query = function (queryInfo, callback) { + /// + /// Gets all tabs that have the specified properties, or all tabs if no properties are specified. + /// + /// + /// + callback({}); +}; + +chrome.tabs.highlight = function (highlightInfo, callback) { + /// + /// Highlights the given tabs. + /// + /// + /// + callback(new chrome.windows.Window()); +}; + +chrome.tabs.update = function (tabId, updateProperties, callback) { + /// + /// Modifies the properties of a tab. Properties that are not specified in updateProperties are not modified. + /// + /// Defaults to the selected tab of the current window. + /// + /// + callback(new chrome.Tab()); +}; + +chrome.tabs.move = function (tabIds, moveProperties, callback) { + /// + /// Moves one or more tabs to a new position within its window, or to a new window. Note that tabs can only be moved to and from normal (window.type === "normal") windows. + /// + /// The tab or list of tabs to move. + /// + /// + callback({}); +}; + +chrome.tabs.reload = function (tabId, reloadProperties, callback) { + /// + /// Reload a tab. + /// + /// The ID of the tab to reload; defaults to the selected tab of the current window. + /// + /// + callback(); +}; + +chrome.tabs.remove = function (tabIds, callback) { + /// + /// Closes one or more tabs. + /// + /// The tab or list of tabs to close. + /// + callback(); +}; + +chrome.tabs.detectLanguage = function (tabId, callback) { + /// + /// Detects the primary language of the content in a tab. + /// + /// Defaults to the active tab of the current window. + /// + callback(""); +}; + +chrome.tabs.captureVisibleTab = function (windowId, options, callback) { + /// + /// Captures the visible area of the currently active tab in the specified window. You must have host permission for the URL displayed by the tab. + /// + /// The target window. Defaults to the current window. + /// + /// + callback(""); +}; + +chrome.tabs.executeScript = function (tabId, details, callback) { + /// + /// Injects JavaScript code into a page. For details, see the programmatic injection section of the content scripts doc. + /// + /// The ID of the tab in which to run the script; defaults to the active tab of the current window. + /// Details of the script to run. + /// Called after all the JavaScript has been executed. + callback({}); +}; + +chrome.tabs.insertCSS = function (tabId, details, callback) { + /// + /// Injects CSS into a page. For details, see the programmatic injection section of the content scripts doc. + /// + /// The ID of the tab in which to insert the CSS; defaults to the active tab of the current window. + /// Details of the CSS text to insert. + /// Called when all the CSS has been inserted. + callback(); +}; + +//#region Chrome.tabs Events +chrome.tabs.onCreated = { + addListener: function (callback) { + /// + /// Fired when a tab is created. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set. + /// + callback(new chrome.Tab()); + } +}; + +chrome.tabs.onUpdated = { + addListener: function (callback) { + /// + /// Fired when a tab is updated. + /// + callback({}, {}, new chrome.Tab()); + } +}; + +chrome.tabs.onMoved = { + addListener: function (callback) { + /// + /// Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response. This event is not fired when a tab is moved between windows. For that, see ref:onDetached. + /// + callback({}, {}); + } +}; + +chrome.tabs.onSelectionChanged = { + addListener: function (callback) { + /// + /// Fires when the selected tab in a window changes. + /// + callback({}, {}); + } +}; + +chrome.tabs.onActiveChanged = { + addListener: function (callback) { + /// + /// Fires when the selected tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to ref:onUpdated events to be notified when a URL is set. + /// + callback({}, {}); + } +}; + +chrome.tabs.onActivated = { + addListener: function (callback) { + /// + /// Fires when the active tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set. + /// + callback({}); + } +}; + +chrome.tabs.onHighlightChanged = { + addListener: function (callback) { + /// + /// Fired when the highlighted or selected tabs in a window changes. + /// + callback({}); + } +}; + +chrome.tabs.onHighlighted = { + addListener: function (callback) { + /// + /// Fired when the highlighted or selected tabs in a window changes. + /// + callback({}); + } +}; + +chrome.tabs.onDetached = { + addListener: function (callback) { + /// + /// Fired when a tab is detached from a window, for example because it is being moved between windows. + /// + callback({}, {}); + } +}; + +chrome.tabs.onAttached = { + addListener: function (callback) { + /// + /// Fired when a tab is attached to a window, for example because it was moved between windows. + /// + callback({}, {}); + } +}; + +chrome.tabs.onRemoved = { + addListener: function (callback) { + /// + /// Fired when a tab is closed. + /// + callback({}, {}); + } +}; + +chrome.tabs.onReplaced = { + addListener: function (callback) { + /// + /// Fired when a tab is replaced with another tab due to prerendering or instant. + /// + callback({}, {}); + } +}; + +//#endregion +//#endregion +//#region Chrome.test +chrome.test = {}; +chrome.test.getConfig = function (callback) { + /// + /// Gives configuration options set by the test. + /// + /// + callback({}); +}; + +chrome.test.notifyFail = function (message) { + /// + /// Notifies the browser process that test code running in the extension failed. This is only used for internal unit testing. + /// + /// + //No Callback +}; + +chrome.test.notifyPass = function (message) { + /// + /// Notifies the browser process that test code running in the extension passed. This is only used for internal unit testing. + /// + /// + //No Callback +}; + +chrome.test.resetQuota = function () { + /// + /// Resets all accumulated quota state for all extensions. This is only used for internal unit testing. + /// + //No Callback +}; + +chrome.test.log = function (message) { + /// + /// Logs a message during internal unit testing. + /// + /// + //No Callback +}; + +chrome.test.createIncognitoTab = function (url) { + /// + /// Creates an incognito tab during internal testing. Succeeds even if the extension is not enabled in incognito mode. + /// + /// + //No Callback +}; + +chrome.test.sendMessage = function (message, callback) { + /// + /// Sends a string message to the browser process, generating a Notification that C++ test code can wait for. + /// + /// + /// + callback(""); +}; + +chrome.test.callbackAdded = function () { + /// + /// + //No Callback +}; + +chrome.test.runNextTest = function () { + /// + /// + //No Callback +}; + +chrome.test.fail = function (message) { + /// + /// + /// + //No Callback +}; + +chrome.test.succeed = function (message) { + /// + /// + /// + //No Callback +}; + +chrome.test.assertTrue = function (test, message) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.assertFalse = function (test, message) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.assertBool = function (test, expected, message) { + /// + /// + /// + /// + /// + //No Callback +}; + +chrome.test.checkDeepEq = function (expected, actual) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.assertEq = function (expected, actual, message) { + /// + /// + /// + /// + /// + //No Callback +}; + +chrome.test.assertNoLastError = function () { + /// + /// + //No Callback +}; + +chrome.test.assertLastError = function (expectedError) { + /// + /// + /// + //No Callback +}; + +chrome.test.assertThrows = function (fn, self, args, message) { + /// + /// + /// + /// + /// + /// + //No Callback +}; + +chrome.test.callback = function (func, expectedError) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.listenOnce = function (event, func) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.listenForever = function (event, func) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.callbackPass = function (func) { + /// + /// + /// + //No Callback +}; + +chrome.test.callbackFail = function (expectedError, func) { + /// + /// + /// + /// + //No Callback +}; + +chrome.test.runTests = function (tests) { + /// + /// + /// + //No Callback +}; + +chrome.test.getApiFeatures = function () { + /// + /// + //No Callback +}; + +chrome.test.getApiDefinitions = function (apiNames) { + /// + /// + /// + //No Callback +}; + +chrome.test.isProcessingUserGesture = function () { + /// + /// + //No Callback +}; + +chrome.test.runWithUserGesture = function (callback) { + /// + /// Runs the callback in the context of a user gesture. + /// + /// + callback(); +}; + +chrome.test.runWithoutUserGesture = function (callback) { + /// + /// + /// + callback(); +}; + +//#region Chrome.test Events +chrome.test.onMessage = { + addListener: function (callback) { + /// + /// Used to test sending messages to extensions. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.topSites +chrome.topSites = {}; +chrome.topSites.get = function (callback) { + /// + /// Gets a list of top sites. + /// + /// + callback({}); +}; + +//#endregion +//#region Chrome.tts +chrome.tts = {}; +chrome.tts.speak = function (utterance, options, callback) { + /// + /// Speaks text using a text-to-speech engine. + /// + /// The text to speak, either plain text or a complete, well-formed SSML document. Speech engines that do not support SSML will strip away the tags and speak the text. The maximum length of the text is 32,768 characters. + /// The speech options. + /// Called right away, before speech finishes. Check chrome.runtime.lastError to make sure there were no errors. Use options.onEvent to get more detailed feedback. + callback(); +}; + +chrome.tts.stop = function () { + /// + /// Stops any current speech and flushes the queue of any pending utterances. In addition, if speech was paused, it will now be un-paused for the next call to speak. + /// + //No Callback +}; + +chrome.tts.pause = function () { + /// + /// Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech. + /// + //No Callback +}; + +chrome.tts.resume = function () { + /// + /// If speech was paused, resumes speaking where it left off. + /// + //No Callback +}; + +chrome.tts.isSpeaking = function (callback) { + /// + /// Checks whether the engine is currently speaking. On Mac OS X, the result is true whenever the system speech engine is speaking, even if the speech wasn't initiated by Chrome. + /// + /// + callback({}); +}; + +chrome.tts.getVoices = function (callback) { + /// + /// Gets an array of all available voices. + /// + /// + callback({}); +}; + +//#region Chrome.tts Events +chrome.tts.onEvent = { + addListener: function (callback) { + /// + /// Used to pass events back to the function calling speak(). + /// + callback(new chrome.TtsEvent()); + } +}; + +//#endregion +//#endregion +//#region Chrome.ttsEngine +chrome.ttsEngine = {}; +chrome.ttsEngine.sendTtsEvent = function (requestId, event) { + /// + /// Routes a TTS event from a speech engine to a client. + /// + /// + /// The update event from the text-to-speech engine indicating the status of this utterance. + //No Callback +}; + +//#region Chrome.ttsEngine Events +chrome.ttsEngine.onSpeak = { + addListener: function (callback) { + /// + /// Called when the user makes a call to tts.speak() and one of the voices from this extension's manifest is the first to match the options object. + /// + callback("", {}, {}); + } +}; + +chrome.ttsEngine.onStop = { + addListener: function (callback) { + /// + /// Fired when a call is made to tts.stop and this extension may be in the middle of speaking. If an extension receives a call to onStop and speech is already stopped, it should do nothing (not raise an error). If speech is in the paused state, this should cancel the paused state. + /// + callback(); + } +}; + +chrome.ttsEngine.onPause = { + addListener: function (callback) { + /// + /// Optional: if an engine supports the pause event, it should pause the current utterance being spoken, if any, until it receives a resume event or stop event. Note that a stop event should also clear the paused state. + /// + callback(); + } +}; + +chrome.ttsEngine.onResume = { + addListener: function (callback) { + /// + /// Optional: if an engine supports the pause event, it should also support the resume event, to continue speaking the current utterance, if any. Note that a stop event should also clear the paused state. + /// + callback(); + } +}; + +//#endregion +//#endregion +//#region Chrome.types +chrome.types = {}; +//#endregion +//#region Chrome.wallpaper +chrome.wallpaper = {}; +chrome.wallpaper.setWallpaper = function (details, callback) { + /// + /// Sets wallpaper to the image at url or wallpaperData with the specified layout + /// + /// + /// + callback({}); +}; + +//#endregion +//#region Chrome.webNavigation +chrome.webNavigation = {}; +chrome.webNavigation.getFrame = function (details, callback) { + /// + /// Retrieves information about the given frame. A frame refers to an <iframe> or a <frame> of a web page and is identified by a tab ID and a frame ID. + /// + /// Information about the frame to retrieve information about. + /// + callback({}); +}; + +chrome.webNavigation.getAllFrames = function (details, callback) { + /// + /// Retrieves information about all frames of a given tab. + /// + /// Information about the tab to retrieve all frames from. + /// + callback({}); +}; + +//#region Chrome.webNavigation Events +chrome.webNavigation.onBeforeNavigate = { + addListener: function (callback) { + /// + /// Fired when a navigation is about to occur. + /// + callback({}); + } +}; + +chrome.webNavigation.onCommitted = { + addListener: function (callback) { + /// + /// Fired when a navigation is committed. The document (and the resources it refers to, such as images and subframes) might still be downloading, but at least part of the document has been received from the server and the browser has decided to switch to the new document. + /// + callback({}); + } +}; + +chrome.webNavigation.onDOMContentLoaded = { + addListener: function (callback) { + /// + /// Fired when the page's DOM is fully constructed, but the referenced resources may not finish loading. + /// + callback({}); + } +}; + +chrome.webNavigation.onCompleted = { + addListener: function (callback) { + /// + /// Fired when a document, including the resources it refers to, is completely loaded and initialized. + /// + callback({}); + } +}; + +chrome.webNavigation.onErrorOccurred = { + addListener: function (callback) { + /// + /// Fired when an error occurs and the navigation is aborted. This can happen if either a network error occurred, or the user aborted the navigation. + /// + callback({}); + } +}; + +chrome.webNavigation.onCreatedNavigationTarget = { + addListener: function (callback) { + /// + /// Fired when a new window, or a new tab in an existing window, is created to host a navigation. + /// + callback({}); + } +}; + +chrome.webNavigation.onReferenceFragmentUpdated = { + addListener: function (callback) { + /// + /// Fired when the reference fragment of a frame was updated. All future events for that frame will use the updated URL. + /// + callback({}); + } +}; + +chrome.webNavigation.onTabReplaced = { + addListener: function (callback) { + /// + /// Fired when the contents of the tab is replaced by a different (usually previously pre-rendered) tab. + /// + callback({}); + } +}; + +chrome.webNavigation.onHistoryStateUpdated = { + addListener: function (callback) { + /// + /// Fired when the frame's history was updated to a new URL. All future events for that frame will use the updated URL. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.webRequest +chrome.webRequest = {}; +chrome.webRequest.handlerBehaviorChanged = function (callback) { + /// + /// Needs to be called when the behavior of the webRequest handlers has changed to prevent incorrect handling due to caching. This function call is expensive. Don't call it often. + /// + /// + callback(); +}; + +//#region Chrome.webRequest Events +chrome.webRequest.onBeforeRequest = { + addListener: function (callback) { + /// + /// Fired when a request is about to occur. + /// + callback({}); + } +}; + +chrome.webRequest.onBeforeSendHeaders = { + addListener: function (callback) { + /// + /// Fired before sending an HTTP request, once the request headers are available. This may occur after a TCP connection is made to the server, but before any HTTP data is sent. + /// + callback({}); + } +}; + +chrome.webRequest.onSendHeaders = { + addListener: function (callback) { + /// + /// Fired just before a request is going to be sent to the server (modifications of previous onBeforeSendHeaders callbacks are visible by the time onSendHeaders is fired). + /// + callback({}); + } +}; + +chrome.webRequest.onHeadersReceived = { + addListener: function (callback) { + /// + /// Fired when HTTP response headers of a request have been received. + /// + callback({}); + } +}; + +chrome.webRequest.onAuthRequired = { + addListener: function (callback) { + /// + /// Fired when an authentication failure is received. The listener has three options: it can provide authentication credentials, it can cancel the request and display the error page, or it can take no action on the challenge. If bad user credentials are provided, this may be called multiple times for the same request. + /// + callback({}, {}); + } +}; + +chrome.webRequest.onResponseStarted = { + addListener: function (callback) { + /// + /// Fired when the first byte of the response body is received. For HTTP requests, this means that the status line and response headers are available. + /// + callback({}); + } +}; + +chrome.webRequest.onBeforeRedirect = { + addListener: function (callback) { + /// + /// Fired when a server-initiated redirect is about to occur. + /// + callback({}); + } +}; + +chrome.webRequest.onCompleted = { + addListener: function (callback) { + /// + /// Fired when a request is completed. + /// + callback({}); + } +}; + +chrome.webRequest.onErrorOccurred = { + addListener: function (callback) { + /// + /// Fired when an error occurs. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.webRequestInternal +chrome.webRequestInternal = {}; +chrome.webRequestInternal.addEventListener = function (callback, filter, extraInfoSpec, eventName, subEventName, webViewInstanceId) { + /// + /// Used internally to implement the special form of addListener for the webRequest events. + /// + /// + /// A set of filters that restricts the events that will be sent to this listener. + /// Array of extra information that should be passed to the listener function. + /// + /// + /// + callback(); +}; + +chrome.webRequestInternal.eventHandled = function (eventName, subEventName, requestId, response) { + /// + /// Used internally to send a response for a blocked event. + /// + /// + /// + /// + /// + //No Callback +}; + +//#endregion +//#region Chrome.webstore +chrome.webstore = {}; +chrome.webstore.install = function (url, successCallback, failureCallback) { + /// + /// + /// If you have more than one <link> tag on your page with the chrome-webstore-item relation, you can choose which item you'd like to install by passing in its URL here. If it is omitted, then the first (or only) link will be used. An exception will be thrown if the passed in URL does not exist on the page. + /// This function is invoked when inline installation successfully completes (after the dialog is shown and the user agrees to add the item to Chrome). You may wish to use this to hide the user interface element that prompted the user to install the app or extension. + /// This function is invoked when inline installation does not successfully complete. Possible reasons for this include the user canceling the dialog, the linked item not being found in the store, or the install being initiated from a non-verified site. + //No Callback +}; + +//#endregion +//#region Chrome.webview +chrome.webview = {}; +chrome.webview.clearData = function (instanceId, options, dataToRemove, callback) { + /// + /// Clears various types of browsing data stored in a storage partition of a . + /// + /// The instance ID of the guest process. + /// + /// The set of data types to remove. + /// Called when deletion has completed. + callback(); +}; + +chrome.webview.executeScript = function (instanceId, details, callback) { + /// + /// Injects JavaScript code into a page. + /// + /// The instance ID of the guest process. + /// Details of the script to run. + /// Called after all the JavaScript has been executed. + callback({}); +}; + +chrome.webview.insertCSS = function (instanceId, details, callback) { + /// + /// Injects JavaScript code into a page. + /// + /// The instance ID of the guest process. + /// Details of the script to run. + /// Called after all the JavaScript has been executed. + callback({}); +}; + +chrome.webview.captureVisibleRegion = function (instanceId, options, callback) { + /// + /// Captures the visible area of the currently loaded page inside . + /// + /// The instance ID of the guest process. + /// + /// + callback(""); +}; + +chrome.webview.go = function (instanceId, relativeIndex) { + /// + /// + /// + /// + //No Callback +}; + +chrome.webview.overrideUserAgent = function (instanceId, userAgentOverride) { + /// + /// + /// + /// + //No Callback +}; + +chrome.webview.reload = function (instanceId) { + /// + /// + /// + //No Callback +}; + +chrome.webview.setPermission = function (instanceId, requestId, action, userInput, callback) { + /// + /// + /// + /// + /// + /// + /// + callback({}); +}; + +chrome.webview.stop = function (instanceId) { + /// + /// + /// + //No Callback +}; + +chrome.webview.terminate = function (instanceId) { + /// + /// + /// + //No Callback +}; + +//#endregion +//#region Chrome.webViewRequest +chrome.webViewRequest = {}; +//#endregion +//#region Chrome.webviewTag +chrome.webviewTag = {}; +chrome.webviewTag.back = function () { + /// + /// Navigates backward one history entry if possible. Equivalent to go(-1). + /// + //No Callback +}; + +chrome.webviewTag.canGoBack = function () { + /// + /// Indicates whether or not it is possible to navigate backward through history. + /// + //No Callback + return true; +}; + +chrome.webviewTag.canGoForward = function () { + /// + /// Indicates whether or not it is possible to navigate forward through history. + /// + //No Callback + return true; +}; + +chrome.webviewTag.clearData = function (options, types, callback) { + /// + ///

Clears browsing data for the webview partition.

+ ///
+ /// Options determining exactly what data to clear. + /// The types of data to be cleared. + /// Called after the data has been successfully cleared. + callback(); +}; + +chrome.webviewTag.executeScript = function (details, callback) { + /// + ///

Injects JavaScript code into the guest page.

The following sample code uses script injection to set the guest page's background color to red:

webview.executeScript({ code: "document.body.bgColor = 'red'" });
+ ///
+ /// Details of the script to run. + /// Called after all the JavaScript has been executed. + callback({}); +}; + +chrome.webviewTag.forward = function () { + /// + /// Navigates forward one history entry if possible. Equivalent to go(1). + /// + //No Callback +}; + +chrome.webviewTag.getProcessId = function () { + /// + /// Returns Chrome's internal process ID for the guest web page's current process, allowing embedders to know how many guests would be affected by terminating the process. Two guests will share a process only if they belong to the same app and have the same storage partition ID. The call is synchronous and returns the embedder's cached notion of the current process ID. The process ID isn't the same as the operating system's process ID. + /// + //No Callback + return {}; +}; + +chrome.webviewTag.getUserAgent = function () { + /// + /// Returns the user agent string used by the webview for guest page requests. + /// + //No Callback + return ""; +}; + +chrome.webviewTag.go = function (relativeIndex) { + /// + /// Navigates to a history entry using a history index relative to the current navigation. If the requested navigation is impossible, this method has no effect. + /// + /// Relative history index to which the webview should be navigated. For example, a value of 2 will navigate forward 2 history entries if possible; a value of -3 will navigate backward 3 entries. + //No Callback +}; + +chrome.webviewTag.insertCSS = function (details, callback) { + /// + /// Injects CSS into the guest page. + /// + /// Details of the CSS to insert. + /// Called after the CSS has been inserted. + callback(); +}; + +chrome.webviewTag.isUserAgentOverridden = function () { + /// + /// Indicates whether or not the webview's user agent string has been overridden by ref:setUserAgentOverride + /// + //No Callback +}; + +chrome.webviewTag.reload = function () { + /// + /// Reloads the current top-level page. + /// + //No Callback +}; + +chrome.webviewTag.setUserAgentOverride = function (userAgent) { + /// + /// Override the user agent string used by the webview for guest page requests. + /// + /// The user agent string to use. + //No Callback +}; + +chrome.webviewTag.stop = function () { + /// + /// Stops loading the current <webview> navigation if in progress. + /// + //No Callback +}; + +chrome.webviewTag.terminate = function () { + /// + /// Forcibly kills the guest web page's renderer process. This may affect multiple webview tags in the current app if they share the same process, but it will not affect webview tags in other apps. + /// + //No Callback +}; + +//#region Chrome.webviewTag Events +chrome.webviewTag.close = { + addListener: function (callback) { + /// + /// Fired when the guest window attempts to close itself.

The following example code navigates the webview to about:blank when the guest attempts to close itself.

webview.addEventListener('close', function() {
+        ///   webview.src = 'about:blank';
+        /// });
+ ///
+ callback(); + } +}; + +chrome.webviewTag.consolemessage = { + addListener: function (callback) { + /// + /// Fired when the guest window logs a console message.

The following example code forwards all log messages to the embedder's console without regard for log level or other properties.

webview.addEventListener('consolemessage', function(e) {
+        ///   console.log('Guest page logged a message: ', e.message);
+        /// });
+ ///
+ callback({}, "", {}, ""); + } +}; + +chrome.webviewTag.contentload = { + addListener: function (callback) { + /// + /// Fired when the guest window fires a load event.

The following example code modifies the default font size of the guest's body element after the page loads:

webview.addEventListener('contentload', function() {
+        ///   webview.executeScript({ code: 'document.body.style.fontSize = "42px"' });
+        /// });
+ ///
+ callback(); + } +}; + +chrome.webviewTag.dialog = { + addListener: function (callback) { + /// + /// Fired when the guest window attempts to open a modal dialog via window.alert, window.confirm, or window.prompt.

Handling this event will block the guest process until each event listener returns or the dialog object becomes unreachable (if preventDefault() was called.)

The default behavior is to cancel the dialog.

+ ///
+ callback("", "", new chrome.DialogController()); + } +}; + +chrome.webviewTag.exit = { + addListener: function (callback) { + /// + /// Fired when the process rendering the guest web content has exited.

The following example code will show a farewell message whenever the guest page crashes:

webview.addEventListener('exit', function(e) {
+        ///   if (e.reason === 'crash') {
+        ///     webview.src = 'data:text/plain,Goodbye, world!';
+        ///   }
+        /// });
+ ///
+ callback({}, ""); + } +}; + +chrome.webviewTag.loadabort = { + addListener: function (callback) { + /// + /// Fired when a top-level load has aborted without committing. + /// + callback("", true, ""); + } +}; + +chrome.webviewTag.loadcommit = { + addListener: function (callback) { + /// + /// Fired when a load has committed. + /// + callback("", true); + } +}; + +chrome.webviewTag.loadredirect = { + addListener: function (callback) { + /// + /// Fired when a top-level load request has redirected to a different URL. + /// + callback("", "", true); + } +}; + +chrome.webviewTag.loadstart = { + addListener: function (callback) { + /// + /// Fired when a load has begun. + /// + callback("", true); + } +}; + +chrome.webviewTag.loadstop = { + addListener: function (callback) { + /// + /// Fired when all loads in the guest page (including all subframes) have completed. Fires in addition to any related loadcommit or loadabort events, which occur per-frame. + /// + callback(); + } +}; + +chrome.webviewTag.newwindow = { + addListener: function (callback) { + /// + /// Fired when the guest page attempts to open a new browser window.

The following example code will create and navigate a new webview in the embedder for each requested new window:

webview.addEventListener('newwindow', function(e) {
+        ///   var newWebview = document.createElement('webview');
+        ///   document.body.appendChild(newWebview);
+        ///   e.window.attach(newWebview);
+        /// });
+ ///
+ callback(new chrome.NewWindow(), "", 0, 0, "", ""); + } +}; + +chrome.webviewTag.permissionrequest = { + addListener: function (callback) { + /// + /// Fired when the guest page needs to request special permission from the embedder.

The following example code will grant the guest page access to the webkitGetUserMedia API. Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:

webview.addEventListener('permissionrequest', function(e) {
+        ///   if (e.permission === 'media') {
+        ///     e.request.allow();
+        ///   }
+        /// });
+ ///
+ callback("", {}, {}); + } +}; + +chrome.webviewTag.responsive = { + addListener: function (callback) { + /// + /// Fired when the process rendering the guest web content has become responsive again after being unresponsive.

The following example code will fade the webview element in or out as it becomes responsive or unresponsive:

webview.style.webkitTransition = 'opacity 250ms';
+        /// webview.addEventListener('unresponsive', function() {
+        ///   webview.style.opacity = '0.5';
+        /// });
+        /// webview.addEventListener('responsive', function() {
+        ///   webview.style.opacity = '1';
+        /// });
+ ///
+ callback({}); + } +}; + +chrome.webviewTag.sizechanged = { + addListener: function (callback) { + /// + /// Fired when the embedded web content has been resized. Only fires if autosize is enabled. + /// + callback(0, 0, 0, 0); + } +}; + +chrome.webviewTag.unresponsive = { + addListener: function (callback) { + /// + /// Fired when the process rendering the guest web content has become unresponsive. This event will be generated once with a matching responsive event if the guest begins to respond again. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.windows +chrome.windows = {}; +chrome.windows.get = function (windowId, getInfo, callback) { + /// + /// Gets details about a window. + /// + /// + /// + /// + callback(new chrome.Window()); +}; + +chrome.windows.getCurrent = function (getInfo, callback) { + /// + /// Gets the current window. + /// + /// + /// + callback(new chrome.Window()); +}; + +chrome.windows.getLastFocused = function (getInfo, callback) { + /// + /// Gets the window that was most recently focused — typically the window 'on top'. + /// + /// + /// + callback(new chrome.Window()); +}; + +chrome.windows.getAll = function (getInfo, callback) { + /// + /// Gets all windows. + /// + /// + /// + callback({}); +}; + +chrome.windows.create = function (createData, callback) { + /// + /// Creates (opens) a new browser with any optional sizing, position or default URL provided. + /// + /// + /// + callback(new chrome.Window()); +}; + +chrome.windows.update = function (windowId, updateInfo, callback) { + /// + /// Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged. + /// + /// + /// + /// + callback(new chrome.Window()); +}; + +chrome.windows.remove = function (windowId, callback) { + /// + /// Removes (closes) a window, and all the tabs inside it. + /// + /// + /// + callback(); +}; + +//#region Chrome.windows Events +chrome.windows.onCreated = { + addListener: function (callback) { + /// + /// Fired when a window is created. + /// + callback(new chrome.Window()); + } +}; + +chrome.windows.onRemoved = { + addListener: function (callback) { + /// + /// Fired when a window is removed (closed). + /// + callback({}); + } +}; + +chrome.windows.onFocusChanged = { + addListener: function (callback) { + /// + /// Fired when the currently focused window changes. Will be chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one chrome window to another. + /// + callback({}); + } +}; + +//#endregion +//#endregion +//#region Chrome.devtools.panels +chrome.devtools.panels = {}; +chrome.devtools.panels.create = function (title, iconPath, pagePath, callback) { + /// + /// Creates an extension panel. + /// + /// Title that is displayed next to the extension icon in the Developer Tools toolbar. + /// Path of the panel's icon relative to the extension directory. + /// Path of the panel's HTML page relative to the extension directory. + /// A function that is called when the panel is created. + callback(new chrome.ExtensionPanel()); +}; + +chrome.devtools.panels.setOpenResourceHandler = function (callback) { + /// + /// Specifies the function to be called when the user clicks a resource link in the Developer Tools window. To unset the handler, either call the method with no parameters or pass null as the parameter. + /// + /// A function that is called when the user clicks on a valid resource link in Developer Tools window. Note that if the user clicks an invalid URL or an XHR, this function is not called. + callback(new chrome.devtools.inspectedWindow.Resource()); +}; + +//#endregion +//#region Chrome.devtools.inspectedWindow +chrome.devtools.inspectedWindow = {}; +chrome.devtools.inspectedWindow.eval = function (expression, callback) { + /// + /// Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. + /// + /// An expression to evaluate. + /// A function called when evaluation completes. + callback({}, {}); +}; + +chrome.devtools.inspectedWindow.reload = function (reloadOptions) { + /// + /// Reloads the inspected page. + /// + /// + //No Callback +}; + +chrome.devtools.inspectedWindow.getResources = function (callback) { + /// + /// Retrieves the list of resources from the inspected page. + /// + /// A function that receives the list of resources when the request completes. + callback({}); +}; + +//#region Chrome.devtools.inspectedWindow Events +chrome.devtools.inspectedWindow.onResourceAdded = { + addListener: function (callback) { + /// + /// Fired when a new resource is added to the inspected page. + /// + callback(new chrome.Resource()); + } +}; + +chrome.devtools.inspectedWindow.onResourceContentCommitted = { + addListener: function (callback) { + /// + /// Fired when a new revision of the resource is committed (e.g. user saves an edited version of the resource in the Developer Tools). + /// + callback(new chrome.Resource(), ""); + } +}; + +//#endregion +//#endregion diff --git a/src/js/lib/dynBookmarks.js b/src/js/lib/dynBookmarks.js index 7eaf7e8..6987607 100644 --- a/src/js/lib/dynBookmarks.js +++ b/src/js/lib/dynBookmarks.js @@ -1,7 +1,6 @@ -/** - * Adapter - */ -import * as dbm from "./_dbm-2.5.x"; +/** Adapter **/ + +import * as dbm from "./storage/_dbm-2.5.x"; export function findAll(done) { dbm.findAll(done); diff --git a/src/js/lib/_dbm-2.5.x.js b/src/js/lib/storage/_dbm-2.5.x.js similarity index 97% rename from src/js/lib/_dbm-2.5.x.js rename to src/js/lib/storage/_dbm-2.5.x.js index e2938e0..a54d1bf 100644 --- a/src/js/lib/_dbm-2.5.x.js +++ b/src/js/lib/storage/_dbm-2.5.x.js @@ -1,6 +1,4 @@ -/** - * Collection of storage functions used in versions pre-2.6 - */ +/// export const dynBookmarksPropName = "dynBookmarks"; diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js new file mode 100644 index 0000000..5430896 --- /dev/null +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -0,0 +1,17 @@ +/// + +import { DynBookRepository } from "./_dbm-repository"; +export const dbmIdsPropName = "dbm_ids"; + +function _convertToDbmId(id) { + return `dbm_${id}`; +} + +class Dbm260 extends DynBookRepository { + constructor() { + this.storage = chrome.storage.sync; + } + create({ id = "", regExp = "", history = [] }, done) {} +} + +export default new Dbm260(); diff --git a/src/js/lib/storage/_dbm-repository.js b/src/js/lib/storage/_dbm-repository.js new file mode 100644 index 0000000..7e95b4d --- /dev/null +++ b/src/js/lib/storage/_dbm-repository.js @@ -0,0 +1,39 @@ +export class DynBookRepository { + /** + * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` + * @param {function} done - callback function called with (err, createdItem) + */ + create = (props, done) => {}; + + /**` + * @param {function} done - callback function called with `done(error, dynBook)` + */ + findAll = done => {}; + + /** + * @param {string} id - id of dynamic bookmark + * @param {function} done - callback function called with `done(error, dynBookItem)` + */ + findById = (id, done) => {}; + + /** + * @param {string} id - id of dynamic bookmark + * @param {function} done - callback function called with `done(error)` + */ + findByIdAndRemove = (id, done) => {}; + + /** + * @param {string} id - id of dynamic bookmark + * @param {object} options - `{regExp: String, history:[String]}` + * @param {function} done - (optional) callback function called with `done(error, updatedDynBookItem)` + */ + findByIdAndUpdate = (id, options, done) => {}; + + /** + * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` + * @param {function} done - callback function called with `done(error)` + */ + overwrite = (newDynBook, done) => {}; +} + +export default DynBookRepository; diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js new file mode 100644 index 0000000..c47bf00 --- /dev/null +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -0,0 +1,18 @@ +/// + +import { Migrator } from "./_migrator"; +import * as dbm25x from "../_dbm-2.5.x"; +import dbm260 from "../_dbm-2.6.0"; + +export class Migrator260 extends Migrator { + up() { + dbm25x.findAll((err, dynBook = {}) => { + if (err) { + return console.warn(err); + } + }); + } + down() {} +} + +export default new Migrator260(); diff --git a/src/js/migrations/_migrator.js b/src/js/lib/storage/migrations/_migrator.js similarity index 100% rename from src/js/migrations/_migrator.js rename to src/js/lib/storage/migrations/_migrator.js diff --git a/src/js/migrations/index.js b/src/js/lib/storage/migrations/index.js similarity index 100% rename from src/js/migrations/index.js rename to src/js/lib/storage/migrations/index.js diff --git a/src/js/migrations/_migration-2.6.0.js b/src/js/migrations/_migration-2.6.0.js deleted file mode 100644 index b02dbaa..0000000 --- a/src/js/migrations/_migration-2.6.0.js +++ /dev/null @@ -1,11 +0,0 @@ -import { Migrator } from "./_migrator"; -import * as dbm_2_5 from "../lib/_dbm-2.5.x"; - -export class Migrator260 extends Migrator { - up() { - dbm_2_5.findAll((err, dynBook) => {}); - } - down() {} -} - -export default new Migrator260(); From a6b7b4cfde600a89835f2cffed33e7c7286949f8 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 15:56:15 +0200 Subject: [PATCH 03/15] finished writing overwrite function in _dbm-2.6.0 --- src/js/lib/storage/_dbm-2.6.0.js | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 5430896..f2d172d 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -4,14 +4,65 @@ import { DynBookRepository } from "./_dbm-repository"; export const dbmIdsPropName = "dbm_ids"; function _convertToDbmId(id) { + if (/^dbm_\d+$/.test(id)) { + return id; + } return `dbm_${id}`; } +function _cloneWithMappedKeys(obj = {}, keyMap = _convertToDbmId) { + let retVal = {}; + for (let key in obj) { + let dbmId = keyMap(key); + retVal[dbmId] = obj[key]; + } + return retVal; +} + +/** + * Checks if there is an error, if found calls callback function and returns `true` else `false` + * @param {function} onErrorFound - callback to call if error was found + */ +function _checkAndHandleError(onErrorFound = errMsg => console.error(errMsg)) { + if (chrome.runtime.lastError) { + onErrorFound(chrome.runtime.lastError.message); + return true; + } + return false; +} + class Dbm260 extends DynBookRepository { constructor() { this.storage = chrome.storage.sync; } create({ id = "", regExp = "", history = [] }, done) {} + overwrite(newDynBook = {}, done) { + const newDynBookMapped = _cloneWithMappedKeys(newDynBook); + this.storage.get([dbmIdsPropName], response => { + if (_checkAndHandleError()) { + return; + } + // Remove ids not found in newDynBook + const dbmIds = response[dbmIdsPropName] || []; + const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); + if (idsToRemove.length > 0) { + this.storage.remove(idsToRemove, () => _checkAndHandleError()); + } + + // Update storage items + const newKeys = Object.keys(newDynBookMapped); + this.storage.set( + { [dbmIdsPropName]: newKeys, ...newDynBookMapped }, + () => { + if (_checkAndHandleError(done)) { + return; + } else { + done(null); + } + } + ); + }); + } } export default new Dbm260(); From 5becf221239321397187c7f77c85e2532db82e7a Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 16:00:43 +0200 Subject: [PATCH 04/15] Implemented Migrator260's up method --- src/js/background.js | 11 +++++++---- src/js/lib/storage/migrations/_migration-2.6.0.js | 15 ++++++++++++--- src/js/lib/storage/migrations/_migrator.js | 4 ++-- src/js/lib/storage/migrations/index.js | 8 ++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 02be246..4e2e30a 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -1,4 +1,7 @@ -import * as dbm from './lib/dynBookmarks'; +import * as dbm from "./lib/dynBookmarks"; +import { migrateStorage } from "./lib/storage/migrations"; + +migrateStorage(); chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (!changeInfo.url) return; @@ -30,8 +33,8 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { }); }); -chrome.bookmarks.onRemoved.addListener((id) => { - dbm.findByIdAndRemove(id, (err) => { +chrome.bookmarks.onRemoved.addListener(id => { + dbm.findByIdAndRemove(id, err => { if (err) { console.warn(err); } else { @@ -54,7 +57,7 @@ chrome.bookmarks.onChanged.addListener((id, changeInfo) => { dynBook[id].history.pop(); } dynBook[id].history.unshift(changeInfo.url); - dbm.overwrite(dynBook, (err) => { + dbm.overwrite(dynBook, err => { if (err) { console.warn(err); } diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js index c47bf00..94eff69 100644 --- a/src/js/lib/storage/migrations/_migration-2.6.0.js +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -4,15 +4,24 @@ import { Migrator } from "./_migrator"; import * as dbm25x from "../_dbm-2.5.x"; import dbm260 from "../_dbm-2.6.0"; +function _logError(errMsg) { + if (errMsg) { + console.error(errMsg); + } +} + export class Migrator260 extends Migrator { - up() { + up(done = _logError) { dbm25x.findAll((err, dynBook = {}) => { if (err) { - return console.warn(err); + return done(err); } + dbm260.overwrite(dynBook, done); }); } - down() {} + down(done = _logError) { + done(null); + } } export default new Migrator260(); diff --git a/src/js/lib/storage/migrations/_migrator.js b/src/js/lib/storage/migrations/_migrator.js index 67972f4..2399ce6 100644 --- a/src/js/lib/storage/migrations/_migrator.js +++ b/src/js/lib/storage/migrations/_migrator.js @@ -1,8 +1,8 @@ export class Migrator { /**Execute migration */ - up = () => {}; + up = done => {}; /**Undo migration */ - down = () => {}; + down = done => {}; } export default Migrator; diff --git a/src/js/lib/storage/migrations/index.js b/src/js/lib/storage/migrations/index.js index 261ee0b..9c7cb58 100644 --- a/src/js/lib/storage/migrations/index.js +++ b/src/js/lib/storage/migrations/index.js @@ -3,6 +3,10 @@ import migrator_260 from "./_migration-2.6.0"; /** * Used to migrate data to new storage when updating application */ -export function migrate() { - migrator_260.up(); +export function migrateStorage() { + migrator_260.up(err => { + if (err) { + console.error(err); + } + }); } From 4de022b35e3296c773a43eb22bb9d927aa062a4a Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 16:23:12 +0200 Subject: [PATCH 05/15] Added @babel/plugin-proposal-class-properties which allow modern class syntax to be used in classes --- package-lock.json | 144 ++++++++++++++---- package.json | 1 + src/js/lib/storage/_dbm-2.5.x.js | 28 +++- .../storage/migrations/_migration-2.6.0.js | 8 + webpack.config.js | 7 +- 5 files changed, 151 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9fb710c..de2f9aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -78,6 +78,99 @@ "@babel/types": "^7.4.4" } }, + "@babel/helper-create-class-features-plugin": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.5.5.tgz", + "integrity": "sha512-ZsxkyYiRA7Bg+ZTRpPvB6AbOFKTFFK4LrvTet8lInm0V468MWCaSYJE+I7v2z2r8KNLtYiV+K5kTCnR7dvyZjg==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-member-expression-to-functions": "^7.5.5", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.5.5", + "@babel/helper-split-export-declaration": "^7.4.4" + }, + "dependencies": { + "@babel/code-frame": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", + "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==", + "dev": true, + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/generator": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.5.tgz", + "integrity": "sha512-ETI/4vyTSxTzGnU2c49XHv2zhExkv9JHLTwDAFz85kmcwuShvYG2H08FwgIguQf4JC75CBnXAUM5PqeF4fj0nQ==", + "dev": true, + "requires": { + "@babel/types": "^7.5.5", + "jsesc": "^2.5.1", + "lodash": "^4.17.13", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.5.5.tgz", + "integrity": "sha512-5qZ3D1uMclSNqYcXqiHoA0meVdv+xUEex9em2fqMnrk/scphGlGgg66zjMrPJESPwrFJ6sbfFQYUSa0Mz7FabA==", + "dev": true, + "requires": { + "@babel/types": "^7.5.5" + } + }, + "@babel/helper-replace-supers": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.5.5.tgz", + "integrity": "sha512-XvRFWrNnlsow2u7jXDuH4jDDctkxbS7gXssrP4q2nUD606ukXHRvydj346wmNg+zAgpFx4MWf4+usfC93bElJg==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.5.5", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/traverse": "^7.5.5", + "@babel/types": "^7.5.5" + } + }, + "@babel/parser": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.5.tgz", + "integrity": "sha512-E5BN68cqR7dhKan1SfqgPGhQ178bkVKpXTPEXnFJBrEt8/DKRZlybmy+IgYLTeN7tp1R5Ccmbm2rBk17sHYU3g==", + "dev": true + }, + "@babel/traverse": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.5.tgz", + "integrity": "sha512-MqB0782whsfffYfSjH4TM+LMjrJnhCNEDMDIjeTpl+ASaUvxcjoiVCo/sM1GhS1pHOXYfWVCYneLjMckuUxDaQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.5.5", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.5.5", + "@babel/types": "^7.5.5", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.13" + } + }, + "@babel/types": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.5.tgz", + "integrity": "sha512-s63F9nJioLqOlW3UkyMd+BYhXt44YuaFm/VV0VwuteqjYwRrObkU7ra9pY4wAJR3oXi8hJrMcrcJdO/HH33vtw==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.13", + "to-fast-properties": "^2.0.0" + } + } + } + }, "@babel/helper-define-map": { "version": "7.4.4", "resolved": "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.4.4.tgz", @@ -279,6 +372,16 @@ "@babel/plugin-syntax-async-generators": "^7.2.0" } }, + "@babel/plugin-proposal-class-properties": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.5.5.tgz", + "integrity": "sha512-AF79FsnWFxjlaosgdi421vmYG6/jg79bVD0dpD44QdgobzHKuLZ6S3vl8la9qIeSwGi8i1fS0O1mfuDAAdo1/A==", + "dev": true, + "requires": { + "@babel/helper-create-class-features-plugin": "^7.5.5", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, "@babel/plugin-proposal-dynamic-import": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.5.0.tgz", @@ -2925,8 +3028,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -2947,14 +3049,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2969,20 +3069,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3099,8 +3196,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3112,7 +3208,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3127,7 +3222,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3135,14 +3229,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3161,7 +3253,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3242,8 +3333,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3255,7 +3345,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3341,8 +3430,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -3378,7 +3466,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3398,7 +3485,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3442,14 +3528,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/package.json b/package.json index 0d02f27..0377912 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "devDependencies": { "@babel/core": "^7.5.4", + "@babel/plugin-proposal-class-properties": "^7.5.5", "@babel/preset-env": "^7.5.4", "babel-loader": "^8.0.6", "buffer": "^5.2.1", diff --git a/src/js/lib/storage/_dbm-2.5.x.js b/src/js/lib/storage/_dbm-2.5.x.js index a54d1bf..c32f8ef 100644 --- a/src/js/lib/storage/_dbm-2.5.x.js +++ b/src/js/lib/storage/_dbm-2.5.x.js @@ -6,7 +6,7 @@ export const dynBookmarksPropName = "dynBookmarks"; * finds dynBook object in hash map form: `{ bookmark_id: { regExp:String, history:[String] } }` * @param {function} done - callback function called with `done(error, dynBook)` */ -export function findAll(done) { +export function findAll(done = _logError) { chrome.storage.sync.get([dynBookmarksPropName], result => { if (chrome.runtime.lastError) { done(chrome.runtime.lastError.message); @@ -22,7 +22,7 @@ export function findAll(done) { * @param {string} id - id of dynamic bookmark * @param {function} done - callback function called with `done(error, dynBookItem)` */ -export function findById(id, done) { +export function findById(id, done = _logError) { findAll((err, dynBook) => { if (err) done(err); else done(null, dynBook[id]); @@ -35,7 +35,7 @@ export function findById(id, done) { * @param {object} options - `{regExp: String, history:[String]}` * @param {function} done - (optional) callback function called with done(error, updatedDynBookItem) */ -export function findByIdAndUpdate(id, options, done) { +export function findByIdAndUpdate(id, options, done = _logError) { findAll((err, dynBook) => { if (err) { if (typeof done == "function") { @@ -64,7 +64,7 @@ export function findByIdAndUpdate(id, options, done) { * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` * @param {function} done - callback function called with done(error) */ -export function overwrite(newDynBook, done) { +export function overwrite(newDynBook, done = _logError) { chrome.storage.sync.set({ [dynBookmarksPropName]: newDynBook }, () => { if (typeof done == "function") { if (chrome.runtime.lastError) { @@ -81,7 +81,7 @@ export function overwrite(newDynBook, done) { * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` * @param {function} done - callback function called with (err, createdItem) */ -export function create(props, done) { +export function create(props, done = _logError) { if (!props.id || !props.regExp) { done("id or regExp props are missing in dynBookmarks.create!"); } @@ -95,7 +95,7 @@ export function create(props, done) { ); } -export function findByIdAndRemove(id, done) { +export function findByIdAndRemove(id, done = _logError) { findAll((err, dynBook) => { if (err) { if (typeof done == "function") { @@ -109,3 +109,19 @@ export function findByIdAndRemove(id, done) { } }); } + +export function clearAll(done = _logError) { + chrome.storage.sync.remove([dynBookmarksPropName], () => { + if (chrome.runtime.lastError) { + done(chrome.runtime.lastError.message); + } else { + done(null); + } + }); +} + +function _logError(errMsg) { + if (errMsg) { + console.error(errMsg); + } +} diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js index 94eff69..929d2d8 100644 --- a/src/js/lib/storage/migrations/_migration-2.6.0.js +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -10,13 +10,21 @@ function _logError(errMsg) { } } +function _isMigrated(dynBook) { + return Object.keys(dynBook).length == 0; +} + export class Migrator260 extends Migrator { up(done = _logError) { dbm25x.findAll((err, dynBook = {}) => { if (err) { return done(err); } + if (_isMigrated(dynBook)) { + return done(null); + } dbm260.overwrite(dynBook, done); + dbm25x.clearAll(); }); } down(done = _logError) { diff --git a/webpack.config.js b/webpack.config.js index c97cf54..4e59784 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -53,7 +53,12 @@ const options = { use: { loader: "babel-loader", options: { - presets: ["@babel/preset-env"] + presets: [ + "@babel/preset-env", + { + plugins: ["@babel/plugin-proposal-class-properties"] + } + ] } } }, From 15f26558b7b55e318bed3b191b9803df316b9768 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Tue, 27 Aug 2019 16:29:45 +0200 Subject: [PATCH 06/15] improved migration function --- src/js/lib/storage/_dbm-2.5.x.js | 4 ++++ src/js/lib/storage/migrations/_migration-2.6.0.js | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/lib/storage/_dbm-2.5.x.js b/src/js/lib/storage/_dbm-2.5.x.js index c32f8ef..992ea9b 100644 --- a/src/js/lib/storage/_dbm-2.5.x.js +++ b/src/js/lib/storage/_dbm-2.5.x.js @@ -110,6 +110,10 @@ export function findByIdAndRemove(id, done = _logError) { }); } +/** + * Removes DynBookmarks object from `chrome.storage.sync` + * @param {function} done - callback function called with `done(errMsg)` + */ export function clearAll(done = _logError) { chrome.storage.sync.remove([dynBookmarksPropName], () => { if (chrome.runtime.lastError) { diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js index 929d2d8..0674ffa 100644 --- a/src/js/lib/storage/migrations/_migration-2.6.0.js +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -23,8 +23,12 @@ export class Migrator260 extends Migrator { if (_isMigrated(dynBook)) { return done(null); } - dbm260.overwrite(dynBook, done); - dbm25x.clearAll(); + dbm25x.clearAll(errMsg => { + if (errMsg) { + return done(errMsg); + } + dbm260.overwrite(dynBook, done); + }); }); } down(done = _logError) { From 136c8280509c787cba8f649872cfaae60e249351 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 13:16:02 +0200 Subject: [PATCH 07/15] fixed bugs with migrations (inheritence in JavaScript is very weird so i just removed it) --- package.json | 2 +- src/js/lib/storage/_dbm-2.6.0.js | 52 +++++++++++-------- .../storage/migrations/_migration-2.6.0.js | 32 ++++++++---- src/js/lib/storage/migrations/_migrator.js | 8 --- src/js/lib/storage/migrations/index.js | 20 ++++--- 5 files changed, 68 insertions(+), 46 deletions(-) delete mode 100644 src/js/lib/storage/migrations/_migrator.js diff --git a/package.json b/package.json index 0377912..186a36f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-dynamic-bookmarks", - "version": "2.6.0", + "version": "2.6.1", "description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.", "scripts": { "dev": "webpack --mode development", diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index f2d172d..846d9c0 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -31,38 +31,48 @@ function _checkAndHandleError(onErrorFound = errMsg => console.error(errMsg)) { return false; } -class Dbm260 extends DynBookRepository { - constructor() { - this.storage = chrome.storage.sync; +class Dbm260 { + constructor(storage = chrome.storage.sync) { + this.storage = storage; } create({ id = "", regExp = "", history = [] }, done) {} overwrite(newDynBook = {}, done) { const newDynBookMapped = _cloneWithMappedKeys(newDynBook); + console.log("dynBookMapped", newDynBookMapped); this.storage.get([dbmIdsPropName], response => { if (_checkAndHandleError()) { return; } - // Remove ids not found in newDynBook - const dbmIds = response[dbmIdsPropName] || []; - const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); - if (idsToRemove.length > 0) { - this.storage.remove(idsToRemove, () => _checkAndHandleError()); - } + const idsToRemove = this._getIdsToRemove(response, newDynBookMapped); + this._removeIds(idsToRemove); + this._updateStorageItems(newDynBookMapped, done); + }); + } - // Update storage items - const newKeys = Object.keys(newDynBookMapped); - this.storage.set( - { [dbmIdsPropName]: newKeys, ...newDynBookMapped }, - () => { - if (_checkAndHandleError(done)) { - return; - } else { - done(null); - } - } - ); + _updateStorageItems(newDynBookMapped, done) { + console.log("Updating storage items to ", newDynBookMapped); + const newKeys = Object.keys(newDynBookMapped); + this.storage.set({ [dbmIdsPropName]: newKeys, ...newDynBookMapped }, () => { + if (_checkAndHandleError(done)) { + return; + } else { + done(null); + } }); } + + _getIdsToRemove(response, newDynBookMapped) { + const dbmIds = response[dbmIdsPropName] || []; + const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); + return idsToRemove; + } + + _removeIds(idsToRemove) { + console.log("Removing ids: ", idsToRemove); + if (idsToRemove.length > 0) { + this.storage.remove(idsToRemove, () => _checkAndHandleError()); + } + } } export default new Dbm260(); diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js index 0674ffa..e93a752 100644 --- a/src/js/lib/storage/migrations/_migration-2.6.0.js +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -1,6 +1,5 @@ /// -import { Migrator } from "./_migrator"; import * as dbm25x from "../_dbm-2.5.x"; import dbm260 from "../_dbm-2.6.0"; @@ -14,25 +13,38 @@ function _isMigrated(dynBook) { return Object.keys(dynBook).length == 0; } -export class Migrator260 extends Migrator { +export class Migrator260 { up(done = _logError) { + console.log("Running 2.6.0 migration..."); dbm25x.findAll((err, dynBook = {}) => { if (err) { return done(err); } if (_isMigrated(dynBook)) { + console.log("Data is already migrated."); return done(null); } - dbm25x.clearAll(errMsg => { - if (errMsg) { - return done(errMsg); - } - dbm260.overwrite(dynBook, done); - }); + this._moveToNewStorage(dynBook, done); }); } - down(done = _logError) { - done(null); + _moveToNewStorage(dynBook, done) { + dbm260.overwrite(dynBook, errMsg => { + if (errMsg) { + return done(errMsg); + } + console.log("Finished moving data to new storage."); + this._removeOldStorage(done); + }); + } + + _removeOldStorage(done) { + console.log("Removing old storage..."); + dbm25x.clearAll(errMsg => { + if (errMsg) { + return done(errMsg); + } + done(null); + }); } } diff --git a/src/js/lib/storage/migrations/_migrator.js b/src/js/lib/storage/migrations/_migrator.js deleted file mode 100644 index 2399ce6..0000000 --- a/src/js/lib/storage/migrations/_migrator.js +++ /dev/null @@ -1,8 +0,0 @@ -export class Migrator { - /**Execute migration */ - up = done => {}; - /**Undo migration */ - down = done => {}; -} - -export default Migrator; diff --git a/src/js/lib/storage/migrations/index.js b/src/js/lib/storage/migrations/index.js index 9c7cb58..980c630 100644 --- a/src/js/lib/storage/migrations/index.js +++ b/src/js/lib/storage/migrations/index.js @@ -1,12 +1,20 @@ -import migrator_260 from "./_migration-2.6.0"; +import { Migrator260 } from "./_migration-2.6.0"; /** * Used to migrate data to new storage when updating application */ export function migrateStorage() { - migrator_260.up(err => { - if (err) { - console.error(err); - } - }); + console.log("Running migrations..."); + try { + let migrator_260 = new Migrator260(); + migrator_260.up(err => { + if (err) { + console.error(err); + } else { + console.log("Finished migrating the data to 2.6.x storage"); + } + }); + } catch (e) { + console.error(e); + } } From af09406217d5bd2893ac5de831fab9d449b524b2 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 14:58:43 +0200 Subject: [PATCH 08/15] refactored and implemented most of Dbm260 functionality --- src/js/lib/storage/_dbm-2.6.0.js | 161 ++++++++++++++++++++++--------- src/js/utils/log/index.js | 24 +++++ 2 files changed, 142 insertions(+), 43 deletions(-) create mode 100644 src/js/utils/log/index.js diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 846d9c0..77a3f36 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -1,46 +1,75 @@ /// - -import { DynBookRepository } from "./_dbm-repository"; +import { logError, checkAndHandleError } from "../../utils/log"; export const dbmIdsPropName = "dbm_ids"; -function _convertToDbmId(id) { - if (/^dbm_\d+$/.test(id)) { - return id; +class Dbm260 { + constructor(storage = chrome.storage.sync) { + this.storage = storage; } - return `dbm_${id}`; -} -function _cloneWithMappedKeys(obj = {}, keyMap = _convertToDbmId) { - let retVal = {}; - for (let key in obj) { - let dbmId = keyMap(key); - retVal[dbmId] = obj[key]; - } - return retVal; -} + /**` + * @param {function} done - callback function called with `done(error, dynBook)` + */ + findAll = done => {}; -/** - * Checks if there is an error, if found calls callback function and returns `true` else `false` - * @param {function} onErrorFound - callback to call if error was found - */ -function _checkAndHandleError(onErrorFound = errMsg => console.error(errMsg)) { - if (chrome.runtime.lastError) { - onErrorFound(chrome.runtime.lastError.message); - return true; - } - return false; -} + /** + * @param {string} id - id of dynamic bookmark + * @param {function} done - callback function called with `done(error, dynBookItem)` + */ + findById = (id, done) => { + const key = _convertToDbmId(id); + this.storage.get([key], result => { + if (!checkAndHandleError(done)) { + done(null, result[key]); + } + }); + }; -class Dbm260 { - constructor(storage = chrome.storage.sync) { - this.storage = storage; + /** + * @param {string} id - id of dynamic bookmark + * @param {function} done - callback function called with `done(error)` + */ + findByIdAndRemove = (id, done) => { + const key = _convertToDbmId(id); + this.storage.remove([key], () => { + if (!checkAndHandleError(done)) { + done(null); + } + }); + }; + + /** + * @param {string} id - id of dynamic bookmark + * @param {object} options - `{regExp: String, history:[String]}` + * @param {function} done - (optional) callback function called with `done(error, updatedDynBookItem)` + */ + findByIdAndUpdate = (id, { regExp, history }, done) => { + const key = _convertToDbmId(id); + this.findById(key, (errMsg, item) => { + if (errMsg) return done(errMsg); + item = { + regExp: regExp || item.regExp, + history: history || item.history + }; + this._setItem(key, item, done); + }); + }; + + create({ id = "", regExp = "", history = [] }, done) { + const key = _convertToDbmId(id); + this._setItem(key, { regExp, history }, done); } - create({ id = "", regExp = "", history = [] }, done) {} + /** + * Overwrites dynamic bookmarks object from storage with `newDynBook`. + * `Warning`: This function is DANGEROUS! Potential data loss! + * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` + * @param {function} done - callback function called with done(error) + */ overwrite(newDynBook = {}, done) { const newDynBookMapped = _cloneWithMappedKeys(newDynBook); console.log("dynBookMapped", newDynBookMapped); this.storage.get([dbmIdsPropName], response => { - if (_checkAndHandleError()) { + if (checkAndHandleError()) { return; } const idsToRemove = this._getIdsToRemove(response, newDynBookMapped); @@ -49,30 +78,76 @@ class Dbm260 { }); } + _getIdsToRemove(response, newDynBookMapped) { + const dbmIds = response[dbmIdsPropName] || []; + const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); + return idsToRemove; + } + + _removeIds(idsToRemove) { + console.log("Removing ids: ", idsToRemove); + if (idsToRemove.length > 0) { + this.storage.remove(idsToRemove, () => checkAndHandleError()); + } + } _updateStorageItems(newDynBookMapped, done) { console.log("Updating storage items to ", newDynBookMapped); const newKeys = Object.keys(newDynBookMapped); this.storage.set({ [dbmIdsPropName]: newKeys, ...newDynBookMapped }, () => { - if (_checkAndHandleError(done)) { - return; - } else { + if (!checkAndHandleError(done)) { done(null); } }); } - _getIdsToRemove(response, newDynBookMapped) { - const dbmIds = response[dbmIdsPropName] || []; - const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); - return idsToRemove; + /** + * Adds `key` if it doesn't already exist to `dbm_ids` + * @param {string} key - Key to add + * @param {function} done - Callback function called with `done(errMsg)` + */ + _addKeyToDbmIds(key, done) { + this.storage.get([dbmIdsPropName], result => { + if (checkAndHandleError(done)) { + return; + } + let ids = result[dbmIdsPropName] || []; + if (ids.includes(key)) { + return done(null); + } + ids.push(key); + this._setItem(dbmIdsPropName, ids, done); + }); } - _removeIds(idsToRemove) { - console.log("Removing ids: ", idsToRemove); - if (idsToRemove.length > 0) { - this.storage.remove(idsToRemove, () => _checkAndHandleError()); - } + /** + * Sets `item` as `{[key]: item}` in `storage`. + * @param {function} done - callback function called with `done(errMsg, storageItem)` + */ + _setItem(key, item, done) { + this.storage.set({ [key]: item }, () => { + if (!checkAndHandleError(done)) { + this._addKeyToDbmIds(key, errMsg => { + done(errMsg, item); + }); + } + }); } } +function _convertToDbmId(id) { + if (/^dbm_.*/.test(id)) { + return id; + } + return `dbm_${id}`; +} + +function _cloneWithMappedKeys(obj = {}, keyMap = _convertToDbmId) { + let retVal = {}; + for (let key in obj) { + let dbmId = keyMap(key); + retVal[dbmId] = obj[key]; + } + return retVal; +} + export default new Dbm260(); diff --git a/src/js/utils/log/index.js b/src/js/utils/log/index.js new file mode 100644 index 0000000..e14e6c0 --- /dev/null +++ b/src/js/utils/log/index.js @@ -0,0 +1,24 @@ +export function logError(errMsg) { + if (errMsg) { + console.error(errMsg); + } +} +export function logWarn(msg) { + if (msg) { + console.warn(msg); + } +} + +/** + * Checks if there is an error, if found calls callback function and returns `true` else `false` + * @param {function} onErrorFound - callback to call if error was found + */ +export function checkAndHandleError( + onErrorFound = errMsg => console.error(errMsg) +) { + if (chrome.runtime.lastError) { + onErrorFound(chrome.runtime.lastError.message); + return true; + } + return false; +} From c8991545ad13cde9843f90083104ae50a7a4c552 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 15:04:48 +0200 Subject: [PATCH 09/15] Refactored files to use logError messages from utils/log instead of their own _logError in each file --- src/js/lib/storage/_dbm-2.5.x.js | 21 +++++++------------ src/js/lib/storage/_dbm-2.6.0.js | 3 ++- .../storage/migrations/_migration-2.6.0.js | 9 ++------ src/js/lib/storage/migrations/index.js | 2 +- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/js/lib/storage/_dbm-2.5.x.js b/src/js/lib/storage/_dbm-2.5.x.js index 992ea9b..d7a64ee 100644 --- a/src/js/lib/storage/_dbm-2.5.x.js +++ b/src/js/lib/storage/_dbm-2.5.x.js @@ -1,4 +1,5 @@ /// +import { logError } from "../../utils/log"; export const dynBookmarksPropName = "dynBookmarks"; @@ -6,7 +7,7 @@ export const dynBookmarksPropName = "dynBookmarks"; * finds dynBook object in hash map form: `{ bookmark_id: { regExp:String, history:[String] } }` * @param {function} done - callback function called with `done(error, dynBook)` */ -export function findAll(done = _logError) { +export function findAll(done = logError) { chrome.storage.sync.get([dynBookmarksPropName], result => { if (chrome.runtime.lastError) { done(chrome.runtime.lastError.message); @@ -22,7 +23,7 @@ export function findAll(done = _logError) { * @param {string} id - id of dynamic bookmark * @param {function} done - callback function called with `done(error, dynBookItem)` */ -export function findById(id, done = _logError) { +export function findById(id, done = logError) { findAll((err, dynBook) => { if (err) done(err); else done(null, dynBook[id]); @@ -35,7 +36,7 @@ export function findById(id, done = _logError) { * @param {object} options - `{regExp: String, history:[String]}` * @param {function} done - (optional) callback function called with done(error, updatedDynBookItem) */ -export function findByIdAndUpdate(id, options, done = _logError) { +export function findByIdAndUpdate(id, options, done = logError) { findAll((err, dynBook) => { if (err) { if (typeof done == "function") { @@ -64,7 +65,7 @@ export function findByIdAndUpdate(id, options, done = _logError) { * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` * @param {function} done - callback function called with done(error) */ -export function overwrite(newDynBook, done = _logError) { +export function overwrite(newDynBook, done = logError) { chrome.storage.sync.set({ [dynBookmarksPropName]: newDynBook }, () => { if (typeof done == "function") { if (chrome.runtime.lastError) { @@ -81,7 +82,7 @@ export function overwrite(newDynBook, done = _logError) { * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` * @param {function} done - callback function called with (err, createdItem) */ -export function create(props, done = _logError) { +export function create(props, done = logError) { if (!props.id || !props.regExp) { done("id or regExp props are missing in dynBookmarks.create!"); } @@ -95,7 +96,7 @@ export function create(props, done = _logError) { ); } -export function findByIdAndRemove(id, done = _logError) { +export function findByIdAndRemove(id, done = logError) { findAll((err, dynBook) => { if (err) { if (typeof done == "function") { @@ -114,7 +115,7 @@ export function findByIdAndRemove(id, done = _logError) { * Removes DynBookmarks object from `chrome.storage.sync` * @param {function} done - callback function called with `done(errMsg)` */ -export function clearAll(done = _logError) { +export function clearAll(done = logError) { chrome.storage.sync.remove([dynBookmarksPropName], () => { if (chrome.runtime.lastError) { done(chrome.runtime.lastError.message); @@ -123,9 +124,3 @@ export function clearAll(done = _logError) { } }); } - -function _logError(errMsg) { - if (errMsg) { - console.error(errMsg); - } -} diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 77a3f36..374ac77 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -1,5 +1,6 @@ /// -import { logError, checkAndHandleError } from "../../utils/log"; +import { checkAndHandleError } from "../../utils/log"; + export const dbmIdsPropName = "dbm_ids"; class Dbm260 { diff --git a/src/js/lib/storage/migrations/_migration-2.6.0.js b/src/js/lib/storage/migrations/_migration-2.6.0.js index e93a752..edbcf44 100644 --- a/src/js/lib/storage/migrations/_migration-2.6.0.js +++ b/src/js/lib/storage/migrations/_migration-2.6.0.js @@ -2,19 +2,14 @@ import * as dbm25x from "../_dbm-2.5.x"; import dbm260 from "../_dbm-2.6.0"; - -function _logError(errMsg) { - if (errMsg) { - console.error(errMsg); - } -} +import { logError } from "../../../utils/log"; function _isMigrated(dynBook) { return Object.keys(dynBook).length == 0; } export class Migrator260 { - up(done = _logError) { + up(done = logError) { console.log("Running 2.6.0 migration..."); dbm25x.findAll((err, dynBook = {}) => { if (err) { diff --git a/src/js/lib/storage/migrations/index.js b/src/js/lib/storage/migrations/index.js index 980c630..a1c6c83 100644 --- a/src/js/lib/storage/migrations/index.js +++ b/src/js/lib/storage/migrations/index.js @@ -11,7 +11,7 @@ export function migrateStorage() { if (err) { console.error(err); } else { - console.log("Finished migrating the data to 2.6.x storage"); + console.log("Finished migrating the data to 2.6.x storage."); } }); } catch (e) { From fb0be962d38a265c273708f16d3fd58af162a427 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 15:15:33 +0200 Subject: [PATCH 10/15] implemented findAll function and made additional refactorings --- src/js/lib/storage/_dbm-2.6.0.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 374ac77..3d38df7 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -11,7 +11,16 @@ class Dbm260 { /**` * @param {function} done - callback function called with `done(error, dynBook)` */ - findAll = done => {}; + findAll = done => { + this._getAllIds((errMsg, ids = []) => { + if (errMsg) return done(errMsg); + this.storage.get(ids, result => { + if (!checkAndHandleError(done)) { + done(null, result); + } + }); + }); + }; /** * @param {string} id - id of dynamic bookmark @@ -69,18 +78,22 @@ class Dbm260 { overwrite(newDynBook = {}, done) { const newDynBookMapped = _cloneWithMappedKeys(newDynBook); console.log("dynBookMapped", newDynBookMapped); - this.storage.get([dbmIdsPropName], response => { - if (checkAndHandleError()) { - return; - } - const idsToRemove = this._getIdsToRemove(response, newDynBookMapped); + this._getAllIds((errMsg, ids = []) => { + if (errMsg) return done(errMsg); + const idsToRemove = this._getIdsToRemove(ids, newDynBookMapped); this._removeIds(idsToRemove); this._updateStorageItems(newDynBookMapped, done); }); } - - _getIdsToRemove(response, newDynBookMapped) { - const dbmIds = response[dbmIdsPropName] || []; + _getAllIds(done) { + this.storage.get([dbmIdsPropName], result => { + if (!checkAndHandleError(done)) { + const ids = result[dbmIdsPropName] || []; + done(null, ids); + } + }); + } + _getIdsToRemove(dbmIds = [], newDynBookMapped = {}) { const idsToRemove = dbmIds.filter(key => !(key in newDynBookMapped)); return idsToRemove; } From 8a5435f46885ccd32a686474cbf402e32be4738e Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 15:41:58 +0200 Subject: [PATCH 11/15] fixed recursion bug --- src/js/lib/storage/_dbm-2.6.0.js | 48 ++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 3d38df7..6177e2a 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -16,7 +16,8 @@ class Dbm260 { if (errMsg) return done(errMsg); this.storage.get(ids, result => { if (!checkAndHandleError(done)) { - done(null, result); + const dynBook = _cloneWithMappedKeys(result, _convertToBookmarkId); + done(null, dynBook); } }); }); @@ -43,7 +44,7 @@ class Dbm260 { const key = _convertToDbmId(id); this.storage.remove([key], () => { if (!checkAndHandleError(done)) { - done(null); + this._removeKeyFromDbmIds(key, done); } }); }; @@ -65,15 +66,25 @@ class Dbm260 { }); }; + /** + * Creates dynBookmark item and sets it into the storage + * @param {object} props - `{id:String, regExp:String, history:[String] (optional)}` + * @param {function} done - callback function called with (err, createdItem) + */ create({ id = "", regExp = "", history = [] }, done) { const key = _convertToDbmId(id); - this._setItem(key, { regExp, history }, done); + this._setItem(key, { regExp, history }, (errMsg, createdItem) => { + if (errMsg) return done(errMsg); + this._addKeyToDbmIds(key, errMsg => { + done(errMsg, createdItem); + }); + }); } /** * Overwrites dynamic bookmarks object from storage with `newDynBook`. - * `Warning`: This function is DANGEROUS! Potential data loss! + * `Warning`: This function is **DANGEROUS**! Potential data loss! * @param {object} newDynBook - new dynamic bookmarks object in form `{bookmark_id: {regExp: String, history:[String]}}` - * @param {function} done - callback function called with done(error) + * @param {function} done - callback function called with `done(errMsg: String)` */ overwrite(newDynBook = {}, done) { const newDynBookMapped = _cloneWithMappedKeys(newDynBook); @@ -85,6 +96,11 @@ class Dbm260 { this._updateStorageItems(newDynBookMapped, done); }); } + + /** + * Returns list of tracked dbm ids + * @param {function} done - callback function called with `done(errMsg: string, ids: string[])` + */ _getAllIds(done) { this.storage.get([dbmIdsPropName], result => { if (!checkAndHandleError(done)) { @@ -120,11 +136,8 @@ class Dbm260 { * @param {function} done - Callback function called with `done(errMsg)` */ _addKeyToDbmIds(key, done) { - this.storage.get([dbmIdsPropName], result => { - if (checkAndHandleError(done)) { - return; - } - let ids = result[dbmIdsPropName] || []; + this._getAllIds((errMsg, ids = []) => { + if (errMsg) return done(errMsg); if (ids.includes(key)) { return done(null); } @@ -132,7 +145,13 @@ class Dbm260 { this._setItem(dbmIdsPropName, ids, done); }); } - + _removeKeyFromDbmIds(key, done) { + this._getAllIds((errMsg, ids = []) => { + if (errMsg) return done(errMsg); + const newIds = ids.filter(el => el !== key); + this._setItem(dbmIdsPropName, newIds, done); + }); + } /** * Sets `item` as `{[key]: item}` in `storage`. * @param {function} done - callback function called with `done(errMsg, storageItem)` @@ -140,14 +159,15 @@ class Dbm260 { _setItem(key, item, done) { this.storage.set({ [key]: item }, () => { if (!checkAndHandleError(done)) { - this._addKeyToDbmIds(key, errMsg => { - done(errMsg, item); - }); + done(null, item); } }); } } +function _convertToBookmarkId(dbmId = "") { + return dbmId.replace(/^dbm_/, ""); +} function _convertToDbmId(id) { if (/^dbm_.*/.test(id)) { return id; From caadda42a6c259c63a19b98b30a6a5678d3d0d11 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 15:46:05 +0200 Subject: [PATCH 12/15] Changed adapter dynBookmarks to now use _dbm-2.6.0 --- src/js/lib/dynBookmarks.js | 2 +- src/js/lib/storage/_dbm-2.6.0.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/lib/dynBookmarks.js b/src/js/lib/dynBookmarks.js index 6987607..89a1acd 100644 --- a/src/js/lib/dynBookmarks.js +++ b/src/js/lib/dynBookmarks.js @@ -1,6 +1,6 @@ /** Adapter **/ -import * as dbm from "./storage/_dbm-2.5.x"; +import dbm from "./storage/_dbm-2.6.0"; export function findAll(done) { dbm.findAll(done); diff --git a/src/js/lib/storage/_dbm-2.6.0.js b/src/js/lib/storage/_dbm-2.6.0.js index 6177e2a..11a8d7a 100644 --- a/src/js/lib/storage/_dbm-2.6.0.js +++ b/src/js/lib/storage/_dbm-2.6.0.js @@ -3,7 +3,7 @@ import { checkAndHandleError } from "../../utils/log"; export const dbmIdsPropName = "dbm_ids"; -class Dbm260 { +export class Dbm260 { constructor(storage = chrome.storage.sync) { this.storage = storage; } From 8e294fcc8014837a21dc9b6f2bf8467a8b45d0c2 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 15:56:53 +0200 Subject: [PATCH 13/15] Fixed version in package.json to 2.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 186a36f..0377912 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-dynamic-bookmarks", - "version": "2.6.1", + "version": "2.6.0", "description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.", "scripts": { "dev": "webpack --mode development", From 08c2a64d4d075726de65783dc186591219b65639 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 16:06:45 +0200 Subject: [PATCH 14/15] optimized onChanged method to avoid MAX_WRITE_OPERATIONS_PER_MINUTE error --- src/js/background.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 4e2e30a..8da6609 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -1,5 +1,6 @@ import * as dbm from "./lib/dynBookmarks"; import { migrateStorage } from "./lib/storage/migrations"; +import { logError } from "./utils/log"; migrateStorage(); @@ -47,22 +48,16 @@ chrome.bookmarks.onRemoved.addListener(id => { // maybe let user setup this in options in future? const maxHistorySize = 10; + chrome.bookmarks.onChanged.addListener((id, changeInfo) => { if (changeInfo.url) { - dbm.findAll((err, dynBook) => { - if (err) { - console.warn(err); - } else if (dynBook[id]) { - if (dynBook[id].history.length >= maxHistorySize) { - dynBook[id].history.pop(); - } - dynBook[id].history.unshift(changeInfo.url); - dbm.overwrite(dynBook, err => { - if (err) { - console.warn(err); - } - }); + dbm.findById(id, (err, item) => { + if (err) return console.warn(err); + if (item.history.length >= maxHistorySize) { + item.history.pop(); } + item.history.unshift(changeInfo.url); + dbm.findByIdAndUpdate(id, item, logError); }); } }); From 811de90f68c7de61dd4dacc84e70588ff631a2ea Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 16:18:51 +0200 Subject: [PATCH 15/15] Set logWarn instead of logError message in background.js --- src/js/background.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 8da6609..d402408 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -1,6 +1,6 @@ import * as dbm from "./lib/dynBookmarks"; import { migrateStorage } from "./lib/storage/migrations"; -import { logError } from "./utils/log"; +import { logWarn } from "./utils/log"; migrateStorage(); @@ -57,7 +57,7 @@ chrome.bookmarks.onChanged.addListener((id, changeInfo) => { item.history.pop(); } item.history.unshift(changeInfo.url); - dbm.findByIdAndUpdate(id, item, logError); + dbm.findByIdAndUpdate(id, item, logWarn); }); } });