OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/identity/extension_auth_flow.h" |
| 6 |
| 7 #include "base/string_util.h" |
| 8 #include "content\public\browser\navigation_controller.h" |
| 9 #include "ipc/ipc_message.h" |
| 10 |
| 11 using content::BrowserContext; |
| 12 using content::WebContents; |
| 13 using content::WebContentsDelegate; |
| 14 using views::View; |
| 15 using views::WebView; |
| 16 using views::Widget; |
| 17 using views::WidgetDelegate; |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 ExtensionAuthFlow::ExtensionAuthFlow( |
| 22 Delegate* delegate, |
| 23 content::BrowserContext* browser_context, |
| 24 const std::string& extension_id, |
| 25 const GURL& provider_url) |
| 26 : delegate_(delegate), |
| 27 browser_context_(browser_context), |
| 28 extension_id_(extension_id), |
| 29 provider_url_(provider_url) { |
| 30 } |
| 31 |
| 32 void ExtensionAuthFlow::Start() { |
| 33 contents_.reset(WebContents::Create( |
| 34 browser_context_, NULL, MSG_ROUTING_NONE, NULL, NULL)); |
| 35 contents_->SetDelegate(this); |
| 36 contents_->GetController().LoadURL( |
| 37 provider_url_, |
| 38 content::Referrer(), |
| 39 content::PAGE_TRANSITION_START_PAGE, |
| 40 std::string()); |
| 41 } |
| 42 |
| 43 void ExtensionAuthFlow::LoadingStateChanged(WebContents* source) { |
| 44 if (source->IsLoading()) |
| 45 return; |
| 46 OnProviderUrlLoaded(); |
| 47 } |
| 48 |
| 49 void ExtensionAuthFlow::OnProviderUrlLoaded() { |
| 50 GURL url = contents_->GetURL(); |
| 51 if (StartsWithASCII(url.spec(), "http://munjalsample.appspot.com", false)) { |
| 52 // if (widget_.get()) |
| 53 // widget_->Close(); |
| 54 result_ = url; |
| 55 ReportResult(); |
| 56 return; |
| 57 } |
| 58 web_view_.reset(new WebView(browser_context_)); |
| 59 web_view_->SetWebContents(contents_.get()); |
| 60 widget_.reset(Widget::CreateWindow(this)); |
| 61 widget_->SetSize(gfx::Size(800, 600)); |
| 62 widget_->Show(); |
| 63 } |
| 64 |
| 65 View* ExtensionAuthFlow::GetContentsView() { |
| 66 CHECK(web_view_.get()); |
| 67 return web_view_.get(); |
| 68 } |
| 69 |
| 70 Widget* ExtensionAuthFlow::GetWidget() { |
| 71 CHECK(web_view_.get()); |
| 72 return web_view_->GetWidget(); |
| 73 } |
| 74 |
| 75 const Widget* ExtensionAuthFlow::GetWidget() const { |
| 76 CHECK(web_view_.get()); |
| 77 return web_view_->GetWidget(); |
| 78 } |
| 79 |
| 80 void ExtensionAuthFlow::WindowClosing() { |
| 81 } |
| 82 |
| 83 void ExtensionAuthFlow::ReportResult() { |
| 84 if (delegate_) |
| 85 delegate_->OnAuthFlowCompleted(result_.spec()); |
| 86 } |
| 87 |
| 88 } // namespace extensions |
OLD | NEW |