(html, js_callback=None)
| 89 | |
| 90 | |
| 91 | def html_to_data_uri(html, js_callback=None): |
| 92 | # This function is called in two ways: |
| 93 | # 1. From Python: in this case value is returned |
| 94 | # 2. From Javascript: in this case value cannot be returned because |
| 95 | # inter-process messaging is asynchronous, so must return value |
| 96 | # by calling js_callback. |
| 97 | html = html.encode("utf-8", "replace") |
| 98 | b64 = base64.b64encode(html).decode("utf-8", "replace") |
| 99 | ret = "data:text/html;base64,{data}".format(data=b64) |
| 100 | if js_callback: |
| 101 | js_print(js_callback.GetFrame().GetBrowser(), |
| 102 | "Python", "html_to_data_uri", |
| 103 | "Called from Javascript. Will call Javascript callback now.") |
| 104 | js_callback.Call(ret) |
| 105 | else: |
| 106 | return ret |
| 107 | |
| 108 | |
| 109 | def set_global_handler(): |
no test coverage detected