Commit e28b0fbb authored by jhawkins@chromium.org's avatar jhawkins@chromium.org

Use Scoped[Bstr,ComPtr,Variant] instead of their ATL equivalents to reduce dependencies on ATL.

BUG=5027
TEST=none
Review URL: http://codereview.chromium.org/200045

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25879 0039d316-1c4b-4281-b951-d872f2087c98
parent 8416157d
......@@ -5,13 +5,11 @@
#ifndef BASE_SCOPED_BSTR_WIN_H_
#define BASE_SCOPED_BSTR_WIN_H_
#include "base/basictypes.h" // needed to pick up OS_WIN
#include "base/logging.h"
#include <windows.h>
#include <oleauto.h>
#include "base/logging.h"
// Manages a BSTR string pointer.
// The class interface is based on scoped_ptr.
class ScopedBstr {
......
......@@ -28,6 +28,12 @@ ScopedVariant::ScopedVariant(int value, VARTYPE vt) {
var_.lVal = value;
}
ScopedVariant::ScopedVariant(double value, VARTYPE vt) {
DCHECK(vt == VT_R8 || vt == VT_DATE);
var_.vt = vt;
var_.dblVal = value;
}
ScopedVariant::ScopedVariant(IDispatch* dispatch) {
var_.vt = VT_EMPTY;
Set(dispatch);
......@@ -38,6 +44,11 @@ ScopedVariant::ScopedVariant(IUnknown* unknown) {
Set(unknown);
}
ScopedVariant::ScopedVariant(SAFEARRAY* safearray) {
var_.vt = VT_EMPTY;
Set(safearray);
}
ScopedVariant::ScopedVariant(const VARIANT& var) {
var_.vt = VT_EMPTY;
Set(var);
......
......@@ -40,12 +40,19 @@ class ScopedVariant {
// VARIANT.lVal (32 bit sized field).
explicit ScopedVariant(int value, VARTYPE vt = VT_I4);
// Creates a new double-precision type variant. |vt| must be either VT_R8
// or VT_DATE.
explicit ScopedVariant(double value, VARTYPE vt = VT_R8);
// VT_DISPATCH
explicit ScopedVariant(IDispatch* dispatch);
// VT_UNKNOWN
explicit ScopedVariant(IUnknown* unknown);
// SAFEARRAY
explicit ScopedVariant(SAFEARRAY* safearray);
// Copies the variant.
explicit ScopedVariant(const VARIANT& var);
......
......@@ -99,7 +99,7 @@ STDMETHODIMP AutocompleteAccessibility::get_accName(VARIANT var_id,
if (!temp_name.empty()) {
// Return name retrieved.
*name = CComBSTR(temp_name.c_str()).Detach();
*name = SysAllocString(temp_name.c_str());
} else {
// If no name is found, return S_FALSE.
return S_FALSE;
......@@ -127,20 +127,19 @@ STDMETHODIMP AutocompleteAccessibility::get_accValue(VARIANT var_id,
std::wstring temp_value;
if (var_id.lVal != CHILDID_SELF)
return E_INVALIDARG;
return E_INVALIDARG;
// Edit box has no children, only handle self.
temp_value = edit_box_->GetText();
if (temp_value.empty())
return S_FALSE;
return S_FALSE;
// Return value retrieved.
*value = CComBSTR(temp_value.c_str()).Detach();
// Return value retrieved.
*value = SysAllocString(temp_value.c_str());
DCHECK(*value);
return S_OK;
}
STDMETHODIMP AutocompleteAccessibility::get_accState(VARIANT var_id,
......
......@@ -254,7 +254,7 @@ STDMETHODIMP BrowserAccessibility::get_accDefaultAction(VARIANT var_id,
return S_FALSE;
}
*def_action = CComBSTR(response().output_string.c_str()).Detach();
*def_action = SysAllocString(response().output_string.c_str());
DCHECK(*def_action);
return S_OK;
......@@ -280,7 +280,7 @@ STDMETHODIMP BrowserAccessibility::get_accDescription(VARIANT var_id,
return S_FALSE;
}
*desc = CComBSTR(response().output_string.c_str()).Detach();
*desc = SysAllocString(response().output_string.c_str());
DCHECK(*desc);
return S_OK;
......@@ -342,7 +342,7 @@ STDMETHODIMP BrowserAccessibility::get_accHelp(VARIANT var_id, BSTR* help) {
return S_FALSE;
}
*help = CComBSTR(response().output_string.c_str()).Detach();
*help = SysAllocString(response().output_string.c_str());
DCHECK(*help);
return S_OK;
......@@ -368,7 +368,7 @@ STDMETHODIMP BrowserAccessibility::get_accKeyboardShortcut(VARIANT var_id,
return S_FALSE;
}
*acc_key = CComBSTR(response().output_string.c_str()).Detach();
*acc_key = SysAllocString(response().output_string.c_str());
DCHECK(*acc_key);
return S_OK;
......@@ -393,7 +393,7 @@ STDMETHODIMP BrowserAccessibility::get_accName(VARIANT var_id, BSTR* name) {
return S_FALSE;
}
*name = CComBSTR(response().output_string.c_str()).Detach();
*name = SysAllocString(response().output_string.c_str());
DCHECK(*name);
return S_OK;
......@@ -504,7 +504,7 @@ STDMETHODIMP BrowserAccessibility::get_accValue(VARIANT var_id, BSTR* value) {
return S_FALSE;
}
*value = CComBSTR(response().output_string.c_str()).Detach();
*value = SysAllocString(response().output_string.c_str());
DCHECK(*value);
return S_OK;
......
......@@ -10,7 +10,10 @@
#include <wtypes.h>
#include "base/registry.h"
#include "base/scoped_bstr_win.h"
#include "base/scoped_comptr_win.h"
#include "base/scoped_variant_win.h"
#include "base/string_util.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
......@@ -107,30 +110,29 @@ void HistoryPublisher::PublishDataToIndexers(const PageData& page_data)
CComSafeArray<unsigned char> thumbnail_arr;
if (page_data.thumbnail) {
for(size_t i = 0; i < page_data.thumbnail->size(); ++i)
for (size_t i = 0; i < page_data.thumbnail->size(); ++i)
thumbnail_arr.Add((*page_data.thumbnail)[i]);
}
// Send data to registered indexers.
for(size_t i = 0; i < indexers_.size(); ++i) {
indexers_[i]->SendPageData(
CComVariant(var_time, VT_DATE),
CComBSTR(page_data.url.spec().c_str()),
CComBSTR(page_data.html),
CComBSTR(page_data.title),
CComBSTR(page_data.thumbnail_format),
CComVariant(thumbnail_arr.m_psa));
ScopedVariant time(var_time, VT_DATE);
ScopedBstr url(ASCIIToWide(page_data.url.spec()).c_str());
ScopedBstr html(page_data.html);
ScopedBstr title(page_data.title);
ScopedBstr format(ASCIIToWide(page_data.thumbnail_format).c_str());
ScopedVariant psa(thumbnail_arr.m_psa);
for (size_t i = 0; i < indexers_.size(); ++i) {
indexers_[i]->SendPageData(time, url, html, title, format, psa);
}
}
void HistoryPublisher::DeleteUserHistoryBetween(const base::Time& begin_time,
const base::Time& end_time)
const {
double var_begin_time = TimeToUTCVariantTime(begin_time);
double var_end_time = TimeToUTCVariantTime(end_time);
for(size_t i = 0; i < indexers_.size(); ++i) {
indexers_[i]->DeleteUserHistoryBetween(CComVariant(var_begin_time, VT_DATE),
CComVariant(var_end_time, VT_DATE));
ScopedVariant var_begin_time(TimeToUTCVariantTime(begin_time), VT_DATE);
ScopedVariant var_end_time(TimeToUTCVariantTime(end_time), VT_DATE);
for (size_t i = 0; i < indexers_.size(); ++i) {
indexers_[i]->DeleteUserHistoryBetween(var_begin_time, var_end_time);
}
}
......
......@@ -4,19 +4,23 @@
#include "chrome/browser/importer/ie_importer.h"
#include <atlbase.h>
#include <ole2.h>
#include <intshcut.h>
#include <pstore.h>
#include <shlobj.h>
#include <urlhist.h>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include "app/l10n_util.h"
#include "app/win_util.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/registry.h"
#include "base/scoped_comptr_win.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/win_util.h"
......@@ -69,7 +73,7 @@ void IEImporter::StartImport(ProfileInfo profile_info,
NotifyStarted();
// Some IE settings (such as Protected Storage) is obtained via COM APIs.
// Some IE settings (such as Protected Storage) are obtained via COM APIs.
win_util::ScopedCOMInitializer com_initializer;
if ((items & HOME_PAGE) && !cancelled())
......@@ -142,8 +146,8 @@ void IEImporter::ImportPasswordsIE6() {
return;
}
CComPtr<IPStore> pstore;
HRESULT result = PStoreCreateInstance(&pstore, 0, 0, 0);
ScopedComPtr<IPStore, &IID_IPStore> pstore;
HRESULT result = PStoreCreateInstance(pstore.Receive(), 0, 0, 0);
if (result != S_OK) {
FreeLibrary(pstorec_dll);
return;
......@@ -152,9 +156,9 @@ void IEImporter::ImportPasswordsIE6() {
std::vector<AutoCompleteInfo> ac_list;
// Enumerates AutoComplete items in the protected database.
CComPtr<IEnumPStoreItems> item;
ScopedComPtr<IEnumPStoreItems, &IID_IEnumPStoreItems> item;
result = pstore->EnumItems(0, &AutocompleteGUID,
&AutocompleteGUID, 0, &item);
&AutocompleteGUID, 0, item.Receive());
if (result != PST_E_OK) {
pstore.Release();
FreeLibrary(pstorec_dll);
......@@ -282,14 +286,14 @@ void IEImporter::ImportHistory() {
chrome::kFileScheme};
int total_schemes = arraysize(kSchemes);
CComPtr<IUrlHistoryStg2> url_history_stg2;
ScopedComPtr<IUrlHistoryStg2> url_history_stg2;
HRESULT result;
result = url_history_stg2.CoCreateInstance(CLSID_CUrlHistory, NULL,
CLSCTX_INPROC_SERVER);
result = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL,
CLSCTX_INPROC_SERVER);
if (FAILED(result))
return;
CComPtr<IEnumSTATURL> enum_url;
if (SUCCEEDED(result = url_history_stg2->EnumUrls(&enum_url))) {
ScopedComPtr<IEnumSTATURL> enum_url;
if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) {
std::vector<history::URLRow> rows;
STATURL stat_url;
ULONG fetched;
......@@ -541,14 +545,14 @@ void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info,
std::wstring IEImporter::ResolveInternetShortcut(const std::wstring& file) {
win_util::CoMemReleaser<wchar_t> url;
CComPtr<IUniformResourceLocator> url_locator;
HRESULT result = url_locator.CoCreateInstance(CLSID_InternetShortcut, NULL,
CLSCTX_INPROC_SERVER);
ScopedComPtr<IUniformResourceLocator> url_locator;
HRESULT result = url_locator.CreateInstance(CLSID_InternetShortcut, NULL,
CLSCTX_INPROC_SERVER);
if (FAILED(result))
return std::wstring();
CComPtr<IPersistFile> persist_file;
result = url_locator.QueryInterface(&persist_file);
ScopedComPtr<IPersistFile> persist_file;
result = persist_file.QueryFrom(url_locator);
if (FAILED(result))
return std::wstring();
......
......@@ -326,7 +326,7 @@ STDMETHODIMP ViewAccessibility::get_accDefaultAction(VARIANT var_id,
GetAccessibleDefaultAction(&temp_action);
}
if (!temp_action.empty()) {
*def_action = CComBSTR(temp_action.c_str()).Detach();
*def_action = SysAllocString(temp_action.c_str());
} else {
return S_FALSE;
}
......@@ -350,7 +350,7 @@ STDMETHODIMP ViewAccessibility::get_accDescription(VARIANT var_id, BSTR* desc) {
view_->GetChildViewAt(var_id.lVal - 1)->GetTooltipText(0, 0, &temp_desc);
}
if (!temp_desc.empty()) {
*desc = CComBSTR(temp_desc.c_str()).Detach();
*desc = SysAllocString(temp_desc.c_str());
} else {
return S_FALSE;
}
......@@ -413,7 +413,7 @@ STDMETHODIMP ViewAccessibility::get_accKeyboardShortcut(VARIANT var_id,
GetAccessibleKeyboardShortcut(&temp_key);
}
if (!temp_key.empty()) {
*acc_key = CComBSTR(temp_key.c_str()).Detach();
*acc_key = SysAllocString(temp_key.c_str());
} else {
return S_FALSE;
}
......@@ -440,7 +440,7 @@ STDMETHODIMP ViewAccessibility::get_accName(VARIANT var_id, BSTR* name) {
}
if (!temp_name.empty()) {
// Return name retrieved.
*name = CComBSTR(temp_name.c_str()).Detach();
*name = SysAllocString(temp_name.c_str());
} else {
// If view has no name, return S_FALSE.
return S_FALSE;
......
......@@ -29,7 +29,7 @@ STDMETHODIMP ViewAccessibilityWrapper::CreateDefaultInstance(REFIID iid) {
if (!SUCCEEDED(hr) || !instance)
return E_FAIL;
CComPtr<IAccessible> accessibility_instance(instance);
ScopedComPtr<IAccessible> accessibility_instance(instance);
if (!SUCCEEDED(instance->Initialize(view_)))
return E_FAIL;
......
......@@ -9,6 +9,7 @@
#include <oleacc.h>
#include "base/basictypes.h"
#include "base/scoped_comptr_win.h"
namespace views {
class View;
......@@ -44,7 +45,7 @@ class ViewAccessibilityWrapper {
private:
// Instance of accessibility information and handling for a View.
CComPtr<IAccessible> accessibility_info_;
ScopedComPtr<IAccessible> accessibility_info_;
// View needed to initialize IAccessible.
views::View* view_;
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "app/l10n_util.h"
#include "app/l10n_util_win.h"
#include "app/win_util.h"
......@@ -94,9 +96,9 @@ NativeTextfieldWin::NativeTextfieldWin(Textfield* textfield)
}
// Set up the text_object_model_.
CComPtr<IRichEditOle> ole_interface;
ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface;
ole_interface.Attach(GetOleInterface());
text_object_model_ = ole_interface;
text_object_model_.QueryFrom(ole_interface);
}
NativeTextfieldWin::~NativeTextfieldWin() {
......@@ -305,7 +307,9 @@ void NativeTextfieldWin::OnCut() {
ReplaceSel(L"", true);
}
LRESULT NativeTextfieldWin::OnImeChar(UINT message, WPARAM wparam, LPARAM lparam) {
LRESULT NativeTextfieldWin::OnImeChar(UINT message,
WPARAM wparam,
LPARAM lparam) {
// http://crbug.com/7707: a rich-edit control may crash when it receives a
// WM_IME_CHAR message while it is processing a WM_IME_COMPOSITION message.
// Since view controls don't need WM_IME_CHAR messages, we prevent WM_IME_CHAR
......@@ -512,7 +516,7 @@ LRESULT NativeTextfieldWin::OnMouseWheel(UINT message, WPARAM w_param,
// applicable.
if (views::RerouteMouseWheel(m_hWnd, w_param, l_param))
return 0;
return DefWindowProc(message, w_param, l_param);;
return DefWindowProc(message, w_param, l_param);
}
void NativeTextfieldWin::OnMouseMove(UINT keys, const CPoint& point) {
......@@ -842,9 +846,9 @@ void NativeTextfieldWin::SetContainsMouse(bool contains_mouse) {
ITextDocument* NativeTextfieldWin::GetTextObjectModel() const {
if (!text_object_model_) {
CComPtr<IRichEditOle> ole_interface;
ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface;
ole_interface.Attach(GetOleInterface());
text_object_model_ = ole_interface;
text_object_model_.QueryFrom(ole_interface);
}
return text_object_model_;
}
......
......@@ -13,6 +13,7 @@
#include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl
#include <vsstyle.h>
#include "base/scoped_comptr_win.h"
#include "views/controls/menu/simple_menu_model.h"
#include "views/controls/textfield/native_textfield_wrapper.h"
......@@ -195,7 +196,7 @@ class NativeTextfieldWin
gfx::Insets content_insets_;
// This interface is useful for accessing the CRichEditCtrl at a low level.
mutable CComQIPtr<ITextDocument> text_object_model_;
mutable ScopedComPtr<ITextDocument> text_object_model_;
// The position and the length of the ongoing composition string.
// These values are used for removing a composition string from a search
......
......@@ -470,7 +470,7 @@ LRESULT WidgetWin::OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param) {
return static_cast<LRESULT>(0L);
}
CComPtr<IAccessible> accessibility_instance(instance);
ScopedComPtr<IAccessible> accessibility_instance(instance);
if (!SUCCEEDED(instance->Initialize(root_view_.get()))) {
// Return with failure.
......
......@@ -11,6 +11,7 @@
#include <atlmisc.h>
#include "base/message_loop.h"
#include "base/scoped_comptr_win.h"
#include "base/system_monitor.h"
#include "base/window_impl.h"
#include "views/focus/focus_manager.h"
......@@ -586,7 +587,7 @@ class WidgetWin : public base::WindowImpl,
int last_mouse_move_y_;
// Instance of accessibility information and handling for MSAA root
CComPtr<IAccessible> accessibility_root_;
ScopedComPtr<IAccessible> accessibility_root_;
scoped_ptr<DefaultThemeProvider> default_theme_provider_;
};
......
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