Apertura del repositorio

This commit is contained in:
2025-05-24 18:09:39 -03:00
parent 76e6359dad
commit d883ddd0d0
35253 changed files with 2891973 additions and 2 deletions
+73
View File
@@ -0,0 +1,73 @@
project(SLPlugin)
include(00-Common)
include(LLCommon)
include(Linking)
include(PluginAPI)
### SLPlugin
set(SLPlugin_SOURCE_FILES
slplugin.cpp
)
if (DARWIN)
list(APPEND SLPlugin_SOURCE_FILES
slplugin-objc.mm
)
list(APPEND SLPlugin_HEADER_FILES
slplugin-objc.h
)
endif (DARWIN)
if (SLPlugin_HEADER_FILES)
list(APPEND SLPlugin_SOURCE_FILES ${SLPlugin_HEADER_FILES})
endif (SLPlugin_HEADER_FILES)
add_executable(SLPlugin
WIN32
MACOSX_BUNDLE
${SLPlugin_SOURCE_FILES}
)
if (WINDOWS)
set_target_properties(SLPlugin
PROPERTIES
LINK_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMTD\""
)
else ()
set_target_properties(SLPlugin
PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/slplugin_info.plist
)
endif ()
if(WINDOWS)
set_target_properties(SLPlugin
PROPERTIES
LINK_FLAGS "/debug"
)
endif(WINDOWS)
target_link_libraries(SLPlugin
llplugin
llmessage
llcommon
ll::pluginlibraries
)
if (DARWIN)
# Make sure the app bundle has a Resources directory (it will get populated by viewer-manifest.py later)
add_custom_command(
TARGET SLPlugin POST_BUILD
COMMAND mkdir
ARGS
-p
${CMAKE_CURRENT_BINARY_DIR}/$<IF:$<BOOL:${LL_GENERATOR_IS_MULTI_CONFIG}>,$<CONFIG>,>/SLPlugin.app/Contents/Resources
)
endif (DARWIN)
if (LL_TESTS)
ll_deploy_sharedlibs_command(SLPlugin)
endif (LL_TESTS)
+55
View File
@@ -0,0 +1,55 @@
/**
* @file slplugin-objc.h
* @brief Header file for slplugin-objc.mm.
*
* @cond
*
* $LicenseInfo:firstyear=2010&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
//Protos for ObjectiveC classes (cannot import cocoa here due to BOOL conflict)
#ifndef __OBJC__
class NSWindow;
#endif // __OBJC__
/* Defined in slplugin-objc.mm: */
class LLCocoaPlugin
{
public:
LLCocoaPlugin();
void setupCocoa();
void createAutoReleasePool();
void deleteAutoReleasePool();
void setupGroup();
void updateWindows();
void processEvents();
public:
//EventTargetRef mEventTarget;
NSWindow* mFrontWindow;
NSWindow* mPluginWindow;
int mHackState;
};
+177
View File
@@ -0,0 +1,177 @@
/**
* @file slplugin-objc.mm
* @brief Objective-C++ file for use with the loader shell, so we can use a couple of Cocoa APIs.
*
* @cond
*
* $LicenseInfo:firstyear=2010&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
#include <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
#include "slplugin-objc.h"
//Note: NSApp is a global defined by cocoa which is an id to the application.
void LLCocoaPlugin::setupCocoa()
{
static bool inited = false;
if(!inited)
{
createAutoReleasePool();
// The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents.
// ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr'
// when init'ing the Cocoa App window.
[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
// This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
// http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
// Needed for Carbon based applications which call into Cocoa
NSApplicationLoad();
// Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image
[[[NSWindow alloc] init] release];
mPluginWindow = [NSApp mainWindow];
deleteAutoReleasePool();
inited = true;
}
}
static NSAutoreleasePool *sPool = NULL;
void LLCocoaPlugin::createAutoReleasePool()
{
if(!sPool)
{
sPool = [[NSAutoreleasePool alloc] init];
}
}
void LLCocoaPlugin::deleteAutoReleasePool()
{
if(sPool)
{
[sPool release];
sPool = NULL;
}
}
LLCocoaPlugin::LLCocoaPlugin():mHackState(0)
{
NSArray* window_list = [NSApp orderedWindows];
mFrontWindow = [window_list objectAtIndex:0];
}
void LLCocoaPlugin::processEvents()
{
// Some plugins (webkit at least) will want an event loop. This qualifies.
NSEvent * event;
event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
[NSApp sendEvent: event];
}
//Turns out the window ordering stuff never gets hit with any of the current plugins.
//Leaving the following code here 'just in case' for the time being.
void LLCocoaPlugin::setupGroup()
{
// CreateWindowGroup(kWindowGroupAttrFixedLevel, &layer_group);
// if(layer_group)
// {
// // Start out with a window layer that's way out in front (fixes the problem with the menubar not getting hidden on first switch to fullscreen youtube)
// SetWindowGroupName(layer_group, CFSTR("SLPlugin Layer"));
// SetWindowGroupLevel(layer_group, kCGOverlayWindowLevel);
// }
}
void LLCocoaPlugin::updateWindows()
{
// NSArray* window_list = [NSApp orderedWindows];
// NSWindow* current_window = [window_list objectAtIndex:0];
// NSWindow* parent_window = [ current_window parentWindow ];
// bool this_is_front_process = false;
// bool parent_is_front_process = false;
//
//
// // Check for a change in this process's frontmost window.
// if ( current_window != mFrontWindow )
// {
// // and figure out whether this process or its parent are currently frontmost
// if ( current_window == parent_window ) parent_is_front_process = true;
// if ( current_window == mPluginWindow ) this_is_front_process = true;
//
// if (current_window != NULL && mFrontWindow == NULL)
// {
// // Opening the first window
//
// if(mHackState == 0)
// {
// // Next time through the event loop, lower the window group layer
// mHackState = 1;
// }
//
// if(parent_is_front_process)
// {
// // Bring this process's windows to the front.
// [mPluginWindow makeKeyAndOrderFront:NSApp];
// [mPluginWindow setOrderedIndex:0];
// }
//
// [NSApp activateIgnoringOtherApps:YES];
// }
//
// else if (( current_window == NULL) && (mFrontWindow != NULL))
// {
// // Closing the last window
//
// if(this_is_front_process)
// {
// // Try to bring this process's parent to the front
// [parent_window makeKeyAndOrderFront:NSApp];
// [parent_window setOrderedIndex:0];
// }
// }
// else if(mHackState == 1)
// {
//// if(layer_group)
//// {
//// // Set the window group level back to something less extreme
//// SetWindowGroupLevel(layer_group, kCGNormalWindowLevel);
//// }
// mHackState = 2;
// }
//
// mFrontWindow = [window_list objectAtIndex:0];
// }
}
+267
View File
@@ -0,0 +1,267 @@
/**
* @file slplugin.cpp
* @brief Loader shell for plugins, intended to be launched by the plugin host application, which directly loads a plugin dynamic library.
*
* @cond
*
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*
* @endcond
*/
#include "linden_common.h"
#include "llpluginprocesschild.h"
#include "llpluginmessage.h"
#include "llerrorcontrol.h"
#include "llapr.h"
#include "llstring.h"
#include <iostream>
#include <fstream>
using namespace std;
#if LL_DARWIN
#include "slplugin-objc.h"
#endif
#if LL_DARWIN || LL_LINUX
#include <signal.h>
#endif
/*
On Mac OS, since we call WaitNextEvent, this process will show up in the dock unless we set the LSBackgroundOnly or LSUIElement flag in the Info.plist.
Normally non-bundled binaries don't have an info.plist file, but it's possible to embed one in the binary by adding this to the linker flags:
-sectcreate __TEXT __info_plist /path/to/slplugin_info.plist
which means adding this to the gcc flags:
-Wl,-sectcreate,__TEXT,__info_plist,/path/to/slplugin_info.plist
Now that SLPlugin is a bundled app on the Mac, this is no longer necessary (it can just use a regular Info.plist file), but I'm leaving this comment in for posterity.
*/
#if LL_DARWIN || LL_LINUX
// Signal handlers to make crashes not show an OS dialog...
static void crash_handler(int sig)
{
// Just exit cleanly.
// TODO: add our own crash reporting
_exit(1);
}
#endif
#if LL_WINDOWS
#include <windows.h>
////////////////////////////////////////////////////////////////////////////////
// Our exception handler - will probably just exit and the host application
// will miss the heartbeat and log the error in the usual fashion.
LONG WINAPI myWin32ExceptionHandler( struct _EXCEPTION_POINTERS* exception_infop )
{
//std::cerr << "This plugin (" << __FILE__ << ") - ";
//std::cerr << "intercepted an unhandled exception and will exit immediately." << std::endl;
// TODO: replace exception handler before we exit?
return EXCEPTION_EXECUTE_HANDLER;
}
////////////////////////////////////////////////////////////////////////////////
// Hook our exception handler and replace the system one
void initExceptionHandler()
{
LPTOP_LEVEL_EXCEPTION_FILTER prev_filter;
// save old exception handler in case we need to restore it at the end
prev_filter = SetUnhandledExceptionFilter( myWin32ExceptionHandler );
}
bool checkExceptionHandler()
{
bool ok = true;
LPTOP_LEVEL_EXCEPTION_FILTER prev_filter;
prev_filter = SetUnhandledExceptionFilter(myWin32ExceptionHandler);
if (prev_filter != myWin32ExceptionHandler)
{
LL_WARNS("AppInit") << "Our exception handler (" << (void *)myWin32ExceptionHandler << ") replaced with " << prev_filter << "!" << LL_ENDL;
ok = false;
}
if (prev_filter == nullptr)
{
ok = false;
if (nullptr == myWin32ExceptionHandler)
{
LL_WARNS("AppInit") << "Exception handler uninitialized." << LL_ENDL;
}
else
{
LL_WARNS("AppInit") << "Our exception handler (" << (void *)myWin32ExceptionHandler << ") replaced with NULL!" << LL_ENDL;
}
}
return ok;
}
#endif
// If this application on Windows platform is a console application, a console is always
// created which is bad. Making it a Windows "application" via CMake settings but not
// adding any code to explicitly create windows does the right thing.
#if LL_WINDOWS
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
#else
int main(int argc, char **argv)
#endif
{
ll_init_apr();
// Set up llerror logging
{
LLError::initForApplication(".",".");
LLError::setDefaultLevel(LLError::LEVEL_INFO);
// LLError::setTagLevel("Plugin", LLError::LEVEL_DEBUG);
// LLError::logToFile("slplugin.log");
}
#if LL_WINDOWS
if( strlen( lpCmdLine ) == 0 )
{
LL_ERRS("slplugin") << "usage: " << "SLPlugin" << " launcher_port" << LL_ENDL;
};
U32 port = 0;
if(!LLStringUtil::convertToU32(lpCmdLine, port))
{
LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL;
};
// Insert our exception handler into the system so this plugin doesn't
// display a crash message if something bad happens. The host app will
// see the missing heartbeat and log appropriately.
initExceptionHandler();
#elif LL_DARWIN || LL_LINUX
if(argc < 2)
{
LL_ERRS("slplugin") << "usage: " << argv[0] << " launcher_port" << LL_ENDL;
}
U32 port = 0;
if(!LLStringUtil::convertToU32(argv[1], port))
{
LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL;
}
// Catch signals that most kinds of crashes will generate, and exit cleanly so the system crash dialog isn't shown.
signal(SIGILL, &crash_handler); // illegal instruction
signal(SIGFPE, &crash_handler); // floating-point exception
signal(SIGBUS, &crash_handler); // bus error
signal(SIGSEGV, &crash_handler); // segmentation violation
signal(SIGSYS, &crash_handler); // non-existent system call invoked
#endif
# if LL_DARWIN
signal(SIGEMT, &crash_handler); // emulate instruction executed
LLCocoaPlugin cocoa_interface;
cocoa_interface.setupCocoa();
cocoa_interface.createAutoReleasePool();
#endif //LL_DARWIN
LLPluginProcessChild *plugin = new LLPluginProcessChild();
plugin->init(port);
#if LL_DARWIN
cocoa_interface.deleteAutoReleasePool();
#endif
LLTimer timer;
timer.start();
#if LL_WINDOWS
checkExceptionHandler();
#endif
#if LL_DARWIN
// If the plugin opens a new window (such as the Flash plugin's fullscreen player), we may need to bring this plugin process to the foreground.
// Use this to track the current frontmost window and bring this process to the front if it changes.
// cocoa_interface.mEventTarget = GetEventDispatcherTarget();
#endif
while(!plugin->isDone())
{
#if LL_DARWIN
cocoa_interface.createAutoReleasePool();
#endif
timer.reset();
plugin->idle();
#if LL_DARWIN
{
cocoa_interface.processEvents();
}
#endif
F64 elapsed = timer.getElapsedTimeF64();
F64 remaining = plugin->getSleepTime() - elapsed;
if(remaining <= 0.0)
{
// We've already used our full allotment.
// LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, not sleeping" << LL_ENDL;
// Still need to service the network...
plugin->pump();
}
else
{
// LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, sleeping for " << remaining * 1000.0f << " ms" << LL_ENDL;
// timer.reset();
// This also services the network as needed.
plugin->sleep(remaining);
// LL_INFOS("slplugin") << "slept for "<< timer.getElapsedTimeF64() * 1000.0f << " ms" << LL_ENDL;
}
#if LL_WINDOWS
// More agressive checking of interfering exception handlers.
// Doesn't appear to be required so far - even for plugins
// that do crash with a single call to the intercept
// exception handler such as QuickTime.
//checkExceptionHandler();
#endif
#if LL_DARWIN
cocoa_interface.deleteAutoReleasePool();
#endif
}
delete plugin;
ll_cleanup_apr();
return 0;
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>