-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoginWidget.cs
65 lines (54 loc) · 1.99 KB
/
LoginWidget.cs
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
using System.Net;
using Banshee.WebBrowser;
using Banshee.WebSource;
namespace Banshee.GoogleMusic
{
public class LoginWidget : WebView
{
private static readonly Cookie[] REQUIRED_COOKIES = new Cookie[] {
new Cookie("SID", "", "/", ".google.com"),
new Cookie("HSID", "", "/", ".google.com"),
new Cookie("SSID", "", "/", ".google.com"),
new Cookie("APISID", "", "/", ".google.com"),
new Cookie("SAPISID", "", "/", ".google.com"),
new Cookie("sjsaid", "", "/music", "play.google.com"),
new Cookie("xt", "", "/music", "play.google.com"),
};
public LoginWidget()
{
OssiferSession.CookieChanged += CookiesChanged;
FullReload();
}
public delegate void UserLoggedInHandler(Cookie[] cookies);
public event UserLoggedInHandler UserLoggedIn;
private static Cookie fromOssiferCookie(OssiferCookie cookie) {
Cookie ret = new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain);
ret.HttpOnly = cookie.HttpOnly;
ret.Secure = cookie.Secure;
return ret;
}
private void CookiesChanged(OssiferCookie oldCookies, OssiferCookie newCookies)
{
bool allCookiesAreAvailable = true;
foreach (Cookie cookie in REQUIRED_COOKIES) {
OssiferCookie ossiferCookie = OssiferSession.GetCookie(cookie.Name, cookie.Domain, cookie.Path);
if (ossiferCookie == null || string.IsNullOrEmpty(ossiferCookie.Value))
allCookiesAreAvailable = false;
}
if (allCookiesAreAvailable && UserLoggedIn != null) {
Cookie[] cookies = new Cookie[REQUIRED_COOKIES.Length];
for (int i=0; i < REQUIRED_COOKIES.Length; i++) {
Cookie requiredCookie = REQUIRED_COOKIES[i];
cookies[i] = fromOssiferCookie(OssiferSession.GetCookie(requiredCookie.Name, requiredCookie.Domain, requiredCookie.Path));
}
UserLoggedIn(cookies);
/* remove self from CookieChanged, so we only alert the user once */
OssiferSession.CookieChanged -= CookiesChanged;
}
}
public override void GoHome()
{
LoadUri("http://play.google.com/music");
}
}
}