| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 HRESULT XPSModule::ReleaseMemory(PVOID buffer) { | 233 HRESULT XPSModule::ReleaseMemory(PVOID buffer) { |
| 234 return g_release_memory_proc(buffer); | 234 return g_release_memory_proc(buffer); |
| 235 } | 235 } |
| 236 | 236 |
| 237 HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) { | 237 HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) { |
| 238 return g_close_provider_proc(provider); | 238 return g_close_provider_proc(provider); |
| 239 } | 239 } |
| 240 | 240 |
| 241 ScopedXPSInitializer::ScopedXPSInitializer() : initialized_(false) { | 241 ScopedXPSInitializer::ScopedXPSInitializer() : initialized_(false) { |
| 242 if (XPSModule::Init()) { | 242 if (!XPSModule::Init()) |
| 243 // Calls to XPS APIs typically require the XPS provider to be opened with | 243 return; |
| 244 // PTOpenProvider. PTOpenProvider calls CoInitializeEx with | 244 // Calls to XPS APIs typically require the XPS provider to be opened with |
| 245 // COINIT_MULTITHREADED. We have seen certain buggy HP printer driver DLLs | 245 // PTOpenProvider. PTOpenProvider calls CoInitializeEx with |
| 246 // that call CoInitializeEx with COINIT_APARTMENTTHREADED in the context of | 246 // COINIT_MULTITHREADED. We have seen certain buggy HP printer driver DLLs |
| 247 // PTGetPrintCapabilities. This call fails but the printer driver calls | 247 // that call CoInitializeEx with COINIT_APARTMENTTHREADED in the context of |
| 248 // CoUninitialize anyway. This results in the apartment being torn down too | 248 // PTGetPrintCapabilities. This call fails but the printer driver calls |
| 249 // early and the msxml DLL being unloaded which in turn causes code in | 249 // CoUninitialize anyway. This results in the apartment being torn down too |
| 250 // unidrvui.dll to have a dangling pointer to an XML document which causes a | 250 // early and the msxml DLL being unloaded which in turn causes code in |
| 251 // crash. To protect ourselves from such drivers we make sure we always have | 251 // unidrvui.dll to have a dangling pointer to an XML document which causes a |
| 252 // an extra CoInitialize (calls to CoInitialize/CoUninitialize are | 252 // crash. To protect ourselves from such drivers we make sure we always have |
| 253 // refcounted). | 253 // an extra CoInitialize (calls to CoInitialize/CoUninitialize are |
| 254 HRESULT coinit_ret = CoInitializeEx(NULL, COINIT_MULTITHREADED); | 254 // refcounted). |
| 255 // If this succeeded we are done because the PTOpenProvider call will | 255 HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); |
| 256 // provide the extra refcount on the apartment. If it failed because someone | 256 // If this succeeded we are done because the PTOpenProvider call will provide |
| 257 // already called CoInitializeEx with COINIT_APARTMENTTHREADED, we try | 257 // the extra refcount on the apartment. If it failed because someone already |
| 258 // the other model to provide the additional refcount (since we don't know | 258 // called CoInitializeEx with COINIT_APARTMENTTHREADED, we try the other model |
| 259 // which model buggy printer drivers will use). | 259 // to provide the additional refcount (since we don't know which model buggy |
| 260 if (coinit_ret == RPC_E_CHANGED_MODE) | 260 // printer drivers will use). |
| 261 coinit_ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); | 261 if (!SUCCEEDED(hr)) |
| 262 DCHECK(SUCCEEDED(coinit_ret)); | 262 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); |
| 263 initialized_ = true; | 263 DCHECK(SUCCEEDED(hr)); |
| 264 } | 264 initialized_ = true; |
| 265 } | 265 } |
| 266 | 266 |
| 267 ScopedXPSInitializer::~ScopedXPSInitializer() { | 267 ScopedXPSInitializer::~ScopedXPSInitializer() { |
| 268 if (initialized_) | 268 if (initialized_) |
| 269 CoUninitialize(); | 269 CoUninitialize(); |
| 270 initialized_ = false; | 270 initialized_ = false; |
| 271 } | 271 } |
| 272 | 272 |
| 273 bool XPSPrintModule::Init() { | 273 bool XPSPrintModule::Init() { |
| 274 static bool initialized = InitImpl(); | 274 static bool initialized = InitImpl(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 for (size_t i = 0; i < arraysize(info); ++i) { | 370 for (size_t i = 0; i < arraysize(info); ++i) { |
| 371 std::replace(info[i].begin(), info[i].end(), ';', ','); | 371 std::replace(info[i].begin(), info[i].end(), ';', ','); |
| 372 driver_info.append(info[i]); | 372 driver_info.append(info[i]); |
| 373 if (i < arraysize(info) - 1) | 373 if (i < arraysize(info) - 1) |
| 374 driver_info.append(";"); | 374 driver_info.append(";"); |
| 375 } | 375 } |
| 376 return driver_info; | 376 return driver_info; |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace printing | 379 } // namespace printing |
| OLD | NEW |