Home | History | Annotate | Download | only in chrome_frame
      1 // Copyright (c) 2011 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 #ifndef CHROME_FRAME_BIND_CONTEXT_INFO_H_
      6 #define CHROME_FRAME_BIND_CONTEXT_INFO_H_
      7 
      8 #include <atlbase.h>
      9 #include <atlcom.h>
     10 
     11 #include "base/win/scoped_comptr.h"
     12 #include "chrome_frame/protocol_sink_wrap.h"
     13 
     14 class __declspec(uuid("71CC3EC7-7E8A-457f-93BC-1090CF31CC18"))
     15 IBindContextInfoInternal : public IUnknown {
     16  public:
     17   STDMETHOD(GetCppObject)(void** me) = 0;
     18 };
     19 
     20 // This class maintains contextual information used by ChromeFrame.
     21 // This information is maintained in the bind context.
     22 // Association with GUID_NULL is for convenience.
     23 class __declspec(uuid("00000000-0000-0000-0000-000000000000")) BindContextInfo
     24   : public CComObjectRootEx<CComMultiThreadModel>,
     25     public IBindContextInfoInternal {
     26  public:
     27   BindContextInfo();
     28   ~BindContextInfo();
     29 
     30   BEGIN_COM_MAP(BindContextInfo)
     31     COM_INTERFACE_ENTRY(IBindContextInfoInternal)
     32     COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, ftm_)
     33   END_COM_MAP()
     34 
     35   // Returns the BindContextInfo instance associated with the bind
     36   // context. Creates it if needed.
     37   // The returned info object will be AddRef-ed on return, so use
     38   // base::win::ScopedComPtr<>::Receive() to receive this pointer.
     39   static HRESULT FromBindContext(IBindCtx* bind_context,
     40                                  BindContextInfo** info);
     41 
     42   void set_chrome_request(bool chrome_request) {
     43     chrome_request_ = chrome_request;
     44   }
     45 
     46   bool chrome_request() const {
     47     return chrome_request_;
     48   }
     49 
     50   void set_no_cache(bool no_cache) {
     51     no_cache_ = no_cache;
     52   }
     53 
     54   bool no_cache() const {
     55     return no_cache_;
     56   }
     57 
     58   bool is_switching() const {
     59     return is_switching_;
     60   }
     61 
     62   void SetToSwitch(IStream* cache);
     63 
     64   IStream* cache() {
     65     return cache_;
     66   }
     67 
     68   void set_prot_data(ProtData* data) {
     69     prot_data_ = data;
     70   }
     71 
     72   scoped_refptr<ProtData> get_prot_data() {
     73     return prot_data_;
     74   }
     75 
     76   bool has_prot_data() const {
     77     return prot_data_.get() != NULL;
     78   }
     79 
     80   void set_protocol(IInternetProtocol* protocol) {
     81     protocol_ = protocol;
     82   }
     83 
     84   IInternetProtocol* protocol() {
     85     return protocol_.get();
     86   }
     87 
     88   // Returns the url being navigated to. We retrieve the url from the ProtData
     89   // instance which wraps the underlying protocol sink.
     90   std::wstring GetUrl();
     91 
     92  protected:
     93   STDMETHOD(GetCppObject)(void** me) {
     94     DCHECK(me);
     95     AddRef();
     96     *me = static_cast<BindContextInfo*>(this);
     97     return S_OK;
     98   }
     99 
    100   HRESULT Initialize(IBindCtx* bind_ctx);
    101 
    102  private:
    103   base::win::ScopedComPtr<IStream> cache_;
    104   bool no_cache_;
    105   bool chrome_request_;
    106   bool is_switching_;
    107   base::win::ScopedComPtr<IUnknown> ftm_;
    108   scoped_refptr<ProtData> prot_data_;
    109   base::win::ScopedComPtr<IInternetProtocol> protocol_;
    110 
    111   DISALLOW_COPY_AND_ASSIGN(BindContextInfo);
    112 };
    113 
    114 #endif  // CHROME_FRAME_BIND_CONTEXT_INFO_H_
    115