Add names for all iframe clients

This commit is contained in:
Kovid Goyal 2021-11-29 22:28:39 +05:30
parent 61e2d4e175
commit ee717920ba
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 9 additions and 4 deletions

View File

@ -287,7 +287,7 @@ class CommentsEditorBoss:
'exec_command': self.exec_command, 'exec_command': self.exec_command,
'focus': self.focus, 'focus': self.focus,
} }
self.comm = IframeClient(handlers) self.comm = IframeClient(handlers, 'comments-editor-iframe')
def initialize(self, data): def initialize(self, data):
window.onerror = self.onerror window.onerror = self.onerror

View File

@ -173,10 +173,14 @@ def create_wrapped_iframe(handlers, bootstrap_text, entry_point, kw):
return iframe, ans return iframe, ans
client_instance_num = 0
class IframeClient: class IframeClient:
def __init__(self, handlers): def __init__(self, handlers, name):
self.encrypted_communications = False self.encrypted_communications = False
self.name = name
self.instance_num = v'++client_instance_num'
self.handlers = {k: handlers[k] for k in handlers} self.handlers = {k: handlers[k] for k in handlers}
self.initialize_handler = handlers.initialize self.initialize_handler = handlers.initialize
self.handlers.initialize = self.initialize self.handlers.initialize = self.initialize
@ -233,6 +237,7 @@ class IframeClient:
def send_message(self, action, data): def send_message(self, action, data):
data.action = action data.action = action
data.iframe_id = f'{self.name}-{self.instance_num}'
if self.encrypted_communications: if self.encrypted_communications:
data = self.gcm_to_parent.encrypt(JSON.stringify(data)) data = self.gcm_to_parent.encrypt(JSON.stringify(data))
window.parent.postMessage(data, '*') window.parent.postMessage(data, '*')

View File

@ -191,7 +191,7 @@ class PopupIframeBoss:
'clear': self.on_clear, 'clear': self.on_clear,
'display': self.display, 'display': self.display,
} }
self.comm = IframeClient(handlers) self.comm = IframeClient(handlers, 'popup-iframe')
self.blob_url_map = {} self.blob_url_map = {}
self.name = None self.name = None
self.frag = None self.frag = None

View File

@ -169,7 +169,7 @@ class IframeBoss:
'replace_highlights': self.replace_highlights, 'replace_highlights': self.replace_highlights,
'clear_selection': def(): window.getSelection().removeAllRanges();, 'clear_selection': def(): window.getSelection().removeAllRanges();,
} }
self.comm = IframeClient(handlers) self.comm = IframeClient(handlers, 'main-iframe')
self.last_window_ypos = 0 self.last_window_ypos = 0
self.length_before = None self.length_before = None