Eliminating a layer of code between the managed classes URI and ProfileManager and the onderlying XPCOM objects, and cleaning up a bunch of stuff. Not part of the build.

This commit is contained in:
jst%netscape.com 2003-05-23 07:09:13 +00:00
Родитель b7b494a1a0
Коммит 1c688e88bc
9 изменённых файлов: 644 добавлений и 1398 удалений

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

@ -14,7 +14,7 @@
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
@ -38,9 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#using <mscorlib.dll>
#include "cstringt.h"
#include "nsISupports.h"
#include <vcclr.h>
#include "nsCOMPtr.h"
#include "nsIWebBrowser.h"
#include "nsIWebBrowserChrome.h"
@ -49,7 +47,6 @@
#include "nsIWebNavigation.h"
#include "nsIWindowWatcher.h"
#include "nsIInputStream.h"
#include "nsIURI.h"
#include "nsEmbedAPI.h"
#include "DotNETEmbed.h"
@ -60,6 +57,55 @@ using namespace System::Runtime::InteropServices;
using namespace Mozilla::Embedding;
// Silly class for holding on to a static UTF8Encoding so that we
// don't need to create a new one in every call to CopyString()...
public __gc class UTF8EncodingHolder
{
public:
static Text::UTF8Encoding *sUTF8Encoding = new Text::UTF8Encoding();
};
String *
Mozilla::Embedding::CopyString(const nsAFlatCString& aStr)
{
return new String(aStr.get(), 0, aStr.Length(),
UTF8EncodingHolder::sUTF8Encoding);
}
// In stead of copying String's to nsAString's we could write a class
// that wraps a String object and exposes it's underlying
// buffer. Doable, if we pin the String object, and so on, but this'll
// do for now.
nsAFlatString&
Mozilla::Embedding::CopyString(String *aSrc, nsAFlatString& aDest)
{
const wchar_t __pin * strbuf = PtrToStringChars(aSrc);
aDest.Assign(strbuf, aSrc->Length);
return aDest;
}
nsAFlatCString&
Mozilla::Embedding::CopyString(String *aSrc, nsAFlatCString& aDest)
{
const wchar_t __pin * strbuf = PtrToStringChars(aSrc);
aDest = NS_ConvertUCS2toUTF8(nsDependentString(strbuf, aSrc->Length));
return aDest;
}
void
Mozilla::Embedding::ThrowIfFailed(nsresult rv)
{
if (NS_FAILED(rv)) {
// XXX: Throw some useful exception here!
throw "rv is an error code!";
}
}
#pragma unmanaged
#define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
@ -67,25 +113,30 @@ using namespace Mozilla::Embedding;
bool ResizeEmbedding(HWND hWnd, nsIWebBrowserChrome* chrome);
bool OpenWebPage(HWND hWnd, const wchar_t* url);
nsresult CreateBrowserWindow(HWND hWnd, PRUint32 aChromeFlags,
nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow);
nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow);
nsCOMPtr<nsIWebBrowserChrome> chrome;
bool InitializeEmbedding()
bool
InitializeEmbedding()
{
nsresult rv = NS_InitEmbedding(nsnull, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not Initialize Gecko Engine");
return (NS_OK == rv) ? true : false;
}
bool TerminateEmbedding()
bool
TerminateEmbedding()
{
nsresult rv = NS_TermEmbedding();
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not Terminate Gecko Engine");
return (NS_OK == rv) ? true : false;
}
nsresult CreateBrowserWindow(HWND hWnd, PRUint32 aChromeFlags, nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow)
nsresult
CreateBrowserWindow(HWND hWnd, PRUint32 aChromeFlags,
nsIWebBrowserChrome *aParent,
nsIWebBrowserChrome **aNewWindow)
{
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
@ -117,57 +168,61 @@ nsresult CreateBrowserWindow(HWND hWnd, PRUint32 aChromeFlags, nsIWebBrowserChro
return NS_OK;
}
bool OpenWebPage(HWND hWnd, const wchar_t *url)
bool
OpenWebPage(HWND hWnd, const wchar_t *url)
{
nsresult rv;
if (!chrome)
{
rv = CreateBrowserWindow(hWnd, nsIWebBrowserChrome::CHROME_ALL,
nsnull, getter_AddRefs(chrome));
CreateBrowserWindow(hWnd, nsIWebBrowserChrome::CHROME_ALL,
nsnull, getter_AddRefs(chrome));
}
if (chrome)
if (chrome)
{
SetWindowLong(hWnd, GWL_USERDATA, (LONG)NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
SetWindowLong(hWnd, GWL_USERDATA,
(LONG)NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
// Start loading a page
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->GetWebBrowser(getter_AddRefs(newBrowser));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
return (NS_OK == webNav->LoadURI(url,
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull, nsnull, nsnull) ? true : false);
rv = webNav->LoadURI(url, nsIWebNavigation::LOAD_FLAGS_NONE, nsnull,
nsnull, nsnull);
return NS_SUCCEEDED(rv);
}
return false;
}
}
bool ResizeEmbedding(HWND hWnd, nsIWebBrowserChrome* chrome)
bool
ResizeEmbedding(HWND hWnd, nsIWebBrowserChrome* chrome)
{
if (!chrome)
if (!chrome)
{
chrome = (nsIWebBrowserChrome *)GetWindowLong(hWnd, GWL_USERDATA);
if (!chrome)
if (!chrome)
return false;
}
nsCOMPtr<nsIEmbeddingSiteWindow> embeddingSite = do_QueryInterface(chrome);
RECT rect;
GetClientRect(hWnd, &rect);
// Make sure the browser is visible and sized
nsCOMPtr<nsIWebBrowser> webBrowser;
chrome->GetWebBrowser(getter_AddRefs(webBrowser));
nsCOMPtr<nsIBaseWindow> webBrowserAsWin = do_QueryInterface(webBrowser);
if (webBrowserAsWin)
if (webBrowserAsWin)
{
webBrowserAsWin->SetPositionAndSize(rect.left,
rect.top,
rect.right - rect.left,
webBrowserAsWin->SetPositionAndSize(rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PR_TRUE);
webBrowserAsWin->SetVisibility(PR_TRUE);
@ -178,7 +233,7 @@ bool ResizeEmbedding(HWND hWnd, nsIWebBrowserChrome* chrome)
//*****************************************************************************
// WebBrowserChrome::nsISupports
//*****************************************************************************
//*****************************************************************************
NS_IMPL_ADDREF(WebBrowserChrome)
NS_IMPL_RELEASE(WebBrowserChrome)
@ -200,25 +255,29 @@ WebBrowserChrome::~WebBrowserChrome()
}
/* attribute nativeSiteWindow siteWindow */
NS_IMETHODIMP WebBrowserChrome::GetSiteWindow(void * *aSiteWindow)
NS_IMETHODIMP
WebBrowserChrome::GetSiteWindow(void * *aSiteWindow)
{
*aSiteWindow = mNativeWindow;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::GetTitle(PRUnichar * *aTitle)
NS_IMETHODIMP
WebBrowserChrome::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = nsnull;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::SetTitle(const PRUnichar * aTitle)
NS_IMETHODIMP
WebBrowserChrome::SetTitle(const PRUnichar * aTitle)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute boolean visibility; */
NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool * aVisibility)
NS_IMETHODIMP
WebBrowserChrome::GetVisibility(PRBool * aVisibility)
{
NS_ENSURE_ARG_POINTER(aVisibility);
*aVisibility = PR_TRUE;
@ -226,61 +285,74 @@ NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool * aVisibility)
}
NS_IMETHODIMP WebBrowserChrome::SetVisibility(PRBool aVisibility)
NS_IMETHODIMP
WebBrowserChrome::SetVisibility(PRBool aVisibility)
{
return NS_OK;
}
/* void setFocus (); */
NS_IMETHODIMP WebBrowserChrome::SetFocus()
NS_IMETHODIMP
WebBrowserChrome::SetFocus()
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
NS_IMETHODIMP
WebBrowserChrome::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y,
PRInt32 cx, PRInt32 cy)
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
NS_IMETHODIMP
WebBrowserChrome::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y,
PRInt32 *cx, PRInt32 *cy)
{
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
{
*x = 0;
*y = 0;
}
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
*cx = 0;
*cy = 0;
}
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
NS_IMETHODIMP
WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
NS_IMETHODIMP
WebBrowserChrome::ShowAsModal(void)
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::IsWindowModal(PRBool *_retval)
NS_IMETHODIMP
WebBrowserChrome::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
NS_IMETHODIMP
WebBrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
NS_IMETHODIMP
WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{
NS_ENSURE_ARG_POINTER(aWebBrowser);
*aWebBrowser = mWebBrowser;
@ -288,47 +360,54 @@ NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
NS_IMETHODIMP
WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{
mWebBrowser = aWebBrowser;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
NS_IMETHODIMP
WebBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
{
*aChromeMask = mChromeFlags;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
NS_IMETHODIMP
WebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
{
mChromeFlags = aChromeMask;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::DestroyBrowserWindow(void)
NS_IMETHODIMP
WebBrowserChrome::DestroyBrowserWindow(void)
{
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aWidth, PRInt32 aHeight)
NS_IMETHODIMP
WebBrowserChrome::SizeBrowserTo(PRInt32 aWidth, PRInt32 aHeight)
{
::MoveWindow((HWND)mNativeWindow, 0, 0, aWidth, aHeight, TRUE);
return NS_OK;
}
nsresult WebBrowserChrome::CreateBrowser(HWND hWnd, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nsIWebBrowser **aBrowser)
nsresult
WebBrowserChrome::CreateBrowser(HWND hWnd, PRInt32 aX, PRInt32 aY, PRInt32 aCX,
PRInt32 aCY, nsIWebBrowser **aBrowser)
{
NS_ENSURE_ARG_POINTER(aBrowser);
*aBrowser = nsnull;
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
if (!mWebBrowser)
return NS_ERROR_FAILURE;
(void)mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
@ -340,9 +419,7 @@ nsresult WebBrowserChrome::CreateBrowser(HWND hWnd, PRInt32 aX, PRInt32 aY, PRIn
if (!mNativeWindow)
return NS_ERROR_FAILURE;
browserBaseWindow->InitWindow( mNativeWindow,
nsnull,
aX, aY, aCX, aCY);
browserBaseWindow->InitWindow(mNativeWindow, nsnull, aX, aY, aCX, aCY);
browserBaseWindow->Create();
if (mWebBrowser)
@ -356,23 +433,27 @@ nsresult WebBrowserChrome::CreateBrowser(HWND hWnd, PRInt32 aX, PRInt32 aY, PRIn
}
#pragma managed
bool Gecko::InitEmbedding()
bool
Gecko::InitEmbedding()
{
return InitializeEmbedding();
}
bool Gecko::TermEmbedding()
bool
Gecko::TermEmbedding()
{
return TerminateEmbedding();
}
bool Gecko::OpenURL(IntPtr hWnd, String *url)
bool
Gecko::OpenURL(IntPtr hWnd, String *url)
{
const wchar_t __pin * pURL = PtrToStringChars(url);
return OpenWebPage((HWND)hWnd.ToInt32(), pURL);
}
bool Gecko::Resize(IntPtr hWnd)
bool
Gecko::Resize(IntPtr hWnd)
{
return ResizeEmbedding((HWND)hWnd.ToInt32(), NULL);
}

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

@ -37,7 +37,7 @@
*
* ***** END LICENSE BLOCK ***** */
#pragma once
#include "nsString.h"
using namespace System;
@ -54,5 +54,28 @@ namespace Mozilla
bool OpenURL(IntPtr hWnd, String *url);
bool Resize(IntPtr hWnd);
}; // class Gecko
// Throw an exception if NS_FAILED(rv)
void ThrowIfFailed(nsresult rv);
// Helper for copying an UCS2 Mozilla nsAFlatString to a managed
// String.
inline String * CopyString(const nsAFlatString& aStr)
{
return new String(aStr.get(), 0, aStr.Length());
}
// Helper for copying an UTF8 Mozilla nsAFlatCString to a managed
// String.
String * CopyString(const nsAFlatCString& aStr);
// Helper for copying a managed String into a Mozilla UCS2
// nsAFlatString.
nsAFlatString& CopyString(String *aSrc, nsAFlatString& aDest);
// Helper for copying a managed String into a Mozilla UTF8
// nsAFlatCString.
nsAFlatCString& CopyString(String *aSrc, nsAFlatCString& aDest);
} // namespace Embedding
}

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

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

@ -39,7 +39,10 @@
#pragma once
using namespace System;
#include "DotNETEmbed.h"
// Forward declarations, Mozilla classes/interfaces.
class nsIURI;
namespace Mozilla
{
@ -47,42 +50,49 @@ namespace Mozilla
{
namespace Networking
{
public __gc class URI : public ICloneable
public __gc class URI : public ICloneable,
public IDisposable
{
private:
unmanagedURI __nogc * mURI;
bool CreateUnmanagedURI();
public:
URI(String *aSpec);
URI(nsIURI *aURI);
~URI();
public:
URI();
~URI();
void Dispose(bool disposing);
void Dispose();
// ICloneable
Object *Clone();
__property String* get_Spec();
__property String* get_PrePath();
__property String* get_Scheme();
__property void set_Scheme(String *aScheme);
__property String* get_UserPass();
__property void set_UserPass(String *aUserPass);
__property String* get_Username();
__property void set_Username(String *aUsername);
__property String* get_Password();
__property void set_Password(String *aPassword);
__property String* get_HostPort();
__property void set_HostPort(String *aHostPort);
__property String* get_Host();
__property void set_Host(String *aHost);
__property IntPtr get_Port();
__property void set_Port(IntPtr aPort);
__property String* get_Path();
__property void set_Path(String *aPath);
bool Equals(URI *aOther);
bool SchemeIs(String *aScheme);
String* Resolve(String *aRelativePath);
__property String* get_AsciiSpec();
__property String* get_AsciiHost();
__property String* get_OriginCharset();
// IDisposable
void Dispose();
__property String* get_Spec();
__property void set_Spec(String *aSpec);
__property String* get_PrePath();
__property String* get_Scheme();
__property void set_Scheme(String *aScheme);
__property String* get_UserPass();
__property void set_UserPass(String *aUserPass);
__property String* get_Username();
__property void set_Username(String *aUsername);
__property String* get_Password();
__property void set_Password(String *aPassword);
__property String* get_HostPort();
__property void set_HostPort(String *aHostPort);
__property String* get_Host();
__property void set_Host(String *aHost);
__property Int32 get_Port();
__property void set_Port(Int32 aPort);
__property String* get_Path();
__property void set_Path(String *aPath);
bool Equals(URI *aOther);
bool SchemeIs(String *aScheme);
// No need for URI *Clone() since we implement ICloneable
String* Resolve(String *aRelativePath);
__property String* get_AsciiSpec();
__property String* get_AsciiHost();
__property String* get_OriginCharset();
private:
nsIURI *mURI; // [OWNER]
}; // class URI
}; // namespace Networking
} // namespace Embedding

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

@ -42,365 +42,165 @@
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIProfile.h"
#include "umProfileManager.h"
#include "DotNetProfileManager.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace Mozilla::Embedding::ProfileManager;
using namespace Mozilla::Embedding;
#pragma unmanaged
unmanagedProfile::unmanagedProfile()
// static
void
ProfileManager::EnsureProfileService()
{
mProfileService = nsnull;
if (sProfileService) {
return;
}
nsresult rv;
nsCOMPtr<nsIProfile> profileService =
do_GetService(NS_PROFILE_CONTRACTID, &rv);
ThrowIfFailed(rv);
sProfileService = profileService.get();
NS_ADDREF(sProfileService);
}
unmanagedProfile::~unmanagedProfile()
{
// static
Int32
ProfileManager::get_ProfileCount()
{
EnsureProfileService();
PRInt32 count;
nsresult rv = sProfileService->GetProfileCount(&count);
ThrowIfFailed(rv);
return count;
}
nsresult unmanagedProfile::CreateProfileService()
// static
String *
ProfileManager::GetProfileList()[]
{
nsresult rv = NS_OK;
mProfileService = do_GetService(NS_PROFILE_CONTRACTID, &rv);
return rv;
EnsureProfileService();
PRUint32 profileCount;
PRUnichar **profiles;
nsresult rv = sProfileService->GetProfileList(&profileCount, &profiles);
ThrowIfFailed(rv);
String *list[] = new String *[profileCount];
for (PRUint32 i = 0; i < profileCount; ++i) {
list[i] = CopyString(nsDependentString(profiles[i]));
}
return list;
}
long unmanagedProfile::GetProfileCount()
// static
bool
ProfileManager::ProfileExists(String *aProfileName)
{
nsresult rv = PR_TRUE;
PRInt32 profCount = 0;
EnsureProfileService();
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return 0L;
PRBool exists;
const wchar_t __pin * profileName = PtrToStringChars(aProfileName);
rv = mProfileService->GetProfileCount(&profCount);
if (NS_FAILED(rv))
return 0L;
return profCount;
}
PRBool unmanagedProfile::ProfileExists(const wchar_t * aProfileName)
{
nsresult rv = PR_TRUE;
PRBool exists = PR_FALSE;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return PR_FALSE;
rv = mProfileService->ProfileExists(aProfileName, &exists);
if (NS_FAILED(rv))
return PR_FALSE;
nsresult rv = sProfileService->ProfileExists(profileName, &exists);
ThrowIfFailed(rv);
return exists;
}
const PRUnichar* unmanagedProfile::GetCurrentProfile()
// static
String*
ProfileManager::get_CurrentProfile()
{
nsresult rv = PR_TRUE;
nsXPIDLString curProfileName;
EnsureProfileService();
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return nsnull;
nsXPIDLString currentProfile;
nsresult rv =
sProfileService->GetCurrentProfile(getter_Copies(currentProfile));
ThrowIfFailed(rv);
rv = mProfileService->GetCurrentProfile(getter_Copies(curProfileName));
if (NS_FAILED(rv))
return nsnull;
return (const PRUnichar *)curProfileName;
return CopyString(currentProfile);
}
bool unmanagedProfile::SetCurrentProfile(const wchar_t * aProfileName)
// static
void
ProfileManager::set_CurrentProfile(String* aCurrentProfile)
{
nsresult rv = PR_TRUE;
EnsureProfileService();
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return false;
rv = mProfileService->SetCurrentProfile(aProfileName);
if (NS_FAILED(rv))
return false;
return true;
const wchar_t __pin * currentProfile = PtrToStringChars(aCurrentProfile);
nsresult rv = sProfileService->SetCurrentProfile(currentProfile);
ThrowIfFailed(rv);
}
void unmanagedProfile::ShutDownCurrentProfile(PRUint32 shutDownType)
// static
void
ProfileManager::ShutDownCurrentProfile(UInt32 shutDownType)
{
nsresult rv = PR_TRUE;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return;
EnsureProfileService();
mProfileService->ShutDownCurrentProfile(shutDownType);
nsresult rv = sProfileService->ShutDownCurrentProfile(shutDownType);
ThrowIfFailed(rv);
}
PRBool unmanagedProfile::CreateNewProfile(const wchar_t * profileName, const wchar_t * nativeProfileDir, const wchar_t * langcode, PRBool useExistingDir)
// static
void
ProfileManager::CreateNewProfile(String* aProfileName,
String *aNativeProfileDir, String* aLangcode,
bool useExistingDir)
{
nsresult rv = PR_TRUE;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return PR_FALSE;
EnsureProfileService();
rv = mProfileService->CreateNewProfile(profileName, nativeProfileDir, langcode, useExistingDir);
if (NS_FAILED(rv))
return PR_FALSE;
const wchar_t __pin * profileName = PtrToStringChars(aProfileName);
const wchar_t __pin * nativeProfileDir = PtrToStringChars(aNativeProfileDir);
const wchar_t __pin * langCode = PtrToStringChars(aLangcode);
nsresult rv = sProfileService->CreateNewProfile(profileName,
nativeProfileDir, langCode,
useExistingDir);
ThrowIfFailed(rv);
}
void unmanagedProfile::RenameProfile(const wchar_t * oldName, const wchar_t * newName)
// static
void
ProfileManager::RenameProfile(String* aOldName, String* aNewName)
{
nsresult rv = PR_TRUE;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return;
EnsureProfileService();
mProfileService->RenameProfile(oldName, newName);
const wchar_t __pin * oldName = PtrToStringChars(aOldName);
const wchar_t __pin * newName = PtrToStringChars(aNewName);
nsresult rv = sProfileService->RenameProfile(oldName, newName);
ThrowIfFailed(rv);
}
void unmanagedProfile::DeleteProfile(const wchar_t * name, PRBool canDeleteFiles)
// static
void
ProfileManager::DeleteProfile(String* aName, bool aCanDeleteFiles)
{
nsresult rv = NS_OK;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return;
EnsureProfileService();
mProfileService->DeleteProfile(name, canDeleteFiles);
const wchar_t __pin * name = PtrToStringChars(aName);
nsresult rv = sProfileService->DeleteProfile(name, aCanDeleteFiles);
ThrowIfFailed(rv);
}
void unmanagedProfile::CloneProfile(const wchar_t * profileName)
// static
void
ProfileManager::CloneProfile(String* aProfileName)
{
nsresult rv = NS_OK;
if (!mProfileService)
rv = CreateProfileService();
if (NS_FAILED(rv))
return;
EnsureProfileService();
mProfileService->CloneProfile(profileName);
}
#pragma managed
Profile::Profile()
{
mProfile = NULL;
}
Profile::~Profile()
{
Dispose(false);
}
void Profile::Dispose()
{
Dispose(true);
}
void Profile::Dispose(bool disposing)
{
if (mProfile)
{
delete mProfile;
mProfile = NULL;
}
if (disposing)
{
GC::SuppressFinalize(this);
}
}
bool Profile::CreateUnmanagedProfile()
{
bool ret = false;
try
{
mProfile = new unmanagedProfile();
if (mProfile)
ret = true;
}
catch (Exception*)
{
throw;
}
return ret;
}
Int32 Profile::get_ProfileCount()
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return 0;
}
return mProfile->GetProfileCount();
}
void Profile::GetProfileList(UInt32* length, String** profileNames)
{
// ToDo
return;
}
bool Profile::ProfileExists(String *aProfileName)
{
bool ret = false;
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return false;
}
try
{
const wchar_t __pin * pName = PtrToStringChars(aProfileName);
ret = mProfile->ProfileExists(pName);
}
catch (Exception*)
{
throw;
}
return ret;
}
String* Profile::get_CurrentProfile()
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return NULL;
}
return Marshal::PtrToStringUni((wchar_t *)mProfile->GetCurrentProfile());
}
void Profile::set_CurrentProfile(String* aCurrentProfile)
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return;
}
try
{
const wchar_t __pin * pName = PtrToStringChars(aCurrentProfile);
mProfile->SetCurrentProfile(pName);
}
catch (Exception*)
{
throw;
}
}
void Profile::ShutDownCurrentProfile(UInt32 shutDownType)
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return;
}
mProfile->ShutDownCurrentProfile(shutDownType);
}
bool Profile::CreateNewProfile(String* aProfileName, String *aNativeProfileDir, String* aLangcode, bool useExistingDir)
{
bool ret = false;
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return false;
}
try
{
const wchar_t __pin * pName = PtrToStringChars(aProfileName);
const wchar_t __pin * pDir = PtrToStringChars(aNativeProfileDir);
const wchar_t __pin * pLang = PtrToStringChars(aLangcode);
ret = mProfile->CreateNewProfile(pName, pDir, pLang, useExistingDir);
}
catch (Exception*)
{
throw;
}
return ret;
}
void Profile::RenameProfile(String* aOldName, String* aNewName)
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return;
}
try
{
const wchar_t __pin * pOld = PtrToStringChars(aOldName);
const wchar_t __pin * pNew = PtrToStringChars(aNewName);
mProfile->RenameProfile(pOld, pNew);
}
catch (Exception*)
{
throw;
}
}
void Profile::DeleteProfile(String* aName, bool aCanDeleteFiles)
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return;
}
try
{
const wchar_t __pin * pName = PtrToStringChars(aName);
mProfile->DeleteProfile(pName, aCanDeleteFiles);
}
catch (Exception*)
{
throw;
}
}
void Profile::CloneProfile(String* aProfileName)
{
if (!mProfile)
{
if (!CreateUnmanagedProfile())
return;
}
try
{
const wchar_t __pin * pName = PtrToStringChars(aProfileName);
mProfile->CloneProfile(pName);
}
catch (Exception*)
{
throw;
}
const wchar_t __pin * profileName = PtrToStringChars(aProfileName);
nsresult rv = sProfileService->CloneProfile(profileName);
ThrowIfFailed(rv);
}

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

@ -39,42 +39,39 @@
#pragma once
#include "DotNETEmbed.h"
using namespace System;
namespace Mozilla
{
namespace Embedding
{
namespace ProfileManager
// Static
public __gc class ProfileManager
{
public __gc class Profile
{
private:
unmanagedProfile __nogc * mProfile;
bool CreateUnmanagedProfile();
public:
// XXX: These should be in an enum!
static UInt32 SHUTDOWN_PERSIST = 1;
static UInt32 SHUTDOWN_CLEANSE = 2;
public:
Profile();
~Profile();
void Dispose(bool disposing);
void Dispose();
__property static Int32 get_ProfileCount();
static String *GetProfileList()[];
static bool ProfileExists(String *aProfileName);
__property static String* get_CurrentProfile();
__property static void set_CurrentProfile(String* aCurrentProfile);
static void ShutDownCurrentProfile(UInt32 shutDownType);
static void CreateNewProfile(String* aProfileName,
String *aNativeProfileDir,
String* aLangcode, bool useExistingDir);
static void RenameProfile(String* aOldName, String* aNewName);
static void DeleteProfile(String* aName, bool aCanDeleteFiles);
static void CloneProfile(String* aProfileName);
static UInt32 SHUTDOWN_PERSIST = 1;
static UInt32 SHUTDOWN_CLEANSE = 2;
__property Int32 get_ProfileCount();
void GetProfileList(UInt32* length, String** profileNames);
bool ProfileExists(String *aProfileName);
__property String* get_CurrentProfile();
__property void set_CurrentProfile(String* aCurrentProfile);
void ShutDownCurrentProfile(UInt32 shutDownType);
bool CreateNewProfile(String* aProfileName, String *aNativeProfileDir, String* aLangcode, bool useExistingDir);
void RenameProfile(String* aOldName, String* aNewName);
void DeleteProfile(String* aName, bool aCanDeleteFiles);
void CloneProfile(String* aProfileName);
}; // class Profile
} // namespace ProfileManager
private:
static nsIProfile *sProfileService = 0; // [OWNER]
static void EnsureProfileService();
}; // class ProfileManager
} // namespace Embedding
}

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

@ -18,42 +18,42 @@
# Contributor(s):
#
topsrcdir = ${MOZ_SRC}/mozilla
srcdir = ${MOZ_SRC}/mozilla/embedding/wrappers/DotNETEmbed
VPATH = ${MOZ_SRC}/mozilla/embedding/wrappers/DotNETEmbed
ifndef MOZ_OBJ_DIR
MOZ_OBJ_DIR = ${MOZ_SRC}/mozilla
endif
# Compiler variables (implicit rules are used to compile .cpp files)
CC = cl
CFLAGS = -nologo -Zi
CXX = cl
CXXFLAGS = -nologo -CLR -TP -Zi -we4700 -we4701 -c -DDEBUG -DXP_WIN -DXP_WIN32 ${INCLUDES}
CFLAGS = -nologo -Zi
CXX = cl
CXXFLAGS = -nologo -CLR -TP -Zi -wd4005 -we4700 -we4701 -c -DDEBUG -DXP_WIN -DXP_WIN32 ${INCLUDES}
OUTPUT_OPTION = -Fo$@
# Linker variables (implicit rules can't use link.exe, so we do that manually)
LDFLAGS = -nologo -dll -debug -libpath:${topsrcdir}/dist/lib/ -NODEFAULTLIB:MSVCRTD
LDFLAGS = -nologo -dll -debug -libpath:${MOZ_OBJ_DIR}/dist/lib/ -NODEFAULTLIB:MSVCRTD
INCLUDES = \
-I${topsrcdir}/dist/include \
-I${topsrcdir}/dist/include/profile \
-I${topsrcdir}/dist/include/webbrwsr \
-I${topsrcdir}/dist/include/widget \
-I${topsrcdir}/dist/include/xpcom \
-I${topsrcdir}/dist/include/nspr \
-I${topsrcdir}/dist/include/necko \
-I${topsrcdir}/dist/include/docshell \
-I${topsrcdir}/dist/include/dom \
-I${topsrcdir}/dist/include/string \
-I${topsrcdir}/dist/include/embed_base \
-I${topsrcdir}/dist/include/windowwatcher \
-I${topsrcdir}/dist/include/xpconnect
-I${MOZ_OBJ_DIR}/dist/include \
-I${MOZ_OBJ_DIR}/dist/include/profile \
-I${MOZ_OBJ_DIR}/dist/include/webbrwsr \
-I${MOZ_OBJ_DIR}/dist/include/widget \
-I${MOZ_OBJ_DIR}/dist/include/xpcom \
-I${MOZ_OBJ_DIR}/dist/include/nspr \
-I${MOZ_OBJ_DIR}/dist/include/necko \
-I${MOZ_OBJ_DIR}/dist/include/docshell \
-I${MOZ_OBJ_DIR}/dist/include/dom \
-I${MOZ_OBJ_DIR}/dist/include/string \
-I${MOZ_OBJ_DIR}/dist/include/embed_base \
-I${MOZ_OBJ_DIR}/dist/include/windowwatcher \
-I${MOZ_OBJ_DIR}/dist/include/xpconnect
DEPS = DotNETEmbed.h Makefile
CPP_FILES = \
DotNETEmbed.cpp \
DotNETProfileManager.cpp \
DotNETNetworking.cpp \
DotNETEmbed.cpp \
DotNETProfileManager.cpp \
DotNETNetworking.cpp \
AssemblyInfo.cpp
OBJ_FILES = $(CPP_FILES:%.cpp=%.obj)
@ -64,8 +64,8 @@ LIBS = user32.lib xpcom.lib embed_base_s.lib
DotNETEmbed.dll: ${OBJ_FILES} DotNETEmbed.snk ${DEPS}
link ${LDFLAGS} ${LIBS} ${OBJ_FILES} -out:DotNETEmbed.dll
@echo
cp DotNETEmbed.dll ${topsrcdir}/dist/bin
cp DotNETEmbed.pdb ${topsrcdir}/dist/bin
cp DotNETEmbed.dll ${MOZ_OBJ_DIR}/dist/bin
cp DotNETEmbed.pdb ${MOZ_OBJ_DIR}/dist/bin
# regasm -silent DotNETEmbed.dll
# @echo
# gacutil.exe -silent -i DotNETEmbed.dll
@ -76,18 +76,18 @@ DotNETEmbed.dll: ${OBJ_FILES} DotNETEmbed.snk ${DEPS}
DotNETEmbed.obj: DotNETEmbed.cpp umWebChrome.h ${DEPS}
${CXX} ${CXXFLAGS} ${OUTPUT_OPTION} DotNETEmbed.cpp
DotNETProfileManager.obj: DotNETProfileManager.cpp umProfileManager.h ${DEPS}
DotNETProfileManager.obj: DotNETProfileManager.cpp ${DEPS}
${CXX} ${CXXFLAGS} ${OUTPUT_OPTION} DotNETProfileManager.cpp
DotNETNetworking.obj: DotNETNetworking.cpp umURI.h ${DEPS}
DotNETNetworking.obj: DotNETNetworking.cpp DotNETNetworking.h ${DEPS}
${CXX} ${CXXFLAGS} ${OUTPUT_OPTION} DotNETNetworking.cpp
AssemblyInfo.obj: AssemblyInfo.cpp ${DEPS}
${CXX} ${CXXFLAGS} ${OUTPUT_OPTION} AssemblyInfo.cpp
extdlls:
cp ${topsrcdir}/dist/bin/nspr4.dll .
cp ${topsrcdir}/dist/bin/plc4.dll .
cp ${topsrcdir}/dist/bin/plds4.dll .
cp ${topsrcdir}/dist/bin/xpcom.dll .
cp ${MOZ_OBJ_DIR}/dist/bin/nspr4.dll .
cp ${MOZ_OBJ_DIR}/dist/bin/plc4.dll .
cp ${MOZ_OBJ_DIR}/dist/bin/plds4.dll .
cp ${MOZ_OBJ_DIR}/dist/bin/xpcom.dll .
clean:
rm -f *.obj DotNETEmbed.dll

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

@ -1,61 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roy Yokoyama <yokoyama@netscape.com> (original author)
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
class unmanagedProfile
{
private:
nsCOMPtr<nsIProfile> mProfileService;
nsresult CreateProfileService();
public:
unmanagedProfile();
~unmanagedProfile();
long GetProfileCount();
PRBool ProfileExists(const wchar_t * aProfileName);
const PRUnichar* GetCurrentProfile();
bool SetCurrentProfile(const wchar_t * aProfileName);
void ShutDownCurrentProfile(PRUint32 shutDownType);
PRBool CreateNewProfile(const wchar_t * profileName, const wchar_t * nativeProfileDir, const wchar_t * langcode, PRBool useExistingDir);
void RenameProfile(const wchar_t * oldName, const wchar_t * newName);
void DeleteProfile(const wchar_t * name, PRBool canDeleteFiles);
void CloneProfile(const wchar_t * profileName);
};

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

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roy Yokoyama <yokoyama@netscape.com> (original author)
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
class unmanagedURI
{
private:
nsCOMPtr<nsIURI> mUri;
nsresult CreateURI();
nsresult CreateURI(PRUnichar* url);
public:
unmanagedURI();
~unmanagedURI();
const char* GetSpec();
const char* GetPrePath();
const char* GetScheme();
void SetScheme(char* aScheme);
const char* GetUserPass();
void SetUserPass(char* aUserPass);
const char* GetUsername();
void SetUsername(char* aUsername);
const char* GetPassword();
void SetPassword(char* aPassword);
const char* GetHostPort();
void SetHostPort(char* aHostPort);
const char* GetHost();
void SetHost(char* aHost);
PRInt32 GetPort();
void SetPort(PRInt32 aPort);
const char* GetPath();
void SetPath(char* aPath);
bool Equals(unmanagedURI* aOther);
bool SchemeIs(char* aScheme);
const char* Resolve(char* aRelativePath);
const char* GetAsciiSpec();
const char* GetAsciiHost();
const char* GetOriginCharset();
};