| 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 "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" | 11 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "content/public/browser/load_notification_details.h" | 12 #include "content/public/browser/load_notification_details.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 15 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/resource_request_details.h" | 18 #include "content/public/browser/resource_request_details.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/page_transition_types.h" | 20 #include "content/public/common/page_transition_types.h" |
| 19 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 20 #include "ui/base/window_open_disposition.h" | 22 #include "ui/base/window_open_disposition.h" |
| 21 | 23 |
| 22 using content::LoadNotificationDetails; | 24 using content::LoadNotificationDetails; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 WebContentsObserver::Observe(contents_); | 67 WebContentsObserver::Observe(contents_); |
| 66 | 68 |
| 67 NavigationController* controller = &(contents_->GetController()); | 69 NavigationController* controller = &(contents_->GetController()); |
| 68 | 70 |
| 69 // Register for appropriate notifications to intercept navigation to the | 71 // Register for appropriate notifications to intercept navigation to the |
| 70 // redirect URLs. | 72 // redirect URLs. |
| 71 registrar_.Add( | 73 registrar_.Add( |
| 72 this, | 74 this, |
| 73 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 75 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 74 content::Source<WebContents>(contents_)); | 76 content::Source<WebContents>(contents_)); |
| 77 registrar_.Add( |
| 78 this, |
| 79 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 80 content::Source<WebContents>(contents_)); |
| 75 | 81 |
| 76 controller->LoadURL( | 82 controller->LoadURL( |
| 77 provider_url_, | 83 provider_url_, |
| 78 content::Referrer(), | 84 content::Referrer(), |
| 79 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 85 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 80 std::string()); | 86 std::string()); |
| 81 } | 87 } |
| 82 | 88 |
| 83 WebContents* WebAuthFlow::CreateWebContents() { | 89 WebContents* WebAuthFlow::CreateWebContents() { |
| 84 return WebContents::Create(WebContents::CreateParams(profile_)); | 90 return WebContents::Create(WebContents::CreateParams(profile_)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
| 123 const content::NotificationDetails& details) { | 129 const content::NotificationDetails& details) { |
| 124 switch (type) { | 130 switch (type) { |
| 125 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { | 131 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
| 126 ResourceRedirectDetails* redirect_details = | 132 ResourceRedirectDetails* redirect_details = |
| 127 content::Details<ResourceRedirectDetails>(details).ptr(); | 133 content::Details<ResourceRedirectDetails>(details).ptr(); |
| 128 if (redirect_details != NULL) | 134 if (redirect_details != NULL) |
| 129 BeforeUrlLoaded(redirect_details->new_url); | 135 BeforeUrlLoaded(redirect_details->new_url); |
| 130 } | 136 } |
| 131 break; | 137 break; |
| 138 case content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED: { |
| 139 std::pair<content::NavigationEntry*, bool>* title = |
| 140 content::Details< |
| 141 std::pair<content::NavigationEntry*, bool> >(details).ptr(); |
| 142 |
| 143 if (title->first) |
| 144 delegate_->OnAuthFlowTitleChange(UTF16ToUTF8(title->first->GetTitle())); |
| 145 } |
| 146 break; |
| 132 default: | 147 default: |
| 133 NOTREACHED() << "Got a notification that we did not register for: " | 148 NOTREACHED() << "Got a notification that we did not register for: " |
| 134 << type; | 149 << type; |
| 135 break; | 150 break; |
| 136 } | 151 } |
| 137 } | 152 } |
| 138 | 153 |
| 139 void WebAuthFlow::ProvisionalChangeToMainFrameUrl( | 154 void WebAuthFlow::ProvisionalChangeToMainFrameUrl( |
| 140 const GURL& url, | 155 const GURL& url, |
| 141 RenderViewHost* render_view_host) { | 156 RenderViewHost* render_view_host) { |
| 142 BeforeUrlLoaded(url); | 157 BeforeUrlLoaded(url); |
| 143 } | 158 } |
| 144 | 159 |
| 145 void WebAuthFlow::DidStopLoading(RenderViewHost* render_view_host) { | 160 void WebAuthFlow::DidStopLoading(RenderViewHost* render_view_host) { |
| 146 AfterUrlLoaded(); | 161 AfterUrlLoaded(); |
| 147 } | 162 } |
| 148 | 163 |
| 149 void WebAuthFlow::WebContentsDestroyed(WebContents* web_contents) { | 164 void WebAuthFlow::WebContentsDestroyed(WebContents* web_contents) { |
| 150 contents_ = NULL; | 165 contents_ = NULL; |
| 151 delegate_->OnAuthFlowFailure(WebAuthFlow::WINDOW_CLOSED); | 166 delegate_->OnAuthFlowFailure(WebAuthFlow::WINDOW_CLOSED); |
| 152 } | 167 } |
| 153 | 168 |
| 154 } // namespace extensions | 169 } // namespace extensions |
| OLD | NEW |