| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/login_web_dialog.h" | |
| 6 | |
| 7 #include <deque> | |
| 8 | |
| 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" | |
| 22 | |
| 23 using content::WebContents; | |
| 24 using content::WebUIMessageHandler; | |
| 25 | |
| 26 namespace chromeos { | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 // Default width/height ratio of screen size. | |
| 31 const double kDefaultWidthRatio = 0.6; | |
| 32 const double kDefaultHeightRatio = 0.6; | |
| 33 | |
| 34 // Default width/height ratio of minimal dialog size. | |
| 35 const double kMinimumWidthRatio = 0.25; | |
| 36 const double kMinimumHeightRatio = 0.25; | |
| 37 | |
| 38 static base::LazyInstance<std::deque<content::WebContents*> > | |
| 39 g_web_contents_stack = LAZY_INSTANCE_INITIALIZER; | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 /////////////////////////////////////////////////////////////////////////////// | |
| 44 // LoginWebDialog, public: | |
| 45 | |
| 46 void LoginWebDialog::Delegate::OnDialogClosed() { | |
| 47 } | |
| 48 | |
| 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()); | |
| 65 } | |
| 66 | |
| 67 LoginWebDialog::~LoginWebDialog() { | |
| 68 delegate_ = NULL; | |
| 69 } | |
| 70 | |
| 71 void LoginWebDialog::Show() { | |
| 72 chrome::ShowWebDialog(parent_window_, | |
| 73 profile_, | |
| 74 this); | |
| 75 is_open_ = true; | |
| 76 } | |
| 77 | |
| 78 void LoginWebDialog::SetDialogSize(int width, int height) { | |
| 79 DCHECK(width >= 0 && height >= 0); | |
| 80 width_ = width; | |
| 81 height_ = height; | |
| 82 } | |
| 83 | |
| 84 void LoginWebDialog::SetDialogTitle(const base::string16& title) { | |
| 85 title_ = title; | |
| 86 } | |
| 87 | |
| 88 /////////////////////////////////////////////////////////////////////////////// | |
| 89 // LoginWebDialog, protected: | |
| 90 | |
| 91 ui::ModalType LoginWebDialog::GetDialogModalType() const { | |
| 92 return ui::MODAL_TYPE_SYSTEM; | |
| 93 } | |
| 94 | |
| 95 base::string16 LoginWebDialog::GetDialogTitle() const { | |
| 96 return title_; | |
| 97 } | |
| 98 | |
| 99 GURL LoginWebDialog::GetDialogContentURL() const { | |
| 100 return url_; | |
| 101 } | |
| 102 | |
| 103 void LoginWebDialog::GetWebUIMessageHandlers( | |
| 104 std::vector<WebUIMessageHandler*>* handlers) const { | |
| 105 } | |
| 106 | |
| 107 void LoginWebDialog::GetDialogSize(gfx::Size* size) const { | |
| 108 size->SetSize(width_, height_); | |
| 109 } | |
| 110 | |
| 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()); | |
| 115 } | |
| 116 | |
| 117 std::string LoginWebDialog::GetDialogArgs() const { | |
| 118 return std::string(); | |
| 119 } | |
| 120 | |
| 121 // static. | |
| 122 content::WebContents* LoginWebDialog::GetCurrentWebContents() { | |
| 123 if (!g_web_contents_stack.Pointer()->size()) | |
| 124 return NULL; | |
| 125 | |
| 126 return g_web_contents_stack.Pointer()->front(); | |
| 127 } | |
| 128 | |
| 129 void LoginWebDialog::OnDialogShown(content::WebUI* webui, | |
| 130 content::RenderViewHost* render_view_host) { | |
| 131 g_web_contents_stack.Pointer()->push_front(webui->GetWebContents()); | |
| 132 } | |
| 133 | |
| 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; | |
| 140 } | |
| 141 | |
| 142 void LoginWebDialog::OnCloseContents(WebContents* source, | |
| 143 bool* out_close_dialog) { | |
| 144 if (out_close_dialog) | |
| 145 *out_close_dialog = true; | |
| 146 | |
| 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(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 bool LoginWebDialog::ShouldShowDialogTitle() const { | |
| 156 return true; | |
| 157 } | |
| 158 | |
| 159 bool LoginWebDialog::HandleContextMenu( | |
| 160 const content::ContextMenuParams& params) { | |
| 161 // Disable context menu. | |
| 162 return true; | |
| 163 } | |
| 164 | |
| 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(); | |
| 171 } | |
| 172 | |
| 173 } // namespace chromeos | |
| OLD | NEW |