Bug 1287002: Utility functions for Microsoft COM glue; r?jimm draft
authorAaron Klotz <aklotz@mozilla.com>
Thu, 14 Jul 2016 16:55:31 -0600
changeset 389245 8c06135fc77955daae1882eeb1034733ebc5802a
parent 389244 7cc325c7502203a7819ca70ae8665a770ee69f9f
child 389246 d349a1c78429b94ff1192d40df58fc6cb57c74eb
push id23333
push useraklotz@mozilla.com
push dateMon, 18 Jul 2016 20:50:01 +0000
reviewersjimm
bugs1287002
milestone50.0a1
Bug 1287002: Utility functions for Microsoft COM glue; r?jimm MozReview-Commit-ID: DTH2lIvKjX9
ipc/mscom/Utils.cpp
ipc/mscom/Utils.h
ipc/mscom/moz.build
new file mode 100644
--- /dev/null
+++ b/ipc/mscom/Utils.cpp
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/mscom/Utils.h"
+#include "mozilla/RefPtr.h"
+
+#include <objidl.h>
+
+namespace mozilla {
+namespace mscom {
+
+bool
+IsProxy(IUnknown* aUnknown)
+{
+  if (!aUnknown) {
+    return false;
+  }
+
+  // Only proxies implement this interface, so if it is present then we must
+  // be dealing with a proxied object.
+  RefPtr<IClientSecurity> clientSecurity;
+  HRESULT hr = aUnknown->QueryInterface(IID_IClientSecurity,
+                                        (void**)getter_AddRefs(clientSecurity));
+  if (SUCCEEDED(hr) || hr == RPC_E_WRONG_THREAD) {
+    return true;
+  }
+  return false;
+}
+
+} // namespace mscom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/ipc/mscom/Utils.h
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_mscom_Utils_h
+#define mozilla_mscom_Utils_h
+
+struct IUnknown;
+
+namespace mozilla {
+namespace mscom {
+
+bool IsProxy(IUnknown* aUnknown);
+
+} // namespace mscom
+} // namespace mozilla
+
+#endif // mozilla_mscom_Utils_h
+
--- a/ipc/mscom/moz.build
+++ b/ipc/mscom/moz.build
@@ -1,16 +1,18 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS.mozilla.mscom += [
     'COMApartmentRegion.h',
+    'Utils.h',
 ]
 
 UNIFIED_SOURCES += [
+    'Utils.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'