summaryrefslogtreecommitdiffstats
path: root/chrome_frame/urlmon_moniker_base.h
blob: 6dd022ce5233da907ab986c03493fbd08ed69ca5 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// 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_URLMON_MONIKER_BASE_H_
#define CHROME_FRAME_URLMON_MONIKER_BASE_H_

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

// An implementation of IStream (minus IUnknown) that delegates to
// another source.  Most of the methods contain a NOTREACHED() as the
// class is used by the ReadStreamCache class where we don't expect those
// calls under normal circumstances.
class DelegatingReadStream : public IStream {
 public:
  DelegatingReadStream() {
  }

  ~DelegatingReadStream() {
  }

  void SetDelegate(IStream* delegate) {
    delegate_ = delegate;
  }

  // ISequentialStream.
  STDMETHOD(Read)(void* pv, ULONG cb, ULONG* read) {
    return delegate_->Read(pv, cb, read);
  }

  STDMETHOD(Write)(const void* pv, ULONG cb, ULONG* written) {
    NOTREACHED();
    return delegate_->Write(pv, cb, written);
  }

  // IStream.
  STDMETHOD(Seek)(LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER* new_pos) {
    NOTREACHED();
    return delegate_->Seek(move, origin, new_pos);
  }

  STDMETHOD(SetSize)(ULARGE_INTEGER new_size) {
    NOTREACHED();
    return delegate_->SetSize(new_size);
  }

  STDMETHOD(CopyTo)(IStream* stream, ULARGE_INTEGER cb, ULARGE_INTEGER* read,
                    ULARGE_INTEGER* written) {
    NOTREACHED();
    return delegate_->CopyTo(stream, cb, read, written);
  }

  STDMETHOD(Commit)(DWORD commit_flags) {
    NOTREACHED();
    return delegate_->Commit(commit_flags);
  }

  STDMETHOD(Revert)() {
    NOTREACHED();
    return delegate_->Revert();
  }

  STDMETHOD(LockRegion)(ULARGE_INTEGER offset, ULARGE_INTEGER cb,
                        DWORD lock_type) {
    NOTREACHED();
    return delegate_->LockRegion(offset, cb, lock_type);
  }

  STDMETHOD(UnlockRegion)(ULARGE_INTEGER offset, ULARGE_INTEGER cb,
                          DWORD lock_type) {
    NOTREACHED();
    return delegate_->UnlockRegion(offset, cb, lock_type);
  }

  STDMETHOD(Stat)(STATSTG* stat_stg, DWORD stat_flag) {
    DCHECK(delegate_);
    return delegate_->Stat(stat_stg, stat_flag);
  }

  STDMETHOD(Clone)(IStream** stream) {
    NOTREACHED();
    return delegate_->Clone(stream);
  }

 protected:
  ScopedComPtr<IStream> delegate_;
};

// A very basic implementation of IBinding that forwards all calls
// to a delegate.
class DelegatingBinding : public IBinding {
 public:
  DelegatingBinding() {
  }

  ~DelegatingBinding() {
  }

  IBinding* delegate() const {
    return delegate_;
  }

  void SetDelegate(IBinding* delegate) {
    delegate_ = delegate;
  }

  STDMETHOD(Abort)() {
    DCHECK(delegate_);
    if (!delegate_)
      return S_OK;
    return delegate_->Abort();
  }

  STDMETHOD(Suspend)() {
    DCHECK(delegate_);
    if (!delegate_)
      return E_FAIL;
    return delegate_->Suspend();
  }

  STDMETHOD(Resume)() {
    DCHECK(delegate_);
    if (!delegate_)
      return E_FAIL;
    return delegate_->Resume();
  }

  STDMETHOD(SetPriority)(LONG priority) {
    DCHECK(delegate_);
    if (!delegate_)
      return E_FAIL;
    return delegate_->SetPriority(priority);
  }

  STDMETHOD(GetPriority)(LONG* priority) {
    DCHECK(delegate_);
    if (!delegate_)
      return E_FAIL;
    return delegate_->GetPriority(priority);
  }

  STDMETHOD(GetBindResult)(CLSID* protocol, DWORD* result_code,
                           LPOLESTR* result, DWORD* reserved) {
    DCHECK(delegate_);
    if (!delegate_)
      return E_FAIL;
    return delegate_->GetBindResult(protocol, result_code, result, reserved);
  }

 protected:
  ScopedComPtr<IBinding> delegate_;
};

#endif  // CHROME_FRAME_URLMON_MONIKER_BASE_H_