forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add color enhancer as a chromium accessibility extensions.
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
Showing
16 changed files
with
1,052 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
ui/accessibility/extensions/colorenhancer/src/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {}; | ||
} |
Oops, something went wrong.