Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2821)

Side by Side Diff: Src/GoogleApis.Auth.WP/OAuth2/WebAuthenticationBrokerUserControl.xaml.cs

Issue 46440043: Issue 422: Back button doesn't work on WP Auth login page (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: minor Created 10 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright 2013 Google Inc 2 Copyright 2013 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
(...skipping 18 matching lines...) Expand all
29 /// Web authentication broker user control for retrieving <seealso cref="Aut horizationCodeResponseUrl"/> 29 /// Web authentication broker user control for retrieving <seealso cref="Aut horizationCodeResponseUrl"/>
30 /// </summary> 30 /// </summary>
31 internal partial class WebAuthenticationBrokerUserControl : UserControl 31 internal partial class WebAuthenticationBrokerUserControl : UserControl
32 { 32 {
33 TaskCompletionSource<AuthorizationCodeResponseUrl> tcsAuthorizationCodeR esponse; 33 TaskCompletionSource<AuthorizationCodeResponseUrl> tcsAuthorizationCodeR esponse;
34 34
35 /// <summary>Constructs a new authentication broker user control.</summa ry> 35 /// <summary>Constructs a new authentication broker user control.</summa ry>
36 public WebAuthenticationBrokerUserControl() 36 public WebAuthenticationBrokerUserControl()
37 { 37 {
38 InitializeComponent(); 38 InitializeComponent();
39
40 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
41 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio nPage;
42 rootPage.BackKeyPress += RootPage_BackKeyPress;
39 } 43 }
40 44
41 /// <summary>Displays the loading animation.</summary> 45 /// <summary>Displays the loading animation.</summary>
42 private void StartLoading() 46 private void StartLoading()
43 { 47 {
44 Loader.Visibility = Visibility.Visible; 48 Loader.Visibility = Visibility.Visible;
45 } 49 }
46 50
47 /// <summary>Removes the loading animation.</summary> 51 /// <summary>Removes the loading animation.</summary>
48 private void StopLoading() 52 private void StopLoading()
(...skipping 10 matching lines...) Expand all
59 var query = e.Uri.Query.Substring(1); 63 var query = e.Uri.Query.Substring(1);
60 tcsAuthorizationCodeResponse.SetResult(new AuthorizationCodeResp onseUrl(query)); 64 tcsAuthorizationCodeResponse.SetResult(new AuthorizationCodeResp onseUrl(query));
61 } 65 }
62 } 66 }
63 67
64 /// <summary>Callback of browser navigation failed.</summary> 68 /// <summary>Callback of browser navigation failed.</summary>
65 private void OnBrowserNavigationFailed(object sender, NavigationFailedEv entArgs e) 69 private void OnBrowserNavigationFailed(object sender, NavigationFailedEv entArgs e)
66 { 70 {
67 if (!tcsAuthorizationCodeResponse.Task.IsCompleted) 71 if (!tcsAuthorizationCodeResponse.Task.IsCompleted)
68 { 72 {
69 tcsAuthorizationCodeResponse.SetException(e.Exception); 73 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=431.
74 // If we encounter a null exception, cancel the task because the WP app crashed.
75 if (e.Exception != null)
76 {
77 tcsAuthorizationCodeResponse.SetException(e.Exception);
78 }
79 else
80 {
81 tcsAuthorizationCodeResponse.SetCanceled();
82 }
70 } 83 }
71 } 84 }
72 85
73 /// <summary>Callback of browser navigated.</summary> 86 /// <summary>Callback of browser navigated.</summary>
74 private void OnBrowserNavigated(object sender, NavigationEventArgs e) 87 private void OnBrowserNavigated(object sender, NavigationEventArgs e)
75 { 88 {
76 StopLoading(); 89 StopLoading();
77 } 90 }
78 91
79 /// <summary>The window launcher that starts browse the browser controll er to the given URI.</summary> 92 /// <summary>The window launcher that starts browse the browser controll er to the given URI.</summary>
80 /// <param name="uri">The authorization code request URI</param> 93 /// <param name="uri">The authorization code request URI</param>
81 /// <returns>The authorization code response</returns> 94 /// <returns>The authorization code response</returns>
82 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri) 95 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri)
83 { 96 {
84 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio nCodeResponseUrl>(); 97 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio nCodeResponseUrl>();
85 StartLoading(); 98 StartLoading();
86 browser.Navigate(uri); 99 browser.Navigate(uri);
87 return tcsAuthorizationCodeResponse.Task; 100 return tcsAuthorizationCodeResponse.Task;
88 } 101 }
102
103 /// <summary>A callback handler for when the user presses the back key.< /summary>
104 void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEv entArgs e)
105 {
106 // Remove this callback.
107 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
108 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio nPage;
109 rootPage.BackKeyPress -= RootPage_BackKeyPress;
110
111 e.Cancel = true;
112 tcsAuthorizationCodeResponse.SetCanceled();
113 }
89 } 114 }
90 } 115 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b