Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10344)

Unified Diff: chrome/renderer/resources/extensions/image_util.js

Issue 307833002: Move some extensions renderer resources to extensions_renderer_resources.grd. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/image_util.js
diff --git a/chrome/renderer/resources/extensions/image_util.js b/chrome/renderer/resources/extensions/image_util.js
deleted file mode 100644
index 79867404af3debe9d11598b8214de822b9389ccd..0000000000000000000000000000000000000000
--- a/chrome/renderer/resources/extensions/image_util.js
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2013 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.
-
-// This function takes an object |imageSpec| with the key |path| -
-// corresponding to the internet URL to be translated - and optionally
-// |width| and |height| which are the maximum dimensions to be used when
-// converting the image.
-function loadImageData(imageSpec, callbacks) {
- var path = imageSpec.path;
- var img = new Image();
- if (typeof callbacks.onerror === 'function') {
- img.onerror = function() {
- callbacks.onerror({ problem: 'could_not_load', path: path });
- };
- }
- img.onload = function() {
- var canvas = document.createElement('canvas');
-
- if (img.width <= 0 || img.height <= 0) {
- callbacks.onerror({ problem: 'image_size_invalid', path: path});
- return;
- }
-
- var scaleFactor = 1;
- if (imageSpec.width && imageSpec.width < img.width)
- scaleFactor = imageSpec.width / img.width;
-
- if (imageSpec.height && imageSpec.height < img.height) {
- var heightScale = imageSpec.height / img.height;
- if (heightScale < scaleFactor)
- scaleFactor = heightScale;
- }
-
- canvas.width = img.width * scaleFactor;
- canvas.height = img.height * scaleFactor;
-
- var canvas_context = canvas.getContext('2d');
- canvas_context.clearRect(0, 0, canvas.width, canvas.height);
- canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height);
- try {
- var imageData = canvas_context.getImageData(
- 0, 0, canvas.width, canvas.height);
- if (typeof callbacks.oncomplete === 'function') {
- callbacks.oncomplete(
- imageData.width, imageData.height, imageData.data.buffer);
- }
- } catch (e) {
- if (typeof callbacks.onerror === 'function') {
- callbacks.onerror({ problem: 'data_url_unavailable', path: path });
- }
- }
- }
- img.src = path;
-}
-
-function on_complete_index(index, err, loading, finished, callbacks) {
- return function(width, height, imageData) {
- delete loading[index];
- finished[index] = { width: width, height: height, data: imageData };
- if (err)
- callbacks.onerror(index);
- if ($Object.keys(loading).length == 0)
- callbacks.oncomplete(finished);
- }
-}
-
-function loadAllImages(imageSpecs, callbacks) {
- var loading = {}, finished = [],
- index, pathname;
-
- for (var index = 0; index < imageSpecs.length; index++) {
- loading[index] = imageSpecs[index];
- loadImageData(imageSpecs[index], {
- oncomplete: on_complete_index(index, false, loading, finished, callbacks),
- onerror: on_complete_index(index, true, loading, finished, callbacks)
- });
- }
-}
-
-exports.loadImageData = loadImageData;
-exports.loadAllImages = loadAllImages;
« no previous file with comments | « chrome/renderer/resources/extensions/i18n_custom_bindings.js ('k') | chrome/renderer/resources/extensions/json_schema.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698