OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ | 5 #ifndef CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
6 #define CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ | 6 #define CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 bool eof_; | 86 bool eof_; |
87 | 87 |
88 private: | 88 private: |
89 DISALLOW_COPY_AND_ASSIGN(SniffData); | 89 DISALLOW_COPY_AND_ASSIGN(SniffData); |
90 }; | 90 }; |
91 | 91 |
92 // A wrapper for bind status callback in IMoniker::BindToStorage | 92 // A wrapper for bind status callback in IMoniker::BindToStorage |
93 class BSCBStorageBind : public BSCBImpl { | 93 class BSCBStorageBind : public BSCBImpl { |
94 public: | 94 public: |
95 typedef BSCBImpl CallbackImpl; | 95 typedef BSCBImpl CallbackImpl; |
96 BSCBStorageBind() : clip_format_(CF_NULL) {} | 96 BSCBStorageBind(); |
| 97 ~BSCBStorageBind(); |
97 | 98 |
98 BEGIN_COM_MAP(BSCBStorageBind) | 99 BEGIN_COM_MAP(BSCBStorageBind) |
99 COM_INTERFACE_ENTRY(IBindStatusCallback) | 100 COM_INTERFACE_ENTRY(IBindStatusCallback) |
100 COM_INTERFACE_ENTRY_CHAIN(CallbackImpl) | 101 COM_INTERFACE_ENTRY_CHAIN(CallbackImpl) |
101 END_COM_MAP() | 102 END_COM_MAP() |
102 | 103 |
103 HRESULT Initialize(IMoniker* moniker, IBindCtx* bind_ctx); | 104 HRESULT Initialize(IMoniker* moniker, IBindCtx* bind_ctx); |
104 HRESULT MayPlayBack(DWORD flags); | 105 HRESULT MayPlayBack(DWORD flags); |
105 | 106 |
106 // IBindStatusCallback | 107 // IBindStatusCallback |
107 STDMETHOD(OnProgress)(ULONG progress, ULONG progress_max, ULONG status_code, | 108 STDMETHOD(OnProgress)(ULONG progress, ULONG progress_max, ULONG status_code, |
108 LPCWSTR status_text); | 109 LPCWSTR status_text); |
109 STDMETHOD(OnDataAvailable)(DWORD flags, DWORD size, FORMATETC* format_etc, | 110 STDMETHOD(OnDataAvailable)(DWORD flags, DWORD size, FORMATETC* format_etc, |
110 STGMEDIUM* stgmed); | 111 STGMEDIUM* stgmed); |
111 STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR error); | 112 STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR error); |
112 | 113 |
113 protected: | 114 protected: |
114 // is it a good time to start caching progress notifications | 115 // is it a good time to start caching progress notifications |
115 bool ShouldCacheProgress(ULONG status_code) const; | 116 bool ShouldCacheProgress(ULONG status_code) const; |
116 | 117 |
117 protected: | 118 protected: |
118 SniffData data_sniffer_; | 119 SniffData data_sniffer_; |
119 | 120 |
120 // A structure to cache the progress notifications | 121 // A structure to cache the progress notifications. |
121 struct Progress { | 122 class Progress { |
| 123 public: |
| 124 Progress(ULONG progress, ULONG progress_max, ULONG status_code, |
| 125 const wchar_t* status_text) |
| 126 : progress_(progress), |
| 127 progress_max_(progress_max), |
| 128 status_code_(status_code), |
| 129 status_text_(NULL) { |
| 130 if (status_text) { |
| 131 int len = lstrlenW(status_text) + 1; |
| 132 status_text_ = reinterpret_cast<wchar_t*>( |
| 133 ::CoTaskMemAlloc(len * sizeof(wchar_t))); |
| 134 if (status_text_) { |
| 135 lstrcpyW(status_text_, status_text); |
| 136 } else { |
| 137 NOTREACHED(); |
| 138 } |
| 139 } |
| 140 } |
| 141 |
| 142 ~Progress() { |
| 143 if (status_text_) { |
| 144 ::CoTaskMemFree(status_text_); |
| 145 } |
| 146 } |
| 147 |
| 148 ULONG progress() const { |
| 149 return progress_; |
| 150 } |
| 151 |
| 152 ULONG progress_max() const { |
| 153 return progress_max_; |
| 154 } |
| 155 |
| 156 ULONG status_code() const { |
| 157 return status_code_; |
| 158 } |
| 159 |
| 160 const wchar_t* status_text() const { |
| 161 return status_text_; |
| 162 } |
| 163 |
| 164 protected: |
122 ULONG progress_; | 165 ULONG progress_; |
123 ULONG progress_max_; | 166 ULONG progress_max_; |
124 ULONG status_code_; | 167 ULONG status_code_; |
125 std::wstring status_text_; | 168 // We don't use std::wstring here since we want to be able to play |
| 169 // progress notifications back exactly as we got them. NULL and L"" are |
| 170 // not equal. |
| 171 wchar_t* status_text_; |
126 }; | 172 }; |
127 | 173 |
128 std::vector<Progress> saved_progress_; | 174 std::vector<Progress*> saved_progress_; |
129 CLIPFORMAT clip_format_; | 175 CLIPFORMAT clip_format_; |
130 | 176 |
131 private: | 177 private: |
132 DISALLOW_COPY_AND_ASSIGN(BSCBStorageBind); | 178 DISALLOW_COPY_AND_ASSIGN(BSCBStorageBind); |
133 }; | 179 }; |
134 | 180 |
135 #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ | 181 #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
OLD | NEW |