org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/Ajax.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 18 Mar 2010 11:56:59 -0700
changeset 276 f2f4a1259de8
parent 273 b1f63c2c240c
permissions -rw-r--r--
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     1
/**
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     2
 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     3
 * All rights reserved.
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     4
 * This component and the accompanying materials are made available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     6
 * which accompanies this distribution, and is available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     8
 *
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     9
 * Initial Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    10
 * Nokia Corporation - initial contribution.
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    11
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    12
 * Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    13
 * 
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    14
 * Description:
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    15
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    16
 */
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// Ajax utility calss to create XmlHttpRequest object
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
function Ajax() 
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
	//	xmlHttpRequest object	
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
	var request = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
    // branch for native XMLHttpRequest object
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
    	try 
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
		{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
			request = new XMLHttpRequest();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
			try
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
			{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
				//	attach the Bypass code, if the browser is firefox
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
				if(netscape.security.PrivilegeManager.enablePrivilege)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
				{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
					//	duplicate the function
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
					request._open = request.open;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
					
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
					//	redefine the function definition
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
					request.open = function(method, url, flag)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
					{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
						try
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
						{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
							// Enable Universal Browser Read
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
							netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
							//	call the native XmlHttpRequest.open method
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
							this._open(method, url, flag);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
						}catch(e)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
						{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
							//	call the native XmlHttpRequest.open method
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
							this._open(method, url, flag);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    52
						}
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    53
					};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
				}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
			}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
			catch(e)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
			{
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
				//	eatup all exceptions
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
			}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
		} 
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
		catch(e) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
			request = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
    // branch for IE/Windows ActiveX version
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
    } else if(window.ActiveXObject) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
       	try {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
        	request = new ActiveXObject("Msxml2.XMLHTTP");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
      	} catch(e) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
        	try {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
          		request = new ActiveXObject("Microsoft.XMLHTTP");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
        	} catch(e) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    72
          		alert('Failed to create XmlHttprequest');
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
				return null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
        	}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
		}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
	
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
	return (request);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
}