[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 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] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 34 | HRESULT BindContextInfo::FromBindContext(IBindCtx* bind_context, |
35 | BindContextInfo** info) { | ||||
36 | DCHECK(info); | ||||
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 37 | if (!bind_context) { |
38 | NOTREACHED(); | ||||
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 39 | return E_POINTER; |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 40 | } |
41 | |||||
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 42 | base::win::ScopedComPtr<IUnknown> context; |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 43 | HRESULT hr = bind_context->GetObjectParam(kBindContextInfo, |
44 | context.Receive()); | ||||
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 45 | if (context) { |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 46 | base::win::ScopedComPtr<IBindContextInfoInternal> internal; |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 47 | hr = internal.QueryFrom(context); |
[email protected] | 25299f2 | 2010-05-13 17:46:43 | [diff] [blame] | 48 | if (SUCCEEDED(hr)) { |
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 49 | hr = internal->GetCppObject(reinterpret_cast<void**>(info)); |
50 | DCHECK_EQ(hr, S_OK); | ||||
[email protected] | 5ae94d2 | 2010-07-21 19:55:36 | [diff] [blame] | 51 | DLOG_IF(ERROR, *info != static_cast<BindContextInfo*>(internal.get())) |
52 | << "marshalling took place!"; | ||||
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 53 | } |
54 | } else { | ||||
55 | DCHECK(FAILED(hr)); | ||||
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); | ||||
62 | if (FAILED(hr)) { | ||||
63 | bind_context_info->Release(); | ||||
64 | } else { | ||||
65 | *info = bind_context_info; | ||||
66 | } | ||||
[email protected] | 25299f2 | 2010-05-13 17:46:43 | [diff] [blame] | 67 | } |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 68 | } |
69 | |||||
[email protected] | 77d7aee | 2010-05-14 20:31:55 | [diff] [blame] | 70 | return hr; |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 71 | } |
72 | |||||
73 | void BindContextInfo::SetToSwitch(IStream* cache) { | ||||
74 | is_switching_ = true; | ||||
75 | if (!no_cache_) { | ||||
76 | cache_ = cache; | ||||
77 | RewindStream(cache_); | ||||
78 | } | ||||
79 | } | ||||
80 | |||||
[email protected] | 4f45d458 | 2011-02-22 23:27:27 | [diff] [blame] | 81 | std::wstring BindContextInfo::GetUrl() { |
82 | if (has_prot_data()) { | ||||
83 | return prot_data_->url(); | ||||
84 | } | ||||
85 | return std::wstring(); | ||||
86 | } | ||||
87 |