Skip to content

Commit

Permalink
Add color enhancer as a chromium accessibility extensions.
Browse files Browse the repository at this point in the history
BUG=

Review URL: https://codereview.chromium.org/984833004

Cr-Commit-Position: refs/heads/master@{#320514}
  • Loading branch information
wnwen authored and Commit bot committed Mar 13, 2015
1 parent b5f736c commit de13b9b
Show file tree
Hide file tree
Showing 16 changed files with 1,052 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ui/accessibility/extensions/accessibility_extensions.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'dependencies': [
'alt',
'caretbrowsing',
'colorenhancer',
'highcontrast',
'longdesc',
]
Expand Down Expand Up @@ -100,6 +101,41 @@
},
],
},
{
'target_name': 'colorenhancer',
'type': 'none',
'copies': [
{
'destination': '<(dest_dir)/colorenhancer',
'files': [
'colorenhancer/res/cvd-128.png',
'colorenhancer/res/cvd-16.png',
'colorenhancer/res/cvd-19.png',
'colorenhancer/res/cvd-38.png',
'colorenhancer/res/cvd-48.png',
'colorenhancer/res/cvd.css',
'colorenhancer/manifest.json',
'colorenhancer/src/background.js',
'colorenhancer/src/common.js',
'colorenhancer/src/cvd.js',
'colorenhancer/src/popup.html',
'colorenhancer/src/popup.js',
]
}
],
'actions': [
{
'action_name': 'colorenhancer_strings',
'variables': {
'grit_grd_file': 'strings/accessibility_extensions_strings.grd',
'grit_out_dir': '<(dest_dir)/colorenhancer',
# We don't generate any RC files, so no resource_ds file is needed.
'grit_resource_ids': '',
},
'includes': [ '../../../build/grit_action.gypi' ],
},
],
},
{
'target_name': 'highcontrast',
'type': 'none',
Expand Down
45 changes: 45 additions & 0 deletions ui/accessibility/extensions/colorenhancer/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "__MSG_COLOR_ENHANCER_APPNAME__",
"version": "1.1.2",
"description": "__MSG_COLOR_ENHANCER_APPDESC__",
"manifest_version": 2,
"icons": {
"16": "res/cvd-16.png",
"48": "res/cvd-48.png",
"128": "res/cvd-128.png"
},
"permissions": [
"<all_urls>",
"tabs"
],
"background": {
"scripts": [
"src/common.js",
"src/storage.js",
"src/background.js"
]
},
"browser_action": {
"default_icon": {
"19": "res/cvd-19.png",
"38": "res/cvd-38.png"
},
"default_title": "__MSG_COLOR_ENHANCER_APPNAME__",
"default_popup": "src/popup.html"
},
"content_scripts": [
{
"run_at": "document_start",
"matches": [
"<all_urls>"
],
"css": [
"res/cvd.css"
],
"js": [
"src/common.js",
"src/cvd.js"
]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ui/accessibility/extensions/colorenhancer/res/cvd.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Copyright 2015 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. */

html.filter0 {
-webkit-filter: url('#cvd_extension_0');
}

html.filter1 {
-webkit-filter: url('#cvd_extension_1');
}
96 changes: 96 additions & 0 deletions ui/accessibility/extensions/colorenhancer/src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2015 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.

/**
* Adds filter script and css to all existing tabs.
*
* TODO(wnwen): Verify content scripts are not being injected multiple times.
*/
function injectContentScripts() {
chrome.windows.getAll({'populate': true}, function(windows) {
for (var i = 0; i < windows.length; i++) {
var tabs = windows[i].tabs;
for (var j = 0; j < tabs.length; j++) {
var url = tabs[j].url;
if (isDisallowedUrl(url)) {
continue;
}
chrome.tabs.insertCSS(
tabs[j].id,
{file: 'res/cvd.css'});
chrome.tabs.executeScript(
tabs[j].id,
{file: 'src/common.js'});
chrome.tabs.executeScript(
tabs[j].id,
{file: 'src/cvd.js'});
}
}
});
}

/**
* Updates all existing tabs with config values.
*/
function updateTabs() {
chrome.windows.getAll({'populate': true}, function(windows) {
for (var i = 0; i < windows.length; i++) {
var tabs = windows[i].tabs;
for (var j = 0; j < tabs.length; j++) {
var url = tabs[j].url;
if (isDisallowedUrl(url)) {
continue;
}
debugPrint('sending to ' + siteFromUrl(url) + ' ' +
getSiteDelta(siteFromUrl(url)) + ',' +
getSiteSeverity(siteFromUrl(url)));
var msg = {
'delta': getSiteDelta(siteFromUrl(url)),
'severity': getSiteSeverity(siteFromUrl(url)),
'type': getDefaultType(),
'simulate': getDefaultSimulate()
};
chrome.tabs.sendRequest(tabs[j].id, msg);
}
}
});
}

/**
* Initial extension loading.
*/
(function initialize() {
injectContentScripts();
updateTabs();

chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request['init']) {
var delta = getDefaultDelta();
if (sender.tab) {
delta = getSiteDelta(siteFromUrl(sender.tab.url));
}

var severity = getDefaultSeverity();
if (sender.tab) {
severity = getSiteSeverity(siteFromUrl(sender.tab.url));
}

var type = getDefaultType();
var simulate = getDefaultSimulate();

var msg = {
'delta': delta,
'severity': severity,
'type': getDefaultType(),
'simulate': getDefaultSimulate()
};
sendResponse(msg);
}
});

document.addEventListener('storage', function(evt) {
updateTabs();
}, false);
})();
54 changes: 54 additions & 0 deletions ui/accessibility/extensions/colorenhancer/src/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2015 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.

// TODO(wnwen): Move most of these functions to their own page rather than
// common, which should be shared with content script.

/**
* TODO(wnwen): Remove this and use actual web API.
*/
function $(id) {
return document.getElementById(id);
}


/**
* TODO(wnwen): Remove this, it's terrible.
*/
function siteFromUrl(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname;
}


/**
* The filter should not apply to these URLs.
*
* @param {string} url The URL to check.
*/
function isDisallowedUrl(url) {
return url.indexOf('chrome') == 0 || url.indexOf('about') == 0;
}


/**
* Whether extension is loaded unpacked or from Chrome Webstore.
*/
function isDevMode = function() {
return !('update_url' in chrome.runtime.getManifest());
}


/**
* Easily turn on/off console logs.
*
* @param {*} message The message to potentially pass to {@code console.log}.
*/
var debugPrint;
if (isDevMode()) {
debugPrint = console.log;
} else {
debugPrint = function() {};
}
Loading

0 comments on commit de13b9b

Please sign in to comment.