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