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

Side by Side Diff: chrome/browser/resources/md_extensions/item_util.js

Issue 2723613004: [MD Extensions] Update Detail View UI (Closed)
Patch Set: missed an i18n Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
michaelpg 2017/03/06 19:08:46 2017 (looks like more than a straight rename)
Devlin 2017/03/06 20:12:12 Done.
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
michaelpg 2017/03/06 19:08:46 !
Devlin 2017/03/06 20:12:12 Done.
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(); // FileNotFound.
michaelpg 2017/03/06 19:08:46 FileNotFound?
Devlin 2017/03/06 20:12:12 Bad joke (that was in the last file): http://theda
michaelpg 2017/03/06 22:19:57 Ah. Hehe, and it works on two levels because we'd
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
michaelpg 2017/03/06 19:08:46 !
Devlin 2017/03/06 20:12:12 Done.
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
michaelpg 2017/03/06 19:08:46 !
Devlin 2017/03/06 20:12:12 Done.
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
michaelpg 2017/03/06 19:08:46 non-null: !
Devlin 2017/03/06 20:12:12 Done.
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 label += (view.incognito ? ' ' +
michaelpg 2017/03/06 19:08:46 this would be more readable as a series of if's
Devlin 2017/03/06 20:12:12 Done.
109 loadTimeData.getString('viewIncognito') : '') +
110 (view.renderProcessId == -1 ?
111 ' ' + loadTimeData.getString('viewInactive') : '') +
112 (view.isIframe ? ' ' + loadTimeData.getString('viewIframe') : '');
113 return label;
114 }
115
116 return {isEnabled: isEnabled,
117 userCanChangeEnablement: userCanChangeEnablement,
118 getItemSource: getItemSource,
119 getItemSourceString: getItemSourceString,
120 computeInspectableViewLabel: computeInspectableViewLabel};
121 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698