OLD | NEW |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 { | 89 { |
90 StopLoading(); | 90 StopLoading(); |
91 } | 91 } |
92 | 92 |
93 /// <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> |
94 /// <param name="uri">The authorization code request URI</param> | 94 /// <param name="uri">The authorization code request URI</param> |
95 /// <returns>The authorization code response</returns> | 95 /// <returns>The authorization code response</returns> |
96 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri) | 96 public Task<AuthorizationCodeResponseUrl> Launch(Uri uri) |
97 { | 97 { |
98 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio
nCodeResponseUrl>(); | 98 tcsAuthorizationCodeResponse = new TaskCompletionSource<Authorizatio
nCodeResponseUrl>(); |
| 99 tcsAuthorizationCodeResponse.Task.ContinueWith(t => |
| 100 { |
| 101 RemoveBackKeyPressCallback(); |
| 102 }, TaskScheduler.FromCurrentSynchronizationContext()); |
99 StartLoading(); | 103 StartLoading(); |
100 browser.Navigate(uri); | 104 browser.Navigate(uri); |
101 return tcsAuthorizationCodeResponse.Task; | 105 return tcsAuthorizationCodeResponse.Task; |
102 } | 106 } |
103 | 107 |
104 /// <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> |
105 void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEv
entArgs e) | 109 void RootPage_BackKeyPress(object sender, System.ComponentModel.CancelEv
entArgs e) |
106 { | 110 { |
107 // Remove this callback. | 111 e.Cancel = true; |
| 112 tcsAuthorizationCodeResponse.SetCanceled(); |
| 113 } |
| 114 |
| 115 /// <summary>Removes <see cref="RootPage_BackKeyPress" as the root page
callback./></summary> |
| 116 void RemoveBackKeyPressCallback() |
| 117 { |
108 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as
PhoneApplicationFrame; | 118 PhoneApplicationFrame rootFrame = Application.Current.RootVisual as
PhoneApplicationFrame; |
109 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio
nPage; | 119 PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicatio
nPage; |
110 rootPage.BackKeyPress -= RootPage_BackKeyPress; | 120 rootPage.BackKeyPress -= RootPage_BackKeyPress; |
111 | |
112 e.Cancel = true; | |
113 tcsAuthorizationCodeResponse.SetCanceled(); | |
114 } | 121 } |
115 } | 122 } |
116 } | 123 } |
OLD | NEW |