OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 5 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "chrome/browser/extensions/component_loader.h" | 16 #include "chrome/browser/extensions/component_loader.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/extensions/api/identity_private.h" | 19 #include "chrome/common/extensions/api/identity_private.h" |
20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
21 #include "chrome/grit/browser_resources.h" | 21 #include "chrome/grit/browser_resources.h" |
22 #include "components/guest_view/browser/guest_view_base.h" | 22 #include "components/guest_view/browser/guest_view_base.h" |
23 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/navigation_handle.h" | |
25 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
30 #include "content/public/browser/resource_request_details.h" | 31 #include "content/public/browser/resource_request_details.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "crypto/random.h" | 33 #include "crypto/random.h" |
33 #include "extensions/browser/app_window/app_window.h" | 34 #include "extensions/browser/app_window/app_window.h" |
34 #include "extensions/browser/event_router.h" | 35 #include "extensions/browser/event_router.h" |
35 #include "extensions/browser/extension_system.h" | 36 #include "extensions/browser/extension_system.h" |
37 #include "net/http/http_response_headers.h" | |
36 #include "url/gurl.h" | 38 #include "url/gurl.h" |
37 | 39 |
38 using content::RenderViewHost; | 40 using content::RenderViewHost; |
39 using content::ResourceRedirectDetails; | 41 using content::ResourceRedirectDetails; |
40 using content::WebContents; | 42 using content::WebContents; |
41 using content::WebContentsObserver; | 43 using content::WebContentsObserver; |
42 using guest_view::GuestViewBase; | 44 using guest_view::GuestViewBase; |
43 | 45 |
44 namespace extensions { | 46 namespace extensions { |
45 | 47 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 WebContentsObserver::Observe(web_contents); | 172 WebContentsObserver::Observe(web_contents); |
171 | 173 |
172 registrar_.RemoveAll(); | 174 registrar_.RemoveAll(); |
173 } | 175 } |
174 | 176 |
175 void WebAuthFlow::RenderProcessGone(base::TerminationStatus status) { | 177 void WebAuthFlow::RenderProcessGone(base::TerminationStatus status) { |
176 if (delegate_) | 178 if (delegate_) |
177 delegate_->OnAuthFlowFailure(WebAuthFlow::WINDOW_CLOSED); | 179 delegate_->OnAuthFlowFailure(WebAuthFlow::WINDOW_CLOSED); |
178 } | 180 } |
179 | 181 |
180 void WebAuthFlow::DidStartProvisionalLoadForFrame( | |
181 content::RenderFrameHost* render_frame_host, | |
182 const GURL& validated_url, | |
183 bool is_error_page, | |
184 bool is_iframe_srcdoc) { | |
185 if (!render_frame_host->GetParent()) | |
186 BeforeUrlLoaded(validated_url); | |
187 } | |
188 | |
189 void WebAuthFlow::DidFailProvisionalLoad( | |
190 content::RenderFrameHost* render_frame_host, | |
191 const GURL& validated_url, | |
192 int error_code, | |
193 const base::string16& error_description, | |
194 bool was_ignored_by_handler) { | |
195 TRACE_EVENT_ASYNC_STEP_PAST1("identity", | |
Michael Courage
2016/09/22 16:25:36
would be nice to keep the error tracing in the new
yzshen1
2016/09/22 18:07:52
I removed it because this doesn't have a correspon
| |
196 "WebAuthFlow", | |
197 this, | |
198 "DidFailProvisionalLoad", | |
199 "error_code", | |
200 error_code); | |
201 if (delegate_) | |
202 delegate_->OnAuthFlowFailure(LOAD_FAILED); | |
203 } | |
204 | |
205 void WebAuthFlow::DidGetRedirectForResourceRequest( | 182 void WebAuthFlow::DidGetRedirectForResourceRequest( |
206 const content::ResourceRedirectDetails& details) { | 183 const content::ResourceRedirectDetails& details) { |
207 BeforeUrlLoaded(details.new_url); | 184 BeforeUrlLoaded(details.new_url); |
208 } | 185 } |
209 | 186 |
210 void WebAuthFlow::TitleWasSet(content::NavigationEntry* entry, | 187 void WebAuthFlow::TitleWasSet(content::NavigationEntry* entry, |
211 bool explicit_set) { | 188 bool explicit_set) { |
212 if (delegate_) | 189 if (delegate_) |
213 delegate_->OnAuthFlowTitleChange(base::UTF16ToUTF8(entry->GetTitle())); | 190 delegate_->OnAuthFlowTitleChange(base::UTF16ToUTF8(entry->GetTitle())); |
214 } | 191 } |
215 | 192 |
216 void WebAuthFlow::DidStopLoading() { | 193 void WebAuthFlow::DidStopLoading() { |
217 AfterUrlLoaded(); | 194 AfterUrlLoaded(); |
218 } | 195 } |
219 | 196 |
220 void WebAuthFlow::DidNavigateMainFrame( | 197 void WebAuthFlow::DidStartNavigation( |
221 const content::LoadCommittedDetails& details, | 198 content::NavigationHandle* navigation_handle) { |
222 const content::FrameNavigateParams& params) { | 199 if (navigation_handle->IsInMainFrame()) |
223 if (delegate_ && details.http_status_code >= 400) | 200 BeforeUrlLoaded(navigation_handle->GetURL()); |
yzshen1
2016/09/16 22:32:44
One question:
It seems the original code doesn't c
clamy
2016/09/19 10:02:54
It is possible to have 2 navigation sin the main f
yzshen1
2016/09/19 15:32:56
Thanks for the info! I will also wait for the WebA
Michael Courage
2016/09/19 19:11:43
At the time I wrote this code I didn't have a grea
| |
201 } | |
202 | |
203 void WebAuthFlow::DidFinishNavigation( | |
204 content::NavigationHandle* navigation_handle) { | |
205 bool failed = | |
206 navigation_handle->GetNetErrorCode() != net::OK || | |
clamy
2016/09/19 10:02:54
This seems like it would trigger for a subframe na
yzshen1
2016/09/19 15:32:56
It seems this is what the original code did. But w
| |
207 (navigation_handle->IsInMainFrame() && | |
208 navigation_handle->GetResponseHeaders()->response_code() >= 400); | |
209 | |
210 if (failed && delegate_) | |
224 delegate_->OnAuthFlowFailure(LOAD_FAILED); | 211 delegate_->OnAuthFlowFailure(LOAD_FAILED); |
225 } | 212 } |
226 | 213 |
227 } // namespace extensions | 214 } // namespace extensions |
OLD | NEW |