cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [16/50] [abbrv] Merging+Moving Windows7 specifics
Date Wed, 17 Oct 2012 23:27:00 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/mp4patch.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/mp4patch.c b/windows7/Cordova/mp4patch.c
new file mode 100644
index 0000000..b377cc0
--- /dev/null
+++ b/windows7/Cordova/mp4patch.c
@@ -0,0 +1,175 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// For some reason, the mp4 files we generate using MF topologies show incorrect durations if several tracks are used
+
+// Pending a root cause explanation for this, work around the problem by overwriting the values in the duration field
+// in the movie header
+
+// The mp4 files are structured as a collection of 'atoms' starting with two fields:
+
+// size (4 bytes)
+// type (4 bytes)
+
+// Among the top level atoms, we're interested in the the movie (moov) atom, which should contain other atoms,
+// including the movie header
+
+// movie duration should be the duration of the longest track
+// time scale is the number of time units per second
+// time in seconds since midnight, January 1, 1904, UTC
+
+// All integer values are stored in big endian form (most significant byte first)
+
+// Each track (track) contains an header (tkhd)
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+// Couple of big-endian read/write macros
+#define READ_BE4(addr)	(*(addr) << 24) | (*(addr+1) << 16) | (*(addr+2) << 8) | *(addr+3)
+#define WRITE_BE4(addr, val) *(addr) = val >> 24; *(addr+1) = (BYTE) (val >> 16); *(addr+2) = (BYTE) (val >> 8); *(addr+3) = (BYTE) val
+
+// The implementation is limited to 32 bits mp4 files for now as Media Foundation does not generate larger files
+
+void locate_moov(BYTE* start, DWORD size, BYTE** moov_start, DWORD* moov_size)
+{
+	// Check top level atoms
+
+	DWORD cursor = 0;
+	DWORD atom_size;
+	DWORD atom_type;
+
+	while (cursor + 8 < size)
+	{
+		atom_size = READ_BE4(start + cursor);
+		atom_type = READ_BE4(start + 4 + cursor);
+
+		if (atom_type == 'moov')
+		{
+			*moov_start = start + cursor;
+			*moov_size = atom_size;
+			return;
+		}
+		 
+		if (atom_size < 8)
+			return;
+		
+		cursor += atom_size;
+	}
+}
+
+void locate_mvhd(BYTE* start, DWORD size, BYTE** mvhd_start, DWORD* mvhd_size)
+{
+	// Check atoms within moov, looking for mvhd
+
+	DWORD cursor = 0;
+	DWORD atom_size;
+	DWORD atom_type;
+
+	while (cursor + 8 < size)
+	{
+		atom_size = READ_BE4(start + cursor);
+		atom_type = READ_BE4(start + 4 + cursor);
+
+		if (atom_type == 'mvhd')
+		{
+			*mvhd_start = start + cursor;
+			*mvhd_size = atom_size;
+			return;
+		}
+
+		if (atom_size < 8)
+			return;
+
+		cursor += atom_size;
+	}
+}
+
+
+void fix_mp4_duration (wchar_t* file_name, LONGLONG duration)
+{
+	HANDLE file_handle;
+	HANDLE mapping_handle;
+	
+	DWORD file_size;
+	BYTE* mapping_addr;
+	BYTE* moov_addr = 0;
+	BYTE* mvhd_addr = 0;
+	DWORD moov_size;
+	DWORD mvhd_size;
+	DWORD time_scale;
+	DWORD fixed_duration;
+	DWORD time_ratio;
+	
+	// Open file for read & write
+	file_handle = CreateFile(file_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+
+	if (file_handle == INVALID_HANDLE_VALUE)
+		return;
+
+	file_size = GetFileSize(file_handle, 0);
+		
+	// Create mapping
+	mapping_handle = CreateFileMapping(file_handle, 0, PAGE_READWRITE, 0, 0, 0);
+
+	if (mapping_handle == NULL)
+		goto close_file;
+
+	// Create view
+	mapping_addr = (BYTE*) MapViewOfFile(mapping_handle, FILE_MAP_WRITE, 0, 0, file_size);
+	
+	// Locate top level movie atom
+	locate_moov(mapping_addr, file_size, &moov_addr, &moov_size);
+
+	if (moov_addr)
+	{
+		// Inside it, locate movie header
+		locate_mvhd(moov_addr + 8, moov_size, &mvhd_addr, &mvhd_size);
+
+		if (mvhd_addr)
+		{
+			// The movie header (mvhd) atom has the following fields:
+			// version (1 byte)
+			// flags (3 bytes)
+			// creation time, modification time, time scale, duration (4 bytes each)
+
+			time_scale = READ_BE4(mvhd_addr + 4 + 4 + 1 + 3 + 4 + 4);
+			
+			if (time_scale)
+			{
+					time_ratio = (DWORD) (10000000L / time_scale);	// Duration is passed as a number of 100 ns units - there are 10 million ticks per sec
+					fixed_duration = (DWORD) (duration/time_ratio);
+
+					WRITE_BE4(mvhd_addr + 4 + 4 + 1 + 3 + 4 + 4 + 4, fixed_duration);
+			}
+		}
+	}
+
+	if (mapping_addr)
+		UnmapViewOfFile(mapping_addr);
+
+	CloseHandle(mapping_handle);
+
+close_file:
+
+	CloseHandle(file_handle);
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/mp4patch.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/mp4patch.h b/windows7/Cordova/mp4patch.h
new file mode 100644
index 0000000..377f0de
--- /dev/null
+++ b/windows7/Cordova/mp4patch.h
@@ -0,0 +1,22 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+void fix_mp4_duration (wchar_t* file_name, LONGLONG duration);
+
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/network.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/network.c b/windows7/Cordova/network.c
new file mode 100644
index 0000000..17951ea
--- /dev/null
+++ b/windows7/Cordova/network.c
@@ -0,0 +1,108 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define _WIN32_WINNT 0x0600	// Get access to GetIfEntry2 (Vista and newer), so we can distinguish hardware network interfaces from software ones
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include <ws2def.h> 
+#include <ws2ipdef.h>
+#include <iphlpapi.h>
+
+#pragma comment(lib, "IPHLPAPI.lib")
+
+#include "network.h"
+
+//-------------------------------------------------------------------------------------------------
+
+// Determine type of the first network interface that's up
+static HRESULT get_network_interface_type (BSTR callback_id)
+{
+	int if_type = 0;
+	MIB_IF_TABLE2 *if_table = 0;
+	unsigned int i;
+	wchar_t *type_as_text;
+
+	// Retrieve list of network interfaces ; return -1 in case of error
+	if (GetIfTable2(&if_table))
+		goto outahere;
+
+	// Look for an active ethernet interface
+	for (i = 0; i < if_table->NumEntries; i++)
+		if (if_table->Table[i].InterfaceAndOperStatusFlags.HardwareInterface && if_table->Table[i].OperStatus == IfOperStatusUp && if_table->Table[i].Type == IF_TYPE_ETHERNET_CSMACD)
+		{
+			if_type = IF_TYPE_ETHERNET_CSMACD;
+			goto outahere;
+		}
+
+	// Look for wifi
+	for (i = 0; i < if_table->NumEntries; i++)
+		if (if_table->Table[i].InterfaceAndOperStatusFlags.HardwareInterface && if_table->Table[i].OperStatus == IfOperStatusUp && if_table->Table[i].Type == IF_TYPE_IEEE80211)
+		{
+			if_type = IF_TYPE_IEEE80211;
+			goto outahere;
+		}
+
+	// Look for anything marked as physical and up
+	for (i = 0; i < if_table->NumEntries; i++)
+		if (if_table->Table[i].InterfaceAndOperStatusFlags.HardwareInterface && if_table->Table[i].OperStatus == IfOperStatusUp)
+		{
+			if_type = if_table->Table[i].Type;
+			break;
+		}
+
+outahere:
+	// The returned value is 0 if there aren't any active interface, or one of the IF_TYPE_* codes from ipifcons.h
+	if (if_table)
+		FreeMibTable(if_table);
+
+	switch (if_type)
+	{
+		case 0:
+			type_as_text = L"'none'";
+			break;
+
+		case IF_TYPE_ETHERNET_CSMACD:
+			type_as_text = L"'ethernet'";
+			break;
+
+		case IF_TYPE_IEEE80211:
+			type_as_text = L"'wifi'";
+			break;
+
+		default:
+			type_as_text = L"'unknown'";
+			break;
+	}
+
+	cordova_success_callback(callback_id, FALSE, type_as_text);
+
+	return S_OK;
+}
+
+HRESULT network_exec(BSTR callback_id, BSTR action, BSTR args, VARIANT *result)
+{
+	if (!wcscmp(action, L"getConnectionInfo"))
+			return get_network_interface_type(callback_id);
+
+	return DISP_E_MEMBERNOTFOUND;
+}
+
+DEFINE_CORDOVA_MODULE(Network, L"NetworkStatus", network_exec, NULL, NULL)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/network.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/network.h b/windows7/Cordova/network.h
new file mode 100644
index 0000000..8eda9c1
--- /dev/null
+++ b/windows7/Cordova/network.h
@@ -0,0 +1,22 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "shell.h"
+
+DECLARE_CORDOVA_MODULE(Network)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/notification.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/notification.c b/windows7/Cordova/notification.c
new file mode 100644
index 0000000..a185b11
--- /dev/null
+++ b/windows7/Cordova/notification.c
@@ -0,0 +1,324 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <stdlib.h>
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <wchar.h>
+
+#include "notification.h"
+#include "json.h"
+
+extern HWND	hWnd;
+
+#define FONT_SIZE	10
+#define FONT_NAME	L"Arial"
+#define MAX_BUTTONS	10
+#define ID_BASE		100
+
+LRESULT CALLBACK NotificationDialogProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	int btn_id;
+	HWND hParent;
+	RECT parent_rect;
+	RECT dialog_rect;
+	RECT rc;
+
+	switch (uMsg)
+	{
+		case WM_INITDIALOG:
+
+			// Center the dialog within parent window
+			hParent = GetParent(hDlg);
+
+			GetWindowRect(hParent, &parent_rect);
+			GetWindowRect(hDlg, &dialog_rect);
+			rc = parent_rect;
+
+			OffsetRect(&dialog_rect, -dialog_rect.left, -dialog_rect.top);
+			OffsetRect(&rc, -rc.left, -rc.top);
+			OffsetRect(&rc, -dialog_rect.right, -dialog_rect.bottom);
+
+			SetWindowPos(hDlg, HWND_TOP, parent_rect.left + rc.right*1/2, parent_rect.top + rc.bottom*1/2, 0, 0, SWP_NOSIZE);
+			return TRUE;
+
+		case WM_COMMAND:
+			if (wParam == IDCANCEL)
+			{
+				EndDialog(hDlg, -1);
+				return FALSE;
+			}
+			else
+			{
+				btn_id = (SHORT) (LOWORD(wParam));
+				EndDialog(hDlg, btn_id - ID_BASE);	// Use large button IDs to avoid collisions with IDOK, IDCANCEL and friends 
+				return TRUE;
+			}
+	
+		default:
+			return FALSE;
+	}
+}
+
+
+// Align an USHORT pointer to a 4 bytes aligned boundary, padding with zero if necessary
+#define ALIGN4(cursor)	if (((BYTE) cursor) & 2) *cursor++ = 0;
+   
+// See http://msdn.microsoft.com/en-us/library/ms645394%28v=vs.85%29.aspx
+
+
+LRESULT DisplayMessage(wchar_t* title, int title_len, wchar_t* message, int message_len, wchar_t* button_label[], int button_len[], int num_buttons)
+{
+    DLGTEMPLATE* dlg_template;
+    DLGITEMTEMPLATE* item_template;
+    WORD* cursor;	// 16 bits words pointer
+    LRESULT ret_code;
+	void* buf;
+	int i;
+	int next_x;
+	int button_width = 80;	// Width of a button
+	int button_gap = 6;	// Width of the space separating two buttons
+	int left_margin = 10;	// Left dialog margin
+	int right_margin = 10;	// Right dialog margin
+	int top_margin = 10;
+	int bottom_margin = 10;
+	int static_height = 40;	// Height of the space where static text is displayed
+	int static_to_buttons_margin = num_buttons > 0 ? 5 : 0;
+	int button_height = num_buttons > 0 ? 15 : 0;
+	int num_gaps = num_buttons ? num_buttons -1 : 0;
+	int static_width = num_buttons ? num_buttons * button_width + button_gap * num_gaps : 80;
+	int buf_len;
+	int font_len = wcslen(FONT_NAME);
+
+	// Compute length of work buffer and allocate it
+	buf_len = sizeof(DLGTEMPLATE) + 4 + title_len + 1 + font_len + 1 + message_len + 1 + sizeof(DLGITEMTEMPLATE) + 4 + 2 + num_buttons * sizeof(DLGITEMTEMPLATE) + 
+				+ 100; // Allow for into account possible alignment padding as well as extra fields (class atoms, user data)
+
+	for (i=0; i<num_buttons; i++)
+		buf_len += button_len[i] + 1;	
+
+	buf = malloc(buf_len);
+
+    dlg_template = (DLGTEMPLATE*) buf;
+ 
+    // Dialog header
+ 
+    dlg_template->style = WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT;
+	dlg_template->dwExtendedStyle = 0;
+    dlg_template->cdit = 1 + num_buttons;         // Number of controls
+    dlg_template->x  = 0;			// In Dialog Box Units
+	dlg_template->y  = 0;	
+    dlg_template->cx = left_margin + static_width + right_margin;
+	dlg_template->cy = top_margin + static_height + static_to_buttons_margin + button_height + bottom_margin;
+
+    cursor = (WORD*)(dlg_template + 1);	// Point past DLGTEMPLATE structure
+    *cursor++ = 0;            // Menu
+    *cursor++ = 0;            // Default Dialog class
+
+    // Copy title, add NUL and shift cursor
+	wmemcpy(cursor, title, title_len);
+	cursor += title_len;
+	*cursor++ = 0;
+
+	// Type point and font name (as DS_FONT was specified)
+	*cursor++ = FONT_SIZE;
+	wmemcpy(cursor, FONT_NAME, font_len);
+	cursor += font_len;
+	*cursor++ = 0;
+
+	// Item templates need to be DWORD aligned
+	ALIGN4(cursor);
+
+	// Static control
+
+    item_template = (DLGITEMTEMPLATE*) cursor;
+    item_template->style = WS_CHILD | WS_VISIBLE | SS_CENTER;
+	item_template->dwExtendedStyle = 0;
+	item_template->x  = left_margin;
+	item_template->y  = top_margin;
+    item_template->cx = static_width;
+	item_template->cy = static_height;
+    item_template->id = -1;
+
+    // Move past DLGITEMTEMPLATE structure
+	cursor = (WORD*)(item_template + 1);
+  
+	// Static class
+	*cursor++ = 0xFFFF;
+    *cursor++ = 0x0082;
+
+	// Title
+	wmemcpy(cursor, message, message_len);
+	cursor += message_len;
+	*cursor++ = 0;
+
+    // Empty user data block
+	*cursor++ = 0;
+
+	next_x = left_margin;
+	
+	// Additional controls
+	for (i=0; i<num_buttons; i++)
+	{
+		ALIGN4(cursor);
+
+		item_template = (DLGITEMTEMPLATE*) cursor;
+		item_template->style = WS_CHILD | WS_VISIBLE;
+		item_template->dwExtendedStyle = 0;
+		item_template->x  = next_x;
+		item_template->y  = top_margin + static_height + static_to_buttons_margin;
+		item_template->cx = button_width;
+		item_template->cy = button_height;
+		item_template->id = ID_BASE + i;
+
+		next_x += button_width + button_gap;
+
+		// Move past DLGITEMTEMPLATE structure
+		cursor = (WORD*)(item_template + 1);
+   
+		// Button class
+		*cursor++ = 0xFFFF;
+		*cursor++ = 0x0080;
+
+		// Title
+		wmemcpy(cursor, button_label[i], button_len[i]);
+		cursor += button_len[i];
+		*cursor++ = 0; 
+  
+		// Empty user data block
+		*cursor++ = 0;             
+	}
+
+	ret_code = DialogBoxIndirect(GetModuleHandle(0), dlg_template, hWnd, NotificationDialogProc); 
+    free(buf); 
+    return ret_code; 
+}
+
+static HRESULT show_dialog(BSTR callback_id, BSTR args)
+{
+	wchar_t buf[10];
+	int ret_code;
+	wchar_t* message = 0;
+	wchar_t* buttons = 0;
+	wchar_t* title = 0;
+	int num_buttons = 0;
+	wchar_t* btn_text[MAX_BUTTONS];
+	int btn_text_len[MAX_BUTTONS];
+	unsigned int cursor = 0;
+
+	JsonArray array;
+	JsonItem item;
+
+	// args should be like "["message","title","button1,button2"]"
+
+	// Validate array contents
+	if (!json_parse_and_validate_args(args, &array, JSON_VALUE_STRING,
+									JSON_VALUE_STRING,
+									JSON_VALUE_STRING,
+									JSON_VALUE_INVALID)) {
+		json_free_args(array);
+		return -1;
+	}
+
+	// message
+	item = json_array_get_first(array);
+	message = json_get_string_value(item);
+
+	// title
+	item = json_array_get_next(item);
+	title = json_get_string_value(item);
+
+	// buttons
+	item = json_array_get_next(item);
+	buttons = json_get_string_value(item);
+	if (*buttons == 0)
+		goto button_done; // No button ; consider that a valid use case
+
+button_parsing:
+
+	btn_text[num_buttons] = buttons + cursor;
+	btn_text_len[num_buttons] = 0;
+
+	// Search for separator
+	while (cursor < wcslen(buttons) && *(buttons + cursor) != L',') {
+		cursor++;
+		btn_text_len[num_buttons]++;
+	}
+
+	num_buttons++;
+
+	cursor++;
+	
+	if (cursor < wcslen(buttons) && num_buttons < MAX_BUTTONS)
+		goto button_parsing;
+
+button_done:
+
+	json_free_args(array);
+
+	ret_code = DisplayMessage(title, wcslen(title), message, wcslen(message), btn_text, btn_text_len, num_buttons);
+
+	if (message)
+		free(message);
+	if (title)
+		free(title);
+	if (buttons)
+		free(buttons);
+
+	wsprintf(buf, L"%d", ret_code);
+
+	cordova_success_callback(callback_id, FALSE, buf);
+
+	return S_OK;
+}
+
+static HRESULT vibrate(BSTR callback_id, BSTR args)
+{
+	return S_OK;
+}
+
+static HRESULT beep(BSTR callback_id, BSTR args)
+{
+	int count;
+
+	args++; // skip initial '['
+	*(args + wcslen(args) - 1) = 0; // remove trailing ']'
+
+	for (count = _wtoi(args); count > 0; count--) {
+		MessageBeep(0xFFFFFFFF);
+		Sleep(100);
+	}
+
+	return S_OK;
+}
+
+HRESULT notification_exec(BSTR callback_id, BSTR action, BSTR args, VARIANT *result)
+{
+	if(!wcscmp(action, L"alert") || !wcscmp(action, L"confirm"))
+		return show_dialog(callback_id, args);
+	if (!wcscmp(action, L"vibrate"))
+		return vibrate(callback_id, args);
+	if (!wcscmp(action, L"beep"))
+		return beep(callback_id, args);
+
+	return DISP_E_MEMBERNOTFOUND;
+}
+
+DEFINE_CORDOVA_MODULE(Notification, L"Notification", notification_exec, NULL, NULL)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/notification.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/notification.h b/windows7/Cordova/notification.h
new file mode 100644
index 0000000..8c43551
--- /dev/null
+++ b/windows7/Cordova/notification.h
@@ -0,0 +1,22 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "shell.h"
+
+DECLARE_CORDOVA_MODULE(Notification)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/platform.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/platform.c b/windows7/Cordova/platform.c
new file mode 100644
index 0000000..3b4f14a
--- /dev/null
+++ b/windows7/Cordova/platform.c
@@ -0,0 +1,49 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "platform.h"
+
+static BOOL event_on = TRUE;
+
+BOOL is_back_button_event_enabled(void)
+{
+	return event_on;
+}
+
+static HRESULT platform_exec(BSTR callback_id, BSTR action, BSTR args, VARIANT *result)
+{
+	if (!wcscmp(action, L"backButtonEventOn"))
+	{
+		event_on = TRUE;
+		return S_OK;
+	}
+
+	if (!wcscmp(action, L"backButtonEventOff"))
+	{
+		event_on = FALSE;
+		return S_OK;
+	}
+
+	return DISP_E_MEMBERNOTFOUND;
+}
+
+DEFINE_CORDOVA_MODULE(Platform, L"Platform", platform_exec, NULL, NULL)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/platform.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/platform.h b/windows7/Cordova/platform.h
new file mode 100644
index 0000000..398a58d
--- /dev/null
+++ b/windows7/Cordova/platform.h
@@ -0,0 +1,24 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "shell.h"
+
+BOOL is_back_button_event_enabled (void);
+
+DECLARE_CORDOVA_MODULE(Platform)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/resource.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/resource.h b/windows7/Cordova/resource.h
new file mode 100644
index 0000000..143eeef
--- /dev/null
+++ b/windows7/Cordova/resource.h
@@ -0,0 +1,37 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define IDB_ToolBar						100
+#define IDD_CaptureSettings             101
+
+// Lists in capture settings dialog
+#define IDC_Camera						102
+#define IDC_Microphone					103
+#define IDC_Resolution					104
+#define IDC_VideoEncoder				105
+
+#define IDC_STATIC                      -1
+
+// Toolbar buttons
+#define	ID_START_VIDEO	1
+#define ID_STOP_VIDEO	2
+#define ID_TAKE_PHOTO	3
+#define	ID_PARAMETERS	4
+#define	ID_RETURN		5
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/resource.rc
----------------------------------------------------------------------
diff --git a/windows7/Cordova/resource.rc b/windows7/Cordova/resource.rc
new file mode 100644
index 0000000..584fc9a
--- /dev/null
+++ b/windows7/Cordova/resource.rc
@@ -0,0 +1,40 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "resource.h"
+#include "winuser.rh"
+
+IDD_CaptureSettings DIALOGEX 0, 0, 350, 130
+
+CAPTION "Capture Settings"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    DEFPUSHBUTTON   "OK",IDOK,236,109,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,290,109,50,14
+    COMBOBOX        IDC_Camera,85,11,250,300,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    COMBOBOX        IDC_Microphone,85,35,250,300,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    COMBOBOX        IDC_Resolution,85,59,250,300,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    COMBOBOX        IDC_VideoEncoder,85,83,250,300,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "Camera:",IDC_STATIC,15,14,60,8
+    LTEXT           "Microphone:",IDC_STATIC,15,37,60,8
+    LTEXT           "Resolution:",IDC_STATIC,15,61,60,8
+    LTEXT           "Video Encoder:",IDC_STATIC,15,85,60,8
+END
+
+IDB_ToolBar BITMAP "toolbar.bmp"

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/shell.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/shell.c b/windows7/Cordova/shell.c
new file mode 100644
index 0000000..6235476
--- /dev/null
+++ b/windows7/Cordova/shell.c
@@ -0,0 +1,1471 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <windows.h>
+#include <wchar.h>		// Unicode only for us
+
+#define CINTERFACE 1	// Get C definitions for COM header files
+#include <oleidl.h>		// IOleClientSite, IOleInPlaceFrame, IOleInPlaceSite
+#include <exdisp.h>		// IWebBrowser2
+#include <mshtml.h>		// IHTMLDocument2
+#include <mshtmhst.h>	// IDocHostUIHandler
+#include <exdispid.h>	// DISPID_TITLECHANGE
+
+#include <ipifcons.h>	// Network types
+
+#include <commctrl.h>					// Let's initialize the common controls library
+#pragma comment(lib, "comctl32.lib")	// so they can be used with the process
+
+#include "shell.h"
+#include "common.h"
+#include "device.h"
+#include "accel.h"
+#include "capture.h"
+#include "network.h"
+#include "notification.h"
+#include "storage.h"
+#include "platform.h"
+#include "file.h"
+#include "filetransfer.h"
+#include "compass.h"
+
+//-------------------------------------------------------------------------------------------------
+
+#define NOT_IMPLEMENTED __debugbreak(); OutputDebugStringA(__FUNCTION__); return 0;
+
+IWebBrowser2*			browser_web_if;			// IWebBrowser2 interface to the browser control
+IOleObject*				browser_ole_if;			// IOleObject interface to the browser control, required to pass various OLE related parameters
+IOleInPlaceObject*		browser_ipo_if;			// IOleInPlaceObject interface to the browser control, required to implement IOleInPlaceSite:OnPosRectChange
+
+IOleClientSite*			browser_cs;
+IOleInPlaceSite*		browser_ips;
+IOleInPlaceFrame*		browser_ipf;
+IDispatch*				browser_dsp;			// Browser event dispatcher
+IDocHostUIHandler*		browser_dui;
+IDispatch*				browser_ext;
+IOleCommandTarget*		browser_oct;
+
+DWORD					browser_dsp_cookie;		// Dispatcher connection id, as returned by the connection point Advise call
+
+IDispatch*				document_dispatch_if;	// Needed to get document interface
+IHTMLDocument2*			document_html2_if;		// Needed to get window interface
+IHTMLWindow2*			html_window2_if;		// Needed to run scripts
+
+static struct IOleClientSite	clsi;
+static struct IOleInPlaceSite	inplsi;
+static struct IOleInPlaceFrame	inplfr;
+static struct IDispatch			disp;
+static struct IDocHostUIHandler	duih;
+static struct IDispatch			ext;
+static struct IOleCommandTarget oct;
+
+int clsi_ref_count;
+int inplsi_ref_count;
+int inplfr_ref_count;
+int disp_ref_count;
+int inplfr_ref_count;
+int duih_ref_count;
+int ext_ref_count;
+int oct_ref_count;
+
+const	wchar_t gate_name[]= L"CordovaExec";
+#define DISPID_GATE	8086
+
+#define APP_NAME		L"Cordova Application"
+#define BASE_URL		L"www\\index.html"
+
+#define IE_GPU_REG_KEY		L"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_GPU_RENDERING"		// Registry key enabling GPU acceleration
+#define IE_COMPAT_REG_KEY	L"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION"	// Registry key controlling browser version emulation
+
+wchar_t full_path[_MAX_PATH];	// We record our initial current directory name in there
+
+HWND hWnd;			// Our main window handle
+extern HWND hCaptureWnd;	// Child window handle, when capturing video
+
+BSTR javascript;	// Small utility object, used whenever invoking a js method
+
+void invoke_js_routine (wchar_t* wcs);
+
+#define STATE_STARTING		0	// Machinery starting
+#define STATE_NATIVE_READY	1	// Native Ready event sent
+#define STATE_PAUSED		2	// Paused
+#define STATE_ENDING		3	// Machinery shutting down
+
+int current_state;	// Rough operating state : not ready / ready / temporarily paused
+
+int skip_title_update = 1;	// Title update skip counter, used to avoid initial "index.html"
+
+// Browser window subclassing
+static WNDPROC initial_browser_wnd_proc;
+LRESULT CALLBACK BrowserWndProcWrapper(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+//-------------------------------------------------------------------------------------------------
+
+static CordovaModule *module_list = NULL;
+
+static void register_cordova_module(CordovaModule *module)
+{
+	CordovaModule *item = module_list;
+
+	if (module->init != NULL)
+		module->init();
+
+	if (!item) {
+		module_list = module;
+		return;
+	}
+
+	module->next = module_list;
+	module_list = module;
+}
+
+
+static void close_cordova_module(CordovaModule *module)
+{
+	if (module->close != NULL)
+		module->close();
+}
+
+static void register_cordova_modules()
+{
+	register_cordova_module(CORDOVA_MODULE(Device));
+	register_cordova_module(CORDOVA_MODULE(Camera));
+	register_cordova_module(CORDOVA_MODULE(Capture));
+	register_cordova_module(CORDOVA_MODULE(Accelerometer));
+	register_cordova_module(CORDOVA_MODULE(Network));
+	register_cordova_module(CORDOVA_MODULE(Notification));
+	register_cordova_module(CORDOVA_MODULE(Storage));
+	register_cordova_module(CORDOVA_MODULE(Platform));
+	register_cordova_module(CORDOVA_MODULE(File));
+	register_cordova_module(CORDOVA_MODULE(FileTransfer));
+	register_cordova_module(CORDOVA_MODULE(Compass));
+}
+
+static void close_cordova_modules()
+{
+	close_cordova_module(CORDOVA_MODULE(Device));
+	close_cordova_module(CORDOVA_MODULE(Camera));
+	close_cordova_module(CORDOVA_MODULE(Capture));
+	close_cordova_module(CORDOVA_MODULE(Accelerometer));
+	close_cordova_module(CORDOVA_MODULE(Network));
+	close_cordova_module(CORDOVA_MODULE(Notification));
+	close_cordova_module(CORDOVA_MODULE(Storage));
+	close_cordova_module(CORDOVA_MODULE(Platform));
+	close_cordova_module(CORDOVA_MODULE(File));
+	close_cordova_module(CORDOVA_MODULE(FileTransfer));
+	close_cordova_module(CORDOVA_MODULE(Compass));
+}
+
+static CordovaModule *find_cordova_module(BSTR module_id)
+{
+	CordovaModule *item = module_list;
+
+	while (item) {
+		if (!wcscmp(item->module_id, module_id))
+			return item;
+		item = item->next;
+	}
+
+	return NULL;
+}
+
+static wchar_t *error_string_from_code(CallbackStatus code)
+{
+	switch (code) {
+		case CB_NO_RESULT: return L"cordova.callbackStatus.NO_RESULT";
+		case CB_OK: return L"cordova.callbackStatus.OK";
+		case CB_CLASS_NOT_FOUND_EXCEPTION: return L"cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION";
+		case CB_ILLEGAL_ACCESS_EXCEPTION: return L"cordova.callbackStatus.ILLEGAL_ACCESS_EXCEPTION";
+		case CB_INSTANTIATION_EXCEPTION: return L"cordova.callbackStatus.INSTANTIATION_EXCEPTION";
+		case CB_MALFORMED_URL_EXCEPTION: return L"cordova.callbackStatus.MALFORMED_URL_EXCEPTION";
+		case CB_IO_EXCEPTION: return L"cordova.callbackStatus.IO_EXCEPTION";
+		case CB_INVALID_ACTION: return L"cordova.callbackStatus.INVALID_ACTION";
+		case CB_JSON_EXCEPTION: return L"cordova.callbackStatus.JSON_EXCEPTION";
+		default: return L"cordova.callbackStatus.ERROR";
+	}
+}
+
+void cordova_success_callback(BSTR callback_id, BOOL keep_callback, const wchar_t *message)
+{
+	wchar_t *status_str = (message == NULL) ? error_string_from_code(CB_NO_RESULT) : error_string_from_code(CB_OK);
+	wchar_t *result = L"window.cordova.callbackSuccess('%s',{status:%s,keepCallback:%s,message:%s});";
+	wchar_t *buf;
+	
+	buf = (wchar_t *) malloc(sizeof(wchar_t) * (1 + wcslen(result) + wcslen(callback_id) + wcslen(status_str) + wcslen(L"false") + wcslen(message)));
+
+	wsprintf(buf, result, callback_id, status_str, keep_callback?L"true":L"false", message);
+	invoke_js_routine(buf);
+
+	free(buf);
+}
+
+void cordova_fail_callback(BSTR callback_id, BOOL keep_callback, CallbackStatus status, const wchar_t *message)
+{
+	wchar_t *status_str = error_string_from_code(status);
+	wchar_t *result = L"window.cordova.callbackError('%s',{status:%s,keepCallback:%s,message:%s});";
+	wchar_t *buf;
+	
+	buf = (wchar_t *) malloc(sizeof(wchar_t) * (1 + wcslen(result) + wcslen(callback_id) + wcslen(status_str) + wcslen(L"false") + wcslen(message)));
+
+	wsprintf(buf, result, callback_id, status_str, keep_callback?L"true":L"false", message);
+	invoke_js_routine(buf);
+
+	free(buf);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE InPlFr_QueryInterface(IOleInPlaceFrame * This, REFIID riid, void **ppvObject)
+{
+	NOT_IMPLEMENTED
+}
+
+ULONG STDMETHODCALLTYPE InPlFr_AddRef(IOleInPlaceFrame * This)
+{
+	NOT_IMPLEMENTED
+}
+
+ULONG STDMETHODCALLTYPE InPlFr_Release(IOleInPlaceFrame * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_GetWindow(IOleInPlaceFrame * This, HWND *phwnd)
+{
+	*phwnd = hWnd;
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_ContextSensitiveHelp(IOleInPlaceFrame * This, BOOL fEnterMode)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_GetBorder(IOleInPlaceFrame * This, LPRECT lprectBorder)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_RequestBorderSpace(IOleInPlaceFrame * This, LPCBORDERWIDTHS pborderwidths)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_SetBorderSpace(IOleInPlaceFrame * This, LPCBORDERWIDTHS pborderwidths)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_SetActiveObject(IOleInPlaceFrame * This, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
+{
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_InsertMenus(IOleInPlaceFrame * This, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_SetMenu(IOleInPlaceFrame * This, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
+{
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_RemoveMenus(IOleInPlaceFrame * This, HMENU hmenuShared)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_SetStatusText(IOleInPlaceFrame * This, LPCOLESTR pszStatusText)
+{
+	// Status updates
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_EnableModeless(IOleInPlaceFrame * This, BOOL fEnable)
+{
+	// We don't track the modeless flag state, but as this gets called, reply something meaningful
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlFr_TranslateAccelerator(IOleInPlaceFrame * This, LPMSG lpmsg, WORD wID)
+{
+	NOT_IMPLEMENTED
+}
+
+//-------------------------------------------------------------------------------------------------
+
+// IOleInPlaceFrame vtable
+static IOleInPlaceFrameVtbl inplfr_vtable =
+{
+	InPlFr_QueryInterface,
+	InPlFr_AddRef,
+	InPlFr_Release,
+	InPlFr_GetWindow,
+	InPlFr_ContextSensitiveHelp,
+	InPlFr_GetBorder,
+	InPlFr_RequestBorderSpace,
+	InPlFr_SetBorderSpace,
+	InPlFr_SetActiveObject,
+	InPlFr_InsertMenus,			// Enables the container to insert menu groups
+	InPlFr_SetMenu,				// Adds a composite menu to the window frame containing the object being activated in place
+	InPlFr_RemoveMenus,			// Removes a container's menu elements from the composite menu
+	InPlFr_SetStatusText,		// Sets and displays status text about the in-place object in the container's frame window status line
+	InPlFr_EnableModeless,		// Enables or disables a frame's modeless dialog boxes
+	InPlFr_TranslateAccelerator	// Translates accelerator keystrokes intended for the container's frame while an object is active in place
+};
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE InPlSi_QueryInterface(IOleInPlaceSite * This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IOleInPlaceSite))
+	{
+		*ppvObject = browser_ips;
+		browser_ips->lpVtbl->AddRef(browser_ips);
+		return NOERROR;
+	}
+
+	// We get queries for IID_ServiceProvider, IID_IOleCommandTarget
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+	
+ULONG STDMETHODCALLTYPE InPlSi_AddRef(IOleInPlaceSite * This)
+{
+	inplsi_ref_count++;
+
+	return inplsi_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE InPlSi_Release(IOleInPlaceSite * This)
+{
+	inplsi_ref_count--;
+
+	ASSERT(inplsi_ref_count >= 0);
+
+	return inplsi_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_GetWindow(IOleInPlaceSite * This, HWND *phwnd)
+{
+	*phwnd = hWnd;
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_ContextSensitiveHelp(IOleInPlaceSite * This, BOOL fEnterMode)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_CanInPlaceActivate(IOleInPlaceSite * This)
+{
+	return S_OK;	// Allow activation
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_OnInPlaceActivate(IOleInPlaceSite * This)
+{
+	return S_OK;	// Go ahead and activate object
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_OnUIActivate(IOleInPlaceSite * This)
+{
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_GetWindowContext(IOleInPlaceSite * This, IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
+{
+	*ppFrame = browser_ipf;
+	*ppDoc = 0;
+	GetClientRect(hWnd, lprcPosRect);
+	GetClientRect(hWnd, lprcClipRect);
+
+	// The OLEINPLACEFRAMEINFO structure will need to be modified if we ever want custom keystrokes/accelerators
+	lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
+	lpFrameInfo->fMDIApp = FALSE;
+	lpFrameInfo->hwndFrame = hWnd;
+	lpFrameInfo->haccel = 0;
+	lpFrameInfo->cAccelEntries = 0;
+	
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_Scroll(IOleInPlaceSite * This, SIZE scrollExtant)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_OnUIDeactivate(IOleInPlaceSite * This, BOOL fUndoable)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_OnInPlaceDeactivate(IOleInPlaceSite * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_DiscardUndoState(IOleInPlaceSite * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_DeactivateAndUndo(IOleInPlaceSite * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE InPlSi_OnPosRectChange(IOleInPlaceSite * This, LPCRECT lprcPosRect)
+{
+	if (browser_ipo_if && browser_ipo_if->lpVtbl)
+		browser_ipo_if->lpVtbl->SetObjectRects(browser_ipo_if, lprcPosRect, lprcPosRect);
+
+	return S_OK;
+}
+
+//-------------------------------------------------------------------------------------------------
+
+// IOleInPlaceSite vtable
+static IOleInPlaceSiteVtbl inplsi_vtable =
+{
+	InPlSi_QueryInterface,
+	InPlSi_AddRef,
+	InPlSi_Release,
+	InPlSi_GetWindow,
+	InPlSi_ContextSensitiveHelp,
+	InPlSi_CanInPlaceActivate,	// Determines whether the container can activate the object in place
+	InPlSi_OnInPlaceActivate,	// Notifies the container that one of its objects is being activated in place
+	InPlSi_OnUIActivate,		// Notifies the container that the object is about to be activated in place and that the object is going to replace the container's main menu with an in-place composite menu
+	InPlSi_GetWindowContext,	// Enables an in-place object to retrieve the window interfaces that form the window object hierarchy, and the position in the parent window where the object's in-place activation window should be located
+	InPlSi_Scroll,				// Instructs the container to scroll the view of the object by the specified number of pixels
+	InPlSi_OnUIDeactivate,		// Notifies the container to reinstall its user interface and take focus
+	InPlSi_OnInPlaceDeactivate,	// Notifies the container that it should reinstall its user interface and take focus, and whether the object has an undoable state
+	InPlSi_DiscardUndoState,	// Instructs the container to discard its undo state
+	InPlSi_DeactivateAndUndo,	// Deactivates the object, ends the in-place session, and reverts to the container's saved undo state
+	InPlSi_OnPosRectChange		// Notifies the container that the object extents have changed
+};
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE DUIH_QueryInterface(IDocHostUIHandler * This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IDocHostUIHandler)) 
+	{
+		*ppvObject = browser_dui;
+		browser_dui->lpVtbl->AddRef(browser_dui);
+		return NOERROR;
+	}
+
+	// We're using IOleCommandTarget to intercept javascript error dialogs
+	if (IsEqualIID(riid,&IID_IOleCommandTarget))
+	{
+		*ppvObject = browser_oct;
+		browser_oct->lpVtbl->AddRef(browser_oct);
+		return NOERROR;
+	}
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+
+ULONG STDMETHODCALLTYPE DUIH_AddRef(IDocHostUIHandler * This)
+{
+	duih_ref_count++;
+
+	return duih_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE DUIH_Release(IDocHostUIHandler * This)
+{
+	duih_ref_count--;
+
+	ASSERT(duih_ref_count >= 0);
+
+	return duih_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_ShowContextMenu(IDocHostUIHandler * This, DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
+{
+	// Pretend we take care of all menus but copy & paste - so the HTML control does not show its own contextual menus
+	if (dwID == CONTEXT_MENU_TEXTSELECT)
+		return S_FALSE;
+	else
+		return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_GetHostInfo(IDocHostUIHandler * This, DOCHOSTUIINFO *pInfo)
+{
+	// Specify some of our UI tastes to the HTML control
+	pInfo->cbSize = sizeof(DOCHOSTUIINFO);
+	pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE | DOCHOSTUIFLAG_NO3DOUTERBORDER | DOCHOSTUIFLAG_SCROLL_NO |
+						DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION | DOCHOSTUIFLAG_NOTHEME | DOCHOSTUIFLAG_DPI_AWARE | DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE;
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_ShowUI(IDocHostUIHandler * This, DWORD dwID, IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
+{
+	return S_FALSE; // Use the HTML control's UI rather than our own, for now
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_HideUI(IDocHostUIHandler * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_UpdateUI(IDocHostUIHandler * This)
+{
+	// We don't have any special UI to update at the host application level
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_EnableModeless(IDocHostUIHandler * This, BOOL fEnable)
+{
+	// We don't track the modeless flag state, but as this gets called, reply something meaningful
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_OnDocWindowActivate(IDocHostUIHandler * This, BOOL fActivate)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_OnFrameWindowActivate(IDocHostUIHandler * This, BOOL fActivate)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_ResizeBorder(IDocHostUIHandler * This, LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_TranslateAccelerator(IDocHostUIHandler * This, LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_GetOptionKeyPath(IDocHostUIHandler * This, LPOLESTR *pchKey, DWORD dw)
+{
+	return S_FALSE;	// Don't use customized settings : use whatever is stored in the default IE registry area
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_GetDropTarget(IDocHostUIHandler * This, IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
+{
+	return E_NOTIMPL;	// We don't supply a customized drop target
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_GetExternal(IDocHostUIHandler * This, IDispatch **ppDispatch)
+{
+	// Plug generic dispatcher that will allow calls from the javascript side
+	browser_ext->lpVtbl->AddRef(browser_ext);
+	*ppDispatch = browser_ext;
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_TranslateUrl(IDocHostUIHandler * This, DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
+{
+	return S_FALSE;	// Don't translate 
+}
+
+HRESULT STDMETHODCALLTYPE DUIH_FilterDataObject(IDocHostUIHandler * This, IDataObject *pDO, IDataObject **ppDORet)
+{
+	NOT_IMPLEMENTED
+}
+
+//-------------------------------------------------------------------------------------------------
+
+// IDocHostUIHandler vtable
+static IDocHostUIHandlerVtbl duih_vtable =
+{
+	DUIH_QueryInterface,
+	DUIH_AddRef,
+	DUIH_Release,
+	DUIH_ShowContextMenu,
+	DUIH_GetHostInfo,
+	DUIH_ShowUI,
+	DUIH_HideUI,
+	DUIH_UpdateUI,
+	DUIH_EnableModeless,
+	DUIH_OnDocWindowActivate,
+	DUIH_OnFrameWindowActivate,
+	DUIH_ResizeBorder,
+	DUIH_TranslateAccelerator,
+	DUIH_GetOptionKeyPath,
+	DUIH_GetDropTarget,
+	DUIH_GetExternal,
+	DUIH_TranslateUrl,
+	DUIH_FilterDataObject
+};
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE OCT_QueryInterface (IOleCommandTarget* This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IOleCommandTarget))
+	{
+		*ppvObject = browser_oct;
+		browser_oct->lpVtbl->AddRef(browser_oct);
+		return NOERROR;
+	}
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+
+ULONG STDMETHODCALLTYPE OCT_AddRef (IOleCommandTarget* This)
+{
+	oct_ref_count++;
+
+	return oct_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE OCT_Release (IOleCommandTarget* This)
+{
+	oct_ref_count--;
+
+	ASSERT(oct_ref_count >= 0);
+
+	return oct_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE OCT_QueryStatus (IOleCommandTarget* This,const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[  ], OLECMDTEXT* pCmdText)
+{
+	return E_NOTIMPL;
+}
+
+HRESULT STDMETHODCALLTYPE OCT_Exec (IOleCommandTarget* This, const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut)
+{
+	if (pguidCmdGroup && IsEqualGUID(pguidCmdGroup, &CGID_DocHostCommandHandler))
+		switch (nCmdID)
+		{
+			case OLECMDID_SHOWMESSAGE:
+				 return OLECMDERR_E_NOTSUPPORTED;
+
+			case OLECMDID_SHOWSCRIPTERROR:
+				// The JavaScript engine reported an error: stop running scripts on the page
+				pvaOut->vt = VT_BOOL;
+				pvaOut->boolVal = VARIANT_FALSE;
+				return S_OK;
+
+			default:
+				 return OLECMDERR_E_NOTSUPPORTED;
+         }
+
+	 return OLECMDERR_E_UNKNOWNGROUP;
+}
+
+// IOleCommandTarget vtable
+static IOleCommandTargetVtbl oct_vtable =
+{
+	OCT_QueryInterface,
+	OCT_AddRef,
+	OCT_Release,
+	OCT_QueryStatus,
+	OCT_Exec
+};
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE ClSi_QueryInterface(IOleClientSite * This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IOleClientSite)) 
+	{
+		*ppvObject = browser_cs;
+		browser_cs->lpVtbl->AddRef(browser_cs);
+		return NOERROR;
+	}
+
+	if (IsEqualIID(riid,&IID_IOleInPlaceSite))
+	{
+		*ppvObject = browser_ips;
+		browser_ips->lpVtbl->AddRef(browser_ips);
+		return NOERROR;
+	}
+
+	if (IsEqualIID(riid,&IID_IServiceProvider)) 
+	{
+		*ppvObject = 0;
+		return E_NOINTERFACE;
+	}
+
+	if (IsEqualIID(riid,&IID_IDispatch)) 
+	{
+		*ppvObject = 0;
+		return E_NOINTERFACE;
+	}
+
+	if (IsEqualIID(riid,&IID_IDocHostUIHandler))
+	{
+		*ppvObject = browser_dui;
+		browser_dui->lpVtbl->AddRef(browser_dui);
+		return NOERROR;
+	}
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+
+ULONG STDMETHODCALLTYPE ClSi_AddRef(IOleClientSite * This)
+{
+	clsi_ref_count++;
+	if (clsi_ref_count == 1)
+	{
+		// Initialize sub-objects
+	}
+
+	return clsi_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE ClSi_Release(IOleClientSite * This)
+{
+	clsi_ref_count--;
+
+	ASSERT(clsi_ref_count >= 0);
+
+	// Dispose of our sub-objects here
+	return clsi_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_SaveObject(IOleClientSite * This)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_GetMoniker(IOleClientSite * This, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_GetContainer(IOleClientSite * This, IOleContainer **ppContainer)
+{
+	// We don't support IOleContainer interface at that time
+	*ppContainer = 0;
+	return E_NOINTERFACE;
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_ShowObject(IOleClientSite * This)
+{
+	return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_OnShowWindow(IOleClientSite * This, BOOL fShow)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE ClSi_RequestNewObjectLayout(IOleClientSite * This)
+{
+	NOT_IMPLEMENTED
+}
+
+//-------------------------------------------------------------------------------------------------
+
+// IOleClientSite vtable
+static IOleClientSiteVtbl clsi_vtable = 
+{
+	ClSi_QueryInterface,
+	ClSi_AddRef,
+	ClSi_Release,
+	ClSi_SaveObject,			// Saves the embedded object associated with the client site
+	ClSi_GetMoniker,			// Retrieves a moniker for the object's client site
+	ClSi_GetContainer,			// Retrieves a pointer to the object's container
+	ClSi_ShowObject,			// Asks a container to display its object to the user
+	ClSi_OnShowWindow,			// Notifies a container when an embedded object's window is about to become visible or invisible
+	ClSi_RequestNewObjectLayout	// Asks a container to resize the display site for embedded objects
+};
+
+//-------------------------------------------------------------------------------------------------
+
+void invoke_js_routine (wchar_t* wcs)
+{
+	BSTR wcs_as_bstr;
+
+	wcs_as_bstr = SysAllocString(wcs);
+	PostMessage(hWnd, WM_EXEC_JS_SCRIPT, 0, (LPARAM) wcs_as_bstr);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+BOOL CALLBACK enum_proc(HWND window, LPARAM reply)
+{
+	static wchar_t wanted[] = L"Internet Explorer_Server";
+	char buf[sizeof(wanted)];
+
+	if (GetClassName(window, (wchar_t*) buf, sizeof(wanted)/sizeof(wanted[0]))
+		&& !memcmp(buf, wanted, sizeof(wanted)))
+	{
+		// Report success and stop enumeration
+		(*(HWND*) reply) = window;
+		return FALSE;
+	}
+	else
+		return TRUE;
+}
+
+void set_native_ready (void)
+{
+	// Find browser window and subclass its window proc so we can intercept back key presses...
+	HWND hBrowserWnd = 0;
+	WNDPROC browser_wnd_proc;
+
+	EnumChildWindows(hWnd, enum_proc, (LPARAM) &hBrowserWnd);
+
+	browser_wnd_proc = (WNDPROC) GetWindowLong(hBrowserWnd, GWL_WNDPROC);
+	if (browser_wnd_proc && browser_wnd_proc != BrowserWndProcWrapper)
+	{
+		initial_browser_wnd_proc = browser_wnd_proc;
+		SetWindowLong(hBrowserWnd, GWL_WNDPROC, (LONG) BrowserWndProcWrapper);
+		BringWindowToTop(hBrowserWnd);
+	}
+
+	// Fire onNativeReady event
+	invoke_js_routine(L"cordova.require('cordova/channel').onNativeReady.fire();");
+}
+
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE Ext_QueryInterface(IDispatch * This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IDispatch)) 
+	{
+		*ppvObject = browser_ext;
+		browser_ext->lpVtbl->AddRef(browser_ext);
+		return NOERROR;
+	}
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+
+ULONG STDMETHODCALLTYPE Ext_AddRef(IDispatch * This)
+{
+	ext_ref_count++;
+
+	return ext_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE Ext_Release(IDispatch * This)
+{
+	ext_ref_count--;
+
+	ASSERT(ext_ref_count >= 0);
+
+	return ext_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE Ext_GetTypeInfoCount(IDispatch * This, UINT *pctinfo)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE Ext_GetTypeInfo(IDispatch * This, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE Ext_GetIDsOfNames(IDispatch * This, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+	HRESULT hr = S_OK;
+	UINT	i;
+
+	// Map method name to integer
+	for ( i=0; i < cNames; i++)
+		if (CompareString( lcid, NORM_IGNORECASE, gate_name, -1, rgszNames[i], -1 ) == CSTR_EQUAL)
+			rgDispId[i] = DISPID_GATE;
+		else
+		{
+			// At least one unknown selector
+			rgDispId[i] = DISPID_UNKNOWN;
+			hr = DISP_E_UNKNOWNNAME;
+		}
+
+	return hr;
+}
+
+HRESULT STDMETHODCALLTYPE Ext_Invoke(IDispatch * This, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+	if (dispIdMember == DISPID_GATE)
+	{
+		if (wFlags & DISPATCH_METHOD)
+		{
+			CordovaModule *module;
+
+			// Check params
+			if (pDispParams->cArgs != 4)
+				return DISP_E_BADPARAMCOUNT;
+
+			if (pDispParams->rgvarg[0].vt != VT_BSTR || 
+				pDispParams->rgvarg[1].vt != VT_BSTR || 
+				pDispParams->rgvarg[2].vt != VT_BSTR || 
+				pDispParams->rgvarg[3].vt != VT_BSTR)
+					return DISP_E_TYPEMISMATCH;
+
+			// Find module
+			module = find_cordova_module(pDispParams->rgvarg[2].bstrVal);
+			if (module == NULL)
+				return DISP_E_MEMBERNOTFOUND;
+
+			// Execute command
+			return module->exec(pDispParams->rgvarg[3].bstrVal, pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal, pVarResult);
+		}
+	}
+
+	return DISP_E_MEMBERNOTFOUND;
+}
+
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+
+HRESULT STDMETHODCALLTYPE Disp_QueryInterface(IDispatch * This, REFIID riid, void **ppvObject)
+{
+	if (IsEqualIID(riid,&IID_IUnknown) || IsEqualIID(riid,&IID_IDispatch)) 
+	{
+		*ppvObject = browser_dsp;
+		browser_dsp->lpVtbl->AddRef(browser_dsp);
+		return NOERROR;
+	}
+
+	// We also get called for DIID_DWebBrowserEvents2, but IDispatch is fine
+
+	*ppvObject = 0;
+	return E_NOINTERFACE;
+}
+
+ULONG STDMETHODCALLTYPE Disp_AddRef(IDispatch * This)
+{
+	disp_ref_count++;
+
+	return disp_ref_count;
+}
+
+ULONG STDMETHODCALLTYPE Disp_Release(IDispatch * This)
+{
+	disp_ref_count--;
+
+	ASSERT(disp_ref_count >= 0);
+
+	return disp_ref_count;
+}
+
+HRESULT STDMETHODCALLTYPE Disp_GetTypeInfoCount(IDispatch * This, UINT *pctinfo)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE Disp_GetTypeInfo(IDispatch * This, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE Disp_GetIDsOfNames(IDispatch * This, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+	NOT_IMPLEMENTED
+}
+
+HRESULT STDMETHODCALLTYPE Disp_Invoke(IDispatch * This, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+	HRESULT hr;
+	wchar_t* title;
+
+	// That's our DIID_DWebBrowserEvents2 event sink callback
+
+	switch (dispIdMember)
+	{
+		case DISPID_DOCUMENTCOMPLETE:
+			// Get access to the document IDispatch interface
+			// Note: in the presence of frames, we would receive several of these events and would need
+			// to check that the IUnknown interfaces for This and browser_web_if are identical
+			// We may get a nil pointer if the base document fails to load
+			hr = browser_web_if->lpVtbl->get_Document(browser_web_if, &document_dispatch_if);
+
+			if (document_dispatch_if)
+			{
+				// Retrieve IHTMLDocument2 interface
+				hr = document_dispatch_if->lpVtbl->QueryInterface(document_dispatch_if, &IID_IHTMLDocument2, &document_html2_if);
+
+				// Retrieve IHTMLWindow2 interface
+				document_html2_if->lpVtbl->get_parentWindow(document_html2_if, &html_window2_if);
+
+				// Set initial Cordova state and release application
+				set_native_ready();
+				current_state = STATE_NATIVE_READY;
+			}
+			break;
+
+		case DISPID_TITLECHANGE:
+			if (skip_title_update)
+			{
+				skip_title_update--;
+				break;
+			}
+
+			// Update window caption
+			title = pDispParams->rgvarg[0].bstrVal;
+			SetWindowText(hWnd, title);
+			break;
+
+		case DISPID_NAVIGATEERROR:
+			{
+				// Silently dismiss navigation errors for now
+				VARIANT_BOOL * cancel = pDispParams->rgvarg[0].pboolVal;
+				*cancel = VARIANT_TRUE;
+			}
+			return S_OK;
+
+		default:
+			;
+	}
+
+	return S_OK;
+}
+
+//-------------------------------------------------------------------------------------------------
+
+static IDispatchVtbl disp_vtable = 
+{
+	Disp_QueryInterface,
+	Disp_AddRef,
+	Disp_Release,
+	Disp_GetTypeInfoCount,
+	Disp_GetTypeInfo,
+	Disp_GetIDsOfNames,
+	Disp_Invoke
+};
+
+//-------------------------------------------------------------------------------------------------
+
+static IDispatchVtbl ext_vtable = 
+{
+	Ext_QueryInterface,
+	Ext_AddRef,
+	Ext_Release,
+	Ext_GetTypeInfoCount,
+	Ext_GetTypeInfo,
+	Ext_GetIDsOfNames,
+	Ext_Invoke
+};
+
+//-------------------------------------------------------------------------------------------------
+
+#define MAIN_WINDOW_CLASS	L"Cordova Shell Window"
+#define MAIN_WINDOW_NAME	APP_NAME
+#define MAIN_WINDOW_STYLE	WS_OVERLAPPEDWINDOW
+
+//-------------------------------------------------------------------------------------------------
+
+static void call_js_script(BSTR wcs_as_bstr)
+{
+	VARIANT v;
+
+	if (html_window2_if)
+	{
+		VariantInit(&v);
+		html_window2_if->lpVtbl->execScript(html_window2_if, wcs_as_bstr, javascript, &v);
+		SysFreeString(wcs_as_bstr);
+	}
+}
+
+
+void ProcessBackKeyStroke (void)
+{
+	// I there are listeners for back button down notifications
+	if (is_back_button_event_enabled())
+	{
+		call_js_script(SysAllocString(L"cordova.fireDocumentEvent('backbutton');"));
+	}
+}
+
+LRESULT CALLBACK CordovaShellWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	// WindowProc for the main host application window
+
+	switch (uMsg)
+	{
+		case WM_KEYDOWN:
+			if (wParam == VK_BACK)
+				ProcessBackKeyStroke();
+			break;
+
+		case WM_CLOSE:
+			current_state = STATE_ENDING;	// The window will get deactivated before being destroyed
+											// Do not bother sending "pause" event
+											// But send the "destroy" event
+			call_js_script(SysAllocString(L"cordova.require('cordova/channel').onDestroy.fire();"));
+			break;
+	
+		case WM_DESTROY: 
+			PostQuitMessage(0); 
+			return 0; 
+
+		case WM_SIZE: 
+			if (browser_web_if && browser_web_if->lpVtbl)
+			{
+				browser_web_if->lpVtbl->put_Width(browser_web_if, LOWORD(lParam));
+				browser_web_if->lpVtbl->put_Height(browser_web_if, HIWORD(lParam));
+			}
+
+			if (hCaptureWnd)
+				SetWindowPos(hCaptureWnd, 0, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOMOVE | SWP_NOZORDER);
+			return 0;
+
+		case WM_DISPLAYCHANGE:
+			camera_notify_display_change();
+			return 0;
+
+		case WM_EXEC_JS_SCRIPT:
+			call_js_script((BSTR) lParam);
+			return 0;
+
+		case WM_USER_ACCEL:
+			// New accelerometer sample available ; propagate to the JS side
+			propagate_accel_sample();
+			return 0;
+
+		case WM_USER_COMPASS:
+			// New compass sample available ; propagate to the JS side
+			propagate_compass_sample();
+			return 0;
+
+		case WM_PARENTNOTIFY:
+			// The capture window got destroyed, time to let the JS side know the outcome of the last requested service
+			if (LOWORD(wParam) == WM_DESTROY && (HWND) lParam == hCaptureWnd)
+			{
+				notify_capture_result();
+			}
+			break;
+
+		case WM_ACTIVATE:
+			if (LOWORD(wParam))
+			{
+				// Window activated ; send resume event if in paused state
+				if (current_state == STATE_PAUSED)
+				{
+					invoke_js_routine(L"cordova.require('cordova/channel').onResume.fire();");
+					current_state = STATE_NATIVE_READY;
+				}
+			}
+			else
+			{
+				// Window deactivated ; send pause event if we're in active state
+				if (current_state == STATE_NATIVE_READY)
+				{
+					invoke_js_routine(L"cordova.require('cordova/channel').onPause.fire();");
+					current_state = STATE_PAUSED;
+				}
+			}
+			break;
+
+		default:
+			return DefWindowProc(hWnd, uMsg, wParam, lParam);
+	}
+
+	return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+LRESULT CALLBACK BrowserWndProcWrapper(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	if (uMsg == WM_KEYDOWN && wParam == VK_BACK)
+		ProcessBackKeyStroke();
+
+	return initial_browser_wnd_proc(hWnd, uMsg, wParam, lParam);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+void create_browser_object (void)
+{
+	HRESULT hr;
+	BSTR base_url;
+	VARIANT nil;
+	BSTR app_name;
+	IConnectionPointContainer* cp_container_if;
+	IConnectionPoint* cp_if;
+
+	// Initialize client site object
+	browser_cs = &clsi;
+	browser_cs->lpVtbl = &clsi_vtable;
+
+	// Initialize in place site object
+	browser_ips = &inplsi;
+	browser_ips->lpVtbl = &inplsi_vtable;
+
+	// Initialize in place frame object
+	browser_ipf = &inplfr;
+	browser_ipf->lpVtbl = &inplfr_vtable;
+
+	// Initialize event dispatcher object
+	browser_dsp = &disp;
+	browser_dsp->lpVtbl = &disp_vtable;
+
+	// Initialize external interface dispatcher object
+	browser_ext = &ext;
+	browser_ext->lpVtbl = &ext_vtable;
+
+	// Initialize host doc ui handler object
+	browser_dui = &duih;
+	browser_dui->lpVtbl = &duih_vtable;
+	
+	// Initialize OLE command target object
+	browser_oct = &oct;
+	browser_oct->lpVtbl = &oct_vtable;
+
+	CoCreateInstance(&CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER,  &IID_IWebBrowser2, (void**)&browser_web_if);
+
+	if (browser_web_if)
+	{
+		// Get IOleObject interface
+		browser_web_if->lpVtbl->QueryInterface(browser_web_if, &IID_IOleObject, &browser_ole_if);
+
+		if (browser_ole_if)
+		{
+			app_name = SysAllocString(APP_NAME);
+
+			hr = browser_ole_if->lpVtbl->SetClientSite(browser_ole_if, browser_cs);
+			hr = browser_ole_if->lpVtbl->SetHostNames(browser_ole_if, app_name, 0);
+
+			// Activate object
+			hr = browser_ole_if->lpVtbl->DoVerb(browser_ole_if, OLEIVERB_INPLACEACTIVATE, 0, browser_cs, 0, hWnd, 0);
+		}
+
+		// Also get a IOleInPlaceObject interface, as it's the expected way to resize the browser control
+		browser_web_if->lpVtbl->QueryInterface(browser_web_if, &IID_IOleInPlaceObject, &browser_ipo_if);
+
+		// Connect an event sink to the browser so we can get notified when there's an update to the document title
+
+		hr = browser_web_if->lpVtbl->QueryInterface(browser_web_if, &IID_IConnectionPointContainer, &cp_container_if);
+		hr = cp_container_if->lpVtbl->FindConnectionPoint(cp_container_if, &DIID_DWebBrowserEvents2, &cp_if);
+		hr = cp_if->lpVtbl->Advise(cp_if, (IUnknown*) browser_dsp, &browser_dsp_cookie);
+
+		// Disable drag & drop on our window
+		hr = browser_web_if->lpVtbl->put_RegisterAsDropTarget(browser_web_if, VARIANT_FALSE);
+
+		// Direct the browser to our index.html file
+
+		base_url = SysAllocString(full_path);
+		VariantInit(&nil);
+
+		hr = browser_web_if->lpVtbl->Navigate(browser_web_if, base_url, &nil, &nil, &nil, &nil);
+	
+		if (hr == S_OK)
+			// Display our HTML window
+			hr = browser_web_if->lpVtbl->put_Visible(browser_web_if, VARIANT_TRUE);
+		else
+			browser_web_if->lpVtbl->Quit(browser_web_if);
+
+		SysFreeString(base_url);
+
+		browser_web_if->lpVtbl->Release(browser_web_if);
+	}
+}
+
+//-------------------------------------------------------------------------------------------------
+
+void set_ie_feature (wchar_t* key_name, DWORD new_val)
+{
+	wchar_t filename[_MAX_PATH];
+	wchar_t* last_component;
+	DWORD info;
+	HKEY key;
+	LONG ret;
+	DWORD len;
+	DWORD val;
+	DWORD type;
+
+	filename[0]  = L'\0';
+
+	// First retrieve the current executable name
+	GetModuleFileName(0, filename, _MAX_PATH);
+
+	last_component = wcsrchr(filename, L'\\');
+
+	if (last_component && *last_component == '\\')
+		last_component++;
+	else
+		return;
+
+
+	ret = RegCreateKeyEx(HKEY_CURRENT_USER, key_name, 0, 0, 0, KEY_READ | KEY_WRITE, 0, &key, &info);
+
+	if (ret != ERROR_SUCCESS)
+		return;
+
+	len = sizeof(DWORD);
+
+	ret = RegQueryValueEx(key, last_component, 0, &type, (LPBYTE) &val, &len);
+
+	// If no value exists for our exe name (e.g. it hasn't been explicitly enabled or disabled)
+	if (ret != ERROR_SUCCESS || type != REG_DWORD)
+		// Stick a value there named after our exe name
+		RegSetValueEx(key, last_component, 0, REG_DWORD, (LPBYTE) &new_val, sizeof(DWORD));
+
+	RegCloseKey(key);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+int get_ie_version (void)
+{
+	DWORD info;
+	HKEY key;
+	LONG ret;
+	DWORD len;
+	DWORD type;
+	wchar_t buf[20];
+	int major;
+
+	buf[0] = L'\0';
+
+	ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Internet Explorer" , 0, 0, 0, KEY_READ, 0, &key, &info);
+
+	if (ret != ERROR_SUCCESS)
+		return -1;
+
+	if (info == REG_OPENED_EXISTING_KEY)
+	{
+		len = sizeof(buf);
+
+		ret = RegQueryValueEx(key, L"Version", 0, &type, (LPBYTE) buf, &len);
+
+		if (ret == ERROR_SUCCESS)
+		{
+			major = _wtoi(buf);
+			RegCloseKey(key);
+			return major;
+		}
+	}
+
+	RegCloseKey(key);
+	return -1;
+}
+
+//-------------------------------------------------------------------------------------------------
+
+void early_init (void)
+{
+	DWORD major, minor;
+	INITCOMMONCONTROLSEX ccex;
+	DWORD winver = GetVersion();
+
+	major = (DWORD)(LOBYTE(LOWORD(winver)));
+	minor = (DWORD)(HIBYTE(LOWORD(winver)));
+
+	// We need at least Windows Seven
+	if (major < 6 || (major == 6 && minor < 1))
+	{
+		MessageBox(GetForegroundWindow(), L"This program requires Windows 7 or newer.", L"Missing Prerequisites", MB_OK);
+		ExitProcess(61);
+	}
+
+	// IE 9 or newer required
+	if (get_ie_version() < 9)
+	{
+		MessageBox(GetForegroundWindow(), L"This program requires Internet Explorer 9 or newer", L"Missing Prerequisites", MB_OK);
+		ExitProcess(90);
+	}
+
+	// Form full path for our base URL file ; better do this early, as the current directory can be changed later
+	GetFullPathName(BASE_URL, _MAX_PATH, full_path, 0);	// Possible failure if the base directory has a very long name
+
+
+	// A little BSTR object that we'll need to invoke js routines
+	javascript = SysAllocString(L"javascript");
+
+	// IE GPU acceleration is disabled by default for apps hosting the HTML control
+	set_ie_feature(IE_GPU_REG_KEY, 1);
+
+	// Disable pre-IE9 emulation
+	set_ie_feature(IE_COMPAT_REG_KEY, 9999);
+
+	// We need both COM (sensor API, etc) and OLE (WebBrowser control) services
+	if (!SUCCEEDED(OleInitialize(0)))
+		ExitProcess(0x01e);
+
+	// Ensure the common controls library is setup to allow toolbar creation
+	ccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
+	ccex.dwICC  = ICC_BAR_CLASSES;
+	InitCommonControlsEx(&ccex);
+}
+
+//-------------------------------------------------------------------------------------------------
+
+int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+	MSG msg;
+	int code;
+	WNDCLASSEX wc = {
+		sizeof(WNDCLASSEX),
+		CS_HREDRAW | CS_VREDRAW,
+		CordovaShellWndProc,
+		0,
+		0,
+		0,
+		0,	// >>> icon 
+		LoadCursor(NULL, IDC_ARROW),
+		0, // must handle background paint
+		0,
+		MAIN_WINDOW_CLASS,
+		0 // >>> small icon update
+		};
+
+	set_thread_name(-1, "Primary Thread");
+
+	early_init();
+	register_cordova_modules();
+
+	RegisterClassEx(&wc);
+
+	hWnd = CreateWindow(MAIN_WINDOW_CLASS, MAIN_WINDOW_NAME, MAIN_WINDOW_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0, 0);
+
+	if (!hWnd)
+		return 0;
+
+	create_browser_object();
+
+	ShowWindow(hWnd, nCmdShow); 
+	UpdateWindow(hWnd);
+
+	setup_capture();
+
+	while ((code = GetMessage( &msg, 0, 0, 0 )) != 0)
+	{
+		if (code == -1)
+		{
+		}
+		else
+		{
+			TranslateMessage(&msg);
+			DispatchMessage(&msg);
+		}
+	} 
+
+	close_cordova_modules();
+	OleUninitialize();
+
+	return msg.wParam;
+}
+
+
+// http://msdn.microsoft.com/en-us/ie/aa740471 for IE9 headers & libs
+// $(ProgramFiles)\Microsoft SDKs\Internet Explorer\v9\include
+// http://msdn.microsoft.com/en-us/library/ie/bb508516%28v=vs.85%29.aspx for MSHTML usage notes
+// http://support.microsoft.com/kb/261003/en-us for error handling
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/shell.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/shell.h b/windows7/Cordova/shell.h
new file mode 100644
index 0000000..e463f67
--- /dev/null
+++ b/windows7/Cordova/shell.h
@@ -0,0 +1,61 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//    http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#ifndef __SHELL_H__
+#define __SHELL_H__
+
+#include <WTypes.h>
+#include <OaIdl.h>
+
+#define NULL_MESSAGE L"null"
+
+typedef enum {
+	CB_NO_RESULT = 0,
+	CB_OK = 1,
+	CB_CLASS_NOT_FOUND_EXCEPTION = 2,
+	CB_ILLEGAL_ACCESS_EXCEPTION = 3,
+	CB_INSTANTIATION_EXCEPTION = 4,
+	CB_MALFORMED_URL_EXCEPTION = 5,
+	CB_IO_EXCEPTION = 6,
+	CB_INVALID_ACTION = 7,
+	CB_JSON_EXCEPTION = 8,
+	CB_GENERIC_ERROR = 9
+} CallbackStatus;
+
+typedef HRESULT (*module_exec_func) (BSTR callback_id, BSTR action, BSTR args, VARIANT *result);
+typedef void (*module_close_func) (void);
+typedef void (*module_init_func) (void);
+
+struct _CordovaModule {
+	BSTR module_id;
+	module_exec_func exec;
+	module_init_func init;
+	module_close_func close;
+	struct _CordovaModule *next;
+};
+typedef struct _CordovaModule CordovaModule;
+
+#define CORDOVA_MODULE(name) &Cordova##name
+#define DECLARE_CORDOVA_MODULE(name) extern CordovaModule Cordova##name;
+#define DEFINE_CORDOVA_MODULE(name, id, exec_func, init_func, close_func) CordovaModule Cordova##name = { id, exec_func, init_func, close_func, NULL };
+
+void cordova_success_callback(BSTR callback_id, BOOL keep_callback, const wchar_t *message);
+void cordova_fail_callback(BSTR callback_id, BOOL keep_callback, CallbackStatus status, const wchar_t *message);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/storage.c
----------------------------------------------------------------------
diff --git a/windows7/Cordova/storage.c b/windows7/Cordova/storage.c
new file mode 100644
index 0000000..f723132
--- /dev/null
+++ b/windows7/Cordova/storage.c
@@ -0,0 +1,384 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <Shlwapi.h>
+#include <Shlobj.h>
+#include <wchar.h>
+#define CINTERFACE 1	// Get C definitions for COM header files
+
+#include "lib/sqlite/sqlite3.h"
+#include "storage.h"
+#include "json.h"
+#include "common.h"
+
+#define DROP_QUERY L"drop"
+#define ALTER_QUERY L"alter"
+#define CREATE_QUERY L"create"
+#define TRUNCATE_QUERY L"truncate"
+
+struct _CordovaDb {
+	sqlite3 *db;
+	wchar_t *name;
+	struct _CordovaDb *next;
+};
+typedef struct _CordovaDb CordovaDb;
+
+static CordovaDb *db_list = NULL;
+
+static CordovaDb *find_cordova_db(const wchar_t *name)
+{
+	CordovaDb *item = db_list;
+
+	while (item != NULL) {
+		if (!wcscmp(name, item->name))
+			return item;
+
+		item = item->next;
+	}
+
+	return NULL;
+}
+
+static void remove_cordova_db(CordovaDb *db)
+{
+	CordovaDb *item;
+
+	if (db_list == db)
+		db_list = NULL;
+	else {
+		item = db_list;
+		while (item) {
+			if (item->next == db) {
+				item->next = db->next;
+				break;
+			}
+
+			item = item->next;
+		}
+	}
+
+	sqlite3_close(db->db);
+	free(db->name);
+	free(db);
+}
+
+static HRESULT remove_database(BSTR callback_id, BSTR args)
+{
+	wchar_t path[MAX_PATH];
+	CordovaDb *cordova_db;
+	JsonArray array;
+	JsonItem item;
+	wchar_t *db_name = NULL;
+
+	if (db_list == NULL)
+		goto out;
+
+	// Extract db name
+	if (!json_parse_and_validate_args(args, &array, JSON_VALUE_STRING,
+											JSON_VALUE_INVALID)) {
+		json_free_args(array);
+		return E_FAIL;
+	}
+	item = json_array_get_first(array);
+
+	if (json_get_value_type(item) != JSON_VALUE_STRING) {
+		json_free_args(array);
+		return E_FAIL;
+	}
+	db_name = json_get_string_value(item);
+	json_free_args(array);
+
+	// Find & remove
+	cordova_db = find_cordova_db(db_name);
+	if (cordova_db) {
+		remove_cordova_db(cordova_db);
+
+		if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path))) 
+			goto out;
+		PathAppend(path, L"Cordova\\db");
+		PathAppend(path, db_name);
+
+		DeleteFile(path);
+	}
+
+out:
+	if (db_name)
+		free(db_name);
+
+	return S_OK;
+}
+
+static HRESULT open_database(BSTR callback_id, BSTR args, VARIANT *result)
+{
+	int res;
+	wchar_t path[MAX_PATH];
+	sqlite3 *db;
+	CordovaDb *cordova_db;
+	JsonArray array;
+	JsonItem item;
+	wchar_t *db_name;
+
+	if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path))) 
+		return E_FAIL;
+
+	PathAppend(path, L"Cordova\\db");
+	res = SHCreateDirectory(NULL,path);
+	if(!SUCCEEDED(res) && (res != ERROR_FILE_EXISTS) && (res != ERROR_ALREADY_EXISTS))
+		return E_FAIL;
+
+		// Validate array contents
+	if (!json_parse_and_validate_args(args, &array, JSON_VALUE_STRING,
+											JSON_VALUE_STRING,
+											JSON_VALUE_STRING,
+											JSON_VALUE_INT,
+											JSON_VALUE_INVALID)) {
+		json_free_args(array);
+		return E_FAIL;
+	}
+	item = json_array_get_first(array);
+
+	db_name = json_get_string_value(item);
+	json_free_args(array);
+
+	cordova_db = find_cordova_db(db_name);
+	if (cordova_db != NULL)
+		db = cordova_db->db;
+	else {
+		PathAppend(path, db_name);
+		res = sqlite3_open16((const char *) path, &db);
+		if (res != SQLITE_OK) {
+			sqlite3_close(db);
+			free (db_name);
+			return E_FAIL;
+		}
+
+		cordova_db = (CordovaDb *)calloc(1, sizeof(CordovaDb));
+		cordova_db->db = db;
+		cordova_db->name = db_name;
+		cordova_db->next = db_list;
+
+		db_list = cordova_db;
+	}
+
+	VariantInit(result);
+	result->vt = VT_INT;
+	result->intVal = (int) db;
+
+	return S_OK;
+}
+
+static BOOL is_ddl(const wchar_t *query)
+{
+	if (!_wcsnicmp(query, DROP_QUERY, wcslen(DROP_QUERY)) ||
+		!_wcsnicmp(query, ALTER_QUERY, wcslen(ALTER_QUERY)) ||
+		!_wcsnicmp(query, CREATE_QUERY, wcslen(CREATE_QUERY)) ||
+		!_wcsnicmp(query, TRUNCATE_QUERY, wcslen(TRUNCATE_QUERY)))
+			return TRUE;
+
+	return FALSE;
+}
+
+static HRESULT execute_sql(BSTR callback_id, BSTR args)
+{
+	HRESULT res = S_OK;
+	sqlite3 *db;
+	sqlite3_stmt *stmt = NULL;
+	JsonArray array;
+	JsonItem item;
+	TextBuf response;
+	wchar_t *tx_id = NULL;
+	wchar_t *command = NULL;
+
+	response = text_buf_new();
+
+	// Validate array contents
+	if (!json_parse_and_validate_args(args, &array, JSON_VALUE_INT,
+											JSON_VALUE_STRING,
+											JSON_VALUE_ARRAY,
+											JSON_VALUE_STRING,
+											JSON_VALUE_INVALID)) {
+		res = E_FAIL;
+		goto out;
+	}
+
+	item = json_array_item_at(array, 3);
+	tx_id = json_get_string_value(item);
+
+	item = json_array_get_first(array);
+	db = (sqlite3 *) json_get_int_value(item);
+
+	item = json_array_get_next(item);
+	command = json_get_string_value(item);
+
+	if (is_ddl(command)) {
+		if (sqlite3_prepare16_v2(db, command, wcslen(command) * sizeof(wchar_t), &stmt, NULL) != SQLITE_OK) {
+			cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.SYNTAX_ERR,message:\"Syntax error\"}");
+			goto out;
+		}
+		if (sqlite3_step(stmt) != SQLITE_DONE) {
+			cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.DATABASE_ERR,message:\"Database error\"}");
+			goto out;
+		}
+
+		text_buf_append(response, L"{id:'");
+		text_buf_append(response, tx_id);
+		text_buf_append(response, L"',data:''}");
+
+		cordova_success_callback(callback_id, FALSE, text_buf_get(response));
+	} else {
+		JsonItem sql_arg;
+		int db_res = SQLITE_OK;
+		int index = 1;
+
+		// Prepare
+		if (sqlite3_prepare16_v2(db, command, wcslen(command) * sizeof(wchar_t), &stmt, NULL) != SQLITE_OK) {
+			cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.SYNTAX_ERR,message:\"Syntax error\"}");
+			goto out;
+		}
+
+		// Bind arguments
+		item = json_array_get_next(item);
+		sql_arg = json_get_array_value(item);
+		while (sql_arg != NULL) {
+			switch (json_get_value_type(sql_arg)) {
+			case JSON_VALUE_EMPTY:
+				break;
+			case JSON_VALUE_INT:
+				db_res = sqlite3_bind_int(stmt, index, json_get_int_value(sql_arg));
+				break;
+			case JSON_VALUE_DOUBLE:
+				db_res = sqlite3_bind_double(stmt, index, json_get_double_value(sql_arg));
+				break;
+			case JSON_VALUE_STRING:
+				{
+					wchar_t *str = json_get_string_value(sql_arg);
+					db_res = sqlite3_bind_text16(stmt, index, str, wcslen(str) * sizeof(wchar_t), NULL);
+					free(str);
+					break;
+				}
+			case JSON_VALUE_NULL:
+				db_res = sqlite3_bind_null(stmt, index);
+				break;
+			default:
+				cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.SYNTAX_ERR,message:\"Syntax error\"}");
+				goto out;
+			}
+			if (db_res != SQLITE_OK) {
+				cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR,L"{code:SQLError.SYNTAX_ERR,message:\"Syntax error\"}");
+				goto out;
+			}
+
+			sql_arg = json_array_get_next(sql_arg);
+			index++;
+		}
+
+		// Execute & prepare response
+		text_buf_append(response, L"{id:'");
+		text_buf_append(response, tx_id);
+		text_buf_append(response, L"',data:[");
+
+		db_res = sqlite3_step(stmt);
+		if (db_res == SQLITE_ROW) {
+			do {
+				int j;
+
+				text_buf_append(response, L"{");
+				for (j = 0; j < sqlite3_column_count(stmt); j++) {
+					if (j > 0)
+						text_buf_append(response, L",");
+
+					text_buf_append(response, L"\"");
+					text_buf_append(response, (wchar_t *) sqlite3_column_name16(stmt, j));
+					text_buf_append(response, L"\":");
+					if (sqlite3_column_type(stmt, j) == SQLITE_INTEGER) {
+						static wchar_t number[20];
+						swprintf(number, 19, L"%d", sqlite3_column_int(stmt, j));
+						text_buf_append(response, number);
+					} else if (sqlite3_column_type(stmt, j) == SQLITE_TEXT) {
+						text_buf_append(response, L"\"");
+						text_buf_append(response, (wchar_t *) sqlite3_column_text16(stmt, j));
+						text_buf_append(response, L"\"");
+					} else if (sqlite3_column_type(stmt, j) == SQLITE_NULL) {
+						text_buf_append(response, L"null");
+					} else {
+						cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.DATABASE_ERR,message:\"Database error\"}");
+						goto out;
+					}
+				}
+				text_buf_append(response, L"}");
+
+				// Next
+				db_res = sqlite3_step(stmt);
+				if (db_res == SQLITE_ROW)
+					text_buf_append(response, L",");
+			} while (db_res == SQLITE_ROW);
+		} else if (db_res != SQLITE_DONE) {
+			cordova_fail_callback(callback_id, FALSE, CB_GENERIC_ERROR, L"{code:SQLError.DATABASE_ERR,message:\"Database error\"}");
+			goto out;
+		}
+
+		text_buf_append(response, L"]}");
+
+		// Success
+		cordova_success_callback(callback_id, FALSE, text_buf_get(response));
+	}
+
+out:
+	json_free_args(array);
+	if (stmt)
+		sqlite3_finalize(stmt);
+	text_buf_free(response);
+	if (tx_id)
+		free(tx_id);
+	if (command)
+		free(command);
+
+	return res;
+}
+
+HRESULT storage_exec(BSTR callback_id, BSTR action, BSTR args, VARIANT *result)
+{
+	if (!wcscmp(action, L"openDatabase"))
+		return open_database(callback_id, args, result);
+	if (!wcscmp(action, L"removeDatabase"))
+		return remove_database(callback_id, args);
+	if (!wcscmp(action, L"executeSql"))
+		return execute_sql(callback_id, args);
+
+	return DISP_E_MEMBERNOTFOUND;
+}
+
+void storage_close(void)
+{
+	while (db_list != NULL) {
+		CordovaDb *item;
+
+		sqlite3_close(db_list->db);
+		free(db_list->name);
+
+		item = db_list;
+		db_list = db_list->next;
+
+		free(item);
+	}
+}
+
+DEFINE_CORDOVA_MODULE(Storage, L"Storage", storage_exec, NULL, storage_close)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/storage.h
----------------------------------------------------------------------
diff --git a/windows7/Cordova/storage.h b/windows7/Cordova/storage.h
new file mode 100644
index 0000000..311092f
--- /dev/null
+++ b/windows7/Cordova/storage.h
@@ -0,0 +1,22 @@
+// Copyright 2012 Intel Corporation
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "shell.h"
+
+DECLARE_CORDOVA_MODULE(Storage)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/toolbar.bmp
----------------------------------------------------------------------
diff --git a/windows7/Cordova/toolbar.bmp b/windows7/Cordova/toolbar.bmp
new file mode 100644
index 0000000..1c3965f
Binary files /dev/null and b/windows7/Cordova/toolbar.bmp differ

http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/3711f4bc/windows7/Cordova/www/accel_game.css
----------------------------------------------------------------------
diff --git a/windows7/Cordova/www/accel_game.css b/windows7/Cordova/www/accel_game.css
new file mode 100644
index 0000000..e6672fd
--- /dev/null
+++ b/windows7/Cordova/www/accel_game.css
@@ -0,0 +1,23 @@
+body{
+background-color:#000;
+}
+
+#box{
+width: 500px;
+height: 500px;
+border: 1px solid #333;
+margin: 0 auto;
+background: #FFF;
+text-align: center;
+}
+
+h1 {
+text-align: center;
+font-variant: small-caps;
+color: #FFF;
+}
+
+#valueX, #valueY, #valueZ, #valueL, #valueR,#valueU,#valueD {
+font-variant: small-caps;
+color: #FFF;
+}


Mime
View raw message