1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Adam Lock <adamlock@eircom.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef IWEBBROWSERIMPL_H
40 #define IWEBBROWSERIMPL_H
44 #include "nsIWebNavigation.h"
45 #include "nsIPrefBranch.h"
46 #include "nsIPrefLocalizedString.h"
47 #include "nsIDOMWindow.h"
48 #include "nsIBaseWindow.h"
49 #include "nsIWindowWatcher.h"
50 #include "nsIInputStream.h"
51 #include "nsIStringStream.h"
53 #include "nsComponentManagerUtils.h"
54 #include "nsServiceManagerUtils.h"
56 #include "PropertyList.h"
58 // CPMozillaControl.h was autogenerated by the ATL proxy wizard so don't edit it!
59 #include "CPMozillaControl.h"
61 #define ENSURE_BROWSER_IS_VALID() \
62 if (!BrowserIsValid()) \
64 NS_ASSERTION(0, "Browser is not valid"); \
65 return SetErrorInfo(E_UNEXPECTED, L"Browser is not in a valid state"); \
68 #define ENSURE_GET_WEBNAV() \
69 nsCOMPtr<nsIWebNavigation> webNav; \
70 nsresult rv = GetWebNavigation(getter_AddRefs(webNav)); \
73 NS_ASSERTION(0, "Cannot get nsIWebNavigation"); \
74 return SetErrorInfo(E_UNEXPECTED, L"Could not obtain nsIWebNavigation interface"); \
77 template<class T
, const CLSID
*pclsid
, const GUID
* plibid
= &LIBID_MSHTML
>
78 class IWebBrowserImpl
:
79 public CStockPropImpl
<T
, IWebBrowser2
, &IID_IWebBrowser2
, plibid
>,
80 public CProxyDWebBrowserEvents
<T
>,
81 public CProxyDWebBrowserEvents2
<T
>
86 // Ready state of control
87 mBrowserReadyState
= READYSTATE_UNINITIALIZED
;
88 // Flag indicates if the browser is busy
93 // Methods to be implemented by the derived class
94 // Return the nsIWebNavigation object
95 virtual nsresult
GetWebNavigation(nsIWebNavigation
**aWebNav
) = 0;
96 // Return the nsIDOMWindow object
97 virtual nsresult
GetDOMWindow(nsIDOMWindow
**aDOMWindow
) = 0;
98 // Return the nsIPrefBranch object
99 virtual nsresult
GetPrefs(nsIPrefBranch
**aPrefBranch
) = 0;
100 // Return the valid state of the browser
101 virtual PRBool
BrowserIsValid() = 0;
104 // Properties related to this interface
105 // Post data from last navigate operation
106 CComVariant mLastPostData
;
107 // Ready status of the browser
108 READYSTATE mBrowserReadyState
;
109 // Controls starts off unbusy
112 PropertyList mPropertyList
;
117 // Sets error information for VB programmers and the like who want to know why
118 // some method call failed.
120 virtual HRESULT
SetErrorInfo(HRESULT hr
, LPCOLESTR lpszDesc
= NULL
)
122 if (lpszDesc
== NULL
)
124 // Fill in a few generic descriptions
128 lpszDesc
= L
"Method was called while control was uninitialized";
131 lpszDesc
= L
"Method was called with an invalid parameter";
135 AtlSetErrorInfo(*pclsid
, lpszDesc
, 0, NULL
, GUID_NULL
, hr
, NULL
);
140 // IWebBrowser implementation
141 virtual HRESULT STDMETHODCALLTYPE
GoBack(void)
143 ATLTRACE(_T("IWebBrowserImpl::GoBack()\n"));
144 ENSURE_BROWSER_IS_VALID();
147 PRBool aCanGoBack
= PR_FALSE
;
148 webNav
->GetCanGoBack(&aCanGoBack
);
149 if (aCanGoBack
== PR_TRUE
)
156 virtual HRESULT STDMETHODCALLTYPE
GoForward(void)
158 ATLTRACE(_T("IWebBrowserImpl::GoBack()\n"));
159 ENSURE_BROWSER_IS_VALID();
162 PRBool aCanGoForward
= PR_FALSE
;
163 webNav
->GetCanGoForward(&aCanGoForward
);
164 if (aCanGoForward
== PR_TRUE
)
171 virtual HRESULT STDMETHODCALLTYPE
GoHome(void)
173 ATLTRACE(_T("IWebBrowserImpl::GoHome()\n"));
174 ENSURE_BROWSER_IS_VALID();
176 CComBSTR
bstrUrl(L
"http://home.netscape.com/");
178 // Find the home page stored in prefs
179 nsCOMPtr
<nsIPrefBranch
> prefBranch
;
180 if (NS_SUCCEEDED(GetPrefs(getter_AddRefs(prefBranch
))))
182 nsCOMPtr
<nsIPrefLocalizedString
> homePage
;
183 prefBranch
->GetComplexValue("browser.startup.homepage",
184 NS_GET_IID(nsIPrefLocalizedString
),
185 getter_AddRefs(homePage
));
189 nsString homePageString
;
190 nsresult rv
= homePage
->ToString(getter_Copies(homePageString
));
191 if (NS_SUCCEEDED(rv
))
193 bstrUrl
= homePageString
.get();
198 // Navigate to the home page
199 Navigate(bstrUrl
, NULL
, NULL
, NULL
, NULL
);
203 virtual HRESULT STDMETHODCALLTYPE
GoSearch(void)
205 ATLTRACE(_T("IWebBrowserImpl::GoSearch()\n"));
206 ENSURE_BROWSER_IS_VALID();
208 CComBSTR
bstrUrl(L
"http://search.netscape.com/");
210 //NOTE: This code has not been implemented yet
212 // Find the home page stored in prefs
213 nsCOMPtr
<nsIPrefBranch
> prefBranch
;
214 if (NS_SUCCEEDED(GetPrefs(getter_AddRefs(prefBranch
))))
216 // TODO find and navigate to the search page stored in prefs
217 // and not this hard coded address
220 // Navigate to the search page
221 Navigate(bstrUrl
, NULL
, NULL
, NULL
, NULL
);
226 virtual HRESULT STDMETHODCALLTYPE
Navigate(BSTR URL
, VARIANT __RPC_FAR
*Flags
, VARIANT __RPC_FAR
*TargetFrameName
, VARIANT __RPC_FAR
*PostData
, VARIANT __RPC_FAR
*Headers
)
228 ATLTRACE(_T("IWebBrowserImpl::Navigate()\n"));
229 ENSURE_BROWSER_IS_VALID();
233 // Extract the URL parameter
236 NS_ASSERTION(0, "No URL supplied");
237 return SetErrorInfo(E_INVALIDARG
);
240 PRBool openInNewWindow
= PR_FALSE
;
241 PRUint32 loadFlags
= nsIWebNavigation::LOAD_FLAGS_NONE
;
243 // Extract the navigate flags parameter
246 Flags
->vt
!= VT_ERROR
&&
247 Flags
->vt
!= VT_EMPTY
&&
248 Flags
->vt
!= VT_NULL
)
251 if ( vFlags
.ChangeType(VT_I4
, Flags
) != S_OK
)
253 NS_ASSERTION(0, "Flags param is invalid");
254 return SetErrorInfo(E_INVALIDARG
);
256 lFlags
= vFlags
.lVal
;
258 if (lFlags
& navOpenInNewWindow
)
260 openInNewWindow
= PR_TRUE
;
262 if (lFlags
& navNoHistory
)
265 loadFlags
|= nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY
;
267 if (lFlags
& navNoReadFromCache
)
269 // Disable read from cache
270 loadFlags
|= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE
;
273 if (lFlags
& navNoWriteToCache
)
275 // Disable write to cache
276 loadFlags
|= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE
;
279 // Extract the target frame parameter
280 nsCOMPtr
<nsIWebNavigation
> targetNav
;
281 if (TargetFrameName
&&
282 TargetFrameName
->vt
== VT_BSTR
&&
283 TargetFrameName
->bstrVal
)
285 // Search for the named frame
286 nsCOMPtr
<nsIDOMWindow
> window
;
287 GetDOMWindow(getter_AddRefs(window
));
290 nsCOMPtr
<nsIWindowWatcher
> windowWatcher
= do_GetService(NS_WINDOWWATCHER_CONTRACTID
);
293 nsCOMPtr
<nsIDOMWindow
> targetWindow
;
294 windowWatcher
->GetWindowByName(TargetFrameName
->bstrVal
, window
,
295 getter_AddRefs(targetWindow
));
298 targetNav
= do_GetInterface(targetWindow
);
302 // No target nav? Open in new window
304 openInNewWindow
= PR_TRUE
;
307 // Open in new window
310 CComQIPtr
<IDispatch
> spDispNew
;
311 VARIANT_BOOL bCancel
= VARIANT_FALSE
;
313 // Test if the event sink can give us a new window to navigate into
314 Fire_NewWindow2(&spDispNew
, &bCancel
);
316 lFlags
&= ~(navOpenInNewWindow
);
317 if ((bCancel
== VARIANT_FALSE
) && spDispNew
)
319 CComQIPtr
<IWebBrowser2
> spOther
= spDispNew
;
322 CComVariant
vURL(URL
);
323 CComVariant
vFlags(lFlags
);
324 return spOther
->Navigate2(&vURL
, &vFlags
, TargetFrameName
, PostData
, Headers
);
328 // NOTE: The IE control will launch an instance of iexplore.exe and
329 // return an interface to that if the client does not respond to
330 // FireNewWindow2, but the Mozilla control will not. Potentially
331 // it could also open an instance of IE for such occasions.
334 // Can't open a new window without client support
338 // As documented in MSDN:
340 // The post data specified by PostData is passed as a SAFEARRAY
341 // structure. The variant should be of type VT_ARRAY and point to
342 // a SAFEARRAY. The SAFEARRAY should be of element type VT_UI1,
343 // dimension one, and have an element count equal to the number of
344 // bytes of post data.
346 // Extract the post data parameter
347 nsCOMPtr
<nsIInputStream
> postDataStream
;
348 mLastPostData
.Clear();
350 PostData
->vt
== (VT_ARRAY
| VT_UI1
) &&
353 mLastPostData
.Copy(PostData
);
355 unsigned long nSizeData
= PostData
->parray
->rgsabound
[0].cElements
;
359 sprintf(szCL
, "Content-Length: %lu\r\n\r\n", nSizeData
);
360 unsigned long nSizeCL
= strlen(szCL
);
361 unsigned long nSize
= nSizeCL
+ nSizeData
;
363 char *tmp
= (char *) nsMemory::Alloc(nSize
+ 1); // byte stream owns this mem
367 // Copy the array data into a buffer
368 SafeArrayLock(PostData
->parray
);
369 memcpy(tmp
, szCL
, nSizeCL
);
370 memcpy(tmp
+ nSizeCL
, PostData
->parray
->pvData
, nSizeData
);
372 SafeArrayUnlock(PostData
->parray
);
374 // Create a byte array input stream object.
375 nsCOMPtr
<nsIStringInputStream
> stream
376 (do_CreateInstance("@mozilla.org/io/string-input-stream;1"));
377 rv
= stream
->AdoptData(tmp
, nSize
);
378 if (NS_FAILED(rv
) || !stream
)
380 NS_ASSERTION(0, "cannot create byte stream");
382 return SetErrorInfo(E_UNEXPECTED
);
385 postDataStream
= stream
;
390 // Extract the headers parameter
391 nsCOMPtr
<nsIStringInputStream
> headersStream
;
393 Headers
->vt
== VT_BSTR
&&
398 char *headers
= OLE2A(Headers
->bstrVal
);
401 size_t nSize
= SysStringLen(Headers
->bstrVal
) + 1;
402 char *tmp
= (char *) nsMemory::Alloc(nSize
); // byteArray stream owns this mem
405 // Copy BSTR to buffer
406 WideCharToMultiByte(CP_ACP
, 0, Headers
->bstrVal
, nSize
- 1, tmp
, nSize
, NULL
, NULL
);
407 tmp
[nSize
- 1] = '\0';
409 // Create a byte array input stream object which will own the buffer
410 headersStream
= do_CreateInstance("@mozilla.org/io/string-input-stream;1");
412 rv
= headersStream
->AdoptData(tmp
, nSize
);
414 if (NS_FAILED(rv
) || !headersStream
)
416 NS_ASSERTION(0, "cannot create byte stream");
423 // Use the specified target or the top level web navigation
424 nsCOMPtr
<nsIWebNavigation
> webNavToUse
;
427 webNavToUse
= targetNav
;
431 GetWebNavigation(getter_AddRefs(webNavToUse
));
435 rv
= NS_ERROR_FAILURE
;
438 rv
= webNavToUse
->LoadURI(URL
,
439 loadFlags
, nsnull
, postDataStream
, headersStream
);
442 return NS_SUCCEEDED(rv
) ? S_OK
: E_FAIL
;
445 virtual HRESULT STDMETHODCALLTYPE
Refresh(void)
447 ATLTRACE(_T("IWebBrowserImpl::Refresh()\n"));
449 CComVariant
vRefreshType(REFRESH_NORMAL
);
450 return Refresh2(&vRefreshType
);
453 virtual HRESULT STDMETHODCALLTYPE
Refresh2(VARIANT __RPC_FAR
*Level
)
455 ATLTRACE(_T("IWebBrowserImpl::Refresh2()\n"));
457 ENSURE_BROWSER_IS_VALID();
462 // Check the requested refresh type
463 OLECMDID_REFRESHFLAG iRefreshLevel
= OLECMDIDF_REFRESH_NORMAL
;
464 CComVariant vLevelAsInt
;
465 if ( vLevelAsInt
.ChangeType(VT_I4
, Level
) != S_OK
)
467 NS_ASSERTION(0, "Cannot change refresh type to int");
468 return SetErrorInfo(E_UNEXPECTED
);
470 iRefreshLevel
= (OLECMDID_REFRESHFLAG
) vLevelAsInt
.iVal
;
472 // Turn the IE refresh type into the nearest NG equivalent
473 PRUint32 flags
= nsIWebNavigation::LOAD_FLAGS_NONE
;
474 switch (iRefreshLevel
& OLECMDIDF_REFRESH_LEVELMASK
)
476 case OLECMDIDF_REFRESH_NORMAL
:
477 case OLECMDIDF_REFRESH_IFEXPIRED
:
478 case OLECMDIDF_REFRESH_CONTINUE
:
479 case OLECMDIDF_REFRESH_NO_CACHE
:
480 case OLECMDIDF_REFRESH_RELOAD
:
481 flags
= nsIWebNavigation::LOAD_FLAGS_NONE
;
483 case OLECMDIDF_REFRESH_COMPLETELY
:
484 flags
= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE
| nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY
;
487 // No idea what refresh type this is supposed to be
488 NS_ASSERTION(0, "Unknown refresh type");
489 return SetErrorInfo(E_UNEXPECTED
);
492 webNav
->Reload(flags
);
496 virtual HRESULT STDMETHODCALLTYPE
Stop(void)
498 ATLTRACE(_T("IWebBrowserImpl::Stop()\n"));
499 ENSURE_BROWSER_IS_VALID();
501 webNav
->Stop(nsIWebNavigation::STOP_ALL
);
504 virtual HRESULT STDMETHODCALLTYPE
get_Application(IDispatch __RPC_FAR
*__RPC_FAR
*ppDisp
)
506 ATLTRACE(_T("IWebBrowserImpl::get_Application()\n"));
507 ENSURE_BROWSER_IS_VALID();
510 return SetErrorInfo(E_INVALIDARG
);
512 // Return a pointer to this controls dispatch interface
513 *ppDisp
= (IDispatch
*) this;
517 virtual HRESULT STDMETHODCALLTYPE
get_Parent(IDispatch __RPC_FAR
*__RPC_FAR
*ppDisp
)
522 virtual HRESULT STDMETHODCALLTYPE
get_Container(IDispatch __RPC_FAR
*__RPC_FAR
*ppDisp
)
524 ATLTRACE(_T("IWebBrowserImpl::get_Container()\n"));
525 ENSURE_BROWSER_IS_VALID();
528 return SetErrorInfo(E_INVALIDARG
);
530 //TODO: Implement get_Container: Retrieve a pointer to the IDispatch interface of the container.
532 return SetErrorInfo(E_UNEXPECTED
);
534 virtual HRESULT STDMETHODCALLTYPE
get_Document(IDispatch __RPC_FAR
*__RPC_FAR
*ppDisp
)
536 ATLTRACE(_T("IWebBrowserImpl::get_Document()\n"));
537 ENSURE_BROWSER_IS_VALID();
540 return SetErrorInfo(E_INVALIDARG
);
545 virtual HRESULT STDMETHODCALLTYPE
get_TopLevelContainer(VARIANT_BOOL __RPC_FAR
*pBool
)
547 ATLTRACE(_T("IWebBrowserImpl::get_TopLevelContainer()\n"));
548 ENSURE_BROWSER_IS_VALID();
551 return SetErrorInfo(E_INVALIDARG
);
553 //TODO: Implement get_TopLevelContainer
554 *pBool
= VARIANT_TRUE
;
558 virtual HRESULT STDMETHODCALLTYPE
get_Type(BSTR __RPC_FAR
*Type
)
560 ATLTRACE(_T("IWebBrowserImpl::get_Type()\n"));
561 ENSURE_BROWSER_IS_VALID();
563 //NOTE: This code should work in theory, but can't be verified because GetDoctype
564 // has not been implemented yet.
566 nsIDOMDocument
*pIDOMDocument
= nsnull
;
567 if ( SUCCEEDED(GetDOMDocument(&pIDOMDocument
)) )
569 nsIDOMDocumentType
*pIDOMDocumentType
= nsnull
;
570 if ( SUCCEEDED(pIDOMDocument
->GetDoctype(&pIDOMDocumentType
)) )
572 nsAutoString docName
;
573 pIDOMDocumentType
->GetName(docName
);
574 //NG_TRACE("pIDOMDocumentType returns: %s", docName);
575 //Still need to manipulate docName so that it goes into *Type param of this function.
579 //TODO: Implement get_Type
580 return SetErrorInfo(E_FAIL
, L
"get_Type: failed");
583 virtual HRESULT STDMETHODCALLTYPE
get_Left(long __RPC_FAR
*pl
)
585 ATLTRACE(_T("IWebBrowserImpl::get_Left()\n"));
586 ENSURE_BROWSER_IS_VALID();
589 return SetErrorInfo(E_INVALIDARG
);
592 //TODO: Implement get_Left - Should return the left position of this control.
596 virtual HRESULT STDMETHODCALLTYPE
put_Left(long Left
)
598 ATLTRACE(_T("IWebBrowserImpl::put_Left()\n"));
599 ENSURE_BROWSER_IS_VALID();
600 //TODO: Implement put_Left - Should set the left position of this control.
603 virtual HRESULT STDMETHODCALLTYPE
get_Top(long __RPC_FAR
*pl
)
605 ATLTRACE(_T("IWebBrowserImpl::get_Top()\n"));
606 ENSURE_BROWSER_IS_VALID();
609 return SetErrorInfo(E_INVALIDARG
);
611 //TODO: Implement get_Top - Should return the top position of this control.
615 virtual HRESULT STDMETHODCALLTYPE
put_Top(long Top
)
617 ATLTRACE(_T("IWebBrowserImpl::put_Top()\n"));
618 ENSURE_BROWSER_IS_VALID();
619 //TODO: Implement set_Top - Should set the top position of this control.
622 virtual HRESULT STDMETHODCALLTYPE
get_Width(long __RPC_FAR
*pl
)
624 ATLTRACE(_T("IWebBrowserImpl::get_Width()\n"));
625 ENSURE_BROWSER_IS_VALID();
626 //TODO: Implement get_Width- Should return the width of this control.
629 return SetErrorInfo(E_INVALIDARG
);
634 virtual HRESULT STDMETHODCALLTYPE
put_Width(long Width
)
636 ATLTRACE(_T("IWebBrowserImpl::put_Width()\n"));
637 ENSURE_BROWSER_IS_VALID();
638 //TODO: Implement put_Width - Should set the width of this control.
641 virtual HRESULT STDMETHODCALLTYPE
get_Height(long __RPC_FAR
*pl
)
643 ATLTRACE(_T("IWebBrowserImpl::get_Height()\n"));
644 ENSURE_BROWSER_IS_VALID();
647 return SetErrorInfo(E_INVALIDARG
);
650 //TODO: Implement get_Height - Should return the hieght of this control.
654 virtual HRESULT STDMETHODCALLTYPE
put_Height(long Height
)
656 ATLTRACE(_T("IWebBrowserImpl::put_Height()\n"));
657 ENSURE_BROWSER_IS_VALID();
658 //TODO: Implement put_Height - Should set the height of this control.
662 virtual HRESULT STDMETHODCALLTYPE
get_LocationName(BSTR __RPC_FAR
*LocationName
)
664 ATLTRACE(_T("IWebBrowserImpl::get_LocationName()\n"));
665 ENSURE_BROWSER_IS_VALID();
666 if (LocationName
== NULL
)
668 return SetErrorInfo(E_INVALIDARG
);
670 // Get the url from the web shell
671 nsString szLocationName
;
673 nsCOMPtr
<nsIBaseWindow
> baseWindow
= do_QueryInterface(webNav
);
674 baseWindow
->GetTitle(getter_Copies(szLocationName
));
675 if (!szLocationName
.get())
677 return SetErrorInfo(E_UNEXPECTED
);
680 // Convert the string to a BSTR
682 LPCOLESTR pszConvertedLocationName
= W2COLE(szLocationName
.get());
683 *LocationName
= SysAllocString(pszConvertedLocationName
);
688 virtual HRESULT STDMETHODCALLTYPE
get_LocationURL(BSTR __RPC_FAR
*LocationURL
)
690 ATLTRACE(_T("IWebBrowserImpl::get_LocationURL()\n"));
691 ENSURE_BROWSER_IS_VALID();
693 if (LocationURL
== NULL
)
695 return SetErrorInfo(E_INVALIDARG
);
697 nsCOMPtr
<nsIURI
> uri
;
698 // Get the current url from the browser
699 nsCOMPtr
<nsIWebNavigation
> webNav
;
700 GetWebNavigation(getter_AddRefs(webNav
));
703 webNav
->GetCurrentURI(getter_AddRefs(uri
));
709 uri
->GetAsciiSpec(aURI
);
710 *LocationURL
= SysAllocString(A2OLE(aURI
.get()));
720 virtual HRESULT STDMETHODCALLTYPE
get_Busy(VARIANT_BOOL __RPC_FAR
*pBool
)
722 ATLTRACE(_T("IWebBrowserImpl::get_Busy()\n"));
723 ENSURE_BROWSER_IS_VALID();
726 return SetErrorInfo(E_INVALIDARG
);
728 *pBool
= (mBusyFlag
) ? VARIANT_TRUE
: VARIANT_FALSE
;
732 // IWebBrowserApp implementation
733 virtual HRESULT STDMETHODCALLTYPE
Quit(void)
735 ATLTRACE(_T("IWebBrowserImpl::Quit()\n"));
736 ENSURE_BROWSER_IS_VALID();
738 //This generates an exception in the IE control.
739 // TODO fire quit event
743 virtual HRESULT STDMETHODCALLTYPE
ClientToWindow(int __RPC_FAR
*pcx
, int __RPC_FAR
*pcy
)
745 ATLTRACE(_T("IWebBrowserImpl::ClientToWindow()\n"));
746 ENSURE_BROWSER_IS_VALID();
748 //This generates an exception in the IE control.
749 // TODO convert points to be relative to browser
753 virtual HRESULT STDMETHODCALLTYPE
PutProperty(BSTR Property
, VARIANT vtValue
)
755 ATLTRACE(_T("IWebBrowserImpl::PutProperty()\n"));
756 ENSURE_BROWSER_IS_VALID();
757 if (Property
== NULL
)
759 return SetErrorInfo(E_INVALIDARG
);
761 mPropertyList
.AddOrReplaceNamedProperty(Property
, vtValue
);
765 virtual HRESULT STDMETHODCALLTYPE
GetProperty(BSTR Property
, VARIANT __RPC_FAR
*pvtValue
)
767 ATLTRACE(_T("IWebBrowserImpl::GetProperty()\n"));
768 ENSURE_BROWSER_IS_VALID();
769 if (Property
== NULL
|| pvtValue
== NULL
)
771 return SetErrorInfo(E_INVALIDARG
);
773 VariantInit(pvtValue
);
774 for (unsigned long i
= 0; i
< mPropertyList
.GetSize(); i
++)
776 if (wcsicmp(mPropertyList
.GetNameOf(i
), Property
) == 0)
778 // Copy the new value
779 VariantCopy(pvtValue
, const_cast<VARIANT
*>(mPropertyList
.GetValueOf(i
)));
786 virtual HRESULT STDMETHODCALLTYPE
get_Name(BSTR __RPC_FAR
*Name
)
788 ATLTRACE(_T("IWebBrowserImpl::get_Name()\n"));
789 ENSURE_BROWSER_IS_VALID();
792 return SetErrorInfo(E_INVALIDARG
);
795 // TODO: Implement get_Name (get Mozilla's executable name)
796 *Name
= SysAllocString(L
"Mozilla Web Browser Control");
800 virtual HRESULT STDMETHODCALLTYPE
get_HWND(long __RPC_FAR
*pHWND
)
802 ATLTRACE(_T("IWebBrowserImpl::get_HWND()\n"));
803 ENSURE_BROWSER_IS_VALID();
806 return SetErrorInfo(E_INVALIDARG
);
809 //This is supposed to return a handle to the IE main window. Since that doesn't exist
810 //in the control's case, this shouldn't do anything.
815 virtual HRESULT STDMETHODCALLTYPE
get_FullName(BSTR __RPC_FAR
*FullName
)
817 ATLTRACE(_T("IWebBrowserImpl::get_FullName()\n"));
818 ENSURE_BROWSER_IS_VALID();
819 if (FullName
== NULL
)
821 return SetErrorInfo(E_INVALIDARG
);
824 // TODO: Implement get_FullName (Return the full path of the executable containing this control)
825 *FullName
= SysAllocString(L
""); // TODO get Mozilla's executable name
829 virtual HRESULT STDMETHODCALLTYPE
get_Path(BSTR __RPC_FAR
*Path
)
831 ATLTRACE(_T("IWebBrowserImpl::get_Path()\n"));
832 ENSURE_BROWSER_IS_VALID();
836 return SetErrorInfo(E_INVALIDARG
);
839 // TODO: Implement get_Path (get Mozilla's path)
840 *Path
= SysAllocString(L
"");
844 virtual HRESULT STDMETHODCALLTYPE
get_Visible(VARIANT_BOOL __RPC_FAR
*pBool
)
846 ATLTRACE(_T("IWebBrowserImpl::get_Visible()\n"));
847 ENSURE_BROWSER_IS_VALID();
851 return SetErrorInfo(E_INVALIDARG
);
854 //TODO: Implement get_Visible?
855 *pBool
= VARIANT_TRUE
;
859 virtual HRESULT STDMETHODCALLTYPE
put_Visible(VARIANT_BOOL Value
)
861 ATLTRACE(_T("IWebBrowserImpl::put_Visible()\n"));
862 ENSURE_BROWSER_IS_VALID();
864 //TODO: Implement put_Visible?
868 virtual HRESULT STDMETHODCALLTYPE
get_StatusBar(VARIANT_BOOL __RPC_FAR
*pBool
)
870 ATLTRACE(_T("IWebBrowserImpl::get_StatusBar()\n"));
871 ENSURE_BROWSER_IS_VALID();
874 return SetErrorInfo(E_INVALIDARG
);
876 //There is no StatusBar in this control.
877 *pBool
= VARIANT_FALSE
;
881 virtual HRESULT STDMETHODCALLTYPE
put_StatusBar(VARIANT_BOOL Value
)
883 ATLTRACE(_T("IWebBrowserImpl::put_StatusBar()\n"));
884 ENSURE_BROWSER_IS_VALID();
885 //There is no StatusBar in this control.
889 virtual HRESULT STDMETHODCALLTYPE
get_StatusText(BSTR __RPC_FAR
*StatusText
)
891 ATLTRACE(_T("IWebBrowserImpl::get_StatusText()\n"));
892 ENSURE_BROWSER_IS_VALID();
893 if (StatusText
== NULL
)
895 return SetErrorInfo(E_INVALIDARG
);
898 //TODO: Implement get_StatusText
899 //NOTE: This function is related to the MS status bar which doesn't exist in this control. Needs more
900 // investigation, but probably doesn't apply.
901 *StatusText
= SysAllocString(L
"");
905 virtual HRESULT STDMETHODCALLTYPE
put_StatusText(BSTR StatusText
)
907 ATLTRACE(_T("IWebBrowserImpl::put_StatusText()\n"));
908 ENSURE_BROWSER_IS_VALID();
909 //TODO: Implement put_StatusText
910 //NOTE: This function is related to the MS status bar which doesn't exist in this control. Needs more
911 // investigation, but probably doesn't apply.
915 virtual HRESULT STDMETHODCALLTYPE
get_ToolBar(int __RPC_FAR
*Value
)
917 ATLTRACE(_T("IWebBrowserImpl::get_ToolBar()\n"));
918 ENSURE_BROWSER_IS_VALID();
921 return SetErrorInfo(E_INVALIDARG
);
924 //There is no ToolBar in this control.
929 virtual HRESULT STDMETHODCALLTYPE
put_ToolBar(int Value
)
931 ATLTRACE(_T("IWebBrowserImpl::put_ToolBar()\n"));
932 ENSURE_BROWSER_IS_VALID();
933 //There is no ToolBar in this control.
937 virtual HRESULT STDMETHODCALLTYPE
get_MenuBar(VARIANT_BOOL __RPC_FAR
*Value
)
939 ATLTRACE(_T("IWebBrowserImpl::get_MenuBar()\n"));
940 ENSURE_BROWSER_IS_VALID();
943 return SetErrorInfo(E_INVALIDARG
);
946 //There is no MenuBar in this control.
947 *Value
= VARIANT_FALSE
;
951 virtual HRESULT STDMETHODCALLTYPE
put_MenuBar(VARIANT_BOOL Value
)
953 ATLTRACE(_T("IWebBrowserImpl::put_MenuBar()\n"));
954 ENSURE_BROWSER_IS_VALID();
955 //There is no MenuBar in this control.
959 virtual HRESULT STDMETHODCALLTYPE
get_FullScreen(VARIANT_BOOL __RPC_FAR
*pbFullScreen
)
961 ATLTRACE(_T("IWebBrowserImpl::get_FullScreen()\n"));
962 ENSURE_BROWSER_IS_VALID();
963 if (pbFullScreen
== NULL
)
965 return SetErrorInfo(E_INVALIDARG
);
968 //FullScreen mode doesn't really apply to this control.
969 *pbFullScreen
= VARIANT_FALSE
;
973 virtual HRESULT STDMETHODCALLTYPE
put_FullScreen(VARIANT_BOOL bFullScreen
)
975 ATLTRACE(_T("IWebBrowserImpl::put_FullScreen()\n"));
976 ENSURE_BROWSER_IS_VALID();
977 //FullScreen mode doesn't really apply to this control.
981 // IWebBrowser2 implementation
982 virtual HRESULT STDMETHODCALLTYPE
Navigate2(VARIANT __RPC_FAR
*URL
, VARIANT __RPC_FAR
*Flags
, VARIANT __RPC_FAR
*TargetFrameName
, VARIANT __RPC_FAR
*PostData
, VARIANT __RPC_FAR
*Headers
)
984 ATLTRACE(_T("IWebBrowserImpl::Navigate2()\n"));
985 CComVariant vURLAsString
;
986 if (vURLAsString
.ChangeType(VT_BSTR
, URL
) != S_OK
)
988 return SetErrorInfo(E_INVALIDARG
);
990 return Navigate(vURLAsString
.bstrVal
, Flags
, TargetFrameName
, PostData
, Headers
);
993 virtual HRESULT STDMETHODCALLTYPE
QueryStatusWB(OLECMDID cmdID
, OLECMDF __RPC_FAR
*pcmdf
)
995 ATLTRACE(_T("IWebBrowserImpl::QueryStatusWB()\n"));
996 ENSURE_BROWSER_IS_VALID();
999 return SetErrorInfo(E_INVALIDARG
);
1001 // Call through to IOleCommandTarget::QueryStatus
1002 CComQIPtr
<IOleCommandTarget
> cmdTarget
= this;
1010 hr
= cmdTarget
->QueryStatus(NULL
, 1, &cmd
, NULL
);
1013 *pcmdf
= (OLECMDF
) cmd
.cmdf
;
1020 virtual HRESULT STDMETHODCALLTYPE
ExecWB(OLECMDID cmdID
, OLECMDEXECOPT cmdexecopt
, VARIANT __RPC_FAR
*pvaIn
, VARIANT __RPC_FAR
*pvaOut
)
1022 ATLTRACE(_T("IWebBrowserImpl::ExecWB()\n"));
1023 ENSURE_BROWSER_IS_VALID();
1024 // Call through to IOleCommandTarget::Exec
1025 CComQIPtr
<IOleCommandTarget
> cmdTarget
= this;
1028 return cmdTarget
->Exec(NULL
, cmdID
, cmdexecopt
, pvaIn
, pvaOut
);
1033 virtual HRESULT STDMETHODCALLTYPE
ShowBrowserBar(VARIANT __RPC_FAR
*pvaClsid
, VARIANT __RPC_FAR
*pvarShow
, VARIANT __RPC_FAR
*pvarSize
)
1035 ATLTRACE(_T("IWebBrowserImpl::ShowBrowserBar()\n"));
1036 ENSURE_BROWSER_IS_VALID();
1040 virtual HRESULT STDMETHODCALLTYPE
get_ReadyState(READYSTATE __RPC_FAR
*plReadyState
)
1042 ATLTRACE(_T("IWebBrowserImpl::get_ReadyState()\n"));
1043 // Note: may be called when browser is not yet initialized so there
1044 // is no validity check here.
1045 if (plReadyState
== NULL
)
1047 return SetErrorInfo(E_INVALIDARG
);
1049 *plReadyState
= mBrowserReadyState
;
1053 virtual HRESULT STDMETHODCALLTYPE
get_Offline(VARIANT_BOOL __RPC_FAR
*pbOffline
)
1055 ATLTRACE(_T("IWebBrowserImpl::get_Offline()\n"));
1056 ENSURE_BROWSER_IS_VALID();
1057 if (pbOffline
== NULL
)
1059 return SetErrorInfo(E_INVALIDARG
);
1061 //TODO: Implement get_Offline
1062 *pbOffline
= VARIANT_FALSE
;
1065 virtual HRESULT STDMETHODCALLTYPE
put_Offline(VARIANT_BOOL bOffline
)
1067 ATLTRACE(_T("IWebBrowserImpl::put_Offline()\n"));
1068 ENSURE_BROWSER_IS_VALID();
1069 //TODO: Implement get_Offline
1073 virtual HRESULT STDMETHODCALLTYPE
get_Silent(VARIANT_BOOL __RPC_FAR
*pbSilent
)
1075 ATLTRACE(_T("IWebBrowserImpl::get_Silent()\n"));
1076 ENSURE_BROWSER_IS_VALID();
1077 if (pbSilent
== NULL
)
1079 return SetErrorInfo(E_INVALIDARG
);
1081 //Only really applies to the IE app, not a control
1082 *pbSilent
= VARIANT_FALSE
;
1085 virtual HRESULT STDMETHODCALLTYPE
put_Silent(VARIANT_BOOL bSilent
)
1087 ATLTRACE(_T("IWebBrowserImpl::put_Silent()\n"));
1088 ENSURE_BROWSER_IS_VALID();
1089 //Only really applies to the IE app, not a control
1093 virtual HRESULT STDMETHODCALLTYPE
get_RegisterAsBrowser(VARIANT_BOOL __RPC_FAR
*pbRegister
)
1095 ATLTRACE(_T("IWebBrowserImpl::get_RegisterAsBrowser()\n"));
1096 ENSURE_BROWSER_IS_VALID();
1098 if (pbRegister
== NULL
)
1100 return SetErrorInfo(E_INVALIDARG
);
1102 //TODO: Implement get_RegisterAsBrowser
1103 *pbRegister
= VARIANT_FALSE
;
1106 virtual HRESULT STDMETHODCALLTYPE
put_RegisterAsBrowser(VARIANT_BOOL bRegister
)
1108 ATLTRACE(_T("IWebBrowserImpl::put_RegisterAsBrowser()\n"));
1109 ENSURE_BROWSER_IS_VALID();
1110 //TODO: Implement put_RegisterAsBrowser
1114 virtual HRESULT STDMETHODCALLTYPE
get_RegisterAsDropTarget(VARIANT_BOOL __RPC_FAR
*pbRegister
)
1119 virtual HRESULT STDMETHODCALLTYPE
put_RegisterAsDropTarget(VARIANT_BOOL bRegister
)
1125 virtual HRESULT STDMETHODCALLTYPE
get_TheaterMode(VARIANT_BOOL __RPC_FAR
*pbRegister
)
1127 ATLTRACE(_T("IWebBrowserImpl::get_TheaterMode()\n"));
1128 ENSURE_BROWSER_IS_VALID();
1129 if (pbRegister
== NULL
)
1131 return SetErrorInfo(E_INVALIDARG
);
1133 // TheaterMode doesn't apply to this control.
1134 *pbRegister
= VARIANT_FALSE
;
1137 virtual HRESULT STDMETHODCALLTYPE
put_TheaterMode(VARIANT_BOOL bRegister
)
1139 ATLTRACE(_T("IWebBrowserImpl::put_TheaterMode()\n"));
1140 ENSURE_BROWSER_IS_VALID();
1141 //There is no TheaterMode in this control.
1145 virtual HRESULT STDMETHODCALLTYPE
get_AddressBar(VARIANT_BOOL __RPC_FAR
*Value
)
1147 ATLTRACE(_T("IWebBrowserImpl::get_AddressBar()\n"));
1148 ENSURE_BROWSER_IS_VALID();
1151 return SetErrorInfo(E_INVALIDARG
);
1153 //There is no AddressBar in this control.
1154 *Value
= VARIANT_FALSE
;
1157 virtual HRESULT STDMETHODCALLTYPE
put_AddressBar(VARIANT_BOOL Value
)
1159 ATLTRACE(_T("IWebBrowserImpl::put_AddressBar()\n"));
1160 ENSURE_BROWSER_IS_VALID();
1161 //There is no AddressBar in this control.
1165 virtual HRESULT STDMETHODCALLTYPE
get_Resizable(VARIANT_BOOL __RPC_FAR
*Value
)
1167 ATLTRACE(_T("IWebBrowserImpl::get_Resizable()\n"));
1168 ENSURE_BROWSER_IS_VALID();
1171 return SetErrorInfo(E_INVALIDARG
);
1173 //TODO: Not sure if this should actually be implemented or not.
1174 *Value
= VARIANT_TRUE
;
1177 virtual HRESULT STDMETHODCALLTYPE
put_Resizable(VARIANT_BOOL Value
)
1179 ATLTRACE(_T("IWebBrowserImpl::put_Resizable()\n"));
1180 ENSURE_BROWSER_IS_VALID();
1181 //TODO: Not sure if this should actually be implemented or not.