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

Delta Between Two Patch Sets: Src/GoogleApis.Auth.WP/OAuth2/WebAuthenticationBrokerUserControl.xaml.cs

Issue 117500043: Issue 475: Fix a bug when perssing on back button (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: Created 10 years, 2 months ago
Right Patch Set: ContinueWith 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 { 54 {
55 Loader.Visibility = Visibility.Collapsed; 55 Loader.Visibility = Visibility.Collapsed;
56 } 56 }
57 57
58 /// <summary>Callback of browser navigating.</summary> 58 /// <summary>Callback of browser navigating.</summary>
59 private void OnBrowserNavigating(object sender, NavigatingEventArgs e) 59 private void OnBrowserNavigating(object sender, NavigatingEventArgs e)
60 { 60 {
61 // The code or the error should be received by localhost. 61 // The code or the error should be received by localhost.
62 if (e.Uri.Host == "localhost") 62 if (e.Uri.Host == "localhost")
63 { 63 {
64 RemoveBackKeyPressCallback();
65 var query = e.Uri.Query.Substring(1); 64 var query = e.Uri.Query.Substring(1);
66 tcsAuthorizationCodeResponse.SetResult(new AuthorizationCodeResp onseUrl(query)); 65 tcsAuthorizationCodeResponse.SetResult(new AuthorizationCodeResp onseUrl(query));
67 } 66 }
68 } 67 }
69 68
70 /// <summary>Callback of browser navigation failed.</summary> 69 /// <summary>Callback of browser navigation failed.</summary>
71 private void OnBrowserNavigationFailed(object sender, NavigationFailedEv entArgs e) 70 private void OnBrowserNavigationFailed(object sender, NavigationFailedEv entArgs e)
72 { 71 {
73 if (!tcsAuthorizationCodeResponse.Task.IsCompleted) 72 if (!tcsAuthorizationCodeResponse.Task.IsCompleted)
74 { 73 {
75 RemoveBackKeyPressCallback();
76
77 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=431. 74 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=431.
78 // If we encounter a null exception, cancel the task because the Windows Phone app crashed. 75 // If we encounter a null exception, cancel the task because the Windows Phone app crashed.
79 if (e.Exception != null) 76 if (e.Exception != null)
80 { 77 {
81 tcsAuthorizationCodeResponse.SetException(e.Exception); 78 tcsAuthorizationCodeResponse.SetException(e.Exception);
82 } 79 }
83 else 80 else
84 { 81 {
85 tcsAuthorizationCodeResponse.SetCanceled(); 82 tcsAuthorizationCodeResponse.SetCanceled();
86 } 83 }
87 } 84 }
88 } 85 }
89 86
90 /// <summary>Callback of browser navigated.</summary> 87 /// <summary>Callback of browser navigated.</summary>
91 private void OnBrowserNavigated(object sender, NavigationEventArgs e) 88 private void OnBrowserNavigated(object sender, NavigationEventArgs e)
92 { 89 {
93 StopLoading(); 90 StopLoading();
94 } 91 }
95 92
96 /// <summary>The window launcher that starts browse the browser controll er to the given URI.</summary> 93 /// <summary>The window launcher that starts browse the browser controll er to the given URI.</summary>
97 /// <param name="uri">The authorization code request URI</param> 94 /// <param name="uri">The authorization code request URI</param>
98 /// <returns>The authorization code response</returns> 95 /// <returns>The authorization code response</returns>
99 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri) 96 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri)
100 { 97 {
101 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio nCodeResponseUrl>(); 98 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio nCodeResponseUrl>();
99 tcsAuthorizationCodeResponse.Task.ContinueWith(t =>
100 {
101 RemoveBackKeyPressCallback();
102 }, TaskScheduler.FromCurrentSynchronizationContext());
102 StartLoading(); 103 StartLoading();
103 browser.Navigate(uri); 104 browser.Navigate(uri);
104 return tcsAuthorizationCodeResponse.Task; 105 return tcsAuthorizationCodeResponse.Task;
105 } 106 }
106 107
107 /// <summary>A callback handler for when the user presses the back key.< /summary> 108 /// <summary>A callback handler for when the user presses the back key.< /summary>
108 void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEv entArgs e) 109 void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEv entArgs e)
109 { 110 {
110 RemoveBackKeyPressCallback(); 111 e.Cancel = true;
111 112 tcsAuthorizationCodeResponse.SetCanceled();
112 if (tcsAuthorizationCodeResponse.Task.Status == TaskStatus.Running)
113 {
114 e.Cancel = true;
115 tcsAuthorizationCodeResponse.SetCanceled();
116 }
117 } 113 }
118 114
119 /// <summary>Removes <see cref="RootPage_BackKeyPress" as the root page callback./></summary> 115 /// <summary>Removes <see cref="RootPage_BackKeyPress" as the root page callback./></summary>
120 void RemoveBackKeyPressCallback() 116 void RemoveBackKeyPressCallback()
121 { 117 {
122 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame; 118 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
123 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio nPage; 119 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio nPage;
124 rootPage.BackKeyPress -= RootPage_BackKeyPress; 120 rootPage.BackKeyPress -= RootPage_BackKeyPress;
125 } 121 }
126 } 122 }
127 } 123 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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