~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/localserver/ie/file_submit_behavior.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2006, Google Inc.
 
2
//
 
3
// Redistribution and use in source and binary forms, with or without 
 
4
// modification, are permitted provided that the following conditions are met:
 
5
//
 
6
//  1. Redistributions of source code must retain the above copyright notice, 
 
7
//     this list of conditions and the following disclaimer.
 
8
//  2. Redistributions in binary form must reproduce the above copyright notice,
 
9
//     this list of conditions and the following disclaimer in the documentation
 
10
//     and/or other materials provided with the distribution.
 
11
//  3. Neither the name of Google Inc. nor the names of its contributors may be
 
12
//     used to endorse or promote products derived from this software without
 
13
//     specific prior written permission.
 
14
//
 
15
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
16
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
17
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
18
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
19
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
20
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
21
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
22
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
24
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 
 
26
#ifndef GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__
 
27
#define GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__
 
28
#ifdef OS_WINCE
 
29
// FileSubmitter is not implemented for WinCE.
 
30
#else
 
31
 
 
32
#include <windows.h>
 
33
#include "gears/base/common/string16.h"
 
34
#include "gears/base/ie/activex_utils.h"
 
35
 
 
36
 
 
37
//------------------------------------------------------------------------------
 
38
// SubmitFileBehavior
 
39
//
 
40
// A "binary behavior" used to support the submission of files in our local
 
41
// store as part of form submissions. This class exposes one property on the
 
42
// hosting HTMLElement:
 
43
//   - name, the form field name to submit with the file data
 
44
// The behavior also knows the name of the temporary file it will upload,
 
45
// which is set by its creating FileSubmitterBehaviorFactory during the
 
46
// behavior's construction.
 
47
// When a form containing an element having this behavior is submitted,
 
48
// the name / file pair is uploaded as part of the resulting POST.
 
49
//
 
50
// Caveat: The behavior does not work when attached to <input> elements which
 
51
// ironically are exactly the type of elements we wanted to augment. Apparently
 
52
// the IElementBehaviorSubmit.GetSubmitInfo method is not called when the
 
53
// hosting element is an <input> element.
 
54
//
 
55
// @see GearsFileSubmitter
 
56
//------------------------------------------------------------------------------
 
57
class ATL_NO_VTABLE SubmitFileBehavior
 
58
    : public CComObjectRootEx<CComMultiThreadModel>,
 
59
      public CComCoClass<SubmitFileBehavior>,
 
60
      public IElementBehavior,
 
61
      public IElementBehaviorSubmit,
 
62
      public IObjectSafetyImpl<SubmitFileBehavior,
 
63
                               INTERFACESAFE_FOR_UNTRUSTED_CALLER +
 
64
                               INTERFACESAFE_FOR_UNTRUSTED_DATA>,
 
65
      public IDispatchImpl<IDispatch> {
 
66
 public:
 
67
  DECLARE_NOT_AGGREGATABLE(SubmitFileBehavior)
 
68
  DECLARE_PROTECT_FINAL_CONSTRUCT()
 
69
 
 
70
  BEGIN_COM_MAP(SubmitFileBehavior)
 
71
    COM_INTERFACE_ENTRY(IDispatch)
 
72
    COM_INTERFACE_ENTRY(IObjectSafety)
 
73
    COM_INTERFACE_ENTRY(IElementBehavior)
 
74
    COM_INTERFACE_ENTRY(IElementBehaviorSubmit)
 
75
  END_COM_MAP()
 
76
 
 
77
  // IElementBehavior
 
78
  STDMETHOD(Detach)(void);
 
79
  STDMETHOD(Init)(IElementBehaviorSite *pBehaviorSite);
 
80
  STDMETHOD(Notify)(long lEvent, VARIANT *pVar);
 
81
 
 
82
  // IElementBehaviorSubmit
 
83
  STDMETHOD(GetSubmitInfo)(IHTMLSubmitData *submit_data);
 
84
  STDMETHOD(Reset)(void);
 
85
 
 
86
  // IDispatch overrides
 
87
  STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *names, UINT num_names,
 
88
                           LCID lcid, DISPID *dispid);
 
89
  STDMETHOD(Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD flags,
 
90
                    DISPPARAMS* params, VARIANT *result, EXCEPINFO *exceptinfo,
 
91
                    unsigned int *argerr);
 
92
 
 
93
  static const wchar_t *GetNamePropertyName() {
 
94
    return kName_DispName;
 
95
  }
 
96
 
 
97
  void InitFromBehaviorFactory(std::string16 &filename);
 
98
 
 
99
 private:
 
100
  // Returns the IHTMLElement we're bound to
 
101
  HRESULT GetHTMLElement(IHTMLElement **element_out) {
 
102
    ATLASSERT(behavior_site_);
 
103
    return behavior_site_->GetElement(element_out);
 
104
  }
 
105
 
 
106
  // Returns the html attribute value of the HTMLElement we're bound to.
 
107
  HRESULT GetHTMLElementAttributeValue(const wchar_t *name, VARIANT *value) {
 
108
    CComPtr<IHTMLElement> element;
 
109
    HRESULT hr = GetHTMLElement(&element);
 
110
    if (FAILED(hr)) return hr;
 
111
    return ActiveXUtils::GetHTMLElementAttributeValue(element, name, value);
 
112
  }
 
113
 
 
114
  CComBSTR name_;
 
115
  CComBSTR filename_;
 
116
  CComPtr<IElementBehaviorSite> behavior_site_;
 
117
 
 
118
  // Name and dispatch ids for the property exposed by this behavior.
 
119
  static const wchar_t *kName_DispName;
 
120
  static const DISPID kName_DispId = 1;
 
121
};
 
122
 
 
123
#endif  // OS_WINCE
 
124
#endif  // GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__