diff options
-rw-r--r-- | ceee/ie/common/ceee_util.cc | 29 | ||||
-rw-r--r-- | ceee/ie/common/ceee_util.h | 17 | ||||
-rw-r--r-- | ceee/ie/common/ceee_util_unittest.cc | 55 | ||||
-rw-r--r-- | ceee/ie/common/common.gyp | 16 | ||||
-rw-r--r-- | ceee/ie/ie.gyp | 1 | ||||
-rw-r--r-- | chrome_frame/chrome_frame.gyp | 2 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_activex_base.h | 8 | ||||
-rw-r--r-- | chrome_frame/test/chrome_frame_test_utils.cc | 9 |
8 files changed, 126 insertions, 11 deletions
diff --git a/ceee/ie/common/ceee_util.cc b/ceee/ie/common/ceee_util.cc new file mode 100644 index 0000000..4d9b3d5 --- /dev/null +++ b/ceee/ie/common/ceee_util.cc @@ -0,0 +1,29 @@ +// 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. +// +// Utility functions for CEEE. + +#include "ceee/ie/common/ceee_util.h" + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/win/registry.h" + +#include "toolband.h" // NOLINT + +namespace ceee_util { + +bool IsIeCeeeRegistered() { + wchar_t clsid[40] = { 0 }; + int num_chars = ::StringFromGUID2(CLSID_ToolBand, clsid, arraysize(clsid)); + CHECK(num_chars > 0); + + std::wstring path(L"CLSID\\"); + path += clsid; + + base::win::RegKey key; + return key.Open(HKEY_CLASSES_ROOT, path.c_str(), KEY_QUERY_VALUE); +} + +} // namespace ceee_util diff --git a/ceee/ie/common/ceee_util.h b/ceee/ie/common/ceee_util.h new file mode 100644 index 0000000..36654fa --- /dev/null +++ b/ceee/ie/common/ceee_util.h @@ -0,0 +1,17 @@ +// 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. +// +// Utility functions for CEEE. + +#ifndef CEEE_IE_COMMON_CEEE_UTIL_H_ +#define CEEE_IE_COMMON_CEEE_UTIL_H_ + +namespace ceee_util { + +// Returns true iff the IE CEEE is registered. +bool IsIeCeeeRegistered(); + +} // namespace ceee_util + +#endif // CEEE_IE_COMMON_CEEE_UTIL_H_ diff --git a/ceee/ie/common/ceee_util_unittest.cc b/ceee/ie/common/ceee_util_unittest.cc new file mode 100644 index 0000000..2414998 --- /dev/null +++ b/ceee/ie/common/ceee_util_unittest.cc @@ -0,0 +1,55 @@ +// 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. +// +// Unit tests for the CEEE utilities. + +#include "ceee/ie/common/ceee_util.h" + +#include <ostream> // NOLINT +#include <winerror.h> + +#include "base/logging.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "ceee/testing/utils/mock_static.h" + +namespace { + +using testing::_; +using testing::Return; + +TEST(CeeeUtilTest, IsIeCeeeRegisteredRealRegistry) { + // This exercises the code but does not assert on the result, + // it simply prints the result for human evaluation. + // + // It's hard to mock the HKCR registry so don't try for now; + // further tests mock out the entire registry access. + bool is_registered = ceee_util::IsIeCeeeRegistered(); + std::cout << "IsIeCeeeRegistered returned " << is_registered << std::endl; +} + +MOCK_STATIC_CLASS_BEGIN(MockRegOpenKeyEx) + MOCK_STATIC_INIT_BEGIN(MockRegOpenKeyEx) + MOCK_STATIC_INIT(RegOpenKeyEx); + MOCK_STATIC_INIT_END() + + MOCK_STATIC5(LSTATUS, APIENTRY, RegOpenKeyEx, + HKEY, LPCWSTR, DWORD, REGSAM, PHKEY); +MOCK_STATIC_CLASS_END(MockRegOpenKeyEx) + +TEST(CeeeUtilTest, IsIeCeeeRegisteredYes) { + MockRegOpenKeyEx mock_reg; + EXPECT_CALL(mock_reg, RegOpenKeyEx(_, _, _, _, _)) + .WillOnce(Return(ERROR_SUCCESS)); + ASSERT_TRUE(ceee_util::IsIeCeeeRegistered()); +} + +TEST(CeeeUtilTest, IsIeCeeeRegisteredNo) { + MockRegOpenKeyEx mock_reg; + EXPECT_CALL(mock_reg, RegOpenKeyEx(_, _, _, _, _)) + .WillOnce(Return(ERROR_FILE_NOT_FOUND)); + ASSERT_FALSE(ceee_util::IsIeCeeeRegistered()); +} + +} // namespace diff --git a/ceee/ie/common/common.gyp b/ceee/ie/common/common.gyp index 9a47400..8ef29dd 100644 --- a/ceee/ie/common/common.gyp +++ b/ceee/ie/common/common.gyp @@ -49,18 +49,20 @@ 'type': 'static_library', 'dependencies': [ 'ie_common_settings', - '../../../base/base.gyp:base', - '../../../breakpad/breakpad.gyp:breakpad_handler', - '../../../build/temp_gyp/googleurl.gyp:googleurl', - '../../../net/net.gyp:net_base', - '../../../ceee/common/common.gyp:initializing_coclass', - '../../../ceee/common/common.gyp:ceee_common', + '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/breakpad/breakpad.gyp:breakpad_handler', + '<(DEPTH)/build/temp_gyp/googleurl.gyp:googleurl', + '<(DEPTH)/ceee/common/common.gyp:initializing_coclass', + '<(DEPTH)/ceee/common/common.gyp:ceee_common', + '<(DEPTH)/ceee/ie/plugin/toolband/toolband.gyp:toolband_idl', '<(DEPTH)/chrome/chrome.gyp:chrome_version_header', '<(DEPTH)/chrome_frame/chrome_frame.gyp:chrome_tab_idl', - '../plugin/toolband/toolband.gyp:toolband_idl', + '<(DEPTH)/net/net.gyp:net_base', ], 'sources': [ 'api_registration.h', + 'ceee_util.cc', + 'ceee_util.h', 'chrome_frame_host.cc', 'chrome_frame_host.h', 'constants.cc', diff --git a/ceee/ie/ie.gyp b/ceee/ie/ie.gyp index b3bd6a98..2ee286c 100644 --- a/ceee/ie/ie.gyp +++ b/ceee/ie/ie.gyp @@ -48,6 +48,7 @@ 'broker/window_api_module_unittest.cc', 'broker/window_events_funnel_unittest.cc', 'common/ceee_module_util_unittest.cc', + 'common/ceee_util_unittest.cc', 'common/chrome_frame_host_unittest.cc', 'common/crash_reporter_unittest.cc', 'common/extension_manifest_unittest.cc', diff --git a/chrome_frame/chrome_frame.gyp b/chrome_frame/chrome_frame.gyp index 6fc4d6d..095a1ed 100644 --- a/chrome_frame/chrome_frame.gyp +++ b/chrome_frame/chrome_frame.gyp @@ -695,6 +695,8 @@ 'chrome_frame_strings', 'chrome_frame_utils', 'chrome_tab_idl', + '../ceee/ie/common/common.gyp:ie_common', + '../ceee/ie/common/common.gyp:ie_guids', '../chrome/chrome.gyp:common', '../chrome/chrome.gyp:utility', '../build/temp_gyp/googleurl.gyp:googleurl', diff --git a/chrome_frame/chrome_frame_activex_base.h b/chrome_frame/chrome_frame_activex_base.h index ebaf06c..1dd2755 100644 --- a/chrome_frame/chrome_frame_activex_base.h +++ b/chrome_frame/chrome_frame_activex_base.h @@ -24,6 +24,7 @@ #include "base/win/scoped_comptr.h" #include "base/win/scoped_variant.h" #include "grit/chrome_frame_resources.h" +#include "ceee/ie/common/ceee_util.h" #include "chrome/common/url_constants.h" #include "chrome_frame/chrome_frame_plugin.h" #include "chrome_frame/com_message_event.h" @@ -411,7 +412,12 @@ END_MSG_MAP() (lstrcmpi(profile_name.c_str(), kRundllProfileName) == 0); // Browsers without IDeleteBrowsingHistory in non-priv mode // have their profiles moved into "Temporary Internet Files". - if (is_IE && GetIEVersion() < IE_8 && !is_privileged_) { + // + // If CEEE is registered, we must have a persistent profile. We + // considered checking if e.g. ceee_ie.dll is loaded in the process + // but this gets into edge cases when the user enables the CEEE add-on + // after CF is first loaded. + if (is_IE && GetIEVersion() < IE_8 && !ceee_util::IsIeCeeeRegistered()) { *profile_path = GetIETemporaryFilesFolder(); *profile_path = profile_path->Append(L"Google Chrome Frame"); } else { diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc index c51877f..f44f22c 100644 --- a/chrome_frame/test/chrome_frame_test_utils.cc +++ b/chrome_frame/test/chrome_frame_test_utils.cc @@ -24,6 +24,7 @@ #include "base/win_util.h" #include "base/win/registry.h" #include "base/win/windows_version.h" +#include "ceee/ie/common/ceee_util.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths_internal.h" @@ -400,6 +401,7 @@ HRESULT LaunchIEAsComServer(IWebBrowser2** web_browser) { return hr; } +// TODO(joi@chromium.org) Could share this code with chrome_frame_plugin.h FilePath GetProfilePath(const std::wstring& profile_name) { FilePath profile_path; chrome::GetChromeFrameUserDataDirectory(&profile_path); @@ -432,17 +434,18 @@ IEVersion GetInstalledIEVersion() { return IE_UNSUPPORTED; } +// TODO(joi@chromium.org) Could share this code with chrome_frame_plugin.h FilePath GetProfilePathForIE() { FilePath profile_path; // Browsers without IDeleteBrowsingHistory in non-priv mode // have their profiles moved into "Temporary Internet Files". // The code below basically retrieves the version of IE and computes // the profile directory accordingly. - if (GetInstalledIEVersion() >= IE_8) { - profile_path = GetProfilePath(kIEProfileName); - } else { + if (GetInstalledIEVersion() <= IE_7 && !ceee_util::IsIeCeeeRegistered()) { profile_path = GetIETemporaryFilesFolder(); profile_path = profile_path.Append(L"Google Chrome Frame"); + } else { + profile_path = GetProfilePath(kIEProfileName); } return profile_path; } |