@noldova/desktop.electron 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/api/index.d.ts +253 -32
  2. package/api/index.js +1 -0
  3. package/api/index.js.map +1 -1
  4. package/interfaces/i-frame-navigation.js +9 -0
  5. package/interfaces/i-frame-navigation.js.map +1 -0
  6. package/models/feed-source.js +4 -2
  7. package/models/feed-source.js.map +1 -1
  8. package/models/web-view-history.js +19 -0
  9. package/models/web-view-history.js.map +1 -0
  10. package/package.json +10 -4
  11. package/preload.cjs +7 -0
  12. package/preload.cjs.map +1 -1
  13. package/resources.js +122 -1
  14. package/resources.js.map +1 -1
  15. package/services/electron-web-view-contents.js +10 -0
  16. package/services/electron-web-view-contents.js.map +1 -1
  17. package/services/electron-web-view-engine.js +3 -2
  18. package/services/electron-web-view-engine.js.map +1 -1
  19. package/services/electron-web-view-session.js +19 -0
  20. package/services/electron-web-view-session.js.map +1 -1
  21. package/services/feed-provider.js +4 -3
  22. package/services/feed-provider.js.map +1 -1
  23. package/services/feed-updater.js +7 -4
  24. package/services/feed-updater.js.map +1 -1
  25. package/services/ipc-router.js +12 -0
  26. package/services/ipc-router.js.map +1 -1
  27. package/services/main-process-log.js +9 -7
  28. package/services/main-process-log.js.map +1 -1
  29. package/services/main-process-recovery.js +1 -0
  30. package/services/main-process-recovery.js.map +1 -1
  31. package/services/main-process.js +17 -2
  32. package/services/main-process.js.map +1 -1
  33. package/services/open-web-view.js +213 -33
  34. package/services/open-web-view.js.map +1 -1
  35. package/services/runtime-events.js +4 -0
  36. package/services/runtime-events.js.map +1 -1
  37. package/services/shown-file-policy.js.map +1 -1
  38. package/services/squirrel-handoff.js +1 -1
  39. package/services/squirrel-handoff.js.map +1 -1
  40. package/services/update-controller.js +2 -2
  41. package/services/update-controller.js.map +1 -1
  42. package/services/web-view-attach-guard.js +5 -2
  43. package/services/web-view-attach-guard.js.map +1 -1
  44. package/services/web-view-bridge.js +40 -2
  45. package/services/web-view-bridge.js.map +1 -1
  46. package/services/web-view-favicon.js +115 -0
  47. package/services/web-view-favicon.js.map +1 -0
  48. package/services/web-view-host.js +70 -6
  49. package/services/web-view-host.js.map +1 -1
  50. package/services/web-view-origin-check.js +32 -25
  51. package/services/web-view-origin-check.js.map +1 -1
  52. package/services/open-web-view.resources.js +0 -13
  53. package/services/open-web-view.resources.js.map +0 -1
  54. package/services/web-view-origin-check.resources.js +0 -46
  55. package/services/web-view-origin-check.resources.js.map +0 -1
@@ -11,8 +11,8 @@ import { JsonException, JsonReader } from "@noldova/context.json";
11
11
  import { WebViewAction, WebViewAnswered, WebViewEvent, WebViewEventKind, WebViewFailure, WebViewFailureKind, WebViewNavigation, WebViewNavigationKind } from "@noldova/desktop.protocol";
12
12
  import { CaughtFailure } from "../models/caught-failure.js";
13
13
  import { Resources } from "../resources.js";
14
- import { OpenWebViewResources } from "./open-web-view.resources.js";
15
14
  import { WebViewEventCut } from "./web-view-event-cut.js";
15
+ import { WebViewFavicon } from "./web-view-favicon.js";
16
16
  import { WebViewKeyInput } from "./web-view-key-input.js";
17
17
  export class OpenWebView {
18
18
  session;
@@ -25,22 +25,34 @@ export class OpenWebView {
25
25
  waitAsync;
26
26
  now;
27
27
  lost;
28
+ input;
28
29
  endings = new Set();
29
30
  redirects = new Set();
30
31
  refusedRequests = new Set();
31
32
  relayKeys = [];
32
33
  finds = new Map();
33
34
  navigations = [];
35
+ favicon;
34
36
  windowRequests = [];
35
37
  lastInput;
36
38
  relayedInputs = 0;
39
+ relayedPresses = [];
40
+ touchPoints = [];
41
+ uncountedInputs = 0;
42
+ openPageCalls = 0;
37
43
  allowed = [];
38
44
  guest = null;
39
45
  pendingUrl;
40
46
  committedUrl;
47
+ kept = null;
48
+ keptScroll = null;
49
+ navigationCount = 0;
50
+ inputCount = 0;
41
51
  isCrashed = false;
42
52
  isAttached = false;
53
+ isFocusHeld = false;
43
54
  isClosed = false;
55
+ isControlled = false;
44
56
  state = String.empty;
45
57
  zoomFactor = 1;
46
58
  search;
@@ -48,7 +60,7 @@ export class OpenWebView {
48
60
  info;
49
61
  windowId;
50
62
  partition;
51
- constructor(info, windowId, partition, session, check, declaration, report, isShortcut, pressShortcut, platform, waitAsync, now, lost) {
63
+ constructor(info, windowId, partition, session, check, declaration, report, isShortcut, pressShortcut, platform, waitAsync, now, lost, input) {
52
64
  this.info = info;
53
65
  this.windowId = windowId;
54
66
  this.partition = partition;
@@ -62,18 +74,34 @@ export class OpenWebView {
62
74
  this.waitAsync = waitAsync;
63
75
  this.now = now;
64
76
  this.lost = lost;
77
+ this.input = input;
65
78
  this.lastInput = undefined;
66
79
  this.pendingUrl = undefined;
67
80
  this.committedUrl = undefined;
68
81
  this.search = undefined;
82
+ this.favicon = new WebViewFavicon(session, check, () => this.allowed, waitAsync, t => this.emit(WebViewEventKind.Favicon, { [Resources.imageField]: t }));
69
83
  }
70
84
  get contents() {
71
85
  return this.guest;
72
86
  }
87
+ get isRestorable() {
88
+ return !Object.isNull(this.kept) && !this.isClosed;
89
+ }
73
90
  get zoom() {
74
91
  return this.zoomFactor;
75
92
  }
76
- async bindAsync(guest) {
93
+ async keepAsync() {
94
+ const guest = this.guest;
95
+ if (Object.isNull(guest) || guest.isDestroyed() || guest.getURL() !== this.committedUrl)
96
+ return;
97
+ const kept = guest.readHistory();
98
+ this.kept = kept;
99
+ this.keptScroll = null;
100
+ const scroll = await this.readScrollAsync(guest);
101
+ if (this.kept === kept)
102
+ this.keptScroll = scroll;
103
+ }
104
+ async bindAsync(guest, isPristine = false) {
77
105
  const previous = this.guest;
78
106
  if (this.isClosed)
79
107
  return false;
@@ -85,13 +113,14 @@ export class OpenWebView {
85
113
  }
86
114
  this.guest = guest;
87
115
  this.isAttached = false;
116
+ this.isFocusHeld = false;
88
117
  this.isCrashed = false;
89
118
  if (!Object.isNull(previous) && !previous.isDestroyed() && previous.debugger.isAttached())
90
119
  previous.debugger.detach();
91
120
  this.listen(guest);
92
121
  this.state = JSON.stringify(this.readState(guest));
93
122
  this.restoreZoom();
94
- const failure = await this.attachAsync(guest);
123
+ const [failure] = await Promise.all([this.attachAsync(guest), isPristine ? this.startAsync(guest, true) : null]);
95
124
  if (!Object.isNull(failure)) {
96
125
  if (this.guest === guest)
97
126
  this.loseUnlessEnding(guest, failure);
@@ -99,17 +128,19 @@ export class OpenWebView {
99
128
  }
100
129
  if (this.guest !== guest)
101
130
  return false;
102
- const url = this.pendingUrl ?? this.committedUrl;
103
- this.pendingUrl = undefined;
104
- const navigations = this.navigations.splice(0);
105
- const answer = Object.isUndefined(url) ? null : await this.navigateAsync(url);
106
- for (const settle of navigations)
107
- settle(answer);
131
+ if (!isPristine)
132
+ await this.startAsync(guest, false);
108
133
  return true;
109
134
  }
110
135
  setAllowedOrigins(origins) {
111
136
  this.allowed = [...origins];
112
137
  }
138
+ setControlled(isControlled) {
139
+ if (this.isControlled === isControlled)
140
+ return;
141
+ this.isControlled = isControlled;
142
+ this.emit(WebViewEventKind.Controlled, { [Resources.isControlledField]: isControlled });
143
+ }
113
144
  async navigateAsync(url) {
114
145
  if (this.isClosed)
115
146
  return null;
@@ -123,6 +154,7 @@ export class OpenWebView {
123
154
  if (this.isClosed || Object.isNull(guest))
124
155
  return this.navigateAsync(url);
125
156
  this.isCrashed = false;
157
+ this.navigationCount += 1;
126
158
  void guest.loadURL(url).catch(() => undefined);
127
159
  const failure = this.isAttached ? null : await this.attachAsync(guest);
128
160
  if (!Object.isNull(failure) && this.guest === guest)
@@ -144,12 +176,14 @@ export class OpenWebView {
144
176
  return OpenWebView.noHistory();
145
177
  if (!(await this.allowsAsync(url)))
146
178
  return OpenWebView.refused(url);
179
+ this.navigationCount += 1;
147
180
  contents.reload();
148
181
  return OpenWebView.started();
149
182
  }
150
183
  default:
151
184
  if (!contents.isLoading())
152
185
  return OpenWebView.noHistory();
186
+ this.navigationCount += 1;
153
187
  contents.stop();
154
188
  return OpenWebView.started();
155
189
  }
@@ -158,6 +192,8 @@ export class OpenWebView {
158
192
  const guest = this.guest;
159
193
  if (this.isCrashed || !this.isAttached || Object.isNull(guest))
160
194
  return OpenWebView.fail(call, this.isCrashed ? WebViewFailureKind.Crashed : WebViewFailureKind.Unavailable);
195
+ if (method === Resources.focusEmulationMethod)
196
+ return OpenWebView.fail(call, WebViewFailureKind.NotAllowed, Resources.focusEmulationRefused);
161
197
  if (!this.declaration.allows(method, params))
162
198
  return OpenWebView.fail(call, WebViewFailureKind.NotAllowed);
163
199
  const stroke = method === Resources.dispatchKeyEventMethod ? OpenWebView.readStroke(params) : null;
@@ -168,6 +204,10 @@ export class OpenWebView {
168
204
  this.relayKeys.push(relayKey);
169
205
  const abort = new AbortController();
170
206
  const isInput = method.startsWith(Resources.inputDomainPrefix);
207
+ const isPageCall = method !== Resources.insertTextMethod && method !== Resources.dispatchKeyEventMethod;
208
+ const presses = this.countPresses(method, params);
209
+ const press = presses > 0 ? Symbol(method) : null;
210
+ const isUncounted = isInput && !Resources.pressFreeInputMethods.includes(method);
171
211
  return new Promise(resolve => {
172
212
  const finish = (answer) => {
173
213
  this.endings.delete(end);
@@ -180,12 +220,28 @@ export class OpenWebView {
180
220
  this.waitAsync(timeoutMilliseconds, abort.signal).then(() => end(WebViewFailureKind.TimedOut), () => undefined);
181
221
  if (isInput)
182
222
  this.relayedInputs += 1;
183
- const sent = OpenWebView.relayAsync(guest, method, params);
223
+ if (!Object.isNull(press))
224
+ this.relayedPresses = [...this.relayedPresses, ...Array.from({ length: presses }, () => press)];
225
+ if (isUncounted)
226
+ this.uncountedInputs += 1;
227
+ if (isPageCall)
228
+ this.startPageCall();
229
+ const sent = isPageCall ? this.holdFocusAsync(guest).then(() => OpenWebView.relayAsync(guest, method, params)) : OpenWebView.relayAsync(guest, method, params);
184
230
  if (isInput)
185
- void sent.then(() => this.settleInput(), () => this.settleInput());
186
- sent.then(reply => finish(OpenWebView.answer(call, reply)), (error) => finish(new WebViewAnswered(call, null, new WebViewFailure(WebViewFailureKind.Protocol, Resources.webViewServerErrorCode, error instanceof Error ? error.message : String(error)))));
231
+ void sent.then(() => this.settleInput(press, isUncounted), () => this.settleInput(press, isUncounted));
232
+ const handled = isPageCall ? OpenWebView.afterRendererAsync(guest, sent) : sent;
233
+ if (isPageCall)
234
+ void handled.then(() => this.endPageCall(), () => this.endPageCall());
235
+ handled.then(reply => finish(OpenWebView.answer(call, reply)), (error) => finish(new WebViewAnswered(call, null, new WebViewFailure(WebViewFailureKind.Protocol, Resources.webViewServerErrorCode, error instanceof Error ? error.message : String(error)))));
187
236
  });
188
237
  }
238
+ releaseFocus() {
239
+ const guest = this.guest;
240
+ if (!this.isFocusHeld || Object.isNull(guest))
241
+ return;
242
+ this.isFocusHeld = false;
243
+ void guest.debugger.sendCommand(Resources.focusEmulationMethod, { [Resources.enabledParameter]: false }).catch(() => undefined);
244
+ }
189
245
  allowsRequest(request) {
190
246
  const isRedirect = this.redirects.delete(request.id);
191
247
  const isPage = request.resourceType === Resources.mainFrameResource;
@@ -196,6 +252,9 @@ export class OpenWebView {
196
252
  this.emitRefusedNavigation(request.url, isRedirect);
197
253
  return allows;
198
254
  }
255
+ allowsIconRequest(url) {
256
+ return this.favicon.allowsRequest(url);
257
+ }
199
258
  noteRedirect(redirect) {
200
259
  this.redirects.add(redirect.id);
201
260
  const ip = redirect.ip ?? String.empty;
@@ -249,6 +308,7 @@ export class OpenWebView {
249
308
  if (this.isClosed)
250
309
  return;
251
310
  this.isClosed = true;
311
+ this.favicon.close();
252
312
  this.end(WebViewFailureKind.ViewClosed);
253
313
  this.settleFinds(null);
254
314
  this.pendingUrl = undefined;
@@ -262,6 +322,7 @@ export class OpenWebView {
262
322
  guest.stop();
263
323
  }
264
324
  this.isAttached = false;
325
+ this.isFocusHeld = false;
265
326
  }
266
327
  listen(guest) {
267
328
  guest.setWebRTCIPHandlingPolicy(Resources.webViewRtcPolicy);
@@ -274,11 +335,12 @@ export class OpenWebView {
274
335
  if (this.isBound(guest))
275
336
  this.noteInput(input.type);
276
337
  });
277
- guest.on(Resources.willFrameNavigateEvent, (event, url, isMainFrame) => this.judgeFrame(guest, event, url, isMainFrame));
338
+ guest.on(Resources.willFrameNavigateEvent, navigation => this.judgeFrame(guest, navigation));
339
+ guest.on(Resources.didStartNavigationEvent, navigation => this.noteStart(guest, navigation));
278
340
  guest.on(Resources.willAttachWebviewEvent, event => this.prevent(guest, event, Resources.nestedViewRequest));
279
341
  guest.on(Resources.beforeInputEvent, (event, input) => {
280
342
  if (this.isBound(guest))
281
- this.judgeInput(event, input);
343
+ this.judgeInput(guest, event, input);
282
344
  });
283
345
  guest.on(Resources.certificateErrorEvent, (event, _url, _error, _certificate, callback) => {
284
346
  this.prevent(guest, event, Resources.certificateRequest);
@@ -298,7 +360,7 @@ export class OpenWebView {
298
360
  this.reportState();
299
361
  });
300
362
  guest.on(Resources.didFailLoadEvent, (_event, code, description, url, isMainFrame) => {
301
- if (this.isBound(guest) && isMainFrame && code !== Resources.webViewAbortedLoadCode)
363
+ if (this.isBound(guest) && isMainFrame && code !== Resources.webViewAbortedLoadCode && !OpenWebView.isSourceDocument(url))
302
364
  this.emit(WebViewEventKind.LoadFailed, { [Resources.addressField]: url, [Resources.codeField]: code, [Resources.descriptionField]: description });
303
365
  });
304
366
  guest.on(Resources.renderProcessGoneEvent, () => {
@@ -311,6 +373,15 @@ export class OpenWebView {
311
373
  this.noteCommitted(guest);
312
374
  this.endFind();
313
375
  this.restoreZoom();
376
+ this.favicon.noteNavigation();
377
+ });
378
+ guest.on(Resources.didStopLoadingEvent, () => {
379
+ if (this.isBound(guest))
380
+ this.favicon.noteStop();
381
+ });
382
+ guest.on(Resources.pageFaviconUpdatedEvent, (_event, favicons) => {
383
+ if (this.isBound(guest))
384
+ void this.favicon.updateAsync(guest, favicons);
314
385
  });
315
386
  guest.on(Resources.didNavigateInPageEvent, () => {
316
387
  if (this.isBound(guest))
@@ -342,10 +413,12 @@ export class OpenWebView {
342
413
  return;
343
414
  this.guest = null;
344
415
  this.isAttached = false;
416
+ this.isFocusHeld = false;
345
417
  this.endFind();
346
418
  this.end(WebViewFailureKind.Unavailable);
347
419
  }
348
420
  noteCommitted(guest) {
421
+ this.kept = null;
349
422
  const url = guest.getURL();
350
423
  if (url.length > 0 && url !== Resources.blankPage)
351
424
  this.committedUrl = url;
@@ -419,6 +492,58 @@ export class OpenWebView {
419
492
  else
420
493
  this.stepZoom(step);
421
494
  }
495
+ goToAsync(url) {
496
+ return Object.isUndefined(url) ? Promise.resolve(null) : this.navigateAsync(url);
497
+ }
498
+ async startAsync(guest, isPristine) {
499
+ const pending = this.pendingUrl;
500
+ const kept = isPristine && Object.isUndefined(pending) ? this.kept : null;
501
+ const scroll = this.keptScroll;
502
+ this.pendingUrl = undefined;
503
+ this.kept = null;
504
+ this.keptScroll = null;
505
+ const navigations = this.navigations.splice(0);
506
+ const answer = Object.isNull(kept) ? await this.goToAsync(pending ?? this.committedUrl) : await this.restoreAsync(guest, kept, scroll);
507
+ for (const settle of navigations)
508
+ settle(answer);
509
+ }
510
+ async restoreAsync(guest, kept, scroll) {
511
+ const count = this.navigationCount;
512
+ const inputs = this.inputCount;
513
+ const url = kept.currentUrl;
514
+ const isRestorable = !Object.isNull(url) && url === this.committedUrl && await this.allowsAsync(url) && !this.isClosed && this.guest === guest;
515
+ if (this.navigationCount !== count)
516
+ return null;
517
+ if (!isRestorable)
518
+ return this.goToAsync(this.committedUrl);
519
+ this.isCrashed = false;
520
+ void guest.restoreHistoryAsync(kept).then(() => this.scrollBackAsync(guest, kept, count, inputs, scroll), () => {
521
+ if (this.navigationCount === count && this.guest === guest && !this.isClosed && guest.getURL() === String.empty)
522
+ void this.goToAsync(this.committedUrl);
523
+ });
524
+ return OpenWebView.started();
525
+ }
526
+ async scrollBackAsync(guest, kept, count, inputs, scroll) {
527
+ if (Object.isNull(scroll) || (scroll[0] === 0 && scroll[1] === 0))
528
+ return;
529
+ const shown = await this.readScrollAsync(guest);
530
+ if (Object.isNull(shown) || shown[0] !== 0 || shown[1] !== 0 || this.navigationCount !== count || this.inputCount !== inputs || this.guest !== guest || guest.getURL() !== kept.currentUrl)
531
+ return;
532
+ await guest.executeJavaScriptInIsolatedWorld(Resources.scrollBackWorld, [{ code: Resources.formatScrollBackScript(scroll[0], scroll[1]) }]).catch(() => undefined);
533
+ }
534
+ async readScrollAsync(guest) {
535
+ const abort = new AbortController();
536
+ const read = guest.debugger.sendCommand(Resources.layoutMetricsMethod, {}).then(t => OpenWebView.readScroll(t), () => null);
537
+ const late = this.waitAsync(Resources.webViewScrollReadTimeout, abort.signal).then(() => null, () => null);
538
+ const scroll = await Promise.race([read, late]);
539
+ abort.abort();
540
+ return scroll;
541
+ }
542
+ static readScroll(reply) {
543
+ const viewport = OpenWebView.readObject(OpenWebView.readObject(reply)?.[Resources.layoutViewportField]);
544
+ const [x, y] = [viewport?.[Resources.pageXField], viewport?.[Resources.pageYField]];
545
+ return Number.isSafeInteger(x) && Number.isSafeInteger(y) ? [Number(x), Number(y)] : null;
546
+ }
422
547
  async moveAsync(guest, offset, move) {
423
548
  const url = guest.readHistoryEntry(offset);
424
549
  if (Object.isNull(url))
@@ -426,6 +551,7 @@ export class OpenWebView {
426
551
  if (!(await this.allowsAsync(url)))
427
552
  return OpenWebView.refused(url);
428
553
  this.isCrashed = false;
554
+ this.navigationCount += 1;
429
555
  move();
430
556
  return OpenWebView.started();
431
557
  }
@@ -438,14 +564,18 @@ export class OpenWebView {
438
564
  const addresses = isIP(host) !== 0 ? [host] : await this.session.resolveHostAsync(host).catch(() => []);
439
565
  return addresses.length > 0 && addresses.every(t => this.check.allowsConnection(url, this.allowed, t));
440
566
  }
441
- judgeFrame(guest, event, url, isMainFrame) {
567
+ judgeFrame(guest, navigation) {
442
568
  if (!this.isBound(guest))
443
- return event.preventDefault();
444
- if (this.check.allowsNavigation(url, this.allowed, !isMainFrame))
569
+ return navigation.preventDefault();
570
+ if (this.check.allowsNavigation(navigation.url, this.allowed, !navigation.isMainFrame))
445
571
  return;
446
- event.preventDefault();
447
- if (isMainFrame)
448
- this.emitRefusedNavigation(url, false);
572
+ navigation.preventDefault();
573
+ if (navigation.isMainFrame)
574
+ this.emitRefusedNavigation(navigation.url, false);
575
+ }
576
+ noteStart(guest, navigation) {
577
+ if (this.isBound(guest) && navigation.isMainFrame && !navigation.isSameDocument && OpenWebView.isSourceDocument(navigation.url))
578
+ this.emitRefusedNavigation(navigation.url, false);
449
579
  }
450
580
  askForWindow(details) {
451
581
  const now = this.now();
@@ -457,15 +587,44 @@ export class OpenWebView {
457
587
  this.emit(WebViewEventKind.NewWindowRequested, {
458
588
  [Resources.addressField]: details.url,
459
589
  [Resources.hadRecentInputField]: !Object.isUndefined(this.lastInput) && now - this.lastInput <= Resources.recentInputMilliseconds,
460
- [Resources.originField]: origin === Resources.nullOrigin ? null : origin
590
+ [Resources.originField]: origin === Resources.nullOrigin ? null : origin,
591
+ ...Object.isUndefined(details.disposition) ? {} : { [Resources.dispositionField]: details.disposition }
461
592
  });
462
593
  }
463
- settleInput() {
594
+ settleInput(press, isUncounted) {
464
595
  this.relayedInputs -= 1;
596
+ this.relayedPresses = this.relayedPresses.filter(t => t !== press);
597
+ if (isUncounted)
598
+ this.uncountedInputs -= 1;
599
+ }
600
+ async holdFocusAsync(guest) {
601
+ if (this.isFocusHeld)
602
+ return;
603
+ this.isFocusHeld = true;
604
+ const isHeld = await guest.debugger.sendCommand(Resources.focusEmulationMethod, { [Resources.enabledParameter]: true }).then(() => true, () => false);
605
+ if (!isHeld && this.guest === guest)
606
+ this.isFocusHeld = false;
607
+ }
608
+ startPageCall() {
609
+ this.openPageCalls += 1;
610
+ this.input(Resources.inputStartKind);
611
+ }
612
+ endPageCall() {
613
+ this.openPageCalls -= 1;
614
+ this.input(Resources.inputEndKind);
465
615
  }
466
616
  noteInput(type) {
617
+ if (!Resources.pointerMoveTypes.includes(type))
618
+ this.inputCount += 1;
619
+ const isPress = Resources.personPressTypes.includes(type);
620
+ if (isPress && this.relayedPresses.length > 0) {
621
+ this.relayedPresses = this.relayedPresses.slice(1);
622
+ return;
623
+ }
467
624
  if (this.relayedInputs === 0 && Resources.personInputTypes.includes(type))
468
625
  this.lastInput = this.now();
626
+ if (this.openPageCalls > 0 && isPress && this.uncountedInputs === 0)
627
+ this.input(Resources.inputPressKind);
469
628
  }
470
629
  prevent(guest, event, request) {
471
630
  event.preventDefault();
@@ -500,6 +659,7 @@ export class OpenWebView {
500
659
  }
501
660
  detach(guest) {
502
661
  this.isAttached = false;
662
+ this.isFocusHeld = false;
503
663
  this.end(WebViewFailureKind.Unavailable);
504
664
  if (this.isCrashed || guest.isDestroyed())
505
665
  return;
@@ -509,7 +669,7 @@ export class OpenWebView {
509
669
  });
510
670
  }
511
671
  loseUnlessEnding(guest, failure) {
512
- if (failure.includes(OpenWebViewResources.targetClosedError))
672
+ if (failure.includes(Resources.targetClosedError))
513
673
  this.unbind(guest);
514
674
  else
515
675
  this.lost();
@@ -528,16 +688,15 @@ export class OpenWebView {
528
688
  if (!Object.isNull(event))
529
689
  this.report(event);
530
690
  }
531
- judgeInput(event, input) {
691
+ judgeInput(guest, event, input) {
532
692
  if (!Resources.keyDownInputs.includes(input.type))
533
693
  return;
534
694
  const stroke = { key: input.key, code: input.code, ctrlKey: input.control, altKey: input.alt, shiftKey: input.shift, metaKey: input.meta };
535
695
  const relayKey = this.relayKeys.find(t => OpenWebView.isSameStroke(t, stroke));
536
696
  if (!Object.isUndefined(relayKey))
537
697
  return this.forgetRelayKey(relayKey);
538
- const isShortcut = this.isShortcut(stroke);
539
- const name = isShortcut ? null : this.declaration.findKey(stroke, this.platform);
540
- if (!isShortcut && Object.isNull(name))
698
+ const name = this.declaration.findKey(stroke, this.platform, guest.isLoading());
699
+ if (Object.isNull(name) && !this.isShortcut(stroke))
541
700
  return this.judgeZoomKey(event, stroke);
542
701
  event.preventDefault();
543
702
  if (input.isAutoRepeat)
@@ -559,6 +718,9 @@ export class OpenWebView {
559
718
  if (!this.isClosed)
560
719
  this.report(new WebViewEvent(this.info.module, this.info.id, kind, details));
561
720
  }
721
+ static afterRendererAsync(guest, sent) {
722
+ return sent.finally(() => guest.executeJavaScriptInIsolatedWorld(Resources.focusBarrierWorld, [{ code: Resources.focusBarrierScript }]).catch(() => undefined));
723
+ }
562
724
  static async relayAsync(guest, method, params) {
563
725
  if (method === Resources.insertTextMethod) {
564
726
  const text = params[Resources.textField];
@@ -580,6 +742,16 @@ export class OpenWebView {
580
742
  return relayed.key === pressed.key && (relayed.code === String.empty || relayed.code === pressed.code)
581
743
  && relayed.ctrlKey === pressed.ctrlKey && relayed.altKey === pressed.altKey && relayed.shiftKey === pressed.shiftKey && relayed.metaKey === pressed.metaKey;
582
744
  }
745
+ countPresses(method, params) {
746
+ const points = params[Resources.touchPointsField];
747
+ const held = this.touchPoints;
748
+ const ids = Array.isArray(points) ? points.map(t => OpenWebView.readTouchPointId(t, method)) : [];
749
+ if (method === Resources.dispatchTouchEventMethod)
750
+ this.touchPoints = ids;
751
+ if (!Resources.relayedPressTypes.has(method) || Resources.relayedPressTypes.get(method) !== params[Resources.typeField])
752
+ return 0;
753
+ return ids.length === 0 ? 1 : ids.filter(t => !held.includes(t)).length;
754
+ }
583
755
  static readStroke(params) {
584
756
  const modifiers = Number.isSafeInteger(params[Resources.modifiersField]) ? Number(params[Resources.modifiersField]) : 0;
585
757
  return {
@@ -597,6 +769,10 @@ export class OpenWebView {
597
769
  return new WebViewAnswered(call, null, new WebViewFailure(WebViewFailureKind.Protocol, Resources.webViewServerErrorCode, Resources.webViewReplyNotObject));
598
770
  return Buffer.byteLength(JSON.stringify(value)) > Resources.webViewReplyLimit ? OpenWebView.fail(call, WebViewFailureKind.TooLarge) : new WebViewAnswered(call, value);
599
771
  }
772
+ static readTouchPointId(point, method) {
773
+ const id = OpenWebView.readObject(point)?.[Resources.touchPointIdField];
774
+ return Number.isSafeInteger(id) ? id : Symbol(method);
775
+ }
600
776
  static readObject(value) {
601
777
  try {
602
778
  return JsonReader.fromValue(value).toJson();
@@ -606,18 +782,22 @@ export class OpenWebView {
606
782
  return null;
607
783
  }
608
784
  }
609
- static fail(call, kind) {
610
- return new WebViewAnswered(call, null, new WebViewFailure(kind));
785
+ static fail(call, kind, message = null) {
786
+ return new WebViewAnswered(call, null, new WebViewFailure(kind, null, message));
611
787
  }
612
788
  static found(matches, active) {
613
789
  const count = Math.max(matches, 0);
614
790
  return { [Resources.matchesField]: count, [Resources.activeField]: Math.min(Math.max(active, 0), count) };
615
791
  }
616
792
  static timedOut() {
617
- return { [OpenWebViewResources.isTimedOutField]: true };
793
+ return { [Resources.isTimedOutField]: true };
618
794
  }
619
795
  static ended() {
620
- return { [OpenWebViewResources.isEndedField]: true };
796
+ return { [Resources.isEndedField]: true };
797
+ }
798
+ static isSourceDocument(url) {
799
+ const parsed = URL.parse(url);
800
+ return parsed?.protocol === Resources.aboutScheme && parsed.pathname === Resources.sourceDocumentPath;
621
801
  }
622
802
  static originOf(url) {
623
803
  return URL.parse(url)?.origin ?? Resources.nullOrigin;