From 09a5166987a58ec58df207f47d26d62d09b098e2 Mon Sep 17 00:00:00 2001 From: "amusil%netscape.com" Date: Thu, 3 Sep 1998 21:08:25 +0000 Subject: [PATCH] MacFE code for Anthrax along with minor XP tweaks --- cmd/macfe/central/uapp.cp | 8 +- cmd/macfe/central/umimemap.cp | 44 ++++ cmd/macfe/central/umimemap.h | 17 +- .../prefs/CBrowserApplicationsMediator.cp | 222 ++++++++++++++++-- cmd/macfe/rsrc/navigator/PrefsWindowRat.cnst | Bin 39190 -> 39411 bytes include/np.h | 4 +- lib/layout/layembed.c | 94 ++------ lib/layout/layobj.c | 189 +++++++++------ lib/layout/laytags.c | 89 ++++++- modules/plugin/src/npglue.cpp | 91 +++++-- 10 files changed, 570 insertions(+), 188 deletions(-) diff --git a/cmd/macfe/central/uapp.cp b/cmd/macfe/central/uapp.cp index 6572bab63801..5513672e9afe 100644 --- a/cmd/macfe/central/uapp.cp +++ b/cmd/macfe/central/uapp.cp @@ -1183,7 +1183,13 @@ void CFrontApp::RegisterMimeType(CMimeMapper * mapper) if (pdesc) NPL_RegisterPluginType(mimeName, mapper->GetExtensions(), mapper->GetDescription(), nil, pdesc, true); return; // XP code will take care of the cdata - + +#ifdef ANTHRAX + case CMimeMapper::Applet: + + NPL_RegisterAppletType(mimeName, mapper->GetAppletName()); + break; +#endif default: // Disable the previous plug-in, if any if (pdesc) diff --git a/cmd/macfe/central/umimemap.cp b/cmd/macfe/central/umimemap.cp index 2ba266308e1e..8f0d47294644 100644 --- a/cmd/macfe/central/umimemap.cp +++ b/cmd/macfe/central/umimemap.cp @@ -106,6 +106,10 @@ static const char* Pref_LoadAction = ".load_action"; static const char* Pref_LatentPlugin = ".latent_plug_in"; static const char* Pref_FileFlags = ".file_flags"; +#ifdef ANTHRAX +static const char* Pref_AppletName = ".applet"; +#endif + // CreateMapperFor converts an xp pref name into a mimetype mapper. // Finds an existing mapper or creates a new one, and // populates its fields from user pref values. @@ -215,6 +219,15 @@ void CMimeMapper::ReadMimePrefs() ::BlockMoveData( value, (Ptr) &fFileType, sizeof(OSType) ); } } + +#ifdef ANTHRAX + err = PREF_GetCharPref( CPrefs::Concat(fBasePref, Pref_AppletName), value, &size ); + if (PREF_NOERROR == err) + { + fNumChildrenFound++; + fAppletName = value; + } +#endif err = PREF_GetCharPref( CPrefs::Concat(fBasePref, Pref_AppName), value, &size ); if (PREF_NOERROR == err) @@ -431,6 +444,10 @@ CMimeMapper::CMimeMapper( const CMimeMapper& clone ) fIsLocked = clone.fIsLocked; fNumChildrenFound = clone.fNumChildrenFound; + +#ifdef ANTHRAX + fAppletName = clone.fAppletName; +#endif } // Copies values from the mapper to xp user pref tree. @@ -470,6 +487,10 @@ void CMimeMapper::WriteMimePrefs( Boolean ) PREF_SetCharPref( CPrefs::Concat(fBasePref, Pref_MimeType), fMimeType ); PREF_SetCharPref( CPrefs::Concat(fBasePref, Pref_AppName), fAppName ); PREF_SetCharPref( CPrefs::Concat(fBasePref, Pref_PluginName), fPluginName ); +#ifdef ANTHRAX + PREF_SetCharPref( CPrefs::Concat(fBasePref, Pref_AppletName), fAppletName ); + ++fNumChildrenFound; +#endif fNumChildrenFound += 3; // store appsig and filetype as 4-byte character strings, if possible. // otherwise, store as binary. @@ -508,6 +529,9 @@ CMimeMapper::CMimeMapper( fDescription = ""; fLatentPlugin = false; fBasePref = nil; +#ifdef ANTHRAX + fAppletName = ""; +#endif } // Disposes of all allocated structures @@ -529,9 +553,19 @@ CMimeMapper & CMimeMapper::operator= (const CMimeMapper& mapper) fDescription = mapper.fDescription; fLatentPlugin = mapper.fLatentPlugin; fFileFlags = mapper.fFileFlags; +#ifdef ANTHRAX + fAppletName = mapper.fAppletName; +#endif return *this; } +#ifdef ANTHRAX +void CMimeMapper::SetAppletName(const CStr255& newAppletName) +{ + fAppletName = newAppletName; +} +#endif /* ANTHRAX */ + void CMimeMapper::SetAppName(const CStr255& newName) { fAppName = newName; @@ -935,7 +969,12 @@ CMimeMapper* CMimeList::FindMimeType(const FSSpec& inFileSpec) // on type and/or creator. bing: If we decide to support Mac file // types for plug-ins, we should check the file type here. // +#ifdef ANTHRAX + if(map->GetLoadAction() == CMimeMapper::Plugin || + map->GetLoadAction() == CMimeMapper::Applet) +#else if (map->GetLoadAction() == CMimeMapper::Plugin) +#endif /* ANTHRAX */ { if (cinfo && (map->GetMimeName() == cinfo->type)) return map; @@ -1041,7 +1080,12 @@ void CMimeList::HandleRegisterViewerEvent(const AppleEvent &inAppleEvent, // If the type is being handled by a plug-in, donÕt let the AE override Boolean result = false; +#ifdef ANTHRAX // is this addition for anthrax correct? - amusil + if (mapper->GetLoadAction() != CMimeMapper::Plugin && + mapper->GetLoadAction() != CMimeMapper::Applet) +#else if (mapper->GetLoadAction() != CMimeMapper::Plugin) +#endif /* ANTHRAX */ { mapper->RegisterViewer(appSign, fileType); result = true; diff --git a/cmd/macfe/central/umimemap.h b/cmd/macfe/central/umimemap.h index d3aed9e762f7..2c52a0d6cf68 100644 --- a/cmd/macfe/central/umimemap.h +++ b/cmd/macfe/central/umimemap.h @@ -28,6 +28,8 @@ #include "PascalString.h" #include "ICKeys.h" // Needed for fileflags +#define ANTHRAX + class LFileBufferStream; class CPrefs; @@ -43,7 +45,11 @@ typedef struct URL_Struct_ URL_Struct; class CMimeMapper { public: // All these must be non-zero because of a presumed bug in back end +#ifdef ANTHRAX + enum LoadAction { Save = 0, Launch = 1, Internal = 2, Unknown = 3, Plugin = 4, Applet = 5}; +#else enum LoadAction { Save = 0, Launch = 1, Internal = 2, Unknown = 3, Plugin = 4}; +#endif // ¥¥ Constructors/destructors void InitMapper(); @@ -68,6 +74,9 @@ public: // ¥¥ Access // Set functions are used by app setup box +#ifdef ANTHRAX + void SetAppletName(const CStr255& newAppletName); +#endif void SetAppName(const CStr255& newName); void SetMimeType(const CStr255& newType); void SetExtensions(const CStr255& newExtensions); @@ -87,6 +96,9 @@ public: Boolean IsViewerRegistered() const { return fRegisteredViewer; } // Get functions +#ifdef ANTHRAX + CStr255 GetAppletName() {return fAppletName;} +#endif CStr255 GetAppName() {return fAppName;}; CStr255 GetMimeName() {return fMimeType;}; CStr255 GetExtensions() {return fExtensions;}; @@ -144,7 +156,10 @@ private: char* fBasePref; // Corresponding XP pref branch name Int32 fFileFlags; // IC style FileFlags Boolean fIsLocked; // If the mimetype pref is locked (for Mission Control functionality) - + +#ifdef ANTHRAX + CStr255 fAppletName; +#endif }; diff --git a/cmd/macfe/prefs/CBrowserApplicationsMediator.cp b/cmd/macfe/prefs/CBrowserApplicationsMediator.cp index e6e9ac70e5db..b6634598cb6f 100644 --- a/cmd/macfe/prefs/CBrowserApplicationsMediator.cp +++ b/cmd/macfe/prefs/CBrowserApplicationsMediator.cp @@ -54,9 +54,11 @@ enum eChooseApplicationButton, eFileTypePopupMenu, eSaveRButton, - eUnknownRButton, - eResourceCheckbox, - eOutgoingCheckbox + eUnknownRButton +#ifdef ANTHRAX + , eAppletButton, + eAppletPopupMenu +#endif }; #pragma mark --CMimeCell-- @@ -352,6 +354,11 @@ void CMimeTableView::DrawCell( case CMimeMapper::Plugin: handlerName = mapper->GetPluginName(); break; +#ifdef ANTHRAX + case CMimeMapper::Applet: + handlerName = mapper->GetAppletName(); + break; +#endif /* ANTHRAX */ } textRect.left = offsetHandler; @@ -448,6 +455,13 @@ private: void BuildPluginList(); void DeletePluginList(); void BuildFileTypeMenu(); +#ifdef ANTHRAX + void SyncAppletControls(Boolean mimeTypeChanged); + void BuildAppletList(); + void BuildAppletMenu(); + void DeleteAppletList(); +#endif + CMimeMapper::LoadAction GetLoadAction(); Boolean mInitialized; // Initialized with fCellInfo yet? @@ -468,8 +482,6 @@ private: LGARadioButton *mRadioInternal; LGARadioButton *mRadioUnknown; LGARadioButton *mRadioPlugin; - LGACheckbox *mSendResouceFork; - LGACheckbox *mOutgoingCheckbox; // CFilePicker *mAppPicker; LCaption *mAppName; LButton *mAppButton; @@ -477,6 +489,12 @@ private: CStr255 mAppStr; OSType mAppSig; Boolean mLocked; +#ifdef ANTHRAX + LGARadioButton *mRadioApplet; + LGAPopup *mAppletPopup; + char** mAppletList; + uint32 mAppletCount; +#endif }; // class CEditMIMEWindow //----------------------------------- @@ -485,6 +503,10 @@ CEditMIMEWindow::CEditMIMEWindow(LStream* inStream): LGADialogBox(inStream), mModified(false), mInitialized(false), +#ifdef ANTHRAX + mAppletList(nil), + mAppletCount(0), +#endif mPluginList(nil), mPluginCount(0), mLocked( false ) @@ -497,6 +519,9 @@ CEditMIMEWindow::~CEditMIMEWindow() //----------------------------------- { DeletePluginList(); +#ifdef ANTHRAX + DeleteAppletList(); +#endif } @@ -536,6 +561,14 @@ void CEditMIMEWindow::FinishCreateSelf() mRadioPlugin = (LGARadioButton *)FindPaneByID(ePluginRButton); XP_ASSERT(mRadioPlugin); + +#ifdef ANTHRAX + mRadioApplet = (LGARadioButton *)FindPaneByID(eAppletButton); + XP_ASSERT(mRadioApplet); + + mAppletPopup = (LGAPopup *)FindPaneByID(eAppletPopupMenu); + XP_ASSERT(mAppletPopup); +#endif /* ANTHRAX */ // mAppPicker = (CFilePicker *)FindPaneByID(eApplicationFilePicker); // XP_ASSERT(mAppPicker); @@ -546,9 +579,6 @@ void CEditMIMEWindow::FinishCreateSelf() mAppButton = (LButton *)FindPaneByID(eChooseApplicationButton); XP_ASSERT(mAppButton); - mSendResouceFork = (LGACheckbox* ) ( FindPaneByID(eResourceCheckbox) ); - mOutgoingCheckbox = (LGACheckbox* ) ( FindPaneByID(eOutgoingCheckbox) ); - XP_ASSERT( mSendResouceFork ); // mAppMenuLabel = (LCaption *)FindPaneByID(pref8AppMenuLabel); // XP_ASSERT(mAppMenuLabel); @@ -668,6 +698,82 @@ void CEditMIMEWindow::BuildPluginMenu() } } +#ifdef ANTHRAX +void CEditMIMEWindow::DeleteAppletList() +{ + if (mAppletList) + { + uint32 index = 0; + + while (mAppletList[index++]) + { + free(mAppletList[index]); + } + free(mAppletList); + mAppletList = nil; + } +} + +void CEditMIMEWindow::BuildAppletList() +{ + // Delete the old list + DeleteAppletList(); + + // Get the new list from XP code - HACK!!!! for now + mAppletList = NPL_FindAppletsForType(mCellInfo->mMapper->GetMimeName()); + + // Count how many are in the list + mAppletCount = 0; + if (mAppletList) + { + while (mAppletList[mAppletCount]) + mAppletCount++; + } +} + +void CEditMIMEWindow::BuildAppletMenu() +{ + uint32 oldCount = mAppletCount; + + BuildAppletList(); + + if (oldCount || mAppletCount) + { + SetMenuSizeForLGAPopup(mAppletPopup, mAppletCount); + + MenuHandle menuH = mAppletPopup->GetMacMenuH(); + uint32 index = 0; + uint32 desiredValue = 1; // Default desired value is first item + while (mAppletList[index]) + { + SetMenuItemText(menuH, index+1, CStr255(mAppletList[index])); + ::EnableItem(menuH, index+1); + if (mCellInfo->mMapper->GetAppletName() == mAppletList[index]) + { + desiredValue = index + 1; + } + index++; + } + + // + // If the previously-selected applet name is in this list, + // select it; otherwise just select the first item. + // If we didn't change the control value, make sure it + // redraws since the contents of the list have changed. + // + uint32 previousValue = mAppletPopup->GetValue(); + if (desiredValue != previousValue) + { + mAppletPopup->SetValue(desiredValue); + } + else + { + mAppletPopup->Refresh(); + } + } +} +#endif /* ANTHRAX */ + //struct BNDLIds //{ // Utility structure for bundle parsing // Int16 localID; @@ -857,6 +963,11 @@ void CEditMIMEWindow::UpdateRadioUItoMapper() case CMimeMapper::Plugin: mRadioPlugin->SetValue(1); break; +#ifdef ANTHRAX + case CMimeMapper::Applet: + mRadioApplet->SetValue(1); + break; +#endif } } @@ -997,6 +1108,41 @@ void CEditMIMEWindow::SyncPluginControls(Boolean mimeTypeChanged) } +#ifdef ANTHRAX +void CEditMIMEWindow::SyncAppletControls(Boolean mimeTypeChanged) +{ + if (mimeTypeChanged) + { + BuildAppletMenu(); + } + // + // If we have an Applet installed, enable the radio button + // + if (mAppletCount > 0) + { + mRadioApplet->Enable(); + } + else + { + mRadioApplet->Disable(); + if (mRadioApplet->GetValue() == 1) + mRadioUnknown->SetValue(1); + } + + // + // Determine the Applet popup control enabled state + // + + if (GetLoadAction() == CMimeMapper::Applet && mAppletCount > 0) + { + mAppletPopup->Enable(); + } + else + { + mAppletPopup->Disable(); + } +} +#endif /* ANTHRAX */ CMimeMapper::LoadAction CEditMIMEWindow::GetLoadAction() { @@ -1005,6 +1151,9 @@ CMimeMapper::LoadAction CEditMIMEWindow::GetLoadAction() if ( mRadioInternal->GetValue() ) return CMimeMapper::Internal; if ( mRadioUnknown->GetValue() ) return CMimeMapper::Unknown; if (mRadioPlugin ->GetValue() ) return CMimeMapper::Plugin; +#ifdef ANTHRAX + if(mRadioApplet->GetValue()) return CMimeMapper::Applet; +#endif return CMimeMapper::Unknown; } @@ -1014,13 +1163,17 @@ void CEditMIMEWindow::ListenToMessage(MessageT inMessage, void *ioParam) //----------------------------------- { if (!mInitialized) - { return; - } + if ( ioParam == mRadioLaunch) SyncApplicationControls(false); if ( ioParam == mRadioPlugin ) SyncPluginControls(false); +#ifdef ANTHRAX + if(ioParam == mRadioApplet) + SyncAppletControls(false); +#endif + switch (inMessage) { // Pick a handler @@ -1029,8 +1182,9 @@ void CEditMIMEWindow::ListenToMessage(MessageT inMessage, void *ioParam) case eCommunicatorRButton: case eUnknownRButton: case ePluginRButton: - case eResourceCheckbox: - case eOutgoingCheckbox: +#ifdef ANTHRAX + case eAppletButton: +#endif mModified = TRUE; break; @@ -1068,6 +1222,15 @@ void CEditMIMEWindow::ListenToMessage(MessageT inMessage, void *ioParam) break; } +#ifdef ANTHRAX + case eAppletPopupMenu: + { + SyncAppletControls(false); + mModified = TRUE; + break; + } +#endif /* ANTHRAX */ + // Edit some text case msg_EditField2: { @@ -1083,7 +1246,7 @@ void CEditMIMEWindow::ListenToMessage(MessageT inMessage, void *ioParam) mModified = TRUE; break; } - + case msg_OK: UpdateMapperToUI(); break; @@ -1108,17 +1271,23 @@ void CEditMIMEWindow::UpdateUIToMapper() UpdateRadioUItoMapper(); SyncTextControls(); SyncInternalControl(); +#ifdef ANTHRAX + SyncAppletControls(true); +#endif SyncApplicationControls(true); SyncPluginControls(true); Int32 fileFlags = mCellInfo->mMapper->GetFileFlags(); - Boolean flag = ( fileFlags & ICmap_resource_fork_mask ) > 0; - mSendResouceFork->SetValue(flag ); + Boolean flag = ( fileFlags & ICmap_resource_fork_mask ) > 0; + flag = (!(fileFlags & ICmap_not_outgoing_mask) )> 0; - mOutgoingCheckbox->SetValue( flag ); mLocked = PREF_PrefIsLocked( CPrefs::Concat(mCellInfo->mMapper->GetBasePref(), ".mimetype") ); if( mLocked ) { - for( PaneIDT i = eDescriptionField ; i<= eOutgoingCheckbox ; i++ ) +#ifdef ANTHRAX + for( PaneIDT i = eDescriptionField ; i<= eAppletPopupMenu ; i++ ) +#else + for( PaneIDT i = eDescriptionField ; i<= eUnknownRButton ; i++ ) +#endif { LPane* pane = FindPaneByID( i ); if( pane ) @@ -1170,6 +1339,19 @@ void CEditMIMEWindow::UpdateMapperToUI() mCellInfo->mMapper->SetPluginName(plugin); } } +#ifdef ANTHRAX + else if(mRadioApplet->GetValue() == 1) + { + uint32 item = mAppletPopup->GetValue(); + XP_ASSERT(item > 0); + if (mAppletList && item > 0 && item <= mAppletCount) + { + char* applet = mAppletList[item - 1]; // Menu is 1-based, list is 0-based + if (applet) + mCellInfo->mMapper->SetAppletName(applet); + } + } +#endif else mCellInfo->mMapper->SetPluginName( "\p" ); @@ -1179,11 +1361,9 @@ void CEditMIMEWindow::UpdateMapperToUI() ::DisposeIconSuite( mCellInfo->mIcon , true); mCellInfo->mIcon = nil; } + + // XXX this file flag stuff might no longer be needed, but I'm not sure Int32 fileFlags = 0; - if( mSendResouceFork->GetValue( ) ) - fileFlags = fileFlags | ICmap_resource_fork_mask ; - if( !mOutgoingCheckbox->GetValue() ) - fileFlags = fileFlags | ICmap_not_outgoing_mask ; mCellInfo->mMapper->SetFileFlags( fileFlags ); } #pragma mark --CBrowserApplicationsMediator-- diff --git a/cmd/macfe/rsrc/navigator/PrefsWindowRat.cnst b/cmd/macfe/rsrc/navigator/PrefsWindowRat.cnst index 2fbb14dd68f97fe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to see if this mimetype has an applet handler */ - if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL) - { - PA_UNLOCK(buff); - if(buff) - XP_FREE(buff); + embed = (LO_EmbedStruct *)lo_NewElement(context, state, LO_EMBED, NULL, 0); + if (embed == NULL) + { + return; + } - /* just pass it to our object handler */ - lo_FormatObject(context, state, tag); - - /* manually close the java app - this is normally done in lo_ProcessObjectTag */ - lo_CloseJavaApp(context, state, state->current_java); - - XP_FREE(appletName); - } - else - { - PA_UNLOCK(buff); - if(buff) - XP_FREE(buff); -#endif /* ANTHRAX */ + embed->objTag.type = LO_EMBED; + embed->objTag.ele_id = NEXT_ELEMENT; + embed->objTag.x = state->x; + embed->objTag.x_offset = 0; + embed->objTag.y = state->y; + embed->objTag.y_offset = 0; + embed->objTag.width = 0; + embed->objTag.height = 0; + embed->objTag.next = NULL; + embed->objTag.prev = NULL; - embed = (LO_EmbedStruct *)lo_NewElement(context, state, LO_EMBED, NULL, 0); - if (embed == NULL) - { - return; - } + LO_NVList_Init( &embed->attributes ); + LO_NVList_Init( &embed->parameters ); - embed->objTag.type = LO_EMBED; - embed->objTag.ele_id = NEXT_ELEMENT; - embed->objTag.x = state->x; - embed->objTag.x_offset = 0; - embed->objTag.y = state->y; - embed->objTag.y_offset = 0; - embed->objTag.width = 0; - embed->objTag.height = 0; - embed->objTag.next = NULL; - embed->objTag.prev = NULL; + embed->attributes.n = PA_FetchAllNameValues(tag, + &(embed->attributes.names), &(embed->attributes.values), CS_FE_ASCII); - LO_NVList_Init( &embed->attributes ); - LO_NVList_Init( &embed->parameters ); - - embed->attributes.n = PA_FetchAllNameValues(tag, - &(embed->attributes.names), &(embed->attributes.values), CS_FE_ASCII); - - lo_FormatEmbedInternal(context, state, tag, embed, FALSE, FALSE); -#ifdef ANTHRAX - } -#endif /* ANTHRAX */ + lo_FormatEmbedInternal(context, state, tag, embed, FALSE, FALSE); } @@ -347,8 +295,6 @@ lo_FormatEmbedObject(MWContext* context, lo_DocState* state, if (param_count > 0) { - int i; - /* Add all tag parameters to the parameters list */ embed->parameters.names = (char**) PA_ALLOC(param_count*sizeof(char*)); embed->parameters.values = (char**) PA_ALLOC(param_count*sizeof(char*)); diff --git a/lib/layout/layobj.c b/lib/layout/layobj.c index 9fac57bd1426..bc474ec9460d 100644 --- a/lib/layout/layobj.c +++ b/lib/layout/layobj.c @@ -42,9 +42,11 @@ Bool lo_CheckObjectBlockage(MWContext*, lo_DocState*, lo_ObjectStack*); static void lo_SetClassID(PA_Tag* tag, char* appletName); static char* lo_GetNextName(char** index); static char* lo_GetNextValue(char** index); -static void lo_SetJavaArgs(char* tag, LO_JavaAppStruct* current_java); +static void lo_SetArgs(char* tag, lo_ObjectStack* top); static void lo_itoa(uint32 n, char* s); static void lo_ReverseString(char* s); +static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue); +static void lo_RemoveParam(PA_Tag* tag, char* name); #endif /* ANTHRAX */ void @@ -60,7 +62,6 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) char* pluginName; #ifdef ANTHRAX - XP_Bool javaMimetypeHandler = FALSE; char* appletName; NET_cinfo* fileInfo; #endif /* ANTHRAX */ @@ -256,7 +257,7 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) We do a lookup and if there is an association, the name of the applet is placed into "appletName". - NOTE: PREF_CopyCharPref() allocates memory for appletName + NOTE: NPL_FindAppletEnabledForMimetype() allocates memory for appletName and we must free it. 9.23.97 amusil @@ -265,13 +266,31 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL) { /* Set the type */ - type = LO_JAVA; + type = LO_EMBED; + sub_type = LO_JAVA; /* set the CLASSID to whatever was put into "appletName" */ - lo_SetClassID(tag, appletName); + /*lo_SetClassID(tag, appletName);*/ + + lo_AddParam(tag, "CODE", appletName); + lo_SetArgs((char*)tag->data, top); + lo_RemoveParam(tag, "type"); + lo_RemoveParam(tag, "src"); + lo_RemoveParam(tag, "data"); + lo_AddParam(tag, "TYPE", JAVA_PLUGIN_MIMETYPE); + + + /* do the same for the clone_tag */ + if(top->clone_tag) + { + lo_AddParam(top->clone_tag, "CODE", appletName); + lo_RemoveParam(top->clone_tag, "type"); + lo_RemoveParam(top->clone_tag, "src"); + lo_RemoveParam(top->clone_tag, "data"); + lo_AddParam(top->clone_tag, "TYPE", JAVA_PLUGIN_MIMETYPE); + } /* set this so that we know later to translate the DATA/SRC param to a Java arg */ - javaMimetypeHandler = TRUE; XP_FREE(appletName); } #endif /* ANTHRAX */ @@ -323,14 +342,30 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL) { /* Set the type */ - type = LO_JAVA; + type = LO_EMBED; + sub_type = LO_JAVA; /* set the CLASSID to whatever was put into "appletName" */ - lo_SetClassID(tag, appletName); + /*lo_SetClassID(tag, appletName);*/ - /* set this so that we know later to translate the DATA/SRC param to a Java arg */ - javaMimetypeHandler = TRUE; - XP_FREE(appletName); /* do we need to free this regardless? */ + lo_SetArgs((char*)tag->data, top); + lo_RemoveParam(tag, "type"); + lo_RemoveParam(tag, "src"); + lo_RemoveParam(tag, "data"); + lo_AddParam(tag, "TYPE", JAVA_PLUGIN_MIMETYPE); + lo_AddParam(tag, "CODE", appletName); + + /* do the same for the clone_tag */ + if(top->clone_tag) + { + lo_AddParam(top->clone_tag, "CODE", appletName); + lo_RemoveParam(top->clone_tag, "type"); + lo_RemoveParam(top->clone_tag, "src"); + lo_RemoveParam(top->clone_tag, "data"); + lo_AddParam(top->clone_tag, "TYPE", JAVA_PLUGIN_MIMETYPE); + } + + XP_FREE(appletName); /* do we need to free this regardless? */ } if(buff) XP_FREE(buff); @@ -341,10 +376,10 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) if (type == LO_EMBED) { object->lo_element.lo_plugin.type = LO_EMBED; - if(sub_type == LO_JAVA) - { - object->lo_element.lo_plugin.sub_type = LO_JAVA; - } + if(sub_type == LO_JAVA) + { + object->lo_element.lo_plugin.sub_type = LO_JAVA; + } } else if (type == LO_BUILTIN) { @@ -364,18 +399,6 @@ lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag) object->lo_element.lo_plugin.type = LO_JAVA; lo_FormatJavaObject(context, state, tag, (LO_JavaAppStruct*) object); - - /* - If we determined previously that this is an applet to mimetype - association, we must set up the SRC or DATA as an arg for the - applet. - - 9.8.97 amusil - */ -#ifdef ANTHRAX - if(javaMimetypeHandler) - lo_SetJavaArgs((char*)tag->data, state->current_java); -#endif /* ANTHRAX */ } } #endif /* JAVA */ @@ -1129,7 +1152,6 @@ static void lo_SetClassID(PA_Tag* tag, char* appletName) { uint32 appletNameLen, oldTagLen, newTagLen; char* tagData; - char foo; appletNameLen = XP_STRLEN(appletName); oldTagLen = XP_STRLEN((char*)tag->data); @@ -1273,23 +1295,21 @@ static char* lo_GetNextValue(char** tag) /* - lo_SetJavaArgs + lo_SetArgs -------------- - Extracts every param and passes them as arguements to the Java applet. + Extracts every param and passes them as arguments to the Java applet. Here is the mapping: <... X=Y ...> becomes equivalent to NOTE: lo_GetNextName() lo_GetNextValue() and allocates new memory for the return values. 10.7.97 amusil */ -#ifdef JAVA -static void lo_SetJavaArgs(char* tag, LO_JavaAppStruct* current_java) + +static void lo_SetArgs(char* tag, lo_ObjectStack* top) { char* paramName; char* paramValue; char* index; - Bool is_percent; - int32 val; index = tag; while(TRUE) @@ -1299,52 +1319,26 @@ static void lo_SetJavaArgs(char* tag, LO_JavaAppStruct* current_java) break; /* always map data to src */ - if(!strcasecomp(paramName, "data")) + if(!XP_STRCASECMP(paramName, "data")) { XP_FREE(paramName); paramName = XP_STRDUP("src"); } paramValue = lo_GetNextValue(&index); - - /* Check if the user specified a % for height and width */ - if(!strcasecmp(paramName, "height")) - { - val = lo_ValueOrPercent(paramValue, &is_percent); - if(is_percent) - { - XP_FREE(paramValue); - /* int32 cannot exceed 10 digits */ - paramValue = XP_ALLOC(11 * sizeof(char)); - lo_itoa(current_java->height, paramValue); - } - } - - if(!strcasecmp(paramName, "width")) - { - val = lo_ValueOrPercent(paramValue, &is_percent); - if(is_percent) - { - XP_FREE(paramValue); - /* int32 cannot exceed 10 digits */ - paramValue = XP_ALLOC(11 * sizeof(char)); - lo_itoa(current_java->width, paramValue); - } - } /* increment and resize array */ - ++(current_java->parameters.n); - current_java->parameters.names = XP_REALLOC(current_java->parameters.names, current_java->parameters.n*sizeof(char*)); - XP_ASSERT(current_java->parameters.names); - current_java->parameters.values = XP_REALLOC(current_java->parameters.values, current_java->parameters.n*sizeof(char*)); - XP_ASSERT(current_java->parameters.values); + ++(top->parameters.n); + top->parameters.names = XP_REALLOC(top->parameters.names, top->parameters.n*sizeof(char*)); + XP_ASSERT(top->parameters.names); + top->parameters.values = XP_REALLOC(top->parameters.values, top->parameters.n*sizeof(char*)); + XP_ASSERT(top->parameters.values); /* point the new array elements to the newly allocated paramName and paramValue */ - current_java->parameters.names[current_java->parameters.n-1] = paramName; - current_java->parameters.values[current_java->parameters.n-1] = paramValue; + top->parameters.names[top->parameters.n-1] = paramName; + top->parameters.values[top->parameters.n-1] = paramValue; } } -#endif static void lo_itoa(uint32 n, char* s) { @@ -1376,4 +1370,63 @@ static void lo_ReverseString(char* s) } } +static void lo_RemoveParam(PA_Tag* tag, char* name) +{ + char* start, *end; + char* tagData = (char*)tag->data; + start = XP_STRCASESTR(tagData, name); + if(start != NULL) + { + end = start; + + /* advance to the = */ + while(*end != '=') + ++end; + + /* skip the = */ + ++end; + + /* advance through whitespace */ + while(*end == ' ') + ++end; + + /* advance until we hit whitespace again */ + while(*end != ' ') + ++end; + + /* clear it out */ + while(start != end) + { + *start = ' '; + ++start; + } + } +} + +static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue) +{ + uint32 nameLen, valueLen, oldTagLen, newTagLen; + char* tagData; + + nameLen = XP_STRLEN(aName); + valueLen = XP_STRLEN(aValue); + oldTagLen = XP_STRLEN((char*)(tag->data)); + newTagLen = oldTagLen + nameLen + valueLen + 3; + + tag->data = XP_REALLOC(tag->data, newTagLen+1); + + /* Remove the '>' character */ + tagData = (char*)(tag->data); + tagData[oldTagLen-1] = 0; + + /* Add "aName=aValue" */ + XP_STRCAT(tagData, " "); + XP_STRCAT(tagData, aName); + XP_STRCAT(tagData, "="); + XP_STRCAT(tagData, aValue); + XP_STRCAT(tagData, " >"); + + tag->data_len = newTagLen; +} + #endif /* ANTHRAX */ diff --git a/lib/layout/laytags.c b/lib/layout/laytags.c index c2fa50bcced4..98fd58f3790f 100644 --- a/lib/layout/laytags.c +++ b/lib/layout/laytags.c @@ -90,9 +90,14 @@ /* Added to encapsulate code that was previously in six different places in LO_LayoutTag()! */ static void lo_ProcessFontTag( lo_DocState *state, PA_Tag *tag, int32 fontSpecifier, int32 attrSpecifier ); +static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue); + #ifdef OJI #define JAVA_PLUGIN_MIMETYPE "application/x-java-vm" -static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue); +#endif + +#ifdef ANTHRAX +static void lo_RemoveParam(PA_Tag* tag, char* name); #endif /************************************* @@ -1316,7 +1321,7 @@ static void lo_process_span_tag(MWContext *context, lo_DocState *state, PA_Tag *tag) { LO_SpanStruct *span; - PA_Block buff; + PA_Block buf; lo_DocLists *doc_lists; doc_lists = lo_GetCurrentDocLists(state); @@ -6605,6 +6610,12 @@ XP_TRACE(("lo_LayoutTag(%d)\n", tag->type)); case P_EMBED: if (tag->is_end == FALSE && !state->hide_content) { +#ifdef ANTHRAX + PA_Block buff; + NET_cinfo* fileInfo; + char* str; + char* appletName; +#endif /* * If we have started loading an EMBED we are * out if the HEAD section of the HTML @@ -6612,7 +6623,44 @@ XP_TRACE(("lo_LayoutTag(%d)\n", tag->type)); */ state->top_state->in_head = FALSE; state->top_state->in_body = TRUE; + +#ifdef ANTHRAX + /* determine the mimetype */ + buff = lo_FetchParamValue(context, tag, PARAM_TYPE); + if(buff == NULL) + { + /* get SRC */ + buff = lo_FetchParamValue(context, tag, PARAM_SRC); + PA_LOCK(str, char *, buff); + + /* if we didn't find a type param, look for an association in the SRC */ + fileInfo = NET_cinfo_find_type(str); + str = fileInfo->type; + } + else + PA_LOCK(str, char *, buff); + + /* check to see if this mimetype has an applet handler */ + if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL) + { + PA_UNLOCK(buff); + if(buff) + XP_FREE(buff); + + //lo_AddParam(tag, "CODE", appletName); + //lo_RemoveParam(tag, "type"); + //lo_AddParam(tag, "TYPE", "application/x-java-vm"); + //lo_FormatEmbed(context, state, tag); + + lo_ProcessObjectTag(context, state, tag, FALSE); + tag->is_end = TRUE; + lo_ProcessObjectTag(context, state, tag, FALSE); + } + else + lo_FormatEmbed(context, state, tag); +#else lo_FormatEmbed(context, state, tag); +#endif /* ANTHRAX */ } break; @@ -7581,7 +7629,41 @@ void lo_PostLayoutTag(MWContext * context, lo_DocState *state, PA_Tag *tag, XP_B #endif /* PICS_SUPPORT */ } -#ifdef OJI +#ifdef ANTHRAX +static void lo_RemoveParam(PA_Tag* tag, char* name) +{ + char* start, *end; + char* tagData = (char*)tag->data; + start = XP_STRCASESTR(tagData, name); + if(start != NULL) + { + end = start; + + /* advance to the = */ + while(*end != '=') + ++end; + + /* skip the = */ + ++end; + + /* advance through whitespace */ + while(*end == ' ') + ++end; + + /* advance until we hit whitespace again */ + while(*end != ' ') + ++end; + + /* clear it out */ + while(start != end) + { + *start = ' '; + ++start; + } + } +} +#endif + static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue) { uint32 nameLen, valueLen, oldTagLen, newTagLen; @@ -7607,5 +7689,4 @@ static void lo_AddParam(PA_Tag* tag, char* aName, char* aValue) tag->data_len = newTagLen; } -#endif /* OJI */ diff --git a/modules/plugin/src/npglue.cpp b/modules/plugin/src/npglue.cpp index b07da97e09ba..6388c8448b8a 100644 --- a/modules/plugin/src/npglue.cpp +++ b/modules/plugin/src/npglue.cpp @@ -1366,7 +1366,10 @@ np_posturlinternal(NPP npp, const char* relativeURL, const char *target, } } else - return NPERR_OUT_OF_MEMORY_ERROR; + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } /* * FTP protocol requires that the data be in a file. @@ -3163,7 +3166,7 @@ NPL_NewPresentStream(FO_Present_Types format_out, void* type, URL_Struct* urls, strLen = XP_STRLEN(fileName); - newTag = XP_ALLOC((36+strLen)*sizeof(char)); + newTag = (char*)XP_ALLOC((36+strLen)*sizeof(char)); newTag[0] = 0; XP_STRCAT(newTag, "next) { - if(!XP_STRCMP(handle->name, type)) + if(!XP_STRCMP(handle->name, type) && !XP_STRCMP(handle->filename, filename)) break; } @@ -5387,6 +5391,7 @@ NPL_RegisterAppletType(NPMIMEType type) return NPERR_OUT_OF_MEMORY_ERROR; StrAllocCopy(handle->name, type); + StrAllocCopy(handle->filename, filename); handle->pdesc = NULL; handle->next = np_alist; @@ -5397,27 +5402,77 @@ NPL_RegisterAppletType(NPMIMEType type) /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ if (!wildtype) NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ #else if (!wildtype) - { NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); -#ifdef XP_UNIX - /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want - * plugin to possibly handle that case too. Hence this. - */ - NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, - NPL_NewPresentStream); -#endif /* XP_UNIX */ - } - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); #endif - NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); - NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + + newPref = np_CreateMimePref(type, "load_action"); + PREF_SetIntPref(newPref, 5); + XP_FREE(newPref); return NPERR_NO_ERROR; } +void +NPL_InstallAppletHandler(char* appletName, char* mimetype, char* extension) +{ + char* newPref; + char buffer[100]; + int32 numApplets; + int bufLen = 100; + + /* check if it's an entirely new mimetype */ + newPref = np_CreateMimePref(mimetype, "mimetype"); + if(PREF_GetCharPref(newPref, buffer, &bufLen) != PREF_OK) + { + PREF_SetCharPref(newPref, mimetype); + XP_FREE(newPref); + + newPref = np_CreateMimePref(mimetype, "extension"); + PREF_SetCharPref(newPref, extension); + } + XP_FREE(newPref); + + newPref = np_CreateMimePref(mimetype, "num_applets"); + + /* check if this is the first applet installed for this mimetype */ + if(PREF_GetIntPref(newPref, &numApplets) != PREF_OK) + { + /* First Applet installed for mimetype */ + PREF_SetIntPref(newPref, 1); + XP_FREE(newPref); + + newPref = np_CreateMimePref(mimetype, "applet1"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + + newPref = np_CreateMimePref(mimetype, "applet"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + } + else + { + char appletN[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; + ++numApplets; + PREF_SetIntPref(newPref, numApplets); + XP_FREE(newPref); + + XP_ASSERT(numApplets < 10); + appletN[6] = (numApplets+48); + newPref = np_CreateMimePref(mimetype, appletN); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + + /* Set the new Applet as the default */ + newPref = np_CreateMimePref(mimetype, "applet"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + } + + NPL_RegisterAppletType(mimetype, appletName); +} + /* ANTHRAX STATIC FUNCTIONS */ /* @@ -5500,7 +5555,7 @@ static char* np_CreateMimePref(const char* mimetype, const char* pref) len = XP_STRLEN("mime..") + XP_STRLEN(mimetype) + XP_STRLEN(pref); - prefName = XP_ALLOC((len+1)*sizeof(char)); + prefName = (char*)XP_ALLOC((len+1)*sizeof(char)); XP_ASSERT(prefName); if(!prefName) return NULL;