fixes and updates for the embedding, base on the gtk code base
This commit is contained in:
briane%qnx.com 2001-12-07 14:30:38 +00:00
Родитель ba0136d403
Коммит f7e61d4f3e
30 изменённых файлов: 4251 добавлений и 622 удалений

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

@ -0,0 +1,152 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <strings.h>
#include <nsXPIDLString.h>
#include "nsIURI.h"
#include "EmbedContentListener.h"
#include "EmbedPrivate.h"
#include "PtMozilla.h"
EmbedContentListener::EmbedContentListener(void)
{
NS_INIT_REFCNT();
mOwner = nsnull;
}
EmbedContentListener::~EmbedContentListener()
{
}
NS_IMPL_ISUPPORTS1(EmbedContentListener,
nsIURIContentListener)
nsresult
EmbedContentListener::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::OnStartURIOpen(nsIURI *aURI,
PRBool *aAbortOpen)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb = NULL;
PtCallbackInfo_t cbinfo;
PtMozillaUrlCb_t url;
if (!moz->open_cb)
return NS_OK;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &url;
cbinfo.reason = Pt_CB_MOZ_OPEN;
cb = moz->open_cb;
aURI->GetSpec(&(url.url));
if (PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo) == Pt_END)
{
*aAbortOpen = PR_TRUE;
return NS_ERROR_ABORT;
}
*aAbortOpen = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::DoContent(const char *aContentType,
PRBool aIsContentPreferred,
nsIRequest *aRequest,
nsIStreamListener **aContentHandler,
PRBool *aAbortProcess)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::IsPreferred(const char *aContentType,
char **aDesiredContentType,
PRBool *aCanHandleContent)
{
if (aContentType &&
(!strcasecmp(aContentType, "text/html") ||
!strcasecmp(aContentType, "text/plain") ||
!strcasecmp(aContentType, "application/vnd.mozilla.xul+xml") ||
!strcasecmp(aContentType, "text/rdf") ||
!strcasecmp(aContentType, "text/xml") ||
!strcasecmp(aContentType, "application/xml") ||
!strcasecmp(aContentType, "application/xhtml+xml") ||
!strcasecmp(aContentType, "text/css") ||
!strcasecmp(aContentType, "image/gif") ||
!strcasecmp(aContentType, "image/jpeg") ||
!strcasecmp(aContentType, "image/png") ||
!strcasecmp(aContentType, "image/tiff") ||
!strcasecmp(aContentType, "application/http-index-format"))) {
*aCanHandleContent = PR_TRUE;
}
else {
*aCanHandleContent = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::CanHandleContent(const char *aContentType,
PRBool aIsContentPreferred,
char **aDesiredContentType,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,49 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedContentListener_h
#define __EmbedContentListener_h
#include <nsIURIContentListener.h>
class EmbedPrivate;
class EmbedContentListener : public nsIURIContentListener
{
public:
EmbedContentListener();
virtual ~EmbedContentListener();
nsresult Init (EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
NS_DECL_NSIURICONTENTLISTENER
private:
EmbedPrivate *mOwner;
};
#endif /* __EmbedContentListener_h */

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

@ -0,0 +1,118 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <nsCOMPtr.h>
#include <nsIDOMMouseEvent.h>
#include "nsIDOMKeyEvent.h"
#include "EmbedEventListener.h"
#include "EmbedPrivate.h"
EmbedEventListener::EmbedEventListener(void)
{
NS_INIT_REFCNT();
mOwner = nsnull;
}
EmbedEventListener::~EmbedEventListener()
{
}
NS_IMPL_ADDREF(EmbedEventListener)
NS_IMPL_RELEASE(EmbedEventListener)
NS_INTERFACE_MAP_BEGIN(EmbedEventListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
NS_INTERFACE_MAP_END
nsresult
EmbedEventListener::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
return NS_OK;
}
// All of the event listeners below return NS_OK to indicate that the
// event should not be consumed in the default case.
NS_IMETHODIMP
EmbedEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,67 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedEventListener_h
#define __EmbedEventListener_h
#include <nsIDOMKeyListener.h>
#include <nsIDOMMouseListener.h>
class EmbedPrivate;
class EmbedEventListener : public nsIDOMKeyListener,
public nsIDOMMouseListener
{
public:
EmbedEventListener();
virtual ~EmbedEventListener();
nsresult Init(EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMKeyListener
NS_IMETHOD KeyDown(nsIDOMEvent* aDOMEvent);
NS_IMETHOD KeyUp(nsIDOMEvent* aDOMEvent);
NS_IMETHOD KeyPress(nsIDOMEvent* aDOMEvent);
// nsIDOMMouseListener
NS_IMETHOD MouseDown(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseClick(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseDblClick(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseOver(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseOut(nsIDOMEvent* aDOMEvent);
private:
EmbedPrivate *mOwner;
};
#endif /* __EmbedEventListener_h */

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

@ -0,0 +1,97 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <strings.h>
#include <nsXPIDLString.h>
#include "nsIURI.h"
#include "EmbedPrintListener.h"
#include "EmbedPrivate.h"
#include "PtMozilla.h"
EmbedPrintListener::EmbedPrintListener(void)
{
NS_INIT_REFCNT();
mOwner = nsnull;
}
EmbedPrintListener::~EmbedPrintListener()
{
}
NS_IMPL_ISUPPORTS1(EmbedPrintListener, nsIPrintListener)
nsresult
EmbedPrintListener::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
return NS_OK;
}
void
EmbedPrintListener::InvokePrintCallback(int status, unsigned int cur, unsigned int max)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaPrintStatusCb_t pstatus;
if (!moz->print_status_cb)
return;
cb = moz->print_status_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_PRINT_STATUS;
cbinfo.cbdata = &pstatus;
memset(&pstatus, 0, sizeof(PtMozillaPrintStatusCb_t));
pstatus.status = status;
pstatus.max = max;
pstatus.cur = cur;
PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
}
/* void OnStartPrinting (); */
NS_IMETHODIMP
EmbedPrintListener::OnStartPrinting()
{
InvokePrintCallback(Pt_MOZ_PRINT_START, 0, 0);
return NS_OK;
}
/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */
NS_IMETHODIMP
EmbedPrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax)
{
InvokePrintCallback(Pt_MOZ_PRINT_PROGRESS, aProgress, aProgressMax);
return NS_OK;
}
/* void OnEndPrinting (in PRUint32 aStatus); */
NS_IMETHODIMP
EmbedPrintListener::OnEndPrinting(PRUint32 aStatus)
{
InvokePrintCallback(Pt_MOZ_PRINT_COMPLETE, 0, 0);
return NS_OK;
}

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

@ -0,0 +1,51 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedPrintListener_h
#define __EmbedPrintListener_h
#include <nsIPrintListener.h>
class EmbedPrivate;
class EmbedPrintListener : public nsIPrintListener
{
public:
EmbedPrintListener();
virtual ~EmbedPrintListener();
nsresult Init (EmbedPrivate *aOwner);
void InvokePrintCallback(int, unsigned int, unsigned int);
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTLISTENER
private:
EmbedPrivate *mOwner;
};
#endif /* __EmbedPrintListener_h */

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

@ -0,0 +1,807 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <nsIDocShell.h>
#include <nsIURI.h>
#include <nsIWebProgress.h>
#include <nsIURIFixup.h>
#include "nsReadableUtils.h"
#include "nsIWidget.h"
// for NS_APPSHELL_CID
#include <nsWidgetsCID.h>
// for do_GetInterface
#include <nsIInterfaceRequestor.h>
#include <nsIInterfaceRequestorUtils.h>
// for do_CreateInstance
#include <nsIComponentManager.h>
#include <nsIPrintSettings.h>
#include "nsPrintSettingsImpl.h"
// for initializing our window watcher service
#include <nsIWindowWatcher.h>
#include <nsILocalFile.h>
#include <nsEmbedAPI.h>
#include <nsString.h>
// all of the crap that we need for event listeners
// and when chrome windows finish loading
#include <nsIDOMWindow.h>
#include <nsPIDOMWindow.h>
#include <nsIDOMWindowInternal.h>
#include <nsIChromeEventHandler.h>
#include <nsIContentViewer.h>
#include <nsIContentViewerEdit.h>
#include "nsIWebBrowserPrint.h"
#include "nsIClipboardCommands.h"
#include "docshell/nsCDefaultURIFixup.h"
#include "nsGfxCIID.h"
// for the focus hacking we need to do
#include <nsIFocusController.h>
// for profiles
#include <nsMPFileLocProvider.h>
#include "nsIWebBrowserPrint.h"
#include "nsIPrintOptions.h"
// all of our local includes
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
#include "EmbedProgress.h"
#include "EmbedContentListener.h"
#include "EmbedEventListener.h"
#include "EmbedWindowCreator.h"
#include "EmbedStream.h"
#include "EmbedPrintListener.h"
#include "PtMozilla.h"
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static const char sWatcherContractID[] = "@mozilla.org/embedcomp/window-watcher;1";
nsIAppShell *EmbedPrivate::sAppShell = nsnull;
nsIPref *EmbedPrivate::sPrefs = nsnull;
nsVoidArray *EmbedPrivate::sWindowList = nsnull;
EmbedPrivate::EmbedPrivate(void)
{
mOwningWidget = nsnull;
mWindow = nsnull;
mProgress = nsnull;
mContentListener = nsnull;
mEventListener = nsnull;
mStream = nsnull;
mChromeMask = 0;
mIsChrome = PR_FALSE;
mChromeLoaded = PR_FALSE;
mListenersAttached = PR_FALSE;
mMozWindowWidget = 0;
if (!sWindowList) {
sWindowList = new nsVoidArray();
}
sWindowList->AppendElement(this);
}
EmbedPrivate::~EmbedPrivate()
{
}
nsresult
EmbedPrivate::Init(PtWidget_t *aOwningWidget)
{
// are we being re-initialized?
if (mOwningWidget)
return NS_OK;
// hang on with a reference to the owning widget
mOwningWidget = aOwningWidget;
// Create our embed window, and create an owning reference to it and
// initialize it. It is assumed that this window will be destroyed
// when we go out of scope.
mWindow = new EmbedWindow();
mWindowGuard = NS_STATIC_CAST(nsIWebBrowserChrome *, mWindow);
mWindow->Init(this);
// Create our progress listener object, make an owning reference,
// and initialize it. It is assumed that this progress listener
// will be destroyed when we go out of scope.
mProgress = new EmbedProgress();
mProgressGuard = NS_STATIC_CAST(nsIWebProgressListener *,
mProgress);
mProgress->Init(this);
// Create our content listener object, initialize it and attach it.
// It is assumed that this will be destroyed when we go out of
// scope.
mContentListener = new EmbedContentListener();
mContentListenerGuard = mContentListener;
mContentListener->Init(this);
// Create our key listener object and initialize it. It is assumed
// that this will be destroyed before we go out of scope.
mEventListener = new EmbedEventListener();
mEventListenerGuard =
NS_STATIC_CAST(nsISupports *, NS_STATIC_CAST(nsIDOMKeyListener *,
mEventListener));
mEventListener->Init(this);
// Create our print listener object, make an owning reference,
// and initialize it. It is assumed that this print listener
// will be destroyed when we go out of scope.
mPrint = new EmbedPrintListener();
mPrintGuard = NS_STATIC_CAST(nsIPrintListener *, mPrint);
mPrint->Init(this);
m_PrintSettings = (nsIPrintSettings*)new nsPrintSettings();
// has the window creator service been set up?
static int initialized = PR_FALSE;
// Set up our window creator ( only once )
if (!initialized)
{
// We set this flag here instead of on success. If it failed we
// don't want to keep trying and leaking window creator objects.
initialized = PR_TRUE;
// create our local object
EmbedWindowCreator *creator = new EmbedWindowCreator();
nsCOMPtr<nsIWindowCreator> windowCreator;
windowCreator = NS_STATIC_CAST(nsIWindowCreator *, creator);
// Attach it via the watcher service
nsCOMPtr<nsIWindowWatcher> watcher = do_GetService(sWatcherContractID);
if (watcher)
watcher->SetWindowCreator(windowCreator);
}
if (!sPrefs)
{
// get prefs
nsresult rv;
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_CONTRACTID, &rv));
if (pref)
{
sPrefs = pref.get();
NS_ADDREF(sPrefs);
//sPrefs->ResetPrefs();
sPrefs->ReadUserPrefs(nsnull);
}
}
return NS_OK;
}
nsIPref *
EmbedPrivate::GetPrefs()
{
return (sPrefs);
}
nsresult
EmbedPrivate::Setup()
{
// Get the nsIWebBrowser object for our embedded window.
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// get a handle on the navigation object
mNavigation = do_QueryInterface(webBrowser);
mFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
// Create our session history object and tell the navigation object
// to use it. We need to do this before we create the web browser
// window.
mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID);
mNavigation->SetSessionHistory(mSessionHistory);
// create the window
mWindow->CreateWindow();
// bind the progress listener to the browser object
nsCOMPtr<nsISupportsWeakReference> supportsWeak;
supportsWeak = do_QueryInterface(mProgressGuard);
nsCOMPtr<nsIWeakReference> weakRef;
supportsWeak->GetWeakReference(getter_AddRefs(weakRef));
webBrowser->AddWebBrowserListener(weakRef, nsIWebProgressListener::GetIID());
// set ourselves as the parent uri content listener
nsCOMPtr<nsIURIContentListener> uriListener;
uriListener = do_QueryInterface(mContentListenerGuard);
webBrowser->SetParentURIContentListener(uriListener);
return NS_OK;
}
void
EmbedPrivate::Show(void)
{
// Get the nsIWebBrowser object for our embedded window.
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// and set the visibility on the thing
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(webBrowser);
baseWindow->SetVisibility(PR_TRUE);
}
void
EmbedPrivate::Hide(void)
{
// Get the nsIWebBrowser object for our embedded window.
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// and set the visibility on the thing
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(webBrowser);
baseWindow->SetVisibility(PR_FALSE);
}
void
EmbedPrivate::Position(PRUint32 aX, PRUint32 aY)
{
mWindow->mBaseWindow->SetPosition(aX, aY);
}
void
EmbedPrivate::Size(PRUint32 aWidth, PRUint32 aHeight)
{
mWindow->mBaseWindow->SetSize(aWidth, aHeight, PR_TRUE);
}
void
EmbedPrivate::Destroy(void)
{
// Get the nsIWebBrowser object for our embedded window.
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// Release our progress listener
nsCOMPtr<nsISupportsWeakReference> supportsWeak;
supportsWeak = do_QueryInterface(mProgressGuard);
nsCOMPtr<nsIWeakReference> weakRef;
supportsWeak->GetWeakReference(getter_AddRefs(weakRef));
webBrowser->RemoveWebBrowserListener(weakRef,
nsIWebProgressListener::GetIID());
weakRef = nsnull;
supportsWeak = nsnull;
// Release our content listener
webBrowser->SetParentURIContentListener(nsnull);
mContentListenerGuard = nsnull;
mContentListener = nsnull;
// Now that we have removed the listener, release our progress
// object
mProgressGuard = nsnull;
mProgress = nsnull;
// detach our event listeners and release the event receiver
DetachListeners();
if (mEventReceiver)
mEventReceiver = nsnull;
// remove this from the window list
sWindowList->RemoveElement(this);
// destroy our child window
mWindow->ReleaseChildren();
// release navigation
mNavigation = nsnull;
mFixup = nsnull;
m_PrintSettings = nsnull;
// release session history
mSessionHistory = nsnull;
mOwningWidget = nsnull;
mMozWindowWidget = 0;
}
void
EmbedPrivate::SetURI(const char *aURI)
{
mURI.AssignWithConversion(aURI);
}
void
EmbedPrivate::LoadCurrentURI(void)
{
if (mURI.Length())
mNavigation->LoadURI(mURI.get(), // URI string
nsIWebNavigation::LOAD_FLAGS_NONE, // Load flags
nsnull, // Refering URI
nsnull, // Post data
nsnull); // extra headers
}
void
EmbedPrivate::Stop(void)
{
if (mNavigation)
mNavigation->Stop(nsIWebNavigation::STOP_ALL);
}
void
EmbedPrivate::Reload(int32_t flags)
{
PRUint32 reloadFlags = 0;
// map the external API to the internal web navigation API.
switch (flags)
{
case MOZ_EMBED_FLAG_RELOADNORMAL:
reloadFlags = 0;
break;
case MOZ_EMBED_FLAG_RELOADBYPASSCACHE:
reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE;
break;
case MOZ_EMBED_FLAG_RELOADBYPASSPROXY:
reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
break;
case MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE:
reloadFlags = (nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY |
nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE);
break;
case MOZ_EMBED_FLAG_RELOADCHARSETCHANGE:
reloadFlags = nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE;
break;
default:
reloadFlags = 0;
break;
}
if (mNavigation)
mNavigation->Reload(reloadFlags);
}
void
EmbedPrivate::Back(void)
{
if (mNavigation)
mNavigation->GoBack();
}
void
EmbedPrivate::Forward(void)
{
if (mNavigation)
mNavigation->GoForward();
}
PRBool
EmbedPrivate::CanGoBack()
{
PRBool nsresult = PR_FALSE;
if (mNavigation)
mNavigation->GetCanGoBack(&nsresult);
return (nsresult);
}
PRBool
EmbedPrivate::CanGoForward()
{
PRBool nsresult = PR_FALSE;
if (mNavigation)
mNavigation->GetCanGoForward(&nsresult);
return (nsresult);
}
void
EmbedPrivate::Cut()
{
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(mWindow->mWebBrowser));
if (clipboard)
clipboard->CutSelection();
}
void
EmbedPrivate::Copy()
{
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(mWindow->mWebBrowser));
if (clipboard)
clipboard->CopySelection();
}
void
EmbedPrivate::Paste()
{
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(mWindow->mWebBrowser));
if (clipboard)
clipboard->Paste();
}
void
EmbedPrivate::SelectAll()
{
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(mWindow->mWebBrowser));
if (clipboard)
clipboard->SelectAll();
}
void
EmbedPrivate::Clear()
{
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(mWindow->mWebBrowser));
if (clipboard)
clipboard->SelectNone();
}
void
EmbedPrivate::Print(PpPrintContext_t *pc)
{
nsCOMPtr<nsIDOMWindow> window;
mWindow->mWebBrowser->GetContentDOMWindow(getter_AddRefs(window));
nsCOMPtr<nsIWebBrowserPrint> print( do_GetInterface( mWindow->mWebBrowser ) );
m_PrintSettings->SetEndPageRange((PRInt32) pc);
m_PrintSettings->SetOrientation(1);
print->Print(window, m_PrintSettings, mPrint);
}
nsresult
EmbedPrivate::OpenStream(const char *aBaseURI, const char *aContentType)
{
nsresult rv;
if (!mStream) {
mStream = new EmbedStream();
mStreamGuard = do_QueryInterface(mStream);
mStream->InitOwner(this);
rv = mStream->Init();
if (NS_FAILED(rv))
return rv;
}
rv = mStream->OpenStream(aBaseURI, aContentType);
return rv;
}
int
EmbedPrivate::SaveAs(char *fname)
{
if (mWindow)
return (mWindow->SaveAs(fname));
return (1);
}
int
EmbedPrivate::SaveURI(char *aURI, char *fname)
{
if (mWindow && mFixup)
{
nsIURI* uri;
nsCString u(aURI);
nsresult rv = mFixup->CreateFixupURI(ToNewUnicode(u), 0, &(uri));
return (mWindow->SaveURI(uri, fname));
}
return (1);
}
void
EmbedPrivate::CancelSaveURI()
{
if (mWindow)
mWindow->CancelSaveURI();
}
nsresult
EmbedPrivate::AppendToStream(const char *aData, PRInt32 aLen)
{
if (!mStream)
return NS_ERROR_FAILURE;
// Attach listeners to this document since in some cases we don't
// get updates for content added this way.
ContentStateChange();
return mStream->AppendToStream(aData, aLen);
}
nsresult
EmbedPrivate::CloseStream(void)
{
nsresult rv;
if (!mStream)
return NS_ERROR_FAILURE;
rv = mStream->CloseStream();
// release
mStream = 0;
mStreamGuard = 0;
return rv;
}
/* static */
EmbedPrivate *
EmbedPrivate::FindPrivateForBrowser(nsIWebBrowserChrome *aBrowser)
{
if (!sWindowList)
return nsnull;
// Get the number of browser windows.
PRInt32 count = sWindowList->Count();
// This function doesn't get called very often at all ( only when
// creating a new window ) so it's OK to walk the list of open
// windows.
for (int i = 0; i < count; i++)
{
EmbedPrivate *tmpPrivate = NS_STATIC_CAST(EmbedPrivate *,
sWindowList->ElementAt(i));
// get the browser object for that window
nsIWebBrowserChrome *chrome = NS_STATIC_CAST(nsIWebBrowserChrome *,
tmpPrivate->mWindow);
if (chrome == aBrowser)
return tmpPrivate;
}
return nsnull;
}
void
EmbedPrivate::ContentStateChange(void)
{
// we don't attach listeners to chrome
if (mListenersAttached && !mIsChrome)
return;
GetListener();
if (!mEventReceiver)
return;
AttachListeners();
}
void
EmbedPrivate::ContentFinishedLoading(void)
{
if (mIsChrome) {
// We're done loading.
mChromeLoaded = PR_TRUE;
// get the web browser
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// get the content DOM window for that web browser
nsCOMPtr<nsIDOMWindow> domWindow;
webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow) {
NS_WARNING("no dom window in content finished loading\n");
return;
}
// resize the content
domWindow->SizeToContent();
// and since we're done loading show the window, assuming that the
// visibility flag has been set.
PRBool visibility;
mWindow->GetVisibility(&visibility);
if (visibility)
mWindow->SetVisibility(PR_TRUE);
}
}
// handle focus in and focus out events
void
EmbedPrivate::TopLevelFocusIn(void)
{
nsCOMPtr<nsPIDOMWindow> piWin;
GetPIDOMWindow(getter_AddRefs(piWin));
if (!piWin)
return;
nsCOMPtr<nsIFocusController> focusController;
piWin->GetRootFocusController(getter_AddRefs(focusController));
if (focusController)
focusController->SetActive(PR_TRUE);
}
void
EmbedPrivate::TopLevelFocusOut(void)
{
nsCOMPtr<nsPIDOMWindow> piWin;
GetPIDOMWindow(getter_AddRefs(piWin));
if (!piWin)
return;
nsCOMPtr<nsIFocusController> focusController;
piWin->GetRootFocusController(getter_AddRefs(focusController));
if (focusController)
focusController->SetActive(PR_FALSE);
}
void
EmbedPrivate::ChildFocusIn(void)
{
nsCOMPtr<nsPIDOMWindow> piWin;
GetPIDOMWindow(getter_AddRefs(piWin));
if (!piWin)
return;
piWin->Activate();
}
void
EmbedPrivate::ChildFocusOut(void)
{
nsCOMPtr<nsPIDOMWindow> piWin;
GetPIDOMWindow(getter_AddRefs(piWin));
if (!piWin)
return;
piWin->Deactivate();
// but the window is still active until the toplevel gets a focus
// out
nsCOMPtr<nsIFocusController> focusController;
piWin->GetRootFocusController(getter_AddRefs(focusController));
if (focusController)
focusController->SetActive(PR_TRUE);
}
// Get the event listener for the chrome event handler.
void
EmbedPrivate::GetListener(void)
{
if (mEventReceiver)
return;
nsCOMPtr<nsPIDOMWindow> piWin;
GetPIDOMWindow(getter_AddRefs(piWin));
if (!piWin)
return;
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
piWin->GetChromeEventHandler(getter_AddRefs(chromeHandler));
mEventReceiver = do_QueryInterface(chromeHandler);
}
// attach key and mouse event listeners
void
EmbedPrivate::AttachListeners(void)
{
if (!mEventReceiver || mListenersAttached)
return;
nsIDOMEventListener *eventListener =
NS_STATIC_CAST(nsIDOMEventListener *,
NS_STATIC_CAST(nsIDOMKeyListener *, mEventListener));
// add the key listener
nsresult rv;
rv = mEventReceiver->AddEventListenerByIID(eventListener,
NS_GET_IID(nsIDOMKeyListener));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to add key listener\n");
return;
}
rv = mEventReceiver->AddEventListenerByIID(eventListener,
NS_GET_IID(nsIDOMMouseListener));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to add mouse listener\n");
return;
}
// ok, all set.
mListenersAttached = PR_TRUE;
}
void
EmbedPrivate::DetachListeners(void)
{
if (!mListenersAttached || !mEventReceiver)
return;
nsIDOMEventListener *eventListener =
NS_STATIC_CAST(nsIDOMEventListener *,
NS_STATIC_CAST(nsIDOMKeyListener *, mEventListener));
nsresult rv;
rv = mEventReceiver->RemoveEventListenerByIID(eventListener,
NS_GET_IID(nsIDOMKeyListener));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to remove key listener\n");
return;
}
rv =
mEventReceiver->RemoveEventListenerByIID(eventListener,
NS_GET_IID(nsIDOMMouseListener));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to remove mouse listener\n");
return;
}
mListenersAttached = PR_FALSE;
}
nsresult
EmbedPrivate::GetPIDOMWindow(nsPIDOMWindow **aPIWin)
{
*aPIWin = nsnull;
// get the web browser
nsCOMPtr<nsIWebBrowser> webBrowser;
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// get the content DOM window for that web browser
nsCOMPtr<nsIDOMWindow> domWindow;
webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow)
return NS_ERROR_FAILURE;
// get the private DOM window
nsCOMPtr<nsPIDOMWindow> domWindowPrivate = do_QueryInterface(domWindow);
// and the root window for that DOM window
nsCOMPtr<nsIDOMWindowInternal> rootWindow;
domWindowPrivate->GetPrivateRoot(getter_AddRefs(rootWindow));
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(rootWindow));
*aPIWin = piWin.get();
if (*aPIWin) {
NS_ADDREF(*aPIWin);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

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

@ -0,0 +1,179 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedPrivate_h
#define __EmbedPrivate_h
#include <nsCOMPtr.h>
#include <nsString.h>
#include <nsIWebNavigation.h>
#include <nsIURIFixup.h>
#include <nsISHistory.h>
#include "nsIExternalHelperAppService.h"
// for our one function that gets the EmbedPrivate via the chrome
// object.
#include <nsIWebBrowserChrome.h>
#include <nsIPrintSettings.h>
#include <nsIAppShell.h>
#include <nsIDOMEventReceiver.h>
#include <nsVoidArray.h>
// for profiles
#include <nsIPref.h>
#include <Pt.h>
class EmbedProgress;
class EmbedWindow;
class EmbedContentListener;
class EmbedEventListener;
class EmbedStream;
class EmbedPrintListener;
class nsPIDOMWindow;
class EmbedPrivate {
public:
EmbedPrivate();
~EmbedPrivate();
nsresult Init (PtWidget_t *aOwningWidget);
nsresult Setup ();
void Unrealize (void);
void Show (void);
void Hide (void);
void Position (PRUint32 aX, PRUint32 aY);
void Size (PRUint32 aWidth, PRUint32 aHeight);
void Destroy (void);
void SetURI (const char *aURI);
void LoadCurrentURI (void);
void Stop (void);
void Reload(int32_t flags);
void Back (void);
void Forward (void);
void Cut (void);
void Copy (void);
void Paste (void);
void SelectAll (void);
void Clear (void);
int SaveAs(char *fname);
int SaveURI(char *uri, char *fname);
void CancelSaveURI();
void Print(PpPrintContext_t *pc);
PRBool CanGoBack();
PRBool CanGoForward();
nsIPref *GetPrefs();
nsresult OpenStream (const char *aBaseURI, const char *aContentType);
nsresult AppendToStream (const char *aData, PRInt32 aLen);
nsresult CloseStream (void);
nsCOMPtr<nsIHelperAppLauncher> app_launcher;
nsCOMPtr<nsISupports> context;
// This function will find the specific EmbedPrivate object for a
// given nsIWebBrowserChrome.
static EmbedPrivate *FindPrivateForBrowser(nsIWebBrowserChrome *aBrowser);
// This is an upcall that will come from the progress listener
// whenever there is a content state change. We need this so we can
// attach event listeners.
void ContentStateChange (void);
// This is an upcall from the progress listener when content is
// finished loading. We have this so that if it's chrome content
// that we can size to content properly and show ourselves if
// visibility is set.
void ContentFinishedLoading(void);
// these let the widget code know when the toplevel window gets and
// looses focus.
void TopLevelFocusIn (void);
void TopLevelFocusOut(void);
// these are when the widget itself gets focus in and focus out
// events
void ChildFocusIn (void);
void ChildFocusOut(void);
PtWidget_t *mOwningWidget;
// all of the objects that we own
EmbedWindow *mWindow;
nsCOMPtr<nsISupports> mWindowGuard;
EmbedProgress *mProgress;
nsCOMPtr<nsISupports> mProgressGuard;
EmbedContentListener *mContentListener;
nsCOMPtr<nsISupports> mContentListenerGuard;
EmbedEventListener *mEventListener;
nsCOMPtr<nsISupports> mEventListenerGuard;
EmbedStream *mStream;
nsCOMPtr<nsISupports> mStreamGuard;
EmbedPrintListener *mPrint;
nsCOMPtr<nsISupports> mPrintGuard;
nsCOMPtr<nsIWebNavigation> mNavigation;
nsCOMPtr<nsIURIFixup> mFixup;
nsCOMPtr<nsISHistory> mSessionHistory;
// our event receiver
nsCOMPtr<nsIDOMEventReceiver> mEventReceiver;
// the currently loaded uri
nsString mURI;
nsIPrintSettings *m_PrintSettings;
// the number of widgets that have been created
static PRUint32 sWidgetCount;
// the path to components
static char *sCompPath;
// the appshell we have created
static nsIAppShell *sAppShell;
// for profiles
static nsIPref *sPrefs;
static nsVoidArray *sWindowList;
// chrome mask
PRUint32 mChromeMask;
// is this a chrome window?
PRBool mIsChrome;
// has the chrome finished loading?
PRBool mChromeLoaded;
// saved window ID for reparenting later
PtWidget_t *mMozWindowWidget;
// this will get the PIDOMWindow for this widget
nsresult GetPIDOMWindow (nsPIDOMWindow **aPIWin);
private:
// is the chrome listener attached yet?
PRBool mListenersAttached;
void GetListener (void);
void AttachListeners(void);
void DetachListeners(void);
};
#endif /* __EmbedPrivate_h */

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

@ -0,0 +1,350 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include "EmbedProgress.h"
#include <nsXPIDLString.h>
#include <nsIChannel.h>
#include <nsCWebBrowser.h>
#include <nsIComponentManager.h>
#include <nsIDocShellTreeItem.h>
#include "nsIWidget.h"
#include <nsString.h>
#include <nsError.h>
#include <nsIDNSService.h>
#include "nsReadableUtils.h"
#include <nsILocalFile.h>
#include <nsIRequestObserver.h>
#include <nsISocketTransportService.h>
#include "nsGfxCIID.h"
#include "EmbedWindow.h"
#include "EmbedPrivate.h"
#include "nsIURI.h"
#include "PtMozilla.h"
EmbedProgress::EmbedProgress(void)
{
NS_INIT_REFCNT();
mOwner = nsnull;
mSkipOnState = mDownloadDocument = 0;
}
EmbedProgress::~EmbedProgress()
{
}
NS_IMPL_ISUPPORTS2(EmbedProgress,
nsIWebProgressListener,
nsISupportsWeakReference)
nsresult
EmbedProgress::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
PRUint32 aStatus)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb = NULL;
PtCallbackInfo_t cbinfo;
PRUnichar *url;
PtMozillaNetStateCb_t state;
aRequest->GetName( &url );
nsString surl( url );
if( ( aStateFlags & STATE_IS_NETWORK ) && NS_FAILED( aStatus ) )
{
PtWebErrorCallback_t cbw;
/* invoke the Pt_CB_WEB_ERROR in the client */
cb = moz->web_error_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_ERROR;
cbinfo.cbdata = &cbw;
memset( &cbw, 0, sizeof( PtWebErrorCallback_t ) );
char *s = ToNewCString(surl);
strcpy( cbw.url, s );
free( s );
cbw.type = WWW_ERROR_TOPVIEW;
switch( aStatus )
{
case NS_ERROR_UNKNOWN_HOST:
cbw.reason = -12;
break;
case NS_ERROR_NET_TIMEOUT:
cbw.reason = -408;
break;
case NS_ERROR_NO_CONTENT:
cbw.reason = -8;
break;
case NS_ERROR_FILE_NOT_FOUND:
cbw.reason = -404;
break;
case NS_ERROR_CONNECTION_REFUSED:
cbw.reason = -13;
break;
/* these will not cause the web error */
case NS_BINDING_ABORTED:
break;
default:
cbw.reason = -1;
break;
}
if( cbw.reason ) PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
/* let it check for STATE_STOP */
}
memset(&cbinfo, 0, sizeof(cbinfo));
if( aStateFlags & STATE_IS_NETWORK /* STATE_IS_REQUEST STATE_IS_DOCUMENT */ )
{
if( aStateFlags & STATE_START )
{
cbinfo.reason = Pt_CB_MOZ_START;
if( ( cb = moz->start_cb ) )
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
}
else if( aStateFlags & STATE_STOP )
{
PtWebCompleteCallback_t cbcomplete;
#if 1
/* if the mozilla was saving a file as a result of Pt_ARG_MOZ_DOWNLOAD or Pt_ARG_MOZ_UNKNOWN_RESP, move the temporary file into the desired destination ( moz->download_dest ) */
if( moz->download_dest )
{
if( moz->EmbedRef->app_launcher )
{
nsCOMPtr<nsIURI> aSourceUrl;
PRInt64 dummy;
nsCOMPtr<nsIFile> tempFile;
moz->EmbedRef->app_launcher->GetDownloadInfo( getter_AddRefs(aSourceUrl), &dummy, getter_AddRefs( tempFile ) );
if( tempFile )
{
nsresult rv;
nsCOMPtr<nsILocalFile> fileToUse = do_CreateInstance( NS_LOCAL_FILE_CONTRACTID, &rv );
fileToUse->InitWithPath( moz->download_dest );
PRBool equalToTempFile = PR_FALSE;
PRBool filetoUseAlreadyExists = PR_FALSE;
fileToUse->Equals( tempFile, &equalToTempFile );
fileToUse->Exists(&filetoUseAlreadyExists);
if( filetoUseAlreadyExists && !equalToTempFile )
fileToUse->Remove(PR_FALSE);
// extract the new leaf name from the file location
nsXPIDLCString fileName;
fileToUse->GetLeafName(getter_Copies(fileName));
nsCOMPtr<nsIFile> directoryLocation;
fileToUse->GetParent(getter_AddRefs(directoryLocation));
if( directoryLocation ) rv = tempFile->MoveTo(directoryLocation, fileName);
}
moz->EmbedRef->app_launcher = NULL;
}
free(moz->download_dest);
moz->download_dest = NULL;
}
#endif
cbinfo.reason = Pt_CB_MOZ_COMPLETE;
cbinfo.cbdata = &cbcomplete;
memset( &cbcomplete, 0, sizeof( PtWebCompleteCallback_t ) );
char *s = ToNewCString(surl);
strcpy( cbcomplete.url, s );
free( s );
if( ( cb = moz->complete_cb ) )
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
}
}
// invoke the raw status callbacks for page load status
cbinfo.reason = Pt_CB_MOZ_NET_STATE;
cbinfo.cbdata = &state;
state.flags = aStateFlags;
state.status = aStatus;
state.url = (char *)ToNewCString(surl);
char *statusMessage = "";
PRInt32 flags = aStateFlags;
if (flags & STATE_IS_REQUEST)
{
if (flags & STATE_REDIRECTING)
statusMessage = "Redirecting to site:";
else if (flags & STATE_TRANSFERRING)
statusMessage = "Receiving Data:";
else if (flags & STATE_NEGOTIATING)
statusMessage = "Waiting for authorization:";
}
if (flags & STATE_IS_DOCUMENT)
{
if (flags & STATE_START)
statusMessage = "Loading site:";
else if (flags & STATE_STOP)
statusMessage = "Finishing:";
}
state.message = statusMessage;
if( ( cb = moz->net_state_cb ) && statusMessage[0])
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaProgressCb_t prog;
PRInt32 cur, max;
nsXPIDLCString uriString;
if (!moz->progress_cb)
return NS_OK;
cur = aCurTotalProgress;
max = aMaxTotalProgress;
if (cur > max && max != -1 && max != 0)
cur = max; // Progress complete
cb = moz->progress_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_PROGRESS;
cbinfo.cbdata = &prog;
prog.cur = cur;
prog.max = max;
PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *aLocation)
{
NS_ENSURE_ARG_POINTER(aLocation);
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb = NULL;
PtCallbackInfo_t cbinfo;
PtMozillaUrlCb_t url;
char *uri;
aLocation->GetSpec(&uri);
mOwner->SetURI(uri);
if (!moz->url_cb)
return NS_OK;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &url;
cbinfo.reason = Pt_CB_MOZ_URL;
aLocation->GetSpec(&(url.url));
cb = moz->url_cb;
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaInfoCb_t info;
nsAutoString Text ( aMessage );
if (!moz->info_cb)
return NS_OK;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &info;
cbinfo.reason = Pt_CB_MOZ_INFO;
cb = moz->info_cb;
const char* msg = ToNewCString(Text);
info.type = Pt_MOZ_INFO_CONNECT;
info.status = 0;
info.data = (char *)msg;
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
nsMemory::Free( (void*)msg );
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aState)
{
return NS_OK;
}
/* static */
void
EmbedProgress::RequestToURIString(nsIRequest *aRequest, char **aString)
{
// is it a channel
nsCOMPtr<nsIChannel> channel;
channel = do_QueryInterface(aRequest);
if (!channel)
return;
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (!uri)
return;
nsXPIDLCString uriString;
uri->GetSpec(getter_Copies(uriString));
if (!uriString)
return;
*aString = nsCRT::strdup((const char *)uriString);
}

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

@ -0,0 +1,53 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedProgress_h
#define __EmbedProgress_h
#include <nsIWebProgressListener.h>
#include <nsWeakReference.h>
#include "EmbedPrivate.h"
class EmbedProgress : public nsIWebProgressListener,
public nsSupportsWeakReference
{
public:
EmbedProgress();
virtual ~EmbedProgress();
PRBool mSkipOnState, mDownloadDocument;
nsresult Init(EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
private:
static void RequestToURIString (nsIRequest *aRequest, char **aString);
EmbedPrivate *mOwner;
};
#endif /* __EmbedProgress_h */

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

@ -0,0 +1,301 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <nsIPipe.h>
#include <nsIInputStream.h>
#include <nsIOutputStream.h>
#include <nsIContentViewerContainer.h>
#include <nsIDocumentLoaderFactory.h>
#include <nsNetUtil.h>
#include <prmem.h>
#include "nsIContentViewer.h"
#include "EmbedStream.h"
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
// nsIInputStream interface
NS_IMPL_ISUPPORTS1(EmbedStream, nsIInputStream)
EmbedStream::EmbedStream()
{
NS_INIT_REFCNT();
mOwner = nsnull;
mOffset = 0;
mDoingStream = PR_FALSE;
}
EmbedStream::~EmbedStream()
{
}
void
EmbedStream::InitOwner(EmbedPrivate *aOwner)
{
mOwner = aOwner;
}
NS_METHOD
EmbedStream::Init(void)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIInputStream> bufInStream;
nsCOMPtr<nsIOutputStream> bufOutStream;
rv = NS_NewPipe(getter_AddRefs(bufInStream),
getter_AddRefs(bufOutStream));
if (NS_FAILED(rv)) return rv;
mInputStream = do_QueryInterface(bufInStream, &rv);
if (NS_FAILED(rv))
return rv;
mOutputStream = do_QueryInterface(bufOutStream, &rv);
return rv;
}
NS_METHOD
EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
{
NS_ENSURE_ARG_POINTER(aBaseURI);
NS_ENSURE_ARG_POINTER(aContentType);
nsresult rv = NS_OK;
// if we're already doing a stream then close the current one
if (mDoingStream)
CloseStream();
// set our state
mDoingStream = PR_TRUE;
// initialize our streams
rv = Init();
if (NS_FAILED(rv))
return rv;
// get the content area of our web browser
nsCOMPtr<nsIWebBrowser> browser;
mOwner->mWindow->GetWebBrowser(getter_AddRefs(browser));
// get the viewer container
nsCOMPtr<nsIContentViewerContainer> viewerContainer;
viewerContainer = do_GetInterface(browser);
// create a new uri object
nsCOMPtr<nsIURI> uri;
nsCAutoString spec(aBaseURI);
rv = NS_NewURI(getter_AddRefs(uri), spec.get());
if (NS_FAILED(rv))
return rv;
// create a new load group
rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull);
if (NS_FAILED(rv))
return rv;
// create a new input stream channel
rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), uri,
NS_STATIC_CAST(nsIInputStream *, this),
aContentType,
1024); /* len */
if (NS_FAILED(rv))
return rv;
// set the channel's load group
rv = mChannel->SetLoadGroup(mLoadGroup);
if (NS_FAILED(rv))
return rv;
// find a document loader for this command plus content type
// combination
nsCAutoString docLoaderContractID;
docLoaderContractID = NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX;
docLoaderContractID += "view;1?type=";
docLoaderContractID += aContentType;
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;
docLoaderFactory = do_CreateInstance(docLoaderContractID.get(), &rv);
if (NS_FAILED(rv))
return rv;
// ok, create an instance of the content viewer for that command and
// mime type
nsCOMPtr<nsIContentViewer> contentViewer;
rv = docLoaderFactory->CreateInstance("view", mChannel, mLoadGroup,
aContentType, viewerContainer,
nsnull,
getter_AddRefs(mStreamListener),
getter_AddRefs(contentViewer));
if (NS_FAILED(rv))
return rv;
// set the container viewer container for this content view
rv = contentViewer->SetContainer(viewerContainer);
if (NS_FAILED(rv))
return rv;
// embed this sucker
rv = viewerContainer->Embed(contentViewer, "view", nsnull);
if (NS_FAILED(rv))
return rv;
// start our request
nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
rv = mStreamListener->OnStartRequest(request, NULL);
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
NS_METHOD
EmbedStream::AppendToStream(const char *aData, PRInt32 aLen)
{
nsresult rv;
// append the data
rv = Append(aData, aLen);
if (NS_FAILED(rv))
return rv;
// notify our listeners
nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
rv = mStreamListener->OnDataAvailable(request,
NULL,
NS_STATIC_CAST(nsIInputStream *, this),
mOffset, /* offset */
aLen); /* len */
// move our counter
mOffset += aLen;
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
NS_METHOD
EmbedStream::CloseStream(void)
{
nsresult rv = NS_OK;
NS_ENSURE_STATE(mDoingStream);
mDoingStream = PR_FALSE;
nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel, &rv);
if (NS_FAILED(rv))
goto loser;
rv = mStreamListener->OnStopRequest(request, NULL, NS_OK);
if (NS_FAILED(rv))
return rv;
loser:
mLoadGroup = nsnull;
mChannel = nsnull;
mStreamListener = nsnull;
mOffset = 0;
return rv;
}
NS_METHOD
EmbedStream::Append(const char *aData, PRUint32 aLen)
{
nsresult rv = NS_OK;
PRUint32 bytesWritten = 0;
rv = mOutputStream->Write(aData, aLen, &bytesWritten);
if (NS_FAILED(rv))
return rv;
NS_ASSERTION(bytesWritten == aLen,
"underlying byffer couldn't handle the write");
return rv;
}
NS_IMETHODIMP
EmbedStream::Available(PRUint32 *_retval)
{
return mInputStream->Available(_retval);
}
NS_IMETHODIMP
EmbedStream::Read(char * aBuf, PRUint32 aCount, PRUint32 *_retval)
{
return mInputStream->Read(aBuf, aCount, _retval);
}
NS_IMETHODIMP EmbedStream::Close(void)
{
return mInputStream->Close();
}
NS_IMETHODIMP
EmbedStream::ReadSegments(nsWriteSegmentFun aWriter, void * aClosure,
PRUint32 aCount, PRUint32 *_retval)
{
char *readBuf = (char *)nsMemory::Alloc(aCount);
PRUint32 nBytes;
if (!readBuf)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = mInputStream->Read(readBuf, aCount, &nBytes);
*_retval = 0;
if (NS_SUCCEEDED(rv)) {
PRUint32 writeCount = 0;
rv = aWriter(this, aClosure, readBuf, 0, nBytes, &writeCount);
}
nsMemory::Free(readBuf);
return rv;
}
NS_IMETHODIMP
EmbedStream::GetNonBlocking(PRBool *aNonBlocking)
{
NS_NOTREACHED("GetNonBlocking");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedStream::GetObserver(nsIInputStreamObserver * *aObserver)
{
NS_NOTREACHED("GetObserver");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedStream::SetObserver(nsIInputStreamObserver * aObserver)
{
NS_NOTREACHED("SetObserver");
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,67 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <nsISupports.h>
#include <nsCOMPtr.h>
#include <nsIOutputStream.h>
#include <nsIInputStream.h>
#include <nsILoadGroup.h>
#include <nsIChannel.h>
#include <nsIStreamListener.h>
class EmbedPrivate;
class EmbedStream : public nsIInputStream
{
public:
EmbedStream();
virtual ~EmbedStream();
void InitOwner (EmbedPrivate *aOwner);
NS_METHOD Init (void);
NS_METHOD OpenStream (const char *aBaseURI, const char *aContentType);
NS_METHOD AppendToStream (const char *aData, PRInt32 aLen);
NS_METHOD CloseStream (void);
NS_METHOD Append (const char *aData, PRUint32 aLen);
// nsISupports
NS_DECL_ISUPPORTS
// nsIInputStream
NS_DECL_NSIINPUTSTREAM
private:
nsCOMPtr<nsIOutputStream> mOutputStream;
nsCOMPtr<nsIInputStream> mInputStream;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIStreamListener> mStreamListener;
PRUint32 mOffset;
PRBool mDoingStream;
EmbedPrivate *mOwner;
};

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

@ -0,0 +1,642 @@
/*
* vim:ts=2:et:sw=2
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include <nsIDocShell.h>
#include <nsIWebProgress.h>
#include <nsIURI.h>
#include "nsIWidget.h"
// for do_GetInterface
#include <nsIInterfaceRequestor.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsIWebBrowserPersist.h>
// for do_CreateInstance
#include <nsIComponentManager.h>
#include "nsIWebProgressListener.h"
#include <nsCWebBrowser.h>
#include <nsIComponentManager.h>
#include <nsIDocShellTreeItem.h>
#include <nsILocalFile.h>
#include <nsString.h>
#include "nsReadableUtils.h"
#include "EmbedWindow.h"
#include "EmbedPrivate.h"
#include "PtMozilla.h"
PtWidget_t *EmbedWindow::sTipWindow = nsnull;
EmbedWindow::EmbedWindow(void)
{
NS_INIT_REFCNT();
mOwner = nsnull;
mVisibility = PR_FALSE;
mIsModal = PR_FALSE;
}
EmbedWindow::~EmbedWindow(void)
{
ExitModalEventLoop(PR_FALSE);
}
nsresult
EmbedWindow::Init(EmbedPrivate *aOwner)
{
// save our owner for later
mOwner = aOwner;
// create our nsIWebBrowser object and set up some basic defaults.
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
if (!mWebBrowser)
return NS_ERROR_FAILURE;
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
// get the doc shel for cut/copy/paste
//mRootDocShell = do_GetInterface(mWebBrowser);
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mWebBrowser);
item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
return NS_OK;
}
nsresult
EmbedWindow::CreateWindow(void)
{
nsresult rv;
PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
// Get the base window interface for the web browser object and
// create the window.
mBaseWindow = do_QueryInterface(mWebBrowser);
rv = mBaseWindow->InitWindow(ownerAsWidget,
nsnull,
0, 0,
ownerAsWidget->area.size.w,
ownerAsWidget->area.size.h);
if (NS_FAILED(rv))
return rv;
rv = mBaseWindow->Create();
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
void
EmbedWindow::ReleaseChildren(void)
{
ExitModalEventLoop(PR_FALSE);
mBaseWindow->Destroy();
mBaseWindow = 0;
mWebBrowser = 0;
}
// nsISupports
NS_IMPL_ADDREF(EmbedWindow)
NS_IMPL_RELEASE(EmbedWindow)
NS_INTERFACE_MAP_BEGIN(EmbedWindow)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsIDNSListener)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
// nsIWebBrowserChrome
NS_IMETHODIMP
EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaInfoCb_t info;
nsAutoString Text ( aStatus );
int type = 0;
switch (aStatusType)
{
case STATUS_SCRIPT:
type = Pt_MOZ_INFO_JSSTATUS;
break;
case STATUS_SCRIPT_DEFAULT:
return NS_OK;
break;
case STATUS_LINK:
type = Pt_MOZ_INFO_LINK;
break;
default:
return NS_OK;
break;
}
if (!moz->info_cb)
return NS_OK;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &info;
cbinfo.reason = Pt_CB_MOZ_INFO;
cb = moz->info_cb;
info.type = type;
info.status = 0;
const char* status = ToNewCString(Text);
info.data = (char *)status;
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
nsMemory::Free( (void*)status );
return NS_OK;
}
int
EmbedWindow::SaveAs(char *fname)
{
nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
if (persist)
{
nsCOMPtr<nsILocalFile> file;
NS_NewLocalFile(fname, PR_TRUE, getter_AddRefs(file));
persist->SaveDocument(nsnull, file, nsnull);
return (0);
}
return 1;
}
int
EmbedWindow::SaveURI(nsIURI *uri, char *fname)
{
PtMozillaWidget_t *w = (PtMozillaWidget_t *)(mOwner->mOwningWidget);
nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
if (persist)
{
nsCOMPtr<nsILocalFile> file;
NS_NewLocalFile(fname, PR_TRUE, getter_AddRefs(file));
persist->SetProgressListener((nsIWebProgressListener*) w->EmbedRef->mProgress);
persist->SaveURI(uri, nsnull, file);
return (0);
}
return 1;
}
void
EmbedWindow::CancelSaveURI()
{
PtMozillaWidget_t *w = (PtMozillaWidget_t *)(mOwner->mOwningWidget);
nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
persist->SetProgressListener(nsnull);
persist->CancelSave();
}
NS_IMETHODIMP
EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser)
{
*aWebBrowser = mWebBrowser;
NS_IF_ADDREF(*aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser)
{
mWebBrowser = aWebBrowser;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags)
{
*aChromeFlags = mOwner->mChromeMask;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags)
{
mOwner->mChromeMask = aChromeFlags;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::DestroyBrowserWindow(void)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
if (!moz->destroy_cb)
return NS_OK;
cb = moz->destroy_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_DESTROY;
PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
EmbedWindow::ShowAsModal(void)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
EmbedWindow::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::ExitModalEventLoop(nsresult aStatus)
{
return NS_OK;
}
// nsIWebBrowserChromeFocus
NS_IMETHODIMP
EmbedWindow::FocusNextElement()
{
PtContainerFocusNext(mOwner->mOwningWidget, NULL);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::FocusPrevElement()
{
PtContainerFocusPrev(mOwner->mOwningWidget, NULL);
return NS_OK;
}
// nsIEmbeddingSiteWindow
NS_IMETHODIMP
EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
PRInt32 aCX, PRInt32 aCY)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaNewAreaCb_t resize;
nsresult rv = NS_ERROR_INVALID_ARG;
#if 0
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
rv = mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE);
}
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
rv = mBaseWindow->SetPosition(aX, aY);
}
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
rv = mBaseWindow->SetSize(aCX, aCY, PR_TRUE);
}
#endif
if (!moz->resize_cb)
return NS_OK;
cb = moz->resize_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_NEW_AREA;
cbinfo.cbdata = &resize;
memset(&resize, 0, sizeof(PtMozillaNewAreaCb_t));
if( aCX==0 && aCY==0 )
resize.flags = Pt_MOZ_NEW_AREA_SET_POSITION;
else
resize.flags = Pt_MOZ_NEW_AREA_SET_AREA;
resize.area.pos.x = aX;
resize.area.pos.y = aY;
resize.area.size.w = aCX;
resize.area.size.h = aCY;
PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX,
PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
{
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY);
}
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
return mBaseWindow->GetPosition(aX, aY);
}
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
return mBaseWindow->GetSize(aCX, aCY);
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
EmbedWindow::SetFocus(void)
{
// XXX might have to do more here.
return mBaseWindow->SetFocus();
}
NS_IMETHODIMP
EmbedWindow::GetTitle(PRUnichar **aTitle)
{
*aTitle = ToNewUnicode(mTitle);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetTitle(const PRUnichar *aTitle)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *)mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaInfoCb_t info;
nsString mTitleString(aTitle);
char *str;
mTitle = aTitle;
if (!moz->info_cb)
return NS_OK;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &info;
cbinfo.reason = Pt_CB_MOZ_INFO;
cb = moz->info_cb;
info.type = Pt_MOZ_INFO_TITLE;
info.status = 0;
str = ToNewCString(mTitleString);
info.data = str;
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
nsMemory::Free( (void*)str );
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetSiteWindow(void **aSiteWindow)
{
PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
*aSiteWindow = NS_STATIC_CAST(void *, ownerAsWidget);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetVisibility(PRBool *aVisibility)
{
*aVisibility = mVisibility;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetVisibility(PRBool aVisibility)
{
// We always set the visibility so that if it's chrome and we finish
// the load we know that we have to show the window.
mVisibility = aVisibility;
return NS_OK;
}
// nsITooltipListener
NS_IMETHODIMP
EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords,
const PRUnichar *aTipText)
{
nsAutoString tipText ( aTipText );
const char* tipString = ToNewCString(tipText);
PtArg_t args[10];
PhRect_t extent;
PhDim_t dim;
PhPoint_t pos = {0, 0};
int n = 0;
if (sTipWindow)
PtDestroyWidget(sTipWindow);
// get the root origin for this content window
nsCOMPtr<nsIWidget> mainWidget;
mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget));
PtWidget_t *window;
window = NS_STATIC_CAST(PtWidget_t *, mainWidget->GetNativeData(NS_NATIVE_WINDOW));
PgExtentText(&extent, &pos, NULL, tipString, 0);
dim.w = extent.lr.x - extent.ul.x + 1;
dim.h = extent.lr.y - extent.ul.y + 1;
pos.x = aXCoords;
pos.y = aYCoords;
n = 0;
PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
sTipWindow = PtCreateWidget(PtRegion, window, n, args);
n = 0;
pos.x = pos.y = 0;
PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
PtSetArg(&args[n++], Pt_ARG_FLAGS, Pt_HIGHLIGHTED, (int)(~0));
PtSetArg(&args[n++], Pt_ARG_FILL_COLOR, 0xfeffb1, 0);
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, tipString, 0);
PtSetArg(&args[n++], Pt_ARG_BASIC_FLAGS, Pt_STATIC_GRADIENT | Pt_TOP_OUTLINE | Pt_LEFT_OUTLINE |
Pt_RIGHT_OUTLINE | Pt_BOTTOM_OUTLINE, (int)(~0));
PtCreateWidget(PtLabel, sTipWindow, n, args);
// realize the widget
PtRealizeWidget(sTipWindow);
nsMemory::Free( (void*)tipString );
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::OnHideTooltip(void)
{
if (sTipWindow)
PtDestroyWidget(sTipWindow);
sTipWindow = NULL;
return NS_OK;
}
// nsIDNSListener
/* void OnStartLookup (in nsISupports ctxt, in string hostname); */
NS_IMETHODIMP EmbedWindow::OnStartLookup(nsISupports *ctxt, const char *hostname)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb = NULL;
PtCallbackInfo_t cbinfo;
PtMozillaNetStateCb_t state;
cbinfo.reason = Pt_CB_MOZ_NET_STATE;
cbinfo.cbdata = &state;
state.flags = 0;
state.status = 0;
state.url = (char *)hostname;
char *statusMessage = "Resolving host name:";
state.message = statusMessage;
if( ( cb = moz->net_state_cb ) )
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
return NS_OK;
}
/* [noscript] void OnFound (in nsISupports ctxt, in string hostname, in nsHostEntStar entry); */
NS_IMETHODIMP EmbedWindow::OnFound(nsISupports *ctxt, const char *hostname, nsHostEnt * entry)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb = NULL;
PtCallbackInfo_t cbinfo;
PtMozillaNetStateCb_t state;
cbinfo.reason = Pt_CB_MOZ_NET_STATE;
cbinfo.cbdata = &state;
state.flags = 0;
state.status = 0;
state.url = (char *)hostname;
char *statusMessage = "Opening connection:";
state.message = statusMessage;
if( ( cb = moz->net_state_cb ) )
PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
return NS_OK;
}
/* void OnStopLookup (in nsISupports ctxt, in string hostname, in nsresult status); */
NS_IMETHODIMP EmbedWindow::OnStopLookup(nsISupports *ctxt, const char *hostname, nsresult status)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIContextMenuListener
NS_IMETHODIMP EmbedWindow::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaContextCb_t cmenu;
if (!moz->context_cb)
return NS_OK;
cb = moz->context_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_CONTEXT;
cbinfo.cbdata = &cmenu;
memset(&cmenu, 0, sizeof(PtMozillaContextCb_t));
if (aContextFlags & CONTEXT_NONE)
cmenu.flags |= Pt_MOZ_CONTEXT_NONE;
if (aContextFlags & CONTEXT_LINK)
cmenu.flags |= Pt_MOZ_CONTEXT_LINK;
if (aContextFlags & CONTEXT_IMAGE)
cmenu.flags |= Pt_MOZ_CONTEXT_IMAGE;
if (aContextFlags & CONTEXT_DOCUMENT)
cmenu.flags |= Pt_MOZ_CONTEXT_DOCUMENT;
if (aContextFlags & CONTEXT_TEXT)
cmenu.flags |= Pt_MOZ_CONTEXT_TEXT;
if (aContextFlags & CONTEXT_INPUT)
cmenu.flags |= Pt_MOZ_CONTEXT_INPUT;
nsCOMPtr<nsIDOMMouseEvent> mouseEvent (do_QueryInterface( aEvent ));
if(!mouseEvent) return NS_OK;
mouseEvent->GetScreenX( &cmenu.x );
mouseEvent->GetScreenY( &cmenu.y );
PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
/* store the url we clicked on */
nsAutoString rightClickUrl;
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv));
if(NS_FAILED(rv)) return NS_OK;
// Note that this string is in UCS2 format
rv = linkElement->GetHref( rightClickUrl );
if(NS_FAILED(rv)) {
if( moz->rightClickUrl ) free( moz->rightClickUrl );
moz->rightClickUrl = NULL;
return NS_OK;
}
if( moz->rightClickUrl ) free( moz->rightClickUrl );
moz->rightClickUrl = ToNewCString(rightClickUrl);
return NS_OK;
}
// nsIInterfaceRequestor
NS_IMETHODIMP
EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
nsresult rv;
rv = QueryInterface(aIID, aInstancePtr);
// pass it up to the web browser object
if (NS_FAILED(rv) || !*aInstancePtr) {
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(mWebBrowser);
return ir->GetInterface(aIID, aInstancePtr);
}
return rv;
}

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

@ -0,0 +1,102 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedWindow_h
#define __EmbedWindow_h
#include <nsString.h>
#include <nsIWebBrowserChrome.h>
#include <nsIWebBrowserChromeFocus.h>
#include <nsIEmbeddingSiteWindow.h>
#include <nsITooltipListener.h>
#include <nsIContextMenuListener.h>
#include <nsIDNSListener.h>
#include <nsISupports.h>
#include <nsIWebBrowser.h>
#include <nsIDocShell.h>
#include <nsIBaseWindow.h>
#include <nsIInterfaceRequestor.h>
#include <nsCOMPtr.h>
#include "nsString.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMHTMLAnchorElement.h"
#include <Pt.h>
class EmbedPrivate;
class EmbedWindow : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow,
public nsITooltipListener,
public nsIDNSListener,
public nsIContextMenuListener,
public nsIInterfaceRequestor
{
public:
EmbedWindow();
virtual ~EmbedWindow();
nsresult Init (EmbedPrivate *aOwner);
nsresult CreateWindow (void);
void ReleaseChildren (void);
int SaveAs(char *fname);
int SaveURI(nsIURI *uri, char *fname);
void CancelSaveURI();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSITOOLTIPLISTENER
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSIDNSLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
nsString mTitle;
nsString mJSStatus;
nsString mLinkMessage;
nsCOMPtr<nsIBaseWindow> mBaseWindow; // [OWNER]
nsCOMPtr<nsIWebBrowser> mWebBrowser; // [OWNER]
private:
EmbedPrivate *mOwner;
static PtWidget_t *sTipWindow;
PRBool mVisibility;
PRBool mIsModal;
};
#endif /* __EmbedWindow_h */

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

@ -0,0 +1,86 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#include "EmbedWindowCreator.h"
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
// in order to create orphaned windows
#include "PtMozilla.h"
EmbedWindowCreator::EmbedWindowCreator(void)
{
NS_INIT_REFCNT();
}
EmbedWindowCreator::~EmbedWindowCreator()
{
}
NS_IMPL_ISUPPORTS1(EmbedWindowCreator, nsIWindowCreator)
NS_IMETHODIMP
EmbedWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
EmbedPrivate *embedPrivate = EmbedPrivate::FindPrivateForBrowser(aParent);
PtMozillaWidget_t *nmoz, *moz;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaNewWindowCb_t nwin;
if (!embedPrivate)
return NS_ERROR_FAILURE;
moz = (PtMozillaWidget_t *)embedPrivate->mOwningWidget;
if (!moz || !moz->new_window_cb)
return NS_ERROR_FAILURE;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.cbdata = &nwin;
cbinfo.reason = Pt_CB_MOZ_NEW_WINDOW;
cb = moz->new_window_cb;
nwin.window_flags = aChromeFlags;
PtSetParentWidget(NULL);
if (PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo) == Pt_CONTINUE)
{
nmoz = (PtMozillaWidget_t *) nwin.widget;
EmbedPrivate *newEmbedPrivate = nmoz->EmbedRef;
if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
newEmbedPrivate->mIsChrome = PR_TRUE;
*_retval = NS_STATIC_CAST(nsIWebBrowserChrome *, (newEmbedPrivate->mWindow));
if (*_retval)
{
NS_ADDREF(*_retval);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}

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

@ -0,0 +1,39 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Edmond <briane@qnx.com>
*/
#ifndef __EmbedWindowCreator_h
#define __EmbedWindowCreator_h
#include <nsIWindowCreator.h>
class EmbedWindowCreator : public nsIWindowCreator
{
public:
EmbedWindowCreator();
virtual ~EmbedWindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
};
#endif /* __EmbedWindowCreator_h */

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

@ -17,7 +17,6 @@
#
# Contributor(s):
# Christopher Blizzard <blizzard@mozilla.org>
# Brian Edmond <briane@qnx.com>
DEPTH = ../../../..
topsrcdir = @top_srcdir@
@ -26,44 +25,45 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = phembedmoz
MODULE = phembedmoz
LIBRARY_NAME = phembedmoz
EXPORT_LIBRARY = 1
REQUIRES = xpcom \
string \
docshell \
webshell \
necko \
widget \
dom \
gfx \
layout \
content \
uriloader \
webbrwsr \
shistory \
embed_base \
pref \
cookie\
view\
windowwatcher \
mpfilelocprovider \
appshell \
exthandler \
helperAppDlg \
mozcomps \
find \
appcomps \
mimetype \
webbrowserpersist \
$(NULL)
REQUIRES = xpcom \
string \
docshell \
webshell \
necko \
widget \
dom \
gfx \
layout \
content \
uriloader \
webbrwsr \
shistory \
embed_base \
pref \
windowwatcher \
mpfilelocprovider \
webbrowserpersist \
find \
exthandler \
helperAppDlg \
$(NULL)
CPPSRCS = \
PhMozEmbedStream.cpp \
EmbedPrivate.cpp \
EmbedPrintListener.cpp \
EmbedWindow.cpp \
EmbedProgress.cpp \
EmbedContentListener.cpp \
EmbedEventListener.cpp \
EmbedWindowCreator.cpp \
PtMozilla.cpp \
WebBrowserContainer.cpp \
EmbedStream.cpp \
PromptService.cpp \
nsUnknownContentTypeHandler.cpp
nsUnknownContentTypeHandler.cpp \
nsPrintSettingsImpl.cpp
SHARED_LIBRARY_LIBS= \
$(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \
@ -71,14 +71,25 @@ SHARED_LIBRARY_LIBS= \
$(NULL)
EXPORTS = \
PtMozilla.h PhMozEmbedStream.h stdhdrs.h
PtMozilla.h
EXTRA_DSO_LDOPTS = \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
EXTRA_DSO_LDOPTS += $(MOZ_PH_LDFLAGS)
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS)
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(MOZ_PH_CFLAGS)
ifeq ($(OS_ARCH), SunOS)
ifndef GNU_CC
# When using Sun's WorkShop compiler, including
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
# causes most of these compiles to fail with:
# line 29: Error: Multiple declaration for std::tm.
# So, this gets around the problem.
DEFINES += -D_TIME_H=1
endif
endif
CXXFLAGS += $(MOZ_GTK_CFLAGS)

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

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

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

@ -51,6 +51,7 @@
#include "nsIEmbeddingSiteWindow.h"
#include "nsIFactory.h"
#include "nsIPromptService.h"
#include "nsPIPromptService.h"
#include "nsIServiceManager.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
@ -61,22 +62,25 @@
// CPromptService
//*****************************************************************************
class CPromptService: public nsIPromptService {
class CPromptService: public nsIPromptService, public nsPIPromptService {
public:
CPromptService();
virtual ~CPromptService();
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSPIPROMPTSERVICE
private:
nsCOMPtr<nsIWindowWatcher> mWWatch;
CWebBrowserContainer *GetWebBrowser(nsIDOMWindow *aWindow);
PtWidget_t *GetWebBrowser(nsIDOMWindow *aWindow);
int InvokeDialogCallback(PtWidget_t *w, int type, char *title, char *text, char *msg, int *value);
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
//NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
NS_IMPL_ISUPPORTS2(CPromptService, nsIPromptService, nsPIPromptService)
CPromptService::CPromptService() :
mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")) {
@ -86,10 +90,10 @@ CPromptService::CPromptService() :
CPromptService::~CPromptService() {
}
CWebBrowserContainer *CPromptService::GetWebBrowser(nsIDOMWindow *aWindow)
PtWidget_t *CPromptService::GetWebBrowser(nsIDOMWindow *aWindow)
{
nsCOMPtr<nsIWebBrowserChrome> chrome;
CWebBrowserContainer *val = 0;
PtWidget_t *val = 0;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return nsnull;
@ -113,14 +117,43 @@ CWebBrowserContainer *CPromptService::GetWebBrowser(nsIDOMWindow *aWindow)
return val;
}
int
CPromptService::InvokeDialogCallback(PtWidget_t *w, int type, char *title, char *text, char *msg, int *value)
{
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) w;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaDialogCb_t dlg;
int ret;
if (!moz->dialog_cb)
return NS_OK;
cb = moz->dialog_cb;
memset(&cbinfo, 0, sizeof(cbinfo));
cbinfo.reason = Pt_CB_MOZ_DIALOG;
cbinfo.cbdata = &dlg;
memset(&dlg, 0, sizeof(PtMozillaDialogCb_t));
dlg.type = type;
dlg.title = title;
dlg.text = text;
if ((type == Pt_MOZ_DIALOG_ALERT_CHECK) || (type == Pt_MOZ_DIALOG_CONFIRM_CHECK))
dlg.message = msg;
ret = PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
if (value)
*value = dlg.ret_value;
return (ret);
}
NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsString mTitle(dialogTitle);
nsString mText(text);
CWebBrowserContainer *w = GetWebBrowser( parent );
w->InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, ToNewCString(mTitle), ToNewCString(mText), nsnull, nsnull);
PtWidget_t *w = GetWebBrowser( parent );
InvokeDialogCallback(w, Pt_MOZ_DIALOG_ALERT, ToNewCString(mTitle), ToNewCString(mText), nsnull, nsnull);
return NS_OK;
}
@ -135,9 +168,9 @@ NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent,
nsString mText(text);
nsString mMsg(checkboxMsg);
int ret;
CWebBrowserContainer *w = GetWebBrowser( parent );
PtWidget_t *w = GetWebBrowser( parent );
w->InvokeDialogCallback(Pt_MOZ_DIALOG_ALERT, ToNewCString(mTitle), ToNewCString(mText), \
InvokeDialogCallback(w, Pt_MOZ_DIALOG_ALERT, ToNewCString(mTitle), ToNewCString(mText), \
ToNewCString(mMsg), &ret);
*checkValue = ret;
@ -152,9 +185,9 @@ NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent,
{
nsString mTitle(dialogTitle);
nsString mText(text);
CWebBrowserContainer *w = GetWebBrowser( parent );
PtWidget_t *w = GetWebBrowser( parent );
if (w->InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, ToNewCString(mTitle), ToNewCString(mText), nsnull, nsnull) == Pt_CONTINUE)
if (InvokeDialogCallback(w, Pt_MOZ_DIALOG_CONFIRM, ToNewCString(mTitle), ToNewCString(mText), nsnull, nsnull) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
@ -185,15 +218,16 @@ NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent,
nsString mText(text);
nsString mMsg(checkboxMsg);
int ret;
CWebBrowserContainer *w = GetWebBrowser( parent );
PtWidget_t *w = GetWebBrowser( parent );
if (w->InvokeDialogCallback(Pt_MOZ_DIALOG_CONFIRM, ToNewCString(mTitle), ToNewCString(mText), \
if (InvokeDialogCallback(w, Pt_MOZ_DIALOG_CONFIRM, ToNewCString(mTitle), ToNewCString(mText), \
ToNewCString(mMsg), &ret) == Pt_CONTINUE)
*_retval = PR_TRUE;
else
*_retval = PR_FALSE;
*checkValue = ret;
if (checkValue)
*checkValue = ret;
return NS_OK;
}
@ -207,16 +241,14 @@ NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
PRBool *checkValue,
PRBool *_retval)
{
CWebBrowserContainer *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) w->m_pOwner;
PtWidget_t *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = (PtMozillaWidget_t *) w;
PtCallbackList_t *cb;
PtCallbackInfo_t cbinfo;
PtMozillaAuthenticateCb_t auth;
nsString mTitle(dialogTitle);
nsString mRealm(checkboxMsg);
/* ATENTIE */ printf( "CWebBrowserContainer::PromptUsernameAndPassword\n" );
if (!moz->auth_cb)
return NS_OK;
@ -229,7 +261,7 @@ NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
auth.title = ToNewCString(mTitle);
auth.realm = ToNewCString(mRealm);
if (PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo) == Pt_CONTINUE)
if (PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo) == Pt_CONTINUE)
{
nsCString mUser(auth.user);
nsCString mPass(auth.pass);
@ -254,7 +286,6 @@ NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent,
PRBool *checkValue,
PRBool *_retval)
{
/* ATENTIE */ printf( "CWebBrowserContainer::PromptPassword\n" );
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -285,6 +316,39 @@ NS_IMETHODIMP CPromptService::ConfirmEx(nsIDOMWindow *parent,
*buttonPressed = 0;
return NS_OK;
}
nsresult
CPromptService::DoDialog(nsIDOMWindow *aParent,
nsIDialogParamBlock *aParamBlock, const char *aChromeURL)
{
#if 0
NS_ENSURE_ARG(aParamBlock);
NS_ENSURE_ARG(aChromeURL);
if (!mWatcher)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// get a parent, if at all possible
// (though we'd rather this didn't fail, it's OK if it does. so there's
// no failure or null check.)
nsCOMPtr<nsIDOMWindow> activeParent; // retain ownership for method lifetime
if (!aParent) {
mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
aParent = activeParent;
}
nsCOMPtr<nsISupports> arguments(do_QueryInterface(aParamBlock));
nsCOMPtr<nsIDOMWindow> dialog;
rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
return rv;
#else
return NS_OK;
#endif
}
//*****************************************************************************
// CPromptServiceFactory

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -29,17 +29,16 @@
#include <photon/PtWebClient.h>
#include <photon/PpProto.h>
#include "WebBrowserContainer.h"
#include "EmbedPrivate.h"
#if 0
#include "nsIInputStream.h"
#include "nsILoadGroup.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
#include "nsIStreamListener.h"
#include "nsIExternalHelperAppService.h"
#include "nsISHistory.h"
#include "nsIHistoryEntry.h"
#endif
/*
* PtMozilla public
@ -88,14 +87,23 @@ extern PtWidgetClassRef_t *PtMozilla;
#define MAX_URL_LENGTH 1024
typedef enum
{
MOZ_EMBED_FLAG_RELOADNORMAL = 0,
MOZ_EMBED_FLAG_RELOADBYPASSCACHE = 1,
MOZ_EMBED_FLAG_RELOADBYPASSPROXY = 2,
MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE = 3,
MOZ_EMBED_FLAG_RELOADCHARSETCHANGE = 4
} MozEmbedReloadFlags;
// progress callback, can be itemized or full
#define Pt_MOZ_PROGRESS 1
#define Pt_MOZ_PROGRESS_ALL 2
typedef struct mozilla_progress_t
{
int type; // unused at this time
int32 cur;
int32 max;
int32_t cur;
int32_t max;
} PtMozillaProgressCb_t;
// url change callback, also used for open callback
@ -287,23 +295,6 @@ enum
Pt_MOZ_COMMAND_SAVEAS,
};
class BrowserAccess
{
public:
CWebBrowserContainer *WebBrowserContainer;
nsCOMPtr<nsIWebBrowser> WebBrowser;
nsCOMPtr<nsIBaseWindow> WebBrowserAsWin;
nsCOMPtr<nsIWebNavigation> WebNavigation;
nsCOMPtr<nsISHistory> mSessionHistory;
nsCOMPtr<nsIDocShell> rootDocShell;
nsIPref *mPrefs;
/* pass extra information to the mozilla widget, so that it will know what to do when Pt_ARG_MOZ_UNKNOWN_RESP comes */
nsCOMPtr<nsIHelperAppLauncher> app_launcher;
nsCOMPtr<nsISupports> context;
};
typedef struct {
short response;
char user[255];
@ -316,7 +307,7 @@ typedef struct Pt_mozilla_client_widget
PtContainerWidget_t container;
// Mozilla interfaces
class BrowserAccess *MyBrowser;
EmbedPrivate *EmbedRef;
char url[MAX_URL_LENGTH];
int navigate_flags;

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

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

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

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

@ -0,0 +1,529 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsPrintSettingsImpl.h"
#include "nsCoord.h"
#include "nsUnitConversion.h"
#include "nsReadableUtils.h"
// For Prefs
#include "nsIPref.h"
#include "nsIServiceManager.h"
NS_IMPL_ISUPPORTS1(nsPrintSettings, nsIPrintSettings)
/** ---------------------------------------------------
* See documentation in nsPrintSettingsImpl.h
* @update 6/21/00 dwc
*/
nsPrintSettings::nsPrintSettings() :
mPrintRange(kRangeAllPages),
mStartPageNum(1),
mEndPageNum(1),
mScaling(1.0),
mPrintBGColors(PR_FALSE),
mPrintBGImages(PR_FALSE),
mPrintOptions(0L),
mPrintReversed(PR_FALSE),
mPrintInColor(PR_TRUE),
mPaperSize(kLetterPaperSize),
mOrientation(kPortraitOrientation),
mPrintToFile(PR_FALSE),
mPrintFrameType(kFramesAsIs),
mPrintPageDelay(500),
mPrintSilent(PR_FALSE)
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
mPrintOptions = kOptPrintOddPages | kOptPrintEvenPages;
mHeaderStrs[0].AssignWithConversion("&T");
mHeaderStrs[2].AssignWithConversion("&U");
mFooterStrs[0].AssignWithConversion("&PT"); // Use &P (Page Num Only) or &PT (Page Num of Page Total)
mFooterStrs[2].AssignWithConversion("&D");
}
/** ---------------------------------------------------
* See documentation in nsPrintSettingsImpl.h
* @update 6/21/00 dwc
*/
nsPrintSettings::~nsPrintSettings()
{
}
/* attribute long startPageRange; */
NS_IMETHODIMP nsPrintSettings::GetStartPageRange(PRInt32 *aStartPageRange)
{
//NS_ENSURE_ARG_POINTER(aStartPageRange);
*aStartPageRange = mStartPageNum;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetStartPageRange(PRInt32 aStartPageRange)
{
mStartPageNum = aStartPageRange;
return NS_OK;
}
/* attribute long endPageRange; */
NS_IMETHODIMP nsPrintSettings::GetEndPageRange(PRInt32 *aEndPageRange)
{
//NS_ENSURE_ARG_POINTER(aEndPageRange);
*aEndPageRange = mEndPageNum;
pc = (PpPrintContext_t *) *aEndPageRange;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetEndPageRange(PRInt32 aEndPageRange)
{
mEndPageNum = aEndPageRange;
return NS_OK;
}
/* attribute boolean printReversed; */
NS_IMETHODIMP nsPrintSettings::GetPrintReversed(PRBool *aPrintReversed)
{
//NS_ENSURE_ARG_POINTER(aPrintReversed);
*aPrintReversed = mPrintReversed;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintReversed(PRBool aPrintReversed)
{
mPrintReversed = aPrintReversed;
return NS_OK;
}
/* attribute boolean printInColor; */
NS_IMETHODIMP nsPrintSettings::GetPrintInColor(PRBool *aPrintInColor)
{
//NS_ENSURE_ARG_POINTER(aPrintInColor);
*aPrintInColor = mPrintInColor;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintInColor(PRBool aPrintInColor)
{
mPrintInColor = aPrintInColor;
return NS_OK;
}
/* attribute short paperSize; */
NS_IMETHODIMP nsPrintSettings::GetPaperSize(PRInt32 *aPaperSize)
{
//NS_ENSURE_ARG_POINTER(aPaperSize);
*aPaperSize = mPaperSize;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPaperSize(PRInt32 aPaperSize)
{
mPaperSize = aPaperSize;
return NS_OK;
}
/* attribute short orientation; */
NS_IMETHODIMP nsPrintSettings::GetOrientation(PRInt32 *aOrientation)
{
//NS_ENSURE_ARG_POINTER(aOrientation);
*aOrientation = mOrientation;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetOrientation(PRInt32 aOrientation)
{
mOrientation = aOrientation;
return NS_OK;
}
/* attribute wstring printCommand; */
NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand)
{
//NS_ENSURE_ARG_POINTER(aPrintCommand);
*aPrintCommand = ToNewUnicode(mPrintCommand);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand)
{
mPrintCommand = aPrintCommand;
return NS_OK;
}
/* attribute boolean printToFile; */
NS_IMETHODIMP nsPrintSettings::GetPrintToFile(PRBool *aPrintToFile)
{
//NS_ENSURE_ARG_POINTER(aPrintToFile);
*aPrintToFile = mPrintToFile;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintToFile(PRBool aPrintToFile)
{
mPrintToFile = aPrintToFile;
return NS_OK;
}
/* attribute wstring toFileName; */
NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName)
{
//NS_ENSURE_ARG_POINTER(aToFileName);
*aToFileName = ToNewUnicode(mToFileName);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
{
mToFileName = aToFileName;
return NS_OK;
}
/* attribute long printPageDelay; */
NS_IMETHODIMP nsPrintSettings::GetPrintPageDelay(PRInt32 *aPrintPageDelay)
{
*aPrintPageDelay = mPrintPageDelay;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintPageDelay(PRInt32 aPrintPageDelay)
{
mPrintPageDelay = aPrintPageDelay;
return NS_OK;
}
/* attribute double marginTop; */
NS_IMETHODIMP nsPrintSettings::GetMarginTop(double *aMarginTop)
{
NS_ENSURE_ARG_POINTER(aMarginTop);
*aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
{
mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop));
return NS_OK;
}
/* attribute double marginLeft; */
NS_IMETHODIMP nsPrintSettings::GetMarginLeft(double *aMarginLeft)
{
NS_ENSURE_ARG_POINTER(aMarginLeft);
*aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetMarginLeft(double aMarginLeft)
{
mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft));
return NS_OK;
}
/* attribute double marginBottom; */
NS_IMETHODIMP nsPrintSettings::GetMarginBottom(double *aMarginBottom)
{
NS_ENSURE_ARG_POINTER(aMarginBottom);
*aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetMarginBottom(double aMarginBottom)
{
mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom));
return NS_OK;
}
/* attribute double marginRight; */
NS_IMETHODIMP nsPrintSettings::GetMarginRight(double *aMarginRight)
{
NS_ENSURE_ARG_POINTER(aMarginRight);
*aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetMarginRight(double aMarginRight)
{
mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight));
return NS_OK;
}
/* attribute double scaling; */
NS_IMETHODIMP nsPrintSettings::GetScaling(double *aScaling)
{
NS_ENSURE_ARG_POINTER(aScaling);
*aScaling = mScaling;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetScaling(double aScaling)
{
mScaling = aScaling;
return NS_OK;
}
/* attribute boolean printBGColors; */
NS_IMETHODIMP nsPrintSettings::GetPrintBGColors(PRBool *aPrintBGColors)
{
NS_ENSURE_ARG_POINTER(aPrintBGColors);
*aPrintBGColors = mPrintBGColors;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintBGColors(PRBool aPrintBGColors)
{
mPrintBGColors = aPrintBGColors;
return NS_OK;
}
/* attribute boolean printBGImages; */
NS_IMETHODIMP nsPrintSettings::GetPrintBGImages(PRBool *aPrintBGImages)
{
NS_ENSURE_ARG_POINTER(aPrintBGImages);
*aPrintBGImages = mPrintBGImages;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintBGImages(PRBool aPrintBGImages)
{
mPrintBGImages = aPrintBGImages;
return NS_OK;
}
/* attribute long printRange; */
NS_IMETHODIMP nsPrintSettings::GetPrintRange(PRInt16 *aPrintRange)
{
NS_ENSURE_ARG_POINTER(aPrintRange);
*aPrintRange = mPrintRange;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintRange(PRInt16 aPrintRange)
{
mPrintRange = aPrintRange;
return NS_OK;
}
/* attribute wstring docTitle; */
NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = ToNewUnicode(mTitle);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
mTitle = aTitle;
return NS_OK;
}
/* attribute wstring docURL; */
NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL)
{
NS_ENSURE_ARG_POINTER(aDocURL);
*aDocURL = ToNewUnicode(mURL);
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL)
{
NS_ENSURE_ARG_POINTER(aDocURL);
mURL = aDocURL;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintSettings::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff)
{
NS_ENSURE_ARG_POINTER(aTurnOnOff);
*aTurnOnOff = mPrintOptions & aType;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintSettings::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff)
{
if (aTurnOnOff) {
mPrintOptions |= aType;
} else {
mPrintOptions &= ~aType;
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintSettings::GetPrintOptionsBits(PRInt32 *aBits)
{
NS_ENSURE_ARG_POINTER(aBits);
*aBits = mPrintOptions;
return NS_OK;
}
/* attribute wstring docTitle; */
nsresult
nsPrintSettings::GetMarginStrs(PRUnichar * *aTitle,
nsHeaderFooterEnum aType,
PRInt16 aJust)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = nsnull;
if (aType == eHeader) {
switch (aJust) {
case kJustLeft: *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
case kJustRight: *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
} //switch
} else {
switch (aJust) {
case kJustLeft: *aTitle = ToNewUnicode(mFooterStrs[0]);break;
case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
case kJustRight: *aTitle = ToNewUnicode(mFooterStrs[2]);break;
} //switch
}
return NS_OK;
}
nsresult
nsPrintSettings::SetMarginStrs(const PRUnichar * aTitle,
nsHeaderFooterEnum aType,
PRInt16 aJust)
{
NS_ENSURE_ARG_POINTER(aTitle);
if (aType == eHeader) {
switch (aJust) {
case kJustLeft: mHeaderStrs[0] = aTitle;break;
case kJustCenter: mHeaderStrs[1] = aTitle;break;
case kJustRight: mHeaderStrs[2] = aTitle;break;
} //switch
} else {
switch (aJust) {
case kJustLeft: mFooterStrs[0] = aTitle;break;
case kJustCenter: mFooterStrs[1] = aTitle;break;
case kJustRight: mFooterStrs[2] = aTitle;break;
} //switch
}
return NS_OK;
}
/* attribute wstring Header String Left */
NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eHeader, kJustLeft);
}
NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eHeader, kJustLeft);
}
/* attribute wstring Header String Center */
NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eHeader, kJustCenter);
}
NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eHeader, kJustCenter);
}
/* attribute wstring Header String Right */
NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eHeader, kJustRight);
}
NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eHeader, kJustRight);
}
/* attribute wstring Footer String Left */
NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eFooter, kJustLeft);
}
NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eFooter, kJustLeft);
}
/* attribute wstring Footer String Center */
NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eFooter, kJustCenter);
}
NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eFooter, kJustCenter);
}
/* attribute wstring Footer String Right */
NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(PRUnichar * *aTitle)
{
return GetMarginStrs(aTitle, eFooter, kJustRight);
}
NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const PRUnichar * aTitle)
{
return SetMarginStrs(aTitle, eFooter, kJustRight);
}
/* attribute long printFrame; */
NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(PRInt16 *aPrintFrameType)
{
NS_ENSURE_ARG_POINTER(aPrintFrameType);
*aPrintFrameType = (PRInt32)mPrintFrameType;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(PRInt16 aPrintFrameType)
{
mPrintFrameType = aPrintFrameType;
return NS_OK;
}
/* attribute long isCancelled; */
NS_IMETHODIMP nsPrintSettings::GetPrintSilent(PRBool *aPrintSilent)
{
NS_ENSURE_ARG_POINTER(aPrintSilent);
*aPrintSilent = mPrintSilent;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettings::SetPrintSilent(PRBool aPrintSilent)
{
mPrintSilent = aPrintSilent;
return NS_OK;
}

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

@ -0,0 +1,90 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Brian Edmond <briane@qnx.com>
*/
#ifndef nsPrintSettingsImpl_h__
#define nsPrintSettingsImpl_h__
#include "nsIPrintSettings.h"
#include "nsMargin.h"
#include "nsString.h"
#include <Pt.h>
//*****************************************************************************
//*** nsPrintSettings
//*****************************************************************************
class nsPrintSettings : public nsIPrintSettings
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTSETTINGS
nsPrintSettings();
virtual ~nsPrintSettings();
protected:
typedef enum {
eHeader,
eFooter
} nsHeaderFooterEnum;
nsresult GetMarginStrs(PRUnichar * *aTitle, nsHeaderFooterEnum aType, PRInt16 aJust);
nsresult SetMarginStrs(const PRUnichar * aTitle, nsHeaderFooterEnum aType, PRInt16 aJust);
// Members
nsMargin mMargin;
PRInt32 mPrintOptions;
// scriptable data members
PRInt16 mPrintRange;
PRInt32 mStartPageNum; // only used for ePrintRange_SpecifiedRange
PRInt32 mEndPageNum;
double mScaling;
PRBool mPrintBGColors; // print background colors
PRBool mPrintBGImages; // print background images
PRInt16 mPrintFrameType;
PRBool mPrintSilent;
PRInt32 mPrintPageDelay;
nsString mTitle;
nsString mURL;
nsString mPageNumberFormat;
nsString mHeaderStrs[3];
nsString mFooterStrs[3];
PRBool mPrintReversed;
PRBool mPrintInColor; // a false means grayscale
PRInt32 mPaperSize; // see page size consts
PRInt32 mOrientation; // see orientation consts
nsString mPrintCommand;
PRBool mPrintToFile;
nsString mToFileName;
PpPrintContext_t *pc;
};
#endif /* nsPrintSettings_h__ */

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

@ -43,11 +43,10 @@
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDocShell.h"
#include "nsIMIMEInfo.h"
#include "mimetype/nsIMIMEInfo.h"
#include "nsIURI.h"
#include "nsIFile.h"
#include "WebBrowserContainer.h"
#include "PtMozilla.h"
#include <photon/PtWebClient.h>
@ -62,7 +61,7 @@ nsUnknownContentTypeHandler::~nsUnknownContentTypeHandler( ) { }
NS_IMETHODIMP nsUnknownContentTypeHandler::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, nsISupports *aContext ) {
nsresult rv = NS_OK;
/* ATENTIE */ printf("ShowProgressDialog!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ //printf("ShowProgressDialog!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* we need a dummy listener because the nsExternalAppHandler class verifies that a progress window has been displayed */
nsCOMPtr<nsIWebProgressListener> dummy = new nsWebProgressListener;
@ -73,7 +72,7 @@ NS_IMETHODIMP nsUnknownContentTypeHandler::ShowProgressDialog(nsIHelperAppLaunch
NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher, nsISupports *aContext ) {
nsresult rv = NS_OK;
/* ATENTIE */ printf("Show!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ //printf("Show!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* try to get the PtMozillawidget_t* pointer form the aContext - use the fact the the WebBrowserContainer is
registering itself as nsIDocumentLoaderObserver ( SetDocLoaderObserver ) */
@ -81,13 +80,15 @@ NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher
nsCOMPtr<nsIDOMWindow> domw( do_GetInterface( aContext ) );
nsIDOMWindow *parent;
domw->GetParent( &parent );
CWebBrowserContainer *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) w->m_pOwner;
PtWidget_t *w = GetWebBrowser( parent );
PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) w;
/* go ahead and start the downloading process */
nsCOMPtr<nsIWebProgressListener> listener = NS_STATIC_CAST(nsIWebProgressListener*, moz->MyBrowser->WebBrowserContainer );
// nsCOMPtr<nsIWebProgressListener> listener = NS_CAST(nsIWebProgressListener *, moz->EmbedRef->mProgress );
nsCOMPtr<nsIWebProgressListener> listener;
listener = NS_STATIC_CAST(nsIWebProgressListener *, listener);
aLauncher->SetWebProgressListener( listener );
moz->MyBrowser->WebBrowserContainer->mSkipOnState = 0; /* reinstate nsIWebProgressListener's CWebBrowserContainer::OnStateChange() */
// moz->MyBrowser->WebBrowserContainer->mSkipOnState = 0; /* reinstate nsIWebProgressListener's CWebBrowserContainer::OnStateChange() */
/* get the mime type - need to provide it in the callback info */
nsCOMPtr<nsIMIMEInfo> mimeInfo;
@ -111,8 +112,8 @@ NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher
cb.action = WWW_ACTION_OK;
/* pass extra information to the mozilla widget, so that it will know what to do when Pt_ARG_MOZ_UNKNOWN_RESP comes */
moz->MyBrowser->app_launcher = aLauncher;
moz->MyBrowser->context = aContext;
moz->EmbedRef->app_launcher = aLauncher;
moz->EmbedRef->context = aContext;
strcpy( cb.content_type, mimeType );
strcpy( cb.url, url );
@ -123,15 +124,15 @@ NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher
/* only Show() method is used - remove this code */
NS_IMETHODIMP nsUnknownContentTypeHandler::PromptForSaveToFile( nsISupports * aWindowContext, const PRUnichar * aDefaultFile, const PRUnichar * aSuggestedFileExtension, nsILocalFile ** aNewFile ) {
/* ATENTIE */ printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ //printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
return NS_OK;
}
CWebBrowserContainer *nsUnknownContentTypeHandler::GetWebBrowser(nsIDOMWindow *aWindow)
PtWidget_t *nsUnknownContentTypeHandler::GetWebBrowser(nsIDOMWindow *aWindow)
{
nsCOMPtr<nsIWebBrowserChrome> chrome;
CWebBrowserContainer *val = 0;
PtWidget_t *val = 0;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return nsnull;
@ -170,8 +171,8 @@ nsWebProgressListener::~nsWebProgressListener() { }
/* void onProgressChange (in nsIWebProgress aProgress, in nsIRequest aRequest, in long curSelfProgress, in long maxSelfProgress, in long curTotalProgress, in long maxTotalProgress); */
NS_IMETHODIMP nsWebProgressListener::OnProgressChange(nsIWebProgress *aProgress, nsIRequest *aRequest, PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curTotalProgress, PRInt32 maxTotalProgress) {
/* ATENTIE */ printf("OnProgressChange curSelfProgress=%d maxSelfProgress=%d curTotalProgress=%d maxTotalProgress=%d\n",
curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress );
/* ATENTIE */ //printf("OnProgressChange curSelfProgress=%d maxSelfProgress=%d curTotalProgress=%d maxTotalProgress=%d\n",
//curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress );
return NS_OK;
}
@ -203,7 +204,7 @@ NS_IMPL_RELEASE( className );
/* QueryInterface implementation for this class. */
NS_IMETHODIMP className::QueryInterface( REFNSIID anIID, void **anInstancePtr ) {
nsresult rv = NS_OK;
/* ATENTIE */ printf("QueryInterface!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* ATENTIE */ //printf("QueryInterface!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
/* Check for place to return result. */
if( !anInstancePtr ) rv = NS_ERROR_NULL_POINTER;

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

@ -7,7 +7,8 @@
#include "nsIWebBrowserPersist.h"
#include "nsWeakReference.h"
#include "nsIWindowWatcher.h"
#include "WebBrowserContainer.h"
#include "nsIEmbeddingSiteWindow.h"
#include <Pt.h>
static NS_DEFINE_CID( kCID, NS_IHELPERAPPLAUNCHERDIALOG_IID );
@ -28,7 +29,7 @@ public:
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
private:
CWebBrowserContainer* GetWebBrowser(nsIDOMWindow *aWindow);
PtWidget_t* GetWebBrowser(nsIDOMWindow *aWindow);
}; // nsUnknownContentTypeHandler

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