summaryrefslogtreecommitdiffstats
path: root/chrome_frame/bind_context_info.cc
blob: 3eb2554495ceddc56fa724cb9e9396b3c7699cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/bind_context_info.h"
#include "chrome_frame/utils.h"

// This is non const due to API expectations
static wchar_t* kBindContextInfo = L"_CHROMEFRAME_BIND_CONTEXT_INFO_";

// BindContextInfo member definitions.
BindContextInfo::BindContextInfo()
    : no_cache_(false),
      chrome_request_(false),
      is_switching_(false) {
}

BindContextInfo* BindContextInfo::FromBindContext(IBindCtx* bind_context) {
  if (!bind_context) {
    NOTREACHED();
    return NULL;
  }

  ScopedComPtr<IUnknown> context;
  bind_context->GetObjectParam(kBindContextInfo, context.Receive());
  if (context) {
    return static_cast<BindContextInfo*>(context.get());
  }

  CComObject<BindContextInfo>* bind_context_info = NULL;
  CComObject<BindContextInfo>::CreateInstance(&bind_context_info);
  DCHECK(bind_context_info != NULL);

  bind_context->RegisterObjectParam(kBindContextInfo, bind_context_info);
  return bind_context_info;
}

void BindContextInfo::SetToSwitch(IStream* cache) {
  is_switching_ = true;
  if  (!no_cache_) {
    cache_ = cache;
    RewindStream(cache_);
  }
}