Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2017-04-10 13:02:22 +0000
committerIvan Furnadjiev2017-04-21 08:08:47 +0000
commitec69db4af8f4cf95fb27ddd013f67f0d90bc87ad (patch)
treec7804a92a0b4919665897ef24a86e170ef8ab924
parentbcc7fb4e6aff077e308e27c1f138349760e06a79 (diff)
downloadorg.eclipse.rap-ec69db4af8f4cf95fb27ddd013f67f0d90bc87ad.tar.gz
org.eclipse.rap-ec69db4af8f4cf95fb27ddd013f67f0d90bc87ad.tar.xz
org.eclipse.rap-ec69db4af8f4cf95fb27ddd013f67f0d90bc87ad.zip
Expose Client class in client API
The Client class we use to identify browser and available features could be highly useful for custom widget developer. 415810: [WebClient] make Client class public https://bugs.eclipse.org/bugs/show_bug.cgi?id=415810 Change-Id: I14a57be9a57d442cfde5a90b869ee17a6e7f579e
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rap.js13
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/client/Client.js93
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ClientAPITest.js7
3 files changed, 102 insertions, 11 deletions
diff --git a/bundles/org.eclipse.rap.rwt/js/rap.js b/bundles/org.eclipse.rap.rwt/js/rap.js
index 9d8409e389..939ca7ab72 100644
--- a/bundles/org.eclipse.rap.rwt/js/rap.js
+++ b/bundles/org.eclipse.rap.rwt/js/rap.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 EclipseSource and others.
+ * Copyright (c) 2012, 2017 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -84,7 +84,7 @@ rap = {
* For SWT/RWT widgets (any Control or Item) a wrapper (instance of {@link Widget}) is returned that approximates
* a subset of the API of its Java analog. Getting objects of other types is unsupported.
* @see Widget
- * @see rap.registerTypeHandler
+ * @see rap.registerTypeHandler
* @param {string} id The protocol id for a client object.
* @returns {Object} The client object associated with the id.
*/
@@ -113,6 +113,15 @@ rap = {
},
/**
+ * @description Returns an instance of Client object used for basic client detection.
+ * @returns {Client}
+ * @since 3.2
+ */
+ getClient : function() {
+ return rwt.client.Client;
+ },
+
+ /**
* @description Register the function as a listener of the given type. Registering unknown
* types throws an Error.
* @param {string} type The type of the event (e.g. "send").
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/client/Client.js b/bundles/org.eclipse.rap.rwt/js/rwt/client/Client.js
index a7ec57e3cc..4e9e2f4176 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/client/Client.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/client/Client.js
@@ -18,6 +18,9 @@ namespace( "rwt.client" );
*
* Version names follow the wikipedia scheme: major.minor[.revision[.build]] at
* http://en.wikipedia.org/wiki/Software_version
+ *
+ * @public
+ * @since 3.2
*/
rwt.client.Client = {
@@ -30,7 +33,6 @@ rwt.client.Client = {
this._engineVersionRevision = 0;
this._engineVersionBuild = 0;
this._browserPlatform = "other";
- this._runsLocally = window.location.protocol === "file:";
this._defaultLocale = "en";
// NOTE: Order is important!
this._initKonqueror();
@@ -43,62 +45,102 @@ rwt.client.Client = {
this._initPlatform();
},
- getRunsLocally : function() {
- return this._runsLocally;
- },
-
+ /**
+ * @description Returns the name of the browser engine - "trident", "gecko", "webkit" or "blink".
+ * If the browser engine name can't be detected this function returns "unknown".
+ */
getEngine : function() {
return this._engineName;
},
+ /**
+ * @description Returns the name of the browser, "chrome" or "firefox" for example.
+ * If the browser name can't be detected this function returns "unknown".
+ */
getBrowser : function() {
return this._browserName;
},
+ /**
+ * @description Returns the browser engine version.
+ */
getVersion : function() {
return this._engineVersion;
},
+ /**
+ * @description Returns the major number of browser engine version.
+ */
getMajor : function() {
return this._engineVersionMajor;
},
+ /**
+ * @description Returns the minor number of browser engine version.
+ */
getMinor : function() {
return this._engineVersionMinor;
},
+ /**
+ * @description Returns the revision number of browser engine version.
+ */
getRevision : function() {
return this._engineVersionRevision;
},
+ /**
+ * @description Returns the build number of browser engine version.
+ */
getBuild : function() {
return this._engineVersionBuild;
},
+ /**
+ * @description Returns true is browser engine is "trident" (IE/Edge), false otherwise.
+ */
isTrident : function() {
return this._engineName === "trident";
},
+ /**
+ * @description Returns true is browser engine is "gecko" (Firefox), false otherwise.
+ */
isGecko : function() {
return this._engineName === "gecko";
},
+ /**
+ * @description Returns true is browser engine is "blink" (Chrome/Opera), false otherwise.
+ */
isBlink : function() {
return this._engineName === "blink";
},
+ /**
+ * @description Returns true is browser engine is "webkit" (Safari), false otherwise.
+ */
isWebkit : function() {
return this._engineName === "webkit";
},
+ /**
+ * @description Returns the client timezone.
+ */
getTimezoneOffset : function() {
return ( new Date() ).getTimezoneOffset();
},
+ /**
+ * @description Returns the browser locale as defined in http://www.ietf.org/rfc/bcp/bcp47.txt.
+ */
getLocale : function() {
return this._browserLocale;
},
+ /**
+ * @description Returns the language part from the browser locale.
+ */
getLanguage : function() {
var locale = this.getLocale();
var language;
@@ -111,14 +153,23 @@ rwt.client.Client = {
return language;
},
+ /**
+ * @description Returns the region part from the browser locale.
+ */
getTerritory : function() {
return this.getLocale().split( "_" )[ 1 ] || "";
},
+ /**
+ * @description Returns the browser default locale.
+ */
getDefaultLocale : function() {
return this._defaultLocale;
},
+ /**
+ * @description Returns true if the current browser locale is the default one, false otherwise.
+ */
usesDefaultLocale : function() {
return this._browserLocale === this._defaultLocale;
},
@@ -127,30 +178,51 @@ rwt.client.Client = {
return this._engineBoxSizingAttributes;
},
+ /**
+ * @description Returns client platform like Windows, Android for example.
+ */
getPlatform : function() {
return this._browserPlatform;
},
+ /**
+ * @description Returns true if the browser is mobile Safari, false otherwise.
+ */
isMobileSafari : function() {
return this.getPlatform() === "ios" && this.getBrowser() === "safari";
},
+ /**
+ * @description Returns true if the browser is mobile Chrome, false otherwise.
+ */
isMobileChrome : function() {
return this.getPlatform() === "android" && this.getBrowser() === "chrome";
},
+ /**
+ * @description Returns true if the browser is default Android browser, false otherwise.
+ */
isAndroidBrowser : function() {
return this.getPlatform() === "android" && this.getBrowser() === "android";
},
+ /**
+ * @description Returns true if the browser is mobile Firefox, false otherwise.
+ */
isMobileFirefox : function() {
return this.getPlatform() === "android" && this.getBrowser() === "firefox";
},
+ /**
+ * @description Returns true if the browser supports file drop, false otherwise.
+ */
supportsFileDrop : function() {
return !!window.FormData;
},
+ /**
+ * @description Returns true if the browser supports touch events, false otherwise.
+ */
supportsTouch : function() {
return this.isMobileSafari()
|| this.isAndroidBrowser()
@@ -158,8 +230,12 @@ rwt.client.Client = {
|| this.isMobileFirefox();
},
- // NOTE: This returns true if the browser sufficiently implements
- // border-radius, drop-shadow and linear-gradient.
+ /**
+ * @description Returns true if the browser supports CSS3, false otherwise.
+ *
+ * NOTE: This returns true if the browser sufficiently implements border-radius,
+ * drop-shadow and linear-gradient.
+ */
supportsCss3 : function() {
var engine = rwt.client.Client.getEngine();
var version = rwt.client.Client.getVersion();
@@ -189,6 +265,9 @@ rwt.client.Client = {
return result;
},
+ /**
+ * @description Returns application base path.
+ */
getBasePath : function() {
if( !this._basePath ) {
this._basePath = this._computeBasePath( document.location.href );
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ClientAPITest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ClientAPITest.js
index 19775c807c..4993f81de6 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ClientAPITest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/ClientAPITest.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 EclipseSource and others.
+ * Copyright (c) 2011, 2017 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -352,6 +352,10 @@ rwt.qx.Class.define( "org.eclipse.rwt.test.tests.ClientAPITest", {
// succeeds by not crashing
},
+ testGetClient : function() {
+ assertIdentical( rwt.client.Client, rap.getClient() );
+ },
+
setUp : function() {
shell = TestUtil.createShellByProtocol( "w2" );
},
@@ -363,7 +367,6 @@ rwt.qx.Class.define( "org.eclipse.rwt.test.tests.ClientAPITest", {
}
}
-
}
} );

Back to the top