Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_web_dialog.cc
blob562c33644a4279a766e15a2c7079c968c6be506b
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.
5 #include "chrome/browser/chromeos/login/login_web_dialog.h"
7 #include <deque>
9 #include "base/lazy_instance.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chromeos/login/helper.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser_dialogs.h"
15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/web_contents.h"
18 #include "ui/gfx/native_widget_types.h"
19 #include "ui/gfx/rect.h"
20 #include "ui/gfx/size.h"
21 #include "ui/views/widget/widget.h"
23 using content::WebContents;
24 using content::WebUIMessageHandler;
26 namespace chromeos {
28 namespace {
30 // Default width/height ratio of screen size.
31 const double kDefaultWidthRatio = 0.6;
32 const double kDefaultHeightRatio = 0.6;
34 // Default width/height ratio of minimal dialog size.
35 const double kMinimumWidthRatio = 0.25;
36 const double kMinimumHeightRatio = 0.25;
38 static base::LazyInstance<std::deque<content::WebContents*> >
39 g_web_contents_stack = LAZY_INSTANCE_INITIALIZER;
41 } // namespace
43 ///////////////////////////////////////////////////////////////////////////////
44 // LoginWebDialog, public:
46 void LoginWebDialog::Delegate::OnDialogClosed() {
49 LoginWebDialog::LoginWebDialog(Profile* profile,
50 Delegate* delegate,
51 gfx::NativeWindow parent_window,
52 const base::string16& title,
53 const GURL& url,
54 Style style)
55 : profile_(profile),
56 parent_window_(parent_window),
57 delegate_(delegate),
58 title_(title),
59 url_(url),
60 style_(style),
61 is_open_(false) {
62 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
63 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width());
64 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height());
67 LoginWebDialog::~LoginWebDialog() {
68 delegate_ = NULL;
71 void LoginWebDialog::Show() {
72 chrome::ShowWebDialog(parent_window_,
73 profile_,
74 this);
75 is_open_ = true;
78 void LoginWebDialog::SetDialogSize(int width, int height) {
79 DCHECK(width >= 0 && height >= 0);
80 width_ = width;
81 height_ = height;
84 void LoginWebDialog::SetDialogTitle(const base::string16& title) {
85 title_ = title;
88 ///////////////////////////////////////////////////////////////////////////////
89 // LoginWebDialog, protected:
91 ui::ModalType LoginWebDialog::GetDialogModalType() const {
92 return ui::MODAL_TYPE_SYSTEM;
95 base::string16 LoginWebDialog::GetDialogTitle() const {
96 return title_;
99 GURL LoginWebDialog::GetDialogContentURL() const {
100 return url_;
103 void LoginWebDialog::GetWebUIMessageHandlers(
104 std::vector<WebUIMessageHandler*>* handlers) const {
107 void LoginWebDialog::GetDialogSize(gfx::Size* size) const {
108 size->SetSize(width_, height_);
111 void LoginWebDialog::GetMinimumDialogSize(gfx::Size* size) const {
112 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
113 size->SetSize(kMinimumWidthRatio * screen_bounds.width(),
114 kMinimumHeightRatio * screen_bounds.height());
117 std::string LoginWebDialog::GetDialogArgs() const {
118 return std::string();
121 // static.
122 content::WebContents* LoginWebDialog::GetCurrentWebContents() {
123 if (!g_web_contents_stack.Pointer()->size())
124 return NULL;
126 return g_web_contents_stack.Pointer()->front();
129 void LoginWebDialog::OnDialogShown(content::WebUI* webui,
130 content::RenderViewHost* render_view_host) {
131 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents());
134 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) {
135 is_open_ = false;
136 notification_registrar_.RemoveAll();
137 if (delegate_)
138 delegate_->OnDialogClosed();
139 delete this;
142 void LoginWebDialog::OnCloseContents(WebContents* source,
143 bool* out_close_dialog) {
144 if (out_close_dialog)
145 *out_close_dialog = true;
147 if (g_web_contents_stack.Pointer()->size() &&
148 source == g_web_contents_stack.Pointer()->front()) {
149 g_web_contents_stack.Pointer()->pop_front();
150 } else {
151 NOTREACHED();
155 bool LoginWebDialog::ShouldShowDialogTitle() const {
156 return true;
159 bool LoginWebDialog::HandleContextMenu(
160 const content::ContextMenuParams& params) {
161 // Disable context menu.
162 return true;
165 void LoginWebDialog::Observe(int type,
166 const content::NotificationSource& source,
167 const content::NotificationDetails& details) {
168 DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
169 // TODO(saintlou): Do we need a throbber for Aura?
170 NOTIMPLEMENTED();
173 } // namespace chromeos