b=450088 backing out (new reftest failed)
[wine-gecko.git] / modules / oji / src / nsJVMPluginTagInfo.cpp
blobca56e61bf7fe2b0e328cd489127ce6e1306bf14f
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
13 * License.
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.
22 * Contributor(s):
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"
40 #include "plstr.h"
41 #include "nsCRT.h" // mixing metaphors with plstr.h!
42 #ifdef XP_UNIX
43 #undef Bool
44 #endif
46 static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
48 ////////////////////////////////////////////////////////////////////////////////
49 // nsJVMPluginTagInfo
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);
63 if (fSimulatedCode)
64 PL_strfree(fSimulatedCode);
67 NS_IMPL_AGGREGATED(nsJVMPluginTagInfo)
68 NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsJVMPluginTagInfo)
69 NS_INTERFACE_MAP_ENTRY(nsIJVMPluginTagInfo)
70 NS_INTERFACE_MAP_END
73 static void
74 oji_StandardizeCodeAttribute(char* buf)
76 // strip off the ".class" suffix
77 char* cp;
79 if ((cp = PL_strrstr(buf, ".class")) != NULL)
80 *cp = '\0';
82 // Convert '/' to '.'
83 cp = buf;
84 while ((*cp) != '\0') {
85 if ((*cp) == '/')
86 (*cp) = '.';
88 ++cp;
92 NS_METHOD
93 nsJVMPluginTagInfo::GetCode(const char* *result)
95 if (fSimulatedCode) {
96 *result = fSimulatedCode;
97 return NS_OK;
100 const char* code;
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;
106 return NS_OK;
109 const char* classid;
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;
115 return NS_OK;
118 // XXX what about "javaprogram:" and "javabean:"?
119 return NS_ERROR_FAILURE;
122 NS_METHOD
123 nsJVMPluginTagInfo::GetCodeBase(const char* *result)
125 // If we've already cached and computed the value, use it...
126 if (fSimulatedCodebase) {
127 *result = fSimulatedCodebase;
128 return NS_OK;
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) {
135 *result = codebase;
136 return NS_OK;
139 // Okay, we'll need to simulate it from the layout tag's base URL.
140 const char* docBase;
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;
155 return NS_OK;
158 NS_METHOD
159 nsJVMPluginTagInfo::GetArchive(const char* *result)
161 return fPluginTagInfo->GetAttribute("archive", result);
164 NS_METHOD
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;
171 switch (type) {
172 case nsPluginTagType_Applet:
173 attrName = "name";
174 break;
175 default:
176 attrName = "id";
177 break;
179 return fPluginTagInfo->GetAttribute(attrName, result);
182 NS_METHOD
183 nsJVMPluginTagInfo::GetMayScript(PRBool *result)
185 const char* attr;
186 *result = PR_FALSE;
188 nsresult err = fPluginTagInfo->GetAttribute("mayscript", &attr);
189 if (err) return err;
191 if (PL_strcasecmp(attr, "true") == 0)
193 *result = PR_TRUE;
195 return NS_OK;
198 NS_METHOD
199 nsJVMPluginTagInfo::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
200 nsIPluginTagInfo2* info)
202 if(!aInstancePtr)
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;
218 return result;
220 error:
221 delete jvmTagInfo;
222 return result;
225 ////////////////////////////////////////////////////////////////////////////////