Support for IE9 GWT Developer Mode plugin.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9599 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/plugins/platform/Win/AllowDialog.cpp b/plugins/platform/Win/AllowDialog.cpp
new file mode 100644
index 0000000..6e5672b
--- /dev/null
+++ b/plugins/platform/Win/AllowDialog.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed 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 "AllowDialog.h"
+#include "Debug.h"
+#include "resource.h"
+
+HINSTANCE AllowDialog::hInstance;
+
+static BOOL CALLBACK allowDialogProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) {
+ if (message != WM_COMMAND) {
+ return false;
+ }
+ bool allowed;
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ allowed = false;
+ break;
+ case IDC_ALLOW_BUTTON:
+ allowed = true;
+ break;
+ default:
+ // ignore anything but buttons which close the dialog
+ return false;
+ }
+ bool remember = IsDlgButtonChecked(hwndDlg, IDC_REMEMBER_CHECKBOX) == BST_CHECKED;
+ int returnVal = (allowed ? 1 : 0) + (remember ? 2 : 0);
+ EndDialog(hwndDlg, (INT_PTR) returnVal);
+ return true;
+}
+
+void AllowDialog::setHInstance(HINSTANCE hInstance) {
+ AllowDialog::hInstance = hInstance;
+}
+
+bool AllowDialog::askUserToAllow(bool* remember) {
+ int result = (int) DialogBox(hInstance, MAKEINTRESOURCE(IDD_ALLOW_DIALOG),
+ NULL, (DLGPROC) allowDialogProc);
+ *remember = (result & 2) != 0;
+ return (result & 1) != 0;
+}
diff --git a/plugins/platform/Win/AllowDialog.h b/plugins/platform/Win/AllowDialog.h
new file mode 100644
index 0000000..93f9438
--- /dev/null
+++ b/plugins/platform/Win/AllowDialog.h
@@ -0,0 +1,42 @@
+#ifndef _H_AllowDialog
+#define _H_AllowDialog
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed 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.
+ */
+
+#ifdef _WINDOWS
+#include <windows.h>
+#include <winnt.h>
+#include <windef.h>
+
+class AllowDialog {
+public:
+ static void setHInstance(HINSTANCE hInstance);
+
+ /**
+ * Ask the user if a connection should be allowed.
+ *
+ * @param remember *remember is set to true if the user asked us to remember this decision,
+ * false otherwise
+ * @return return true if this connection should be allowed
+ */
+ static bool askUserToAllow(bool* remember);
+
+private:
+ static HINSTANCE hInstance;
+};
+#endif
+
+#endif
diff --git a/plugins/platform/Win/Preferences.cpp b/plugins/platform/Win/Preferences.cpp
new file mode 100644
index 0000000..7eeb381
--- /dev/null
+++ b/plugins/platform/Win/Preferences.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed 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 <winnt.h>
+#include <winreg.h>
+#include "Debug.h"
+#include "Preferences.h"
+#include "AllowedConnections.h"
+
+#define REG_ACCESS_LIST "SOFTWARE\\Google\\Google Web Toolkit\\gwt-dev-plugin.accessList"
+
+/**
+ * Return a null-terminated string containing the access list.
+ *
+ * @param HKEY registry key for the access list value
+ * @return null-terminated string containing the access list (an empty string
+ * if the value does not exist) -- caller is responsible for freeing with
+ * delete[]
+ */
+static char* getAccessList(HKEY keyHandle) {
+ char *buf;
+ DWORD len = 512;
+ while(true) {
+ buf = new char[len];
+ int cc = RegQueryValueExA(keyHandle, NULL, 0, NULL, (LPBYTE) buf, &len);
+ if (cc == ERROR_SUCCESS) {
+ break;
+ } else if (cc == ERROR_FILE_NOT_FOUND) {
+ // special handling if the value doesn't exist
+ len = 0;
+ break;
+ } else if (cc != ERROR_MORE_DATA) {
+ // log unexpected errors
+ Debug::log(Debug::Error) << "Unable to load access list from registry: "
+ << cc << Debug::flush;
+ len = 0;
+ break;
+ }
+ // Buffer wasn't big enough, so make it bigger and try again
+ delete [] buf;
+ len *= 2;
+ }
+ buf[len] = 0;
+ return buf;
+}
+
+void Preferences::addNewRule(const std::string& pattern, bool exclude) {
+ HKEY keyHandle;
+ if (RegCreateKeyExA(HKEY_CURRENT_USER, REG_ACCESS_LIST, 0, 0,
+ REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &keyHandle, NULL)
+ != ERROR_SUCCESS) {
+ return;
+ }
+ char *buf = getAccessList(keyHandle);
+ std::string pref(buf);
+ delete [] buf;
+ if (pref.length() > 0) {
+ pref += ',';
+ }
+ if (exclude) {
+ pref += '!';
+ }
+ pref += pattern;
+ int cc = RegSetValueExA(keyHandle, NULL, 0, REG_SZ, (LPBYTE) pref.c_str(),
+ pref.length() + 1);
+ if (cc != ERROR_SUCCESS) {
+ Debug::log(Debug::Error) << "Unable to store access list in registry: "
+ << cc << Debug::flush;
+ }
+ RegCloseKey(keyHandle);
+}
+
+void Preferences::loadAccessList() {
+ // TODO(jat): can Reg* routines throw exceptions? If so, we need to make
+ // this exception safe about closing the key hendle and freeing the buffer.
+ HKEY keyHandle;
+ if (RegCreateKeyExA(HKEY_CURRENT_USER, REG_ACCESS_LIST, 0, 0,
+ REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &keyHandle, NULL)
+ != ERROR_SUCCESS) {
+ return;
+ }
+ char *buf = getAccessList(keyHandle);
+ AllowedConnections::initFromAccessList(buf);
+ delete [] buf;
+ RegCloseKey(keyHandle);
+}
diff --git a/plugins/platform/Win/Preferences.h b/plugins/platform/Win/Preferences.h
new file mode 100644
index 0000000..f4fc49b
--- /dev/null
+++ b/plugins/platform/Win/Preferences.h
@@ -0,0 +1,34 @@
+#ifndef _H_Preferences
+#define _H_Preferences
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed 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 <string>
+
+/**
+ * Deal with getting/storing/updating preferences in the Windows registry.
+ */
+class Preferences {
+private:
+ // prevent instantiation
+ Preferences() {}
+
+public:
+ static void loadAccessList();
+ static void addNewRule(const std::string& pattern, bool exclude);
+};
+
+#endif