WebBrowser/WebBrowserPage.py

branch
QtWebEngine
changeset 4910
e97af1181efd
parent 4906
939ff20f712d
child 4913
e16573640cb8
equal deleted inserted replaced
4909:a7bede0eb067 4910:e97af1181efd
106 the main frame 106 the main frame
107 @type bool 107 @type bool
108 @return flag indicating acceptance 108 @return flag indicating acceptance
109 @rtype bool 109 @rtype bool
110 """ 110 """
111 ## self.__lastRequest = request
112 ## if self.__lastRequest.url() != request.url() or \
113 ## type_ != QWebPage.NavigationTypeOther:
114 ## self.__lastRequestType = type_
115
116 # TODO: Qt 5.6: move to handleUnknownProtocol
117 scheme = url.scheme() 111 scheme = url.scheme()
118 if scheme == "mailto": 112 if scheme == "mailto":
119 QDesktopServices.openUrl(url) 113 QDesktopServices.openUrl(url)
120 return False 114 return False
121 115
122 # AdBlock 116 # AdBlock
123 if url.scheme() == "abp": 117 if url.scheme() == "abp":
124 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url): 118 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url):
125 return False 119 return False
126 120
127 ##
128 ## if type_ == QWebPage.NavigationTypeFormResubmitted:
129 ## res = E5MessageBox.yesNo(
130 ## self.view(),
131 ## self.tr("Resending POST request"),
132 ## self.tr(
133 ## """In order to display the site, the request along with"""
134 ## """ all the data must be sent once again, which may lead"""
135 ## """ to some unexpected behaviour of the site e.g. the"""
136 ## """ same action might be performed once again. Do you"""
137 ## """ want to continue anyway?"""),
138 ## icon=E5MessageBox.Warning)
139 ## if not res:
140 ## return False
141
142 return QWebEnginePage.acceptNavigationRequest(self, url, type_, 121 return QWebEnginePage.acceptNavigationRequest(self, url, type_,
143 isMainFrame) 122 isMainFrame)
144 ##
145 ## def populateNetworkRequest(self, request):
146 ## """
147 ## Public method to add data to a network request.
148 ##
149 ## @param request reference to the network request object
150 ## (QNetworkRequest)
151 ## """
152 ## try:
153 ## request.setAttribute(QNetworkRequest.User + 100, self)
154 ## if self.__lastRequest.url() == request.url():
155 ## request.setAttribute(QNetworkRequest.User + 101,
156 ## self.__lastRequestType)
157 ## if self.__lastRequestType == \
158 ## QWebPage.NavigationTypeLinkClicked:
159 ## request.setRawHeader(b"X-Eric6-UserLoadAction",
160 ## QByteArray(b"1"))
161 ## except TypeError:
162 ## pass
163 ##
164 ## def pageAttributeId(self):
165 ## """
166 ## Public method to get the attribute id of the page attribute.
167 ##
168 ## @return attribute id of the page attribute (integer)
169 ## """
170 ## return QNetworkRequest.User + 100
171 ##
172 ## def supportsExtension(self, extension):
173 ## """
174 ## Public method to check the support for an extension.
175 ##
176 ## @param extension extension to test for (QWebPage.Extension)
177 ## @return flag indicating the support of extension (boolean)
178 ## """
179 ## try:
180 ## if extension in [QWebPage.ErrorPageExtension,
181 ## QWebPage.ChooseMultipleFilesExtension]:
182 ## return True
183 ## except AttributeError:
184 ## pass
185 ##
186 ## return QWebPage.supportsExtension(self, extension)
187 ##
188 ## def extension(self, extension, option, output):
189 ## """
190 ## Public method to implement a specific extension.
191 ##
192 ## @param extension extension to be executed (QWebPage.Extension)
193 ## @param option provides input to the extension
194 ## (QWebPage.ExtensionOption)
195 ## @param output stores the output results (QWebPage.ExtensionReturn)
196 ## @return flag indicating a successful call of the extension (boolean)
197 ## """
198 ## if extension == QWebPage.ChooseMultipleFilesExtension:
199 ## info = sip.cast(option,
200 ## QWebPage.ChooseMultipleFilesExtensionOption)
201 ## files = sip.cast(output,
202 ## QWebPage.ChooseMultipleFilesExtensionReturn)
203 ## if info is None or files is None:
204 ## return super(HelpWebPage, self).extension(
205 ## extension, option, output)
206 ##
207 ## suggestedFileName = ""
208 ## if info.suggestedFileNames:
209 ## suggestedFileName = info.suggestedFileNames[0]
210 ##
211 ## files.fileNames = E5FileDialog.getOpenFileNames(
212 ## None,
213 ## self.tr("Select files to upload..."),
214 ## suggestedFileName)
215 ## return True
216 ##
217 ## if extension == QWebPage.ErrorPageExtension:
218 ## info = sip.cast(option, QWebPage.ErrorPageExtensionOption)
219 ##
220 ## errorPage = sip.cast(output, QWebPage.ErrorPageExtensionReturn)
221 ## urlString = bytes(info.url.toEncoded()).decode()
222 ## errorPage.baseUrl = info.url
223 ## if info.domain == QWebPage.QtNetwork and \
224 ## info.error == QNetworkReply.ProtocolUnknownError:
225 ## url = QUrl(info.url)
226 ## res = E5MessageBox.yesNo(
227 ## None,
228 ## self.tr("Protocol Error"),
229 ## self.tr("""Open external application for {0}-link?\n"""
230 ## """URL: {1}""").format(
231 ## url.scheme(), url.toString(
232 ## QUrl.PrettyDecoded | QUrl.RemovePassword)),
233 ## yesDefault=True)
234 ##
235 ## if res:
236 ## QDesktopServices.openUrl(url)
237 ## return True
238 ## elif info.domain == QWebPage.QtNetwork and \
239 ## info.error == QNetworkReply.ContentAccessDenied and \
240 ## info.errorString.startswith("AdBlockRule:"):
241 ## if info.frame != info.frame.page().mainFrame():
242 ## # content in <iframe>
243 ## docElement = info.frame.page().mainFrame()\
244 ## .documentElement()
245 ## for element in docElement.findAll("iframe"):
246 ## src = element.attribute("src")
247 ## if src in info.url.toString():
248 ## element.setAttribute("style", "display:none;")
249 ## return False
250 ## else:
251 ## # the whole page is blocked
252 ## rule = info.errorString.replace("AdBlockRule:", "")
253 ## title = self.tr("Content blocked by AdBlock Plus")
254 ## message = self.tr(
255 ## "Blocked by rule: <i>{0}</i>").format(rule)
256 ##
257 ## htmlFile = QFile(":/html/adblockPage.html")
258 ## htmlFile.open(QFile.ReadOnly)
259 ## html = htmlFile.readAll()
260 ## html = html.replace(
261 ## "@FAVICON@", "qrc:icons/adBlockPlus16.png")
262 ## html = html.replace(
263 ## "@IMAGE@", "qrc:icons/adBlockPlus64.png")
264 ## html = html.replace("@TITLE@", title.encode("utf8"))
265 ## html = html.replace("@MESSAGE@", message.encode("utf8"))
266 ## errorPage.content = html
267 ## return True
268 ##
269 ## if info.domain == QWebPage.QtNetwork and \
270 ## info.error == QNetworkReply.OperationCanceledError and \
271 ## info.errorString == "eric6:No Error":
272 ## return False
273 ##
274 ## if info.domain == QWebPage.WebKit and info.error == 203:
275 ## # "Loading is handled by the media engine"
276 ## return False
277 ##
278 ## title = self.tr("Error loading page: {0}").format(urlString)
279 ## htmlFile = QFile(":/html/notFoundPage.html")
280 ## htmlFile.open(QFile.ReadOnly)
281 ## html = htmlFile.readAll()
282 ## pixmap = qApp.style()\
283 ## .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
284 ## imageBuffer = QBuffer()
285 ## imageBuffer.open(QIODevice.ReadWrite)
286 ## if pixmap.save(imageBuffer, "PNG"):
287 ## html = html.replace("@IMAGE@", imageBuffer.buffer().toBase64())
288 ## pixmap = qApp.style()\
289 ## .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(16, 16)
290 ## imageBuffer = QBuffer()
291 ## imageBuffer.open(QIODevice.ReadWrite)
292 ## if pixmap.save(imageBuffer, "PNG"):
293 ## html = html.replace(
294 ## "@FAVICON@", imageBuffer.buffer().toBase64())
295 ## html = html.replace("@TITLE@", title.encode("utf8"))
296 ## html = html.replace("@H1@", info.errorString.encode("utf8"))
297 ## html = html.replace(
298 ## "@H2@", self.tr("When connecting to: {0}.")
299 ## .format(urlString).encode("utf8"))
300 ## html = html.replace(
301 ## "@LI-1@",
302 ## self.tr("Check the address for errors such as "
303 ## "<b>ww</b>.example.org instead of "
304 ## "<b>www</b>.example.org").encode("utf8"))
305 ## html = html.replace(
306 ## "@LI-2@",
307 ## self.tr(
308 ## "If the address is correct, try checking the network "
309 ## "connection.").encode("utf8"))
310 ## html = html.replace(
311 ## "@LI-3@",
312 ## self.tr(
313 ## "If your computer or network is protected by a firewall "
314 ## "or proxy, make sure that the browser is permitted to "
315 ## "access the network.").encode("utf8"))
316 ## html = html.replace(
317 ## "@LI-4@",
318 ## self.tr("If your cache policy is set to offline browsing,"
319 ## "only pages in the local cache are available.")
320 ## .encode("utf8"))
321 ## html = html.replace(
322 ## "@BUTTON@", self.tr("Try Again").encode("utf8"))
323 ## errorPage.content = html
324 ## return True
325 ##
326 ## return QWebPage.extension(self, extension, option, output)
327 ##
328 ## def __loadStarted(self):
329 ## """
330 ## Private slot to handle the loadStarted signal.
331 ## """
332 ## self.__adBlockedEntries = []
333 ##
334 ## def addAdBlockRule(self, rule, url):
335 ## """
336 ## Public slot to add an AdBlock rule to the page.
337 ##
338 ## @param rule AdBlock rule to add (AdBlockRule)
339 ## @param url URL that matched the rule (QUrl)
340 ## """
341 ## from .AdBlock.AdBlockPage import AdBlockedPageEntry
342 ## entry = AdBlockedPageEntry(rule, url)
343 ## if entry not in self.__adBlockedEntries:
344 ## self.__adBlockedEntries.append(entry)
345 ##
346 ## def getAdBlockedPageEntries(self):
347 ## """
348 ## Public method to get the list of AdBlock page entries.
349 ##
350 ## @return list of AdBlock page entries (list of AdBlockedPageEntry)
351 ## """
352 ## return self.__adBlockedEntries
353 123
354 @classmethod 124 @classmethod
355 def userAgent(cls, resolveEmpty=False): 125 def userAgent(cls, resolveEmpty=False):
356 """ 126 """
357 Class method to get the global user agent setting. 127 Class method to get the global user agent setting.

eric ide

mercurial