1 // Copyright 2007, 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.
34 #include "gears/base/common/common.h"
35 #include "gears/base/common/thread_locals.h"
36 #include "gears/base/ie/activex_utils.h"
37 #include "gears/base/ie/atl_headers.h"
38 #include "gears/ui/ie/html_dialog_bridge_iemobile.h"
39 #include "gears/third_party/AtlActiveScriptSite.h"
41 // Set the permissions dialog object
42 // window.external does not work on PIE, so we use this instead...
43 // basically we get the browser object used by the permissions dialog
44 // and traverse the dom to find a PIEDialogBridge instance. If there is one,
45 // we can safely set the dialog pointer.
47 HRESULT
PIEDialogBridge::AccessPermissionsDialog() {
48 // First we get the global permissions dialog object...
49 // (permissions dialog is modal)
51 CComQIPtr
<HtmlDialogHostInterface
> permissions_dialog(
52 HtmlDialogHost::html_permissions_dialog_
);
54 if (!permissions_dialog
)
57 HtmlDialogHost
* html_dialog
= HtmlDialogHost::html_permissions_dialog_
;
58 CComPtr
<IPIEHTMLDocument2
> document(html_dialog
->document_
);
60 if (!document
) return S_FALSE
;
62 // then we retrieve all the elements in the document, and we look for us
63 CComPtr
<IPIEHTMLElementCollection
> html_collection
;
64 HRESULT hr
= document
->get_all(&html_collection
);
65 ASSERT(html_collection
);
68 hr
= html_collection
->get_length(&len
);
72 for (int i
= 0; i
< len
; i
++) {
76 index
.intVal
= static_cast<int>(i
);
78 CComPtr
<IDispatch
> disp
;
79 hr
= html_collection
->item(index
, index
, &disp
);
82 // get the current element
83 CComQIPtr
<IPIEHTMLObjectElement
> elem(disp
);
85 // if we have an object element, we check that it's a
86 // PIEDialogBridge object; we only set one object per document.
88 CComQIPtr
<PIEDialogBridgeInterface
> bridge_pointer
;
89 CComPtr
<IDispatch
> disp_object
;
90 hr
= elem
->get_object(&disp_object
);
91 bridge_pointer
= disp_object
;
93 bridge_pointer
->SetDialog(permissions_dialog
);
102 HRESULT
PIEDialogBridge::SetDialog(IDispatch
* dialog
) {
114 HRESULT
PIEDialogBridge::IsPocketIE(VARIANT_BOOL
*retval
) {
116 AccessPermissionsDialog();
119 return dialog_
->IsPocketIE(retval
);
124 HRESULT
PIEDialogBridge::GetDialogArguments(BSTR
*args_string
) {
126 AccessPermissionsDialog();
129 HRESULT hr
= dialog_
->GetDialogArguments(args_string
);
135 HRESULT
PIEDialogBridge::CloseDialog(const BSTR result_string
) {
137 AccessPermissionsDialog();
140 return dialog_
->CloseDialog(result_string
);