From 0cf97963b8baa129b95511cc23cd1d0a79a60777 Mon Sep 17 00:00:00 2001 From: "vB Results, LLC" Date: Thu, 10 Mar 2016 07:42:59 +0000 Subject: [PATCH] Added WebView Navigation Type Support --- apps/tests/ui/web-view/web-view-tests.ts | 20 ++++++++++++++++++- ios.d.ts | 12 ++++++------ ui/web-view/web-view-common.ts | 17 +++++++++++++--- ui/web-view/web-view.android.ts | 4 ++-- ui/web-view/web-view.d.ts | 9 +++++++++ ui/web-view/web-view.ios.ts | 25 ++++++++++++++++++++++-- 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/apps/tests/ui/web-view/web-view-tests.ts b/apps/tests/ui/web-view/web-view-tests.ts index 9b7d3dcce..4e39ccd9b 100644 --- a/apps/tests/ui/web-view/web-view-tests.ts +++ b/apps/tests/ui/web-view/web-view-tests.ts @@ -1,4 +1,4 @@ -import TKUnit = require("../../TKUnit"); +import TKUnit = require("../../TKUnit"); import testModule = require("../../ui-test"); // @@ -185,6 +185,24 @@ export class WebViewTest extends testModule.UITest { webView.src = targetSrc; } + + public testLoadStartedNavigationTypeExists(done) { + let webView = this.testView; + let targetSrc = "https://github.com/"; + + webView.on(webViewModule.WebView.loadStartedEvent, function (args: webViewModule.LoadEventData) { + try { + TKUnit.assertNull(args.error, args.error); + TKUnit.assertTrue(webViewModule.WebView.navigationTypes.indexOf(args.navigationType) > -1, "navigationTypeExists"); + done(null); + } + catch (e) { + done(e); + } + }); + + webView.src = targetSrc; + } } export function createTestCase(): WebViewTest { diff --git a/ios.d.ts b/ios.d.ts index f5fea120d..d1d6c9ff1 100644 --- a/ios.d.ts +++ b/ios.d.ts @@ -27073,12 +27073,12 @@ declare enum UITouchPhase { UITouchPhaseCancelled } declare enum UIWebViewNavigationType { - UIWebViewNavigationTypeLinkClicked, - UIWebViewNavigationTypeFormSubmitted, - UIWebViewNavigationTypeBackForward, - UIWebViewNavigationTypeReload, - UIWebViewNavigationTypeFormResubmitted, - UIWebViewNavigationTypeOther + LinkClicked, + FormSubmitted, + BackForward, + Reload, + FormResubmitted, + Other } declare enum UIWebPaginationMode { UIWebPaginationModeUnpaginated, diff --git a/ui/web-view/web-view-common.ts b/ui/web-view/web-view-common.ts index fbee78f03..064fd29fb 100644 --- a/ui/web-view/web-view-common.ts +++ b/ui/web-view/web-view-common.ts @@ -1,4 +1,4 @@ -import definition = require("ui/web-view"); +import definition = require("ui/web-view"); import view = require("ui/core/view"); import dependencyObservable = require("ui/core/dependency-observable"); import proxy = require("ui/core/proxy"); @@ -76,6 +76,15 @@ export abstract class WebView extends view.View implements definition.WebView { public static loadStartedEvent = "loadStarted"; public static loadFinishedEvent = "loadFinished"; + public static navigationTypes = [ + "linkClicked", + "formSubmitted", + "backForward", + "reload", + "formResubmitted", + "other" + ]; + public static urlProperty = urlProperty; public static srcProperty = srcProperty; @@ -111,17 +120,19 @@ export abstract class WebView extends view.View implements definition.WebView { eventName: WebView.loadFinishedEvent, object: this, url: url, + navigationType: undefined, error: error }; this.notify(args); } - public _onLoadStarted(url: string) { + public _onLoadStarted(url: string, navigationType: string) { var args = { eventName: WebView.loadStartedEvent, object: this, url: url, + navigationType: navigationType, error: undefined }; @@ -151,4 +162,4 @@ export abstract class WebView extends view.View implements definition.WebView { abstract goForward(): void; abstract reload(): void; -} \ No newline at end of file +} diff --git a/ui/web-view/web-view.android.ts b/ui/web-view/web-view.android.ts index 7d702d044..8ecc3b384 100644 --- a/ui/web-view/web-view.android.ts +++ b/ui/web-view/web-view.android.ts @@ -1,4 +1,4 @@ -import common = require("./web-view-common"); +import common = require("./web-view-common"); import trace = require("trace"); import * as fileSystemModule from "file-system"; @@ -37,7 +37,7 @@ function ensureWebViewClientClass() { if (this._view) { trace.write("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", trace.categories.Debug); - this._view._onLoadStarted(url); + this._view._onLoadStarted(url, common.WebView.navigationTypes[common.WebView.navigationTypes.indexOf("linkClicked")]); } } diff --git a/ui/web-view/web-view.d.ts b/ui/web-view/web-view.d.ts index 9f5ff0689..24ec66722 100644 --- a/ui/web-view/web-view.d.ts +++ b/ui/web-view/web-view.d.ts @@ -20,6 +20,11 @@ declare module "ui/web-view" { */ public static loadFinishedEvent: string; + /** + * Array of string values used when passing navigation types. + */ + public static navigationTypes: string[]; + /** * Represents the observable property backing the Url property of each WebView instance. */ @@ -102,6 +107,10 @@ declare module "ui/web-view" { * Gets the url of the web-view. */ url: string; + /** + * Gets the navigation type of the web-view. + */ + navigationType: string; /** * Gets the error (if any). */ diff --git a/ui/web-view/web-view.ios.ts b/ui/web-view/web-view.ios.ts index 36f66eef3..6c7a08dfa 100644 --- a/ui/web-view/web-view.ios.ts +++ b/ui/web-view/web-view.ios.ts @@ -1,4 +1,4 @@ -import common = require("./web-view-common"); +import common = require("./web-view-common"); import trace = require("trace"); global.moduleMerge(common, exports); @@ -16,9 +16,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate { public webViewShouldStartLoadWithRequestNavigationType(webView: UIWebView, request: NSURLRequest, navigationType: number) { let owner = this._owner.get(); + if (owner && request.URL) { + var navTypeIndex = common.WebView.navigationTypes.indexOf("other"); + + switch (navigationType) { + case UIWebViewNavigationType.LinkClicked: + navTypeIndex = common.WebView.navigationTypes.indexOf("linkClicked"); + break; + case UIWebViewNavigationType.FormSubmitted: + navTypeIndex = common.WebView.navigationTypes.indexOf("formSubmitted"); + break; + case UIWebViewNavigationType.BackForward: + navTypeIndex = common.WebView.navigationTypes.indexOf("backForward"); + break; + case UIWebViewNavigationType.Reload: + navTypeIndex = common.WebView.navigationTypes.indexOf("reload"); + break; + case UIWebViewNavigationType.FormResubmitted: + navTypeIndex = common.WebView.navigationTypes.indexOf("formResubmitted"); + break; + } + trace.write("UIWebViewDelegateClass.webViewShouldStartLoadWithRequestNavigationType(" + request.URL.absoluteString + ", " + navigationType + ")", trace.categories.Debug); - owner._onLoadStarted(request.URL.absoluteString); + owner._onLoadStarted(request.URL.absoluteString, common.WebView.navigationTypes[navTypeIndex]); } return true;