~webapps/unity-webapps-gmail/trunk

« back to all changes in this revision

Viewing changes to GMail.user.js

  • Committer: Robert Bruce Park
  • Date: 2013-11-15 05:35:57 UTC
  • mfrom: (77.1.7 login-fix)
  • Revision ID: robert.park@canonical.com-20131115053557-rwj4woalzekxi4l5
Fix Gmail logins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
    reportTestState('PASS SELF TEST');
81
81
}
82
82
 
 
83
function validatedNode(nodeInfo) {
 
84
    var resultSet = document.evaluate(nodeInfo.query,
 
85
                                      document,
 
86
                                      null,
 
87
                                      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
 
88
                                      null);
 
89
    if (!nodeInfo.validator(resultSet.snapshotItem(0))) {
 
90
        var testNode = document.createElement("div");
 
91
        testNode.innerHTML = nodeInfo.fragment;
 
92
        resultSet = document.evaluate(nodeInfo.query, testNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
 
93
        var fragmentOk = resultSet.snapshotLength > 0 && nodeInfo.validator(resultSet.snapshotItem(0));
 
94
        reportTestState("REPORT: ERROR: Failed to validate node " + nodeInfo.name + " fragment check " + (fragmentOk ? "OK" : "failed"));
 
95
        return null;
 
96
    }
 
97
    return resultSet.snapshotItem(0);
 
98
}
 
99
 
83
100
function isCorrectPage() {
84
101
    var i, ids = ['hist_frame', 'js_frame'];
85
102
 
141
158
            setTimeout(wait, 1000);
142
159
            return;
143
160
        }
144
 
        var gmaillogin;
 
161
        var login = null;
145
162
        try {
146
 
            gmaillogin = document.evaluate('//div[@role="navigation"]/div/div[1]/div[3]/div/ol/li[4]/div/div/div/div[2]/span[2]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue.textContent;
 
163
            var loginNode = validatedNode({
 
164
                    name: 'login query',
 
165
                    query: '//div[@role="navigation"]//*[contains(text(), "@")]',
 
166
                    validator: function (node) {
 
167
                        return node.textContent.match(/^.*@.*\.{1}.*$/) !== null;
 
168
                    },
 
169
                    fragment: '<div role="navigation"><span>example@example.com</span></div>'
 
170
                });
 
171
 
 
172
            if (loginNode !== null) {
 
173
                login = loginNode.textContent;
 
174
            }
147
175
        } catch (gmail_err) {
148
 
            gmaillogin = "";
149
 
        }
150
 
 
151
 
        var gappslogin;
152
 
        try {
153
 
            gappslogin = document.evaluate('//div[@role="navigation"]/div/div[1]/div[3]/div/ol/li[4]/div/div/div/div[3]/span[2]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue.textContent;
154
 
        } catch (gapps_err) {
155
 
            gappslogin = "";
156
 
        }
157
 
 
158
 
        // in the webapp container (qtwebkit based) we get served something specific
159
 
        try {
160
 
            if (!gappslogin && !gmaillogin) {
161
 
                gmaillogin = document.evaluate('//div[@role="navigation"]/div/div[1]/div[2]/ol/li[1]/div/div/div[1]/div/span[2]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue.textContent;
162
 
            }
163
 
        } catch (err) {}
164
 
 
165
 
        var login = gmaillogin.indexOf("@") !== -1 ? gmaillogin : gappslogin.indexOf("@") !== -1 ? gappslogin : "";
 
176
        }
166
177
 
167
178
        Unity.init({ name: "Gmail",
168
179
                     login: login,