Implement QWebEngineView.createWindow
This commit is contained in:
parent
bb4d09ffd9
commit
a4cd0291a6
@ -381,7 +381,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
|
|
||||||
def __init__(self, win_id, mode_manager, parent=None):
|
def __init__(self, win_id, mode_manager, parent=None):
|
||||||
super().__init__(win_id)
|
super().__init__(win_id)
|
||||||
widget = webview.WebEngineView(tabdata=self.data)
|
widget = webview.WebEngineView(tabdata=self.data, win_id=win_id)
|
||||||
self.history = WebEngineHistory(self)
|
self.history = WebEngineHistory(self)
|
||||||
self.scroller = WebEngineScroller(self, parent=self)
|
self.scroller = WebEngineScroller(self, parent=self)
|
||||||
self.caret = WebEngineCaret(win_id=win_id, mode_manager=mode_manager,
|
self.caret = WebEngineCaret(win_id=win_id, mode_manager=mode_manager,
|
||||||
|
@ -26,17 +26,64 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
|
|||||||
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import log, debug, usertypes
|
from qutebrowser.utils import log, debug, usertypes, objreg
|
||||||
|
|
||||||
|
|
||||||
class WebEngineView(QWebEngineView):
|
class WebEngineView(QWebEngineView):
|
||||||
|
|
||||||
"""Custom QWebEngineView subclass with qutebrowser-specific features."""
|
"""Custom QWebEngineView subclass with qutebrowser-specific features."""
|
||||||
|
|
||||||
def __init__(self, tabdata, parent=None):
|
def __init__(self, tabdata, win_id, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self._win_id = win_id
|
||||||
self.setPage(WebEnginePage(tabdata, parent=self))
|
self.setPage(WebEnginePage(tabdata, parent=self))
|
||||||
|
|
||||||
|
def createWindow(self, wintype):
|
||||||
|
"""Called by Qt when a page wants to create a new window.
|
||||||
|
|
||||||
|
This function is called from the createWindow() method of the
|
||||||
|
associated QWebEnginePage, each time the page wants to create a new
|
||||||
|
window of the given type. This might be the result, for example, of a
|
||||||
|
JavaScript request to open a document in a new window.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
wintype: This enum describes the types of window that can be
|
||||||
|
created by the createWindow() function.
|
||||||
|
|
||||||
|
QWebEnginePage::WebBrowserWindow:
|
||||||
|
A complete web browser window.
|
||||||
|
QWebEnginePage::WebBrowserTab:
|
||||||
|
A web browser tab.
|
||||||
|
QWebEnginePage::WebDialog:
|
||||||
|
A window without decoration.
|
||||||
|
QWebEnginePage::WebBrowserBackgroundTab:
|
||||||
|
A web browser tab without hiding the current visible
|
||||||
|
WebEngineView. (Added in Qt 5.7)
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The new QWebEngineView object.
|
||||||
|
"""
|
||||||
|
background = False
|
||||||
|
if wintype == QWebEnginePage.WebBrowserWindow:
|
||||||
|
log.webview.warning("WebBrowserWindow requested, but we don't "
|
||||||
|
"support that!")
|
||||||
|
elif wintype == QWebEnginePage.WebBrowserTab:
|
||||||
|
pass
|
||||||
|
elif wintype == QWebEnginePage.WebDialog:
|
||||||
|
log.webview.warning("WebDialog requested, but we don't support "
|
||||||
|
"that!")
|
||||||
|
elif (hasattr(QWebEnginePage, 'WebBrowserBackgroundTab') and
|
||||||
|
wintype == QWebEnginePage.WebBrowserBackgroundTab):
|
||||||
|
background = True
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid wintype {}".format(debug.qenum_key(
|
||||||
|
QWebEnginePage, wintype)))
|
||||||
|
|
||||||
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
|
window=self._win_id)
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
return tabbed_browser.tabopen(background=background)._widget
|
||||||
|
|
||||||
|
|
||||||
class WebEnginePage(QWebEnginePage):
|
class WebEnginePage(QWebEnginePage):
|
||||||
|
|
||||||
@ -74,11 +121,6 @@ class WebEnginePage(QWebEnginePage):
|
|||||||
logger = level_to_logger[level]
|
logger = level_to_logger[level]
|
||||||
logger(logstring)
|
logger(logstring)
|
||||||
|
|
||||||
def createWindow(self, _typ):
|
|
||||||
"""Handle new windows via JS."""
|
|
||||||
log.stub()
|
|
||||||
return None
|
|
||||||
|
|
||||||
def acceptNavigationRequest(self,
|
def acceptNavigationRequest(self,
|
||||||
url: QUrl,
|
url: QUrl,
|
||||||
typ: QWebEnginePage.NavigationType,
|
typ: QWebEnginePage.NavigationType,
|
||||||
|
22
tests/end2end/data/javascript/window_open.html
Normal file
22
tests/end2end/data/javascript/window_open.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function open_modal() {
|
||||||
|
if (window.showModalDialog) {
|
||||||
|
window.showModalDialog();
|
||||||
|
} else {
|
||||||
|
window.open('', 'window', 'modal');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<button onclick="window.open('', 'window')" id="open-normal">normal</button>
|
||||||
|
<button onclick="open_modal()" id="open-modal">modal</button>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -19,7 +19,6 @@ Feature: Using hints
|
|||||||
|
|
||||||
### Opening in current or new tab
|
### Opening in current or new tab
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Following a hint and force to open in current tab.
|
Scenario: Following a hint and force to open in current tab.
|
||||||
When I open data/hints/link_blank.html
|
When I open data/hints/link_blank.html
|
||||||
And I hint with args "links current" and follow a
|
And I hint with args "links current" and follow a
|
||||||
@ -27,7 +26,6 @@ Feature: Using hints
|
|||||||
Then the following tabs should be open:
|
Then the following tabs should be open:
|
||||||
- data/hello.txt (active)
|
- data/hello.txt (active)
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Following a hint and allow to open in new tab.
|
Scenario: Following a hint and allow to open in new tab.
|
||||||
When I open data/hints/link_blank.html
|
When I open data/hints/link_blank.html
|
||||||
And I hint with args "links normal" and follow a
|
And I hint with args "links normal" and follow a
|
||||||
@ -36,7 +34,6 @@ Feature: Using hints
|
|||||||
- data/hints/link_blank.html
|
- data/hints/link_blank.html
|
||||||
- data/hello.txt (active)
|
- data/hello.txt (active)
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Following a hint to link with sub-element and force to open in current tab.
|
Scenario: Following a hint to link with sub-element and force to open in current tab.
|
||||||
When I open data/hints/link_span.html
|
When I open data/hints/link_span.html
|
||||||
And I run :tab-close
|
And I run :tab-close
|
||||||
@ -154,13 +151,11 @@ Feature: Using hints
|
|||||||
And I hint wht args "links normal" and follow a
|
And I hint wht args "links normal" and follow a
|
||||||
Then "navigation request: url http://localhost:*/data/hello2.txt, type NavigationTypeLinkClicked, *" should be logged
|
Then "navigation request: url http://localhost:*/data/hello2.txt, type NavigationTypeLinkClicked, *" should be logged
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Opening a link inside a specific iframe
|
Scenario: Opening a link inside a specific iframe
|
||||||
When I open data/hints/iframe_target.html
|
When I open data/hints/iframe_target.html
|
||||||
And I hint with args "links normal" and follow a
|
And I hint with args "links normal" and follow a
|
||||||
Then "navigation request: url http://localhost:*/data/hello.txt, type NavigationTypeLinkClicked, *" should be logged
|
Then "navigation request: url http://localhost:*/data/hello.txt, type NavigationTypeLinkClicked, *" should be logged
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Opening a link with specific target frame in a new tab
|
Scenario: Opening a link with specific target frame in a new tab
|
||||||
When I open data/hints/iframe_target.html
|
When I open data/hints/iframe_target.html
|
||||||
And I hint with args "links tab" and follow a
|
And I hint with args "links tab" and follow a
|
||||||
|
@ -9,7 +9,6 @@ Feature: Javascript stuff
|
|||||||
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/906
|
# https://github.com/The-Compiler/qutebrowser/issues/906
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: Closing a JS window twice (issue 906)
|
Scenario: Closing a JS window twice (issue 906)
|
||||||
When I open about:blank
|
When I open about:blank
|
||||||
And I open data/javascript/issue906.html in a new tab
|
And I open data/javascript/issue906.html in a new tab
|
||||||
|
@ -551,7 +551,6 @@ Feature: Various utility commands.
|
|||||||
Then the page should not be scrolled
|
Then the page should not be scrolled
|
||||||
And the error "prompt-accept: This command is only allowed in prompt/yesno mode." should be shown
|
And the error "prompt-accept: This command is only allowed in prompt/yesno mode." should be shown
|
||||||
|
|
||||||
@qtwebengine_todo: createWindow is not implemented yet
|
|
||||||
Scenario: :repeat-command with mode-switching command
|
Scenario: :repeat-command with mode-switching command
|
||||||
Given I open data/hints/link_blank.html
|
Given I open data/hints/link_blank.html
|
||||||
And I run :tab-only
|
And I run :tab-only
|
||||||
|
Loading…
Reference in New Issue
Block a user