OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Closure compiler won't let this be declared inside cr.define(). |
| 6 /** @enum {string} */ |
| 7 var SourceType = { |
| 8 WEBSTORE: 'webstore', |
| 9 POLICY: 'policy', |
| 10 SIDELOADED: 'sideloaded', |
| 11 UNPACKED: 'unpacked', |
| 12 }; |
| 13 |
| 14 cr.define('extensions', function() { |
| 15 /** |
| 16 * Returns true if the extension is enabled, including terminated |
| 17 * extensions. |
| 18 * @param {!chrome.developerPrivate.ExtensionState} state |
| 19 * @return {boolean} |
| 20 */ |
| 21 function isEnabled(state) { |
| 22 switch (state) { |
| 23 case chrome.developerPrivate.ExtensionState.ENABLED: |
| 24 case chrome.developerPrivate.ExtensionState.TERMINATED: |
| 25 return true; |
| 26 case chrome.developerPrivate.ExtensionState.DISABLED: |
| 27 return false; |
| 28 } |
| 29 assertNotReached(); |
| 30 } |
| 31 |
| 32 /** |
| 33 * Returns true if the user can change whether or not the extension is |
| 34 * enabled. |
| 35 * @param {!chrome.developerPrivate.ExtensionInfo} item |
| 36 * @return {boolean} |
| 37 */ |
| 38 function userCanChangeEnablement(item) { |
| 39 // User doesn't have permission. |
| 40 if (!item.userMayModify) |
| 41 return false; |
| 42 // Item is forcefully disabled. |
| 43 if (item.disableReasons.corruptInstall || |
| 44 item.disableReasons.suspiciousInstall || |
| 45 item.disableReasons.updateRequired) { |
| 46 return false; |
| 47 } |
| 48 // An item with dependent extensions can't be disabled (it would bork the |
| 49 // dependents). |
| 50 if (item.dependentExtensions.length > 0) |
| 51 return false; |
| 52 // Blacklisted can't be enabled, either. |
| 53 if (item.state == chrome.developerPrivate.ExtensionState.BLACKLISTED) |
| 54 return false; |
| 55 |
| 56 return true; |
| 57 } |
| 58 |
| 59 /** |
| 60 * @param {!chrome.developerPrivate.ExtensionInfo} item |
| 61 * @return {SourceType} |
| 62 */ |
| 63 function getItemSource(item) { |
| 64 if (item.controlledInfo && |
| 65 item.controlledInfo.type == |
| 66 chrome.developerPrivate.ControllerType.POLICY) { |
| 67 return SourceType.POLICY; |
| 68 } |
| 69 if (item.location == chrome.developerPrivate.Location.THIRD_PARTY) |
| 70 return SourceType.SIDELOADED; |
| 71 if (item.location == chrome.developerPrivate.Location.UNPACKED) |
| 72 return SourceType.UNPACKED; |
| 73 return SourceType.WEBSTORE; |
| 74 } |
| 75 |
| 76 /** |
| 77 * @param {SourceType} source |
| 78 * @return {string} |
| 79 */ |
| 80 function getItemSourceString(source) { |
| 81 switch (source) { |
| 82 case SourceType.POLICY: |
| 83 return loadTimeData.getString('itemSourcePolicy'); |
| 84 case SourceType.SIDELOADED: |
| 85 return loadTimeData.getString('itemSourceSideloaded'); |
| 86 case SourceType.UNPACKED: |
| 87 return loadTimeData.getString('itemSourceUnpacked'); |
| 88 case SourceType.WEBSTORE: |
| 89 return loadTimeData.getString('itemSourceWebstore'); |
| 90 } |
| 91 assertNotReached(); |
| 92 } |
| 93 |
| 94 /** |
| 95 * Computes the human-facing label for the given inspectable view. |
| 96 * @param {!chrome.developerPrivate.ExtensionView} view |
| 97 * @return {string} |
| 98 */ |
| 99 function computeInspectableViewLabel(view) { |
| 100 // Trim the "chrome-extension://<id>/". |
| 101 var url = new URL(view.url); |
| 102 var label = view.url; |
| 103 if (url.protocol == 'chrome-extension:') |
| 104 label = url.pathname.substring(1); |
| 105 if (label == '_generated_background_page.html') |
| 106 label = loadTimeData.getString('viewBackgroundPage'); |
| 107 // Add any qualifiers. |
| 108 if (view.incognito) |
| 109 label += ' ' + loadTimeData.getString('viewIncognito'); |
| 110 if (view.renderProcessId == -1) |
| 111 label += ' ' + loadTimeData.getString('viewInactive'); |
| 112 if (view.isIframe) |
| 113 label += ' ' + loadTimeData.getString('viewIframe'); |
| 114 |
| 115 return label; |
| 116 } |
| 117 |
| 118 return {isEnabled: isEnabled, |
| 119 userCanChangeEnablement: userCanChangeEnablement, |
| 120 getItemSource: getItemSource, |
| 121 getItemSourceString: getItemSourceString, |
| 122 computeInspectableViewLabel: computeInspectableViewLabel}; |
| 123 }); |
OLD | NEW |