Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: chrome/browser/extensions/api/identity/extension_auth_flow.cc

Issue 10178020: Start implementing an auth flow for platform apps to be able to do auth (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/identity/extension_auth_flow.cc
===================================================================
--- chrome/browser/extensions/api/identity/extension_auth_flow.cc (revision 0)
+++ chrome/browser/extensions/api/identity/extension_auth_flow.cc (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/identity/extension_auth_flow.h"
+
+#include "base/string_util.h"
+#include "content\public\browser\navigation_controller.h"
+#include "ipc/ipc_message.h"
+
+using content::BrowserContext;
+using content::WebContents;
+using content::WebContentsDelegate;
+using views::View;
+using views::WebView;
+using views::Widget;
+using views::WidgetDelegate;
+
+namespace extensions {
+
+ExtensionAuthFlow::ExtensionAuthFlow(
+ Delegate* delegate,
+ content::BrowserContext* browser_context,
+ const std::string& extension_id,
+ const GURL& provider_url)
+ : delegate_(delegate),
+ browser_context_(browser_context),
+ extension_id_(extension_id),
+ provider_url_(provider_url) {
+}
+
+void ExtensionAuthFlow::Start() {
+ contents_.reset(WebContents::Create(
+ browser_context_, NULL, MSG_ROUTING_NONE, NULL, NULL));
+ contents_->SetDelegate(this);
+ contents_->GetController().LoadURL(
+ provider_url_,
+ content::Referrer(),
+ content::PAGE_TRANSITION_START_PAGE,
+ std::string());
+}
+
+void ExtensionAuthFlow::LoadingStateChanged(WebContents* source) {
+ if (source->IsLoading())
+ return;
+ OnProviderUrlLoaded();
+}
+
+void ExtensionAuthFlow::OnProviderUrlLoaded() {
+ GURL url = contents_->GetURL();
+ if (StartsWithASCII(url.spec(), "http://munjalsample.appspot.com", false)) {
+ // if (widget_.get())
+ // widget_->Close();
+ result_ = url;
+ ReportResult();
+ return;
+ }
+ web_view_.reset(new WebView(browser_context_));
+ web_view_->SetWebContents(contents_.get());
+ widget_.reset(Widget::CreateWindow(this));
+ widget_->SetSize(gfx::Size(800, 600));
+ widget_->Show();
+}
+
+View* ExtensionAuthFlow::GetContentsView() {
+ CHECK(web_view_.get());
+ return web_view_.get();
+}
+
+Widget* ExtensionAuthFlow::GetWidget() {
+ CHECK(web_view_.get());
+ return web_view_->GetWidget();
+}
+
+const Widget* ExtensionAuthFlow::GetWidget() const {
+ CHECK(web_view_.get());
+ return web_view_->GetWidget();
+}
+
+void ExtensionAuthFlow::WindowClosing() {
+}
+
+void ExtensionAuthFlow::ReportResult() {
+ if (delegate_)
+ delegate_->OnAuthFlowCompleted(result_.spec());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698