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