From 74e9983aad8bb03972a9716de621fd9292cad5b1 Mon Sep 17 00:00:00 2001 From: "tommi@chromium.org" Date: Fri, 14 May 2010 02:27:34 +0000 Subject: Not using std::wstring to store progress status text because mshtml is sensitive to NULL vs L"". TEST=see bug BUG=44103 Review URL: http://codereview.chromium.org/2118001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47232 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/urlmon_bind_status_callback.cc | 27 ++++++++++----- chrome_frame/urlmon_bind_status_callback.h | 52 ++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 14 deletions(-) (limited to 'chrome_frame') diff --git a/chrome_frame/urlmon_bind_status_callback.cc b/chrome_frame/urlmon_bind_status_callback.cc index 5730870..0f886a1 100644 --- a/chrome_frame/urlmon_bind_status_callback.cc +++ b/chrome_frame/urlmon_bind_status_callback.cc @@ -204,6 +204,16 @@ void SniffData::DetermineRendererType(bool last_chance) { ///////////////////////////////////////////////////////////////////// +BSCBStorageBind::BSCBStorageBind() : clip_format_(CF_NULL) { +} + +BSCBStorageBind::~BSCBStorageBind() { + for (std::vector::iterator i = saved_progress_.begin(); + i != saved_progress_.end(); i++) { + delete (*i); + } +} + HRESULT BSCBStorageBind::Initialize(IMoniker* moniker, IBindCtx* bind_ctx) { DLOG(INFO) << __FUNCTION__ << me() << StringPrintf(" tid=%i", PlatformThread::CurrentId()); @@ -250,9 +260,8 @@ STDMETHODIMP BSCBStorageBind::OnProgress(ULONG progress, ULONG progress_max, } if (ShouldCacheProgress(status_code)) { - Progress new_progress = { progress, progress_max, status_code, - status_text ? status_text : std::wstring() }; - saved_progress_.push_back(new_progress); + saved_progress_.push_back(new Progress(progress, progress_max, status_code, + status_text)); } else { hr = CallbackImpl::OnProgress(progress, progress_max, status_code, status_text); @@ -347,12 +356,12 @@ HRESULT BSCBStorageBind::MayPlayBack(DWORD flags) { clip_format_ = kMagicClipFormat; } else { if (!saved_progress_.empty()) { - for (std::vector::iterator i = saved_progress_.begin(); - i != saved_progress_.end(); i++) { - const wchar_t* status_text = i->status_text_.empty() ? - NULL : i->status_text_.c_str(); - CallbackImpl::OnProgress(i->progress_, i->progress_max_, - i->status_code_, status_text); + for (std::vector::iterator i = saved_progress_.begin(); + i != saved_progress_.end(); i++) { + Progress* p = (*i); + CallbackImpl::OnProgress(p->progress(), p->progress_max(), + p->status_code(), p->status_text()); + delete p; } saved_progress_.clear(); } diff --git a/chrome_frame/urlmon_bind_status_callback.h b/chrome_frame/urlmon_bind_status_callback.h index 484bef3..ef73cb8 100644 --- a/chrome_frame/urlmon_bind_status_callback.h +++ b/chrome_frame/urlmon_bind_status_callback.h @@ -93,7 +93,8 @@ class SniffData { class BSCBStorageBind : public BSCBImpl { public: typedef BSCBImpl CallbackImpl; - BSCBStorageBind() : clip_format_(CF_NULL) {} + BSCBStorageBind(); + ~BSCBStorageBind(); BEGIN_COM_MAP(BSCBStorageBind) COM_INTERFACE_ENTRY(IBindStatusCallback) @@ -117,15 +118,56 @@ END_COM_MAP() protected: SniffData data_sniffer_; - // A structure to cache the progress notifications - struct Progress { + // A structure to cache the progress notifications. + class Progress { + public: + Progress(ULONG progress, ULONG progress_max, ULONG status_code, + const wchar_t* status_text) + : progress_(progress), + progress_max_(progress_max), + status_code_(status_code), + status_text_(NULL) { + if (status_text) { + int len = lstrlenW(status_text) + 1; + status_text_.reset(new wchar_t[len]); + if (status_text_.get()) { + lstrcpyW(status_text_.get(), status_text); + } else { + NOTREACHED(); + } + } + } + + ~Progress() { + } + + ULONG progress() const { + return progress_; + } + + ULONG progress_max() const { + return progress_max_; + } + + ULONG status_code() const { + return status_code_; + } + + const wchar_t* status_text() const { + return status_text_.get(); + } + + protected: ULONG progress_; ULONG progress_max_; ULONG status_code_; - std::wstring status_text_; + // We don't use std::wstring here since we want to be able to play + // progress notifications back exactly as we got them. NULL and L"" are + // not equal. + scoped_ptr status_text_; }; - std::vector saved_progress_; + std::vector saved_progress_; CLIPFORMAT clip_format_; private: -- cgit v1.1