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

Unified Diff: ui/accessibility/extensions/longdesc/background.js

Issue 593293002: Initial checkin of accessibility extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix license issues Created 6 years, 3 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
« no previous file with comments | « ui/accessibility/extensions/highcontrast/popup.js ('k') | ui/accessibility/extensions/longdesc/icon.png » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/extensions/longdesc/background.js
diff --git a/ui/accessibility/extensions/longdesc/background.js b/ui/accessibility/extensions/longdesc/background.js
new file mode 100644
index 0000000000000000000000000000000000000000..5e05eb9c0c18b81a64bec40108899c1de78a24ac
--- /dev/null
+++ b/ui/accessibility/extensions/longdesc/background.js
@@ -0,0 +1,66 @@
+/* Copyright (c) 2014 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. */
+
+var ariaDescribedAt = '';
+var longDesc = '';
+
+ /**
+ * This is called when the extension is first loaded, so that it can be
+ * immediately used in all already-open tabs. It's not needed for any
+ * new tabs that open after that, the content script will be automatically
+ * injected into any new tab.
+ */
+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++) {
+ chrome.tabs.executeScript(
+ tabs[j].id,
+ {file: 'lastRightClick.js'});
+ }
+ }
+});
+
+/**
+ * Add context menu item when the extension is installed.
+ */
+chrome.contextMenus.create({
+ "title": "More information...",
+ "contexts": ["all"],
+ "id": "moreInfo",
+ "onclick": contextMenuClicked,
+ "enabled": false
+ });
+
+/**
+ * Add listener for messages from content script.
+ * Enable/disable the context menu item.
+ */
+chrome.runtime.onMessage.addListener(
+ function (request, sender, sendResponse) {
+ if (request.enabled) {
+ ariaDescribedAt = request.ariaDescribedAt;
+ longDesc = request.longDesc;
+ }
+ chrome.contextMenus.update('moreInfo', {
+ "enabled": request.enabled
+ });
+ });
+
+/**
+ * Event handler for when a context menu item is clicked.
+ * aria-describedat is given a higher priority.
+ * No need to strip the URL of leading/trailing white space
+ * because Chrome takes care of this.
+ *
+ * @param info
+ * @param tab
+ */
+function contextMenuClicked(info, tab) {
+ if (ariaDescribedAt !== '') {
+ chrome.tabs.create({url: ariaDescribedAt});
+ } else if (longDesc !== '') {
+ chrome.tabs.create({url: longDesc});
+ }
+}
« no previous file with comments | « ui/accessibility/extensions/highcontrast/popup.js ('k') | ui/accessibility/extensions/longdesc/icon.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698