My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!--
Copyright 2010 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<style type="text/css">
body {
padding: 0px;
margin: 1px;
min-width: 320px;
overflow: hidden;
background-image: -webkit-gradient(radial, 50% 10%, 10, 50% 10%, 400, from(#f1f8eb), to(#FFF));
}

td {
font-family: verdana;
font-size: 12px;
color: black;
}
</style>

<script src="chrome_ex_oauthsimple.js"></script>
<script src="chrome_ex_oauth.js"></script>
<script src="send_logic.js"></script>
<script>
function loadHandler() {
document.getElementById('help').innerHTML = chrome.i18n.getMessage('help_message');

if (oauth.hasToken()) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sending_message');
document.getElementById('signout').innerHTML = chrome.i18n.getMessage('sign_out_message');

chrome.tabs.getSelected(null, function(tab) {
if (tab.url.indexOf('http:') == 0 ||
tab.url.indexOf('https:') == 0) {
chrome.tabs.executeScript(null, {file: "content_script.js"});
} else {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('invalid_scheme_message');
}
});
} else {
// we need the options page to show signin
activateSignInLink("chrome.tabs.create({url: 'oauth_interstitial.html'})");
}
}

function sendToPhoneListener(status, responseText) {
if (status == STATUS_SUCCESS) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sent_message');
activateSignOutLink();
} else if (status == STATUS_LOGIN_REQUIRED) {
activateSignInLink("chrome.tabs.create({url: 'help.html?fromPopup=1'})"); // token revoked
} else if (status == STATUS_DEVICE_NOT_REGISTERED) {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('device_not_registered_message');
activateSignOutLink();
} else {
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('error_sending_message', responseText);
activateSignOutLink();
}
}

chrome.extension.onConnect.addListener(function(port) {
// This will get called by the content script. We go through
// these hoops to get the optional text selection.
port.onMessage.addListener(function(info) {
var msgType = (info.selection && info.selection.length > 0) ? 'selection' : 'page';
sendToPhone(info.title, info.url, msgType, info.selection, sendToPhoneListener);
});
});

function setSignOutVisibility(visible) {
var signOutLink = document.getElementById('signout');
signOutLink.style.visibility = visible ? 'visible' : 'hidden';
var sep = document.getElementById('sep');
sep.style.visibility = visible ? 'visible' : 'hidden';
}

function activateSignOutLink() {
setSignOutVisibility(true);
var signOutLink = document.getElementById('signout');
signOutLink.innerHTML = chrome.i18n.getMessage('sign_out_message');
signOutLink.style.color = 'blue';
signOutLink.onclick = function() {
chrome.extension.getBackgroundPage().closeBrowserChannel();
oauth.clearTokens();
window.close();
}
}

function activateSignInLink(onclick) {
var link = '<a href="#" onclick="' + onclick + '">' +
chrome.i18n.getMessage('sign_in_message') + '</a>';
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('sign_in_required_message', link);
setSignOutVisibility(false);
}

</script>

<body onload="loadHandler()">
<table>
<tr>
<td><img src="icon_48.png" style="margin-right: 4px;"/></td>
<td width="100%" valign="middle">
<b><div id="msg"></div></b>
<p><a id="help" href="#" onclick="chrome.tabs.create({url: 'help.html'})"></a> <span id="sep">|</span>
<a id="signout" href="#" style="color: gray;"></a></p>
</td>
<td valign="top"><a href="#" onclick="window.close()"><img src="popup_close.png" style="margin: 2px;"></a></td>
</tr>
</table>
</body>

Change log

r254 by burke.davey on May 4, 2011   Diff
- Fix race condition bug in getting access
token.
- Cosmetic improvements to flow.
- Make sure browser channel starts and
stops properly.
- s/tabs/2-spaces.
Go to: 
Project members, sign in to write a code review

Older revisions

r252 by burke.davey on May 2, 2011   Diff
Small bug fix.
r251 by costin on Apr 27, 2011   Diff
Use the non-live version which has the
required changes, fix a bug in the
error path.

r249 by costin on Apr 27, 2011   Diff
Switch to OAuth1 for authentication,
using the chrome example javascript
files.
Few small changes on how login/logout
state is displayed and detected.
...
All revisions of this file

File info

Size: 4395 bytes, 124 lines
Powered by Google Project Hosting