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

Side by Side Diff: chrome/browser/resources/settings/site_settings/protocol_handlers.js

Issue 2131953002: Site Settings Desktop: Implement protocol handler section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 5 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.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'protocol-handlers' is the polymer element for showing the
8 * protocol handlers category under Site Settings.
9 */
10
11 var MenuActions = {
12 SET_DEFAULT: 'SetDefault',
13 REMOVE: 'Remove',
14 };
15
16 /**
17 * @typedef {{host: string,
18 * protocol: string,
19 * spec: string}}
20 */
21 var HandlerEntry;
22
23 /**
24 * @typedef {{default_handler: number,
25 * handlers: !Array<!HandlerEntry>,
26 * has_policy_recommendations: boolean,
27 * is_default_handler_set_by_user: boolean,
28 * protocol: string}}
29 */
30 var ProtocolEntry;
31
32 Polymer({
33 is: 'protocol-handlers',
34
35 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
36
37 properties: {
38 /**
39 * Represents the state of the main toggle shown for the category.
40 */
41 categoryEnabled: Boolean,
42
43 /**
44 * Array of protocols and their handlers.
45 * @type {!Array<!ProtocolEntry>}
46 */
47 protocols: Array,
48
49 /**
50 * The possible menu actions.
51 * @type {MenuActions}
52 */
53 menuActions_: {
54 type: Object,
55 value: MenuActions,
56 readOnly: true,
57 },
58 },
59
60 ready: function() {
61 this.addWebUIListener('setHandlersEnabled',
62 this.setHandlersEnabled_.bind(this));
63 this.addWebUIListener('setProtocolHandlers',
64 this.setProtocolHandlers_.bind(this));
65 this.addWebUIListener('setIgnoredProtocolHandlers',
66 this.setIgnoredProtocolHandlers_.bind(this));
67 this.browserProxy.initializeProtocolHandlerList();
68 },
69
70 /**
71 * Obtains the description for the main toggle.
72 * @param {number} categoryEnabled Whether the main toggle is enabled.
73 * @return {string} The description to use.
74 * @private
75 */
76 computeHandlersDescription_: function(categoryEnabled) {
77 return this.computeCategoryDesc(
78 settings.ContentSettingsTypes.PROTOCOL_HANDLERS, categoryEnabled, true);
79 },
80
81 /**
82 * Returns whether the given index matches the default handler.
83 * @param {number} index The index to evaluate.
84 * @param {number} defaultHandler The default handler index.
85 * @return {boolean} Whether the item is default.
86 * @private
87 */
88 isDefault_: function(index, defaultHandler) {
89 return defaultHandler == index;
90 },
91
92 /**
93 * Updates the main toggle to set it enabled/disabled.
94 * @param {boolean} enabled The state to set.
95 * @private
96 */
97 setHandlersEnabled_: function(enabled) {
98 this.categoryEnabled = enabled;
99 },
100
101 /**
102 * Updates the list of protocol handlers.
103 * @param {!Array<!ProtocolEntry>} protocols The new protocol handler list.
104 * @private
105 */
106 setProtocolHandlers_: function(protocols) {
107 this.protocols = protocols;
108 },
109
110 /**
111 * Updates the list of ignored protocol handlers.
112 * @param {!Array<!ProtocolEntry>} args The new (ignored) protocol handler
113 * list.
114 * @private
115 */
116 setIgnoredProtocolHandlers_: function(args) {
117 // TODO(finnur): Figure this out. Have yet to be able to trigger the C++
118 // side to send this.
119 },
120
121 /**
122 * A handler when the toggle is flipped.
123 * @private
124 */
125 onToggleChange_: function(event) {
126 this.browserProxy.setProtocolHandlerDefault(this.categoryEnabled);
127 },
128
129 /**
130 * A handler when an action is selected in the action menu.
131 * @private
132 */
133 onActionMenuIronActivate_: function(event) {
134 var protocol = event.model.item.protocol;
135 var url = event.model.item.spec;
136 if (event.detail.selected == MenuActions.SET_DEFAULT) {
137 this.browserProxy.setProtocolDefault(protocol, url);
138 } else if (event.detail.selected == MenuActions.REMOVE) {
139 this.browserProxy.removeProtocolHandler(protocol, url);
140 }
141 },
142 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698