Index: chrome/browser/chromeos/arc/arc_auth_ui.cc |
diff --git a/chrome/browser/chromeos/arc/arc_auth_ui.cc b/chrome/browser/chromeos/arc/arc_auth_ui.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8604d72f12e88c5d952a218f6ab6c3090b5f8a84 |
--- /dev/null |
+++ b/chrome/browser/chromeos/arc/arc_auth_ui.cc |
@@ -0,0 +1,97 @@ |
+// Copyright 2016 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/chromeos/arc/arc_auth_ui.h" |
+ |
+#include "chrome/browser/chromeos/arc/arc_auth_service.h" |
+#include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/web_contents.h" |
+#include "net/base/load_states.h" |
+#include "ui/views/controls/webview/web_dialog_view.h" |
+#include "ui/views/widget/widget.h" |
+ |
+namespace arc { |
+ |
+namespace { |
+ |
+const int kDefaultWidth = 480; |
+const int kDefaultHeight = 640; |
+ |
+} // namespace |
+ |
+ArcAuthUI::ArcAuthUI(content::BrowserContext* browser_context, |
+ Delegate* delegate) |
+ : browser_context_(browser_context), delegate_(delegate) { |
+ DCHECK(browser_context_ != nullptr && delegate_ != nullptr); |
+ views::WebDialogView* view = new views::WebDialogView( |
+ browser_context_, this, new ChromeWebContentsHandler); |
+ widget_ = views::Widget::CreateWindow(view); |
+ widget_->Show(); |
+} |
+ |
+ArcAuthUI::~ArcAuthUI() {} |
+ |
+void ArcAuthUI::Close() { |
+ widget_->CloseNow(); |
+} |
+ |
+ui::ModalType ArcAuthUI::GetDialogModalType() const { |
+ return ui::MODAL_TYPE_SYSTEM; |
+} |
+ |
+base::string16 ArcAuthUI::GetDialogTitle() const { |
+ return base::string16(); |
+} |
+ |
+GURL ArcAuthUI::GetDialogContentURL() const { |
+ return ArcAuthFetcher::CreateURL(); |
+} |
+ |
+void ArcAuthUI::GetWebUIMessageHandlers( |
+ std::vector<content::WebUIMessageHandler*>* handlers) const {} |
+ |
+void ArcAuthUI::GetDialogSize(gfx::Size* size) const { |
+ size->SetSize(kDefaultWidth, kDefaultHeight); |
+} |
+ |
+std::string ArcAuthUI::GetDialogArgs() const { |
+ return std::string(); |
+} |
+ |
+void ArcAuthUI::OnDialogClosed(const std::string& json_retval) { |
+ delegate_->OnAuthUIClosed(); |
+ delete this; |
+} |
+ |
+void ArcAuthUI::OnCloseContents(content::WebContents* source, |
+ bool* out_close_dialog) { |
+ *out_close_dialog = true; |
+} |
+ |
+bool ArcAuthUI::ShouldShowDialogTitle() const { |
+ return false; |
+} |
+ |
+bool ArcAuthUI::HandleContextMenu(const content::ContextMenuParams& params) { |
+ // Disable context menu. |
+ return true; |
+} |
+ |
+void ArcAuthUI::OnLoadingStateChanged(content::WebContents* source) { |
+ // Check an auth code whenever page is reloaded. |
+ if (source->GetLoadState().state == net::LoadState::LOAD_STATE_IDLE) |
xiyuan
2016/01/27 23:56:05
A couple of questions:
- Is LOAD_STATE_IDLE used
khmel
2016/01/28 05:22:08
Thanks for good hints! Yes, LOAD_STATE_IDLE appear
|
+ auth_fetcher_.reset( |
+ new ArcAuthFetcher(browser_context_->GetRequestContext(), this)); |
xiyuan
2016/01/27 23:56:05
nit: need {} when the branch has more than one lin
khmel
2016/01/28 05:22:08
Done.
|
+} |
+ |
+void ArcAuthUI::OnAuthCodeFetched(const std::string& auth_code) { |
+ ArcAuthService::Get()->SetAuthCodeAndStartArc(auth_code); |
+} |
+ |
+void ArcAuthUI::OnAuthCodeNeedUI() {} |
+ |
+void ArcAuthUI::OnAuthCodeFailed() {} |
+ |
+} // namespace arc |