Skip to content

Commit 3a34fcb

Browse files
committed
setup: update ExtensionInstallForcelist on install
1 parent b5047aa commit 3a34fcb

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

BrowserGuard.iss

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ Filename: "{sys}\icacls.exe";Parameters: """{app}\BrowserGuardHost\edge.json"" /
7171
[UninstallRun]
7272

7373
[Code]
74+
const
75+
// Determined by the signing key (webextensions\pem\edge.pem).
76+
// Must match the appid in Resources\manifest.xml.
77+
ExtensionId = 'ddniogodiahgpmfkljajobgkaecabnif';
78+
// SOFTWARE\Policies is shared between the 32 and 64 bit registry views.
79+
ForcelistKey = 'SOFTWARE\Policies\Microsoft\Edge\ExtensionInstallForcelist';
80+
7481
function GetProgramFiles(Param: string): string;
7582
begin
7683
if IsWin64 then Result := ExpandConstant('{pf64}')
@@ -125,8 +132,78 @@ begin
125132
Log('Cannot write update manifest: ' + FilePath);
126133
end;
127134
135+
// Force installing the extension from the locally hosted update manifest.
136+
// Entries are named with sequential numbers, so an unused slot is picked,
137+
// and an entry left by a previous install is reused instead of duplicated.
138+
function FindOwnForcelistValueName(var ValueName: String): Boolean;
139+
var
140+
Names: TArrayOfString;
141+
Data: String;
142+
i: Integer;
143+
begin
144+
Result := False;
145+
if not RegGetValueNames(HKEY_LOCAL_MACHINE, ForcelistKey, Names) then
146+
Exit;
147+
for i := 0 to GetArrayLength(Names) - 1 do
148+
begin
149+
if RegQueryStringValue(HKEY_LOCAL_MACHINE, ForcelistKey, Names[i], Data) then
150+
begin
151+
if Pos(ExtensionId + ';', Data) = 1 then
152+
begin
153+
ValueName := Names[i];
154+
Result := True;
155+
Exit;
156+
end;
157+
end;
158+
end;
159+
end;
160+
161+
procedure RegisterForcelist();
162+
var
163+
ValueName, Entry: String;
164+
Slot: Integer;
165+
begin
166+
Entry := ExtensionId + ';' + GetExtensionFolderUrl() + '/manifest.xml';
167+
168+
if not FindOwnForcelistValueName(ValueName) then
169+
begin
170+
Slot := 1;
171+
while RegValueExists(HKEY_LOCAL_MACHINE, ForcelistKey, IntToStr(Slot)) do
172+
Slot := Slot + 1;
173+
ValueName := IntToStr(Slot);
174+
end;
175+
176+
if not RegWriteStringValue(HKEY_LOCAL_MACHINE, ForcelistKey, ValueName, Entry) then
177+
Log('Cannot write policy value: ' + ForcelistKey + '\' + ValueName);
178+
end;
179+
180+
// Only the entry belonging to this extension is removed, so policies set for
181+
// other extensions are left untouched.
182+
procedure UnregisterForcelist();
183+
var
184+
ValueName: String;
185+
begin
186+
while FindOwnForcelistValueName(ValueName) do
187+
begin
188+
if not RegDeleteValue(HKEY_LOCAL_MACHINE, ForcelistKey, ValueName) then
189+
begin
190+
Log('Cannot delete policy value: ' + ForcelistKey + '\' + ValueName);
191+
Exit;
192+
end;
193+
end;
194+
end;
195+
128196
procedure CurStepChanged(CurStep: TSetupStep);
129197
begin
130198
if CurStep = ssPostInstall then
199+
begin
131200
ExpandUpdateManifest();
201+
RegisterForcelist();
202+
end;
203+
end;
204+
205+
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
206+
begin
207+
if CurUninstallStep = usUninstall then
208+
UnregisterForcelist();
132209
end;

0 commit comments

Comments
 (0)