blob: fdc6c8d476f28340f3ef4385f4dd2c49d6b9f2aa [file] [log] [blame]
[email protected]70277f62010-04-15 01:39:261// 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
9static wchar_t* kBindContextInfo = L"_CHROMEFRAME_BIND_CONTEXT_INFO_";
10
11// BindContextInfo member definitions.
12BindContextInfo::BindContextInfo()
13 : no_cache_(false),
14 chrome_request_(false),
15 is_switching_(false) {
16}
17
[email protected]25299f22010-05-13 17:46:4318BindContextInfo::~BindContextInfo() {
19}
20
21HRESULT 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]77d7aee2010-05-14 20:31:5534HRESULT BindContextInfo::FromBindContext(IBindCtx* bind_context,
35 BindContextInfo** info) {
36 DCHECK(info);
[email protected]70277f62010-04-15 01:39:2637 if (!bind_context) {
38 NOTREACHED();
[email protected]77d7aee2010-05-14 20:31:5539 return E_POINTER;
[email protected]70277f62010-04-15 01:39:2640 }
41
42 ScopedComPtr<IUnknown> context;
[email protected]77d7aee2010-05-14 20:31:5543 HRESULT hr = bind_context->GetObjectParam(kBindContextInfo,
44 context.Receive());
[email protected]70277f62010-04-15 01:39:2645 if (context) {
[email protected]25299f22010-05-13 17:46:4346 ScopedComPtr<IBindContextInfoInternal> internal;
[email protected]77d7aee2010-05-14 20:31:5547 hr = internal.QueryFrom(context);
[email protected]25299f22010-05-13 17:46:4348 DCHECK(SUCCEEDED(hr));
49 if (SUCCEEDED(hr)) {
50 BindContextInfo* ret = NULL;
[email protected]77d7aee2010-05-14 20:31:5551 hr = internal->GetCppObject(reinterpret_cast<void**>(info));
52 DCHECK_EQ(hr, S_OK);
[email protected]25299f22010-05-13 17:46:4353 DLOG_IF(ERROR, reinterpret_cast<void*>(ret) !=
54 reinterpret_cast<void*>(internal.get()))
55 << "marshalling took place!";
[email protected]77d7aee2010-05-14 20:31:5556 }
57 } else {
58 DCHECK(FAILED(hr));
59 CComObject<BindContextInfo>* bind_context_info = NULL;
60 hr = CComObject<BindContextInfo>::CreateInstance(&bind_context_info);
61 DCHECK(bind_context_info != NULL);
62 if (bind_context_info) {
63 bind_context_info->AddRef();
64 hr = bind_context_info->Initialize(bind_context);
65 if (FAILED(hr)) {
66 bind_context_info->Release();
67 } else {
68 *info = bind_context_info;
69 }
[email protected]25299f22010-05-13 17:46:4370 }
[email protected]70277f62010-04-15 01:39:2671 }
72
[email protected]77d7aee2010-05-14 20:31:5573 return hr;
[email protected]70277f62010-04-15 01:39:2674}
75
76void BindContextInfo::SetToSwitch(IStream* cache) {
77 is_switching_ = true;
78 if (!no_cache_) {
79 cache_ = cache;
80 RewindStream(cache_);
81 }
82}
83