1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsJVMPluginTagInfo.h"
39 #include "nsIPluginTagInfo2.h"
41 #include "nsCRT.h" // mixing metaphors with plstr.h!
46 static NS_DEFINE_IID(kIPluginTagInfo2IID
, NS_IPLUGINTAGINFO2_IID
);
48 ////////////////////////////////////////////////////////////////////////////////
50 ////////////////////////////////////////////////////////////////////////////////
52 nsJVMPluginTagInfo::nsJVMPluginTagInfo(nsISupports
* outer
, nsIPluginTagInfo2
* info
)
53 : fPluginTagInfo(info
), fSimulatedCodebase(NULL
), fSimulatedCode(NULL
)
55 NS_INIT_AGGREGATED(outer
);
58 nsJVMPluginTagInfo::~nsJVMPluginTagInfo(void)
60 if (fSimulatedCodebase
)
61 PL_strfree(fSimulatedCodebase
);
64 PL_strfree(fSimulatedCode
);
67 NS_IMPL_AGGREGATED(nsJVMPluginTagInfo
)
68 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsJVMPluginTagInfo
)
69 NS_INTERFACE_MAP_ENTRY(nsIJVMPluginTagInfo
)
74 oji_StandardizeCodeAttribute(char* buf
)
76 // strip off the ".class" suffix
79 if ((cp
= PL_strrstr(buf
, ".class")) != NULL
)
84 while ((*cp
) != '\0') {
93 nsJVMPluginTagInfo::GetCode(const char* *result
)
96 *result
= fSimulatedCode
;
101 nsresult err
= fPluginTagInfo
->GetAttribute("code", &code
);
102 if (err
== NS_OK
&& code
) {
103 fSimulatedCode
= PL_strdup(code
);
104 oji_StandardizeCodeAttribute(fSimulatedCode
);
105 *result
= fSimulatedCode
;
110 err
= fPluginTagInfo
->GetAttribute("classid", &classid
);
111 if (err
== NS_OK
&& classid
&& PL_strncasecmp(classid
, "java:", 5) == 0) {
112 fSimulatedCode
= PL_strdup(classid
+ 5); // skip "java:"
113 oji_StandardizeCodeAttribute(fSimulatedCode
);
114 *result
= fSimulatedCode
;
118 // XXX what about "javaprogram:" and "javabean:"?
119 return NS_ERROR_FAILURE
;
123 nsJVMPluginTagInfo::GetCodeBase(const char* *result
)
125 // If we've already cached and computed the value, use it...
126 if (fSimulatedCodebase
) {
127 *result
= fSimulatedCodebase
;
131 // See if it's supplied as an attribute...
132 const char* codebase
;
133 nsresult err
= fPluginTagInfo
->GetAttribute("codebase", &codebase
);
134 if (err
== NS_OK
&& codebase
!= NULL
) {
139 // Okay, we'll need to simulate it from the layout tag's base URL.
141 err
= fPluginTagInfo
->GetDocumentBase(&docBase
);
142 if (err
!= NS_OK
) return err
;
143 codebase
= (const char*) docBase
;
145 if ((fSimulatedCodebase
= PL_strdup(codebase
)) != NULL
) {
146 char* lastSlash
= PL_strrchr(fSimulatedCodebase
, '/');
148 // chop of the filename from the original document base URL to
149 // generate the codebase.
150 if (lastSlash
!= NULL
)
151 *(lastSlash
+ 1) = '\0';
154 *result
= fSimulatedCodebase
;
159 nsJVMPluginTagInfo::GetArchive(const char* *result
)
161 return fPluginTagInfo
->GetAttribute("archive", result
);
165 nsJVMPluginTagInfo::GetName(const char* *result
)
167 const char* attrName
;
168 nsPluginTagType type
;
169 nsresult err
= fPluginTagInfo
->GetTagType(&type
);
170 if (err
!= NS_OK
) return err
;
172 case nsPluginTagType_Applet
:
179 return fPluginTagInfo
->GetAttribute(attrName
, result
);
183 nsJVMPluginTagInfo::GetMayScript(PRBool
*result
)
188 nsresult err
= fPluginTagInfo
->GetAttribute("mayscript", &attr
);
191 if (PL_strcasecmp(attr
, "true") == 0)
199 nsJVMPluginTagInfo::Create(nsISupports
* outer
, const nsIID
& aIID
, void* *aInstancePtr
,
200 nsIPluginTagInfo2
* info
)
203 return NS_ERROR_INVALID_POINTER
;
205 if (outer
&& !aIID
.Equals(NS_GET_IID(nsISupports
)))
206 return NS_ERROR_INVALID_ARG
;
208 nsJVMPluginTagInfo
* jvmTagInfo
= new nsJVMPluginTagInfo(outer
, info
);
209 if (jvmTagInfo
== NULL
)
210 return NS_ERROR_OUT_OF_MEMORY
;
212 nsresult result
= jvmTagInfo
->AggregatedQueryInterface(aIID
, aInstancePtr
);
213 if (NS_FAILED(result
)) goto error
;
215 result
= jvmTagInfo
->QueryInterface(kIPluginTagInfo2IID
,
216 (void**)&jvmTagInfo
->fPluginTagInfo
);
217 if (NS_FAILED(result
)) goto error
;
225 ////////////////////////////////////////////////////////////////////////////////