OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/chromeos/arc/arc_auth_ui.h" | |
6 | |
7 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
8 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | |
9 #include "content/public/browser/browser_context.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "net/base/load_states.h" | |
12 #include "ui/views/controls/webview/web_dialog_view.h" | |
13 #include "ui/views/widget/widget.h" | |
14 | |
15 namespace arc { | |
16 | |
17 namespace { | |
18 | |
19 const int kDefaultWidth = 480; | |
20 const int kDefaultHeight = 640; | |
21 | |
22 } // namespace | |
23 | |
24 ArcAuthUI::ArcAuthUI(content::BrowserContext* browser_context, | |
25 Delegate* delegate) | |
26 : browser_context_(browser_context), delegate_(delegate) { | |
27 DCHECK(browser_context_ != nullptr && delegate_ != nullptr); | |
28 views::WebDialogView* view = new views::WebDialogView( | |
29 browser_context_, this, new ChromeWebContentsHandler); | |
30 widget_ = views::Widget::CreateWindow(view); | |
31 widget_->Show(); | |
32 } | |
33 | |
34 ArcAuthUI::~ArcAuthUI() {} | |
35 | |
36 void ArcAuthUI::Close() { | |
37 widget_->CloseNow(); | |
38 } | |
39 | |
40 ui::ModalType ArcAuthUI::GetDialogModalType() const { | |
41 return ui::MODAL_TYPE_SYSTEM; | |
42 } | |
43 | |
44 base::string16 ArcAuthUI::GetDialogTitle() const { | |
45 return base::string16(); | |
46 } | |
47 | |
48 GURL ArcAuthUI::GetDialogContentURL() const { | |
49 return ArcAuthFetcher::CreateURL(); | |
50 } | |
51 | |
52 void ArcAuthUI::GetWebUIMessageHandlers( | |
53 std::vector<content::WebUIMessageHandler*>* handlers) const {} | |
54 | |
55 void ArcAuthUI::GetDialogSize(gfx::Size* size) const { | |
56 size->SetSize(kDefaultWidth, kDefaultHeight); | |
57 } | |
58 | |
59 std::string ArcAuthUI::GetDialogArgs() const { | |
60 return std::string(); | |
61 } | |
62 | |
63 void ArcAuthUI::OnDialogClosed(const std::string& json_retval) { | |
64 delegate_->OnAuthUIClosed(); | |
65 delete this; | |
66 } | |
67 | |
68 void ArcAuthUI::OnCloseContents(content::WebContents* source, | |
69 bool* out_close_dialog) { | |
70 *out_close_dialog = true; | |
71 } | |
72 | |
73 bool ArcAuthUI::ShouldShowDialogTitle() const { | |
74 return false; | |
75 } | |
76 | |
77 bool ArcAuthUI::HandleContextMenu(const content::ContextMenuParams& params) { | |
78 // Disable context menu. | |
79 return true; | |
80 } | |
81 | |
82 void ArcAuthUI::OnLoadingStateChanged(content::WebContents* source) { | |
83 // Check an auth code whenever page is reloaded. | |
84 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
| |
85 auth_fetcher_.reset( | |
86 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.
| |
87 } | |
88 | |
89 void ArcAuthUI::OnAuthCodeFetched(const std::string& auth_code) { | |
90 ArcAuthService::Get()->SetAuthCodeAndStartArc(auth_code); | |
91 } | |
92 | |
93 void ArcAuthUI::OnAuthCodeNeedUI() {} | |
94 | |
95 void ArcAuthUI::OnAuthCodeFailed() {} | |
96 | |
97 } // namespace arc | |
OLD | NEW |