~ubuntu-branches/debian/stretch/downthemall/stretch

« back to all changes in this revision

Viewing changes to modules/support/iconcheat.jsm

  • Committer: Package Import Robot
  • Author(s): Michael Meskes
  • Date: 2016-09-21 13:33:55 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20160921133355-ylst3mzzo82mghyw
Tags: upstream-3.0.6
ImportĀ upstreamĀ versionĀ 3.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* You may find the license in the LICENSE file */
2
 
 
3
 
const EXPORTED_SYMBOLS = ['loadWindow'];
4
 
 
5
 
const Cc = Components.classes;
6
 
const Ci = Components.interfaces;
7
 
const Cr = Components.results;
8
 
const Cu = Components.utils;
9
 
const Ctor = Components.Constructor;
10
 
const Exception = Components.Exception;
11
 
 
12
 
function loadWindow() {};
13
 
 
14
 
try {
15
 
        // moz-1.9.3+
16
 
        Cu.import("resource://gre/modules/AddonManager.jsm");
17
 
        
18
 
        const ZipReader = Ctor("@mozilla.org/libjar/zip-reader;1", "nsIZipReader", "open");
19
 
        
20
 
        Cu.import("resource://dta/version.jsm");
21
 
        Cu.import("resource://gre/modules/XPCOMUtils.jsm");
22
 
        
23
 
        const DirectoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
24
 
        if (!(DirectoryService instanceof Ci.nsIDirectoryService)) {
25
 
                throw new Exception("eek");
26
 
        }
27
 
        let profileDir = DirectoryService.get("ProfD", Ci.nsILocalFile);
28
 
        let iconDir = profileDir.clone();
29
 
        iconDir.append('icons');
30
 
        iconDir.append('default');
31
 
        
32
 
        // xpi version
33
 
        function extract(file) {
34
 
                let jar = new ZipReader(file);
35
 
                let entries = jar.findEntries("chrome/icons/default/*.(ico|png|xpm)$");
36
 
                while (entries.hasMore()) {
37
 
                        let entry = entries.getNext();
38
 
                        try {
39
 
                                let name = entry.split(/[/\\]/).pop();
40
 
                                let dst = iconDir.clone();
41
 
                                dst.append(name);
42
 
                                jar.extract(entry, dst);
43
 
                        }
44
 
                        catch (ex) {
45
 
                                Cu.reportError(ex);
46
 
                        }
47
 
                }
48
 
        }
49
 
        
50
 
        // flat-package version
51
 
        function copy(directory) {
52
 
                let srcDirectory = directory.clone();
53
 
                srcDirectory.append('chrome');
54
 
                srcDirectory.append('icons');
55
 
                srcDirectory.append('default');
56
 
                let icons = srcDirectory.directoryEntries;
57
 
                while (icons.hasMoreElements()) {
58
 
                        let icon = icons.getNext();
59
 
                        if ((icon instanceof Ci.nsIFile) && icon.isFile()) {
60
 
                                try {
61
 
                                        icon.copyTo(iconDir, icon.leafName);
62
 
                                }
63
 
                                catch (ex) {
64
 
                                        // no op
65
 
                                }
66
 
                        }
67
 
                }
68
 
        }
69
 
        
70
 
        // Directory Provider we use to check the system :p
71
 
        function CheatDirProvider() {}
72
 
        CheatDirProvider.prototype = {
73
 
                hasMore: false,
74
 
                QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider, Ci.nsIDirectoryServiceProvider2, Ci.nsISimpleEnumerator]),
75
 
                getFile: function(prop, persist) {
76
 
                        throw Cr.NS_ERROR_FAILURE;
77
 
                },
78
 
                getFiles: function(prop, persist) {
79
 
                        if (prop == "AChromDL") {
80
 
                                this.hasMore = true;
81
 
                                return this;
82
 
                        } 
83
 
                        throw Cr.NS_ERROR_FAILURE;
84
 
                },
85
 
                hasMoreElements: function() this.hasMore,
86
 
                getNext: function() {
87
 
                        if (!this.hasMore) {
88
 
                                throw Cr.NS_ERROR_FAILURE;
89
 
                        }
90
 
                        this.hasMore = false;
91
 
                        return profileDir.clone();
92
 
                }
93
 
        };
94
 
        
95
 
        // Create icons if not there yet, or if we got a major version update
96
 
        if (!iconDir.exists() || Version.showAbout) {
97
 
                if (!iconDir.exists()) {
98
 
                        iconDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
99
 
                }
100
 
                AddonManager.getAddonByID(Version.ID, function(addon) {
101
 
                        let uri = addon.getResourceURI('icon.png');
102
 
                        if (uri instanceof Ci.nsIJARURI) {
103
 
                                uri = uri.JARFile;
104
 
                                if (uri instanceof Ci.nsIFileURL) {
105
 
                                        extract(uri.file);
106
 
                                }
107
 
                        }
108
 
                        else if (uri instanceof Ci.nsIFileURL) {
109
 
                                copy(uri.file.parent);
110
 
                        }
111
 
                });
112
 
        }
113
 
        
114
 
        // exported
115
 
        loadWindow = function(window) {
116
 
                let _p = new CheatDirProvider();
117
 
                DirectoryService.registerProvider(_p);
118
 
                window.addEventListener('load', function() {
119
 
                        window.removeEventListener('load', arguments.callee, true);
120
 
                        window.setTimeout(function() {
121
 
                                DirectoryService.unregisterProvider(_p);
122
 
                                delete _p;                              
123
 
                        }, 0);
124
 
                }, true);
125
 
        }       
126
 
}
127
 
catch (ex) {
128
 
        // moz-1.9.2-
129
 
        // no need to do anything;
130
 
}
 
 
b'\\ No newline at end of file'