1 // Copyright (c) 2011 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.
5 #include "chrome_frame/bind_context_info.h"
6 #include "chrome_frame/utils.h"
8 // This is non const due to API expectations
9 static wchar_t* kBindContextInfo
= L
"_CHROMEFRAME_BIND_CONTEXT_INFO_";
11 // BindContextInfo member definitions.
12 BindContextInfo::BindContextInfo()
14 chrome_request_(false),
15 is_switching_(false) {
18 BindContextInfo::~BindContextInfo() {
21 HRESULT
BindContextInfo::Initialize(IBindCtx
* bind_ctx
) {
24 HRESULT hr
= CoCreateFreeThreadedMarshaler(GetUnknown(), ftm_
.Receive());
27 hr
= bind_ctx
->RegisterObjectParam(kBindContextInfo
, GetUnknown());
30 DCHECK(SUCCEEDED(hr
)) << "Failed to initialize BindContextInfo";
34 HRESULT
BindContextInfo::FromBindContext(IBindCtx
* bind_context
,
35 BindContextInfo
** info
) {
42 base::win::ScopedComPtr
<IUnknown
> context
;
43 HRESULT hr
= bind_context
->GetObjectParam(kBindContextInfo
,
46 base::win::ScopedComPtr
<IBindContextInfoInternal
> internal
;
47 hr
= internal
.QueryFrom(context
);
49 hr
= internal
->GetCppObject(reinterpret_cast<void**>(info
));
51 DLOG_IF(ERROR
, *info
!= static_cast<BindContextInfo
*>(internal
.get()))
52 << "marshalling took place!";
56 CComObject
<BindContextInfo
>* bind_context_info
= NULL
;
57 hr
= CComObject
<BindContextInfo
>::CreateInstance(&bind_context_info
);
58 DCHECK(bind_context_info
!= NULL
);
59 if (bind_context_info
) {
60 bind_context_info
->AddRef();
61 hr
= bind_context_info
->Initialize(bind_context
);
63 bind_context_info
->Release();
65 *info
= bind_context_info
;
73 void BindContextInfo::SetToSwitch(IStream
* cache
) {
81 std::wstring
BindContextInfo::GetUrl() {
82 if (has_prot_data()) {
83 return prot_data_
->url();
85 return std::wstring();