What's new? | Help | Directory | Sign in
Google
             
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2006, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// A collection of static utility methods.

#ifndef GEARS_BASE_IE_ACTIVEX_UTILS_H__
#define GEARS_BASE_IE_ACTIVEX_UTILS_H__

#include <vector>
#include "gears/base/common/scoped_refptr.h"
#include "gears/base/common/string16.h"
#include "gears/base/ie/atl_headers.h"

struct IHTMLElement;
class BrowsingContext;
class SecurityOrigin;

#ifdef WINCE
struct IWebBrowser2;
struct IPIEHTMLDocument;
struct IPIEHTMLDocument2;
struct IPIEHTMLWindow2;
typedef IPIEHTMLDocument IHTMLDocument;
typedef IPIEHTMLDocument2 IHTMLDocument2;
// WinMo 5 SDK defines IHTMLWindow2, so we can't typedef IPIEHTMLWindow2.
#endif

class ActiveXUtils {
public:
// Returns the location url of the containing webBrowser as determined by
// IWebBrowser2.LocationURL.
// TODO(cprince): across the codebase, change PageOrigin to PageSecurityOrigin
// and PageLocation to PageLocationUrl, for consistency.
static bool GetPageLocation(IUnknown *site, std::string16 *page_location_url);
static bool GetPageOrigin(IUnknown *site, SecurityOrigin *security_origin);

// Returns the page's browsing context.
// Returns true on success.
static bool GetPageBrowsingContext(
IUnknown *site, scoped_refptr<BrowsingContext> *browsing_context);

#ifdef WINCE
// We're not able to get IWebBrowser2 on WinCE. Instead we obtain the window
// and document objects from the script engine's IDispatch pointer.
#else
// Returns the IWebBrowser2 interface corresponding to the given site.
static HRESULT GetWebBrowser2(IUnknown *site,
IWebBrowser2 **browser2);
#endif

// Returns the IHTMLDocument2 interface corresponding to the given site.
static HRESULT GetHtmlDocument2(IUnknown *site,
IHTMLDocument2 **document2);

// Returns the IHTMLWindow2 interface corresponding to the given site.
static HRESULT GetHtmlWindow2(IUnknown *site,
#ifdef WINCE
IPIEHTMLWindow2 **window2);
#else
IHTMLWindow2 **window2);
#endif

#ifdef WINCE
// WinCE does not provide I(PIE)HTMLWindow3, but we do not need it.
#else
// Returns the IHTMLWindow3 interface corresponding to the given site.
// Can be used with our HtmlEventMonitor.
static HRESULT GetHtmlWindow3(IUnknown *site,
IHTMLWindow3 **window3);
#endif

// Returns the IDispatch interface for the script engine at the given site.
// TODO(zork): Remove dump_on_error.
static HRESULT GetScriptDispatch(IUnknown *site,
IDispatch **script_dispatch,
bool dump_on_error = false);

// Returns the dispatch id of the named member.
static HRESULT GetDispatchMemberId(IDispatch *dispatch, const WCHAR *name,
DISPID *dispid) {
*dispid = DISPID_UNKNOWN;
return dispatch->GetIDsOfNames(IID_NULL, const_cast<WCHAR**>(&name), 1, 0,
dispid);
}

// Appends to the vector out the names of dispatch's properties.
static HRESULT GetDispatchPropertyNames(IDispatch *dispatch,
std::vector<std::string16> *out);

// Returns the property value by name.
// The caller is responsible for freeing the returned VARIANT.
static HRESULT GetDispatchProperty(IDispatch *dispatch, const WCHAR *name,
VARIANT *value) {
DISPID dispid;
HRESULT hr = GetDispatchMemberId(dispatch, name, &dispid);
if (FAILED(hr)) return hr;
return GetDispatchProperty(dispatch, dispid, value);
}

// Returns the property value by dispid.
// The caller is responsible for freeing the returned VARIANT.
static HRESULT GetDispatchProperty(IDispatch *dispatch, DISPID dispid,
VARIANT *value);

// Sets the property value by name.
static HRESULT SetDispatchProperty(IDispatch *dispatch, const WCHAR *name,
const VARIANT *value) {
DISPID dispid;
HRESULT hr = GetDispatchMemberId(dispatch, name, &dispid);
if (FAILED(hr)) return hr;
return SetDispatchProperty(dispatch, dispid, value);
}

// Sets the property value by dispid.
static HRESULT SetDispatchProperty(IDispatch *dispatch, DISPID dispid,
const VARIANT *value);

// Adds a new property to object.
// If the property already exists then it is returned.
// Parameters:
// dispatch - in - the properties are added to this object
// name - in - the case sensitive name of the property
// dispid - out - the identifier for the property
static HRESULT AddDispatchProperty(IDispatch* dispatch, const char16* name,
DISPID* dispid);

// Convenience function for calling AddDispatchProperty
// and then SetDispathProperty.
static HRESULT AddAndSetDispatchProperty(IDispatch* dispatch,
const char16* name,
const VARIANT* value);

#ifdef WINCE
// TODO(andreip): implement on Windows Mobile.
#else
// Returns the html attribute value of the given HTMLElement.
// The caller is responsible for freeing the returned VARIANT.
static HRESULT GetHTMLElementAttributeValue(IHTMLElement *element,
const WCHAR *name,
VARIANT *value);
#endif

// Convert NULL BSTR to the empty string.
static const CComBSTR kEmptyBSTR;
static const BSTR SafeBSTR(const BSTR value) {
return value ? value : kEmptyBSTR.m_str;
}
// Returns true if there the browser is in 'online' mode and the local
// system is connected to a network.
static bool IsOnline();
};


#endif // GEARS_BASE_IE_ACTIVEX_UTILS_H__
Show details Hide details

Change log

r2684 by gears.daemon on Aug 11, 2008   Diff
[Author: nigeltao]

Remove unused ActiveXUtils functions.
Presumably, these functions
became unused when there were no longer
any pure-COM modules (as
opposed to Dispatcher-backed modules).

R=cprince
CC=gears-eng@googlegroups.com
APPROVED=cprince
DELTA=21  (0 added, 21 deleted, 0 changed)
...
Go to: 
Project members, sign in to write a code review

Older revisions

r2321 by gears.daemon on Jul 10, 2008   Diff
[Author: nigeltao]

Remove JsParamFetcher, as it is no
longer used, as well as its
support member variables in
...
r1814 by gears.daemon on May 30, 2008   Diff
[Author: mpcomplete]

Add BrowsingContext to associate with
network requests.

...
r1278 by gears.daemon on Apr 01, 2008   Diff
[Author: nigeltao]

Worker messages can now be JSON
objects (more or less), not just
strings.  For more details, see the
...
All revisions of this file

File info

Size: 7332 bytes, 176 lines