Bug 2647 - phonegap example : storage preview support
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 13 May 2010 15:47:02 -0700
changeset 333 895153411a80
parent 332 c27ec884e806
child 334 915daddff233
Bug 2647 - phonegap example : storage preview support
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ChromeInstancesManager.java
org.symbian.tools.wrttools.previewer/preview/data/appManager_data.js
org.symbian.tools.wrttools.previewer/preview/data/calendar_data.js
org.symbian.tools.wrttools.previewer/preview/data/contact_data.js
org.symbian.tools.wrttools.previewer/preview/data/landmarks_data.js
org.symbian.tools.wrttools.previewer/preview/data/location_data.js
org.symbian.tools.wrttools.previewer/preview/data/logging_data.js
org.symbian.tools.wrttools.previewer/preview/data/mediaManagement_data.js
org.symbian.tools.wrttools.previewer/preview/data/messaging_data.js
org.symbian.tools.wrttools.previewer/preview/data/sensor_data.js
org.symbian.tools.wrttools.previewer/preview/data/sysInfo_data.js
org.symbian.tools.wrttools.previewer/preview/script/lib/device.js
org.symbian.tools.wrttools.previewer/preview/script/lib/loader.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/AppManager.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Contact.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Landmarks.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Location.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Logging.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/MediaManagement.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Messaging.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Sensor.js
org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/SysInfo.js
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/MasterScriptProvider.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/Providers.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapInstaller.java
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ChromeInstancesManager.java	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/ChromeInstancesManager.java	Thu May 13 15:47:02 2010 -0700
@@ -44,6 +44,8 @@
             "--disable-extenions", // Use standard UI, should also improve speed and stability
             "--activate-on-launch", // Bring to front on Mac
             "--disable-geolocation", // Use our own Geolocation (needed to emulate Geolocation in phonegap) 
+            "--disable-local-storage", // Disable local storage (needed to emulate Geolocation in phonegap) 
+            "--disable-session-storage", // Disable local storage (needed to emulate Geolocation in phonegap) 
             "--no-default-browser-check", // Our users don't need this nagging
             "--no-first-run", // We don't care
             "--app=%s" // Here we will have widget URI as --app argument
--- a/org.symbian.tools.wrttools.previewer/preview/data/appManager_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/appManager_data.js	Thu May 13 15:47:02 2010 -0700
@@ -109,4 +109,4 @@
 	device.implementation.loadData('Service.AppManager', 'Application', data_apps);
 	device.implementation.loadData('Service.AppManager', 'UserInstalledPackage', data_packages);
 
-})()
+})();
--- a/org.symbian.tools.wrttools.previewer/preview/data/calendar_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/calendar_data.js	Thu May 13 15:47:02 2010 -0700
@@ -146,4 +146,4 @@
 	device.implementation.loadData('Service.Calendar', 'C:Calendar', data_entries);
 	device.implementation.loadData('Service.Calendar', 'C:MyCalendar', data2);
 
-})()
+})();
--- a/org.symbian.tools.wrttools.previewer/preview/data/contact_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/contact_data.js	Thu May 13 15:47:02 2010 -0700
@@ -168,4 +168,4 @@
     device.implementation.loadData('Service.Contact', 'Group', data_groups);
     device.implementation.loadData('Service.Contact', 'Database', data_database);
     
-})()
+})();
--- a/org.symbian.tools.wrttools.previewer/preview/data/landmarks_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/landmarks_data.js	Thu May 13 15:47:02 2010 -0700
@@ -348,5 +348,5 @@
     device.implementation.loadData('Service.Landmarks', 'Category', data_category);
     device.implementation.loadData('Service.Landmarks', 'Database', data_database);
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/location_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/location_data.js	Thu May 13 15:47:02 2010 -0700
@@ -48,5 +48,5 @@
     device.implementation.loadData('Service.Location', 'BasicLocationInformation', data_basicLocationInformation);
     device.implementation.loadData('Service.Location', 'GenericLocationInfo', data_genericLocationInfo);
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/logging_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/logging_data.js	Thu May 13 15:47:02 2010 -0700
@@ -386,5 +386,5 @@
      */
     device.implementation.loadData('Service.Logging', 'Log', logging_data);
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/mediaManagement_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/mediaManagement_data.js	Thu May 13 15:47:02 2010 -0700
@@ -242,5 +242,5 @@
     device.implementation.loadData('Service.MediaManagement', 'Video', video_data);
     device.implementation.loadData('Service.MediaManagement', 'StreamingURL', streaming_data);
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/messaging_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/messaging_data.js	Thu May 13 15:47:02 2010 -0700
@@ -202,5 +202,5 @@
      */
     device.implementation.loadData('Service.Messaging', 'Inbox', data_messaging);
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/sensor_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/sensor_data.js	Thu May 13 15:47:02 2010 -0700
@@ -478,5 +478,5 @@
     device.implementation.loadData('Service.Sensor', 'OrientationRet', dataRet_orientation);
     device.implementation.loadData('Service.Sensor', 'RotationRet', dataRet_rotation);*/
 
-})()
+})();
 	
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/data/sysInfo_data.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/data/sysInfo_data.js	Thu May 13 15:47:02 2010 -0700
@@ -355,4 +355,4 @@
 	 */
 	device.implementation.loadData('Service.SysInfo', '', data_5800);
 
-})()
+})();
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/device.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/device.js	Thu May 13 15:47:02 2010 -0700
@@ -82,28 +82,28 @@
 		var path = path || (libpath + "sapi/");
 		
 		// load API
-		loadScript(path + "AppManager.js");
-		loadScript(path + "Calendar.js");
-		loadScript(path + "Contact.js");
-		loadScript(path + "Landmarks.js");
-		loadScript(path + "Location.js");
-		loadScript(path + "Logging.js");
-		loadScript(path + "MediaManagement.js");
-		loadScript(path + "Messaging.js");
-		loadScript(path + "Sensor.js");
-		loadScript(path + "SysInfo.js");
+//		loadScript(path + "AppManager.js");
+//		loadScript(path + "Calendar.js");
+//		loadScript(path + "Contact.js");
+//		loadScript(path + "Landmarks.js");
+//		loadScript(path + "Location.js");
+//		loadScript(path + "Logging.js");
+//		loadScript(path + "MediaManagement.js");
+//		loadScript(path + "Messaging.js");
+//		loadScript(path + "Sensor.js");
+//		loadScript(path + "SysInfo.js");
 		
 		// load sample data
-		loadScript(datapath + "appManager_data.js");
-		loadScript(datapath + "calendar_data.js");
-		loadScript(datapath + "contact_data.js");
-		loadScript(datapath + "landmarks_data.js");
-		loadScript(datapath + "location_data.js");
-		loadScript(datapath + "logging_data.js");
-		loadScript(datapath + "mediaManagement_data.js");
-		loadScript(datapath + "messaging_data.js");
-		loadScript(datapath + "sensor_data.js");
-		loadScript(datapath + "sysInfo_data.js");
+//		loadScript(datapath + "appManager_data.js");
+//		loadScript(datapath + "calendar_data.js");
+//		loadScript(datapath + "contact_data.js");
+//		loadScript(datapath + "landmarks_data.js");
+//		loadScript(datapath + "location_data.js");
+//		loadScript(datapath + "logging_data.js");
+//		loadScript(datapath + "mediaManagement_data.js");
+//		loadScript(datapath + "messaging_data.js");
+//		loadScript(datapath + "sensor_data.js");
+//		loadScript(datapath + "sysInfo_data.js");
 	}
 	
 	function loadScript(src){
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/loader.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/loader.js	Thu May 13 15:47:02 2010 -0700
@@ -90,11 +90,6 @@
 	/*
 	 Load Scripts
 	 */
-	_BRIDGE_REF.helper.loadScript("preview/script/lib/widget.js");
-	_BRIDGE_REF.helper.loadScript("preview/script/lib/systeminfo.js");
-	_BRIDGE_REF.helper.loadScript("preview/script/lib/menu.js");
-	_BRIDGE_REF.helper.loadScript("preview/script/lib/menuItem.js");
-	_BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
 
 	//	Inject SAPI scripts	
 	if (_BRIDGE_REF.nokia) {
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/AppManager.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/AppManager.js	Thu May 13 15:47:02 2010 -0700
@@ -235,5 +235,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Contact.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Contact.js	Thu May 13 15:47:02 2010 -0700
@@ -419,5 +419,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Landmarks.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Landmarks.js	Thu May 13 15:47:02 2010 -0700
@@ -568,5 +568,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Location.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Location.js	Thu May 13 15:47:02 2010 -0700
@@ -535,5 +535,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Logging.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Logging.js	Thu May 13 15:47:02 2010 -0700
@@ -547,5 +547,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/MediaManagement.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/MediaManagement.js	Thu May 13 15:47:02 2010 -0700
@@ -169,5 +169,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Messaging.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Messaging.js	Thu May 13 15:47:02 2010 -0700
@@ -378,5 +378,5 @@
 	};
 		
 
-}) ()
+}) ();
 
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Sensor.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/Sensor.js	Thu May 13 15:47:02 2010 -0700
@@ -263,4 +263,4 @@
 		msgChannelInfoMapInvalid	: '%s:%s:ChannelInfoMap Type Invalid'
 	};
 
-}) ()
\ No newline at end of file
+}) ();
\ No newline at end of file
--- a/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/SysInfo.js	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/lib/sapi/SysInfo.js	Thu May 13 15:47:02 2010 -0700
@@ -411,4 +411,4 @@
 		
 	  }
 
-}) ()
\ No newline at end of file
+}) ();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/MasterScriptProvider.java	Thu May 13 15:47:02 2010 -0700
@@ -0,0 +1,129 @@
+/**
+ * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.previewer.http.handlers;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.json.simple.JSONObject;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+
+public class MasterScriptProvider implements IResourceProvider {
+    private static final String[] FILES_CORE = { "loader.js", "widget.js", "systeminfo.js", "menu.js", "menuItem.js",
+            "console.js" };
+    private static final String PATH_DEVICE_JS = "preview/script/lib/device.js";
+    private static final String PATH_LOADER_JS = "preview/script/lib/loader.js";
+    private static final String[] FILES_SERVICES = { "AppManager.js", "Calendar.js", "Contact.js", "Landmarks.js",
+            "Location.js", "Logging.js", "MediaManagement.js", "Messaging.js", "Sensor.js", "SysInfo.js" };
+
+    private static final String[] FILES_SERVICES_DATA = { "appManager_data.js", "calendar_data.js", "contact_data.js",
+            "landmarks_data.js", "location_data.js", "logging_data.js", "mediaManagement_data.js", "messaging_data.js",
+            "sensor_data.js", "sysInfo_data.js" };
+    private String WRT10;
+    private String WRT11_SERVICES;
+
+    public String[] getPaths() {
+        return new String[] { PATH_LOADER_JS, PATH_DEVICE_JS };
+    }
+
+    public InputStream getResourceStream(IProject project, IPath resource, Map<String, String[]> parameters)
+            throws IOException, CoreException {
+        if (resource.equals(new Path(PATH_LOADER_JS))) {
+            synchronized (this) {
+                if (WRT10 == null) {
+                    loadCoreAPI();
+                }
+            }
+            return new ByteArrayInputStream((WRT10).getBytes("utf8"));
+        } else if (resource.equals(new Path(PATH_DEVICE_JS))) {
+            synchronized (this) {
+                if (WRT11_SERVICES == null) {
+                    loadWRT11Services();
+                }
+            }
+            return new ByteArrayInputStream((WRT11_SERVICES).getBytes("utf8"));
+        } else {
+            return null;
+        }
+    }
+
+    private void load(String base, String jsfile, StringBuilder builder) throws IOException {
+        final IPath path = new Path(base).append(jsfile);
+        InputStream stream = FileLocator.openStream(PreviewerPlugin.getDefault().getBundle(), path, false);
+        if (stream != null) {
+            try {
+                builder.append(String.format("// Start \"%s\"\n", path.toOSString()));
+                BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "utf8"));
+                String sz;
+                while ((sz = reader.readLine()) != null) {
+                    builder.append(sz).append('\n');
+                }
+                builder.append(String.format("// End \"%s\"\n", path.toOSString()));
+            } finally {
+                stream.close();
+            }
+        } else {
+            PreviewerPlugin.log("Missing JS file " + path.toOSString(), null);
+        }
+
+    }
+
+    private void loadCoreAPI() {
+        final StringBuilder builder = new StringBuilder();
+        try {
+            for (String jsfile : FILES_CORE) {
+                load("/preview/script/lib/", jsfile, builder);
+            }
+        } catch (IOException e) {
+            PreviewerPlugin.log(e);
+        }
+        WRT10 = builder.toString();
+    }
+
+    private void loadWRT11Services() {
+        final StringBuilder builder = new StringBuilder();
+        try {
+            load("/preview/script/lib/", "device.js", builder);
+            for (String jsfile : FILES_SERVICES) {
+                load("/preview/script/lib/sapi", jsfile, builder);
+            }
+            for (String jsfile : FILES_SERVICES_DATA) {
+                load("/preview/data", jsfile, builder);
+            }
+        } catch (IOException e) {
+            PreviewerPlugin.log(e);
+        }
+        WRT11_SERVICES = builder.toString();
+    }
+
+    public void post(IProject project, IPath resource, Map<String, String[]> parameterMap, JSONObject object)
+            throws IOException, CoreException {
+        // Nothing to do
+    }
+
+}
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/Providers.java	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/Providers.java	Thu May 13 15:47:02 2010 -0700
@@ -47,6 +47,7 @@
     private final Map<String, IResourceProvider> HANDLERS = new TreeMap<String, IResourceProvider>();
     private final IResourceProvider defaultHandler = new WorkspaceResourceProvider();
     public Providers() {
+        addPaths(new MasterScriptProvider());
         addPaths(new PreviewerStaticResourceProvider());
         addPaths(new PreferencesResourceProvider());
         addPaths(new ProjectIndexResourceProvider());
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapInstaller.java	Wed May 12 15:03:32 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/PhoneGapInstaller.java	Thu May 13 15:47:02 2010 -0700
@@ -32,6 +32,7 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.wst.jsdt.core.IJavaScriptProject;
+import org.eclipse.wst.jsdt.core.IType;
 import org.eclipse.wst.jsdt.core.JavaScriptCore;
 import org.eclipse.wst.jsdt.core.JavaScriptModelException;
 import org.symbian.tools.wrttools.Activator;
@@ -61,8 +62,10 @@
     public boolean isInstalled(IProject project) {
         IJavaScriptProject jsProject = JavaScriptCore.create(project);
         try {
-            return jsProject.findType("Accelerometer") != null && jsProject.findType("Camera") != null
-                    && jsProject.findType("Geolocation") != null;
+            final IType accel = jsProject.findType("Accelerometer");
+            final IType camera = jsProject.findType("Camera");
+            final IType geo = jsProject.findType("Geolocation");
+            return accel != null && camera != null && geo != null;
         } catch (JavaScriptModelException e) {
             Activator.log(e);
         }