1
// Copyright 2006, Google Inc.
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are met:
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.
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.
26
#ifndef GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__
27
#define GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__
29
// FileSubmitter is not implemented for WinCE.
33
#include "gears/base/common/string16.h"
34
#include "gears/base/ie/activex_utils.h"
37
//------------------------------------------------------------------------------
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.
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.
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> {
67
DECLARE_NOT_AGGREGATABLE(SubmitFileBehavior)
68
DECLARE_PROTECT_FINAL_CONSTRUCT()
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)
78
STDMETHOD(Detach)(void);
79
STDMETHOD(Init)(IElementBehaviorSite *pBehaviorSite);
80
STDMETHOD(Notify)(long lEvent, VARIANT *pVar);
82
// IElementBehaviorSubmit
83
STDMETHOD(GetSubmitInfo)(IHTMLSubmitData *submit_data);
84
STDMETHOD(Reset)(void);
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);
93
static const wchar_t *GetNamePropertyName() {
94
return kName_DispName;
97
void InitFromBehaviorFactory(std::string16 &filename);
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);
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);
116
CComPtr<IElementBehaviorSite> behavior_site_;
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;
124
#endif // GEARS_LOCALSERVER_IE_FILE_SUBMIT_BEHAVIOR_H__