| 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 #include "chrome_frame/bind_context_info.h" | 5 #include "chrome_frame/bind_context_info.h" |
| 6 #include "chrome_frame/utils.h" | 6 #include "chrome_frame/utils.h" |
| 7 | 7 |
| 8 // This is non const due to API expectations | 8 // This is non const due to API expectations |
| 9 static wchar_t* kBindContextInfo = L"_CHROMEFRAME_BIND_CONTEXT_INFO_"; | 9 static wchar_t* kBindContextInfo = L"_CHROMEFRAME_BIND_CONTEXT_INFO_"; |
| 10 | 10 |
| 11 // BindContextInfo member definitions. | 11 // BindContextInfo member definitions. |
| 12 BindContextInfo::BindContextInfo() | 12 BindContextInfo::BindContextInfo() |
| 13 : no_cache_(false), | 13 : no_cache_(false), |
| 14 chrome_request_(false), | 14 chrome_request_(false), |
| 15 is_switching_(false) { | 15 is_switching_(false) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 BindContextInfo::~BindContextInfo() { |
| 19 } |
| 20 |
| 18 BindContextInfo* BindContextInfo::FromBindContext(IBindCtx* bind_context) { | 21 BindContextInfo* BindContextInfo::FromBindContext(IBindCtx* bind_context) { |
| 19 if (!bind_context) { | 22 if (!bind_context) { |
| 20 NOTREACHED(); | 23 NOTREACHED(); |
| 21 return NULL; | 24 return NULL; |
| 22 } | 25 } |
| 23 | 26 |
| 24 ScopedComPtr<IUnknown> context; | 27 ScopedComPtr<IUnknown> context; |
| 25 bind_context->GetObjectParam(kBindContextInfo, context.Receive()); | 28 bind_context->GetObjectParam(kBindContextInfo, context.Receive()); |
| 26 if (context) { | 29 if (context) { |
| 27 return static_cast<BindContextInfo*>(context.get()); | 30 ScopedComPtr<IBindContextInfoInternal> internal; |
| 31 HRESULT hr = internal.QueryFrom(context); |
| 32 DCHECK(SUCCEEDED(hr)); |
| 33 if (SUCCEEDED(hr)) { |
| 34 BindContextInfo* ret = NULL; |
| 35 internal->GetCppObject(reinterpret_cast<void**>(&ret)); |
| 36 DCHECK(ret); |
| 37 DLOG_IF(WARNING, reinterpret_cast<void*>(ret) != |
| 38 reinterpret_cast<void*>(internal.get())) |
| 39 << "marshalling took place!"; |
| 40 return ret; |
| 41 } |
| 28 } | 42 } |
| 29 | 43 |
| 30 CComObject<BindContextInfo>* bind_context_info = NULL; | 44 CComObject<BindContextInfo>* bind_context_info = NULL; |
| 31 CComObject<BindContextInfo>::CreateInstance(&bind_context_info); | 45 HRESULT hr = CComObject<BindContextInfo>::CreateInstance(&bind_context_info); |
| 32 DCHECK(bind_context_info != NULL); | 46 DCHECK(bind_context_info != NULL); |
| 47 if (bind_context_info) { |
| 48 bind_context_info->AddRef(); |
| 49 hr = CoCreateFreeThreadedMarshaler(bind_context_info->GetUnknown(), |
| 50 bind_context_info->ftm_.Receive()); |
| 51 DCHECK(bind_context_info->ftm_); |
| 52 if (SUCCEEDED(hr)) { |
| 53 hr = bind_context->RegisterObjectParam(kBindContextInfo, |
| 54 bind_context_info); |
| 55 } |
| 33 | 56 |
| 34 bind_context->RegisterObjectParam(kBindContextInfo, bind_context_info); | 57 DCHECK(SUCCEEDED(hr)) << "Failed to initialize BindContextInfo"; |
| 58 bind_context_info->Release(); |
| 59 if (FAILED(hr)) |
| 60 bind_context_info = NULL; |
| 61 } |
| 62 |
| 35 return bind_context_info; | 63 return bind_context_info; |
| 36 } | 64 } |
| 37 | 65 |
| 38 void BindContextInfo::SetToSwitch(IStream* cache) { | 66 void BindContextInfo::SetToSwitch(IStream* cache) { |
| 39 is_switching_ = true; | 67 is_switching_ = true; |
| 40 if (!no_cache_) { | 68 if (!no_cache_) { |
| 41 cache_ = cache; | 69 cache_ = cache; |
| 42 RewindStream(cache_); | 70 RewindStream(cache_); |
| 43 } | 71 } |
| 44 } | 72 } |
| 45 | 73 |
| OLD | NEW |