Have moved gecko plugin to deprecated

This commit is contained in:
Robert Osfield 2010-12-13 17:36:02 +00:00
parent 543b2ee56e
commit bf6d45a531
16 changed files with 0 additions and 5145 deletions

View File

@ -416,7 +416,6 @@ FIND_PACKAGE(ITK)
FIND_PACKAGE(LibVNCServer)
FIND_PACKAGE(OurDCMTK)
FIND_PACKAGE(OpenAL)
FIND_PACKAGE(XUL)
FIND_PACKAGE(FFmpeg)
FIND_PACKAGE(DirectShow)
FIND_PACKAGE(SDL)

View File

@ -101,13 +101,6 @@ IF(GDAL_FOUND)
ADD_SUBDIRECTORY(ogr)
ENDIF()
IF(XUL_FOUND)
IF(WIN32 OR APPLE OR GTK_FOUND)
ADD_SUBDIRECTORY(gecko)
ENDIF()
ENDIF()
############################################################
#

View File

@ -1,68 +0,0 @@
SET(TARGET_SRC
llembeddedbrowser.cpp
llembeddedbrowserwindow.cpp
llmozlib2.cpp
nsProfileDirServiceProvider.cpp
UBrowser.cpp
ReaderWriterUBrowser.cpp
)
SET(TARGET_H
llembeddedbrowser.h
llembeddedbrowserwindow.h
llmozlib2.h
nsProfileDirServiceProvider.h
nsProfileLock.h
nsProfileStringTypes.h
UBrowser.h
)
ADD_DEFINITIONS(-DMOZILLA_INTERNAL_API)
ADD_DEFINITIONS(-DXUL_DIR=${XUL_DIR})
SET(ALL_REQUIRED_XUL_INCLUDE_DIRS
${XUL_INCLUDE_DIRS}
${XUL_INCLUDE_DIR}/xpcom
${XUL_INCLUDE_DIR}/string
${XUL_INCLUDE_DIR}/locale
${XUL_INCLUDE_DIR}/view
${XUL_INCLUDE_DIR}/content
${XUL_INCLUDE_DIR}/gfx
${XUL_INCLUDE_DIR}/layout
${XUL_INCLUDE_DIR}/webbrwsr
${XUL_INCLUDE_DIR}/widget
${XUL_INCLUDE_DIR}/dom
${XUL_INCLUDE_DIR}/docshell
${XUL_INCLUDE_DIR}/pref
${XUL_INCLUDE_DIR}/nkcache
${XUL_INCLUDE_DIR}/necko/
${XUL_INCLUDE_DIR}/profdirserviceprovider
${XUL_INCLUDE_DIR}/nkcache
${XUL_INCLUDE_DIR}/xulapp
${XUL_INCLUDE_DIR}/profile
${XUL_INCLUDE_DIR}/appshell
${XUL_INCLUDE_DIR}/xpcom_obsolete
${XUL_INCLUDE_DIR}/intl
${XUL_INCLUDE_DIR}/windowwatcher
${XUL_INCLUDE_DIR}/xpconnect
)
IF(WIN32 OR APPLE)
INCLUDE_DIRECTORIES(${ALL_REQUIRED_XUL_INCLUDE_DIRS} )
SET(TARGET_EXTERNAL_LIBRARIES ${XUL_LIBRARIES})
ELSE()
INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS} ${ALL_REQUIRED_XUL_INCLUDE_DIRS} )
SET(TARGET_EXTERNAL_LIBRARIES ${GTK_LIBRARIES} ${XUL_LIBRARIES})
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-aliasing=0")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
SET(TARGET_ADDED_LIBRARIES osgWidget osgViewer)
#### end var setup ###
SETUP_PLUGIN(gecko gecko)

View File

@ -1,103 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* 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
* OpenSceneGraph Public License for more details.
*/
#include <osgDB/ReaderWriter>
#include <osgDB/FileNameUtils>
#include <osgDB/Registry>
#include <osgViewer/ViewerEventHandlers>
#include "UBrowser.h"
class ReaderWriterUBrowser : public osgDB::ReaderWriter
{
public:
ReaderWriterUBrowser()
{
OSG_INFO<<"ReaderWriterUBrowser::ReaderWriterUBrowser()"<<std::endl;
supportsExtension("gecko","browser image");
supportsExtension("browser","browser image");
osg::ref_ptr<osgWidget::BrowserManager> previousManager = osgWidget::BrowserManager::instance();
_initialized = false;
osgWidget::BrowserManager::instance() = new UBrowserManager;
if (previousManager.valid() && !(previousManager->getApplication().empty()))
{
osgWidget::BrowserManager::instance()->setApplication(previousManager->getApplication());
}
OSG_INFO<<"ReaderWriterUBrowser::ReaderWriterUBrowser() done"<<std::endl;
}
virtual ~ReaderWriterUBrowser()
{
// should we restore the previous value?
osgWidget::BrowserManager::instance() = 0;
}
virtual const char* className() const { return "Browser Reader/Writer"; }
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
if (!_initialized)
{
if (osgWidget::BrowserManager::instance()->getApplication().empty())
{
osgWidget::BrowserManager::instance()->setApplication(osg::DisplaySettings::instance()->getApplication());
}
osgWidget::BrowserManager::instance()->init(osgWidget::BrowserManager::instance()->getApplication());
}
unsigned int width = 1024;
unsigned int height = 1024;
return osgWidget::BrowserManager::instance()->createBrowserImage(osgDB::getNameLessExtension(file), width, height);
}
virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
osgDB::ReaderWriter::ReadResult result = readImage(fileName, options);
if (!result.validImage()) return result;
osg::ref_ptr<osgWidget::Browser> browser = new osgWidget::Browser();
if (browser->assign(dynamic_cast<osgWidget::BrowserImage*>(result.getImage())))
{
return browser.release();
}
else
{
return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
}
}
bool _initialized;
};
// now register with Registry to instantiate the above
// reader/writer.
REGISTER_OSGPLUGIN(ubrowser, ReaderWriterUBrowser)

View File

@ -1,624 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* 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
* OpenSceneGraph Public License for more details.
*/
#include "UBrowser.h"
#include <osg/Image>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osg/io_utils>
#include <osg/GraphicsThread>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/ReadFile>
#ifdef _WINDOWS
#include <windows.h>
#elif defined(__APPLE__)
#include <Carbon/Carbon.h>
#else
extern "C" {
#include <gtk/gtk.h>
}
#endif
//////////////////////////////////////////////////////////////////////////
//
// UBrowserManager implementation
//
UBrowserManager::UBrowserManager():
_initialized(false),
_nativeWindowHandle(0),
_previousButtonMask(0)
{
OSG_INFO<<"UBrowserManager::UBrowserManager()"<<std::endl;
}
UBrowserManager::~UBrowserManager()
{
if (_thread.valid())
{
_thread->setDone(true);
while(_thread->isRunning())
{
OpenThreads::Thread::YieldCurrentThread();
}
_thread = 0;
}
}
osgWidget::BrowserImage* UBrowserManager::createBrowserImage(const std::string& url, int width, int height)
{
return new UBrowserImage(this, url, width, height);
}
#if 1
#if defined(_WINDOWS)
void* UBrowserManager::getNativeWindowHandle()
{
if (_nativeWindowHandle) return _nativeWindowHandle;
// My implementation of the embedded browser needs a native window handle
// Can't get this via GLUT so had to use this hack
_nativeWindowHandle = FindWindow( NULL, _appWindowName.c_str() );
return _nativeWindowHandle;
}
#elif defined(__APPLE__)
void* UBrowserManager::getNativeWindowHandle()
{
if (_nativeWindowHandle) return _nativeWindowHandle;
// Create a window just for this purpose.
Rect window_rect = {100, 100, 200, 200};
_nativeWindowHandle = (void*) NewCWindow(
NULL,
&window_rect,
"\p",
false, // Create the window invisible.
zoomDocProc, // Window with a grow box and a zoom box
kLastWindowOfClass, // create it behind other windows
false, // no close box
0);
}
return _nativeWindowHandle;
}
#else
void* UBrowserManager::getNativeWindowHandle()
{
if (_nativeWindowHandle) return _nativeWindowHandle;
gtk_disable_setlocale();
gtk_init(NULL, NULL);
GtkWidget *win = gtk_window_new(GTK_WINDOW_POPUP);
// Why a layout widget? A MozContainer would be ideal, but
// it involves exposing Mozilla headers to mozlib-using apps.
// A layout widget with a GtkWindow parent has the desired
// properties of being plain GTK, having a window, and being
// derived from a GtkContainer.
GtkWidget *rtnw = gtk_layout_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(win), rtnw);
gtk_widget_realize(rtnw);
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(rtnw), GTK_NO_WINDOW);
_nativeWindowHandle = rtnw;
return _nativeWindowHandle;
}
#endif
#endif
struct InitOperation : public osg::Operation
{
InitOperation():
Operation("init",false) {}
/** Override the standard Operation operator and dynamic cast object to a GraphicsContext,
* on success call operation()(GraphicsContext*).*/
virtual void operator () (osg::Object* object)
{
OSG_NOTICE<<"InitOperation begin"<<std::endl;
UBrowserManager* ubrowserManager = dynamic_cast<UBrowserManager*>(object);
OSG_NOTICE<<"InitOperation ubrowserManager="<<ubrowserManager<<std::endl;
// create a single browser window and set things up.
std::string applicationDir = osgDB::getFilePath(ubrowserManager->getApplication());
if (applicationDir.empty()) applicationDir = osgDB::getRealPath(".");
else applicationDir = osgDB::getRealPath(applicationDir);
std::string componentDir = ADDQUOTES(XUL_DIR);
std::string profileDir = applicationDir + "/" + ".profile";
OSG_NOTICE<<"applicationDir="<<applicationDir<<std::endl;
OSG_NOTICE<<"componentDir="<<componentDir<<std::endl;
OSG_NOTICE<<"profileDir="<<profileDir<<std::endl;
OSG_NOTICE<<"ubrowserManager->getNativeWindowHandle()="<<ubrowserManager->getNativeWindowHandle()<<std::endl;
OSG_NOTICE<<"before LLMozLib init() "<<std::endl;
LLMozLib::getInstance()->init( applicationDir, componentDir, profileDir, ubrowserManager->getNativeWindowHandle() );
OSG_NOTICE<<"done LLMozLib init() "<<std::endl;
// append details to agent string
LLMozLib::getInstance()->setBrowserAgentId( ubrowserManager->getApplication() );
OSG_NOTICE<<"InitOperation end"<<std::endl;
}
};
struct UpdateOperation : public osg::Operation
{
UpdateOperation():
osg::Operation("update",true) {}
virtual void operator () (osg::Object* object)
{
UBrowserManager* ubrowserManager = dynamic_cast<UBrowserManager*>(object);
// OSG_NOTICE<<"Update"<<std::endl;
if (ubrowserManager->_ubrowserImageList.empty())
{
// OSG_NOTICE<<"Nothing to do"<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
return;
}
#if !defined(_WINDOWS) && !defined(__APPLE__)
// pump the GTK+Gecko event queue for a (limited) while. this should
// be done so that the Gecko event queue doesn't starve, and done
// *here* so that mNeedsUpdate[] can be populated by callbacks
// from Gecko.
gtk_main_iteration_do(0);
for (int iter=0; iter<10; ++iter)
{
if (gtk_events_pending())
gtk_main_iteration();
}
#endif
typedef std::list< osg::ref_ptr<UBrowserImage> > RefImageList;
RefImageList images;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(ubrowserManager->_ubrowserImageListMutex);
std::copy(ubrowserManager->_ubrowserImageList.begin(),
ubrowserManager->_ubrowserImageList.end(),
std::back_inserter(images));
}
int numUpdated = 0;
for(RefImageList::iterator itr = images.begin();
itr != images.end();
++itr)
{
if (update(itr->get())) ++numUpdated;
}
if (numUpdated==0)
{
//OSG_NOTICE<<"completed Update but no images updated"<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
}
else
{
//OSG_NOTICE<<"completed Updated "<<numUpdated<<std::endl;
}
}
bool update(UBrowserImage* image)
{
if (!image) return false;
double deltaTime = image->getTimeOfLastRender() - image->getTimeOfLastUpdate();
// OSG_NOTICE<<"deltaTime = "<<deltaTime<<std::endl;
// OSG_NOTICE<<" image->getTimeOfLastRender() = "<<image->getTimeOfLastRender()<<std::endl;
// OSG_NOTICE<<" image->getTimeOfLastUpdate() = "<<image->getTimeOfLastUpdate()<<std::endl;
if (deltaTime<0.0)
{
return false;
}
int id = image->getBrowserWindowId();
if (id==0)
{
int width = image->s();
int height = image->t();
OSG_INFO<<"Constructing browser window for first time, width = "<<width<<" height = "<<height<<std::endl;
id = LLMozLib::getInstance()->createBrowserWindow( width, height );
image->setBrowserWindowId(id);
// tell LLMozLib about the size of the browser window
LLMozLib::getInstance()->setSize( id, width, height );
// observer events that LLMozLib emits
LLMozLib::getInstance()->addObserver( id, image );
// don't flip bitmap
LLMozLib::getInstance()->flipWindow( id, false );
LLMozLib::getInstance()->navigateTo( id, image->getHomeURL() );
}
//if ( _needsUpdate )
{
// grab a page but don't reset 'needs update' flag until we've written it to the texture in display()
LLMozLib::getInstance()->grabBrowserWindow( id );
int width = LLMozLib::getInstance()->getBrowserRowSpan( id ) / LLMozLib::getInstance()->getBrowserDepth( id );
int height = LLMozLib::getInstance()->getBrowserHeight( id );
GLint internalFormat = LLMozLib::getInstance()->getBrowserDepth( id ) == 3 ? GL_RGB : GL_RGBA;
GLenum pixelFormat = LLMozLib::getInstance()->getBrowserDepth( id ) == 3 ? GL_BGR_EXT : GL_BGRA_EXT;
// OSG_NOTICE<<" doing image update "<<std::endl;
image->setImage(width,height,1, internalFormat, pixelFormat, GL_UNSIGNED_BYTE,
(unsigned char*)LLMozLib::getInstance()->getBrowserWindowPixels( id ),
osg::Image::NO_DELETE);
image->updated();
// _needsUpdate = false;
}
return true;
}
};
void UBrowserManager::init(const std::string& application)
{
if (_initialized) return;
_application = application;
setUpKeyMap();
_thread = new osg::OperationThread;
_thread->setParent(this);
osg::ref_ptr<osg::BarrierOperation> barrier = new osg::BarrierOperation(2,osg::BarrierOperation::NO_OPERATION, false);
_thread->startThread();
_thread->add(new InitOperation());
_thread->add(barrier.get());
_thread->add(new UpdateOperation());
// wait till the init has been run.
barrier->block();
_initialized = true;
}
void UBrowserManager::setUpKeyMap()
{
_keyMap[osgGA::GUIEventAdapter::KEY_BackSpace] = nsIDOMKeyEvent::DOM_VK_BACK_SPACE;
_keyMap[osgGA::GUIEventAdapter::KEY_Tab] = nsIDOMKeyEvent::DOM_VK_TAB;
_keyMap[osgGA::GUIEventAdapter::KEY_Linefeed] = nsIDOMKeyEvent::DOM_VK_ENTER;
_keyMap[osgGA::GUIEventAdapter::KEY_Clear] = nsIDOMKeyEvent::DOM_VK_CLEAR;
_keyMap[osgGA::GUIEventAdapter::KEY_Return] = nsIDOMKeyEvent::DOM_VK_RETURN;
_keyMap[osgGA::GUIEventAdapter::KEY_Pause] = nsIDOMKeyEvent::DOM_VK_PAUSE;
_keyMap[osgGA::GUIEventAdapter::KEY_Scroll_Lock] = nsIDOMKeyEvent::DOM_VK_SCROLL_LOCK;
_keyMap[osgGA::GUIEventAdapter::KEY_Escape] = nsIDOMKeyEvent::DOM_VK_ESCAPE;
_keyMap[osgGA::GUIEventAdapter::KEY_Delete] = nsIDOMKeyEvent::DOM_VK_DELETE;
/* Cursor control & motion */
_keyMap[osgGA::GUIEventAdapter::KEY_Home] = nsIDOMKeyEvent::DOM_VK_HOME;
_keyMap[osgGA::GUIEventAdapter::KEY_Left] = nsIDOMKeyEvent::DOM_VK_LEFT;
_keyMap[osgGA::GUIEventAdapter::KEY_Up] = nsIDOMKeyEvent::DOM_VK_UP;
_keyMap[osgGA::GUIEventAdapter::KEY_Right] = nsIDOMKeyEvent::DOM_VK_RIGHT;
_keyMap[osgGA::GUIEventAdapter::KEY_Down] = nsIDOMKeyEvent::DOM_VK_DOWN;
_keyMap[osgGA::GUIEventAdapter::KEY_Page_Up] = nsIDOMKeyEvent::DOM_VK_PAGE_UP;
_keyMap[osgGA::GUIEventAdapter::KEY_Page_Down] = nsIDOMKeyEvent::DOM_VK_PAGE_DOWN;
_keyMap[osgGA::GUIEventAdapter::KEY_End] = nsIDOMKeyEvent::DOM_VK_END;
/* Misc Functions */
_keyMap[osgGA::GUIEventAdapter::KEY_Print] = nsIDOMKeyEvent::DOM_VK_PRINTSCREEN;
_keyMap[osgGA::GUIEventAdapter::KEY_Insert] = nsIDOMKeyEvent::DOM_VK_INSERT;
_keyMap[osgGA::GUIEventAdapter::KEY_Cancel] = nsIDOMKeyEvent::DOM_VK_CANCEL;
_keyMap[osgGA::GUIEventAdapter::KEY_Num_Lock] = nsIDOMKeyEvent::DOM_VK_NUM_LOCK;
/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Space] = nsIDOMKeyEvent::DOM_VK_SPACE;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Tab] = nsIDOMKeyEvent::DOM_VK_TAB;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Enter] = nsIDOMKeyEvent::DOM_VK_ENTER;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Home] = nsIDOMKeyEvent::DOM_VK_HOME;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Left] = nsIDOMKeyEvent::DOM_VK_LEFT;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Up] = nsIDOMKeyEvent::DOM_VK_UP;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Right] = nsIDOMKeyEvent::DOM_VK_RIGHT;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Down] = nsIDOMKeyEvent::DOM_VK_DOWN;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Up] = nsIDOMKeyEvent::DOM_VK_PAGE_UP;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Page_Down] = nsIDOMKeyEvent::DOM_VK_PAGE_DOWN;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_End] = nsIDOMKeyEvent::DOM_VK_END;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Insert] = nsIDOMKeyEvent::DOM_VK_INSERT;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Delete] = nsIDOMKeyEvent::DOM_VK_DELETE;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Equal] = nsIDOMKeyEvent::DOM_VK_EQUALS;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Multiply] = nsIDOMKeyEvent::DOM_VK_MULTIPLY;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Add] = nsIDOMKeyEvent::DOM_VK_ADD;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Separator] = nsIDOMKeyEvent::DOM_VK_SEPARATOR;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Subtract] = nsIDOMKeyEvent::DOM_VK_SUBTRACT;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Decimal] = nsIDOMKeyEvent::DOM_VK_DECIMAL;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_Divide] = nsIDOMKeyEvent::DOM_VK_DIVIDE;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_0] = nsIDOMKeyEvent::DOM_VK_NUMPAD0;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_1] = nsIDOMKeyEvent::DOM_VK_NUMPAD1;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_2] = nsIDOMKeyEvent::DOM_VK_NUMPAD2;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_3] = nsIDOMKeyEvent::DOM_VK_NUMPAD3;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_4] = nsIDOMKeyEvent::DOM_VK_NUMPAD4;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_5] = nsIDOMKeyEvent::DOM_VK_NUMPAD5;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_6] = nsIDOMKeyEvent::DOM_VK_NUMPAD6;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_7] = nsIDOMKeyEvent::DOM_VK_NUMPAD7;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_8] = nsIDOMKeyEvent::DOM_VK_NUMPAD8;
_keyMap[osgGA::GUIEventAdapter::KEY_KP_9] = nsIDOMKeyEvent::DOM_VK_NUMPAD9;
/*
* Auxiliary Functions; note the duplicate definitions for left and right
* function keys; Sun keyboards and a few other manufactures have such
* function key groups on the left and/or right sides of the keyboard.
* We've not found a keyboard with more than 35 function keys total.
*/
_keyMap[osgGA::GUIEventAdapter::KEY_F1] = nsIDOMKeyEvent::DOM_VK_F1;
_keyMap[osgGA::GUIEventAdapter::KEY_F2] = nsIDOMKeyEvent::DOM_VK_F2;
_keyMap[osgGA::GUIEventAdapter::KEY_F3] = nsIDOMKeyEvent::DOM_VK_F3;
_keyMap[osgGA::GUIEventAdapter::KEY_F4] = nsIDOMKeyEvent::DOM_VK_F4;
_keyMap[osgGA::GUIEventAdapter::KEY_F5] = nsIDOMKeyEvent::DOM_VK_F5;
_keyMap[osgGA::GUIEventAdapter::KEY_F6] = nsIDOMKeyEvent::DOM_VK_F6;
_keyMap[osgGA::GUIEventAdapter::KEY_F7] = nsIDOMKeyEvent::DOM_VK_F7;
_keyMap[osgGA::GUIEventAdapter::KEY_F8] = nsIDOMKeyEvent::DOM_VK_F8;
_keyMap[osgGA::GUIEventAdapter::KEY_F9] = nsIDOMKeyEvent::DOM_VK_F9;
_keyMap[osgGA::GUIEventAdapter::KEY_F10] = nsIDOMKeyEvent::DOM_VK_F10;
_keyMap[osgGA::GUIEventAdapter::KEY_F11] = nsIDOMKeyEvent::DOM_VK_F12;
_keyMap[osgGA::GUIEventAdapter::KEY_F12] = nsIDOMKeyEvent::DOM_VK_F13;
_keyMap[osgGA::GUIEventAdapter::KEY_F13] = nsIDOMKeyEvent::DOM_VK_F13;
_keyMap[osgGA::GUIEventAdapter::KEY_F14] = nsIDOMKeyEvent::DOM_VK_F14;
_keyMap[osgGA::GUIEventAdapter::KEY_F15] = nsIDOMKeyEvent::DOM_VK_F15;
_keyMap[osgGA::GUIEventAdapter::KEY_F16] = nsIDOMKeyEvent::DOM_VK_F16;
_keyMap[osgGA::GUIEventAdapter::KEY_F17] = nsIDOMKeyEvent::DOM_VK_F17;
_keyMap[osgGA::GUIEventAdapter::KEY_F18] = nsIDOMKeyEvent::DOM_VK_F18;
_keyMap[osgGA::GUIEventAdapter::KEY_F19] = nsIDOMKeyEvent::DOM_VK_F19;
_keyMap[osgGA::GUIEventAdapter::KEY_F20] = nsIDOMKeyEvent::DOM_VK_F20;
_keyMap[osgGA::GUIEventAdapter::KEY_F21] = nsIDOMKeyEvent::DOM_VK_F21;
_keyMap[osgGA::GUIEventAdapter::KEY_F22] = nsIDOMKeyEvent::DOM_VK_F22;
_keyMap[osgGA::GUIEventAdapter::KEY_F23] = nsIDOMKeyEvent::DOM_VK_F23;
_keyMap[osgGA::GUIEventAdapter::KEY_F24] = nsIDOMKeyEvent::DOM_VK_F24;
/* Modifiers */
_keyMap[osgGA::GUIEventAdapter::KEY_Meta_L] = nsIDOMKeyEvent::DOM_VK_META;
_keyMap[osgGA::GUIEventAdapter::KEY_Meta_R] = nsIDOMKeyEvent::DOM_VK_META;
_keyMap[osgGA::GUIEventAdapter::KEY_Control_L] = nsIDOMKeyEvent::DOM_VK_CONTROL;
_keyMap[osgGA::GUIEventAdapter::KEY_Control_R] = nsIDOMKeyEvent::DOM_VK_CONTROL;
_keyMap[osgGA::GUIEventAdapter::KEY_Shift_L] = nsIDOMKeyEvent::DOM_VK_SHIFT;
_keyMap[osgGA::GUIEventAdapter::KEY_Shift_R] = nsIDOMKeyEvent::DOM_VK_SHIFT;
_keyMap[osgGA::GUIEventAdapter::KEY_Alt_R] = nsIDOMKeyEvent::DOM_VK_ALT;
_keyMap[osgGA::GUIEventAdapter::KEY_Alt_L] = nsIDOMKeyEvent::DOM_VK_ALT;
_keyMap[osgGA::GUIEventAdapter::KEY_Caps_Lock] = nsIDOMKeyEvent::DOM_VK_CAPS_LOCK;
}
int UBrowserManager::convertToXULKey(int key) const
{
KeyMap::const_iterator itr = _keyMap.find(key);
if (_keyMap.find(key)==_keyMap.end()) return key;
else return itr->second;
}
struct PointerEventOperation : public osg::Operation
{
PointerEventOperation(UBrowserImage* image, int x, int y, int buttonDelta):
osg::Operation("pointer event",false),
_image(image),
_x(x),
_y(y),
_buttonDelta(buttonDelta) {}
virtual void operator () (osg::Object* object)
{
int id = _image->getBrowserWindowId();
// send event to LLMozLib
if (_buttonDelta>0)
{
LLMozLib::getInstance()->mouseDown( id, _x, _y );
}
else if (_buttonDelta<0)
{
LLMozLib::getInstance()->mouseUp( id, _x, _y );
// this seems better than sending focus on mouse down (still need to improve this)
LLMozLib::getInstance()->focusBrowser( id, true );
}
else
{
// send event to LLMozLib
LLMozLib::getInstance()->mouseMove( id, _x, _y );
}
}
osg::ref_ptr<UBrowserImage> _image;
int _x;
int _y;
int _buttonDelta;
};
bool UBrowserManager::sendPointerEvent(UBrowserImage* image, int x, int y, int buttonMask)
{
int deltaButton = (buttonMask&1) - (_previousButtonMask&1);
_previousButtonMask = buttonMask;
_thread->add(new PointerEventOperation(image, x, y, deltaButton));
active(image);
return true;
}
struct KeyEventOperation : public osg::Operation
{
KeyEventOperation(UBrowserImage* image, int key, bool isUnicode):
osg::Operation("key event",false),
_image(image),
_key(key),
_isUnicode(isUnicode) {}
virtual void operator () (osg::Object* object)
{
int id = _image->getBrowserWindowId();
if (_isUnicode) LLMozLib::getInstance()->unicodeInput( id, _key );
else LLMozLib::getInstance()->keyPress( id, _key );
}
osg::ref_ptr<UBrowserImage> _image;
int _key;
bool _isUnicode;
};
bool UBrowserManager::sendKeyEvent(UBrowserImage* image, int key, bool keyDown)
{
if (!keyDown) return false;
KeyMap::const_iterator itr = _keyMap.find(key);
if (_keyMap.find(key)==_keyMap.end()) _thread->add(new KeyEventOperation(image, key, true));
else _thread->add(new KeyEventOperation(image, itr->second, false));
active(image);
return true;
}
struct NavigateToOperation : public osg::Operation
{
NavigateToOperation(UBrowserImage* image, const std::string& url):
osg::Operation("key event",false),
_image(image),
_url(url) {}
virtual void operator () (osg::Object* object)
{
int id = _image->getBrowserWindowId();
LLMozLib::getInstance()->navigateTo( id, _url );
}
osg::ref_ptr<UBrowserImage> _image;
std::string _url;
};
void UBrowserManager::navigateTo(UBrowserImage* image, const std::string& url)
{
_thread->add(new NavigateToOperation(image, url));
active(image);
}
void UBrowserManager::active(UBrowserImage* image)
{
}
////////////////////////////////////////////////////////////////////////////////////
//
// UBrowser implementation
UBrowserImage::UBrowserImage(UBrowserManager* manager, const std::string& homeURL, int width, int height):
_browserWindowId(0),
_needsUpdate(true),
_timeOfLastUpdate(0.0),
_timeOfLastRender(0.0)
{
_manager = manager;
GLint internalFormat = GL_RGB;
GLenum pixelFormat = GL_BGR_EXT;
setImage(width,height,1, internalFormat, pixelFormat, GL_UNSIGNED_BYTE,
0,
osg::Image::NO_DELETE);
setDataVariance(osg::Object::DYNAMIC);
setOrigin(osg::Image::TOP_LEFT);
_homeURL = homeURL;
manager->registerUBrowserImage(this);
}
UBrowserImage::~UBrowserImage()
{
_manager->unregisterUBrowserImage(this);
}
bool UBrowserImage::sendPointerEvent(int x, int y, int buttonMask)
{
return _manager->sendPointerEvent(this, x, y, buttonMask);
}
bool UBrowserImage::sendKeyEvent(int key, bool keyDown)
{
return _manager->sendKeyEvent(this, key, keyDown);
}
void UBrowserImage::setFrameLastRendered(const osg::FrameStamp*)
{
_timeOfLastRender = time();
_manager->active(this);
}
void UBrowserImage::updated()
{
_timeOfLastUpdate = time();
}
void UBrowserImage::navigateTo(const std::string& url)
{
_manager->navigateTo(this, url);
}

View File

@ -1,196 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* 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
* OpenSceneGraph Public License for more details.
*/
#ifndef UBROWSER_H
#define UBROWSER_H
#include <osgWidget/Browser>
#include <osg/OperationThread>
#include <osg/Timer>
#include <list>
#include <algorithm>
#include <nsGUIEvent.h>
#include "llmozlib2.h"
class UBrowserImage;
//////////////////////////////////////////////////////////////////////////
//
// UBrowserManager interface
//
class UBrowserManager : public osgWidget::BrowserManager
{
public:
UBrowserManager();
bool isInitialized() const { return _initialized; }
virtual void init(const std::string& application);
virtual osgWidget::BrowserImage* createBrowserImage(const std::string& url, int width, int height);
public:
void* getNativeWindowHandle();
void registerUBrowserImage(UBrowserImage* image)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_ubrowserImageListMutex);
_ubrowserImageList.push_back(image);
}
void unregisterUBrowserImage(UBrowserImage* image)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_ubrowserImageListMutex);
UBrowserImageList::iterator itr = std::find(_ubrowserImageList.begin(), _ubrowserImageList.end(), image);
if (itr != _ubrowserImageList.end()) _ubrowserImageList.erase(itr);
}
bool sendKeyEvent(UBrowserImage* image, int key, bool keyDown);
bool sendPointerEvent(UBrowserImage* image, int x, int y, int buttonMask);
void navigateTo(UBrowserImage* image, const std::string& page);
typedef std::list< UBrowserImage* > UBrowserImageList;
OpenThreads::Mutex _ubrowserImageListMutex;
UBrowserImageList _ubrowserImageList;
void active(UBrowserImage* image);
protected:
UBrowserManager(const UBrowserManager& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) {}
virtual ~UBrowserManager();
META_Object(osgWidget,UBrowserManager)
void setUpKeyMap();
int convertToXULKey(int key) const;
bool _initialized;
void* _nativeWindowHandle;
typedef std::map<int, int> KeyMap;
KeyMap _keyMap;
int _previousButtonMask;
osg::ref_ptr<osg::OperationThread> _thread;
};
////////////////////////////////////////////////////////////////////////////////////
//
// UBrowser interface
class UBrowserImage : public osgWidget::BrowserImage, public LLEmbeddedBrowserWindowObserver
{
public:
UBrowserImage(UBrowserManager* manager, const std::string& homeURL, int width, int height);
const std::string& getHomeURL() const { return _homeURL; }
virtual bool sendPointerEvent(int x, int y, int buttonMask);
virtual bool sendKeyEvent(int key, bool keyDown);
virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp);
virtual void navigateTo(const std::string& url);
////////////////////////////////////////////////////////////////////////////////
// virtual
void onPageChanged( const EventType& eventIn )
{
// flag that an update is required - page grab happens in idle() so we don't stall
OSG_NOTICE << "Event: onPageChanged " << eventIn.getEventUri() << std::endl;
_needsUpdate = true;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onNavigateBegin( const EventType& eventIn )
{
OSG_NOTICE << "Event: begin navigation to " << eventIn.getEventUri() << std::endl;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onNavigateComplete( const EventType& eventIn )
{
OSG_NOTICE << "Event: end navigation to " << eventIn.getEventUri() << " with response status of " << eventIn.getIntValue() << std::endl;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onUpdateProgress( const EventType& eventIn )
{
OSG_NOTICE << "Event: progress value updated to " << eventIn.getIntValue() << std::endl;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onStatusTextChange( const EventType& eventIn )
{
OSG_INFO << "Event: status updated to " << eventIn.getStringValue() << std::endl;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onLocationChange( const EventType& eventIn )
{
OSG_NOTICE << "Event: location changed to " << eventIn.getStringValue() << std::endl;
};
////////////////////////////////////////////////////////////////////////////////
// virtual
void onClickLinkHref( const EventType& eventIn )
{
OSG_NOTICE << "Event: clicked on link to " << eventIn.getStringValue() << std::endl;
};
void setBrowserWindowId(int id) { _browserWindowId = id; }
int getBrowserWindowId() const { return _browserWindowId; }
osg::ref_ptr<UBrowserManager> _manager;
void updated();
double getTimeOfLastUpdate() const { return _timeOfLastUpdate; }
double getTimeOfLastRender() const { return _timeOfLastRender; }
double time() const { return osg::Timer::instance()->time_s(); }
protected:
virtual ~UBrowserImage();
int _browserWindowId;
bool _needsUpdate;
std::string _homeURL;
double _timeOfLastUpdate;
double _timeOfLastRender;
};
#endif

View File

@ -1,450 +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 Linden Lab Inc. (http://lindenlab.com) code.
*
* The Initial Developer of the Original Code is:
* Callum Prentice (callum@ubrowser.com)
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Callum Prentice (callum@ubrowser.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 ***** */
// Windows specific switches
#ifdef WIN32
// appears to be required by LibXUL/Mozilla code to avoid crashes in debug versions of their code (undef'd at end of this file)
#ifdef _DEBUG
#define DEBUG 1
#endif
#endif // WIN32
#include <iostream>
#include "llembeddedbrowser.h"
#include "llembeddedbrowserwindow.h"
#ifdef WIN32
#pragma warning( disable : 4265 ) // "class has virtual functions, but destructor is not virtual"
#pragma warning( disable : 4291 ) // (no matching operator delete found; memory will not be freed if initialization throws an exception)
#endif // WIN32
#include "nsBuildID.h"
#include "nsICacheService.h"
#include "nsICookieManager.h"
#include "nsIPref.h"
#include "nsNetCID.h"
#include "nsProfileDirServiceProvider.h"
#include "nsXULAppAPI.h"
#include "nsIAppShell.h"
#include "nsIPromptService.h"
#include "time.h"
#include "nsWidgetsCID.h"
#include "nsNetCID.h"
static nsIAppShell *sAppShell = nsnull;
// singleton pattern - initialization
LLEmbeddedBrowser* LLEmbeddedBrowser::sInstance = 0;
////////////////////////////////////////////////////////////////////////////////
//
LLEmbeddedBrowser::LLEmbeddedBrowser() :
mNativeWindowHandle( 0 ),
mErrorNum( 0 )
{
}
////////////////////////////////////////////////////////////////////////////////
//
LLEmbeddedBrowser::~LLEmbeddedBrowser()
{
}
////////////////////////////////////////////////////////////////////////////////
//
LLEmbeddedBrowser* LLEmbeddedBrowser::getInstance()
{
if ( ! sInstance )
{
sInstance = new LLEmbeddedBrowser;
}
return sInstance;
}
////////////////////////////////////////////////////////////////////////////////
//
void LLEmbeddedBrowser::setLastError( int errorNumIn )
{
mErrorNum = errorNumIn;
}
////////////////////////////////////////////////////////////////////////////////
//
void LLEmbeddedBrowser::clearLastError()
{
mErrorNum = 0x0000;
}
////////////////////////////////////////////////////////////////////////////////
//
int LLEmbeddedBrowser::getLastError()
{
return mErrorNum;
}
////////////////////////////////////////////////////////////////////////////////
//
std::string LLEmbeddedBrowser::getGREVersion()
{
// take the string directly from Mozilla
return std::string( GRE_BUILD_ID );
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::init( std::string applicationDir,
std::string componentDir,
std::string profileDir,
void* nativeWindowHandleIn )
{
mNativeWindowHandle = nativeWindowHandleIn;
NS_ConvertUTF8toUTF16 applicationDirUTF16(applicationDir.c_str());
NS_ConvertUTF8toUTF16 componentDirUTF16(componentDir.c_str());
NS_ConvertUTF8toUTF16 profileDirUTF16(profileDir.c_str());
nsCOMPtr< nsILocalFile > applicationDirNative;
nsresult result = NS_NewLocalFile( applicationDirUTF16, PR_FALSE, getter_AddRefs( applicationDirNative ) );
if ( NS_FAILED( result ) )
{
setLastError( 0x1000 );
return false;
};
nsCOMPtr< nsILocalFile > componentDirNative;
result = NS_NewLocalFile( componentDirUTF16 , PR_FALSE, getter_AddRefs( componentDirNative ) );
if ( NS_FAILED( result ) )
{
setLastError( 0x1001 );
return false;
};
result = XRE_InitEmbedding( componentDirNative, applicationDirNative, nsnull, nsnull, 0 );
if ( NS_FAILED( result ) )
{
setLastError( 0x1002 );
return false;
};
nsCOMPtr< nsILocalFile > profileDirNative;
result = NS_NewLocalFile( profileDirUTF16 , PR_TRUE, getter_AddRefs( profileDirNative ) );
if ( NS_FAILED( result ) )
{
setLastError( 0x1007 );
return false;
};
nsCOMPtr< nsProfileDirServiceProvider > locProvider;
NS_NewProfileDirServiceProvider( PR_TRUE, getter_AddRefs( locProvider ) );
if ( ! locProvider )
{
setLastError( 0x1003 );
XRE_TermEmbedding();
return PR_FALSE;
};
result = locProvider->Register();
if ( NS_FAILED( result ) )
{
setLastError( 0x1004 );
XRE_TermEmbedding();
return PR_FALSE;
};
result = locProvider->SetProfileDir( profileDirNative );
if ( NS_FAILED( result ) )
{
setLastError( 0x1005 );
XRE_TermEmbedding();
return PR_FALSE;
};
nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID );
if ( pref )
{
pref->SetBoolPref( "security.warn_entering_secure", PR_FALSE );
pref->SetBoolPref( "security.warn_entering_weak", PR_FALSE );
pref->SetBoolPref( "security.warn_leaving_secure", PR_FALSE );
pref->SetBoolPref( "security.warn_submit_insecure", PR_FALSE );
pref->SetBoolPref( "network.protocol-handler.warn-external-default", PR_FALSE );
}
else
{
setLastError( 0x1006 );
};
// disable proxy by default
enableProxy( false, "", 0 );
// Originally from Linux version but seems to help other platforms too
nsresult rv;
nsCOMPtr<nsIAppShell> appShell;
NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
appShell = do_CreateInstance(kAppShellCID, &rv);
if (!appShell)
{
setLastError( 0x1008 );
return PR_FALSE;
}
sAppShell = appShell.get();
NS_ADDREF(sAppShell);
sAppShell->Create(0, nsnull);
sAppShell->Spinup();
clearLastError();
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::reset()
{
XRE_TermEmbedding();
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::clearCache()
{
nsCOMPtr< nsICacheService > cacheService = do_GetService( NS_CACHESERVICE_CONTRACTID );
if (! cacheService)
return false;
cacheService->EvictEntries( nsICache::STORE_ANYWHERE );
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn )
{
nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID );
if ( pref )
{
if ( proxyEnabledIn )
pref->SetIntPref( "network.proxy.type", 1 );
else
pref->SetIntPref( "network.proxy.type", 0 );
pref->SetCharPref( "network.proxy.ssl", proxyHostNameIn.c_str() );
pref->SetIntPref( "network.proxy.ssl_port", proxyPortIn );
pref->SetCharPref( "network.proxy.ftp", proxyHostNameIn.c_str() );
pref->SetIntPref( "network.proxy.ftp_port", proxyPortIn );
pref->SetCharPref( "network.proxy.gopher", proxyHostNameIn.c_str() );
pref->SetIntPref( "network.proxy.gopher_port", proxyPortIn );
pref->SetCharPref( "network.proxy.http", proxyHostNameIn.c_str() );
pref->SetIntPref( "network.proxy.http_port", proxyPortIn );
pref->SetBoolPref( "network.proxy.share_proxy_settings", true );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::enableCookies( bool enabledIn )
{
nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID );
if ( pref )
{
if ( enabledIn )
pref->SetIntPref( "network.cookie.cookieBehavior", 0 );
else
pref->SetIntPref( "network.cookie.cookieBehavior", 2 );
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::clearAllCookies()
{
nsCOMPtr< nsICookieManager > cookieManager = do_GetService( NS_COOKIEMANAGER_CONTRACTID );
if ( ! cookieManager )
return false;
cookieManager->RemoveAll();
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::enablePlugins( bool enabledIn )
{
nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID );
if ( pref )
{
if ( enabledIn )
{
pref->SetBoolPref( "plugin.scan.plid.all", PR_TRUE );
pref->SetBoolPref( "xpinstall-enabled", PR_TRUE );
}
else
{
pref->SetBoolPref( "plugin.scan.plid.all", PR_FALSE );
pref->SetBoolPref( "xpinstall-enabled", PR_FALSE );
pref->SetBoolPref( "plugin.scan.4xPluginFolder", PR_FALSE );
pref->SetCharPref( "plugin.scan.Quicktime", "20.0" );
pref->SetCharPref( "plugin.scan.Acrobat", "99.0" );
pref->SetCharPref( "plugin.scan.SunJRE", "99.0" );
pref->SetCharPref( "plugin.scan.WindowsMediaPlayer", "99.0" );
};
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
void LLEmbeddedBrowser::setBrowserAgentId( std::string idIn )
{
nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID );
if ( pref )
{
pref->SetCharPref( "general.useragent.extra.* ", idIn.c_str() );
};
}
////////////////////////////////////////////////////////////////////////////////
//
LLEmbeddedBrowserWindow* LLEmbeddedBrowser::createBrowserWindow( int browserWidthIn, int browserHeightIn )
{
nsCOMPtr< nsIWebBrowserChrome > chrome;
LLEmbeddedBrowserWindow* newWin = new LLEmbeddedBrowserWindow();
if ( ! newWin )
{
return 0;
};
nsIWebBrowserChrome** aNewWindow = getter_AddRefs( chrome );
CallQueryInterface( NS_STATIC_CAST( nsIWebBrowserChrome*, newWin ), aNewWindow );
NS_ADDREF( *aNewWindow );
newWin->SetChromeFlags( nsIWebBrowserChrome::CHROME_ALL );
nsCOMPtr< nsIWebBrowser > newBrowser;
newWin->createBrowser( mNativeWindowHandle, browserWidthIn, browserHeightIn, getter_AddRefs( newBrowser ) );
if ( ! newBrowser )
{
return 0;
};
if ( newWin && chrome )
{
newWin->setParent( this );
nsCOMPtr< nsIWebBrowser > newBrowser;
chrome->GetWebBrowser( getter_AddRefs( newBrowser ) );
nsCOMPtr< nsIWebNavigation > webNav( do_QueryInterface ( newBrowser ) );
webNav->LoadURI( NS_ConvertUTF8toUTF16( "about:blank" ).get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull );
clearLastError();
return newWin;
};
setLastError( 0x2001 );
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLEmbeddedBrowser::destroyBrowserWindow( LLEmbeddedBrowserWindow* browserWindowIn )
{
nsCOMPtr< nsIWebBrowser > webBrowser;
nsCOMPtr< nsIWebNavigation > webNavigation;
browserWindowIn->GetWebBrowser( getter_AddRefs( webBrowser ) );
webNavigation = do_QueryInterface( webBrowser );
if ( webNavigation )
{
webNavigation->Stop( nsIWebNavigation::STOP_ALL );
};
nsCOMPtr< nsIWebBrowser > browser = nsnull;
browserWindowIn->GetWebBrowser( getter_AddRefs( browser ) );
nsCOMPtr< nsIBaseWindow > browserAsWin = do_QueryInterface( browser );
if ( browserAsWin )
{
browserAsWin->Destroy();
};
browserWindowIn->SetWebBrowser( nsnull );
NS_RELEASE( browserWindowIn );
delete browserWindowIn;
clearLastError();
return true;
}
// Windows specific switches
#ifdef WIN32
#pragma warning( 3 : 4291 ) // (no matching operator delete found; memory will not be freed if initialization throws an exception)
#pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual"
// #define required by this file for LibXUL/Mozilla code to avoid crashes in their debug code
#ifdef _DEBUG
#undef DEBUG
#endif
#endif // WIN32

View File

@ -1,78 +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 Linden Lab Inc. (http://lindenlab.com) code.
*
* The Initial Developer of the Original Code is:
* Callum Prentice (callum@ubrowser.com)
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Callum Prentice (callum@ubrowser.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 ***** */
#ifndef LLEMBEDDEDBROWSER_H
#define LLEMBEDDEDBROWSER_H
#include <string>
#include <map>
class LLEmbeddedBrowserWindow;
class LLEmbeddedBrowserWindowObserver;
class LLEmbeddedBrowser
{
public:
LLEmbeddedBrowser();
virtual ~LLEmbeddedBrowser();
static LLEmbeddedBrowser* getInstance();
bool init( std::string applicationDir, std::string componentDir, std::string profileDir, void* nativeWindowHandleIn );
bool reset();
bool clearCache();
bool enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn );
bool enableCookies( bool enabledIn );
bool clearAllCookies();
bool enablePlugins( bool enabledIn );
std::string getGREVersion();
void setBrowserAgentId( std::string idIn );
LLEmbeddedBrowserWindow* createBrowserWindow( int browserWidthIn, int browserHeightIn );
bool destroyBrowserWindow( LLEmbeddedBrowserWindow* browserWindowIn );
void setLastError( int errorNumIn );
void clearLastError();
int getLastError();
private:
static LLEmbeddedBrowser* sInstance;
void* mNativeWindowHandle;
int mErrorNum;
};
#endif // LLEMBEDDEDBROWSER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,264 +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 Linden Lab Inc. (http://lindenlab.com) code.
*
* The Initial Developer of the Original Code is:
* Callum Prentice (callum@ubrowser.com)
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Callum Prentice (callum@ubrowser.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 ***** */
#ifndef LLEMBEDDEDBROWSERWINDOW_H
#define LLEMBEDDEDBROWSERWINDOW_H
// Mozilla code has non-virtual destructors
#ifdef WIN32
#pragma warning( disable : 4265 ) // "class has virtual functions, but destructor is not virtual"
#endif
#include "nsIBaseWindow.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgressListener.h"
#include "nsIURIContentListener.h"
#include "nsWeakReference.h"
#include "nsIWebBrowser.h"
#include "nsIToolkit.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptContext.h"
#ifdef WIN32
#pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual"
#endif
#include <string>
#include <list>
#include <algorithm>
#include "llmozlib2.h"
///////////////////////////////////////////////////////////////////////////////
// manages the process of storing and emitting events that the consumer
// of the embedding class can observe
template< class T >
class LLEmbeddedBrowserWindowEmitter
{
public:
LLEmbeddedBrowserWindowEmitter() { };
~LLEmbeddedBrowserWindowEmitter() { };
typedef typename T::EventType EventType;
typedef std::list< T* > ObserverContainer;
typedef void( T::*observerMethod )( const EventType& );
///////////////////////////////////////////////////////////////////////////////
//
bool addObserver( T* observerIn )
{
if ( ! observerIn )
return false;
if ( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
return false;
observers.push_back( observerIn );
return true;
};
///////////////////////////////////////////////////////////////////////////////
//
bool remObserver( T* observerIn )
{
if ( ! observerIn )
return false;
observers.remove( observerIn );
return true;
};
///////////////////////////////////////////////////////////////////////////////
//
void update( observerMethod method, const EventType& msgIn )
{
typename std::list< T* >::iterator iter = observers.begin();
while( iter != observers.end() )
{
( ( *iter )->*method )( msgIn );
++iter;
};
};
protected:
ObserverContainer observers;
};
class LLEmbeddedBrowser;
////////////////////////////////////////////////////////////////////////////////
// class for a "window" that holds a browser - there can be lots of these
class LLEmbeddedBrowserWindow :
public nsIInterfaceRequestor,
public nsIWebBrowserChrome,
public nsIWebProgressListener,
public nsIURIContentListener,
#ifdef SUPPORTS_WEAK_REFENCE
public nsSupportsWeakReference,
#endif
#ifdef NS_DECL_NSITOOLKITOBSERVER
public nsIToolkitObserver,
#endif
public nsIDOMEventListener
{
public:
LLEmbeddedBrowserWindow();
virtual ~LLEmbeddedBrowserWindow();
NS_DECL_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIDOMEVENTLISTENER
#ifdef NS_DECL_NSITOOLKITOBSERVER
NS_DECL_NSITOOLKITOBSERVER
#endif
// housekeeping
nsresult createBrowser( void* nativeWindowHandleIn, PRInt32 widthIn, PRInt32 heightIn, nsIWebBrowser** aBrowser );
void setParent( LLEmbeddedBrowser* parentIn ) { mParent = parentIn; };
PRBool setSize( PRInt16 widthIn, PRInt16 heightIn );
void focusBrowser( PRBool focusBrowserIn );
void scrollByLines( PRInt16 linesIn );
void setWindowId( int windowIdIn );
int getWindowId();
NS_METHOD NotifyInvalidated(nsIWidget*, PRInt32, PRInt32, PRInt32, PRInt32);
// random accessors
const PRInt16 getPercentComplete();
const std::string& getStatusMsg();
const std::string& getCurrentUri();
const std::string& getClickLinkHref();
const std::string& getClickLinkTarget();
// memory buffer management
unsigned char* grabWindow( int xIn, int yIn, int widthIn, int heightIn );
PRBool flipWindow( PRBool flip );
unsigned char* getPageBuffer();
PRInt16 getBrowserWidth();
PRInt16 getBrowserHeight();
PRInt16 getBrowserDepth();
PRInt32 getBrowserRowSpan();
// set background color that you see in between pages - default is white but sometimes useful to change
void setBackgroundColor( const PRUint8 redIn, const PRUint8 greenIn, const PRUint8 blueIn );
// change the caret color (we have different backgrounds to edit fields - black caret on black background == bad)
void setCaretColor( const PRUint8 redIn, const PRUint8 greenIn, const PRUint8 blueIn );
// can turn off updates to a page - e.g. when it's hidden by your windowing system
void setEnabled( PRBool enabledIn );
// navigation
void navigateStop();
PRBool navigateTo( const std::string uriIn );
PRBool canNavigateBack();
void navigateBack();
PRBool canNavigateForward();
void navigateForward();
void navigateReload();
// javascript access/control
std::string evaluateJavascript( std::string scriptIn );
// redirection when you hit a missing page
bool set404RedirectUrl( std::string redirect_url );
bool clr404RedirectUrl();
// mouse & keyboard events
void mouseDown( PRInt16 xPosIn, PRInt16 yPosIn );
void mouseUp( PRInt16 xPosIn, PRInt16 yPosIn );
void mouseMove( PRInt16 xPosIn, PRInt16 yPosIn );
void mouseLeftDoubleClick( PRInt16 xPosIn, PRInt16 yPosIn );
void keyPress( PRInt16 keyCode );
void unicodeInput( PRUint32 uni_char );
// allow consumers of this class and to observe browser events
bool addObserver( LLEmbeddedBrowserWindowObserver* observerIn );
bool remObserver( LLEmbeddedBrowserWindowObserver* observerIn );
// accessor/mutator for scheme that browser doesn't follow - e.g. secondlife.com://
void setNoFollowScheme( std::string schemeIn );
std::string getNoFollowScheme();
private:
PRBool sendMozillaMouseEvent( PRInt16 eventIn, PRInt16 xPosIn, PRInt16 yPosIn, PRUint32 clickCountIn );
PRBool sendMozillaKeyboardEvent( PRUint32 keyIn, PRUint32 ns_vk_code );
PRBool renderCaret();
PRBool enableToolkitObserver( PRBool enableIn );
LLEmbeddedBrowserWindowEmitter< LLEmbeddedBrowserWindowObserver > mEventEmitter;
LLEmbeddedBrowser* mParent;
PRInt16 mPercentComplete;
std::string mStatusText;
std::string mCurrentUri;
std::string mClickHref;
std::string mClickTarget;
std::string mNoFollowScheme;
nsCOMPtr< nsIWebBrowser > mWebBrowser;
nsCOMPtr< nsIBaseWindow > mBaseWindow;
nsCOMPtr< nsIWebNavigation > mWebNav;
int mWindowId;
unsigned char* mPageBuffer;
std::string m404RedirectUrl;
PRBool mEnabled;
PRBool mFlipBitmap;
PRInt32 mBrowserRowSpan;
PRInt16 mBrowserWidth;
PRInt16 mBrowserHeight;
PRInt16 mBrowserDepth;
PRUint8 mBkgRed;
PRUint8 mBkgGreen;
PRUint8 mBkgBlue;
PRUint8 mCaretRed;
PRUint8 mCaretGreen;
PRUint8 mCaretBlue;
};
#endif // LLEMBEDEDDBROWSERWINDOW_H

View File

@ -1,686 +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 Linden Lab Inc. (http://lindenlab.com) code.
*
* The Initial Developer of the Original Code is:
* Callum Prentice (callum@ubrowser.com)
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Callum Prentice (callum@ubrowser.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 <sstream>
#include <iostream>
#include <iomanip>
#include <time.h>
#include "llmozlib2.h"
#include "llembeddedbrowser.h"
#include "llembeddedbrowserwindow.h"
LLMozLib* LLMozLib::sInstance = 0;
////////////////////////////////////////////////////////////////////////////////
//
LLMozLib::LLMozLib() :
mMaxBrowserWindows( 16 )
{
}
////////////////////////////////////////////////////////////////////////////////
//
LLMozLib* LLMozLib::getInstance()
{
if ( ! sInstance )
{
sInstance = new LLMozLib;
};
return sInstance;
}
////////////////////////////////////////////////////////////////////////////////
//
LLMozLib::~LLMozLib()
{
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::init( std::string applicationDir, std::string componentDir, std::string profileDir, void* nativeWindowHandleIn )
{
return LLEmbeddedBrowser::getInstance()->init( applicationDir,
componentDir,
profileDir,
nativeWindowHandleIn );
}
////////////////////////////////////////////////////////////////////////////////
//
int LLMozLib::getLastError()
{
return LLEmbeddedBrowser::getInstance()->getLastError();
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::reset()
{
return LLEmbeddedBrowser::getInstance()->reset();
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::clearCache()
{
return LLEmbeddedBrowser::getInstance()->clearCache();
}
////////////////////////////////////////////////////////////////////////////////
//
const std::string LLMozLib::getVersion()
{
const int majorVersion = 2;
const int minorVersion = 1;
// number of hours since "time began" for this library - used to identify builds of same version
const int magicNumber = static_cast< int >( ( time( NULL ) / 3600L ) - ( 321190L ) );
// return as a string for now - don't think we need to expose actual version numbers
std::ostringstream codec;
codec << std::setw( 1 ) << std::setfill( '0' );
codec << majorVersion << ".";
codec << std::setw( 2 ) << std::setfill( '0' );
codec << minorVersion << ".";
codec << std::setw( 5 ) << std::setfill( '0' );
codec << magicNumber;
codec << " (Mozilla GRE version ";
codec << LLEmbeddedBrowser::getInstance()->getGREVersion();
codec << ")";
return codec.str();
}
////////////////////////////////////////////////////////////////////////////////
//
void LLMozLib::setBrowserAgentId( std::string idIn )
{
LLEmbeddedBrowser::getInstance()->setBrowserAgentId( idIn );
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn )
{
return LLEmbeddedBrowser::getInstance()->enableProxy( proxyEnabledIn, proxyHostNameIn, proxyPortIn );
}
////////////////////////////////////////////////////////////////////////////////
//
int LLMozLib::createBrowserWindow( int browserWindowWidthIn, int browserWindowHeightIn )
{
LLEmbeddedBrowserWindow* browserWindow = LLEmbeddedBrowser::getInstance()->createBrowserWindow( browserWindowWidthIn, browserWindowHeightIn );
if ( browserWindow )
{
// arbitrary limit so we don't exhaust system resources
int id( 0 );
while ( ++id < mMaxBrowserWindows )
{
std::pair< BrowserWindowMapIter, bool > result = mBrowserWindowMap.insert( std::make_pair( id, browserWindow ) );
// find first place the insert succeeds and use that index as the id
if ( result.second )
{
browserWindow->setWindowId( id );
return id;
};
};
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::destroyBrowserWindow( int browserWindowIdIn )
{
// don't use the utility method here since we need the iterator to remove the entry from the map
BrowserWindowMapIter iter = mBrowserWindowMap.find( browserWindowIdIn );
LLEmbeddedBrowserWindow* browserWindow = (*iter).second;
if ( browserWindow )
{
LLEmbeddedBrowser::getInstance()->destroyBrowserWindow( browserWindow );
};
mBrowserWindowMap.erase( iter );
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::setBackgroundColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->setBackgroundColor( redIn, greenIn, blueIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::setCaretColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->setCaretColor( redIn, greenIn, blueIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::setEnabled( int browserWindowIdIn, bool enabledIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->setEnabled( enabledIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::setSize( int browserWindowIdIn, int widthIn, int heightIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->setSize( widthIn, heightIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::scrollByLines( int browserWindowIdIn, int linesIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->scrollByLines( linesIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::addObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->addObserver( subjectIn );
};
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::remObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->remObserver( subjectIn );
};
return true;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::navigateTo( int browserWindowIdIn, const std::string uriIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->navigateTo( uriIn ) ? true : false;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::navigateStop( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->navigateStop();
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::canNavigateBack( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->canNavigateBack() ? true : false;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::navigateBack( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->navigateBack();
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::canNavigateForward( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->canNavigateForward() ? true : false;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::navigateForward( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->navigateForward();
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::navigateReload( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->navigateReload();
return true;
};
return false;
}
///////////////////////////////////////////////////////////////////////////////
//
const unsigned char* LLMozLib::grabBrowserWindow( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->grabWindow( 0, 0, getBrowserWidth( browserWindowIdIn ), getBrowserHeight( browserWindowIdIn ) );
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
const unsigned char* LLMozLib::getBrowserWindowPixels( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getPageBuffer();
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
const bool LLMozLib::flipWindow( int browserWindowIdIn, bool flipIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->flipWindow( flipIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
const int LLMozLib::getBrowserWidth( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getBrowserWidth();
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
const int LLMozLib::getBrowserHeight( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getBrowserHeight();
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
const int LLMozLib::getBrowserDepth( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getBrowserDepth();
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
const int LLMozLib::getBrowserRowSpan( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getBrowserRowSpan();
};
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::mouseDown( int browserWindowIdIn, int xPosIn, int yPosIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->mouseDown( xPosIn, yPosIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::mouseUp( int browserWindowIdIn, int xPosIn, int yPosIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->mouseUp( xPosIn, yPosIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::mouseMove( int browserWindowIdIn, int xPosIn, int yPosIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->mouseMove( xPosIn, yPosIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::mouseLeftDoubleClick( int browserWindowIdIn, int xPosIn, int yPosIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->mouseLeftDoubleClick( xPosIn, yPosIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::keyPress( int browserWindowIdIn, int keyCodeIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->keyPress( keyCodeIn );
return true;
};
return false;
}
bool LLMozLib::unicodeInput( int browserWindowIdIn, unsigned long uni_char )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->unicodeInput( uni_char );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::focusBrowser( int browserWindowIdIn, bool focusBrowserIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->focusBrowser( focusBrowserIn );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
void LLMozLib::setNoFollowScheme( int browserWindowIdIn, std::string schemeIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
browserWindow->setNoFollowScheme( schemeIn );
};
}
////////////////////////////////////////////////////////////////////////////////
//
std::string LLMozLib::getNoFollowScheme( int browserWindowIdIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->getNoFollowScheme();
};
return ( "" );
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::enableCookies( bool enabledIn )
{
return LLEmbeddedBrowser::getInstance()->enableCookies( enabledIn );
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::clearAllCookies()
{
return LLEmbeddedBrowser::getInstance()->clearAllCookies();
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::enablePlugins( bool enabledIn )
{
return LLEmbeddedBrowser::getInstance()->enablePlugins( enabledIn );
}
////////////////////////////////////////////////////////////////////////////////
//
std::string LLMozLib::evaluateJavascript( int browserWindowIdIn, const std::string scriptIn )
{
LLEmbeddedBrowserWindow* browserWindow = getBrowserWindowFromWindowId( browserWindowIdIn );
if ( browserWindow )
{
return browserWindow->evaluateJavascript( scriptIn );
};
return "";
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::set404RedirectUrl( int browser_window_in, std::string redirect_url )
{
LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId( browser_window_in );
if ( browser_window )
{
browser_window->set404RedirectUrl( redirect_url );
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLMozLib::clr404RedirectUrl( int browser_window_in )
{
LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId( browser_window_in );
if ( browser_window )
{
browser_window->clr404RedirectUrl();
return true;
};
return false;
}
////////////////////////////////////////////////////////////////////////////////
// utility method to get an LLEmbeddedBrowserWindow* from a window id (int)
LLEmbeddedBrowserWindow* LLMozLib::getBrowserWindowFromWindowId( int browserWindowIdIn )
{
BrowserWindowMapIter iter = mBrowserWindowMap.find( browserWindowIdIn );
if ( iter != mBrowserWindowMap.end() )
return ( *iter ).second;
else
return 0;
}

View File

@ -1,384 +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 Linden Lab Inc. (http://lindenlab.com) code.
*
* The Initial Developer of the Original Code is:
* Callum Prentice (callum@ubrowser.com)
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Callum Prentice (callum@ubrowser.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 ***** */
#ifndef LLMOZLIB_H
#define LLMOZLIB_H
#include <string>
#include <map>
class LLEmbeddedBrowser;
class LLEmbeddedBrowserWindow;
////////////////////////////////////////////////////////////////////////////////
// data class that is passed with an event
class LLEmbeddedBrowserWindowEvent
{
public:
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn )
{
};
// single int passed with the event - e.g. progress
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, int intValIn ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn ),
mIntVal( intValIn )
{
};
// string passed with the event
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn ),
mStringVal( stringValIn )
{
};
// 2 strings passed with the event
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn, std::string stringVal2In ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn ),
mStringVal( stringValIn ),
mStringVal2( stringVal2In )
{
};
// string and an int passed with the event
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn, int intValIn ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn ),
mIntVal( intValIn ),
mStringVal( stringValIn )
{
};
// 4 ints passed (semantically as a rectangle but could be anything - didn't want to make a RECT type structure)
LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, int xIn, int yIn, int widthIn, int heightIn ) :
mEventWindowId( eventWindowIdIn ),
mEventUri( uriIn ),
mXVal( xIn ),
mYVal( yIn ),
mWidthVal( widthIn ),
mHeightVal( heightIn )
{
};
virtual ~LLEmbeddedBrowserWindowEvent()
{
};
int getEventWindowId() const
{
return mEventWindowId;
};
std::string getEventUri() const
{
return mEventUri;
};
int getIntValue() const
{
return mIntVal;
};
std::string getStringValue() const
{
return mStringVal;
};
std::string getStringValue2() const
{
return mStringVal2;
};
void getRectValue( int& xOut, int& yOut, int& widthOut, int& heightOut ) const
{
xOut = mXVal;
yOut = mYVal;
widthOut = mWidthVal;
heightOut = mHeightVal;
};
private:
int mEventWindowId;
std::string mEventUri;
int mIntVal;
std::string mStringVal;
std::string mStringVal2;
int mXVal;
int mYVal;
int mWidthVal;
int mHeightVal;
};
////////////////////////////////////////////////////////////////////////////////
// derrive from this class and override these methods to observe these events
class LLEmbeddedBrowserWindowObserver
{
public:
virtual ~LLEmbeddedBrowserWindowObserver() { };
typedef LLEmbeddedBrowserWindowEvent EventType;
virtual void onPageChanged( const EventType& eventIn ) { };
virtual void onNavigateBegin( const EventType& eventIn ) { };
virtual void onNavigateComplete( const EventType& eventIn ) { };
virtual void onUpdateProgress( const EventType& eventIn ) { };
virtual void onStatusTextChange( const EventType& eventIn ) { };
virtual void onLocationChange( const EventType& eventIn ) { };
virtual void onClickLinkHref( const EventType& eventIn ) { };
virtual void onClickLinkNoFollow( const EventType& eventIn ) { };
};
////////////////////////////////////////////////////////////////////////////////
// main library class
class LLMozLib
{
public:
virtual ~LLMozLib();
// singleton access
static LLMozLib* getInstance();
// housekeeping
bool init( std::string applicationDir, std::string componentDir, std::string profileDir, void* nativeWindowHandleIn );
bool reset();
bool clearCache();
int getLastError();
const std::string getVersion();
void setBrowserAgentId( std::string idIn );
bool enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn );
bool enableCookies( bool enabledIn );
bool clearAllCookies();
bool enablePlugins( bool enabledIn );
// browser window - creation/deletion, mutation etc.
int createBrowserWindow( int browserWindowWidthIn, int browserWindowHeightIn );
bool destroyBrowserWindow( int browserWindowIdIn );
bool setSize( int browserWindowIdIn, int widthIn, int heightIn );
bool scrollByLines( int browserWindowIdIn, int linesIn );
bool setBackgroundColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn );
bool setCaretColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn );
bool setEnabled( int browserWindowIdIn, bool enabledIn );
// add/remove yourself as an observer on browser events - see LLEmbeddedBrowserWindowObserver declaration
bool addObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn );
bool remObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn );
// navigation - self explanatory
bool navigateTo( int browserWindowIdIn, const std::string uriIn );
bool navigateStop( int browserWindowIdIn );
bool canNavigateBack( int browserWindowIdIn );
bool navigateBack( int browserWindowIdIn );
bool canNavigateForward( int browserWindowIdIn );
bool navigateForward( int browserWindowIdIn );
bool navigateReload( int browserWindowIdIn );
// javascript access/control
std::string evaluateJavascript( int browserWindowIdIn, const std::string scriptIn );
// set/clear URL to redirect to when a 404 page is reached
bool set404RedirectUrl( int browser_window_in, std::string redirect_url );
bool clr404RedirectUrl( int browser_window_in );
// access to rendered bitmap data
const unsigned char* grabBrowserWindow( int browserWindowIdIn ); // renders page to memory and returns pixels
const unsigned char* getBrowserWindowPixels( int browserWindowIdIn ); // just returns pixels - no render
const bool flipWindow( int browserWindowIdIn, bool flipIn ); // optionally flip window (pixels) you get back
const int getBrowserWidth( int browserWindowIdIn ); // current browser width (can vary slightly after page is rendered)
const int getBrowserHeight( int browserWindowIdIn ); // current height
const int getBrowserDepth( int browserWindowIdIn ); // depth in bytes
const int getBrowserRowSpan( int browserWindowIdIn ); // width in pixels * depth in bytes
// mouse/keyboard interaction
bool mouseDown( int browserWindowIdIn, int xPosIn, int yPosIn ); // send a mouse down event to a browser window at given XY in browser space
bool mouseUp( int browserWindowIdIn, int xPosIn, int yPosIn ); // send a mouse up event to a browser window at given XY in browser space
bool mouseMove( int browserWindowIdIn, int xPosIn, int yPosIn ); // send a mouse move event to a browser window at given XY in browser space
bool mouseLeftDoubleClick( int browserWindowIdIn, int xPosIn, int yPosIn ); // send a mouse left button double click to a browser window at given XY in browser space
bool keyPress( int browserWindowIdIn, int keyCodeIn ); // send a key press event to a browser window
bool unicodeInput ( int browserWindowIdIn, unsigned long uni_char ); // send a unicode keypress event to a browser window
bool focusBrowser( int browserWindowIdIn, bool focusBrowserIn ); // set/remove focus to given browser window
// accessor/mutator for scheme that browser doesn't follow - e.g. secondlife.com://
void setNoFollowScheme( int browserWindowIdIn, std::string schemeIn );
std::string getNoFollowScheme( int browserWindowIdIn );
private:
LLMozLib();
LLEmbeddedBrowserWindow* getBrowserWindowFromWindowId( int browserWindowIdIn );
static LLMozLib* sInstance;
const int mMaxBrowserWindows;
typedef std::map< int, LLEmbeddedBrowserWindow* > BrowserWindowMap;
typedef std::map< int, LLEmbeddedBrowserWindow* >::iterator BrowserWindowMapIter;
BrowserWindowMap mBrowserWindowMap;
};
// Mozilla virtual keycodes.
// We don't want to suck in Mozilla headers so we copy these consts
// from nsIDOMKeyEvent.idl.
const unsigned long LL_DOM_VK_CANCEL = 0x03;
const unsigned long LL_DOM_VK_HELP = 0x06;
const unsigned long LL_DOM_VK_BACK_SPACE = 0x08;
const unsigned long LL_DOM_VK_TAB = 0x09;
const unsigned long LL_DOM_VK_CLEAR = 0x0C;
const unsigned long LL_DOM_VK_RETURN = 0x0D;
const unsigned long LL_DOM_VK_ENTER = 0x0E;
const unsigned long LL_DOM_VK_SHIFT = 0x10;
const unsigned long LL_DOM_VK_CONTROL = 0x11;
const unsigned long LL_DOM_VK_ALT = 0x12;
const unsigned long LL_DOM_VK_PAUSE = 0x13;
const unsigned long LL_DOM_VK_CAPS_LOCK = 0x14;
const unsigned long LL_DOM_VK_ESCAPE = 0x1B;
const unsigned long LL_DOM_VK_SPACE = 0x20;
const unsigned long LL_DOM_VK_PAGE_UP = 0x21;
const unsigned long LL_DOM_VK_PAGE_DOWN = 0x22;
const unsigned long LL_DOM_VK_END = 0x23;
const unsigned long LL_DOM_VK_HOME = 0x24;
const unsigned long LL_DOM_VK_LEFT = 0x25;
const unsigned long LL_DOM_VK_UP = 0x26;
const unsigned long LL_DOM_VK_RIGHT = 0x27;
const unsigned long LL_DOM_VK_DOWN = 0x28;
const unsigned long LL_DOM_VK_PRINTSCREEN = 0x2C;
const unsigned long LL_DOM_VK_INSERT = 0x2D;
const unsigned long LL_DOM_VK_DELETE = 0x2E;
// LL_DOM_VK_0 - LL_DOM_VK_9 match their ASCII values
const unsigned long LL_DOM_VK_0 = 0x30;
const unsigned long LL_DOM_VK_1 = 0x31;
const unsigned long LL_DOM_VK_2 = 0x32;
const unsigned long LL_DOM_VK_3 = 0x33;
const unsigned long LL_DOM_VK_4 = 0x34;
const unsigned long LL_DOM_VK_5 = 0x35;
const unsigned long LL_DOM_VK_6 = 0x36;
const unsigned long LL_DOM_VK_7 = 0x37;
const unsigned long LL_DOM_VK_8 = 0x38;
const unsigned long LL_DOM_VK_9 = 0x39;
const unsigned long LL_DOM_VK_SEMICOLON = 0x3B;
const unsigned long LL_DOM_VK_EQUALS = 0x3D;
// LL_DOM_VK_A - LL_DOM_VK_Z match their ASCII values
const unsigned long LL_DOM_VK_A = 0x41;
const unsigned long LL_DOM_VK_B = 0x42;
const unsigned long LL_DOM_VK_C = 0x43;
const unsigned long LL_DOM_VK_D = 0x44;
const unsigned long LL_DOM_VK_E = 0x45;
const unsigned long LL_DOM_VK_F = 0x46;
const unsigned long LL_DOM_VK_G = 0x47;
const unsigned long LL_DOM_VK_H = 0x48;
const unsigned long LL_DOM_VK_I = 0x49;
const unsigned long LL_DOM_VK_J = 0x4A;
const unsigned long LL_DOM_VK_K = 0x4B;
const unsigned long LL_DOM_VK_L = 0x4C;
const unsigned long LL_DOM_VK_M = 0x4D;
const unsigned long LL_DOM_VK_N = 0x4E;
const unsigned long LL_DOM_VK_O = 0x4F;
const unsigned long LL_DOM_VK_P = 0x50;
const unsigned long LL_DOM_VK_Q = 0x51;
const unsigned long LL_DOM_VK_R = 0x52;
const unsigned long LL_DOM_VK_S = 0x53;
const unsigned long LL_DOM_VK_T = 0x54;
const unsigned long LL_DOM_VK_U = 0x55;
const unsigned long LL_DOM_VK_V = 0x56;
const unsigned long LL_DOM_VK_W = 0x57;
const unsigned long LL_DOM_VK_X = 0x58;
const unsigned long LL_DOM_VK_Y = 0x59;
const unsigned long LL_DOM_VK_Z = 0x5A;
const unsigned long LL_DOM_VK_CONTEXT_MENU = 0x5D;
const unsigned long LL_DOM_VK_NUMPAD0 = 0x60;
const unsigned long LL_DOM_VK_NUMPAD1 = 0x61;
const unsigned long LL_DOM_VK_NUMPAD2 = 0x62;
const unsigned long LL_DOM_VK_NUMPAD3 = 0x63;
const unsigned long LL_DOM_VK_NUMPAD4 = 0x64;
const unsigned long LL_DOM_VK_NUMPAD5 = 0x65;
const unsigned long LL_DOM_VK_NUMPAD6 = 0x66;
const unsigned long LL_DOM_VK_NUMPAD7 = 0x67;
const unsigned long LL_DOM_VK_NUMPAD8 = 0x68;
const unsigned long LL_DOM_VK_NUMPAD9 = 0x69;
const unsigned long LL_DOM_VK_MULTIPLY = 0x6A;
const unsigned long LL_DOM_VK_ADD = 0x6B;
const unsigned long LL_DOM_VK_SEPARATOR = 0x6C;
const unsigned long LL_DOM_VK_SUBTRACT = 0x6D;
const unsigned long LL_DOM_VK_DECIMAL = 0x6E;
const unsigned long LL_DOM_VK_DIVIDE = 0x6F;
const unsigned long LL_DOM_VK_F1 = 0x70;
const unsigned long LL_DOM_VK_F2 = 0x71;
const unsigned long LL_DOM_VK_F3 = 0x72;
const unsigned long LL_DOM_VK_F4 = 0x73;
const unsigned long LL_DOM_VK_F5 = 0x74;
const unsigned long LL_DOM_VK_F6 = 0x75;
const unsigned long LL_DOM_VK_F7 = 0x76;
const unsigned long LL_DOM_VK_F8 = 0x77;
const unsigned long LL_DOM_VK_F9 = 0x78;
const unsigned long LL_DOM_VK_F10 = 0x79;
const unsigned long LL_DOM_VK_F11 = 0x7A;
const unsigned long LL_DOM_VK_F12 = 0x7B;
const unsigned long LL_DOM_VK_F13 = 0x7C;
const unsigned long LL_DOM_VK_F14 = 0x7D;
const unsigned long LL_DOM_VK_F15 = 0x7E;
const unsigned long LL_DOM_VK_F16 = 0x7F;
const unsigned long LL_DOM_VK_F17 = 0x80;
const unsigned long LL_DOM_VK_F18 = 0x81;
const unsigned long LL_DOM_VK_F19 = 0x82;
const unsigned long LL_DOM_VK_F20 = 0x83;
const unsigned long LL_DOM_VK_F21 = 0x84;
const unsigned long LL_DOM_VK_F22 = 0x85;
const unsigned long LL_DOM_VK_F23 = 0x86;
const unsigned long LL_DOM_VK_F24 = 0x87;
const unsigned long LL_DOM_VK_NUM_LOCK = 0x90;
const unsigned long LL_DOM_VK_SCROLL_LOCK = 0x91;
const unsigned long LL_DOM_VK_COMMA = 0xBC;
const unsigned long LL_DOM_VK_PERIOD = 0xBE;
const unsigned long LL_DOM_VK_SLASH = 0xBF;
const unsigned long LL_DOM_VK_BACK_QUOTE = 0xC0;
const unsigned long LL_DOM_VK_OPEN_BRACKET = 0xDB;
const unsigned long LL_DOM_VK_BACK_SLASH = 0xDC;
const unsigned long LL_DOM_VK_CLOSE_BRACKET = 0xDD;
const unsigned long LL_DOM_VK_QUOTE = 0xDE;
const unsigned long LL_DOM_VK_META = 0xE0;
#endif // LLMOZLIB_H

View File

@ -1,544 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.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 "nsProfileDirServiceProvider.h"
#include "nsProfileStringTypes.h"
#include "nsProfileLock.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsISupportsUtils.h"
#include "nsISimpleEnumerator.h"
#include "nsIObserverService.h"
#ifdef MOZ_PROFILESHARING
#include "nsIProfileSharingSetup.h"
#include "ipcITransactionService.h"
#endif
// File Name Defines
#define PREFS_FILE_50_NAME NS_LITERAL_CSTRING("prefs.js")
#define USER_CHROME_DIR_50_NAME NS_LITERAL_CSTRING("chrome")
#define LOCAL_STORE_FILE_50_NAME NS_LITERAL_CSTRING("localstore.rdf")
#define HISTORY_FILE_50_NAME NS_LITERAL_CSTRING("history.dat")
#define PANELS_FILE_50_NAME NS_LITERAL_CSTRING("panels.rdf")
#define MIME_TYPES_FILE_50_NAME NS_LITERAL_CSTRING("mimeTypes.rdf")
#define BOOKMARKS_FILE_50_NAME NS_LITERAL_CSTRING("bookmarks.html")
#define DOWNLOADS_FILE_50_NAME NS_LITERAL_CSTRING("downloads.rdf")
#define SEARCH_FILE_50_NAME NS_LITERAL_CSTRING("search.rdf" )
#define MAIL_DIR_50_NAME NS_LITERAL_CSTRING("Mail")
#define IMAP_MAIL_DIR_50_NAME NS_LITERAL_CSTRING("ImapMail")
#define NEWS_DIR_50_NAME NS_LITERAL_CSTRING("News")
#define MSG_FOLDER_CACHE_DIR_50_NAME NS_LITERAL_CSTRING("panacea.dat")
#define STORAGE_FILE_50_NAME NS_LITERAL_CSTRING("storage.sdb")
//*****************************************************************************
// nsProfileDirServiceProvider::nsProfileDirServiceProvider
//*****************************************************************************
nsProfileDirServiceProvider::nsProfileDirServiceProvider(PRBool aNotifyObservers) :
#ifdef MOZ_PROFILELOCKING
mProfileDirLock(nsnull),
#endif
mNotifyObservers(aNotifyObservers),
mSharingEnabled(PR_FALSE)
{
}
nsProfileDirServiceProvider::~nsProfileDirServiceProvider()
{
#ifdef MOZ_PROFILELOCKING
delete mProfileDirLock;
#endif
}
nsresult
nsProfileDirServiceProvider::SetProfileDir(nsIFile* aProfileDir,
nsIFile* aLocalProfileDir)
{
if (!aLocalProfileDir)
aLocalProfileDir = aProfileDir;
if (mProfileDir) {
PRBool isEqual;
if (aProfileDir &&
NS_SUCCEEDED(aProfileDir->Equals(mProfileDir, &isEqual)) && isEqual) {
NS_WARNING("Setting profile dir to same as current");
return NS_OK;
}
#ifdef MOZ_PROFILELOCKING
mProfileDirLock->Unlock();
#endif
UndefineFileLocations();
}
mProfileDir = aProfileDir;
mLocalProfileDir = aLocalProfileDir;
if (!mProfileDir)
return NS_OK;
nsresult rv = InitProfileDir(mProfileDir);
if (NS_FAILED(rv))
return rv;
// Make sure that the local profile dir exists
// we just try to create it - if it exists already, that'll fail; ignore
// errors
mLocalProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
#ifdef MOZ_PROFILESHARING
if (mSharingEnabled) {
nsCOMPtr<ipcITransactionService> transServ =
do_GetService(IPC_TRANSACTIONSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCAutoString nativePath;
rv = mProfileDir->GetNativePath(nativePath);
if (NS_SUCCEEDED(rv))
rv = transServ->Init(nativePath);
}
if (NS_FAILED(rv)) {
NS_WARNING("Unable to initialize transaction service");
}
}
#endif
#ifdef MOZ_PROFILELOCKING
// Lock the non-shared sub-dir if we are sharing,
// the whole profile dir if we are not.
nsCOMPtr<nsILocalFile> dirToLock;
if (mSharingEnabled)
dirToLock = do_QueryInterface(mNonSharedProfileDir);
else
dirToLock = do_QueryInterface(mProfileDir);
rv = mProfileDirLock->Lock(dirToLock, nsnull);
if (NS_FAILED(rv))
return rv;
#endif
if (mNotifyObservers) {
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (!observerService)
return NS_ERROR_FAILURE;
NS_NAMED_LITERAL_STRING(context, "startup");
// Notify observers that the profile has changed - Here they respond to new profile
observerService->NotifyObservers(nsnull, "profile-do-change", context.get());
// Now observers can respond to something another observer did on "profile-do-change"
observerService->NotifyObservers(nsnull, "profile-after-change", context.get());
}
return NS_OK;
}
nsresult
nsProfileDirServiceProvider::Register()
{
nsCOMPtr<nsIDirectoryService> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
if (!directoryService)
return NS_ERROR_FAILURE;
return directoryService->RegisterProvider(this);
}
nsresult
nsProfileDirServiceProvider::Shutdown()
{
if (!mNotifyObservers)
return NS_OK;
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (!observerService)
return NS_ERROR_FAILURE;
NS_NAMED_LITERAL_STRING(context, "shutdown-persist");
observerService->NotifyObservers(nsnull, "profile-before-change", context.get());
return NS_OK;
}
//*****************************************************************************
// nsProfileDirServiceProvider::nsISupports
//*****************************************************************************
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProfileDirServiceProvider,
nsIDirectoryServiceProvider)
//*****************************************************************************
// nsProfileDirServiceProvider::nsIDirectoryServiceProvider
//*****************************************************************************
NS_IMETHODIMP
nsProfileDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval)
{
NS_ENSURE_ARG(prop);
NS_ENSURE_ARG_POINTER(persistant);
NS_ENSURE_ARG_POINTER(_retval);
// Don't assert - we can be called many times before SetProfileDir() has been called.
if (!mProfileDir)
return NS_ERROR_FAILURE;
*persistant = PR_TRUE;
nsIFile* domainDir = mProfileDir;
#ifdef MOZ_PROFILESHARING
// If the prop is prefixed with NS_SHARED,
// the location is in the shared domain.
PRBool bUseShared = PR_FALSE;
if (strncmp(prop, NS_SHARED, sizeof(NS_SHARED)-1) == 0) {
prop += (sizeof(NS_SHARED)-1);
bUseShared = PR_TRUE;
}
if (!bUseShared && mNonSharedProfileDir)
domainDir = mNonSharedProfileDir;
#endif
nsCOMPtr<nsIFile> localFile;
nsresult rv = NS_ERROR_FAILURE;
if (strcmp(prop, NS_APP_PREFS_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
}
else if (strcmp(prop, NS_APP_PREFS_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(PREFS_FILE_50_NAME);
}
else if (strcmp(prop, NS_APP_USER_PROFILE_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
}
else if (strcmp(prop, NS_APP_USER_PROFILE_LOCAL_50_DIR) == 0) {
rv = mLocalProfileDir->Clone(getter_AddRefs(localFile));
}
else if (strcmp(prop, NS_APP_USER_CHROME_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(USER_CHROME_DIR_50_NAME);
}
else if (strcmp(prop, NS_APP_LOCALSTORE_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) {
rv = localFile->AppendNative(LOCAL_STORE_FILE_50_NAME);
if (NS_SUCCEEDED(rv)) {
// it's OK if we can't copy the file... it will be created
// by client code.
(void) EnsureProfileFileExists(localFile, domainDir);
}
}
}
else if (strcmp(prop, NS_APP_HISTORY_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(HISTORY_FILE_50_NAME);
}
else if (strcmp(prop, NS_APP_USER_PANELS_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) {
rv = localFile->AppendNative(PANELS_FILE_50_NAME);
if (NS_SUCCEEDED(rv))
rv = EnsureProfileFileExists(localFile, domainDir);
}
}
else if (strcmp(prop, NS_APP_USER_MIMETYPES_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) {
rv = localFile->AppendNative(MIME_TYPES_FILE_50_NAME);
if (NS_SUCCEEDED(rv))
rv = EnsureProfileFileExists(localFile, domainDir);
}
}
else if (strcmp(prop, NS_APP_BOOKMARKS_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(BOOKMARKS_FILE_50_NAME);
}
else if (strcmp(prop, NS_APP_DOWNLOADS_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(DOWNLOADS_FILE_50_NAME);
}
else if (strcmp(prop, NS_APP_SEARCH_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) {
rv = localFile->AppendNative(SEARCH_FILE_50_NAME);
if (NS_SUCCEEDED(rv))
rv = EnsureProfileFileExists(localFile, domainDir);
}
}
else if (strcmp(prop, NS_APP_MAIL_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(MAIL_DIR_50_NAME);
}
else if (strcmp(prop, NS_APP_IMAP_MAIL_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(IMAP_MAIL_DIR_50_NAME);
}
else if (strcmp(prop, NS_APP_NEWS_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(NEWS_DIR_50_NAME);
}
else if (strcmp(prop, NS_APP_MESSENGER_FOLDER_CACHE_50_DIR) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(MSG_FOLDER_CACHE_DIR_50_NAME);
}
else if (strcmp(prop, NS_APP_STORAGE_50_FILE) == 0) {
rv = domainDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->AppendNative(STORAGE_FILE_50_NAME);
}
if (localFile && NS_SUCCEEDED(rv))
return CallQueryInterface(localFile, _retval);
return rv;
}
//*****************************************************************************
// Protected methods
//*****************************************************************************
nsresult
nsProfileDirServiceProvider::Initialize()
{
#ifdef MOZ_PROFILELOCKING
mProfileDirLock = new nsProfileLock;
if (!mProfileDirLock)
return NS_ERROR_OUT_OF_MEMORY;
#endif
#ifdef MOZ_PROFILESHARING
nsCOMPtr<nsIProfileSharingSetup> sharingSetup =
do_GetService("@mozilla.org/embedcomp/profile-sharing-setup;1");
if (sharingSetup) {
PRBool tempBool;
if (NS_SUCCEEDED(sharingSetup->GetIsSharingEnabled(&tempBool)))
mSharingEnabled = tempBool;
if (mSharingEnabled)
sharingSetup->GetClientName(mNonSharedDirName);
}
#endif
return NS_OK;
}
nsresult
nsProfileDirServiceProvider::InitProfileDir(nsIFile *profileDir)
{
// Make sure our "Profile" folder exists.
// If it does not, copy the profile defaults to its location.
nsresult rv;
PRBool exists;
rv = profileDir->Exists(&exists);
if (NS_FAILED(rv))
return rv;
if (!exists) {
nsCOMPtr<nsIFile> profileDefaultsDir;
nsCOMPtr<nsIFile> profileDirParent;
nsCAutoString profileDirName;
(void)profileDir->GetParent(getter_AddRefs(profileDirParent));
if (!profileDirParent)
return NS_ERROR_FAILURE;
rv = profileDir->GetNativeLeafName(profileDirName);
if (NS_FAILED(rv))
return rv;
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(profileDefaultsDir));
if (NS_FAILED(rv)) {
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(profileDefaultsDir));
if (NS_FAILED(rv))
return rv;
}
rv = profileDefaultsDir->CopyToNative(profileDirParent, profileDirName);
if (NS_FAILED(rv)) {
// if copying failed, lets just ensure that the profile directory exists.
profileDirParent->AppendNative(profileDirName);
rv = profileDirParent->Create(nsIFile::DIRECTORY_TYPE, 0700);
if (NS_FAILED(rv))
return rv;
}
#if !defined(XP_MAC) && !defined(WINCE)
rv = profileDir->SetPermissions(0700);
if (NS_FAILED(rv))
return rv;
#endif
}
else {
PRBool isDir;
rv = profileDir->IsDirectory(&isDir);
if (NS_FAILED(rv))
return rv;
if (!isDir)
return NS_ERROR_FILE_NOT_DIRECTORY;
}
if (mNonSharedDirName.Length())
rv = InitNonSharedProfileDir();
return rv;
}
nsresult
nsProfileDirServiceProvider::InitNonSharedProfileDir()
{
nsresult rv;
NS_ENSURE_STATE(mProfileDir);
NS_ENSURE_STATE(mNonSharedDirName.Length());
nsCOMPtr<nsIFile> localDir;
rv = mProfileDir->Clone(getter_AddRefs(localDir));
if (NS_SUCCEEDED(rv)) {
rv = localDir->Append(mNonSharedDirName);
if (NS_SUCCEEDED(rv)) {
PRBool exists;
rv = localDir->Exists(&exists);
if (NS_SUCCEEDED(rv)) {
if (!exists) {
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
}
else {
PRBool isDir;
rv = localDir->IsDirectory(&isDir);
if (NS_SUCCEEDED(rv)) {
if (!isDir)
rv = NS_ERROR_FILE_NOT_DIRECTORY;
}
}
if (NS_SUCCEEDED(rv))
mNonSharedProfileDir = localDir;
}
}
}
return rv;
}
nsresult
nsProfileDirServiceProvider::EnsureProfileFileExists(nsIFile *aFile, nsIFile *destDir)
{
nsresult rv;
PRBool exists;
rv = aFile->Exists(&exists);
if (NS_FAILED(rv))
return rv;
if (exists)
return NS_OK;
nsCOMPtr<nsIFile> defaultsFile;
// Attempt first to get the localized subdir of the defaults
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultsFile));
if (NS_FAILED(rv)) {
// If that has not been defined, use the top level of the defaults
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(defaultsFile));
if (NS_FAILED(rv))
return rv;
}
nsCAutoString leafName;
rv = aFile->GetNativeLeafName(leafName);
if (NS_FAILED(rv))
return rv;
rv = defaultsFile->AppendNative(leafName);
if (NS_FAILED(rv))
return rv;
return defaultsFile->CopyTo(destDir, EmptyString());
}
nsresult
nsProfileDirServiceProvider::UndefineFileLocations()
{
nsresult rv;
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(directoryService, NS_ERROR_FAILURE);
(void) directoryService->Undefine(NS_APP_PREFS_50_DIR);
(void) directoryService->Undefine(NS_APP_PREFS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PROFILE_50_DIR);
(void) directoryService->Undefine(NS_APP_USER_CHROME_DIR);
(void) directoryService->Undefine(NS_APP_LOCALSTORE_50_FILE);
(void) directoryService->Undefine(NS_APP_HISTORY_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PANELS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_MIMETYPES_50_FILE);
(void) directoryService->Undefine(NS_APP_BOOKMARKS_50_FILE);
(void) directoryService->Undefine(NS_APP_DOWNLOADS_50_FILE);
(void) directoryService->Undefine(NS_APP_SEARCH_50_FILE);
(void) directoryService->Undefine(NS_APP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_IMAP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_NEWS_50_DIR);
(void) directoryService->Undefine(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR);
return NS_OK;
}
//*****************************************************************************
// Global creation function
//*****************************************************************************
nsresult NS_NewProfileDirServiceProvider(PRBool aNotifyObservers,
nsProfileDirServiceProvider** aProvider)
{
NS_ENSURE_ARG_POINTER(aProvider);
*aProvider = nsnull;
nsProfileDirServiceProvider *prov = new nsProfileDirServiceProvider(aNotifyObservers);
if (!prov)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = prov->Initialize();
if (NS_FAILED(rv)) {
delete prov;
return rv;
}
NS_ADDREF(*aProvider = prov);
return NS_OK;
}

View File

@ -1,145 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.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 ***** */
// Interfaces Needed
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsCOMPtr.h"
#include "nsDirectoryServiceUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsEmbedString.h"
#endif
// Forward Declarations
class nsProfileLock;
// --------------------------------------------------------------------------------------
// nsProfileDirServiceProvider - The nsIDirectoryServiceProvider implementation used for
// profile-relative file locations.
// --------------------------------------------------------------------------------------
class nsProfileDirServiceProvider: public nsIDirectoryServiceProvider
{
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
friend nsresult NS_NewProfileDirServiceProvider(PRBool, nsProfileDirServiceProvider**);
public:
/**
* SetProfileDir
*
* @param aProfileDir The directory containing the profile files.
* It does not need to exist before calling this
* method. If it does not, it will be created and
* defaults will be copied to it.
* @param aLocalProfileDir
* Directory for local profile data, e.g. Cache.
* If null, aProfileDir will be used for this purpose.
*/
virtual nsresult SetProfileDir(nsIFile* aProfileDir,
nsIFile* aLocalProfileDir = nsnull);
/**
* Register
*
* Convenience method to register the provider with directory service.
* The service holds strong references to registered providers so consumers
* don't need to hold a reference to this object after calling Register().
*/
virtual nsresult Register();
/**
* Shutdown
*
* This method must be called before shutting down XPCOM if this object
* was created with aNotifyObservers == PR_TRUE. If this object was
* created with aNotifyObservers == PR_FALSE, this method is a no-op.
*/
virtual nsresult Shutdown();
protected:
nsProfileDirServiceProvider(PRBool aNotifyObservers = PR_TRUE);
virtual ~nsProfileDirServiceProvider();
nsresult Initialize();
nsresult InitProfileDir(nsIFile* profileDir);
nsresult InitNonSharedProfileDir();
nsresult EnsureProfileFileExists(nsIFile *aFile, nsIFile *destDir);
nsresult UndefineFileLocations();
protected:
nsCOMPtr<nsIFile> mProfileDir;
nsCOMPtr<nsIFile> mLocalProfileDir;
nsProfileLock* mProfileDirLock;
PRPackedBool mNotifyObservers;
PRPackedBool mSharingEnabled;
#ifndef MOZILLA_INTERNAL_API
nsEmbedString mNonSharedDirName;
#else
nsString mNonSharedDirName;
#endif
nsCOMPtr<nsIFile> mNonSharedProfileDir;
};
// --------------------------------------------------------------------------------------
/**
* Global method to create an instance of nsProfileDirServiceProvider
*
* @param aNotifyObservers If true, will send out profile startup
* notifications when the profile directory is set.
* See nsIProfileChangeStatus.
*/
nsresult NS_NewProfileDirServiceProvider(PRBool aNotifyObservers,
nsProfileDirServiceProvider** aProvider);

View File

@ -1,112 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
* Brendan Eich <brendan@mozilla.org>
*
* 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 ***** */
#ifndef __nsProfileLock_h___
#define __nsProfileLock_h___
#include "nsILocalFile.h"
class nsIProfileUnlocker;
#if defined (XP_WIN)
#include <windows.h>
#endif
#if defined (XP_OS2)
#define INCL_DOSERRORS
#define INCL_DOSFILEMGR
#include <os2.h>
#endif
#if defined (XP_UNIX)
#include "prclist.h"
#endif
class nsProfileLock
#if defined (XP_UNIX)
: public PRCList
#endif
{
public:
nsProfileLock();
nsProfileLock(nsProfileLock& src);
~nsProfileLock();
nsProfileLock& operator=(nsProfileLock& rhs);
/**
* Attempt to lock a profile directory.
*
* @param aProfileDir [in] The profile directory to lock.
* @param aUnlocker [out] Optional. This is only returned when locking
* fails with NS_ERROR_FILE_ACCESS_DENIED, and may not
* be returned at all.
* @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked.
*/
nsresult Lock(nsILocalFile* aProfileDir, nsIProfileUnlocker* *aUnlocker);
nsresult Unlock();
private:
PRPackedBool mHaveLock;
#if defined (XP_WIN)
HANDLE mLockFileHandle;
#elif defined (XP_OS2)
LHANDLE mLockFileHandle;
#elif defined (XP_UNIX)
static void RemovePidLockFiles();
static void FatalSignalHandler(int signo);
static PRCList mPidLockList;
nsresult LockWithFcntl(const nsACString& lockFilePath);
/**
* @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this
* lock is merely an "obsolete" lock to keep out old Firefoxes
*/
nsresult LockWithSymlink(const nsACString& lockFilePath, PRBool aHaveFcntlLock);
char* mPidLockFileName;
int mLockFileDesc;
#endif
};
#endif /* __nsProfileLock_h___ */

View File

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Marco Pesenti Gritti <marco@gnome.org>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the 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 ***** */
/**
* We support two builds of the directory service provider.
* One, linked into the profile component, uses the internal
* string API. The other can be used by standalone embedding
* clients, and uses embed strings.
* To keep the code clean, we are using typedefs to equate
* embed/internal string types. We are also defining some
* internal macros in terms of the embedding strings API.
*
* When modifying the profile directory service provider, be
* sure to use methods supported by both the internal and
* embed strings APIs.
*/
#ifndef MOZILLA_INTERNAL_API
#include "nsStringAPI.h"
typedef nsCString nsPromiseFlatCString;
typedef nsCString nsCAutoString;
#define PromiseFlatCString nsCString
#else
#include "nsString.h"
#include "nsPromiseFlatString.h"
#endif