chrome 100 percent

chrome 100 percent


DisciplinaPedagogia116.445 materiais671.058 seguidores
Pré-visualização50 páginas
{
 var numButtons = buttonList.length;
 for (var i = 0; i < numButtons; i++) {
 if (buttonList[i].iconUrl) {
 $Array.push(urlSpecs, {
 path: buttonList[i].iconUrl,
 width: imageSizes.buttonIcon.width * imageSizes.scaleFactor,
 height: imageSizes.buttonIcon.height * imageSizes.scaleFactor,
 callback: imageDataSetter(buttonList[i], 'iconBitmap')
 });
 }
 }
 }
 return urlSpecs;
}
function replaceNotificationOptionURLs(notification_details, callback) {
 var imageSizes = notificationsPrivate.GetNotificationImageSizes();
 var url_specs = getUrlSpecs(imageSizes, notification_details);
 if (!url_specs.length) {
 callback(true);
 return;
 }
 var errors = 0;
 imageUtil.loadAllImages(url_specs, {
 onerror: function(index) {
 errors++;
 },
 oncomplete: function(imageData) {
 if (errors > 0) {
 callback(false);
 return;
 }
 for (var index = 0; index < url_specs.length; index++) {
 var url_spec = url_specs[index];
 url_spec.callback(imageData[index]);
 }
 callback(true);
 }
 });
}
function genHandle(name, failure_function) {
 return function(id, input_notification_details, callback) {
 // TODO(dewittj): Remove this hack. This is used as a way to deep
 // copy a complex JSON object.
 var notification_details = $JSON.parse(
 $JSON.stringify(input_notification_details));
 var that = this;
 var stack = exceptionHandler.getExtensionStackTrace();
 replaceNotificationOptionURLs(notification_details, function(success) {
 if (success) {
 sendRequest(
 name, [id, notification_details, callback],
 bindingUtil ? undefined : that.definition.parameters,
 bindingUtil ? undefined : {__proto__: null, stack: stack});
 return;
 }
 runCallbackWithLastError(
 name, 'Unable to download all specified images.',
 stack, failure_function, [callback || function() {}, id]);
 });
 };
}
var handleCreate = genHandle('notifications.create',
 function(callback, id) { callback(id); });
var handleUpdate = genHandle('notifications.update',
 function(callback, id) { callback(false); });
var notificationsCustomHook = function(bindingsAPI, extensionId) {
 var apiFunctions = bindingsAPI.apiFunctions;
 apiFunctions.setHandleRequest('create', handleCreate);
 apiFunctions.setHandleRequest('update', handleUpdate);
};
binding.registerCustomHook(notificationsCustomHook);
if (!apiBridge)
 exports.$set('binding', binding.generate());
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Custom binding for the omnibox API. Only injected into the v8 contexts
// for extensions which have permission for the omnibox API.
var binding = apiBridge || require('binding').Binding.create('omnibox');
var registerArgumentMassager = bindingUtil ?
 $Function.bind(bindingUtil.registerEventArgumentMassager, bindingUtil) :
 require('event_bindings').registerArgumentMassager;
var sendRequest = bindingUtil ?
 $Function.bind(bindingUtil.sendRequest, bindingUtil) :
 require('sendRequest').sendRequest;
// Remove invalid characters from |text| so that it is suitable to use
// for |AutocompleteMatch::contents|.
function sanitizeString(text, shouldTrim) {
 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|.
 // 0x2028 = line separator; 0x2029 = paragraph separator.
 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm;
 if (shouldTrim)
 text = text.trimLeft();
 return text.replace(kRemoveChars, '');
}
// Parses the xml syntax supported by omnibox suggestion results. Returns an
// object with two properties: 'description', which is just the text content,
// and 'descriptionStyles', which is an array of style objects in a format
// understood by the C++ backend.
function parseOmniboxDescription(input) {
 var domParser = new DOMParser();
 // The XML parser requires a single top-level element, but we want to
 // support things like 'hello, <match>world</match>!'. So we wrap the
 // provided text in generated root level element.
 var root = domParser.parseFromString(
 '<fragment>' + input + '</fragment>', 'text/xml');
 // DOMParser has a terrible error reporting facility. Errors come out nested
 // inside the returned document.
 var error = root.querySelector('parsererror div');
 if (error) {
 throw new Error(error.textContent);
 }
 // Otherwise, it's valid, so build up the result.
 var result = {
 description: '',
 descriptionStyles: []
 };
 // Recursively walk the tree.
 function walk(node) {
 for (var i = 0, child; child = node.childNodes[i]; i++) {
 // Append text nodes to our description.
 if (child.nodeType == Node.TEXT_NODE) {
 var shouldTrim = result.description.length == 0;
 result.description += sanitizeString(child.nodeValue, shouldTrim);
 continue;
 }
 // Process and descend into a subset of recognized tags.
 if (child.nodeType == Node.ELEMENT_NODE &&
 (child.nodeName == 'dim' || child.nodeName == 'match' ||
 child.nodeName == 'url')) {
 var style = {
 'type': child.nodeName,
 'offset': result.description.length
 };
 $Array.push(result.descriptionStyles, style);
 walk(child);
 style.length = result.description.length - style.offset;
 continue;
 }
 // Descend into all other nodes, even if they are unrecognized, for
 // forward compat.
 walk(child);
 }
 };
 walk(root);
 return result;
}
binding.registerCustomHook(function(bindingsAPI) {
 var apiFunctions = bindingsAPI.apiFunctions;
 apiFunctions.setUpdateArgumentsPreValidate('setDefaultSuggestion',
 function(suggestResult) {
 if (suggestResult.content != undefined) { // null, etc.
 throw new Error(
 'setDefaultSuggestion cannot contain the &quot;content&quot; field');
 }
 return [suggestResult];
 });
 apiFunctions.setHandleRequest('setDefaultSuggestion', function(details) {
 var parseResult = parseOmniboxDescription(details.description);
 sendRequest('omnibox.setDefaultSuggestion', [parseResult],
 bindingUtil ? undefined : this.definition.parameters,
 undefined);
 });
 apiFunctions.setUpdateArgumentsPostValidate(
 'sendSuggestions', function(requestId, userSuggestions) {
 var suggestions = [];
 for (var i = 0; i < userSuggestions.length; i++) {
 var parseResult = parseOmniboxDescription(
 userSuggestions[i].description);
 parseResult.content = userSuggestions[i].content;
 parseResult.deletable = userSuggestions[i].deletable;
 $Array.push(suggestions, parseResult);
 }
 return [requestId, suggestions];
 });
});
registerArgumentMassager('omnibox.onInputChanged', function(args, dispatch) {
 var text = args[0];
 var requestId = args[1];
 var suggestCallback = function(suggestions) {
 chrome.omnibox.sendSuggestions(requestId, suggestions);
 };
 dispatch([text, suggestCallback]);
});
if (!apiBridge)
 exports.$set('binding', binding.generate());
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Custom binding for the pageAction API.
var binding = apiBridge || require('binding').Binding.create('pageAction');
var setIcon = require('setIcon').setIcon;
var sendRequest = bindingUtil ?
 $Function.bind(bindingUtil.sendRequest, bindingUtil) :
 require('sendRequest').sendRequest;