2
* Copyright (C) 2019 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
26
WI.LocalResourceOverride = class LocalResourceOverride extends WI.Object
28
constructor(localResource, {isCaseSensitive, isRegex, disabled} = {})
30
console.assert(localResource instanceof WI.LocalResource);
31
console.assert(localResource.isLocalResourceOverride);
32
console.assert(localResource.url);
33
console.assert(isCaseSensitive === undefined || typeof isCaseSensitive === "boolean");
34
console.assert(isRegex === undefined || typeof isRegex === "boolean");
35
console.assert(disabled === undefined || typeof disabled === "boolean");
39
this._localResource = localResource;
40
this._isCaseSensitive = isCaseSensitive !== undefined ? isCaseSensitive : true;
41
this._isRegex = isRegex !== undefined ? isRegex : false;
42
this._disabled = disabled !== undefined ? disabled : false;
47
static create({url, mimeType, content, base64Encoded, statusCode, statusText, headers, isCaseSensitive, isRegex, disabled})
49
let localResource = new WI.LocalResource({
51
url: isRegex ? url : WI.urlWithoutFragment(url),
61
isLocalResourceOverride: true,
64
return new WI.LocalResourceOverride(localResource, {isCaseSensitive, isRegex, disabled});
71
let {localResource, isCaseSensitive, isRegex, disabled} = json;
72
return new WI.LocalResourceOverride(WI.LocalResource.fromJSON(localResource), {isCaseSensitive, isRegex, disabled});
78
localResource: this._localResource.toJSON(key),
79
isCaseSensitive: this._isCaseSensitive,
80
isRegex: this._isRegex,
81
disabled: this._disabled,
84
if (key === WI.ObjectStore.toJSONSymbol)
85
json[WI.objectStores.localResourceOverrides.keyPath] = this._localResource.url;
92
get url() { return this._localResource.url; }
93
get localResource() { return this._localResource; }
94
get isCaseSensitive() { return this._isCaseSensitive; }
95
get isRegex() { return this._isRegex; }
99
return this._disabled;
102
set disabled(disabled)
104
if (this._disabled === disabled)
107
this._disabled = !!disabled;
109
this.dispatchEventToListeners(WI.LocalResourceOverride.Event.DisabledChanged);
115
let regex = new RegExp(this.url, !this._isCaseSensitive ? "i" : "");
116
return regex.test(url);
119
if (!this._isCaseSensitive)
120
return String(url).toLowerCase() === this.url.toLowerCase();
122
return url === this.url;
127
saveIdentityToCookie(cookie)
129
cookie["local-resource-override-url"] = this._localResource.url;
130
cookie["local-resource-override-is-case-sensitive"] = this._isCaseSensitive;
131
cookie["local-resource-override-is-regex"] = this._isRegex;
132
cookie["local-resource-override-disabled"] = this._disabled;
136
WI.LocalResourceOverride.TypeIdentifier = "local-resource-override";
138
WI.LocalResourceOverride.Event = {
139
DisabledChanged: "local-resource-override-disabled-state-did-change",