Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / embedding / browser / activex / src / common / IWebBrowserImpl.h
blobe3e5136b4c39a490f0e851945ae2fe4928ebb5eb
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
13 * License.
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.
22 * Contributor(s):
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
42 #include <mshtml.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"
52 #include "nsIURI.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()) \
63 { \
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)); \
71 if (NS_FAILED(rv)) \
72 { \
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>
83 public:
84 IWebBrowserImpl()
86 // Ready state of control
87 mBrowserReadyState = READYSTATE_UNINITIALIZED;
88 // Flag indicates if the browser is busy
89 mBusyFlag = PR_FALSE;
92 public:
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;
103 public:
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
110 PRBool mBusyFlag;
111 // Property list
112 PropertyList mPropertyList;
114 // Helper methods
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
125 switch (hr)
127 case E_UNEXPECTED:
128 lpszDesc = L"Method was called while control was uninitialized";
129 break;
130 case E_INVALIDARG:
131 lpszDesc = L"Method was called with an invalid parameter";
132 break;
135 AtlSetErrorInfo(*pclsid, lpszDesc, 0, NULL, GUID_NULL, hr, NULL);
136 return hr;
140 // IWebBrowser implementation
141 virtual HRESULT STDMETHODCALLTYPE GoBack(void)
143 ATLTRACE(_T("IWebBrowserImpl::GoBack()\n"));
144 ENSURE_BROWSER_IS_VALID();
145 ENSURE_GET_WEBNAV();
147 PRBool aCanGoBack = PR_FALSE;
148 webNav->GetCanGoBack(&aCanGoBack);
149 if (aCanGoBack == PR_TRUE)
151 webNav->GoBack();
153 return S_OK;
156 virtual HRESULT STDMETHODCALLTYPE GoForward(void)
158 ATLTRACE(_T("IWebBrowserImpl::GoBack()\n"));
159 ENSURE_BROWSER_IS_VALID();
160 ENSURE_GET_WEBNAV();
162 PRBool aCanGoForward = PR_FALSE;
163 webNav->GetCanGoForward(&aCanGoForward);
164 if (aCanGoForward == PR_TRUE)
166 webNav->GoForward();
168 return S_OK;
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));
187 if (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);
201 return S_OK;
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
211 #if 0
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
219 #endif
220 // Navigate to the search page
221 Navigate(bstrUrl, NULL, NULL, NULL, NULL);
223 return S_OK;
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();
231 nsresult rv;
233 // Extract the URL parameter
234 if (URL == NULL)
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
244 LONG lFlags = 0;
245 if (Flags &&
246 Flags->vt != VT_ERROR &&
247 Flags->vt != VT_EMPTY &&
248 Flags->vt != VT_NULL)
250 CComVariant vFlags;
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)
264 // Disable history
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));
288 if (window)
290 nsCOMPtr<nsIWindowWatcher> windowWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
291 if (windowWatcher)
293 nsCOMPtr<nsIDOMWindow> targetWindow;
294 windowWatcher->GetWindowByName(TargetFrameName->bstrVal, window,
295 getter_AddRefs(targetWindow));
296 if (targetWindow)
298 targetNav = do_GetInterface(targetWindow);
302 // No target nav? Open in new window
303 if (!targetNav)
304 openInNewWindow = PR_TRUE;
307 // Open in new window
308 if (openInNewWindow)
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;
320 if (spOther)
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
335 return S_OK;
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();
349 if (PostData &&
350 PostData->vt == (VT_ARRAY | VT_UI1) &&
351 PostData->parray)
353 mLastPostData.Copy(PostData);
355 unsigned long nSizeData = PostData->parray->rgsabound[0].cElements;
356 if (nSizeData > 0)
358 char szCL[64];
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
364 if (tmp)
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);
371 tmp[nSize] = '\0';
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");
381 nsMemory::Free(tmp);
382 return SetErrorInfo(E_UNEXPECTED);
385 postDataStream = stream;
390 // Extract the headers parameter
391 nsCOMPtr<nsIStringInputStream> headersStream;
392 if (Headers &&
393 Headers->vt == VT_BSTR &&
394 Headers->bstrVal)
397 USES_CONVERSION;
398 char *headers = OLE2A(Headers->bstrVal);
399 if (headers)
401 size_t nSize = SysStringLen(Headers->bstrVal) + 1;
402 char *tmp = (char *) nsMemory::Alloc(nSize); // byteArray stream owns this mem
403 if (tmp)
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");
411 if (headersStream)
412 rv = headersStream->AdoptData(tmp, nSize);
414 if (NS_FAILED(rv) || !headersStream)
416 NS_ASSERTION(0, "cannot create byte stream");
417 nsMemory::Free(tmp);
423 // Use the specified target or the top level web navigation
424 nsCOMPtr<nsIWebNavigation> webNavToUse;
425 if (targetNav)
427 webNavToUse = targetNav;
429 else
431 GetWebNavigation(getter_AddRefs(webNavToUse));
434 // Load the URL
435 rv = NS_ERROR_FAILURE;
436 if (webNavToUse)
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"));
448 // Reload the page
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();
458 ENSURE_GET_WEBNAV();
459 if (Level == NULL)
460 return E_INVALIDARG;
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;
482 break;
483 case OLECMDIDF_REFRESH_COMPLETELY:
484 flags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
485 break;
486 default:
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);
494 return S_OK;
496 virtual HRESULT STDMETHODCALLTYPE Stop(void)
498 ATLTRACE(_T("IWebBrowserImpl::Stop()\n"));
499 ENSURE_BROWSER_IS_VALID();
500 ENSURE_GET_WEBNAV();
501 webNav->Stop(nsIWebNavigation::STOP_ALL);
502 return S_OK;
504 virtual HRESULT STDMETHODCALLTYPE get_Application(IDispatch __RPC_FAR *__RPC_FAR *ppDisp)
506 ATLTRACE(_T("IWebBrowserImpl::get_Application()\n"));
507 ENSURE_BROWSER_IS_VALID();
508 if (!ppDisp)
510 return SetErrorInfo(E_INVALIDARG);
512 // Return a pointer to this controls dispatch interface
513 *ppDisp = (IDispatch *) this;
514 (*ppDisp)->AddRef();
515 return S_OK;
517 virtual HRESULT STDMETHODCALLTYPE get_Parent(IDispatch __RPC_FAR *__RPC_FAR *ppDisp)
519 // TODO
520 return E_NOTIMPL;
522 virtual HRESULT STDMETHODCALLTYPE get_Container(IDispatch __RPC_FAR *__RPC_FAR *ppDisp)
524 ATLTRACE(_T("IWebBrowserImpl::get_Container()\n"));
525 ENSURE_BROWSER_IS_VALID();
526 if (!ppDisp)
528 return SetErrorInfo(E_INVALIDARG);
530 //TODO: Implement get_Container: Retrieve a pointer to the IDispatch interface of the container.
531 *ppDisp = NULL;
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();
538 if (!ppDisp)
540 return SetErrorInfo(E_INVALIDARG);
542 *ppDisp = NULL;
543 return E_NOTIMPL;
545 virtual HRESULT STDMETHODCALLTYPE get_TopLevelContainer(VARIANT_BOOL __RPC_FAR *pBool)
547 ATLTRACE(_T("IWebBrowserImpl::get_TopLevelContainer()\n"));
548 ENSURE_BROWSER_IS_VALID();
549 if (!pBool)
551 return SetErrorInfo(E_INVALIDARG);
553 //TODO: Implement get_TopLevelContainer
554 *pBool = VARIANT_TRUE;
555 return S_OK;
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.
565 #if 0
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.
578 #endif
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();
587 if (pl == NULL)
589 return SetErrorInfo(E_INVALIDARG);
592 //TODO: Implement get_Left - Should return the left position of this control.
593 *pl = 0;
594 return S_OK;
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.
601 return S_OK;
603 virtual HRESULT STDMETHODCALLTYPE get_Top(long __RPC_FAR *pl)
605 ATLTRACE(_T("IWebBrowserImpl::get_Top()\n"));
606 ENSURE_BROWSER_IS_VALID();
607 if (pl == NULL)
609 return SetErrorInfo(E_INVALIDARG);
611 //TODO: Implement get_Top - Should return the top position of this control.
612 *pl = 0;
613 return S_OK;
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.
620 return S_OK;
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.
627 if (pl == NULL)
629 return SetErrorInfo(E_INVALIDARG);
631 *pl = 0;
632 return S_OK;
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.
639 return S_OK;
641 virtual HRESULT STDMETHODCALLTYPE get_Height(long __RPC_FAR *pl)
643 ATLTRACE(_T("IWebBrowserImpl::get_Height()\n"));
644 ENSURE_BROWSER_IS_VALID();
645 if (pl == NULL)
647 return SetErrorInfo(E_INVALIDARG);
650 //TODO: Implement get_Height - Should return the hieght of this control.
651 *pl = 0;
652 return S_OK;
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.
659 return S_OK;
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;
672 ENSURE_GET_WEBNAV();
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
681 USES_CONVERSION;
682 LPCOLESTR pszConvertedLocationName = W2COLE(szLocationName.get());
683 *LocationName = SysAllocString(pszConvertedLocationName);
685 return S_OK;
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));
701 if (webNav)
703 webNav->GetCurrentURI(getter_AddRefs(uri));
705 if (uri)
707 USES_CONVERSION;
708 nsCAutoString aURI;
709 uri->GetAsciiSpec(aURI);
710 *LocationURL = SysAllocString(A2OLE(aURI.get()));
712 else
714 *LocationURL = NULL;
717 return S_OK;
720 virtual HRESULT STDMETHODCALLTYPE get_Busy(VARIANT_BOOL __RPC_FAR *pBool)
722 ATLTRACE(_T("IWebBrowserImpl::get_Busy()\n"));
723 ENSURE_BROWSER_IS_VALID();
724 if (!pBool)
726 return SetErrorInfo(E_INVALIDARG);
728 *pBool = (mBusyFlag) ? VARIANT_TRUE : VARIANT_FALSE;
729 return S_OK;
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
740 return S_OK;
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
750 return S_OK;
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);
762 return S_OK;
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)));
780 return S_OK;
783 return S_OK;
786 virtual HRESULT STDMETHODCALLTYPE get_Name(BSTR __RPC_FAR *Name)
788 ATLTRACE(_T("IWebBrowserImpl::get_Name()\n"));
789 ENSURE_BROWSER_IS_VALID();
790 if (Name == NULL)
792 return SetErrorInfo(E_INVALIDARG);
795 // TODO: Implement get_Name (get Mozilla's executable name)
796 *Name = SysAllocString(L"Mozilla Web Browser Control");
797 return S_OK;
800 virtual HRESULT STDMETHODCALLTYPE get_HWND(long __RPC_FAR *pHWND)
802 ATLTRACE(_T("IWebBrowserImpl::get_HWND()\n"));
803 ENSURE_BROWSER_IS_VALID();
804 if (pHWND == NULL)
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.
811 *pHWND = NULL;
812 return S_OK;
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
826 return S_OK;
829 virtual HRESULT STDMETHODCALLTYPE get_Path(BSTR __RPC_FAR *Path)
831 ATLTRACE(_T("IWebBrowserImpl::get_Path()\n"));
832 ENSURE_BROWSER_IS_VALID();
834 if (Path == NULL)
836 return SetErrorInfo(E_INVALIDARG);
839 // TODO: Implement get_Path (get Mozilla's path)
840 *Path = SysAllocString(L"");
841 return S_OK;
844 virtual HRESULT STDMETHODCALLTYPE get_Visible(VARIANT_BOOL __RPC_FAR *pBool)
846 ATLTRACE(_T("IWebBrowserImpl::get_Visible()\n"));
847 ENSURE_BROWSER_IS_VALID();
849 if (pBool == NULL)
851 return SetErrorInfo(E_INVALIDARG);
854 //TODO: Implement get_Visible?
855 *pBool = VARIANT_TRUE;
856 return S_OK;
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?
865 return S_OK;
868 virtual HRESULT STDMETHODCALLTYPE get_StatusBar(VARIANT_BOOL __RPC_FAR *pBool)
870 ATLTRACE(_T("IWebBrowserImpl::get_StatusBar()\n"));
871 ENSURE_BROWSER_IS_VALID();
872 if (pBool == NULL)
874 return SetErrorInfo(E_INVALIDARG);
876 //There is no StatusBar in this control.
877 *pBool = VARIANT_FALSE;
878 return S_OK;
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.
886 return S_OK;
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"");
902 return S_OK;
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.
912 return S_OK;
915 virtual HRESULT STDMETHODCALLTYPE get_ToolBar(int __RPC_FAR *Value)
917 ATLTRACE(_T("IWebBrowserImpl::get_ToolBar()\n"));
918 ENSURE_BROWSER_IS_VALID();
919 if (Value == NULL)
921 return SetErrorInfo(E_INVALIDARG);
924 //There is no ToolBar in this control.
925 *Value = FALSE;
926 return S_OK;
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.
934 return S_OK;
937 virtual HRESULT STDMETHODCALLTYPE get_MenuBar(VARIANT_BOOL __RPC_FAR *Value)
939 ATLTRACE(_T("IWebBrowserImpl::get_MenuBar()\n"));
940 ENSURE_BROWSER_IS_VALID();
941 if (Value == NULL)
943 return SetErrorInfo(E_INVALIDARG);
946 //There is no MenuBar in this control.
947 *Value = VARIANT_FALSE;
948 return S_OK;
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.
956 return S_OK;
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;
970 return S_OK;
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.
978 return S_OK;
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();
997 if (pcmdf == NULL)
999 return SetErrorInfo(E_INVALIDARG);
1001 // Call through to IOleCommandTarget::QueryStatus
1002 CComQIPtr<IOleCommandTarget> cmdTarget = this;
1003 if (cmdTarget)
1005 OLECMD cmd;
1006 HRESULT hr;
1008 cmd.cmdID = cmdID;
1009 cmd.cmdf = 0;
1010 hr = cmdTarget->QueryStatus(NULL, 1, &cmd, NULL);
1011 if (SUCCEEDED(hr))
1013 *pcmdf = (OLECMDF) cmd.cmdf;
1015 return hr;
1017 return E_NOTIMPL;
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;
1026 if (cmdTarget)
1028 return cmdTarget->Exec(NULL, cmdID, cmdexecopt, pvaIn, pvaOut);
1030 return E_NOTIMPL;
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();
1037 return S_OK;
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;
1050 return S_OK;
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;
1063 return S_OK;
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
1070 return S_OK;
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;
1083 return S_OK;
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
1090 return S_OK;
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;
1104 return S_OK;
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
1111 return S_OK;
1114 virtual HRESULT STDMETHODCALLTYPE get_RegisterAsDropTarget(VARIANT_BOOL __RPC_FAR *pbRegister)
1116 // TODO
1117 return E_NOTIMPL;
1119 virtual HRESULT STDMETHODCALLTYPE put_RegisterAsDropTarget(VARIANT_BOOL bRegister)
1121 // TODO
1122 return E_NOTIMPL;
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;
1135 return S_OK;
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.
1142 return S_OK;
1145 virtual HRESULT STDMETHODCALLTYPE get_AddressBar(VARIANT_BOOL __RPC_FAR *Value)
1147 ATLTRACE(_T("IWebBrowserImpl::get_AddressBar()\n"));
1148 ENSURE_BROWSER_IS_VALID();
1149 if (Value == NULL)
1151 return SetErrorInfo(E_INVALIDARG);
1153 //There is no AddressBar in this control.
1154 *Value = VARIANT_FALSE;
1155 return S_OK;
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.
1162 return S_OK;
1165 virtual HRESULT STDMETHODCALLTYPE get_Resizable(VARIANT_BOOL __RPC_FAR *Value)
1167 ATLTRACE(_T("IWebBrowserImpl::get_Resizable()\n"));
1168 ENSURE_BROWSER_IS_VALID();
1169 if (Value == NULL)
1171 return SetErrorInfo(E_INVALIDARG);
1173 //TODO: Not sure if this should actually be implemented or not.
1174 *Value = VARIANT_TRUE;
1175 return S_OK;
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.
1182 return S_OK;
1186 #endif