1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright 2016 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.
/**
* @fileoverview
* 'add-site-dialog' provides a dialog to add exceptions for a given Content
* Settings category.
*/
Polymer({
is: 'add-site-dialog',
behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
properties: {
/**
* What kind of setting, e.g. Location, Camera, Cookies, and so on.
* @type {settings.ContentSettingsTypes}
*/
category: String,
/**
* Whether this is about an Allow, Block, SessionOnly, or other.
* @type {settings.ContentSetting}
*/
contentSetting: String,
/** @private */
hasIncognito: {
type: Boolean,
observer: 'hasIncognitoChanged_',
},
/**
* The site to add an exception for.
* @private
*/
site_: String,
/**
* The error message to display when the pattern is invalid.
* @private
*/
errorMessage_: String,
},
/** @override */
attached: function() {
assert(this.category);
assert(this.contentSetting);
assert(typeof this.hasIncognito != 'undefined');
this.$.dialog.showModal();
},
/**
* Validates that the pattern entered is valid.
* @private
*/
validate_: function() {
// If input is empty, disable the action button, but don't show the red
// invalid message.
if (this.$.site.value.trim() == '') {
this.$.site.invalid = false;
this.$.add.disabled = true;
return;
}
this.browserProxy.isPatternValidForType(this.site_, this.category)
.then(({isValid, reason}) => {
this.$.site.invalid = !isValid;
this.$.add.disabled = !isValid;
this.errorMessage_ = reason || '';
});
},
/** @private */
onCancelTap_: function() {
this.$.dialog.cancel();
},
/**
* The tap handler for the Add [Site] button (adds the pattern and closes
* the dialog).
* @private
*/
onSubmit_: function() {
assert(!this.$.add.disabled);
let primaryPattern = this.site_;
let secondaryPattern = settings.SITE_EXCEPTION_WILDCARD;
if (this.$.thirdParties.checked) {
primaryPattern = settings.SITE_EXCEPTION_WILDCARD;
secondaryPattern = this.site_;
}
this.browserProxy.setCategoryPermissionForPattern(
primaryPattern, secondaryPattern, this.category, this.contentSetting,
this.$.incognito.checked);
this.$.dialog.close();
},
/** @private */
showIncognitoSessionOnly_: function() {
return this.hasIncognito && !loadTimeData.getBoolean('isGuest') &&
this.contentSetting != settings.ContentSetting.SESSION_ONLY;
},
/** @private */
hasIncognitoChanged_: function() {
if (!this.hasIncognito) {
this.$.incognito.checked = false;
}
},
/**
* @return {boolean}
* @private
*/
shouldHideThirdPartyCookieCheckbox_: function() {
return this.category !== settings.ContentSettingsTypes.COOKIES ||
!loadTimeData.getBoolean('showImprovedCookieControlsForThirdParties');
},
});
|