nsresult WebBrowserChrome::CreateBrowser(HWND nativeWnd) { nsresult rv; mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv); if(NS_FAILED(rv)) return NS_ERROR_FAILURE; AddRef(); if(NS_FAILED(mWebBrowser->SetContainerWindow((nsIWebBrowserChrome*)this))) return NS_ERROR_FAILURE; mNativeWindow = nativeWnd; RECT area; GetClientRect(mNativeWindow, &area); nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebBrowser); if(NS_FAILED(baseWindow->InitWindow(mNativeWindow, NULL, area.left, area.top, area.right - area.left, area.bottom - area.top))) return NS_ERROR_FAILURE; if(NS_FAILED(baseWindow->Create())) return NS_ERROR_FAILURE; baseWindow->SetVisibility(PR_TRUE); nsWeakPtr weakling(dont_AddRef(NS_GetWeakReference(static_cast<nsIWebProgressListener*>(this)))); if(NS_FAILED(mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)))) return NS_ERROR_FAILURE; return NS_OK; }
nsresult BrowserWindow::Shutdown () { PRINT("BrowserWindow::Shutdown\n"); if (!webBrowser) return NS_OK; nsCOMPtr<nsIWebProgressListener> wpl ((nsIWebProgressListener*) this); nsCOMPtr<nsIWeakReference> weakWpl (NS_GetWeakReference (wpl)); if (weakWpl) webBrowser->RemoveWebBrowserListener (weakWpl, NS_GET_IID (nsIWebProgressListener)); listeners.clear (); return NS_OK; }
NS_IMETHODIMP nsArray::ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex, bool aWeak) { nsCOMPtr<nsISupports> elementRef; if (aWeak) { elementRef = getter_AddRefs(static_cast<nsISupports*> (NS_GetWeakReference(aElement))); NS_ASSERTION(elementRef, "ReplaceElementAt: Trying to use weak references on an object that doesn't support it"); if (!elementRef) return NS_ERROR_FAILURE; } else { elementRef = aElement; } bool result = mArray.ReplaceObjectAt(elementRef, aIndex); return result ? NS_OK : NS_ERROR_FAILURE; }
NS_IMETHODIMP nsArray::AppendElement(nsISupports* aElement, bool aWeak) { bool result; if (aWeak) { nsCOMPtr<nsISupports> elementRef = getter_AddRefs(static_cast<nsISupports*> (NS_GetWeakReference(aElement))); NS_ASSERTION(elementRef, "AppendElement: Trying to use weak references on an object that doesn't support it"); if (!elementRef) return NS_ERROR_FAILURE; result = mArray.AppendObject(elementRef); } else { // add the object directly result = mArray.AppendObject(aElement); } return result ? NS_OK : NS_ERROR_FAILURE; }
NS_IMETHODIMP sbArray::InsertElementAt(nsISupports* aElement, PRUint32 aIndex, bool aWeak) { nsCOMPtr<nsISupports> elementRef; if (aWeak) { elementRef = getter_AddRefs(static_cast<nsISupports*> (NS_GetWeakReference(aElement))); NS_ASSERTION(elementRef, "InsertElementAt: Trying to use weak references on an object that doesn't support it"); if (!elementRef) return NS_ERROR_FAILURE; } else { elementRef = aElement; } { /* scope */ mozilla::MutexAutoLock lock(mLock); bool result = mArray.InsertObjectAt(elementRef, aIndex); return result ? NS_OK : NS_ERROR_FAILURE; } }
nsresult BrowserWindow::Create ( Handle * hwnd, PRInt32 width, PRInt32 height) { PRINT("BrowserWindow::Create\n"); nsresult result; webBrowser = do_CreateInstance( NS_WEBBROWSER_CONTRACTID ); if ( ! webBrowser ) return NS_ERROR_FAILURE; (void) webBrowser->SetContainerWindow (static_cast<nsIWebBrowserChrome *> (this)); nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface( webBrowser ); dsti->SetItemType( nsIDocShellTreeItem::typeContentWrapper ); webNav = do_QueryInterface(webBrowser); sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID); webNav->SetSessionHistory(sessionHistory); nsCOMPtr<nsIWindowCreator> windowCreator (static_cast<nsIWindowCreator *> (this)); // Attach it via the watcher service nsCOMPtr<nsIWindowWatcher> watcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID); if (watcher) watcher->SetWindowCreator(windowCreator); nsCOMPtr<nsIX509CertDB> certdb = do_GetService(NS_X509CERTDB_CONTRACTID, &result); /** Component registration... ***/ RegisterComponents (); baseWindow = do_QueryInterface (webBrowser); result = baseWindow->InitWindow( hwnd, nsnull, 0, 0, width, height ); if (!NS_SUCCEEDED(result)) { SHOUT("BrowserWindow: Failed to initialize window\n"); return NS_ERROR_FAILURE; } result = baseWindow->Create(); if (!NS_SUCCEEDED(result)) { SHOUT("BrowserWindow: Failed to create window\n"); return NS_ERROR_FAILURE; } nsCOMPtr<nsIWebProgressListener> wpl (static_cast<nsIWebProgressListener*>(this)); nsCOMPtr<nsIWeakReference> weakWpl (NS_GetWeakReference (wpl)); webBrowser->AddWebBrowserListener (weakWpl, NS_GET_IID (nsIWebProgressListener)); baseWindow->SetVisibility( PR_TRUE ); webNav = do_QueryInterface( webBrowser, &result ); if ( NS_FAILED( result ) || ! webNav ) { return NS_ERROR_FAILURE; } if ( webBrowser ) { // I really hope we don't need this, it calls in nsIWidget.h which calls // in a bunch of local includes we don't want /* #ifdef NS_UNIX // save the window id of the newly created window nsCOMPtr<nsIWidget> mozWidget; baseWindow->GetMainWidget(getter_AddRefs(mozWidget)); GdkWindow *tmp_window = static_cast<GdkWindow *> (mozWidget->GetNativeData(NS_NATIVE_WINDOW)); // and, thanks to superwin we actually need the parent of that. tmp_window = gdk_window_get_parent(tmp_window); // save the widget ID - it should be the mozarea of the window. gpointer data = nsnull; gdk_window_get_user_data(tmp_window, &data); this->nativeMozWidget = static_cast<Handle *> (data); #endif */ return NS_OK; } return NS_ERROR_FAILURE; }