Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_web_dialog.cc
bloba2ec805065d81a1de1371294cc4695cf90f3ff0f
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 "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/login/helper.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser_dialogs.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h"
14 #include "ui/gfx/native_widget_types.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/size.h"
17 #include "ui/views/widget/widget.h"
19 using content::WebContents;
20 using content::WebUIMessageHandler;
22 namespace chromeos {
24 namespace {
26 // Default width/height ratio of screen size.
27 const double kDefaultWidthRatio = 0.6;
28 const double kDefaultHeightRatio = 0.6;
30 // Default width/height ratio of minimal dialog size.
31 const double kMinimumWidthRatio = 0.25;
32 const double kMinimumHeightRatio = 0.25;
34 } // namespace
36 ///////////////////////////////////////////////////////////////////////////////
37 // LoginWebDialog, public:
39 void LoginWebDialog::Delegate::OnDialogClosed() {
42 LoginWebDialog::LoginWebDialog(Delegate* delegate,
43 gfx::NativeWindow parent_window,
44 const base::string16& title,
45 const GURL& url,
46 Style style)
47 : delegate_(delegate),
48 parent_window_(parent_window),
49 title_(title),
50 url_(url),
51 style_(style),
52 is_open_(false) {
53 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
54 width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width());
55 height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height());
58 LoginWebDialog::~LoginWebDialog() {
59 delegate_ = NULL;
62 void LoginWebDialog::Show() {
63 chrome::ShowWebDialog(parent_window_,
64 ProfileHelper::GetSigninProfile(),
65 this);
66 is_open_ = true;
69 void LoginWebDialog::SetDialogSize(int width, int height) {
70 DCHECK(width >= 0 && height >= 0);
71 width_ = width;
72 height_ = height;
75 void LoginWebDialog::SetDialogTitle(const base::string16& title) {
76 title_ = title;
79 ///////////////////////////////////////////////////////////////////////////////
80 // LoginWebDialog, protected:
82 ui::ModalType LoginWebDialog::GetDialogModalType() const {
83 return ui::MODAL_TYPE_SYSTEM;
86 base::string16 LoginWebDialog::GetDialogTitle() const {
87 return title_;
90 GURL LoginWebDialog::GetDialogContentURL() const {
91 return url_;
94 void LoginWebDialog::GetWebUIMessageHandlers(
95 std::vector<WebUIMessageHandler*>* handlers) const {
98 void LoginWebDialog::GetDialogSize(gfx::Size* size) const {
99 size->SetSize(width_, height_);
102 void LoginWebDialog::GetMinimumDialogSize(gfx::Size* size) const {
103 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
104 size->SetSize(kMinimumWidthRatio * screen_bounds.width(),
105 kMinimumHeightRatio * screen_bounds.height());
108 std::string LoginWebDialog::GetDialogArgs() const {
109 return std::string();
112 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) {
113 is_open_ = false;
114 notification_registrar_.RemoveAll();
115 if (delegate_)
116 delegate_->OnDialogClosed();
117 delete this;
120 void LoginWebDialog::OnCloseContents(WebContents* source,
121 bool* out_close_dialog) {
122 if (out_close_dialog)
123 *out_close_dialog = true;
126 bool LoginWebDialog::ShouldShowDialogTitle() const {
127 return true;
130 bool LoginWebDialog::HandleContextMenu(
131 const content::ContextMenuParams& params) {
132 // Disable context menu.
133 return true;
136 void LoginWebDialog::Observe(int type,
137 const content::NotificationSource& source,
138 const content::NotificationDetails& details) {
139 DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
140 // TODO(saintlou): Do we need a throbber for Aura?
141 NOTIMPLEMENTED();
144 } // namespace chromeos