Drop the browser stuff, it will be replaced by hulahop.

master
Marco Pesenti Gritti 17 years ago
parent 6c671fb7fe
commit 42f7eeedc8

@ -1,4 +1,4 @@
SUBDIRS = bin browser data po shell sugar services
SUBDIRS = bin data po shell sugar services
ACLOCAL_AMFLAGS = -I m4

@ -1,183 +0,0 @@
#include <config.h>
#include <stdio.h>
#include <gtkmozembed.h>
#include <gtkmozembed_internal.h>
#include <nsIRequest.h>
#include <nsNetUtil.h>
#include <nsISeekableStream.h>
#include <nsIHttpChannel.h>
#include <nsIUploadChannel.h>
#include <nsIWebBrowser.h>
#include <nsISHistory.h>
#include <nsIHistoryEntry.h>
#include <nsISHEntry.h>
#include <nsIInputStream.h>
#include <nsIWebNavigation.h>
#include "GeckoBrowserPersist.h"
GeckoBrowserPersist::GeckoBrowserPersist(SugarBrowser *browser)
: mBrowser(browser)
{
}
GeckoBrowserPersist::~GeckoBrowserPersist()
{
}
static nsresult
NewURI(const char *uri, nsIURI **result)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager (getter_AddRefs (mgr));
NS_ENSURE_TRUE(mgr, FALSE);
nsCOMPtr<nsIIOService> ioService;
rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1",
NS_GET_IID (nsIIOService),
getter_AddRefs(ioService));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCString cSpec(uri);
return ioService->NewURI (cSpec, nsnull, nsnull, result);
}
static nsresult
GetPostData(SugarBrowser *browser, nsIInputStream **postData)
{
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, NS_ERROR_FAILURE);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(webBrowser));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
PRInt32 sindex;
nsCOMPtr<nsISHistory> sessionHistory;
webNav->GetSessionHistory(getter_AddRefs(sessionHistory));
NS_ENSURE_TRUE(sessionHistory, NS_ERROR_FAILURE);
nsCOMPtr<nsIHistoryEntry> entry;
sessionHistory->GetIndex(&sindex);
sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry));
nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(entry));
if (shEntry) {
shEntry->GetPostData(postData);
}
return NS_OK;
}
bool
GeckoBrowserPersist::SaveURI(const char *uri, const char *filename)
{
nsresult rv;
nsCOMPtr<nsIURI> sourceURI;
rv = NewURI(uri, getter_AddRefs(sourceURI));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCOMPtr<nsILocalFile> destFile = do_CreateInstance("@mozilla.org/file/local;1");
NS_ENSURE_TRUE(destFile, FALSE);
destFile->InitWithNativePath(nsCString(filename));
nsCOMPtr<nsIInputStream> postData;
GetPostData(mBrowser, getter_AddRefs(postData));
nsCOMPtr<nsIChannel> inputChannel;
rv = NS_NewChannel(getter_AddRefs(inputChannel), sourceURI,
nsnull, nsnull, nsnull, nsIRequest::LOAD_NORMAL);
NS_ENSURE_SUCCESS(rv, FALSE);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(inputChannel));
if (httpChannel) {
nsCOMPtr<nsISeekableStream> stream(do_QueryInterface(postData));
if (stream)
{
// Rewind the postdata stream
stream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
// Attach the postdata to the http channel
uploadChannel->SetUploadStream(postData, EmptyCString(), -1);
}
}
nsCOMPtr<nsIInputStream> stream;
rv = inputChannel->Open(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCOMPtr<nsIFileOutputStream> fileOutputStream =
do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, FALSE);
rv = fileOutputStream->Init(destFile, -1, -1, 0);
NS_ENSURE_SUCCESS(rv, FALSE);
// Read data from the input and write to the output
char buffer[8192];
PRUint32 bytesRead;
PRUint32 bytesRemaining;
PRBool cancel = PR_FALSE;
PRBool readError;
rv = stream->Available(&bytesRemaining);
NS_ENSURE_SUCCESS(rv, FALSE);
while (!cancel && bytesRemaining)
{
readError = PR_TRUE;
rv = stream->Read(buffer, PR_MIN(sizeof(buffer), bytesRemaining), &bytesRead);
if (NS_SUCCEEDED(rv))
{
readError = PR_FALSE;
// Write out the data until something goes wrong, or, it is
// all written. We loop because for some errors (e.g., disk
// full), we get NS_OK with some bytes written, then an error.
// So, we want to write again in that case to get the actual
// error code.
const char *bufPtr = buffer; // Where to write from.
while (NS_SUCCEEDED(rv) && bytesRead)
{
PRUint32 bytesWritten = 0;
rv = fileOutputStream->Write(bufPtr, bytesRead, &bytesWritten);
if (NS_SUCCEEDED(rv))
{
bytesRead -= bytesWritten;
bufPtr += bytesWritten;
bytesRemaining -= bytesWritten;
// Force an error if (for some reason) we get NS_OK but
// no bytes written.
if (!bytesWritten)
{
rv = NS_ERROR_FAILURE;
cancel = PR_TRUE;
}
}
else
{
// Disaster - can't write out the bytes - disk full / permission?
cancel = PR_TRUE;
}
}
}
else
{
// Disaster - can't read the bytes - broken link / file error?
cancel = PR_TRUE;
}
}
NS_ENSURE_SUCCESS(rv, FALSE);
stream->Close();
return TRUE;
}

@ -1,19 +0,0 @@
#ifndef __GECKO_BROWSER_PERSIST_H__
#define __GECKO_BROWSER_PERSIST_H__
#include "sugar-browser.h"
class GeckoBrowserPersist
{
public:
GeckoBrowserPersist(SugarBrowser *browser);
~GeckoBrowserPersist();
bool SaveURI(const char *uri, const char *filename);
private:
SugarBrowser *mBrowser;
protected:
/* additional members */
};
#endif // __GECKO_BROWSER_PERSIST_H__

@ -1,142 +0,0 @@
#include <nsCExternalHandlerService.h>
#include <nsIFile.h>
#include <nsIFactory.h>
#include <nsILocalFile.h>
#include <nsStringAPI.h>
#include <nsComponentManagerUtils.h>
#include "GeckoContentHandler.h"
class GeckoContentHandler : public nsIHelperAppLauncherDialog
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
GeckoContentHandler();
virtual ~GeckoContentHandler();
};
GeckoContentHandler::GeckoContentHandler()
{
}
GeckoContentHandler::~GeckoContentHandler()
{
}
NS_IMPL_ISUPPORTS1(GeckoContentHandler, nsIHelperAppLauncherDialog)
NS_IMETHODIMP
GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher,
nsISupports *aContext,
PRUint32 aReason)
{
aLauncher->SaveToDisk(NULL, PR_FALSE);
return NS_OK;
}
#include <glib.h>
NS_IMETHODIMP
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
nsISupports *aWindowContext,
const PRUnichar *aDefaultFile,
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
char *filename = NULL;
nsCString defaultFile;
NS_UTF16ToCString(nsString(aDefaultFile), NS_CSTRING_ENCODING_UTF8, defaultFile);
nsCOMPtr <nsILocalFile> destFile(do_CreateInstance("@mozilla.org/file/local;1"));
NS_ENSURE_TRUE(destFile, NS_ERROR_FAILURE);
const char * suggested = defaultFile.get();
if (strlen(suggested) > 0) {
filename = g_build_path("/", g_get_tmp_dir (), suggested, NULL);
} else {
filename = tempnam(NULL, NULL);
}
if (filename == NULL)
return NS_ERROR_OUT_OF_MEMORY;
destFile->InitWithNativePath(nsCString(filename));
g_free(filename);
NS_IF_ADDREF(*_retval = destFile);
return NS_OK;
}
//*****************************************************************************
// GeckoContentHandlerFactory
//*****************************************************************************
class GeckoContentHandlerFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
GeckoContentHandlerFactory();
virtual ~GeckoContentHandlerFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoContentHandlerFactory, nsIFactory)
GeckoContentHandlerFactory::GeckoContentHandlerFactory() {
}
GeckoContentHandlerFactory::~GeckoContentHandlerFactory() {
}
NS_IMETHODIMP
GeckoContentHandlerFactory::CreateInstance(nsISupports *aOuter,
const nsIID & aIID,
void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NULL;
GeckoContentHandler *inst = new GeckoContentHandler;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return rv;
}
NS_IMETHODIMP
GeckoContentHandlerFactory::LockFactory(PRBool lock)
{
return NS_OK;
}
//*****************************************************************************
nsresult
NS_NewGeckoContentHandlerFactory(nsIFactory** aFactory)
{
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
GeckoContentHandlerFactory *result = new GeckoContentHandlerFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aFactory = result;
return NS_OK;
}

@ -1,19 +0,0 @@
#ifndef __GECKO_CONTENT_HANDLER_H__
#define __GECKO_CONTENT_HANDLER_H__
#include <nsCOMPtr.h>
#include <nsIHelperAppLauncherDialog.h>
#define GECKOCONTENTHANDLER_CID \
{ /* 2321843e-6377-11db-967b-00e08161165f */ \
0x2321843e, \
0x6377, \
0x11db, \
{0x96, 0x7b, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
}
class nsIFactory;
extern "C" NS_EXPORT nsresult NS_NewGeckoContentHandlerFactory(nsIFactory** aFactory);
#endif /* __GECKO_CONTENT_HANDLER_H */

@ -1,86 +0,0 @@
#include "GeckoDirectoryProvider.h"
#include <nsCOMPtr.h>
#include <nsIIOService.h>
#include <nsNetUtil.h>
#include <nsArrayEnumerator.h>
#include <nsILocalFile.h>
#include <nsDirectoryServiceDefs.h>
#include <nsIToolkitChromeRegistry.h>
#include <nsIDirectoryService.h>
#include <nsCOMArray.h>
#include <glib.h>
NS_IMPL_ISUPPORTS2 (GeckoDirectoryProvider,
nsIDirectoryServiceProvider,
nsIDirectoryServiceProvider2)
GeckoDirectoryProvider::GeckoDirectoryProvider(const char *sugar_path,
const char *profile_path)
{
mComponentPath = g_build_filename
(sugar_path, "mozilla", "components", NULL);
mCompregPath = g_build_filename
(profile_path, "compreg.dat", NULL);
}
GeckoDirectoryProvider::~GeckoDirectoryProvider()
{
if(mComponentPath)
g_free(mComponentPath);
if(mCompregPath)
g_free(mCompregPath);
}
/* nsIFile getFile (in string prop, out PRBool persistent); */
NS_IMETHODIMP
GeckoDirectoryProvider::GetFile (const char *prop,
PRBool *persistent,
nsIFile **_retval)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFile> file;
if (!strcmp(prop, NS_XPCOM_COMPONENT_REGISTRY_FILE)) {
rv = NS_NewNativeLocalFile(nsDependentCString(mCompregPath),
PR_TRUE,
getter_AddRefs(file));
}
if (NS_SUCCEEDED(rv) && file) {
NS_ADDREF(*_retval = file);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
/* nsISimpleEnumerator getFiles (in string aProperty); */
NS_IMETHODIMP
GeckoDirectoryProvider::GetFiles (const char *aProperty, nsISimpleEnumerator **aResult)
{
nsresult rv = NS_ERROR_FAILURE;
if (!strcmp(aProperty, NS_XPCOM_COMPONENT_DIR_LIST)) {
if (mComponentPath) {
nsCOMPtr<nsILocalFile> componentDir;
rv = NS_NewNativeLocalFile(nsDependentCString(mComponentPath),
PR_TRUE,
getter_AddRefs(componentDir));
NS_ENSURE_SUCCESS (rv, rv);
nsCOMArray<nsIFile> array;
rv = array.AppendObject (componentDir);
NS_ENSURE_SUCCESS (rv, rv);
rv = NS_NewArrayEnumerator (aResult, array);
NS_ENSURE_SUCCESS (rv, rv);
rv = NS_SUCCESS_AGGREGATE_RESULT;
}
}
return rv;
}

@ -1,40 +0,0 @@
/*
* Copyright (C) 2007, One Laptop Per Child
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GECKO_DIRECTORY_PROVIDER_H
#define GECKO_DIRECTORY_PROVIDER_H
#include <nsIDirectoryService.h>
class GeckoDirectoryProvider : public nsIDirectoryServiceProvider2
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
GeckoDirectoryProvider(const char *sugar_path,
const char *profile_path);
virtual ~GeckoDirectoryProvider();
private:
char *mComponentPath;
char *mCompregPath;
};
#endif /* GECKO_DIRECTORY_PROVIDER_H */

@ -1,237 +0,0 @@
#include <config.h>
#include <unistd.h>
#include <glib.h>
#include <imgICache.h>
#include <nsComponentManagerUtils.h>
#include <nsCOMPtr.h>
#include <nsIDOMHTMLElement.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsIIOService.h>
#include <nsILocalFile.h>
#include <nsIMIMEHeaderParam.h>
#include <nsIProperties.h>
#include <nsISupportsPrimitives.h>
#include <nsIURI.h>
#include <nsIURL.h>
#include <nsServiceManagerUtils.h>
#include <nsStringAPI.h>
#include "GeckoDocumentObject.h"
#include "GeckoBrowserPersist.h"
GeckoDocumentObject::GeckoDocumentObject(SugarBrowser *browser, nsIDOMNode *node)
: mBrowser(browser),
mNode(node),
mImage(NULL)
{
}
GeckoDocumentObject::~GeckoDocumentObject()
{
}
bool GeckoDocumentObject::IsImage()
{
if(mImage) {
return true;
}
nsresult rv;
PRUint16 type;
rv = mNode->GetNodeType(&type);
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(mNode);
if ((nsIDOMNode::ELEMENT_NODE == type) && element) {
nsString uTag;
rv = element->GetLocalName(uTag);
if(NS_FAILED(rv)) return rv;
nsCString tag;
NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag);
if (g_ascii_strcasecmp (tag.get(), "img") == 0) {
nsCOMPtr <nsIDOMHTMLImageElement> imagePtr;
imagePtr = do_QueryInterface(mNode, &rv);
if(NS_FAILED(rv)) return rv;
mImage = imagePtr;
return true;
}
}
return false;
}
static nsresult
NewURI(const char *uri, nsIURI **result)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager (getter_AddRefs (mgr));
NS_ENSURE_TRUE(mgr, FALSE);
nsCOMPtr<nsIIOService> ioService;
rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1",
NS_GET_IID (nsIIOService),
getter_AddRefs(ioService));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCString cSpec(uri);
return ioService->NewURI (cSpec, nsnull, nsnull, result);
}
static nsresult
FilenameFromContentDisposition(nsCString contentDisposition, nsCString &fileName)
{
nsresult rv;
nsCString fallbackCharset;
nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar =
do_GetService("@mozilla.org/network/mime-hdrparam;1");
NS_ENSURE_TRUE(mimehdrpar, NS_ERROR_FAILURE);
nsString aFileName;
rv = mimehdrpar->GetParameter (contentDisposition, "filename",
fallbackCharset, PR_TRUE, nsnull,
aFileName);
if (NS_FAILED(rv) || !fileName.Length()) {
rv = mimehdrpar->GetParameter (contentDisposition, "name",
fallbackCharset, PR_TRUE, nsnull,
aFileName);
}
if (NS_SUCCEEDED(rv) && fileName.Length()) {
NS_UTF16ToCString (aFileName, NS_CSTRING_ENCODING_UTF8, fileName);
}
return NS_OK;
}
static nsresult
GetImageProperties(char *imgURIStr, nsIProperties **properties)
{
nsresult rv;
nsCOMPtr<nsIURI> imageURI;
rv = NewURI(imgURIStr, getter_AddRefs(imageURI));
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager(getter_AddRefs(mgr));
NS_ENSURE_TRUE(mgr, NS_ERROR_FAILURE);
nsCOMPtr<imgICache> imgCache;
rv = mgr->GetServiceByContractID("@mozilla.org/image/cache;1",
NS_GET_IID(imgICache),
getter_AddRefs(imgCache));
if(NS_FAILED(rv)) return rv;
imgCache->FindEntryProperties(imageURI, properties);
NS_ENSURE_TRUE(mgr, NS_ERROR_FAILURE);
return NS_OK;
}
char *
GeckoDocumentObject::GetImageName()
{
if(!IsImage()) {
return NULL;
}
if(mImageName.Length()) {
return g_strdup(mImageName.get());
}
nsresult rv;
char *imgURIStr = GetImageURI();
nsCOMPtr<nsIProperties> imgProperties;
rv = GetImageProperties(imgURIStr, getter_AddRefs(imgProperties));
NS_ENSURE_SUCCESS(rv, NULL);
if (imgProperties) {
nsCOMPtr<nsISupportsCString> dispositionCString;
imgProperties->Get("content-disposition",
NS_GET_IID(nsISupportsCString),
getter_AddRefs(dispositionCString));
if (dispositionCString) {
nsCString contentDisposition;
dispositionCString->GetData(contentDisposition);
FilenameFromContentDisposition(contentDisposition, mImageName);
}
}
if (!mImageName.Length()) {
nsCOMPtr<nsIURI> imageURI;
rv = NewURI(imgURIStr, getter_AddRefs(imageURI));
NS_ENSURE_SUCCESS(rv, NULL);
nsCOMPtr<nsIURL> url(do_QueryInterface(imageURI));
if (url) {
url->GetFileName(mImageName);
}
}
return mImageName.Length() ? g_strdup(mImageName.get()) : NULL;
}
char *
GeckoDocumentObject::GetImageMimeType()
{
if(!IsImage()) {
return NULL;
}
if(mImageMimeType.Length()) {
return g_strdup(mImageMimeType.get());
}
nsresult rv;
char *imgURIStr = GetImageURI();
nsCOMPtr<nsIProperties> imgProperties;
rv = GetImageProperties(imgURIStr, getter_AddRefs(imgProperties));
NS_ENSURE_SUCCESS(rv, NULL);
if (imgProperties) {
nsCOMPtr<nsISupportsCString> typeCString;
imgProperties->Get("type",
NS_GET_IID(nsISupportsCString),
getter_AddRefs(typeCString));
if (typeCString) {
typeCString->GetData(mImageMimeType);
}
}
return mImageMimeType.Length() ? g_strdup(mImageMimeType.get()) : NULL;
}
char *
GeckoDocumentObject::GetImageURI()
{
if(!IsImage()) {
return NULL;
}
if(!mImageURI.Length()) {
nsresult rv;
nsString img;
rv = mImage->GetSrc(img);
if (NS_FAILED(rv)) return NULL;
NS_UTF16ToCString (img, NS_CSTRING_ENCODING_UTF8, mImageURI);
}
return g_strdup(mImageURI.get());
}
bool
GeckoDocumentObject::SaveImage(const char *filename)
{
GeckoBrowserPersist browserPersist(mBrowser);
return browserPersist.SaveURI(mImageURI.get(), filename);
}

@ -1,31 +0,0 @@
#ifndef __GECKO_DOCUMENT_OBJECT_H__
#define __GECKO_DOCUMENT_OBJECT_H__
#include <nsIDOMNode.h>
#include <nsIDOMHTMLImageElement.h>
#include "sugar-browser.h"
class GeckoDocumentObject
{
public:
GeckoDocumentObject(SugarBrowser *browser, nsIDOMNode *node);
~GeckoDocumentObject();
bool IsImage();
char *GetImageURI();
char *GetImageName();
char *GetImageMimeType();
bool SaveImage(const char *filename);
private:
SugarBrowser *mBrowser;
nsCOMPtr<nsIDOMNode> mNode;
nsCOMPtr<nsIDOMHTMLImageElement> mImage;
nsCString mImageURI;
nsCString mImageName;
nsCString mImageMimeType;
protected:
/* additional members */
};
#endif // __GECKO_DOCUMENT_OBJECT_H__

@ -1,262 +0,0 @@
#include "config.h"
#include <nsIFactory.h>
#include <nsIFile.h>
#include <nsIFileURL.h>
#include <nsServiceManagerUtils.h>
#include <nsIMIMEService.h>
#include "sugar-download-manager.h"
#include "GeckoDownload.h"
#define APPLICATION_OCTET_STREAM "application/octet-stream"
class GeckoDownload : public nsITransfer
{
public:
GeckoDownload();
virtual ~GeckoDownload();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIWEBPROGRESSLISTENER2
NS_DECL_NSITRANSFER
protected:
nsIURI *mSource;
nsCString mTargetFileName;
nsIMIMEInfo *mMIMEInfo;
nsILocalFile *mTempFile;
};
GeckoDownload::GeckoDownload ()
{
}
GeckoDownload::~GeckoDownload ()
{
}
NS_IMPL_ISUPPORTS3 (GeckoDownload,
nsIWebProgressListener,
nsIWebProgressListener2,
nsITransfer)
NS_IMETHODIMP
GeckoDownload::Init (nsIURI *aSource,
nsIURI *aTarget,
const nsAString &aDisplayName,
nsIMIMEInfo *aMIMEInfo,
PRTime aStartTime,
nsILocalFile *aTempFile,
nsICancelable *aCancelable)
{
mSource = aSource;
mMIMEInfo = aMIMEInfo;
mTempFile = aTempFile;
nsresult rv;
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
nsCOMPtr<nsIFile> file;
rv = fileURL->GetFile(getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
file->GetNativePath (mTargetFileName);
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aStateFlags,
nsresult aStatus)
{
SugarDownloadManager *download_manager = sugar_get_download_manager();
if(aStateFlags == STATE_START) {
nsCString url;
nsCString mimeType;
mMIMEInfo->GetMIMEType(mimeType);
mSource->GetSpec(url);
/* If the file is application/octet-stream, look up a better mime type
from the extension. */
if(mimeType.Equals(APPLICATION_OCTET_STREAM)) {
nsresult rv;
nsCOMPtr<nsIMIMEService> mimeService(
do_GetService("@mozilla.org/mime;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
const char *fileExt = strrchr(mTargetFileName.get(), '.');
if(fileExt) {
nsCString contentType;
mimeService->GetTypeFromExtension(nsCString(fileExt),
contentType);
if(!contentType.IsEmpty()) {
mimeType = contentType;
}
}
}
sugar_download_manager_download_started(download_manager,
url.get(),
mimeType.get(),
mTargetFileName.get());
} else if(aStateFlags == STATE_STOP) {
if(NS_SUCCEEDED(aStatus)) {
sugar_download_manager_download_completed(download_manager,
mTargetFileName.get());
} else {
sugar_download_manager_download_cancelled(download_manager,
mTargetFileName.get());
}
}
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnProgressChange (nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return OnProgressChange64 (aWebProgress,
aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress);
}
NS_IMETHODIMP
GeckoDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt64 aCurSelfProgress,
PRInt64 aMaxSelfProgress,
PRInt64 aCurTotalProgress,
PRInt64 aMaxTotalProgress)
{
SugarDownloadManager *download_manager = sugar_get_download_manager ();
PRInt32 percentComplete =
(PRInt32)(((float)aCurSelfProgress / (float)aMaxSelfProgress) * 100.0);
sugar_download_manager_update_progress (download_manager,
mTargetFileName.get (),
percentComplete);
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnLocationChange (nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *location)
{
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnStatusChange (nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnSecurityChange (nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 state)
{
return NS_OK;
}
NS_IMETHODIMP
GeckoDownload::OnRefreshAttempted (nsIWebProgress *aWebProgress,
nsIURI *aRefreshURI,
PRInt32 aMillis,
PRBool aSameURI,
PRBool *_retval)
{
return NS_OK;
}
//*****************************************************************************
// GeckoDownloadFactory
//*****************************************************************************
class GeckoDownloadFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
GeckoDownloadFactory();
virtual ~GeckoDownloadFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoDownloadFactory, nsIFactory)
GeckoDownloadFactory::GeckoDownloadFactory() {
}
GeckoDownloadFactory::~GeckoDownloadFactory() {
}
NS_IMETHODIMP
GeckoDownloadFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NULL;
GeckoDownload *inst = new GeckoDownload;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return rv;
}
NS_IMETHODIMP
GeckoDownloadFactory::LockFactory(PRBool lock)
{
return NS_OK;
}
//*****************************************************************************
nsresult
NS_NewGeckoDownloadFactory(nsIFactory** aFactory)
{
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
GeckoDownloadFactory *result = new GeckoDownloadFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aFactory = result;
return NS_OK;
}

@ -1,25 +0,0 @@
#ifndef __GECKO_DOWNLOAD_H__
#define __GECKO_DOWNLOAD_H__
#include <nsCOMPtr.h>
#include <nsIInterfaceRequestor.h>
#include <nsITransfer.h>
#include <nsIWebProgressListener.h>
#include <nsIMIMEInfo.h>
#include <nsIURL.h>
#include <nsILocalFile.h>
#include <nsStringAPI.h>
#define GECKODOWNLOAD_CID \
{ /* b1813bbe-6518-11db-967e-00e08161165f */ \
0xb1813bbe, \
0x6518, \
0x11db, \
{0x96, 0x7e, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
}
class nsIFactory;
extern "C" NS_EXPORT nsresult NS_NewGeckoDownloadFactory(nsIFactory** aFactory);
#endif // __GECKO_DOWNLOAD_H__

@ -1,214 +0,0 @@
#include <config.h>
#include <sys/time.h>
#include <time.h>
#include <glib.h>
#include <nsStringAPI.h>
#include <nsCOMPtr.h>
#include <nsITransferable.h>
#include <nsISupportsPrimitives.h>
#include <nsIDOMEventTarget.h>
#include <nsComponentManagerUtils.h>
#include <nsServiceManagerUtils.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsIDOMMouseEvent.h>
#include <nsIMIMEService.h>
#include "GeckoDragDropHooks.h"
#include "GeckoDocumentObject.h"
#define TEXT_URI_LIST "text/uri-list"
#define TEXT_X_MOZ_URL "text/x-moz-url"
#define FILE_LOCALHOST "file://"
//*****************************************************************************
// UriListDataProvider
//*****************************************************************************
class UriListDataProvider : public nsIFlavorDataProvider
{
public:
UriListDataProvider(GeckoDocumentObject *mDocumentObject);
virtual ~UriListDataProvider();
NS_DECL_ISUPPORTS
NS_DECL_NSIFLAVORDATAPROVIDER
private:
GeckoDocumentObject *mDocumentObject;
nsCString mFilePath;
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(UriListDataProvider, nsIFlavorDataProvider)
UriListDataProvider::UriListDataProvider(GeckoDocumentObject *documentObject)
: mDocumentObject(documentObject)
{
}
UriListDataProvider::~UriListDataProvider()
{
if(mFilePath.Length()) {
remove(mFilePath.get());
}
delete mDocumentObject;
}
NS_IMETHODIMP
UriListDataProvider::GetFlavorData(nsITransferable *aTransferable,
const char *aFlavor, nsISupports **aData,
PRUint32 *aDataLen)
{
NS_ENSURE_ARG_POINTER(aData && aDataLen);
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
char *image_name;
char *mime_type;
char *file_ext;
nsCString mime_ext;
timeval timestamp;
*aData = nsnull;
*aDataLen = 0;
if(g_ascii_strcasecmp(aFlavor, TEXT_URI_LIST) != 0) {
return rv;
}
gettimeofday(&timestamp, NULL);
mFilePath.Append(g_get_tmp_dir());
mFilePath.Append("/");
mFilePath.AppendInt(timestamp.tv_sec);
mFilePath.AppendInt(timestamp.tv_usec);
image_name = mDocumentObject->GetImageName();
file_ext = strrchr(image_name, '.');
mime_type = mDocumentObject->GetImageMimeType();
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1",
&rv));
NS_ENSURE_SUCCESS(rv, rv);
rv = mimeService->GetPrimaryExtension(nsCString(mime_type),
EmptyCString(),
mime_ext);
NS_ENSURE_SUCCESS(rv, rv);
if(!file_ext) {
mFilePath.Append(image_name);
mFilePath.Append(".");
mFilePath.Append(mime_ext);
} else if(strcmp(file_ext, mime_ext.get())) {
image_name[strlen(file_ext)] = 0;
mFilePath.Append(image_name);
mFilePath.Append(".");
mFilePath.Append(mime_ext);
} else {
mFilePath.Append(image_name);
}
g_free(mime_type);
g_free(image_name);
if(!mDocumentObject->SaveImage(mFilePath.get())) {
return NS_ERROR_FAILURE;
}
nsCString localURI(FILE_LOCALHOST);
localURI.Append(mFilePath);
nsString localURI16;
NS_CStringToUTF16(localURI, NS_CSTRING_ENCODING_UTF8, localURI16);
nsCOMPtr<nsISupportsString> localURIData(do_CreateInstance(
"@mozilla.org/supports-string;1", &rv));
if(NS_FAILED(rv)) return rv;
rv = localURIData->SetData(localURI16);
if(NS_FAILED(rv)) return rv;
CallQueryInterface(localURIData, aData);
*aDataLen = sizeof(nsISupportsString*);
// FIXME: Why do we need this? Is there a leak in mozilla?
this->Release();
return rv;
}
//*****************************************************************************
// GeckoDragDropHooks
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoDragDropHooks, nsIClipboardDragDropHooks)
GeckoDragDropHooks::GeckoDragDropHooks(SugarBrowser *browser)
: mBrowser(browser)
{
}
GeckoDragDropHooks::~GeckoDragDropHooks()
{
}
NS_IMETHODIMP
GeckoDragDropHooks::AllowStartDrag(nsIDOMEvent *event, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
GeckoDragDropHooks::AllowDrop(nsIDOMEvent *event, nsIDragSession *session,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
GeckoDragDropHooks::OnCopyOrDrag(nsIDOMEvent *aEvent, nsITransferable *trans,
PRBool *_retval)
{
nsresult rv;
*_retval = true;
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aEvent, &rv);
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
rv = mouseEvent->GetTarget(getter_AddRefs(eventTarget));
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMNode> targetNode;
targetNode = do_QueryInterface(eventTarget, &rv);
if(NS_FAILED(rv)) return rv;
GeckoDocumentObject *documentObject = new GeckoDocumentObject(mBrowser,
targetNode);
if(documentObject->IsImage()) {
rv = trans->RemoveDataFlavor(TEXT_X_MOZ_URL);
if(NS_FAILED(rv)) return rv;
rv = trans->AddDataFlavor(TEXT_URI_LIST);
if(NS_FAILED(rv)) return rv;
UriListDataProvider *rawPtr = new UriListDataProvider(documentObject);
nsCOMPtr<nsISupports> dataProvider(do_QueryInterface(rawPtr, &rv));
if(NS_FAILED(rv)) return rv;
rv = trans->SetTransferData(TEXT_URI_LIST, dataProvider, 0);
if(NS_FAILED(rv)) return rv;
}
return rv;
}
NS_IMETHODIMP
GeckoDragDropHooks::OnPasteOrDrop(nsIDOMEvent *event, nsITransferable *trans,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

@ -1,25 +0,0 @@
#ifndef __GECKO_DRAG_DROP_HOOKS_H__
#define __GECKO_DRAG_DROP_HOOKS_H__
#include <nsIClipboardDragDropHooks.h>
#include "sugar-browser.h"
class GeckoDragDropHooks : public nsIClipboardDragDropHooks
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICLIPBOARDDRAGDROPHOOKS
GeckoDragDropHooks(SugarBrowser *browser);
private:
~GeckoDragDropHooks();
SugarBrowser *mBrowser;
protected:
/* additional members */
};
#endif // __GECKO_DRAG_DROP_HOOKS_H__

@ -1,83 +0,0 @@
SUBDIRS = components
libsugarbrowser_la_CPPFLAGS = \
$(WARN_CFLAGS) \
$(LIB_CFLAGS) \
$(GECKO_CFLAGS) \
$(NSPR_CFLAGS) \
-I$(MOZILLA_INCLUDE_DIR)/chrome \
-I$(MOZILLA_INCLUDE_DIR)/commandhandler \
-I$(MOZILLA_INCLUDE_DIR)/content \
-I$(MOZILLA_INCLUDE_DIR)/dom \
-I$(MOZILLA_INCLUDE_DIR)/docshell \
-I$(MOZILLA_INCLUDE_DIR)/exthandler \
-I$(MOZILLA_INCLUDE_DIR)/gtkembedmoz \
-I$(MOZILLA_INCLUDE_DIR)/imglib2 \
-I$(MOZILLA_INCLUDE_DIR)/mimetype \
-I$(MOZILLA_INCLUDE_DIR)/necko \
-I$(MOZILLA_INCLUDE_DIR)/pref \
-I$(MOZILLA_INCLUDE_DIR)/shistory \
-I$(MOZILLA_INCLUDE_DIR)/uriloader \
-I$(MOZILLA_INCLUDE_DIR)/webbrwsr \
-I$(MOZILLA_INCLUDE_DIR)/webbrowserpersist \
-I$(MOZILLA_INCLUDE_DIR)/widget \
-I$(MOZILLA_INCLUDE_DIR)/xpcom \
-I$(top_builddir)/browser/components/sessionstore \
-I$(top_builddir)/browser/components/browserhelper \
-DPLUGIN_DIR=\"$(libdir)/mozilla/plugins\" \
-DSHARE_DIR=\"$(pkgdatadir)\"
noinst_LTLIBRARIES = libsugarbrowser.la
libsugarbrowser_la_LIBADD = \
$(LIB_LIBS) \
$(GECKO_LIBS)
libsugarbrowser_la_SOURCES = \
$(BUILT_SOURCES) \
GeckoBrowserPersist.h \
GeckoBrowserPersist.cpp \
GeckoContentHandler.h \
GeckoContentHandler.cpp \
GeckoDocumentObject.h \
GeckoDocumentObject.cpp \
GeckoDirectoryProvider.h \
GeckoDirectoryProvider.cpp \
GeckoDragDropHooks.h \
GeckoDragDropHooks.cpp \
GeckoDownload.h \
GeckoDownload.cpp \
sugar-address-entry.c \
sugar-address-entry.h \
sugar-browser.h \
sugar-browser.cpp \
sugar-download.h \
sugar-download.c \
sugar-download-manager.h \
sugar-download-manager.c
BUILT_SOURCES = \
sugar-marshal.c \
sugar-marshal.h
stamp_files = \
stamp-sugar-marshal.c \
stamp-sugar-marshal.h
sugar-marshal.c: stamp-sugar-marshal.c
@true
stamp-sugar-marshal.c: sugar-marshal.list
$(GLIB_GENMARSHAL) --prefix=sugar_marshal $(srcdir)/sugar-marshal.list --header --body > sugar-marshal.c \
&& echo timestamp > $(@F)
sugar-marshal.h: stamp-sugar-marshal.h
@true
stamp-sugar-marshal.h: sugar-marshal.list
$(GLIB_GENMARSHAL) --prefix=sugar_marshal $(srcdir)/sugar-marshal.list --header > sugar-marshal.h \
&& echo timestamp > $(@F)
CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
EXTRA_DIST = sugar-marshal.list

@ -1 +0,0 @@
SUBDIRS = browserhelper sessionstore

@ -1,4 +0,0 @@
nsIBrowserHelper.h
nsIBrowserHelper.xpt
stamp-nsIBrowserHelper.h
stamp-nsIBrowserHelper.xpt

@ -1,32 +0,0 @@
sessionstoredir = $(pkgdatadir)/mozilla/components
sessionstore_DATA = \
nsIBrowserHelper.xpt \
nsBrowserHelper.js
BUILT_SOURCES = \
nsIBrowserHelper.xpt \
nsIBrowserHelper.h
stamp_files = \
stamp-nsIBrowserHelper.xpt \
stamp-nsIBrowserHelper.h
nsIBrowserHelper.xpt: stamp-nsIBrowserHelper.xpt
@true
stamp-nsIBrowserHelper.xpt: nsIBrowserHelper.idl
$(XPIDL) -m typelib -w -v -I $(MOZILLA_IDL_DIR) -e nsIBrowserHelper.xpt \
$(srcdir)/nsIBrowserHelper.idl \
&& echo timestamp > $(@F)
nsIBrowserHelper.h: stamp-nsIBrowserHelper.h
@true
stamp-nsIBrowserHelper.h: nsIBrowserHelper.idl
$(XPIDL) -m header -w -v -I $(MOZILLA_IDL_DIR) -e nsIBrowserHelper.h \
$(srcdir)/nsIBrowserHelper.idl \
&& echo timestamp > $(@F)
CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
EXTRA_DIST = nsIBrowserHelper.idl nsBrowserHelper.js

@ -1,100 +0,0 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const CID = Components.ID("{475e1194-92bc-4e03-92f3-5ad6ccddaca3}");
const CONTRACT_ID = "@laptop.org/browser/browserhelper;1";
const CLASS_NAME = "Browser Helper";
var browsers = [];
function BrowserHelperService() {
}
BrowserHelperService.prototype = {
/* ........ nsIBrowserHelper API .............. */
getBrowser: function bh_getBrowser(aId) {
return browsers[aId]
},
registerBrowser: function bh_registerBrowser(aId, aBrowser) {
browsers[aId] = aBrowser;
},
unregisterBrowser: function bh_unregisterBrowser(aId) {
browsers.pop(aId)
},
QueryInterface: function(aIID) {
if (!aIID.equals(Ci.nsISupports) &&
!aIID.equals(Ci.nsIBrowserHelper)) {
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
return this;
}
}
/* :::::::: Service Registration & Initialization ::::::::::::::: */
/* ........ nsIModule .............. */
const BrowserHelperModule = {
getClassObject: function(aCompMgr, aCID, aIID) {
if (aCID.equals(CID)) {
return BrowserHelperFactory;
}
Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
return null;
},
registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
aCompMgr.registerFactoryLocation(CID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
},
unregisterSelf: function(aCompMgr, aLocation, aType) {
aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
aCompMgr.unregisterFactoryLocation(CID, aLocation);
},
canUnload: function(aCompMgr) {
return true;
}
}
/* ........ nsIFactory .............. */
const BrowserHelperFactory = {
createInstance: function(aOuter, aIID) {
if (aOuter != null) {
Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
return null;
}
return (new BrowserHelperService()).QueryInterface(aIID);
},
lockFactory: function(aLock) { },
QueryInterface: function(aIID) {
if (!aIID.equals(Ci.nsISupports) && !aIID.equals(Ci.nsIModule) &&
!aIID.equals(Ci.nsIFactory) && !aIID.equals(Ci.nsIBrowserHelper)) {
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
return this;
}
};
function NSGetModule(aComMgr, aFileSpec) {
dump("nsBrowserHelper: NSGetModule\n")
return BrowserHelperModule;
}

@ -1,13 +0,0 @@
#include "nsISupports.idl"
interface nsIWebBrowser;
[scriptable, uuid(475e1194-92bc-4e03-92f3-5ad6ccddaca3)]
interface nsIBrowserHelper : nsISupports
{
nsIWebBrowser getBrowser(in long id);
void registerBrowser(in long id, in nsIWebBrowser browser);
void unregisterBrowser(in long id);
};

@ -1,4 +0,0 @@
nsISessionStore.h
nsISessionStore.xpt
stamp-nsISessionStore.h
stamp-nsISessionStore.xpt

@ -1,32 +0,0 @@
sessionstoredir = $(pkgdatadir)/mozilla/components
sessionstore_DATA = \
nsISessionStore.xpt \
nsSessionStore.js
BUILT_SOURCES = \
nsISessionStore.xpt \
nsISessionStore.h
stamp_files = \
stamp-nsISessionStore.xpt \
stamp-nsISessionStore.h
nsISessionStore.xpt: stamp-nsISessionStore.xpt
@true
stamp-nsISessionStore.xpt: nsISessionStore.idl
$(XPIDL) -m typelib -w -v -I $(MOZILLA_IDL_DIR) -e nsISessionStore.xpt \
$(srcdir)/nsISessionStore.idl \
&& echo timestamp > $(@F)
nsISessionStore.h: stamp-nsISessionStore.h
@true
stamp-nsISessionStore.h: nsISessionStore.idl
$(XPIDL) -m header -w -v -I $(MOZILLA_IDL_DIR) -e nsISessionStore.h \
$(srcdir)/nsISessionStore.idl \
&& echo timestamp > $(@F)
CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
EXTRA_DIST = nsISessionStore.idl nsSessionStore.js

@ -1,63 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 Session Restore component.
*
* The Initial Developer of the Original Code is
* Simon Bünzli <zeniko@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dietrich Ayala <dietrich@mozilla.com>
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIWebBrowser;
/**
* nsISessionStore keeps track of the current browsing state - i.e.
* tab history, cookies, scroll state, form data, POSTDATA and window features
* - and allows to restore everything into one window.
*/
[scriptable, uuid(11852a90-20de-11db-a98b-0800200c9a66)]
interface nsISessionStore : nsISupports
{
/**
* @param aBrowser is the browser whose state is to be returned.
*
* @return a JSON string representing the session state.
*/
AString getBrowserState(in nsIWebBrowser aBrowser);
/**
* @param aBrowser is the browser whose state is to be set.
* @param aState is a JSON string representing a session state.
*/
void setBrowserState(in nsIWebBrowser aBrowser, in AString aState);
};

@ -1,541 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 nsSessionStore component.
*
* The Initial Developer of the Original Code is
* Simon Bünzli <zeniko@gmail.com>
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dietrich Ayala <autonome@gmail.com>
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Heavily adapted to xulrunner for the OLPC from the firefox code in
* http://lxr.mozilla.org/seamonkey/source/browser/components/sessionstore.
*
* May 2007 Tomeu Vizoso
*/
/**
* Session Storage and Restoration
*
* Overview
* This service keeps track of a user's session, storing the various bits
* required to return the browser to it's current state. The relevant data is
* stored in memory, and is periodically saved to disk in a file in the
* profile directory. The service is started at first window load, in
* delayedStartup, and will restore the session from the data received from
* the nsSessionStartup service.
*/
/* :::::::: Constants and Helpers ::::::::::::::: */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const CID = Components.ID("{5280606b-2510-4fe0-97ef-9b5a22eafe6b}");
const CONTRACT_ID = "@mozilla.org/browser/sessionstore;1";
const CLASS_NAME = "Browser Session Store Service";
// sandbox to evaluate JavaScript code from non-trustable sources
var EVAL_SANDBOX = new Components.utils.Sandbox("about:blank");
function debug(aMsg) {
aMsg = ("SessionStore: " + aMsg).replace(/\S{80}/g, "$&\n");
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService)
.logStringMessage(aMsg);
}
/* :::::::: The Service ::::::::::::::: */
function SessionStoreService() {
}
SessionStoreService.prototype = {
/* ........ nsISessionStore API .............. */
getBrowserState: function sss_getBrowserState(aBrowser) {
dump("nsSessionStore::getBrowserState\n")
return this._toJSONString(this._getWindowState(aBrowser));
},
setBrowserState: function sss_setBrowserState(aBrowser, aState) {
dump("nsSessionStore::setBrowserState\n")
this.restoreWindow(aBrowser, "(" + aState + ")");
},
/* ........ Saving Functionality .............. */
/**
* Store all session data for a window
* @param aSHistory
* nsISHistory reference
*/
_saveWindowHistory: function sss_saveWindowHistory(aSHistory) {
var entries = [];
dump("nsSessionStore._saveWindowHistory " + aSHistory.count);
for (var i = 0; i < aSHistory.count; i++) {
entries.push(this._serializeHistoryEntry(aSHistory.getEntryAtIndex(i, false)));
}
return entries;
},
/**
* Get an object that is a serialized representation of a History entry
* Used for data storage
* @param aEntry
* nsISHEntry instance
* @returns object
*/
_serializeHistoryEntry: function sss_serializeHistoryEntry(aEntry) {
var entry = { url: aEntry.URI.spec, children: [] };
if (aEntry.title && aEntry.title != entry.url) {
entry.title = aEntry.title;
}
if (aEntry.isSubFrame) {
entry.subframe = true;
}
if (!(aEntry instanceof Ci.nsISHEntry)) {
return entry;
}
var cacheKey = aEntry.cacheKey;
if (cacheKey && cacheKey instanceof Ci.nsISupportsPRUint32) {
entry.cacheKey = cacheKey.data;
}
entry.ID = aEntry.ID;
var x = {}, y = {};
aEntry.getScrollPosition(x, y);
entry.scroll = x.value + "," + y.value;
try {
var prefPostdata = this._prefBranch.getIntPref("sessionstore.postdata");
if (prefPostdata && aEntry.postData && this._checkPrivacyLevel(aEntry.URI.schemeIs("https"))) {
aEntry.postData.QueryInterface(Ci.nsISeekableStream).
seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
var stream = Cc["@mozilla.org/scriptableinputstream;1"].
createInstance(Ci.nsIScriptableInputStream);
stream.init(aEntry.postData);
var postdata = stream.read(stream.available());
if (prefPostdata == -1 || postdata.replace(/^(Content-.*\r\n)+(\r\n)*/, "").length <= prefPostdata) {
entry.postdata = postdata;
}
}
}
catch (ex) { debug(ex); } // POSTDATA is tricky - especially since some extensions don't get it right
if (!(aEntry instanceof Ci.nsISHContainer)) {
return entry;
}
for (var i = 0; i < aEntry.childCount; i++) {
var child = aEntry.GetChildAt(i);
if (child) {
entry.children.push(this._serializeHistoryEntry(child));
}
else { // to maintain the correct frame order, insert a dummy entry
entry.children.push({ url: "about:blank" });
}
}
return entry;
},
/**
* serialize session data for a window
* @param aBrowser
* Browser reference
* @returns string
*/
_getWindowState: function sss_getWindowState(aBrowser) {
dump("nsSessionStore::_getWindowState: " + aBrowser + "\n")
windowState = this._collectWindowData(aBrowser);
/*
this._updateCookies(windowState);
*/
return windowState;
},
_collectWindowData: function sss_collectWindowData(aBrowser) {
dump("nsSessionStore::_collectWindowData\n")
aBrowser.QueryInterface(Ci.nsIWebNavigation);
historyState = this._saveWindowHistory(aBrowser.sessionHistory);
/*
this._updateTextAndScrollData(aWindow);
this._updateCookieHosts(aWindow);
this._updateWindowFeatures(aWindow);
*/
return {history: historyState/*, textAndScroll: textAndScrollState*/};
},
/* ........ Restoring Functionality .............. */
/**
* restore features to a single window
* @param aBrowser
* Browser reference
* @param aState
* JS object or its eval'able source
*/
restoreWindow: function sss_restoreWindow(aBrowser, aState) {
try {
var winData = typeof aState == "string" ? this._safeEval(aState) : aState;
}
catch (ex) { // invalid state object - don't restore anything
debug(ex);
dump(ex);
return;
}
this.restoreHistoryPrecursor(aBrowser, winData.history);
},
/**
* Manage history restoration for a window
* @param aBrowser
* Browser reference
* @param aHistoryData
* History data to be restored
*/
restoreHistoryPrecursor: function sss_restoreHistoryPrecursor(aBrowser, aHistoryData) {
/*
// make sure that all browsers and their histories are available
// - if one's not, resume this check in 100ms (repeat at most 10 times)
for (var t = aIx; t < aTabs.length; t++) {
try {
if (!tabbrowser.getBrowserForTab(aTabs[t]._tab).webNavigation.sessionHistory) {
throw new Error();
}
}
catch (ex) { // in case browser or history aren't ready yet
if (aCount < 10) {
var restoreHistoryFunc = function(self) {
self.restoreHistoryPrecursor(aWindow, aTabs, aSelectTab, aIx, aCount + 1);
}
aWindow.setTimeout(restoreHistoryFunc, 100, this);
return;
}
}
}
*/
// helper hash for ensuring unique frame IDs
var aIdMap = { used: {} };
this.restoreHistory(aBrowser, aHistoryData, aIdMap);
},
/**
* Restory history for a window
* @param aBrowser
* Browser reference
* @param aHistoryData
* History data to be restored
* @param aIdMap
* Hash for ensuring unique frame IDs
*/
restoreHistory: function sss_restoreHistory(aBrowser, aHistoryData, aIdMap) {
dump("nsSessionStore::restoreHistory\n")
aBrowser.QueryInterface(Ci.nsIWebNavigation);
aSHistory = aBrowser.sessionHistory;
aSHistory.QueryInterface(Ci.nsISHistoryInternal);
if (aSHistory.count > 0) {
aSHistory.PurgeHistory(aSHistory.count);
}
if (!aHistoryData) {
aHistoryData = [];
}
for (var i = 0; i < aHistoryData.length; i++) {
aSHistory.addEntry(this._deserializeHistoryEntry(aHistoryData[i], aIdMap), true);
}
/*
// make sure to reset the capabilities and attributes, in case this tab gets reused
var disallow = (aHistoryData.disallow)?aHistoryData.disallow.split(","):[];
CAPABILITIES.forEach(function(aCapability) {
browser.docShell["allow" + aCapability] = disallow.indexOf(aCapability) == -1;
});
Array.filter(tab.attributes, function(aAttr) {
return (_this.xulAttributes.indexOf(aAttr.name) > -1);
}).forEach(tab.removeAttribute, tab);
if (aHistoryData.xultab) {
aHistoryData.xultab.split(" ").forEach(function(aAttr) {
if (/^([^\s=]+)=(.*)/.test(aAttr)) {
tab.setAttribute(RegExp.$1, decodeURI(RegExp.$2));
}
});
}
*/
try {
aBrowser.gotoIndex(aHistoryData.length - 1);
}
catch (ex) { dump(ex + "\n"); } // ignore an invalid aHistoryData.index
},
/**
* expands serialized history data into a session-history-entry instance
* @param aEntry
* Object containing serialized history data for a URL
* @param aIdMap
* Hash for ensuring unique frame IDs
* @returns nsISHEntry
*/
_deserializeHistoryEntry: function sss_deserializeHistoryEntry(aEntry, aIdMap) {
var shEntry = Cc["@mozilla.org/browser/session-history-entry;1"].
createInstance(Ci.nsISHEntry);
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
shEntry.setURI(ioService.newURI(aEntry.url, null, null));
shEntry.setTitle(aEntry.title || aEntry.url);
shEntry.setIsSubFrame(aEntry.subframe || false);
shEntry.loadType = Ci.nsIDocShellLoadInfo.loadHistory;
if (aEntry.cacheKey) {
var cacheKey = Cc["@mozilla.org/supports-PRUint32;1"].
createInstance(Ci.nsISupportsPRUint32);
cacheKey.data = aEntry.cacheKey;
shEntry.cacheKey = cacheKey;
}
if (aEntry.ID) {
// get a new unique ID for this frame (since the one from the last
// start might already be in use)
var id = aIdMap[aEntry.ID] || 0;
if (!id) {
for (id = Date.now(); aIdMap.used[id]; id++);
aIdMap[aEntry.ID] = id;
aIdMap.used[id] = true;
}
shEntry.ID = id;
}
var scrollPos = (aEntry.scroll || "0,0").split(",");
scrollPos = [parseInt(scrollPos[0]) || 0, parseInt(scrollPos[1]) || 0];
shEntry.setScrollPosition(scrollPos[0], scrollPos[1]);
if (aEntry.postdata) {
var stream = Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsIStringInputStream);
stream.setData(aEntry.postdata, -1);
shEntry.postData = stream;
}
if (aEntry.children && shEntry instanceof Ci.nsISHContainer) {
for (var i = 0; i < aEntry.children.length; i++) {
shEntry.AddChild(this._deserializeHistoryEntry(aEntry.children[i], aIdMap), i);
}
}
return shEntry;
},
/* ........ Auxiliary Functions .............. */
/**
* don't save sensitive data if the user doesn't want to
* (distinguishes between encrypted and non-encrypted sites)
* @param aIsHTTPS
* Bool is encrypted
* @returns bool
*/
_checkPrivacyLevel: function sss_checkPrivacyLevel(aIsHTTPS) {
return this._prefBranch.getIntPref("sessionstore.privacy_level") < (aIsHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL);
},
/**
* safe eval'ing
*/
_safeEval: function sss_safeEval(aStr) {
return Components.utils.evalInSandbox(aStr, EVAL_SANDBOX);
},
/**
* Converts a JavaScript object into a JSON string
* (see http://www.json.org/ for the full grammar).
*
* The inverse operation consists of eval("(" + JSON_string + ")");
* and should be provably safe.
*
* @param aJSObject is the object to be converted
* @return the object's JSON representation
*/
_toJSONString: function sss_toJSONString(aJSObject) {
// these characters have a special escape notation
const charMap = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f",
"\r": "\\r", '"': '\\"', "\\": "\\\\" };
// we use a single string builder for efficiency reasons
var parts = [];
// this recursive function walks through all objects and appends their
// JSON representation to the string builder
function jsonIfy(aObj) {
if (typeof aObj == "boolean") {
parts.push(aObj ? "true" : "false");
}
else if (typeof aObj == "number" && isFinite(aObj)) {
// there is no representation for infinite numbers or for NaN!
parts.push(aObj.toString());
}
else if (typeof aObj == "string") {
aObj = aObj.replace(/[\\"\x00-\x1F\u0080-\uFFFF]/g, function($0) {
// use the special escape notation if one exists, otherwise
// produce a general unicode escape sequence
return charMap[$0] ||
"\\u" + ("0000" + $0.charCodeAt(0).toString(16)).slice(-4);
});
parts.push('"' + aObj + '"')
}
else if (aObj == null) {
parts.push("null");
}
else if (aObj instanceof Array || aObj instanceof EVAL_SANDBOX.Array) {
parts.push("[");
for (var i = 0; i < aObj.length; i++) {
jsonIfy(aObj[i]);
parts.push(",");
}
if (parts[parts.length - 1] == ",")
parts.pop(); // drop the trailing colon
parts.push("]");
}
else if (typeof aObj == "object") {
parts.push("{");
for (var key in aObj) {
jsonIfy(key.toString());
parts.push(":");
jsonIfy(aObj[key]);
parts.push(",");
}
if (parts[parts.length - 1] == ",")
parts.pop(); // drop the trailing colon
parts.push("}");
}
else {
throw new Error("No JSON representation for this object!");
}
}
jsonIfy(aJSObject);
var newJSONString = parts.join(" ");
// sanity check - so that API consumers can just eval this string
if (/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
newJSONString.replace(/"(\\.|[^"\\])*"/g, "")
))
throw new Error("JSON conversion failed unexpectedly!");
return newJSONString;
},
/* ........ QueryInterface .............. */
QueryInterface: function(aIID) {
if (!aIID.equals(Ci.nsISupports) &&
!aIID.equals(Ci.nsIObserver) &&
!aIID.equals(Ci.nsISupportsWeakReference) &&
!aIID.equals(Ci.nsIDOMEventListener) &&
!aIID.equals(Ci.nsISessionStore)) {
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
return this;
}
};
/* :::::::: Service Registration & Initialization ::::::::::::::: */
/* ........ nsIModule .............. */
const SessionStoreModule = {
getClassObject: function(aCompMgr, aCID, aIID) {
if (aCID.equals(CID)) {
return SessionStoreFactory;
}
Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
return null;
},
registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
aCompMgr.registerFactoryLocation(CID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
},
unregisterSelf: function(aCompMgr, aLocation, aType) {
aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
aCompMgr.unregisterFactoryLocation(CID, aLocation);
},
canUnload: function(aCompMgr) {
return true;
}
}
/* ........ nsIFactory .............. */
const SessionStoreFactory = {
createInstance: function(aOuter, aIID) {
if (aOuter != null) {
Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
return null;
}
return (new SessionStoreService()).QueryInterface(aIID);
},
lockFactory: function(aLock) { },
QueryInterface: function(aIID) {
if (!aIID.equals(Ci.nsISupports) && !aIID.equals(Ci.nsIModule) &&
!aIID.equals(Ci.nsIFactory) && !aIID.equals(Ci.nsISessionStore)) {
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
return this;
}
};
function NSGetModule(aComMgr, aFileSpec) {
dump("nsSessionStore: NSGetModule\n")
return SessionStoreModule;
}

@ -1,661 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <gtk/gtkentry.h>
#include "sugar-address-entry.h"
enum {
PROP_0,
PROP_PROGRESS,
PROP_ADDRESS,
PROP_TITLE
};
typedef enum {
CURSOR_STANDARD,
CURSOR_DND
} CursorType;
static void _gtk_entry_effective_inner_border (GtkEntry *entry,
GtkBorder *border);
static void get_text_area_size (GtkEntry *entry,
gint *x,
gint *y,
gint *width,
gint *height);
G_DEFINE_TYPE(SugarAddressEntry, sugar_address_entry, GTK_TYPE_ENTRY)
static GQuark quark_inner_border = 0;
static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
static void
draw_insertion_cursor (GtkEntry *entry,
GdkRectangle *cursor_location,
gboolean is_primary,
PangoDirection direction,
gboolean draw_arrow)
{
GtkWidget *widget = GTK_WIDGET (entry);
GtkTextDirection text_dir;
if (direction == PANGO_DIRECTION_LTR)
text_dir = GTK_TEXT_DIR_LTR;
else
text_dir = GTK_TEXT_DIR_RTL;
gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
cursor_location,
is_primary, text_dir, draw_arrow);
}
static void
gtk_entry_get_pixel_ranges (GtkEntry *entry,
gint **ranges,
gint *n_ranges)
{
gint start_char, end_char;
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
{
//PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
PangoLayout *layout = gtk_entry_get_layout (entry);
PangoLayoutLine *line = pango_layout_get_lines (layout)->data;
const char *text = pango_layout_get_text (layout);
gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
gint real_n_ranges, i;
pango_layout_line_get_x_ranges (line, start_index, end_index, ranges, &real_n_ranges);
if (ranges)
{
gint *r = *ranges;
for (i = 0; i < real_n_ranges; ++i)
{
r[2 * i + 1] = (r[2 * i + 1] - r[2 * i]) / PANGO_SCALE;
r[2 * i] = r[2 * i] / PANGO_SCALE;
}
}
if (n_ranges)
*n_ranges = real_n_ranges;
}
else
{
if (n_ranges)
*n_ranges = 0;
if (ranges)
*ranges = NULL;
}
}
static void
gtk_entry_get_cursor_locations (GtkEntry *entry,
CursorType type,
gint *strong_x,
gint *weak_x)
{
if (!entry->visible && !entry->invisible_char)
{
if (strong_x)
*strong_x = 0;
if (weak_x)
*weak_x = 0;
}
else
{
//PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
PangoLayout *layout = gtk_entry_get_layout (entry);
const gchar *text = pango_layout_get_text (layout);
PangoRectangle strong_pos, weak_pos;
gint index;
if (type == CURSOR_STANDARD)
{
index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
}
else /* type == CURSOR_DND */
{
index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
if (entry->dnd_position > entry->current_pos)
{
if (entry->visible)
index += entry->preedit_length;
else
{
gint preedit_len_chars = g_utf8_strlen (text, -1) - entry->text_length;
index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
}
}
}
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
if (strong_x)
*strong_x = strong_pos.x / PANGO_SCALE;
if (weak_x)
*weak_x = weak_pos.x / PANGO_SCALE;
}
}
static void
gtk_entry_draw_cursor (GtkEntry *entry,
CursorType type)
{
GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
if (GTK_WIDGET_DRAWABLE (entry))
{
GtkWidget *widget = GTK_WIDGET (entry);
GdkRectangle cursor_location;
gboolean split_cursor;
GtkBorder inner_border;
gint xoffset;
gint strong_x, weak_x;
gint text_area_height;
PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
gint x1 = 0;
gint x2 = 0;
_gtk_entry_effective_inner_border (entry, &inner_border);
xoffset = inner_border.left - entry->scroll_offset;
gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
g_object_get (gtk_widget_get_settings (widget),
"gtk-split-cursor", &split_cursor,
NULL);
dir1 = entry->resolved_dir;
if (split_cursor)
{
x1 = strong_x;
if (weak_x != strong_x)
{
dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
x2 = weak_x;
}
}
else
{
if (keymap_direction == entry->resolved_dir)
x1 = strong_x;
else
x1 = weak_x;
}
cursor_location.x = xoffset + x1;
cursor_location.y = inner_border.top;
cursor_location.width = 0;
cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
draw_insertion_cursor (entry,
&cursor_location, TRUE, dir1,
dir2 != PANGO_DIRECTION_NEUTRAL);
if (dir2 != PANGO_DIRECTION_NEUTRAL)
{
cursor_location.x = xoffset + x2;
draw_insertion_cursor (entry,
&cursor_location, FALSE, dir2,
TRUE);
}
}
}
static void
get_layout_position (GtkEntry *entry,
gint *x,
gint *y)
{
PangoLayout *layout;
PangoRectangle logical_rect;
gint area_width, area_height;
GtkBorder inner_border;
gint y_pos;
PangoLayoutLine *line;
// layout = gtk_entry_ensure_layout (entry, TRUE);
layout = gtk_entry_get_layout(entry);
get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
_gtk_entry_effective_inner_border (entry, &inner_border);
area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
line = pango_layout_get_lines (layout)->data;
pango_layout_line_get_extents (line, NULL, &logical_rect);
/* Align primarily for locale's ascent/descent */
y_pos = ((area_height - entry->ascent - entry->descent) / 2 +
entry->ascent + logical_rect.y);
/* Now see if we need to adjust to fit in actual drawn string */
if (logical_rect.height > area_height)
y_pos = (area_height - logical_rect.height) / 2;
else if (y_pos < 0)
y_pos = 0;
else if (y_pos + logical_rect.height > area_height)
y_pos = area_height - logical_rect.height;
y_pos = inner_border.top + y_pos / PANGO_SCALE;
if (x)
*x = inner_border.left - entry->scroll_offset;
if (y)
*y = y_pos;
}
static void
_gtk_entry_effective_inner_border (GtkEntry *entry,
GtkBorder *border)
{
GtkBorder *tmp_border;
tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
if (tmp_border)
{
*border = *tmp_border;
return;
}
gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
if (tmp_border)
{
*border = *tmp_border;
g_free (tmp_border);
return;
}
*border = default_inner_border;
}
static void
gtk_entry_draw_text (GtkEntry *entry)
{
GtkWidget *widget;
if (!entry->visible && entry->invisible_char == 0)
return;
if (GTK_WIDGET_DRAWABLE (entry))
{
//PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
PangoLayout *layout = gtk_entry_get_layout (entry);
cairo_t *cr;
gint x, y;
gint start_pos, end_pos;
widget = GTK_WIDGET (entry);
get_layout_position (entry, &x, &y);
cr = gdk_cairo_create (entry->text_area);
cairo_move_to (cr, x, y);
gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
pango_cairo_show_layout (cr, layout);
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
{
gint *ranges;
gint n_ranges, i;
PangoRectangle logical_rect;
GdkColor *selection_color, *text_color;
GtkBorder inner_border;
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
if (GTK_WIDGET_HAS_FOCUS (entry))
{
selection_color = &widget->style->base [GTK_STATE_SELECTED];
text_color = &widget->style->text [GTK_STATE_SELECTED];
}
else
{
selection_color = &widget->style->base [GTK_STATE_ACTIVE];
text_color = &widget->style->text [GTK_STATE_ACTIVE];
}
_gtk_entry_effective_inner_border (entry, &inner_border);
for (i = 0; i < n_ranges; ++i)
cairo_rectangle (cr,
inner_border.left - entry->scroll_offset + ranges[2 * i],
y,
ranges[2 * i + 1],
logical_rect.height);
cairo_clip (cr);
gdk_cairo_set_source_color (cr, selection_color);
cairo_paint (cr);
cairo_move_to (cr, x, y);
gdk_cairo_set_source_color (cr, text_color);
pango_cairo_show_layout (cr, layout);
g_free (ranges);
}
cairo_destroy (cr);
}
}
static void
sugar_address_entry_get_borders (GtkEntry *entry,
gint *xborder,
gint *yborder)
{
GtkWidget *widget = GTK_WIDGET (entry);
gint focus_width;
gboolean interior_focus;
gtk_widget_style_get (widget,
"interior-focus", &interior_focus,
"focus-line-width", &focus_width,
NULL);
if (entry->has_frame)
{
*xborder = widget->style->xthickness;
*yborder = widget->style->ythickness;
}
else
{
*xborder = 0;
*yborder = 0;
}
if (!interior_focus)
{
*xborder += focus_width;
*yborder += focus_width;
}
}
static void
get_text_area_size (GtkEntry *entry,
gint *x,
gint *y,
gint *width,
gint *height)
{
gint xborder, yborder;
GtkRequisition requisition;
GtkWidget *widget = GTK_WIDGET (entry);
gtk_widget_get_child_requisition (widget, &requisition);
sugar_address_entry_get_borders (entry, &xborder, &yborder);
if (x)
*x = xborder;
if (y)
*y = yborder;
if (width)
*width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
if (height)
*height = requisition.height - yborder * 2;
}
static gint
sugar_address_entry_expose(GtkWidget *widget,
GdkEventExpose *event)
{
GtkEntry *entry = GTK_ENTRY (widget);
SugarAddressEntry *address_entry = SUGAR_ADDRESS_ENTRY(widget);
cairo_t *cr;
if (entry->text_area == event->window) {
gint area_width, area_height;
get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
/* gtk_paint_flat_box (widget->style, entry->text_area,
GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
NULL, widget, "entry_bg",
0, 0, area_width, area_height);
*/
if (address_entry->progress != 0.0 && address_entry->progress != 1.0 &&
!GTK_WIDGET_HAS_FOCUS(entry)) {
int bar_width = area_width * address_entry->progress;
float radius = area_height / 2;
cr = gdk_cairo_create(entry->text_area);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_move_to (cr, radius, 0);
cairo_arc (cr, bar_width - radius, radius, radius, M_PI * 1.5, M_PI * 2);
cairo_arc (cr, bar_width - radius, area_height - radius, radius, 0, M_PI * 0.5);
cairo_arc (cr, radius, area_height - radius, radius, M_PI * 0.5, M_PI);
cairo_arc (cr, radius, radius, radius, M_PI, M_PI * 1.5);
cairo_fill(cr);
cairo_destroy (cr);
}
if ((entry->visible || entry->invisible_char != 0) &&
GTK_WIDGET_HAS_FOCUS (widget) &&
entry->selection_bound == entry->current_pos && entry->cursor_visible)
gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
if (entry->dnd_position != -1)
gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
gtk_entry_draw_text (GTK_ENTRY (widget));
} else {
GtkWidgetClass *parent_class;
parent_class = GTK_WIDGET_CLASS(sugar_address_entry_parent_class);
parent_class->expose_event(widget, event);
}
return FALSE;
}
static void
update_entry_text(SugarAddressEntry *address_entry,
gboolean has_focus)
{
if (has_focus) {
gtk_entry_set_text(GTK_ENTRY(address_entry),
address_entry->address);
} else {
gtk_entry_set_text(GTK_ENTRY(address_entry),
address_entry->title);
}
}
static void
sugar_address_entry_set_address(SugarAddressEntry *address_entry,
const char *address)
{
g_free(address_entry->address);
address_entry->address = g_strdup(address);
update_entry_text(address_entry,
gtk_widget_is_focus(GTK_WIDGET(address_entry)));
}
static void
sugar_address_entry_set_title(SugarAddressEntry *address_entry,
const char *title)
{
g_free(address_entry->title);
address_entry->title = g_strdup(title);
update_entry_text(address_entry,
gtk_widget_is_focus(GTK_WIDGET(address_entry)));
}
static void
sugar_address_entry_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SugarAddressEntry *address_entry = SUGAR_ADDRESS_ENTRY(object);
GtkEntry *entry = GTK_ENTRY(object);
switch (prop_id) {
case PROP_PROGRESS:
address_entry->progress = g_value_get_double(value);
if (GTK_WIDGET_REALIZED(entry))
gdk_window_invalidate_rect(entry->text_area, NULL, FALSE);
break;
case PROP_ADDRESS:
sugar_address_entry_set_address(address_entry,
g_value_get_string(value));
break;
case PROP_TITLE:
sugar_address_entry_set_title(address_entry,
g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sugar_address_entry_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SugarAddressEntry *entry = SUGAR_ADDRESS_ENTRY(object);
switch (prop_id) {
case PROP_PROGRESS:
g_value_set_double(value, entry->progress);
break;
case PROP_TITLE:
g_value_set_string(value, entry->title);
break;
case PROP_ADDRESS:
g_value_set_string(value, entry->address);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sugar_address_entry_class_init(SugarAddressEntryClass *klass)
{
GtkWidgetClass *widget_class = (GtkWidgetClass*)klass;
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
widget_class->expose_event = sugar_address_entry_expose;
gobject_class->set_property = sugar_address_entry_set_property;
gobject_class->get_property = sugar_address_entry_get_property;
quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
g_object_class_install_property (gobject_class, PROP_PROGRESS,
g_param_spec_double("progress",
"Progress",
"Progress",
0.0, 1.0, 0.0,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_TITLE,
g_param_spec_string("title",
"Title",
"Title",
"",
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_ADDRESS,
g_param_spec_string("address",
"Address",
"Address",
"",
G_PARAM_READWRITE));
}
static gboolean
button_press_event_cb (GtkWidget *widget, GdkEventButton *event)
{
if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
gtk_editable_select_region(GTK_EDITABLE(widget), 0, -1);
gtk_widget_grab_focus(widget);
return TRUE;
}
return FALSE;
}
static gboolean
focus_in_event_cb(GtkWidget *widget, GdkEventFocus *event)
{
update_entry_text(SUGAR_ADDRESS_ENTRY(widget), TRUE);
return FALSE;
}
static gboolean
focus_out_event_cb(GtkWidget *widget, GdkEventFocus *event)
{
update_entry_text(SUGAR_ADDRESS_ENTRY(widget), FALSE);
return FALSE;
}
static void
sugar_address_entry_init(SugarAddressEntry *entry)
{
entry->progress = 0.0;
entry->address = NULL;
entry->title = g_strdup("");
g_signal_connect(entry, "focus-in-event",
G_CALLBACK(focus_in_event_cb), NULL);
g_signal_connect(entry, "focus-out-event",
G_CALLBACK(focus_out_event_cb), NULL);
g_signal_connect(entry, "button-press-event",
G_CALLBACK(button_press_event_cb), NULL);
}

@ -1,54 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __SUGAR_ADDRESS_ENTRY_H__
#define __SUGAR_ADDRESS_ENTRY_H__
#include <glib-object.h>
G_BEGIN_DECLS
typedef struct _SugarAddressEntry SugarAddressEntry;
typedef struct _SugarAddressEntryClass SugarAddressEntryClass;
typedef struct _SugarAddressEntryPrivate SugarAddressEntryPrivate;
#define SUGAR_TYPE_ADDRESS_ENTRY (sugar_address_entry_get_type())
#define SUGAR_ADDRESS_ENTRY(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_ADDRESS_ENTRY, SugarAddressEntry))
#define SUGAR_ADDRESS_ENTRY_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), SUGAR_TYPE_ADDRESS_ENTRY, SugarAddressEntryClass))
#define SUGAR_IS_ADDRESS_ENTRY(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_ADDRESS_ENTRY))
#define SUGAR_IS_ADDRESS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_ADDRESS_ENTRY))
#define SUGAR_ADDRESS_ENTRY_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_ADDRESS_ENTRY, SugarAddressEntryClass))
struct _SugarAddressEntry {
GtkEntry base_instance;
float progress;
char *title;
char *address;
};
struct _SugarAddressEntryClass {
GtkEntryClass base_class;
};
GType sugar_address_entry_get_type (void);
G_END_DECLS
#endif /* __SUGAR_ADDRESS_ENTRY_H__ */

@ -1,962 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "sugar-browser.h"
#include "sugar-marshal.h"
#include "GeckoContentHandler.h"
#include "GeckoDownload.h"
#include "GeckoDragDropHooks.h"
#include "GeckoDocumentObject.h"
#include "GeckoBrowserPersist.h"
#include "GeckoDirectoryProvider.h"
#include <gdk/gdkx.h>
#include <gtkmozembed_internal.h>
#include <nsCOMPtr.h>
#include <nsIPrefService.h>
#include <nsServiceManagerUtils.h>
#include <nsStringAPI.h>
#include <nsILocalFile.h>
#include <nsIWebBrowser.h>
#include <nsIWebBrowserFocus.h>
#include <nsIWebBrowserPersist.h>
#include <nsIDOMWindow.h>
#include <nsIDOMWindowUtils.h>
#include <nsIDOMDocument.h>
#include <nsIDOMMouseEvent.h>
#include <nsIGenericFactory.h>
#include <nsIHelperAppLauncherDialog.h>
#include <nsIComponentRegistrar.h>
#include <nsIDOMNode.h>
#include <nsIDOMEventTarget.h>
#include <nsIDOMHTMLImageElement.h>
#include <nsIIOService.h>
#include <nsComponentManagerUtils.h>
#include <imgICache.h>
#include <nsIProperties.h>
#include <nsIWebNavigation.h>
#include <nsISupportsPrimitives.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsIMIMEHeaderParam.h>
#include <nsISHistory.h>
#include <nsIHistoryEntry.h>
#include <nsISHEntry.h>
#include <nsIInputStream.h>
#include <nsICommandManager.h>
#include <nsIClipboardDragDropHooks.h>
#include "nsISessionStore.h"
#include "nsIBrowserHelper.h"
#define SUGAR_PATH "SUGAR_PATH"
enum {
PROP_0,
PROP_PROGRESS,
PROP_TITLE,
PROP_ADDRESS,
PROP_CAN_GO_BACK,
PROP_CAN_GO_FORWARD,
PROP_LOADING,
PROP_DOCUMENT_METADATA
};
enum {
MOUSE_CLICK,
N_SIGNALS
};
static int last_instance_id = 0;
static guint signals[N_SIGNALS];
static GObjectClass *parent_class = NULL;
static const nsModuleComponentInfo sSugarComponents[] = {
{
"Gecko Content Handler",
GECKOCONTENTHANDLER_CID,
NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
NULL
},
{
"Gecko Download",
GECKODOWNLOAD_CID,
NS_TRANSFER_CONTRACTID,
NULL
}
};
int (*old_handler) (Display *, XErrorEvent *);
static int
error_handler (Display *d, XErrorEvent *e)
{
gchar buf[64];
gchar *msg;
XGetErrorText(d, e->error_code, buf, 63);
msg =
g_strdup_printf("The program '%s' received an X Window System error.\n"
"This probably reflects a bug in the program.\n"
"The error was '%s'.\n"
" (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
g_get_prgname (),
buf,
e->serial,
e->error_code,
e->request_code,
e->minor_code);
g_warning ("%s", msg);
return 0;
/*return (*old_handler)(d, e);*/
}
static void
setup_plugin_path ()
{
const char *user_path;
char *new_path;
user_path = g_getenv ("MOZ_PLUGIN_PATH");
new_path = g_strconcat (user_path ? user_path : "",
user_path ? ":" : "",
PLUGIN_DIR,
(char *) NULL);
g_setenv ("MOZ_PLUGIN_PATH", new_path, TRUE);
g_free (new_path);
}
static gboolean
setup_directory_provider(const char *full_prof_path)
{
const char *prefix = g_getenv("SUGAR_PREFIX");
if (prefix == NULL) {
g_print("The SUGAR_PREFIX environment variable is not set.");
exit(1);
}
char *components_path = g_build_filename(prefix, "share/sugar", NULL);
GeckoDirectoryProvider *dirProvider =
new GeckoDirectoryProvider(components_path, full_prof_path);
if (!dirProvider) {
g_warning ("failed to create GeckoDirectoryProvider");
return FALSE;
}
g_free(components_path);
NS_ADDREF (dirProvider);
nsCOMPtr<nsIDirectoryServiceProvider> dp (do_QueryInterface (dirProvider));
NS_RELEASE (dirProvider);
dirProvider = nsnull;
if (!dp) return FALSE;
gtk_moz_embed_set_directory_service_provider(dp);
return TRUE;
}
gboolean
sugar_browser_startup(const char *profile_path, const char *profile_name)
{
nsresult rv;
setup_plugin_path();
gtk_moz_embed_set_profile_path(profile_path, profile_name);
old_handler = XSetErrorHandler(error_handler);
char *full_prof_path = g_build_filename(profile_path, profile_name, NULL);
if (!setup_directory_provider(full_prof_path)) {
return FALSE;
}
g_free(full_prof_path);
gtk_moz_embed_push_startup();
nsCOMPtr<nsIPrefService> prefService;
prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_ENSURE_TRUE(prefService, FALSE);
/* Read our predefined default prefs */
nsCString pathToPrefs(g_getenv(SUGAR_PATH));
pathToPrefs.Append("/data/gecko-prefs.js");
nsCOMPtr<nsILocalFile> file;
NS_NewNativeLocalFile(pathToPrefs, PR_TRUE, getter_AddRefs(file));
NS_ENSURE_TRUE(file, FALSE);
rv = prefService->ReadUserPrefs (file);
if (NS_FAILED(rv)) {
g_warning ("failed to read default preferences, error: %x", rv);
return FALSE;
}
nsCOMPtr<nsIPrefBranch> pref;
prefService->GetBranch ("", getter_AddRefs(pref));
NS_ENSURE_TRUE(pref, FALSE);
nsCString pathToMimeTypes(g_getenv(SUGAR_PATH));
pathToMimeTypes.Append("/data/mime.types");
pref->SetCharPref ("helpers.private_mime_types_file", pathToMimeTypes.get());
rv = prefService->ReadUserPrefs (nsnull);
if (NS_FAILED(rv)) {
g_warning ("failed to read user preferences, error: %x", rv);
}
nsCOMPtr<nsIComponentRegistrar> componentRegistrar;
NS_GetComponentRegistrar(getter_AddRefs(componentRegistrar));
NS_ENSURE_TRUE (componentRegistrar, FALSE);
nsCOMPtr<nsIFactory> contentHandlerFactory;
rv = NS_NewGeckoContentHandlerFactory(getter_AddRefs(contentHandlerFactory));
rv = componentRegistrar->RegisterFactory(sSugarComponents[0].mCID,
sSugarComponents[0].mDescription,
sSugarComponents[0].mContractID,
contentHandlerFactory);
if (NS_FAILED(rv)) {
g_warning ("Failed to register factory for %s\n", sSugarComponents[0].mDescription);
return FALSE;
}
nsCOMPtr<nsIFactory> downloadFactory;
rv = NS_NewGeckoDownloadFactory(getter_AddRefs(downloadFactory));
rv = componentRegistrar->RegisterFactory(sSugarComponents[1].mCID,
sSugarComponents[1].mDescription,
sSugarComponents[1].mContractID,
downloadFactory);
if (NS_FAILED(rv)) {
g_warning ("Failed to register factory for %s\n", sSugarComponents[1].mDescription);
return FALSE;
}
return TRUE;
}
void
sugar_browser_shutdown(void)
{
gtk_moz_embed_pop_startup();
}
G_DEFINE_TYPE(SugarBrowser, sugar_browser, GTK_TYPE_MOZ_EMBED)
static nsresult
FilenameFromContentDisposition(nsCString contentDisposition, nsCString &fileName)
{
nsresult rv;
nsCString fallbackCharset;
nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar =
do_GetService("@mozilla.org/network/mime-hdrparam;1");
NS_ENSURE_TRUE(mimehdrpar, NS_ERROR_FAILURE);
nsString aFileName;
rv = mimehdrpar->GetParameter (contentDisposition, "filename",
fallbackCharset, PR_TRUE, nsnull,
aFileName);
if (NS_FAILED(rv) || !fileName.Length()) {
rv = mimehdrpar->GetParameter (contentDisposition, "name",
fallbackCharset, PR_TRUE, nsnull,
aFileName);
}
if (NS_SUCCEEDED(rv) && fileName.Length()) {
NS_UTF16ToCString (aFileName, NS_CSTRING_ENCODING_UTF8, fileName);
}
return NS_OK;
}
static SugarBrowserMetadata *
sugar_browser_get_document_metadata(SugarBrowser *browser)
{
SugarBrowserMetadata *metadata = sugar_browser_metadata_new();
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, metadata);
nsCOMPtr<nsIDOMWindow> DOMWindow;
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
NS_ENSURE_TRUE(DOMWindow, metadata);
nsCOMPtr<nsIDOMWindowUtils> DOMWindowUtils(do_GetInterface(DOMWindow));
NS_ENSURE_TRUE(DOMWindowUtils, metadata);
const PRUnichar contentDispositionLiteral[] =
{'c', 'o', 'n', 't', 'e', 'n', 't', '-', 'd', 'i', 's', 'p',
'o', 's', 'i', 't', 'i', 'o', 'n', '\0'};
nsString contentDisposition;
DOMWindowUtils->GetDocumentMetadata(nsString(contentDispositionLiteral),
contentDisposition);
nsCString cContentDisposition;
NS_UTF16ToCString (contentDisposition, NS_CSTRING_ENCODING_UTF8,
cContentDisposition);
nsCString fileName;
FilenameFromContentDisposition(cContentDisposition, fileName);
if (!fileName.Length()) {
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(webBrowser));
if (webNav) {
nsCOMPtr<nsIURI> docURI;
webNav->GetCurrentURI (getter_AddRefs(docURI));
nsCOMPtr<nsIURL> url(do_QueryInterface(docURI));
if (url) {
url->GetFileName(fileName);
}
}
}
if (fileName.Length()) {
metadata->filename = g_strdup(fileName.get());
}
return metadata;
}
static void
sugar_browser_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SugarBrowser *browser = SUGAR_BROWSER(object);
switch (prop_id) {
case PROP_PROGRESS:
g_value_set_double(value, browser->progress);
break;
case PROP_ADDRESS:
g_value_set_string(value, browser->address);
break;
case PROP_TITLE:
g_value_set_string(value, browser->title);
break;
case PROP_CAN_GO_BACK:
g_value_set_boolean(value, browser->can_go_back);
break;
case PROP_CAN_GO_FORWARD:
g_value_set_boolean(value, browser->can_go_forward);
break;
case PROP_LOADING:
g_value_set_boolean(value, browser->loading);
break;
case PROP_DOCUMENT_METADATA:
SugarBrowserMetadata *metadata;
metadata = sugar_browser_get_document_metadata(browser);
g_value_set_boxed(value, metadata);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
sugar_browser_realize(GtkWidget *widget)
{
SugarBrowser *browser = SUGAR_BROWSER(widget);
GTK_WIDGET_CLASS(parent_class)->realize(widget);
GtkMozEmbed *embed = GTK_MOZ_EMBED(widget);
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(embed, getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, );
nsCOMPtr<nsIBrowserHelper> browserHelper;
browserHelper = do_GetService("@laptop.org/browser/browserhelper;1");
if (browserHelper) {
browserHelper->RegisterBrowser(browser->instance_id, webBrowser);
} else {
g_warning ("Failed to get nsIBrowserHelper");
}
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(webBrowser);
if (commandManager) {
nsresult rv;
nsIClipboardDragDropHooks *rawPtr = new GeckoDragDropHooks(
SUGAR_BROWSER(widget));
nsCOMPtr<nsIClipboardDragDropHooks> geckoDragDropHooks(
do_QueryInterface(rawPtr, &rv));
NS_ENSURE_SUCCESS(rv, );
nsCOMPtr<nsIDOMWindow> DOMWindow = do_GetInterface(webBrowser);
nsCOMPtr<nsICommandParams> cmdParamsObj = do_CreateInstance(
NS_COMMAND_PARAMS_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, );
cmdParamsObj->SetISupportsValue("addhook", geckoDragDropHooks);
commandManager->DoCommand("cmd_clipboardDragDropHook", cmdParamsObj,
DOMWindow);
}
}
static void
sugar_browser_dispose(GObject *object)
{
SugarBrowser *browser = SUGAR_BROWSER(object);
GtkMozEmbed *embed = GTK_MOZ_EMBED(object);
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(embed, getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, );
nsCOMPtr<nsIBrowserHelper> browserHelper;
browserHelper = do_GetService("@laptop.org/browser/browserhelper;1");
if (browserHelper) {
browserHelper->UnregisterBrowser(browser->instance_id);
} else {
g_warning ("Failed to get nsIBrowserHelper");
}
}
static void
sugar_browser_class_init(SugarBrowserClass *browser_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(browser_class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(browser_class);
parent_class = (GObjectClass *) g_type_class_peek_parent(browser_class);
gobject_class->get_property = sugar_browser_get_property;
gobject_class->dispose = sugar_browser_dispose;
widget_class->realize = sugar_browser_realize;
signals[MOUSE_CLICK] = g_signal_new ("mouse_click",
SUGAR_TYPE_BROWSER,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(SugarBrowser, mouse_click),
g_signal_accumulator_true_handled, NULL,
sugar_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN,
1,
SUGAR_TYPE_BROWSER_EVENT);
g_object_class_install_property(gobject_class, PROP_PROGRESS,
g_param_spec_double ("progress",
"Progress",
"Progress",
0.0, 1.0, 0.0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_ADDRESS,
g_param_spec_string ("address",
"Address",
"Address",
"",
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_TITLE,
g_param_spec_string ("title",
"Title",
"Title",
"",
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_CAN_GO_BACK,
g_param_spec_boolean ("can-go-back",
"Can go back",
"Can go back",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_CAN_GO_FORWARD,
g_param_spec_boolean ("can-go-forward",
"Can go forward",
"Can go forward",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_LOADING,
g_param_spec_boolean ("loading",
"Loading",
"Loading",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property(gobject_class, PROP_DOCUMENT_METADATA,
g_param_spec_boxed("document-metadata",
"Document Metadata",
"Document metadata",
SUGAR_TYPE_BROWSER_METADATA,
G_PARAM_READABLE));
}
SugarBrowser *
sugar_browser_create_window(SugarBrowser *browser)
{
return SUGAR_BROWSER_GET_CLASS(browser)->create_window(browser);
}
static void
update_navigation_properties(SugarBrowser *browser)
{
GtkMozEmbed *embed = GTK_MOZ_EMBED(browser);
gboolean can_go_back;
gboolean can_go_forward;
can_go_back = gtk_moz_embed_can_go_back(embed);
if (can_go_back != browser->can_go_back) {
browser->can_go_back = can_go_back;
g_object_notify (G_OBJECT(browser), "can-go-back");
}
can_go_forward = gtk_moz_embed_can_go_forward(embed);
if (can_go_forward != browser->can_go_forward) {
browser->can_go_forward = can_go_forward;
g_object_notify (G_OBJECT(browser), "can-go-forward");
}
}
static void
new_window_cb(GtkMozEmbed *embed,
GtkMozEmbed **newEmbed,
guint chromemask)
{
SugarBrowser *browser;
browser = sugar_browser_create_window(SUGAR_BROWSER(embed));
*newEmbed = GTK_MOZ_EMBED(browser);
}
static void
sugar_browser_set_progress(SugarBrowser *browser, float progress)
{
g_return_if_fail(SUGAR_IS_BROWSER(browser));
browser->progress = progress;
g_object_notify (G_OBJECT(browser), "progress");
}
static void
sugar_browser_set_loading(SugarBrowser *browser, gboolean loading)
{
g_return_if_fail(SUGAR_IS_BROWSER(browser));
browser->loading = loading;
g_object_notify (G_OBJECT(browser), "loading");
}
static void
net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
if (state & GTK_MOZ_EMBED_FLAG_IS_NETWORK) {
if (state & GTK_MOZ_EMBED_FLAG_START) {
browser->total_requests = 0;
browser->current_requests = 0;
sugar_browser_set_progress(browser, 0.03);
sugar_browser_set_loading(browser, TRUE);
update_navigation_properties(browser);
} else if (state & GTK_MOZ_EMBED_FLAG_STOP) {
sugar_browser_set_progress(browser, 1.0);
sugar_browser_set_loading(browser, FALSE);
update_navigation_properties(browser);
}
}
if (state & GTK_MOZ_EMBED_FLAG_IS_REQUEST) {
float progress;
if (state & GTK_MOZ_EMBED_FLAG_START) {
browser->total_requests++;
}
else if (state & GTK_MOZ_EMBED_FLAG_STOP)
{
browser->current_requests++;
}
progress = float(browser->current_requests) /
float(browser->total_requests);
if (progress > browser->progress) {
sugar_browser_set_progress(browser, progress);
}
}
}
static void
title_cb(GtkMozEmbed *embed)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
g_free(browser->title);
browser->title = gtk_moz_embed_get_title(embed);
g_object_notify (G_OBJECT(browser), "title");
}
static void
location_cb(GtkMozEmbed *embed)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
g_free(browser->address);
browser->address = gtk_moz_embed_get_location(embed);
g_object_notify (G_OBJECT(browser), "address");
update_navigation_properties(browser);
}
static gboolean
dom_mouse_click_cb(GtkMozEmbed *embed, nsIDOMMouseEvent *mouseEvent)
{
SugarBrowser *browser = SUGAR_BROWSER(embed);
SugarBrowserEvent *event;
gint return_value = FALSE;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
mouseEvent->GetTarget(getter_AddRefs(eventTarget));
NS_ENSURE_TRUE(mouseEvent, FALSE);
nsCOMPtr<nsIDOMNode> targetNode;
targetNode = do_QueryInterface(eventTarget);
NS_ENSURE_TRUE(targetNode, FALSE);
event = sugar_browser_event_new();
GeckoDocumentObject documentObject(browser, targetNode);
if(documentObject.IsImage()) {
event->image_uri = documentObject.GetImageURI();
event->image_name = documentObject.GetImageName();
}
PRUint16 btn = 0;
mouseEvent->GetButton (&btn);
event->button = btn + 1;
g_signal_emit(browser, signals[MOUSE_CLICK], 0, event, &return_value);
sugar_browser_event_free(event);
return return_value;
}
static void
sugar_browser_init(SugarBrowser *browser)
{
browser->instance_id = last_instance_id;
last_instance_id++;
browser->title = NULL;
browser->address = NULL;
browser->progress = 0.0;
g_signal_connect(G_OBJECT(browser), "new-window",
G_CALLBACK(new_window_cb), NULL);
g_signal_connect(G_OBJECT(browser), "net-state-all",
G_CALLBACK(net_state_cb), NULL);
g_signal_connect(G_OBJECT(browser), "title",
G_CALLBACK(title_cb), NULL);
g_signal_connect(G_OBJECT(browser), "location",
G_CALLBACK(location_cb), NULL);
/* g_signal_connect(G_OBJECT(browser), "dom-mouse-click",
G_CALLBACK(dom_mouse_click_cb), NULL);
*/
}
int
sugar_browser_get_instance_id(SugarBrowser *browser)
{
return browser->instance_id;
}
void
sugar_browser_scroll_pixels(SugarBrowser *browser,
int dx,
int dy)
{
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
NS_ENSURE_TRUE (webBrowser, );
nsCOMPtr<nsIWebBrowserFocus> webBrowserFocus;
webBrowserFocus = do_QueryInterface (webBrowser);
NS_ENSURE_TRUE (webBrowserFocus, );
nsCOMPtr<nsIDOMWindow> DOMWindow;
webBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow));
if (!DOMWindow) {
webBrowser->GetContentDOMWindow (getter_AddRefs(DOMWindow));
}
NS_ENSURE_TRUE (DOMWindow, );
DOMWindow->ScrollBy (dx, dy);
}
void
sugar_browser_grab_focus(SugarBrowser *browser)
{
GtkWidget *child;
child = gtk_bin_get_child(GTK_BIN(browser));
if (child != NULL) {
gtk_widget_grab_focus (child);
} else {
g_warning ("Need to realize the embed before grabbing focus!\n");
}
}
gboolean
sugar_browser_save_uri(SugarBrowser *browser,
const char *uri,
const char *filename)
{
GeckoBrowserPersist browserPersist(browser);
return browserPersist.SaveURI(uri, filename);
}
gboolean
sugar_browser_save_document(SugarBrowser *browser,
const char *filename)
{
nsresult rv;
nsCString cFile(filename);
nsCOMPtr<nsILocalFile> destFile = do_CreateInstance("@mozilla.org/file/local;1");
NS_ENSURE_TRUE(destFile, FALSE);
destFile->InitWithNativePath(cFile);
GString *path = g_string_new (filename);
char *dot_pos = strchr (path->str, '.');
if (dot_pos) {
g_string_truncate (path, dot_pos - path->str);
}
g_string_append (path, " Files");
nsCOMPtr<nsILocalFile> filesFolder;
filesFolder = do_CreateInstance ("@mozilla.org/file/local;1");
filesFolder->InitWithNativePath (nsCString(path->str));
g_string_free (path, TRUE);
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, FALSE);
nsCOMPtr<nsIDOMWindow> DOMWindow;
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
NS_ENSURE_TRUE(DOMWindow, FALSE);
nsCOMPtr<nsIDOMDocument> DOMDocument;
DOMWindow->GetDocument (getter_AddRefs(DOMDocument));
NS_ENSURE_TRUE(DOMDocument, FALSE);
nsCOMPtr<nsIWebBrowserPersist> webPersist = do_QueryInterface (webBrowser);
NS_ENSURE_TRUE(webPersist, FALSE);
rv = webPersist->SaveDocument(DOMDocument, destFile, filesFolder, nsnull, 0, 0);
NS_ENSURE_SUCCESS(rv, FALSE);
return TRUE;
}
char *
sugar_browser_get_session(SugarBrowser *browser)
{
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
if (!webBrowser) {
g_warning ("failed to get nsIWebBrowser");
return NULL;
}
nsCOMPtr<nsISessionStore> sessionStore;
sessionStore = do_GetService("@mozilla.org/browser/sessionstore;1");
if (!sessionStore) {
g_warning ("failed to get nsISessionStore");
return NULL;
}
nsString session;
nsresult rv = sessionStore->GetBrowserState(webBrowser, session);
if (NS_FAILED(rv)) {
g_warning ("failed to get browser state");
return NULL;
}
nsCString sessionUTF8;
NS_UTF16ToCString (session, NS_CSTRING_ENCODING_UTF8, sessionUTF8);
return g_strdup(sessionUTF8.get());
}
gboolean
sugar_browser_set_session(SugarBrowser *browser,
const char *session)
{
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
if (!webBrowser) {
g_warning ("failed to get nsIWebBrowser");
return FALSE;
}
nsCOMPtr<nsISessionStore> sessionStore;
sessionStore = do_GetService("@mozilla.org/browser/sessionstore;1");
if (!sessionStore) {
g_warning ("failed to get nsISessionStore");
return FALSE;
}
nsCString sessionUTF8(session);
nsString sessionUTF16;
NS_CStringToUTF16(sessionUTF8, NS_CSTRING_ENCODING_UTF8, sessionUTF16);
nsresult rv = sessionStore->SetBrowserState(webBrowser, sessionUTF16);
if (NS_FAILED(rv)) {
g_warning ("failed to set browser state");
return FALSE;
}
return TRUE;
}
GType
sugar_browser_event_get_type(void)
{
static GType type = 0;
if (G_UNLIKELY(type == 0)) {
type = g_boxed_type_register_static("SugarBrowserEvent",
(GBoxedCopyFunc)sugar_browser_event_copy,
(GBoxedFreeFunc)sugar_browser_event_free);
}
return type;
}
SugarBrowserEvent *
sugar_browser_event_new(void)
{
SugarBrowserEvent *event;
event = g_new0(SugarBrowserEvent, 1);
return event;
}
SugarBrowserEvent *
sugar_browser_event_copy(SugarBrowserEvent *event)
{
SugarBrowserEvent *copy;
g_return_val_if_fail(event != NULL, NULL);
copy = g_new0(SugarBrowserEvent, 1);
copy->button = event->button;
copy->image_uri = g_strdup(event->image_uri);
copy->image_name = g_strdup(event->image_name);
return copy;
}
void
sugar_browser_event_free(SugarBrowserEvent *event)
{
g_return_if_fail(event != NULL);
if (event->image_uri) {
g_free(event->image_uri);
}
if (event->image_name) {
g_free(event->image_name);
}
g_free(event);
}
GType
sugar_browser_metadata_get_type(void)
{
static GType type = 0;
if (G_UNLIKELY(type == 0)) {
type = g_boxed_type_register_static("SugarBrowserMetadata",
(GBoxedCopyFunc)sugar_browser_metadata_copy,
(GBoxedFreeFunc)sugar_browser_metadata_free);
}
return type;
}
SugarBrowserMetadata *
sugar_browser_metadata_new(void)
{
SugarBrowserMetadata *metadata;
metadata = g_new0(SugarBrowserMetadata, 1);
return metadata;
}
SugarBrowserMetadata *
sugar_browser_metadata_copy(SugarBrowserMetadata *metadata)
{
SugarBrowserMetadata *copy;
g_return_val_if_fail(metadata != NULL, NULL);
copy = g_new0(SugarBrowserMetadata, 1);
copy->filename = g_strdup(metadata->filename);
return copy;
}
void
sugar_browser_metadata_free(SugarBrowserMetadata *metadata)
{
g_return_if_fail(metadata != NULL);
if (metadata->filename) {
g_free(metadata->filename);
}
g_free(metadata);
}

@ -1,108 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __SUGAR_BROWSER_H__
#define __SUGAR_BROWSER_H__
#include <gtkmozembed.h>
G_BEGIN_DECLS
typedef struct _SugarBrowser SugarBrowser;
typedef struct _SugarBrowserClass SugarBrowserClass;
typedef struct _SugarBrowserEvent SugarBrowserEvent;
typedef struct _SugarBrowserMetadata SugarBrowserMetadata;
#define SUGAR_TYPE_BROWSER (sugar_browser_get_type())
#define SUGAR_BROWSER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_BROWSER, SugarBrowser))
#define SUGAR_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_BROWSER, SugarBrowserClass))
#define SUGAR_IS_BROWSER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_BROWSER))
#define SUGAR_IS_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_BROWSER))
#define SUGAR_BROWSER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_BROWSER, SugarBrowserClass))
struct _SugarBrowser {
GtkMozEmbed base_instance;
int instance_id;
int total_requests;
int current_requests;
float progress;
char *address;
char *title;
gboolean can_go_back;
gboolean can_go_forward;
gboolean loading;
gboolean (* mouse_click) (SugarBrowser *browser,
SugarBrowserEvent *event);
};
struct _SugarBrowserClass {
GtkMozEmbedClass base_class;
SugarBrowser * (* create_window) (SugarBrowser *browser);
};
GType sugar_browser_get_type (void);
int sugar_browser_get_instance_id (SugarBrowser *browser);
SugarBrowser *sugar_browser_create_window (SugarBrowser *browser);
void sugar_browser_scroll_pixels (SugarBrowser *browser,
int dx,
int dy);
void sugar_browser_grab_focus (SugarBrowser *browser);
gboolean sugar_browser_save_uri (SugarBrowser *browser,
const char *uri,
const char *filename);
gboolean sugar_browser_save_document (SugarBrowser *browser,
const char *filename);
char *sugar_browser_get_session (SugarBrowser *browser);
gboolean sugar_browser_set_session (SugarBrowser *browser,
const char *session);
gboolean sugar_browser_startup (const char *profile_path,
const char *profile_name);
void sugar_browser_shutdown (void);
#define SUGAR_TYPE_BROWSER_EVENT (sugar_browser_event_get_type())
struct _SugarBrowserEvent {
int button;
char *image_uri;
char *image_name;
};
GType sugar_browser_event_get_type (void);
SugarBrowserEvent *sugar_browser_event_new (void);
SugarBrowserEvent *sugar_browser_event_copy (SugarBrowserEvent *event);
void sugar_browser_event_free (SugarBrowserEvent *event);
#define SUGAR_TYPE_BROWSER_METADATA (sugar_browser_metadata_get_type())
struct _SugarBrowserMetadata {
char *filename;
};
GType sugar_browser_metadata_get_type (void);
SugarBrowserMetadata *sugar_browser_metadata_new (void);
SugarBrowserMetadata *sugar_browser_metadata_copy (SugarBrowserMetadata *event);
void sugar_browser_metadata_free (SugarBrowserMetadata *event);
G_END_DECLS
#endif

@ -1,165 +0,0 @@
#include "sugar-marshal.h"
#include "sugar-download.h"
#include "sugar-download-manager.h"
enum {
DOWNLOAD_STARTED,
DOWNLOAD_COMPLETED,
DOWNLOAD_CANCELLED,
DOWNLOAD_PROGRESS,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void sugar_download_manager_finalize (GObject *object);
static void sugar_download_remove_download (gpointer key, gpointer value, gpointer user_data);
G_DEFINE_TYPE (SugarDownloadManager, sugar_download_manager, G_TYPE_OBJECT)
SugarDownloadManager *DownloadManager = NULL;
static void
sugar_download_manager_init (SugarDownloadManager *download_manager)
{
download_manager->downloads = g_hash_table_new (g_str_hash, g_str_equal);
}
static void
sugar_download_manager_class_init (SugarDownloadManagerClass *download_manager_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (download_manager_class);
gobject_class->finalize = sugar_download_manager_finalize;
signals[DOWNLOAD_STARTED] =
g_signal_new ("download-started",
G_OBJECT_CLASS_TYPE (download_manager_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
NULL, NULL,
sugar_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[DOWNLOAD_COMPLETED] =
g_signal_new ("download-completed",
G_OBJECT_CLASS_TYPE (download_manager_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
NULL, NULL,
sugar_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[DOWNLOAD_CANCELLED] =
g_signal_new ("download-cancelled",
G_OBJECT_CLASS_TYPE (download_manager_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
NULL, NULL,
sugar_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
signals[DOWNLOAD_PROGRESS] =
g_signal_new ("download-progress",
G_OBJECT_CLASS_TYPE (download_manager_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
NULL, NULL,
sugar_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
}
static void
sugar_download_manager_finalize (GObject *object)
{
SugarDownloadManager *download_manager = SUGAR_DOWNLOAD_MANAGER (object);
g_hash_table_foreach (download_manager->downloads, sugar_download_remove_download, NULL);
g_hash_table_destroy (download_manager->downloads);
}
static void
sugar_download_remove_download (gpointer key, gpointer value, gpointer user_data)
{
g_free (value);
}
SugarDownloadManager *
sugar_get_download_manager ()
{
if (DownloadManager == NULL)
DownloadManager = g_object_new (SUGAR_TYPE_DOWNLOAD_MANAGER, NULL);
return DownloadManager;
}
void
sugar_download_manager_download_started (SugarDownloadManager *download_manager,
const char *url,
const char *mime_type,
const char *file_name)
{
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
download_manager->downloads,
file_name);
g_return_if_fail (download == NULL);
download = g_object_new (SUGAR_TYPE_DOWNLOAD, NULL);
sugar_download_set_url (download, url);
sugar_download_set_mime_type (download, mime_type);
sugar_download_set_file_name (download, file_name);
g_hash_table_insert (download_manager->downloads,
(gpointer)file_name,
download);
g_signal_emit (download_manager, signals[DOWNLOAD_STARTED], 0, download);
}
void
sugar_download_manager_download_completed (SugarDownloadManager *download_manager,
const char *file_name)
{
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
download_manager->downloads,
file_name);
g_return_if_fail (download);
g_signal_emit (download_manager, signals[DOWNLOAD_COMPLETED], 0, download);
g_hash_table_remove (download_manager->downloads, file_name);
}
void sugar_download_manager_download_cancelled (SugarDownloadManager *download_manager,
const char *file_name)
{
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
download_manager->downloads,
file_name);
g_return_if_fail (download);
g_signal_emit (download_manager, signals[DOWNLOAD_CANCELLED], 0, download);
g_hash_table_remove (download_manager->downloads, file_name);
}
void
sugar_download_manager_update_progress (SugarDownloadManager *download_manager,
const char *file_name,
const int percent)
{
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
download_manager->downloads,
file_name);
g_return_if_fail (download);
sugar_download_set_percent (download, percent);
g_signal_emit (download_manager, signals [DOWNLOAD_PROGRESS], 0, download);
}

@ -1,57 +0,0 @@
#ifndef __SUGAR_DOWNLOAD_MANAGER_H__
#define __SUGAR_DOWNLOAD_MANAGER_H__
#include <glib-object.h>
#include <glib.h>
G_BEGIN_DECLS
typedef struct _SugarDownloadManager SugarDownloadManager;
typedef struct _SugarDownloadManagerClass SugarDownloadManagerClass;
#define SUGAR_TYPE_DOWNLOAD_MANAGER (sugar_download_manager_get_type())
#define SUGAR_DOWNLOAD_MANAGER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManager))
#define SUGAR_DOWNLOAD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManagerClass))
#define SUGAR_IS_DOWNLOAD_MANAGER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_DOWNLOAD_MANAGER))
#define SUGAR_IS_DOWNLOAD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_DOWNLOAD_MANAGER))
#define SUGAR_DOWNLOAD_MANAGER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManagerClass))
struct _SugarDownloadManager {
GObject base_instance;
GHashTable *downloads;
};
struct _SugarDownloadManagerClass {
GObjectClass base_class;
void (* handle_content) (char *url, char *tmp_file_name);
};
GType sugar_download_manager_get_type(void);
SugarDownloadManager *sugar_get_download_manager(void);
void sugar_download_manager_download_started(
SugarDownloadManager *download_manager,
const char *url,
const char *mime_type,
const char *tmp_file_name);
void sugar_download_manager_download_completed(
SugarDownloadManager *download_manager,
const char *tmp_file_name);
void sugar_download_manager_download_cancelled(
SugarDownloadManager *download_manager,
const char *tmp_file_name);
void sugar_download_manager_update_progress(
SugarDownloadManager *download_manager,
const char *tmp_file_name,
const int percent);
G_END_DECLS
#endif

@ -1,108 +0,0 @@
#include "sugar-download.h"
static void sugar_download_finalize (GObject *object);
G_DEFINE_TYPE (SugarDownload, sugar_download, G_TYPE_OBJECT)
static void
sugar_download_init (SugarDownload *download)
{
download->file_name = NULL;
download->url = NULL;
download->mime_type = NULL;
download->percent = 0;
}
static void
sugar_download_class_init (SugarDownloadClass *download_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (download_class);
gobject_class->finalize = sugar_download_finalize;
}
void
sugar_download_set_file_name (SugarDownload *download, const gchar *file_name)
{
gchar *new_file_name;
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
new_file_name = g_strdup (file_name);
g_free (download->file_name);
download->file_name = new_file_name;
}
void
sugar_download_set_url (SugarDownload *download, const gchar *url)
{
gchar *new_url;
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
new_url = g_strdup (url);
g_free (download->url);
download->url = new_url;
}
void
sugar_download_set_mime_type (SugarDownload *download, const gchar *mime_type)
{
gchar *new_mime_type;
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
new_mime_type = g_strdup (mime_type);
g_free (download->mime_type);
download->mime_type = new_mime_type;
}
void
sugar_download_set_percent (SugarDownload *download, const gint percent)
{
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
download->percent = percent;
}
const gchar *
sugar_download_get_file_name (SugarDownload *download)
{
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
return download->file_name;
}
const gchar *
sugar_download_get_url (SugarDownload *download)
{
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
return download->url;
}
const gchar *
sugar_download_get_mime_type (SugarDownload *download)
{
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
return download->mime_type;
}
gint
sugar_download_get_percent (SugarDownload *download)
{
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), -1);
return download->percent;
}
static void
sugar_download_finalize (GObject *object)
{
SugarDownload *download = SUGAR_DOWNLOAD (object);
g_free (download->file_name);
g_free (download->url);
g_free (download->mime_type);
}

@ -1,50 +0,0 @@
#ifndef __SUGAR_DOWNLOAD_H__
#define __SUGAR_DOWNLOAD_H__
#include <glib-object.h>
#include <glib.h>
G_BEGIN_DECLS
typedef struct _SugarDownload SugarDownload;
typedef struct _SugarDownloadClass SugarDownloadClass;
#define SUGAR_TYPE_DOWNLOAD (sugar_download_get_type())
#define SUGAR_DOWNLOAD(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_DOWNLOAD, SugarDownload))
#define SUGAR_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_DOWNLOAD, SugarDownloadClass))
#define SUGAR_IS_DOWNLOAD(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_DOWNLOAD))
#define SUGAR_IS_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_DOWNLOAD))
#define SUGAR_DOWNLOAD_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_DOWNLOAD, SugarDownloadClass))
struct _SugarDownload {
GObject base_instance;
gchar *file_name;
gchar *url;
gchar *mime_type;
gint percent;
};
struct _SugarDownloadClass {
GObjectClass base_class;
};
GType sugar_download_get_type(void);
void sugar_download_set_file_name (SugarDownload *download,
const gchar *file_name);
void sugar_download_set_url (SugarDownload *download,
const gchar *url);
void sugar_download_set_mime_type (SugarDownload *download,
const gchar *mime_type);
void sugar_download_set_percent (SugarDownload *download,
const gint percent);
const gchar *sugar_download_get_file_name (SugarDownload *download);
const gchar *sugar_download_get_url (SugarDownload *download);
const gchar *sugar_download_get_mime_type (SugarDownload *download);
gint sugar_download_get_percent (SugarDownload *download);
G_END_DECLS
#endif /* __SUGAR_DOWNLOAD_H__ */

@ -1,4 +0,0 @@
VOID:OBJECT,STRING,LONG,LONG
VOID:OBJECT,LONG
VOID:OBJECT
BOOLEAN:BOXED

@ -27,58 +27,11 @@ PKG_CHECK_MODULES(PYGTK, pygtk-2.0)
PKG_CHECK_MODULES(PYCAIRO, pycairo)
PKG_CHECK_MODULES(LIB, gtk+-2.0)
PKG_CHECK_MODULES(SHELL, gtk+-2.0 gstreamer-0.10 gstreamer-plugins-base-0.10)
PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
AC_SUBST(PYGTK_DEFSDIR)
#
# Mozilla
#
AC_ARG_WITH(libxul_sdk,
AC_HELP_STRING([--with-libxul-sdk=DIR], [Path to libxul SDK]))
if test -d "$with_libxul_sdk"; then
# xulrunner 1.9
GECKO_CFLAGS="-I$with_libxul_sdk/sdk/include -DXPCOM_GLUE"
XPCOMGLUE_LIBS="-L$with_libxul_sdk/sdk/lib -lxpcomglue"
MOZILLA_INCLUDE_DIR="$with_libxul_sdk/include"
XPIDL="$with_libxul_sdk/sdk/bin/xpidl"
MOZILLA_IDL_DIR="$with_libxul_sdk/sdk/idl"
AC_SUBST(XPCOMGLUE_LIBS)
AC_SUBST(GECKO_CFLAGS)
AC_SUBST(MOZILLA_INCLUDE_DIR)
AC_SUBST(XPIDL)
AC_SUBST(MOZILLA_IDL_DIR)
PKG_CHECK_MODULES(NSPR, [nspr],
[have_nspr=true],
[
PKG_CHECK_MODULES(NSPR, [mozilla-nspr],
[have_nspr=true],
[
PKG_CHECK_MODULES(NSPR, [xulrunner-nspr],
[have_nspr=true],
have_nspr=false)
])
])
if test "x$have_nspr" = xfalse; then
AC_MSG_ERROR([Could not find nspr])
fi
else
AC_MSG_ERROR([Must specify the xulrunner sdk dir (--with-libxul-sdk)])
fi
#
# Setup GETTEXT
#
@ -95,10 +48,6 @@ AC_OUTPUT([
Makefile
bin/Makefile
data/Makefile
browser/Makefile
browser/components/Makefile
browser/components/sessionstore/Makefile
browser/components/browserhelper/Makefile
services/Makefile
services/presence/Makefile
services/clipboard/Makefile
@ -129,7 +78,6 @@ services/console/interface/logviewer/Makefile
services/console/interface/terminal/Makefile
sugar/Makefile
sugar/activity/Makefile
sugar/browser/Makefile
sugar/clipboard/Makefile
sugar/graphics/Makefile
sugar/p2p/Makefile

@ -1,104 +0,0 @@
#ifndef __sugar_shell_marshal_MARSHAL_H__
#define __sugar_shell_marshal_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
#define g_marshal_value_peek_long(v) g_value_get_long (v)
#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
#define g_marshal_value_peek_float(v) g_value_get_float (v)
#define g_marshal_value_peek_double(v) g_value_get_double (v)
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v) g_value_get_param (v)
#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
#define g_marshal_value_peek_object(v) g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
* Do not access GValues directly in your code. Instead, use the
* g_value_get_*() functions
*/
#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
#define g_marshal_value_peek_char(v) (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
#define g_marshal_value_peek_int(v) (v)->data[0].v_int
#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
#define g_marshal_value_peek_long(v) (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_float(v) (v)->data[0].v_float
#define g_marshal_value_peek_double(v) (v)->data[0].v_double
#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */
/* BOOLEAN:UINT,UINT (./sugar-shell-marshal.list:1) */
extern void sugar_shell_marshal_BOOLEAN__UINT_UINT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
void
sugar_shell_marshal_BOOLEAN__UINT_UINT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__UINT_UINT) (gpointer data1,
guint arg_1,
guint arg_2,
gpointer data2);
register GMarshalFunc_BOOLEAN__UINT_UINT callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
gboolean v_return;
g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__UINT_UINT) (marshal_data ? marshal_data : cc->callback);
v_return = callback (data1,
g_marshal_value_peek_uint (param_values + 1),
g_marshal_value_peek_uint (param_values + 2),
data2);
g_value_set_boolean (return_value, v_return);
}
G_END_DECLS
#endif /* __sugar_shell_marshal_MARSHAL_H__ */

@ -1,20 +0,0 @@
#ifndef __sugar_shell_marshal_MARSHAL_H__
#define __sugar_shell_marshal_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* BOOLEAN:UINT,UINT (./sugar-shell-marshal.list:1) */
extern void sugar_shell_marshal_BOOLEAN__UINT_UINT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
G_END_DECLS
#endif /* __sugar_shell_marshal_MARSHAL_H__ */

@ -1,47 +0,0 @@
sugardir = $(pythondir)/sugar/browser
sugar_PYTHON = \
__init__.py
INCLUDES = \
$(PYTHON_INCLUDES) \
$(PYGTK_CFLAGS) \
$(PYCAIRO_CFLAGS) \
$(LIB_CFLAGS) \
$(GECKO_CFLAGS) \
$(NSPR_CFLAGS) \
-I$(MOZILLA_INCLUDE_DIR)/gtkembedmoz \
-I$(top_srcdir)/browser
pkgpyexecdir = $(pythondir)/sugar/browser
pkgpyexec_LTLIBRARIES = _sugarbrowser.la
_sugarbrowser_la_LDFLAGS = -module -avoid-version $(GECKO_LDFLAGS)
_sugarbrowser_la_LIBADD = \
$(LIB_LIBS) \
$(PYCAIRO_LIBS) \
$(GECKO_LIBS) \
$(XPCOMGLUE_LIBS) \
$(top_builddir)/browser/libsugarbrowser.la
_sugarbrowser_la_SOURCES = \
_sugarbrowsermodule.c \
xulrunner.cpp \
xulrunner.h
nodist__sugarbrowser_la_SOURCES = _sugarbrowser.c
_sugar.c: _sugarbrowser.defs gtkmozembed.defs _sugarbrowser.override gtkmozembed.override
CLEANFILES = _sugarbrowser.c
EXTRA_DIST = _sugarbrowser.override _sugarbrowser.defs gtkmozembed.defs gtkmozembed.override
.defs.c:
(cd $(srcdir)\
&& $(PYGTK_CODEGEN) \
--register $(PYGTK_DEFSDIR)/gdk-types.defs \
--register $(PYGTK_DEFSDIR)/gtk-types.defs \
--override $*.override \
--prefix py$* $*.defs) > gen-$*.c \
&& cp gen-$*.c $*.c \
&& rm -f gen-$*.c

@ -1,31 +0,0 @@
"""Sugar's web-browser activity
XUL Runner and gtkmozembed and is produced by the PyGTK
.defs system.
"""
try:
from sugar.browser import _sugarbrowser
except ImportError:
from sugar import ltihooks
from sugar.browser import _sugarbrowser
from _sugarbrowser import AddressEntry
from _sugarbrowser import startup, shutdown, get_download_manager
class Browser(_sugarbrowser.Browser):
def __init__(self):
_sugarbrowser.Browser.__init__(self)
def get_browser(self):
from xpcom import components
cls = components.classes["@laptop.org/browser/browserhelper;1"]
browser_helper = cls.getService(components.interfaces.nsIBrowserHelper)
print self.get_instance_id()
return browser_helper.getBrowser(self.get_instance_id())
def get_document(self):
return self.browser.contentDOMWindow.document
document = property(get_document)
browser = property(get_browser)

@ -1,206 +0,0 @@
;; -*- scheme -*-
; object definitions ...
(define-boxed SugarBrowserEvent
(in-module "Sugar")
(c-name "SugarBrowserEvent")
(gtype-id "SUGAR_TYPE_BROWSER_EVENT")
(copy-func "sugar_browser_event_copy")
(release-func "sugar_browser_event_free")
)
(define-boxed SugarBrowserMetadata
(in-module "Sugar")
(c-name "SugarBrowserMetadata")
(gtype-id "SUGAR_TYPE_BROWSER_METADATA")
(copy-func "sugar_browser_metadata_copy")
(release-func "sugar_browser_metadata_free")
)
(define-object AddressEntry
(in-module "Sugar")
(parent "GtkEntry")
(c-name "SugarAddressEntry")
(gtype-id "SUGAR_TYPE_ADDRESS_ENTRY")
)
(define-object Browser
(in-module "Sugar")
(parent "GtkMozEmbed")
(c-name "SugarBrowser")
(gtype-id "SUGAR_TYPE_BROWSER")
)
(define-object DownloadManager
(in-module "Sugar")
(parent "GObject")
(c-name "SugarDownloadManager")
(gtype-id "SUGAR_TYPE_DOWNLOAD_MANAGER")
)
(define-object Download
(in-module "Sugar")
(parent "GObject")
(c-name "SugarDownload")
(gtype-id "SUGAR_TYPE_DOWNLOAD")
)
;; Enumerations and flags ...
;; From sugar-address-entry.h
(define-function sugar_address_entry_get_type
(c-name "sugar_address_entry_get_type")
(return-type "GType")
)
;; From sugar-browser.h
(define-function sugar_browser_get_type
(c-name "sugar_browser_get_type")
(return-type "GType")
)
(define-function startup
(c-name "sugar_browser_startup")
(parameters
'("const-char*" "profile_path")
'("const-char*" "profile_name")
)
(return-type "gboolean")
)
(define-function shutdown
(c-name "sugar_browser_shutdown")
(return-type "none")
)
(define-method grab_focus
(of-object "SugarBrowser")
(c-name "sugar_browser_grab_focus")
(return-type "none")
)
(define-method save_uri
(of-object "SugarBrowser")
(c-name "sugar_browser_save_uri")
(return-type "gboolean")
(parameters
'("const-char*" "uri")
'("const-char*" "filename")
)
)
(define-method save_document
(of-object "SugarBrowser")
(c-name "sugar_browser_save_document")
(return-type "gboolean")
(parameters
'("const-char*" "filename")
)
)
(define-method create_window
(of-object "SugarBrowser")
(c-name "sugar_browser_create_window")
(return-type "SugarBrowser*")
)
(define-virtual create_window
(of-object "SugarBrowser")
(c-name "sugar_browser_create_window")
(return-type "SugarBrowser*")
)
(define-method get_session
(of-object "SugarBrowser")
(c-name "sugar_browser_get_session")
(return-type "char*")
)
(define-method set_session
(of-object "SugarBrowser")
(c-name "sugar_browser_set_session")
(return-type "none")
(parameters
'("const-char*" "session")
)
)
(define-method get_instance_id
(of-object "SugarBrowser")
(c-name "sugar_browser_get_instance_id")
(return-type "int")
)
;; From sugar-key-grabber.h
(define-function sugar_key_grabber_get_type
(c-name "sugar_key_grabber_get_type")
(return-type "GType")
)
(define-method grab
(of-object "SugarKeyGrabber")
(c-name "sugar_key_grabber_grab")
(return-type "none")
(parameters
'("const-char*" "key")
)
)
(define-method get_key
(of-object "SugarKeyGrabber")
(c-name "sugar_key_grabber_get_key")
(return-type "char*")
(parameters
'("guint" "keycode")
'("guint" "state")
)
)
;; From sugar-download-manager.h
(define-function sugar_download_manager_get_type
(c-name "sugar_download_manager_get_type")
(return-type "GType")
)
(define-function get_download_manager
(c-name "sugar_get_download_manager")
(return-type "SugarDownloadManager*")
)
;; From sugar-download.h
(define-function sugar_download_get_type
(c-name "sugar_download_get_type")
(return-type "GType")
)
(define-method get_file_name
(of-object "SugarDownload")
(c-name "sugar_download_get_file_name")
(return-type "const-gchar*")
)
(define-method get_url
(of-object "SugarDownload")
(c-name "sugar_download_get_url")
(return-type "const-gchar*")
)
(define-method get_mime_type
(of-object "SugarDownload")
(c-name "sugar_download_get_mime_type")
(return-type "const-gchar*")
)
(define-method get_percent
(of-object "SugarDownload")
(c-name "sugar_download_get_percent")
(return-type "gint")
)
(include "gtkmozembed.defs")

@ -1,80 +0,0 @@
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#include "pygobject.h"
#include "sugar-browser.h"
#include "sugar-address-entry.h"
#include "sugar-download-manager.h"
#include "sugar-download.h"
#include <pygtk/pygtk.h>
#include <glib.h>
%%
modulename _sugarbrowser
%%
import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import hippo.CanvasImage as HippoCanvasImage_Type
%%
ignore-glob
*_get_type
_*
%%
include
gtkmozembed.override
%%
override-slot SugarBrowserMetadata.tp_getattr
static PyObject *
_wrap_sugar_browser_metadata_tp_getattr(PyObject *self, char *attr)
{
SugarBrowserMetadata *metadata = pyg_boxed_get(self, SugarBrowserMetadata);
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[s]", "filename");
else if (!strcmp(attr, "filename")) {
if (metadata->filename) {
return PyString_FromString(metadata->filename);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
return NULL;
}
%%
override-slot SugarBrowserEvent.tp_getattr
static PyObject *
_wrap_sugar_browser_event_tp_getattr(PyObject *self, char *attr)
{
SugarBrowserEvent *event = pyg_boxed_get(self, SugarBrowserEvent);
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[sss]", "image_uri", "button", "image_name");
else if (!strcmp(attr, "image_uri")) {
if (event->image_uri) {
return PyString_FromString(event->image_uri);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "image_name")) {
if (event->image_name) {
return PyString_FromString(event->image_name);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "button"))
return PyInt_FromLong(event->button);
return NULL;
}
%%

@ -1,32 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xulrunner.h"
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygobject.h>
void py_sugarbrowser_register_classes (PyObject *d);
extern PyMethodDef py_sugarbrowser_functions[];
DL_EXPORT(void)
init_sugarbrowser(void)
{
PyObject *m, *d;
xulrunner_startup();
init_pygobject ();
m = Py_InitModule ("_sugarbrowser", py_sugarbrowser_functions);
d = PyModule_GetDict (m);
py_sugarbrowser_register_classes (d);
py_sugarbrowser_add_constants(m, "GTK_MOZ_EMBED_");
if (PyErr_Occurred ()) {
Py_FatalError ("can't initialise module _sugarbrowser");
}
}

@ -1,475 +0,0 @@
;; -*- scheme -*-
; object definitions ...
(define-object MozEmbed
(in-module "Gtk")
(parent "GtkBin")
(c-name "GtkMozEmbed")
(gtype-id "GTK_TYPE_MOZ_EMBED")
)
; (define-object MozEmbedSingle
; (in-module "Gtk")
; (parent "GtkObject")
; (c-name "GtkMozEmbedSingle")
; (gtype-id "GTK_TYPE_MOZ_EMBED_SINGLE")
; )
;; Enumerations and flags ...
(define-enum MozEmbedProgressFlags
(in-module "Gtk")
(c-name "GtkMozEmbedProgressFlags")
(values
'("start" "GTK_MOZ_EMBED_FLAG_START")
'("redirecting" "GTK_MOZ_EMBED_FLAG_REDIRECTING")
'("transferring" "GTK_MOZ_EMBED_FLAG_TRANSFERRING")
'("negotiating" "GTK_MOZ_EMBED_FLAG_NEGOTIATING")
'("stop" "GTK_MOZ_EMBED_FLAG_STOP")
'("is-request" "GTK_MOZ_EMBED_FLAG_IS_REQUEST")
'("is-document" "GTK_MOZ_EMBED_FLAG_IS_DOCUMENT")
'("is-network" "GTK_MOZ_EMBED_FLAG_IS_NETWORK")
'("is-window" "GTK_MOZ_EMBED_FLAG_IS_WINDOW")
)
)
(define-enum MozEmbedStatusFlags
(in-module "Gtk")
(c-name "GtkMozEmbedStatusFlags")
(values
'("dns" "GTK_MOZ_EMBED_STATUS_FAILED_DNS")
'("connect" "GTK_MOZ_EMBED_STATUS_FAILED_CONNECT")
'("timeout" "GTK_MOZ_EMBED_STATUS_FAILED_TIMEOUT")
'("usercanceled" "GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED")
)
)
(define-enum MozEmbedReloadFlags
(in-module "Gtk")
(c-name "GtkMozEmbedReloadFlags")
(values
'("normal" "GTK_MOZ_EMBED_FLAG_RELOADNORMAL")
'("bypasscache" "GTK_MOZ_EMBED_FLAG_RELOADBYPASSCACHE")
'("bypassproxy" "GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXY")
'("bypassproxyandcache" "GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE")
'("charsetchange" "GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE")
)
)
(define-enum MozEmbedChromeFlags
(in-module "Gtk")
(c-name "GtkMozEmbedChromeFlags")
(values
'("defaultchrome" "GTK_MOZ_EMBED_FLAG_DEFAULTCHROME")
'("windowborderson" "GTK_MOZ_EMBED_FLAG_WINDOWBORDERSON")
'("windowcloseon" "GTK_MOZ_EMBED_FLAG_WINDOWCLOSEON")
'("windowresizeon" "GTK_MOZ_EMBED_FLAG_WINDOWRESIZEON")
'("menubaron" "GTK_MOZ_EMBED_FLAG_MENUBARON")
'("toolbaron" "GTK_MOZ_EMBED_FLAG_TOOLBARON")
'("locationbaron" "GTK_MOZ_EMBED_FLAG_LOCATIONBARON")
'("statusbaron" "GTK_MOZ_EMBED_FLAG_STATUSBARON")
'("personaltoolbaron" "GTK_MOZ_EMBED_FLAG_PERSONALTOOLBARON")
'("scrollbarson" "GTK_MOZ_EMBED_FLAG_SCROLLBARSON")
'("titlebaron" "GTK_MOZ_EMBED_FLAG_TITLEBARON")
'("extrachromeon" "GTK_MOZ_EMBED_FLAG_EXTRACHROMEON")
'("allchrome" "GTK_MOZ_EMBED_FLAG_ALLCHROME")
'("windowraised" "GTK_MOZ_EMBED_FLAG_WINDOWRAISED")
'("windowlowered" "GTK_MOZ_EMBED_FLAG_WINDOWLOWERED")
'("centerscreen" "GTK_MOZ_EMBED_FLAG_CENTERSCREEN")
'("dependent" "GTK_MOZ_EMBED_FLAG_DEPENDENT")
'("modal" "GTK_MOZ_EMBED_FLAG_MODAL")
'("openasdialog" "GTK_MOZ_EMBED_FLAG_OPENASDIALOG")
'("openaschrome" "GTK_MOZ_EMBED_FLAG_OPENASCHROME")
)
)
;; From /usr/include/mozilla-1.2b/gtkembedmoz/gtkmozembed.h
(define-function gtk_moz_embed_get_type
(c-name "gtk_moz_embed_get_type")
(return-type "GtkType")
)
(define-function gtk_moz_embed_new
(c-name "gtk_moz_embed_new")
(is-constructor-of "GtkMozEmbed")
(return-type "GtkWidget*")
)
(define-function push_startup
(c-name "gtk_moz_embed_push_startup")
(return-type "none")
)
(define-function pop_startup
(c-name "gtk_moz_embed_pop_startup")
(return-type "none")
)
(define-function gtk_moz_embed_set_comp_path
(c-name "gtk_moz_embed_set_comp_path_deprecated")
(return-type "none")
(parameters
'("char*" "aPath")
)
(deprecated "renamed to gtkmozembed.set_comp_path")
)
(define-function set_comp_path
(c-name "gtk_moz_embed_set_comp_path")
(return-type "none")
(parameters
'("char*" "aPath")
)
)
(define-function gtk_moz_embed_set_profile_path
(c-name "gtk_moz_embed_set_profile_path_deprecated")
(return-type "none")
(parameters
'("char*" "aDir")
'("char*" "aName")
)
(deprecated "renamed to gtkmozembed.set_profile_path")
)
(define-function set_profile_path
(c-name "gtk_moz_embed_set_profile_path")
(return-type "none")
(parameters
'("char*" "aDir")
'("char*" "aName")
)
)
(define-method load_url
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_load_url")
(return-type "none")
(parameters
'("const-char*" "url")
)
)
(define-method stop_load
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_stop_load")
(return-type "none")
)
(define-method can_go_back
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_can_go_back")
(return-type "gboolean")
)
(define-method can_go_forward
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_can_go_forward")
(return-type "gboolean")
)
(define-method go_back
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_go_back")
(return-type "none")
)
(define-method go_forward
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_go_forward")
(return-type "none")
)
(define-method render_data
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_render_data")
(return-type "none")
(parameters
'("const-char*" "data")
'("guint32" "len")
'("const-char*" "base_uri")
'("const-char*" "mime_type")
)
)
(define-method open_stream
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_open_stream")
(return-type "none")
(parameters
'("const-char*" "base_uri")
'("const-char*" "mime_type")
)
)
(define-method append_data
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_append_data")
(return-type "none")
(parameters
'("const-char*" "data")
'("guint32" "len")
)
)
(define-method close_stream
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_close_stream")
(return-type "none")
)
(define-method get_link_message
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_get_link_message")
(return-type "char*")
)
(define-method get_js_status
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_get_js_status")
(return-type "char*")
)
(define-method get_title
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_get_title")
(return-type "char*")
)
(define-method get_location
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_get_location")
(return-type "char*")
)
(define-method reload
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_reload")
(return-type "none")
(parameters
'("gint32" "flags")
)
)
(define-method set_chrome_mask
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_set_chrome_mask")
(return-type "none")
(parameters
'("guint32" "flags")
)
)
(define-method get_chrome_mask
(of-object "GtkMozEmbed")
(c-name "gtk_moz_embed_get_chrome_mask")
(return-type "guint32")
)
; (define-function gtk_moz_embed_progress_flags_get_type
; (c-name "gtk_moz_embed_progress_flags_get_type")
; (return-type "GtkType")
; )
; (define-function gtk_moz_embed_status_enums_get_type
; (c-name "gtk_moz_embed_status_enums_get_type")
; (return-type "GtkType")
; )
; (define-function gtk_moz_embed_reload_flags_get_type
; (c-name "gtk_moz_embed_reload_flags_get_type")
; (return-type "GtkType")
; )
; (define-function gtk_moz_embed_chrome_flags_get_type
; (c-name "gtk_moz_embed_chrome_flags_get_type")
; (return-type "GtkType")
; )
(define-function gtk_moz_embed_single_get
(c-name "gtk_moz_embed_single_get")
(return-type "GtkMozEmbedSingle*")
)
(define-virtual link_message
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual js_status
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual location
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual title
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual progress
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gint" "curprogress")
'("gint" "maxprogress")
)
)
(define-virtual progress_all
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("const-char*" "aURI")
'("gint" "curprogress")
'("gint" "maxprogress")
)
)
(define-virtual net_state
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gint" "state")
'("guint" "status")
)
)
(define-virtual net_state_all
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("const-char*" "aURI")
'("gint" "state")
'("guint" "status")
)
)
(define-virtual net_start
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual net_stop
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual new_window
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("GtkMozEmbed**" "newEmbed")
'("guint" "chromemask")
)
)
(define-virtual visibility
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gboolean" "visibility")
)
)
(define-virtual destroy_brsr
(of-object "GtkMozEmbed")
(return-type "none")
)
(define-virtual open_uri
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("const-char*" "aURI")
)
)
(define-virtual size_to
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gint" "width")
'("gint" "height")
)
)
(define-virtual dom_key_down
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_key_press
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_key_up
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_down
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_up
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_click
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_dbl_click
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_over
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual dom_mouse_out
(of-object "GtkMozEmbed")
(return-type "gint")
(parameters
'("gpointer" "dom_event")
)
)
(define-virtual security_change
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gpointer" "request")
'("guint" "state")
)
)
(define-virtual status_change
(of-object "GtkMozEmbed")
(return-type "none")
(parameters
'("gpointer" "request")
'("gint" "status")
'("gpointer" "message")
)
)
(define-virtual new_window_orphan
(of-object "GtkMozEmbedSingle")
(return-type "none")
(parameters
'("GtkMozEmbed**" "newEmbed")
'("guint" "chromemask")
)
)

@ -1,50 +0,0 @@
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
#include <gtkmozembed.h>
%%
import gobject.GObject as PyGObject_Type
import gtk.Object as PyGtkObject_Type
import gtk.Bin as PyGtkBin_Type
%%
ignore-glob
*_get_type
_*
%%
override gtk_moz_embed_set_comp_path_deprecated kwargs
static PyObject *
_wrap_gtk_moz_embed_set_comp_path_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "aPath", NULL };
char *aPath;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:gtk_moz_embed_set_comp_path", kwlist, &aPath))
return NULL;
if (PyErr_Warn(PyExc_DeprecationWarning, "renamed to gtkmozembed.set_comp_path") < 0)
return NULL;
gtk_moz_embed_set_comp_path(aPath);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gtk_moz_embed_set_profile_path_deprecated kwargs
static PyObject *
_wrap_gtk_moz_embed_set_profile_path_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "aDir", "aName", NULL };
char *aDir, *aName;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss:gtk_moz_embed_set_profile_path", kwlist, &aDir, &aName))
return NULL;
if (PyErr_Warn(PyExc_DeprecationWarning, "renamed to gtkmozembed.set_profile_path") < 0)
return NULL;
gtk_moz_embed_set_profile_path(aDir, aName);
Py_INCREF(Py_None);
return Py_None;
}

@ -1,60 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <string.h>
#include "gtkmozembed_glue.cpp"
extern "C" int
xulrunner_startup(void)
{
static const GREVersionRange greVersion = {
"1.9a", PR_TRUE,
"2", PR_TRUE
};
char xpcomPath[PATH_MAX];
nsresult rv = GRE_GetGREPathWithProperties(&greVersion, 1, nsnull, 0,
xpcomPath, sizeof(xpcomPath));
if (NS_FAILED(rv)) {
fprintf(stderr, "Couldn't find a compatible GRE.\n");
return 1;
}
rv = XPCOMGlueStartup(xpcomPath);
if (NS_FAILED(rv)) {
fprintf(stderr, "Couldn't start XPCOM.");
return 1;
}
rv = GTKEmbedGlueStartup();
if (NS_FAILED(rv)) {
fprintf(stderr, "Couldn't find GTKMozEmbed symbols.");
return 1;
}
char *lastSlash = strrchr(xpcomPath, '/');
if (lastSlash)
*lastSlash = '\0';
gtk_moz_embed_set_path(xpcomPath);
}

@ -1,20 +0,0 @@
/*
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
int xulrunner_startup (void);
Loading…
Cancel
Save