summaryrefslogtreecommitdiffstats
path: root/ceee/common/com_utils.cc
diff options
context:
space:
mode:
authorinitial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 02:14:31 +0000
committerinitial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 02:14:31 +0000
commit5a7bdf208c28c210b39cff63d1cf91302b02821b (patch)
tree5ff484561562f78b29d2670168a9e3b40b48dcab /ceee/common/com_utils.cc
parent26a54a5e0f4603c8fda2fe51789d331125993c9a (diff)
downloadchromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.zip
chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.gz
chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.bz2
Checking in the initial version of CEEE (Chrome Extensions Execution
Environment), an optional feature of Chrome Frame that acts as an adapter layer for a subset of the Chrome Extension APIs. This enables extensions that stick to the supported subset of APIs to work in the context of Chrome Frame with minimal or sometimes no changes. See http://www.chromium.org/developers/design-documents/ceee for an overview of the design of CEEE. TEST=unit tests (run ceee/smoke_tests.bat as an administrator on Windows) BUG=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee/common/com_utils.cc')
-rw-r--r--ceee/common/com_utils.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/ceee/common/com_utils.cc b/ceee/common/com_utils.cc
new file mode 100644
index 0000000..b251ca1
--- /dev/null
+++ b/ceee/common/com_utils.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Utilities for COM objects, error codes etc.
+
+#include "ceee/common/com_utils.h"
+
+#include <atlbase.h>
+#include <shlwapi.h>
+
+#include "base/string_util.h"
+
+namespace com {
+
+std::ostream& operator<<(std::ostream& os, const LogHr& hr) {
+ // Looks up the human-readable system message for the HRESULT code
+ // and since we're not passing any params to FormatMessage, we don't
+ // want inserts expanded.
+ const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS;
+ char error_text[4096] = { '\0' };
+ DWORD message_length = ::FormatMessageA(kFlags, 0, hr.hr_, 0, error_text,
+ arraysize(error_text), NULL);
+ std::string error(error_text);
+ TrimString(error, kWhitespaceASCII, &error);
+
+ return os << "[hr=0x" << std::hex << hr.hr_ << ", msg=" << error << "]";
+}
+
+std::ostream& operator<<(std::ostream& os, const LogWe& we) {
+ // Looks up the human-readable system message for the Windows error code
+ // and since we're not passing any params to FormatMessage, we don't
+ // want inserts expanded.
+ const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS;
+ char error_text[4096] = { '\0' };
+ DWORD message_length = ::FormatMessageA(kFlags, 0, we.we_, 0, error_text,
+ arraysize(error_text), NULL);
+ std::string error(error_text);
+ TrimString(error, kWhitespaceASCII, &error);
+
+ return os << "[we=" << we.we_ << ", msg=" << error << "]";
+}
+
+// Seam so unit tests can mock out the side effects of this function.
+HRESULT UpdateRegistryFromResourceImpl(int reg_id, BOOL should_register,
+ _ATL_REGMAP_ENTRY* entries) {
+ return _pAtlModule->UpdateRegistryFromResource(
+ reg_id, should_register, entries);
+}
+
+HRESULT ModuleRegistrationWithoutAppid(int reg_id, BOOL should_register) {
+ // Get our module path.
+ wchar_t module_path[MAX_PATH] = { 0 };
+ if (0 == ::GetModuleFileName(_AtlBaseModule.GetModuleInstance(),
+ module_path, arraysize(module_path))) {
+ NOTREACHED();
+ return AlwaysErrorFromLastError();
+ }
+
+ // Copy the filename.
+ std::wstring module_basename(::PathFindFileName(module_path));
+ // And strip the filename.
+ if (!::PathRemoveFileSpec(module_path)) {
+ NOTREACHED();
+ return AlwaysErrorFromLastError();
+ }
+
+ _ATL_REGMAP_ENTRY entries[] = {
+ { L"MODULE_PATH", module_path },
+ { L"MODULE_BASENAME", module_basename.c_str() },
+ { NULL, NULL}
+ };
+
+ return UpdateRegistryFromResourceImpl(reg_id, should_register, entries);
+}
+
+} // namespace com