Merge pull request #10343 from druiz17/tabletwebview-fix-links

fix Tablet webview issues of not loading correct url.
This commit is contained in:
druiz17 2017-05-02 08:09:22 -07:00 committed by GitHub
commit 18368cc073

View file

@ -23,11 +23,13 @@ Item {
property bool keyboardRaised: false property bool keyboardRaised: false
property bool punctuationMode: false property bool punctuationMode: false
property bool isDesktop: false property bool isDesktop: false
property bool removingPage: false property string initialPage: ""
property bool loadingPage: false property bool startingUp: true
property alias webView: webview property alias webView: webview
property alias profile: webview.profile property alias profile: webview.profile
property bool remove: false property bool remove: false
property var urlList: []
property var forwardList: []
property int currentPage: -1 // used as a model for repeater property int currentPage: -1 // used as a model for repeater
@ -79,9 +81,12 @@ Item {
id: displayUrl id: displayUrl
color: hifi.colors.baseGray color: hifi.colors.baseGray
font.pixelSize: 12 font.pixelSize: 12
verticalAlignment: Text.AlignLeft
anchors { anchors {
top: nav.bottom top: nav.bottom
horizontalCenter: parent.horizontalCenter; horizontalCenter: parent.horizontalCenter;
left: parent.left
leftMargin: 20
} }
} }
@ -106,19 +111,19 @@ Item {
} }
function goBack() { function goBack() {
if (webview.canGoBack && !isUrlLoaded(webview.url)) { if (webview.canGoBack) {
if (currentPage > 0) { forwardList.push(webview.url);
removingPage = true;
pagesModel.remove(currentPage);
}
webview.goBack(); webview.goBack();
} else if (currentPage > 0) { } else if (web.urlList.length > 0) {
removingPage = true; var url = web.urlList.pop();
pagesModel.remove(currentPage); loadUrl(url);
} else if (web.forwardList.length > 0) {
var url = web.forwardList.pop();
loadUrl(url);
web.forwardList = [];
} }
} }
function closeWebEngine() { function closeWebEngine() {
if (remove) { if (remove) {
web.destroy(); web.destroy();
@ -151,32 +156,42 @@ Item {
view.setEnabled(true); view.setEnabled(true);
} }
function loadUrl(url) {
webview.url = url
web.url = webview.url;
web.address = webview.url;
}
function onInitialPage(url) {
return (url === webview.url);
}
function urlAppend(url) { function urlAppend(url) {
if (removingPage) {
removingPage = false;
return;
}
var lurl = decodeURIComponent(url) var lurl = decodeURIComponent(url)
if (lurl[lurl.length - 1] !== "/") { if (lurl[lurl.length - 1] !== "/") {
lurl = lurl + "/" lurl = lurl + "/"
} }
if (currentPage === -1 || (pagesModel.get(currentPage).webUrl !== lurl && !timer.running)) { web.urlList.push(url);
timer.start(); setBackButtonStatus();
pagesModel.append({webUrl: lurl});
}
} }
onCurrentPageChanged: { function setBackButtonStatus() {
if (currentPage >= 0 && currentPage < pagesModel.count) { if (web.urlList.length > 0 || webview.canGoBack) {
timer.start(); back.enabledColor = hifi.colors.darkGray;
webview.url = pagesModel.get(currentPage).webUrl; back.enabled = true;
web.url = webview.url; } else {
web.address = webview.url; back.enabledColor = hifi.colors.baseGray;
back.enabled = false;
} }
} }
onUrlChanged: { onUrlChanged: {
gotoPage(url) loadUrl(url);
if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
} }
QtObject { QtObject {
@ -184,18 +199,7 @@ Item {
WebChannel.id: "eventBridgeWrapper" WebChannel.id: "eventBridgeWrapper"
property var eventBridge; property var eventBridge;
} }
Timer {
id: timer
interval: 200
running: false
repeat: false
onTriggered: timer.stop();
}
WebEngineView { WebEngineView {
id: webview id: webview
objectName: "webEngineView" objectName: "webEngineView"
@ -235,6 +239,7 @@ Item {
worldId: WebEngineScript.MainWorld worldId: WebEngineScript.MainWorld
} }
property string urlTag: "noDownload=false";
userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ] userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ]
property string newUrl: "" property string newUrl: ""
@ -261,9 +266,7 @@ Item {
keyboard.resetShiftMode(false); keyboard.resetShiftMode(false);
// Required to support clicking on "hifi://" links // Required to support clicking on "hifi://" links
if (WebEngineView.LoadStartedStatus == loadRequest.status) { if (WebEngineView.LoadStartedStatus == loadRequest.status) {
urlAppend(loadRequest.url.toString()); var url = loadRequest.url.toString();
loadingPage = true;
var url = loadRequest.url.toString();
if (urlHandler.canHandleUrl(url)) { if (urlHandler.canHandleUrl(url)) {
if (urlHandler.handleUrl(url)) { if (urlHandler.handleUrl(url)) {
root.stop(); root.stop();
@ -274,9 +277,19 @@ Item {
if (WebEngineView.LoadFailedStatus == loadRequest.status) { if (WebEngineView.LoadFailedStatus == loadRequest.status) {
console.log(" Tablet WebEngineView failed to laod url: " + loadRequest.url.toString()); console.log(" Tablet WebEngineView failed to laod url: " + loadRequest.url.toString());
} }
}
if (WebEngineView.LoadSucceededStatus == loadRequest.status) {
web.address = webview.url;
if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
}
}
onNewViewRequested: { onNewViewRequested: {
var currentUrl = webview.url;
urlAppend(currentUrl);
request.openIn(webview); request.openIn(webview);
} }
} }