Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(997)

Side by Side Diff: printing/backend/win_helper.cc

Issue 6037019: Fixed a crash with some HP printer drivers (when invoking PTGetPrintCapabilit... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/backend/win_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "printing/backend/win_helper.h" 5 #include "printing/backend/win_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace { 9 namespace {
10 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, 10 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 HRESULT XPSModule::ReleaseMemory(PVOID buffer) { 170 HRESULT XPSModule::ReleaseMemory(PVOID buffer) {
171 return g_release_memory_proc(buffer); 171 return g_release_memory_proc(buffer);
172 } 172 }
173 173
174 HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) { 174 HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) {
175 return g_close_provider_proc(provider); 175 return g_close_provider_proc(provider);
176 } 176 }
177 177
178 ScopedXPSInitializer::ScopedXPSInitializer() : initialized_(false) {
179 if (XPSModule::Init()) {
180 // Calls to XPS APIs typically require the XPS provider to be opened with
181 // PTOpenProvider. PTOpenProvider calls CoInitializeEx with
182 // COINIT_MULTITHREADED. We have seen certain buggy HP printer driver DLLs
183 // that call CoInitializeEx with COINIT_APARTMENTTHREADED in the context of
184 // PTGetPrintCapabilities. This call fails but the printer driver calls
185 // CoUninitialize anyway. This results in the apartment being torn down too
186 // early and the msxml DLL being unloaded which in turn causes code in
187 // unidrvui.dll to have a dangling pointer to an XML document which causes a
188 // crash. To protect ourselves from such drivers we make sure we always have
189 // an extra CoInitialize (calls to CoInitialize/CoUninitialize are
190 // refcounted).
191 HRESULT coinit_ret = CoInitializeEx(NULL, COINIT_MULTITHREADED);
192 // If this succeeded we are done because the PTOpenProvider call will
193 // provide the extra refcount on the apartment. If it failed because someone
194 // already called CoInitializeEx with COINIT_APARTMENTTHREADED, we try
195 // the other model to provide the additional refcount (since we don't know
196 // which model buggy printer drivers will use).
197 if (coinit_ret == RPC_E_CHANGED_MODE)
198 coinit_ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
199 DCHECK(SUCCEEDED(coinit_ret));
200 initialized_ = true;
201 }
202 }
203
204 ScopedXPSInitializer::~ScopedXPSInitializer() {
205 if (initialized_)
206 CoUninitialize();
207 initialized_ = false;
208 }
209
178 } // namespace printing 210 } // namespace printing
OLDNEW
« no previous file with comments | « printing/backend/win_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698