Frontend options override refactor (#1016)
* Update how options context overriding works * Make function private
This commit is contained in:
parent
8edb478d0a
commit
3a23f081d1
@ -28,7 +28,6 @@ class PopupPreviewFrame {
|
|||||||
this._frameId = frameId;
|
this._frameId = frameId;
|
||||||
this._popupFactory = popupFactory;
|
this._popupFactory = popupFactory;
|
||||||
this._frontend = null;
|
this._frontend = null;
|
||||||
this._frontendGetOptionsContextOld = null;
|
|
||||||
this._apiOptionsGetOld = null;
|
this._apiOptionsGetOld = null;
|
||||||
this._popupSetCustomOuterCssOld = null;
|
this._popupSetCustomOuterCssOld = null;
|
||||||
this._popupShown = false;
|
this._popupShown = false;
|
||||||
@ -78,8 +77,7 @@ class PopupPreviewFrame {
|
|||||||
pageType: 'web',
|
pageType: 'web',
|
||||||
allowRootFramePopupProxy: false
|
allowRootFramePopupProxy: false
|
||||||
});
|
});
|
||||||
this._frontendGetOptionsContextOld = this._frontend.getOptionsContext.bind(this._frontend);
|
this._frontend.setOptionsContextOverride(this._optionsContext);
|
||||||
this._frontend.getOptionsContext = this._getOptionsContext.bind(this);
|
|
||||||
await this._frontend.prepare();
|
await this._frontend.prepare();
|
||||||
this._frontend.setDisabledOverride(true);
|
this._frontend.setDisabledOverride(true);
|
||||||
this._frontend.canClearSelection = false;
|
this._frontend.canClearSelection = false;
|
||||||
@ -96,14 +94,6 @@ class PopupPreviewFrame {
|
|||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
async _getOptionsContext() {
|
|
||||||
let optionsContext = this._optionsContext;
|
|
||||||
if (optionsContext === null) {
|
|
||||||
optionsContext = this._frontendGetOptionsContextOld();
|
|
||||||
}
|
|
||||||
return optionsContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
async _apiOptionsGet(...args) {
|
async _apiOptionsGet(...args) {
|
||||||
const options = await this._apiOptionsGetOld(...args);
|
const options = await this._apiOptionsGetOld(...args);
|
||||||
options.general.enable = true;
|
options.general.enable = true;
|
||||||
@ -213,6 +203,7 @@ class PopupPreviewFrame {
|
|||||||
async _updateOptionsContext({optionsContext}) {
|
async _updateOptionsContext({optionsContext}) {
|
||||||
this._optionsContext = optionsContext;
|
this._optionsContext = optionsContext;
|
||||||
if (this._frontend === null) { return; }
|
if (this._frontend === null) { return; }
|
||||||
|
this._frontend.setOptionsContextOverride(optionsContext);
|
||||||
await this._frontend.updateOptions();
|
await this._frontend.updateOptions();
|
||||||
await this._updateSearch();
|
await this._updateSearch();
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ class Frontend {
|
|||||||
this._updatePopupToken = null;
|
this._updatePopupToken = null;
|
||||||
this._clearSelectionTimer = null;
|
this._clearSelectionTimer = null;
|
||||||
this._isPointerOverPopup = false;
|
this._isPointerOverPopup = false;
|
||||||
|
this._optionsContextOverride = null;
|
||||||
|
|
||||||
this._runtimeMessageHandlers = new Map([
|
this._runtimeMessageHandlers = new Map([
|
||||||
['requestFrontendReadyBroadcast', {async: false, handler: this._onMessageRequestFrontendReadyBroadcast.bind(this)}],
|
['requestFrontendReadyBroadcast', {async: false, handler: this._onMessageRequestFrontendReadyBroadcast.bind(this)}],
|
||||||
@ -131,26 +132,15 @@ class Frontend {
|
|||||||
this._updateTextScannerEnabled();
|
this._updateTextScannerEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOptionsContextOverride(optionsContext) {
|
||||||
|
this._optionsContextOverride = optionsContext;
|
||||||
|
}
|
||||||
|
|
||||||
async setTextSource(textSource) {
|
async setTextSource(textSource) {
|
||||||
this._textScanner.setCurrentTextSource(null);
|
this._textScanner.setCurrentTextSource(null);
|
||||||
await this._textScanner.search(textSource);
|
await this._textScanner.search(textSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOptionsContext() {
|
|
||||||
let url = window.location.href;
|
|
||||||
if (this._useProxyPopup) {
|
|
||||||
try {
|
|
||||||
url = await api.crossFrame.invoke(this._parentFrameId, 'getUrl', {});
|
|
||||||
} catch (e) {
|
|
||||||
// NOP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const depth = this._depth;
|
|
||||||
const modifierKeys = [...this._activeModifiers];
|
|
||||||
return {depth, url, modifierKeys};
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateOptions() {
|
async updateOptions() {
|
||||||
try {
|
try {
|
||||||
await this._updateOptionsInternal();
|
await this._updateOptionsInternal();
|
||||||
@ -319,7 +309,7 @@ class Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _updateOptionsInternal() {
|
async _updateOptionsInternal() {
|
||||||
const optionsContext = await this.getOptionsContext();
|
const optionsContext = await this._getOptionsContext();
|
||||||
const options = await api.optionsGet(optionsContext);
|
const options = await api.optionsGet(optionsContext);
|
||||||
const scanningOptions = options.scanning;
|
const scanningOptions = options.scanning;
|
||||||
this._options = options;
|
this._options = options;
|
||||||
@ -393,7 +383,7 @@ class Frontend {
|
|||||||
const token = {};
|
const token = {};
|
||||||
this._updatePopupToken = token;
|
this._updatePopupToken = token;
|
||||||
const popup = await popupPromise;
|
const popup = await popupPromise;
|
||||||
const optionsContext = await this.getOptionsContext();
|
const optionsContext = await this._getOptionsContext();
|
||||||
if (this._updatePopupToken !== token) { return; }
|
if (this._updatePopupToken !== token) { return; }
|
||||||
if (popup !== null) {
|
if (popup !== null) {
|
||||||
await popup.setOptionsContext(optionsContext, this._id);
|
await popup.setOptionsContext(optionsContext, this._id);
|
||||||
@ -496,7 +486,7 @@ class Frontend {
|
|||||||
textSource = this._textScanner.getCurrentTextSource();
|
textSource = this._textScanner.getCurrentTextSource();
|
||||||
if (textSource === null) { return; }
|
if (textSource === null) { return; }
|
||||||
}
|
}
|
||||||
this._showPopupContent(textSource, await this.getOptionsContext());
|
this._showPopupContent(textSource, await this._getOptionsContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
_showContent(textSource, focus, definitions, type, sentence, optionsContext) {
|
_showContent(textSource, focus, definitions, type, sentence, optionsContext) {
|
||||||
@ -590,7 +580,7 @@ class Frontend {
|
|||||||
this._popup !== null &&
|
this._popup !== null &&
|
||||||
await this._popup.isVisible()
|
await this._popup.isVisible()
|
||||||
) {
|
) {
|
||||||
this._showPopupContent(textSource, await this.getOptionsContext());
|
this._showPopupContent(textSource, await this._getOptionsContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +612,7 @@ class Frontend {
|
|||||||
|
|
||||||
async _getUpToDateOptionsContext() {
|
async _getUpToDateOptionsContext() {
|
||||||
await this._updatePendingOptions();
|
await this._updatePendingOptions();
|
||||||
return await this.getOptionsContext();
|
return await this._getOptionsContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
_getPreventMiddleMouseValueForPageType(preventMiddleMouseOptions) {
|
_getPreventMiddleMouseValueForPageType(preventMiddleMouseOptions) {
|
||||||
@ -633,4 +623,23 @@ class Frontend {
|
|||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _getOptionsContext() {
|
||||||
|
if (this._optionsContextOverride !== null) {
|
||||||
|
return this._optionsContextOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = window.location.href;
|
||||||
|
if (this._useProxyPopup) {
|
||||||
|
try {
|
||||||
|
url = await api.crossFrame.invoke(this._parentFrameId, 'getUrl', {});
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const depth = this._depth;
|
||||||
|
const modifierKeys = [...this._activeModifiers];
|
||||||
|
return {depth, url, modifierKeys};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user