| 185 | }, |
| 186 | |
| 187 | prepareToActivateMode(mode, onExit) { |
| 188 | // We need to communicate with the background page (and other frames) to initiate link-hints |
| 189 | // mode. To prevent other Vimium commands from being triggered before link-hints mode is |
| 190 | // launched, we install a temporary mode to block (and cache) keyboard events. |
| 191 | let cacheAllKeydownEvents; |
| 192 | this.cacheAllKeydownEvents = cacheAllKeydownEvents = new CacheAllKeydownEvents({ |
| 193 | name: "link-hints/suppress-keyboard-events", |
| 194 | singleton: "link-hints-mode", |
| 195 | indicator: "Collecting hints...", |
| 196 | exitOnEscape: true, |
| 197 | }); |
| 198 | // FIXME(smblott) Global link hints is currently insufficiently reliable. If the mode above is |
| 199 | // left in place, then Vimium blocks. As a temporary measure, we install a timer to remove it. |
| 200 | // TODO(philc): I believe link hints is sufficiently reliable after the manifest V3 port |
| 201 | // that this safeguard can now be removed. |
| 202 | Utils.setTimeout(1000, function () { |
| 203 | if (cacheAllKeydownEvents && cacheAllKeydownEvents.modeIsActive) { |
| 204 | cacheAllKeydownEvents.exit(); |
| 205 | } |
| 206 | }); |
| 207 | this.onExit = [onExit]; |
| 208 | const protocol = window.location.protocol; |
| 209 | // chrome-extension, moz-extension (Firefox), extension (Edge). |
| 210 | const isExtensionPage = protocol.endsWith("extension:"); |
| 211 | chrome.runtime.sendMessage({ |
| 212 | handler: "prepareToActivateLinkHintsMode", |
| 213 | modeIndex: availableModes.indexOf(mode), |
| 214 | isExtensionPage, |
| 215 | requestedByHelpDialog: globalThis.isVimiumHelpDialog, |
| 216 | }); |
| 217 | }, |
| 218 | |
| 219 | // Returns a list of HintDescriptors. Hint descriptors are global. They include all of the |
| 220 | // information necessary for each frame to determine whether and when a hint from *any* frame is |