dom/plugins/base/nsPluginsDirUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsPluginsDirUtils_h___
michael@0 7 #define nsPluginsDirUtils_h___
michael@0 8
michael@0 9 #include "nsPluginsDir.h"
michael@0 10 #include "nsTArray.h"
michael@0 11 #include "prmem.h"
michael@0 12
michael@0 13 ///////////////////////////////////////////////////////////////////////////////
michael@0 14 // Output format from NPP_GetMIMEDescription: "...mime type[;version]:[extension]:[desecription];..."
michael@0 15 // The ambiguity of mime description could cause the browser fail to parse the MIME types
michael@0 16 // correctly.
michael@0 17 // E.g. "mime type::desecription;" // correct w/o ext
michael@0 18 // "mime type:desecription;" // wrong w/o ext
michael@0 19 //
michael@0 20 static nsresult
michael@0 21 ParsePluginMimeDescription(const char *mdesc, nsPluginInfo &info)
michael@0 22 {
michael@0 23 nsresult rv = NS_ERROR_FAILURE;
michael@0 24 if (!mdesc || !*mdesc)
michael@0 25 return rv;
michael@0 26
michael@0 27 char *mdescDup = PL_strdup(mdesc); // make a dup of intput string we'll change it content
michael@0 28 char anEmptyString[] = "";
michael@0 29 nsAutoTArray<char*, 8> tmpMimeTypeArr;
michael@0 30 char delimiters[] = {':',':',';'};
michael@0 31 int mimeTypeVariantCount = 0;
michael@0 32 char *p = mdescDup; // make a dup of intput string we'll change it content
michael@0 33 while(p) {
michael@0 34 char *ptrMimeArray[] = {anEmptyString, anEmptyString, anEmptyString};
michael@0 35
michael@0 36 // It's easy to point out ptrMimeArray[0] to the string sounds like
michael@0 37 // "Mime type is not specified, plugin will not function properly."
michael@0 38 // and show this on "about:plugins" page, but we have to mark this particular
michael@0 39 // mime type of given plugin as disable on "about:plugins" page,
michael@0 40 // which feature is not implemented yet.
michael@0 41 // So we'll ignore, without any warnings, an empty description strings,
michael@0 42 // in other words, if after parsing ptrMimeArray[0] == anEmptyString is true.
michael@0 43 // It is possible do not to registry a plugin at all if it returns
michael@0 44 // an empty string on GetMIMEDescription() call,
michael@0 45 // e.g. plugger returns "" if pluggerrc file is not found.
michael@0 46
michael@0 47 char *s = p;
michael@0 48 int i;
michael@0 49 for (i = 0; i < (int) sizeof(delimiters) && (p = PL_strchr(s, delimiters[i])); i++) {
michael@0 50 ptrMimeArray[i] = s; // save start ptr
michael@0 51 *p++ = 0; // overwrite delimiter
michael@0 52 s = p; // move forward
michael@0 53 }
michael@0 54 if (i == 2)
michael@0 55 ptrMimeArray[i] = s;
michael@0 56 // fill out the temp array
michael@0 57 // the order is important, it should be the same in for loop below
michael@0 58 if (ptrMimeArray[0] != anEmptyString) {
michael@0 59 tmpMimeTypeArr.AppendElement(ptrMimeArray[0]);
michael@0 60 tmpMimeTypeArr.AppendElement(ptrMimeArray[1]);
michael@0 61 tmpMimeTypeArr.AppendElement(ptrMimeArray[2]);
michael@0 62 mimeTypeVariantCount++;
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 // fill out info structure
michael@0 67 if (mimeTypeVariantCount) {
michael@0 68 info.fVariantCount = mimeTypeVariantCount;
michael@0 69 // we can do these 3 mallocs at once, later on code cleanup
michael@0 70 info.fMimeTypeArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
michael@0 71 info.fMimeDescriptionArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
michael@0 72 info.fExtensionArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
michael@0 73
michael@0 74 int j,i;
michael@0 75 for (j = i = 0; i < mimeTypeVariantCount; i++) {
michael@0 76 // the order is important, do not change it
michael@0 77 // we can get rid of PL_strdup here, later on code cleanup
michael@0 78 info.fMimeTypeArray[i] = PL_strdup(tmpMimeTypeArr.ElementAt(j++));
michael@0 79 info.fExtensionArray[i] = PL_strdup(tmpMimeTypeArr.ElementAt(j++));
michael@0 80 info.fMimeDescriptionArray[i] = PL_strdup(tmpMimeTypeArr.ElementAt(j++));
michael@0 81 }
michael@0 82 rv = NS_OK;
michael@0 83 }
michael@0 84 if (mdescDup)
michael@0 85 PR_Free(mdescDup);
michael@0 86 return rv;
michael@0 87 }
michael@0 88
michael@0 89 #endif /* nsPluginsDirUtils_h___ */

mercurial