def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(800, 600) # 首先获取默认的url协议 h1 = QWebEngineUrlScheme.schemeByName(b'http') h2 = QWebEngineUrlScheme.schemeByName(b'https') # 这里需要修改增加本地文件和跨域支持 CorsEnabled = 0x80 # 5.14才增加 h1.setFlags(h1.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) h2.setFlags(h2.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) # 安装url拦截器和自定义url协议处理 de = QWebEngineProfile.defaultProfile() # @UndefinedVariable de.setRequestInterceptor(RequestInterceptor(self)) de.installUrlSchemeHandler(b'myurl', UrlSchemeHandler(self))
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(800, 600) profile = QWebEngineProfile.defaultProfile() # 首先获取默认的url协议 o_http = QWebEngineUrlScheme.schemeByName(QByteArray(b'http')) o_https = QWebEngineUrlScheme.schemeByName(QByteArray(b'https')) print('scheme:', o_http, o_https) # 这里需要修改增加本地文件和跨域支持 CorsEnabled = 0x80 # 5.14才增加 o_http.setFlags(o_http.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) o_https.setFlags(o_https.flags() | QWebEngineUrlScheme.SecureScheme | QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | CorsEnabled) # 安装url拦截器和自定义url协议处理 de = QWebEngineProfile.defaultProfile() # @UndefinedVariable de.setRequestInterceptor(RequestInterceptor(self)) self.urlSchemeHandler = UrlSchemeHandler(self) de.installUrlSchemeHandler(QByteArray(b'myurl'), self.urlSchemeHandler) # for http de.installUrlSchemeHandler(QByteArray(b'myurls'), self.urlSchemeHandler) # for https
def __init__(self, argv, name=None): if name is None: name = "luminos" super().__init__(argv, name) if QWebEngineUrlScheme is not None: if not QWebEngineUrlScheme.schemeByName(b"luminos").name(): scheme = QWebEngineUrlScheme(b"luminos") scheme.setFlags( QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | QWebEngineUrlScheme.ContentSecurityPolicyIgnored | QWebEngineUrlScheme.SecureScheme ) QWebEngineUrlScheme.registerScheme(scheme) self._initProfile() # self.interceptor = UrlRequestInterceptor() # self.profile.setRequestInterceptor(self.interceptor) log.init.debug("Initializing web setings...") config.instance.changed.connect(self._updateSettings) self.settings = WebEngineSettings(_SettingsWrapper(self.profile)) self.settings.initSettings() self._setupSchemeHandler() self.pluginManager = PluginManager() self.controller = Controller(self) self.controller.mainWindowChanged.connect(self._mainWindowChanged)
def initializeSchemes(): name = QWebEngineUrlScheme.schemeByName(SCHEME_DWEB.encode()).name() if name: log.debug('initializeSchemes() already called') return declareUrlScheme( SCHEME_DWEB, syntax=QWebEngineUrlScheme.Syntax.Path, ) declareUrlScheme( SCHEME_DWEBGW, syntax=QWebEngineUrlScheme.Syntax.Path, ) declareUrlScheme( SCHEME_FS, syntax=QWebEngineUrlScheme.Syntax.Path, ) declareUrlScheme(SCHEME_IPFS, syntax=QWebEngineUrlScheme.Syntax.Host) declareUrlScheme(SCHEME_IPNS, syntax=QWebEngineUrlScheme.Syntax.Host) declareUrlScheme(SCHEME_ENS, syntax=QWebEngineUrlScheme.Syntax.Host) declareUrlScheme(SCHEME_ENSR, syntax=QWebEngineUrlScheme.Syntax.Host) dappsRegisterSchemes() registerMiscSchemes()
def install(self, profile, schemes): self.schemes = schemes """Install the handler for luminos:// URLs on the given profile.""" if QWebEngineUrlScheme is not None: assert QWebEngineUrlScheme.schemeByName(b"luminos").name() profile.installUrlSchemeHandler(b"luminos", self) for scheme in schemes.keys(): if QWebEngineUrlScheme.schemeByName(scheme.encode("ascii")).name(): profile.installUrlSchemeHandler(scheme.encode("ascii"), self) if qtutils.version_check("5.11", compiled=False) and not qtutils.version_check( "5.12", compiled=False): # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378 profile.installUrlSchemeHandler(b"chrome-error", self) profile.installUrlSchemeHandler(b"chrome-extension", self)
def install(self, profile): """Install the handler for qute:// URLs on the given profile.""" if QWebEngineUrlScheme is not None: assert QWebEngineUrlScheme.schemeByName(b'qute') is not None profile.installUrlSchemeHandler(b'qute', self) if (qtutils.version_check('5.11', compiled=False) and not qtutils.version_check('5.12', compiled=False)): # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378 profile.installUrlSchemeHandler(b'chrome-error', self) profile.installUrlSchemeHandler(b'chrome-extension', self)
def registerUriScheme(cls, name: str, base_path: str): if not name in cls.schemes.keys(): cls.schemes[name] = base_path if not QWebEngineUrlScheme.schemeByName(name.encode()).name(): scheme = QWebEngineUrlScheme(name.encode()) scheme.setFlags( QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed | QWebEngineUrlScheme.ContentSecurityPolicyIgnored | QWebEngineUrlScheme.SecureScheme ) QWebEngineUrlScheme.registerScheme(scheme)
def install(self, profile): """Install the handler for qute:// URLs on the given profile.""" if QWebEngineUrlScheme is not None: assert QWebEngineUrlScheme.schemeByName(b'qute') is not None profile.installUrlSchemeHandler(b'qute', self) if (qtutils.version_check('5.11', compiled=False) and not qtutils.version_check('5.12', compiled=False)): # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378 profile.installUrlSchemeHandler(b'chrome-error', self) profile.installUrlSchemeHandler(b'chrome-extension', self)
def init(): """Register the qute:// scheme. Note this needs to be called early, before constructing any QtWebEngine classes. """ if QWebEngineUrlScheme is not None: assert not QWebEngineUrlScheme.schemeByName(b'qute').name() scheme = QWebEngineUrlScheme(b'qute') scheme.setFlags(QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed) QWebEngineUrlScheme.registerScheme(scheme)
def init(): """Register the qute:// scheme. Note this needs to be called early, before constructing any QtWebEngine classes. """ if QWebEngineUrlScheme is not None: assert not QWebEngineUrlScheme.schemeByName(b'qute').name() scheme = QWebEngineUrlScheme(b'qute') scheme.setFlags(QWebEngineUrlScheme.LocalScheme | QWebEngineUrlScheme.LocalAccessAllowed) QWebEngineUrlScheme.registerScheme(scheme)
def initializeSchemes(): name = QWebEngineUrlScheme.schemeByName(SCHEME_DWEB.encode()).name() if name: log.debug('initializeSchemes() already called') return declareUrlScheme(SCHEME_DWEB, syntax=QWebEngineUrlScheme.Syntax.Path, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_DWEBGW, syntax=QWebEngineUrlScheme.Syntax.Path, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_FS, syntax=QWebEngineUrlScheme.Syntax.Path, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_IPFS, syntax=QWebEngineUrlScheme.Syntax.Host, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_IPNS, syntax=QWebEngineUrlScheme.Syntax.Host, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_IPID, syntax=QWebEngineUrlScheme.Syntax.Host, flags=defaultSchemeFlags | QWebEngineUrlScheme.ContentSecurityPolicyIgnored) declareUrlScheme(SCHEME_I, syntax=QWebEngineUrlScheme.Syntax.Path, flags=defaultSchemeFlags) declareUrlScheme(SCHEME_ENS, syntax=QWebEngineUrlScheme.Syntax.Host, flags=serviceWorkersFlags) declareUrlScheme(SCHEME_ENSR, syntax=QWebEngineUrlScheme.Syntax.Host) declareUrlScheme(SCHEME_GEMINI, syntax=QWebEngineUrlScheme.Syntax.Host, flags=defaultSchemeFlags) dappsRegisterSchemes() registerMiscSchemes()
def install(self, profile): """Install the handler for qute:// URLs on the given profile.""" if QWebEngineUrlScheme is not None: assert QWebEngineUrlScheme.schemeByName(b'qute') is not None profile.installUrlSchemeHandler(b'qute', self)
def enableSchemeFlag(name: str, flag): scheme = QWebEngineUrlScheme.schemeByName(name.encode()) if scheme: scheme.setFlags(scheme.flags() | flag)