Commit 27f5d779 authored by dmazzoni@chromium.org's avatar dmazzoni@chromium.org

Fix double-initialization of CComModule.

This should allow ATL to work in all build configurations by
dynamically creating a CComModule only if needed.

BUG=102736
TEST=None
Review URL: http://codereview.chromium.org/8467002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109953 0039d316-1c4b-4281-b951-d872f2087c98
parent 7afe8b11
......@@ -8,6 +8,7 @@
#include "content/browser/accessibility/browser_accessibility_win.h"
#include "content/common/view_messages.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/win/atl_module.h"
using webkit_glue::WebAccessibility;
......@@ -52,11 +53,7 @@ VARIANT CreateI4Variant(LONG value) {
class BrowserAccessibilityTest : public testing::Test {
protected:
virtual void SetUp() {
// ATL needs a pointer to a COM module.
static CComModule module;
_pAtlModule = &module;
// Make sure COM is initialized for this thread; it's safe to call twice.
ui::win::CreateATLModuleIfNeeded();
::CoInitialize(NULL);
}
......
......@@ -19,6 +19,7 @@
#include "grit/generated_resources.h"
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/win/atl_module.h"
#include "ui/views/accessibility/native_view_accessibility_win.h"
#include "views/widget/widget.h"
......@@ -26,16 +27,12 @@ namespace {
VARIANT id_self = {VT_I4, CHILDID_SELF};
// Dummy class to force creation of ATL module, needed by COM to instantiate
// NativeViewAccessibilityWin.
class TestAtlModule : public CAtlDllModuleT<TestAtlModule> {};
TestAtlModule test_atl_module_;
} // namespace
class BrowserViewsAccessibilityTest : public InProcessBrowserTest {
public:
BrowserViewsAccessibilityTest() {
ui::win::CreateATLModuleIfNeeded();
::CoInitialize(NULL);
}
......
......@@ -21,6 +21,7 @@
#if defined(OS_WIN)
#include <atlbase.h>
#include <atlcom.h>
#include "ui/base/win/atl_module.h"
#endif
using webkit_glue::WebAccessibility;
......@@ -71,13 +72,7 @@ class RendererAccessibilityBrowserTest : public InProcessBrowserTest {
void RendererAccessibilityBrowserTest::SetUpInProcessBrowserTestFixture() {
#if defined(OS_WIN)
// ATL might need a pointer to a COM module, depending on the build config.
if (!_pAtlModule) {
static CComModule module;
_pAtlModule = &module;
}
// Make sure COM is initialized for this thread; it's safe to call twice.
ui::win::CreateATLModuleIfNeeded();
::CoInitialize(NULL);
#endif
}
......
// Copyright (c) 2011 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.
#ifndef UI_BASE_WIN_ATL_MODULE_H_
#define UI_BASE_WIN_ATL_MODULE_H_
#pragma once
#include <atlbase.h>
#include <atlcom.h>
#include "base/basictypes.h"
namespace ui {
namespace win {
// Ensure that we have exactly one ATL module registered. It's safe to
// call this more than once. ATL functions will crash if there's no
// ATL module registered, or if you try to register two of them, so
// dynamically registering one if needed makes it much easier for us
// to support different build configurations like multi-dll without
// worrying about which side of a module boundary each ATL module object
// belongs on.
//
// This function must be implemented in this header file rather than a
// source file so that it's inlined into the module where it's included,
// rather than in the "ui" module.
static void CreateATLModuleIfNeeded() {
if (_pAtlModule == NULL) {
// This creates the module and automatically updates _pAtlModule.
CR_DEFINE_STATIC_LOCAL(CComModule, module, ());
}
}
} // namespace win
} // namespace ui
#endif // UI_BASE_WIN_ATL_MODULE_H_
......@@ -206,6 +206,7 @@
'base/view_prop.cc',
'base/view_prop.h',
'base/wayland/events_wayland.cc',
'base/win/atl_module.h',
'base/win/events_win.cc',
'base/win/hwnd_util.cc',
'base/win/hwnd_util.h',
......
......@@ -13,6 +13,7 @@
#include "ui/base/accessibility/accessible_text_utils.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/view_prop.h"
#include "ui/base/win/atl_module.h"
#include "views/widget/native_widget_win.h"
#include "views/widget/widget.h"
......@@ -24,6 +25,9 @@ long NativeViewAccessibilityWin::next_unique_id_ = 1;
// static
scoped_refptr<NativeViewAccessibilityWin> NativeViewAccessibilityWin::Create(
views::View* view) {
// Make sure ATL is initialized in this module.
ui::win::CreateATLModuleIfNeeded();
CComObject<NativeViewAccessibilityWin>* instance = NULL;
HRESULT hr = CComObject<NativeViewAccessibilityWin>::CreateInstance(
&instance);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment