Revision: 6082
Author: [email protected]
Date: Thu Sep  3 14:01:13 2009
Log: Add a dialog to let the user allow/deny connections.

http://code.google.com/p/google-web-toolkit/source/detail?r=6082

Added:
  /changes/jat/plugins/plugins/ie/oophm/oophm/AllowDialog.cpp
  /changes/jat/plugins/plugins/ie/oophm/oophm/AllowDialog.h
  /changes/jat/plugins/plugins/ie/oophm/oophm/resource.h
Deleted:
  /changes/jat/plugins/plugins/ie/oophm/oophm/Resource.h
Modified:
  /changes/jat/plugins/plugins/ie/oophm/oophm/Preferences.cpp
  /changes/jat/plugins/plugins/ie/oophm/oophm/dllmain.cpp
  /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.aps
  /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.rc
  /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.vcproj
  /changes/jat/plugins/plugins/ie/oophm/oophm/plugin.cpp
  /changes/jat/plugins/plugins/ie/prebuilt/oophm.dll

=======================================
--- /dev/null
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/AllowDialog.cpp Thu Sep  3  
14:01:13 2009
@@ -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;
+}
=======================================
--- /dev/null
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/AllowDialog.h   Thu Sep  3  
14:01:13 2009
@@ -0,0 +1,38 @@
+#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.
+ */
+
+#include "stdafx.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
=======================================
--- /dev/null
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/resource.h      Thu Sep  3  
14:01:13 2009
@@ -0,0 +1,24 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by oophm.rc
+//
+#define IDS_PROJNAME                    100
+#define IDR_OOPHM                       101
+#define IDR_PLUGIN                      103
+#define IDD_ALLOW_DIALOG                103
+#define IDH_PLUGIN                      103
+#define IDR_JAVAOBJECT                  105
+#define IDR_EXCEPTIONCATCHER            106
+#define IDC_REMEMBER_CHECKBOX           201
+#define IDC_ALLOW_BUTTON                202
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        202
+#define _APS_NEXT_COMMAND_VALUE         32768
+#define _APS_NEXT_CONTROL_VALUE         204
+#define _APS_NEXT_SYMED_VALUE           107
+#endif
+#endif
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/Resource.h      Mon Aug  3  
08:30:11 2009
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2008 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.
- */
-
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by oophm.rc
-//
-#define IDS_PROJNAME                    100
-#define IDR_OOPHM                       101
-#define IDB_PLUGIN                      102
-#define IDR_PLUGIN                      103
-#define IDH_PLUGIN                      104
-#define IDR_JAVAOBJECT                  105
-#define IDR_EXCEPTIONCATCHER            106
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        201
-#define _APS_NEXT_COMMAND_VALUE         32768
-#define _APS_NEXT_CONTROL_VALUE         201
-#define _APS_NEXT_SYMED_VALUE           107
-#endif
-#endif
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/Preferences.cpp Wed Sep  2  
17:27:24 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/Preferences.cpp Thu Sep  3  
14:01:13 2009
@@ -21,14 +21,15 @@
  #include "Preferences.h"
  #include "AllowedConnections.h"

-#define REG_ACCESS_LIST "SOFTWARE\\Google Web Toolkit\\gwt-dmp.accessList"
+#define REG_ACCESS_LIST "SOFTWARE\\Google\\Google Web  
Toolkit\\gwt-dmp.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 -- caller is
- *     responsible for freeing with delete[].
+ * @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;
@@ -38,15 +39,22 @@
      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;
-      return buf;
+      len = 0;
+      break;
      }
      // Buffer wasn't big enough, so make it bigger and try again
      delete [] buf;
      len *= 2;
    }
+  buf[len] = 0;
    return buf;
  }

=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/dllmain.cpp     Mon Aug  3  
08:30:11 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/dllmain.cpp     Thu Sep  3  
14:01:13 2009
@@ -21,6 +21,7 @@
  #include "oophm_i.h"
  #include "dllmain.h"
  #include "dlldatax.h"
+#include "AllowDialog.h"

  CoophmModule _AtlModule;

@@ -31,6 +32,6 @@
        if (!PrxDllMain(hInstance, dwReason, lpReserved))
                return FALSE;
  #endif
-       hInstance;
+        AllowDialog::setHInstance(hInstance);
        return _AtlModule.DllMain(dwReason, lpReserved);
  }
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.aps       Wed Sep  2  
17:03:17 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.aps       Thu Sep  3  
14:01:13 2009
Binary file, no diff available.
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.rc        Mon Aug  3  
08:30:11 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.rc        Thu Sep  3  
14:01:13 2009
@@ -104,10 +104,41 @@

   
/////////////////////////////////////////////////////////////////////////////
  //
-// Bitmap
+// Dialog
  //

-IDB_PLUGIN              BITMAP                  "plugin.bmp"
+IDD_ALLOW_DIALOG DIALOGEX 0, 0, 188, 73
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTER |  
WS_POPUP | WS_CAPTION
+EXSTYLE WS_EX_TOPMOST
+CAPTION "GWT Plugin Security Alert"
+FONT 10, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+    CONTROL         "Remember this decision for this  
server",IDC_REMEMBER_CHECKBOX,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,30,31,129,10
+    LTEXT           "This web server is trying to initiate a GWT  
Development\r\nMode Conncetion -- should it be  
allowed?",IDC_STATIC,10,7,167,19
+    PUSHBUTTON      "Allow",IDC_ALLOW_BUTTON,37,50,50,14
+    DEFPUSHBUTTON   "Deny",IDCANCEL,100,50,50,14
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+    IDD_ALLOW_DIALOG, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 181
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 66
+    END
+END
+#endif    // APSTUDIO_INVOKED
+

   
/////////////////////////////////////////////////////////////////////////////
  //
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.vcproj    Wed Sep  2  
17:27:24 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/oophm.vcproj    Thu Sep  3  
14:01:13 2009
@@ -215,6 +215,10 @@
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
                        
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
+                       <File
+                               RelativePath=".\AllowDialog.cpp"
+                               >
+                       </File>
                        <File
                                RelativePath=".\dlldatax.c"
                                >
@@ -385,6 +389,10 @@
                        Filter="h;hpp;hxx;hm;inl;inc;xsd"
                        
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
+                       <File
+                               RelativePath=".\AllowDialog.h"
+                               >
+                       </File>
                        <File
                                RelativePath=".\dlldatax.h"
                                >
=======================================
--- /changes/jat/plugins/plugins/ie/oophm/oophm/plugin.cpp      Wed Sep  2  
17:27:24 2009
+++ /changes/jat/plugins/plugins/ie/oophm/oophm/plugin.cpp      Thu Sep  3  
14:01:13 2009
@@ -26,6 +26,7 @@
  #include "ServerMethods.h"
  #include "AllowedConnections.h"
  #include "Preferences.h"
+#include "AllowDialog.h"

  // Cplugin

@@ -47,12 +48,15 @@

    std::string url = BSTRToUTF8(burl);
    Debug::log(Debug::Debugging) << "OOPHM connect(url=" << url << ")" <<  
Debug::flush;
-  // TODO(jat): load access list from somewhere
    Preferences::loadAccessList();
-  bool allowed = true; // TODO(jat): change to false when we have a dialog
+  bool allowed = false;
    if (!AllowedConnections::matchesRule(url, &allowed)) {
-    // TODO(jat): permit the user to allow the connection, for now just  
reject it
-    Debug::log(Debug::Debugging) << "Server not matched" << Debug::flush;
+    bool remember;
+    allowed = AllowDialog::askUserToAllow(&remember);
+    if (remember) {
+      std::string host = AllowedConnections::getHostFromUrl(url);
+      Preferences::addNewRule(host, !allowed);
+    }
    }
    if (!allowed) {
      *ret = false;
=======================================
--- /changes/jat/plugins/plugins/ie/prebuilt/oophm.dll  Wed Sep  2 17:03:17  
2009
+++ /changes/jat/plugins/plugins/ie/prebuilt/oophm.dll  Thu Sep  3 14:01:13  
2009
File is too large to display a diff.

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to