~ps-jenkins/unity-chromium-extension/trusty-proposed

« back to all changes in this revision

Viewing changes to chromium-extension/extension-tools.js

  • Committer: Tarmac
  • Author(s): Alexandre Abreu
  • Date: 2013-09-16 15:40:39 UTC
  • mfrom: (227.1.5 latest)
  • Revision ID: tarmac-20130916154039-oj5t4j3stjrog9sz
Release version 3.0
Remove tab integration
Keep webapps installation scheme
Keep website api injection but only handle the init() w/ a default desktop file generated to launch the webbrowser-app in chromeless mode
.

Approved by PS Jenkins bot, Robert Bruce Park.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Chromium Unity integration extension
2
 
 * 
3
 
 *   Copyright 2012 Canonical Ltd.
4
 
 *
5
 
 *   This program is free software: you can redistribute it and/or modify it 
6
 
 *   under the terms of the GNU General Public License version 3, as published 
7
 
 *   by the Free Software Foundation.
8
 
 *
9
 
 *  This program is distributed in the hope that it will be useful, but 
10
 
 *   WITHOUT ANY WARRANTY; without even the implied warranties of 
11
 
 *   MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
12
 
 *   PURPOSE.  See the GNU General Public License for more details.
13
 
 *
14
 
 *   You should have received a copy of the GNU General Public License along 
15
 
 *   with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 **/
17
 
 
18
 
// this is meant to be removed once we settle on a common infrastructure for
19
 
// FF & chromium for implementation specific things (e.g. TLD, logs, imports, ...)
20
 
 
21
 
var Components = {
22
 
    utils: {
23
 
        import: function (resource) {
24
 
            if ( ! resource || ! typeof (resource) === 'string') {
25
 
                return;
26
 
            }
27
 
            
28
 
            var resourceQualifier = 'resource://';
29
 
            
30
 
            if (resource.indexOf (resourceQualifier) == -1) {
31
 
                return;
32
 
            }
33
 
                
34
 
            // very hacky, we don't have the same structure as FF (should)
35
 
            // so we dont consider paths
36
 
            var idx = resource.lastIndexOf ('/');
37
 
            if (idx == -1) {
38
 
                return;
39
 
            }
40
 
            
41
 
            var getResourceContent = function (resourcename) {
42
 
                var content = null;
43
 
                var xhr = new XMLHttpRequest();
44
 
                
45
 
                xhr.onreadystatechange = function() {
46
 
                    if (xhr.readyState == 4) {
47
 
                        content = xhr.responseText;
48
 
                    }
49
 
                };
50
 
                // mmh blocking
51
 
                xhr.open("GET", resourcename, false);
52
 
                
53
 
                try { xhr.send(); } catch(e) { }
54
 
                
55
 
                return content;
56
 
            };
57
 
            
58
 
            var content = getResourceContent (chrome.runtime.getURL (resource.slice (idx+1)));
59
 
            
60
 
            if (   null != content
61
 
                   && typeof (content) === 'string'
62
 
                   && 0 != content.length) {
63
 
                
64
 
                /// yeah! eval!
65
 
                try {
66
 
                    eval.call (window, content);
67
 
                } 
68
 
                catch (e) {
69
 
                    // mmmh ?
70
 
                    console.log ('Components.utils.import: ' + String(e));
71
 
                }
72
 
            }
73
 
        }
74
 
    }
75
 
};
76
 
 
77
 
 
78
 
/*var consoleService = {
79
 
    logStringMessage: function (msg) {
80
 
        if (settings && settings.logging) {
81
 
            console.log (msg);
82
 
        }
83
 
    }
84
 
};*/
85
 
                                  
86