NOT PART OF BUILD. Implement open in new window popup, add uri listener to block popups, reduce use of ns(C)String to avoid linker issues

This commit is contained in:
locka%iol.ie 2003-07-02 21:52:42 +00:00
Родитель 7e9d3920ed
Коммит ce2c2c6cca
11 изменённых файлов: 135 добавлений и 41 удалений

Просмотреть файл

@ -31,6 +31,8 @@
#include "global.h"
#include "wx/strconv.h"
#include "BrowserFrame.h"
#include "nsIURI.h"
@ -46,6 +48,8 @@ BEGIN_EVENT_TABLE(BrowserFrame, GeckoFrame)
EVT_MENU(XRCID("browse_home"), BrowserFrame::OnBrowserHome)
EVT_BUTTON(XRCID("browser_go"), BrowserFrame::OnBrowserGo)
EVT_TEXT_ENTER(XRCID("url"), BrowserFrame::OnBrowserUrl)
EVT_MENU(XRCID("browser_open_in_new_window"),
BrowserFrame::OnBrowserOpenLinkInNewWindow)
END_EVENT_TABLE()
BrowserFrame::BrowserFrame(wxWindow* aParent)
@ -59,8 +63,31 @@ BrowserFrame::BrowserFrame(wxWindow* aParent)
SetupDefaultGeckoWindow();
CreateStatusBar();
}
OnBrowserHome(wxCommandEvent());
nsresult BrowserFrame::LoadURI(const wchar_t *aURI)
{
if (mWebBrowser)
{
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
if (webNav)
{
return webNav->LoadURI(aURI,
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
}
}
return NS_ERROR_FAILURE;
}
nsresult BrowserFrame::LoadURI(const char *aURI)
{
wxMBConv conv;
return LoadURI(conv.cWX2WC(aURI));
}
@ -78,19 +105,11 @@ void BrowserFrame::OnFilePrint(wxCommandEvent & WXUNUSED(event))
void BrowserFrame::OnBrowserGo(wxCommandEvent & WXUNUSED(event))
{
if (mWebBrowser)
wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
wxString url = txtCtrl->GetValue();
if (!url.IsEmpty())
{
wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
wxString url = txtCtrl->GetValue();
if (!url.IsEmpty())
{
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
webNav->LoadURI(NS_ConvertASCIItoUCS2(url.c_str()).get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
}
LoadURI(url);
}
}
@ -164,17 +183,15 @@ void BrowserFrame::OnUpdateBrowserStop(wxUpdateUIEvent &event)
void BrowserFrame::OnBrowserHome(wxCommandEvent & WXUNUSED(event))
{
if (mWebBrowser)
{
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
webNav->LoadURI(NS_ConvertASCIItoUCS2("http://www.mozilla.org/projects/embedding/").get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
}
LoadURI("http://www.mozilla.org/projects/embedding/");
}
void BrowserFrame::OnBrowserOpenLinkInNewWindow(wxCommandEvent & WXUNUSED(event))
{
BrowserFrame* frame = new BrowserFrame(NULL);
frame->Show(TRUE);
frame->LoadURI(mContextLinkUrl.get());
}
///////////////////////////////////////////////////////////////////////////////
// GeckoContainerUI overrides
@ -224,6 +241,9 @@ void BrowserFrame::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *a
{
return;
}
mContextLinkUrl.SetLength(0);
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(event);
if (mouseEvent)
{
@ -254,6 +274,8 @@ void BrowserFrame::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *a
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
{
menuName = "context_browser_link";
aContextMenuInfo->GetAssociatedLink(mContextLinkUrl);
}
else if (aContextFlags & nsIContextMenuListener2::CONTEXT_INPUT)
{

Просмотреть файл

@ -40,6 +40,8 @@ class BrowserFrame :
protected:
DECLARE_EVENT_TABLE()
nsAutoString mContextLinkUrl;
void OnBrowserUrl(wxCommandEvent &event);
void OnBrowserGo(wxCommandEvent &event);
void OnBrowserBack(wxCommandEvent &event);
@ -47,6 +49,7 @@ protected:
void OnBrowserReload(wxCommandEvent &event);
void OnBrowserStop(wxCommandEvent &event);
void OnBrowserHome(wxCommandEvent &event);
void OnBrowserOpenLinkInNewWindow(wxCommandEvent & event);
void OnUpdateBrowserBack(wxUpdateUIEvent &event);
void OnUpdateBrowserForward(wxUpdateUIEvent &event);
void OnUpdateBrowserStop(wxUpdateUIEvent &event);
@ -55,6 +58,9 @@ protected:
public :
BrowserFrame(wxWindow* aParent);
nsresult LoadURI(const char *aURI);
nsresult LoadURI(const wchar_t *aURI);
// GeckoContainerUI overrides
virtual nsresult CreateBrowserWindow(PRUint32 aChromeFlags,
nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow);

Просмотреть файл

@ -31,6 +31,8 @@
#include "global.h"
#include "wx/strconv.h"
#include "nsIWebNavigation.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"
@ -68,10 +70,11 @@ void ChatFrame::OnChat(wxCommandEvent &event)
wxTextCtrl *chatCtrl = (wxTextCtrl *) FindWindowById(XRCID("chat"), this);
if (chatCtrl)
{
wxString txt = chatCtrl->GetValue();
nsAutoString htmlFragment(NS_LITERAL_STRING("<p>Foo: "));
htmlFragment.AppendWithConversion(txt.c_str());
htmlDoc->Writeln(htmlFragment);
wxString html("<p>Foo: ");
html += chatCtrl->GetValue();
wxMBConv conv;
nsAutoString htmlU(conv.cWX2WC(html));
htmlDoc->Writeln(htmlU);
chatCtrl->SetValue("");
}
}

Просмотреть файл

@ -34,6 +34,7 @@
#include "nsIProfile.h"
#include "nsIWindowWatcher.h"
#include "nsMemory.h"
#include "nsEmbedString.h"
#include "BrowserFrame.h"
#include "MailFrame.h"
@ -135,7 +136,7 @@ bool EmbedApp::OnInit()
// Create the main frame window
BrowserFrame* frame = new BrowserFrame(NULL);
frame->Show(TRUE);
// frame->OnBrowserHome(wxCommandEvent());
SetTopWindow(frame);
@ -153,6 +154,7 @@ int EmbedApp::OnExit()
profileService->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST);
}
NS_TermEmbedding();
return 0;
}

Просмотреть файл

@ -32,7 +32,6 @@
// Mozilla Includes
//#include "nsIGenericFactory.h"
#include "nsIComponentManager.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
@ -41,16 +40,20 @@
#include "nsIDOMWindowInternal.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIURIContentListener.h"
#include "nsCWebBrowser.h"
#include "nsCRT.h"
#include "GeckoContainer.h"
GeckoContainer::GeckoContainer(GeckoContainerUI *pUI, const char *aRole) :
mUI(pUI),
mNativeWindow(nsnull),
mSizeSet(PR_FALSE)
mSizeSet(PR_FALSE),
mIsChromeContainer(PR_FALSE),
mIsURIContentListener(PR_TRUE)
{
NS_ASSERTION(mUI, "No GeckoContainerUI! How do you expect this to work???");
if (aRole)
@ -74,10 +77,13 @@ nsresult GeckoContainer::CreateBrowser(PRInt32 aX, PRInt32 aY,
if (!mWebBrowser || NS_FAILED(rv))
return NS_ERROR_FAILURE;
(void)mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
dsti->SetItemType(
mIsChromeContainer ?
nsIDocShellTreeItem::typeChromeWrapper :
nsIDocShellTreeItem::typeContentWrapper);
nsCOMPtr<nsIBaseWindow> browserBaseWindow = do_QueryInterface(mWebBrowser);
@ -96,6 +102,10 @@ nsresult GeckoContainer::CreateBrowser(PRInt32 aX, PRInt32 aY,
(void)mWebBrowser->AddWebBrowserListener(thisListener,
NS_GET_IID(nsIWebProgressListener));
if (mIsURIContentListener)
mWebBrowser->SetParentURIContentListener(NS_STATIC_CAST(nsIURIContentListener *, this));
// The window has been created. Now register for history notifications
// mWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsISHistoryListener));
@ -140,6 +150,7 @@ NS_INTERFACE_MAP_BEGIN(GeckoContainer)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) // optional
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener2)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_ENTRY(nsIGeckoContainer)
@ -446,9 +457,53 @@ NS_IMETHODIMP GeckoContainer::Observe(nsISupports *aSubject, const char *aTopic,
}
//*****************************************************************************
// GeckoContainer::nsIContextMenuListener
// GeckoContainer::nsIURIContentListener
//*****************************************************************************
/* boolean onStartURIOpen (in nsIURI aURI); */
NS_IMETHODIMP GeckoContainer::OnStartURIOpen(nsIURI *aURI, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean doContent (in string aContentType, in boolean aIsContentPreferred, in nsIRequest aRequest, out nsIStreamListener aContentHandler); */
NS_IMETHODIMP GeckoContainer::DoContent(const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest, nsIStreamListener **aContentHandler, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean isPreferred (in string aContentType, out string aDesiredContentType); */
NS_IMETHODIMP GeckoContainer::IsPreferred(const char *aContentType, char **aDesiredContentType, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* boolean canHandleContent (in string aContentType, in boolean aIsContentPreferred, out string aDesiredContentType); */
NS_IMETHODIMP GeckoContainer::CanHandleContent(const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsISupports loadCookie; */
NS_IMETHODIMP GeckoContainer::GetLoadCookie(nsISupports * *aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GeckoContainer::SetLoadCookie(nsISupports * aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsIURIContentListener parentContentListener; */
NS_IMETHODIMP GeckoContainer::GetParentContentListener(nsIURIContentListener * *aParentContentListener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GeckoContainer::SetParentContentListener(nsIURIContentListener * aParentContentListener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// GeckoContainer::nsIContextMenuListener2
//*****************************************************************************

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIWebBrowser.h"
#include "nsIURIContentListener.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsIContextMenuListener.h"
@ -70,7 +71,9 @@ public:
NS_IMETHOD GetContainerUI(GeckoContainerUI **pUI) = 0;
};
#define NS_DECL_NSIGECKOCONTAINER
#define NS_DECL_NSIGECKOCONTAINER \
NS_IMETHOD GetRole(nsACString &aRole); \
NS_IMETHOD GetContainerUI(GeckoContainerUI **pUI);
class GeckoContainer :
public nsIWebBrowserChrome,
@ -81,6 +84,7 @@ class GeckoContainer :
public nsIObserver,
public nsIContextMenuListener2,
public nsITooltipListener,
public nsIURIContentListener,
public nsIGeckoContainer,
public nsSupportsWeakReference
{
@ -101,12 +105,9 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSICONTEXTMENULISTENER2
NS_DECL_NSITOOLTIPLISTENER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIGECKOCONTAINER
// nsIGeckoContainer
NS_IMETHOD GetRole(nsACString &aRole);
NS_IMETHOD GetContainerUI(GeckoContainerUI **pUI);
nsresult CreateBrowser(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nativeWindow aParent,
nsIWebBrowser **aBrowser);
@ -123,6 +124,9 @@ protected:
PRUint32 mChromeFlags;
PRBool mContinueModalLoop;
PRBool mSizeSet;
PRBool mIsChromeContainer;
PRBool mIsURIContentListener;
nsCString mRole;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIWebBrowserChrome> mDependentParent; // opener (for dependent windows only)

Просмотреть файл

@ -68,7 +68,6 @@ bool GeckoFrame::SetupGeckoWindow(GeckoWindow *aGeckoWindow, GeckoContainerUI *a
PRUint32 aChromeFlags = nsIWebBrowserChrome::CHROME_ALL;
geckoContainer->SetChromeFlags(aChromeFlags);
geckoContainer->SetParent(nsnull);
wxSize size = mGeckoWnd->GetClientSize();
// Insert the browser

Просмотреть файл

@ -31,7 +31,6 @@
#include "GeckoProtocolHandler.h"
#include "nsString.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsIGenericFactory.h"
@ -43,6 +42,7 @@
#include "nsIByteArrayInputStream.h"
#include "nsIStreamListener.h"
#include "nsIInputStreamPump.h"
#include "nsEmbedString.h"
// Everytime register handler is called, it picks the next available CID in the
// list.
@ -360,7 +360,7 @@ GeckoProtocolChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aCont
mURI->GetScheme(scheme);
for (PRUint32 i = 0; i < gUsedCIDs; i++)
{
if (scheme.EqualsIgnoreCase(gCallbacks[i].mScheme.get()))
if (stricmp(scheme.get(), gCallbacks[i].mScheme.get()) == 0)
{
rv = gCallbacks[i].mCallback->GetData(
mURI, NS_STATIC_CAST(nsIChannel *,this), mContentType, &mData, &mContentLength);

Просмотреть файл

@ -33,6 +33,7 @@
#include "GeckoContainer.h"
#include "nsIWebBrowserChrome.h"
#include "nsString.h"
GeckoWindowCreator::GeckoWindowCreator()
{
@ -62,7 +63,7 @@ GeckoWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *parent,
nsCAutoString role;
geckoContainer->GetRole(role);
if (role.EqualsIgnoreCase("browser"))
if (stricmp(role.get(), "browser") == 0)
{
GeckoContainerUI *pUI = NULL;
geckoContainer->GetContainerUI(&pUI);

Просмотреть файл

@ -33,6 +33,7 @@
#include "MailFrame.h"
#include "GeckoProtocolHandler.h"
#include "nsEmbedString.h"
#include "nsIURI.h"

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsEmbedAPI.h"
#include "nsIWeakReference.h"
#include "nsIWeakReferenceUtils.h"
#include "nsEmbedString.h"
extern void InitXmlResource(); // Generated by wxrc in C++ source