summaryrefslogtreecommitdiffstats
path: root/chrome_frame/bind_context_info.h
blob: d41c4400f801da67298c087faedc8a6241d747f3 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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.

#ifndef CHROME_FRAME_BIND_CONTEXT_INFO_
#define CHROME_FRAME_BIND_CONTEXT_INFO_

#include <atlbase.h>
#include <atlcom.h>

#include "base/scoped_bstr_win.h"
#include "base/scoped_comptr_win.h"

class __declspec(uuid("71CC3EC7-7E8A-457f-93BC-1090CF31CC18"))
IBindContextInfoInternal : public IUnknown {
 public:
  STDMETHOD(GetCppObject)(void** me) = 0;
};

// This class maintains contextual information used by ChromeFrame.
// This information is maintained in the bind context.
class BindContextInfo
  : public IBindContextInfoInternal,
    public CComObjectRoot {
 public:
  BindContextInfo();
  ~BindContextInfo();

  BEGIN_COM_MAP(BindContextInfo)
    COM_INTERFACE_ENTRY(IBindContextInfoInternal)
    COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, ftm_)
  END_COM_MAP()

  // Returns the BindContextInfo instance associated with the bind
  // context. Creates it if needed.
  static BindContextInfo* FromBindContext(IBindCtx* bind_context);

  void set_chrome_request(bool chrome_request) {
    chrome_request_ = chrome_request;
  }

  bool chrome_request() const {
    return chrome_request_;
  }

  void set_no_cache(bool no_cache) {
    no_cache_ = no_cache;
  }

  bool no_cache() const {
    return no_cache_;
  }

  bool is_switching() const {
    return is_switching_;
  }

  void SetToSwitch(IStream* cache);

  IStream* cache() {
    return cache_;
  }

  // Accept a const wchar_t* to ensure that we don't have a reference
  // to someone else's buffer.
  void set_url(const wchar_t* url) {
    DCHECK(url);
    if (url) {
      url_ = url;
    } else {
      url_.clear();
    }
  }

  const std::wstring& url() const {
    return url_;
  }

 protected:
  STDMETHOD(GetCppObject)(void** me) {
    DCHECK(me);
    *me = static_cast<BindContextInfo*>(this);
    return S_OK;
  }

  HRESULT Initialize(IBindCtx* bind_ctx);

 private:
  ScopedComPtr<IStream> cache_;
  bool no_cache_;
  bool chrome_request_;
  bool is_switching_;
  std::wstring url_;
  ScopedComPtr<IUnknown> ftm_;

  DISALLOW_COPY_AND_ASSIGN(BindContextInfo);
};

#endif  // CHROME_FRAME_BIND_CONTEXT_INFO_