Home | History | Annotate | Download | only in login
      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 "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"
     18 
     19 using content::WebContents;
     20 using content::WebUIMessageHandler;
     21 
     22 namespace chromeos {
     23 
     24 namespace {
     25 
     26 // Default width/height ratio of screen size.
     27 const double kDefaultWidthRatio = 0.6;
     28 const double kDefaultHeightRatio = 0.6;
     29 
     30 }  // namespace
     31 
     32 ///////////////////////////////////////////////////////////////////////////////
     33 // LoginWebDialog, public:
     34 
     35 void LoginWebDialog::Delegate::OnDialogClosed() {
     36 }
     37 
     38 LoginWebDialog::LoginWebDialog(Delegate* delegate,
     39                                gfx::NativeWindow parent_window,
     40                                const string16& title,
     41                                const GURL& url,
     42                                Style style)
     43     : delegate_(delegate),
     44       parent_window_(parent_window),
     45       title_(title),
     46       url_(url),
     47       style_(style),
     48       is_open_(false) {
     49   gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
     50   width_ = static_cast<int>(kDefaultWidthRatio * screen_bounds.width());
     51   height_ = static_cast<int>(kDefaultHeightRatio * screen_bounds.height());
     52 }
     53 
     54 LoginWebDialog::~LoginWebDialog() {
     55   delegate_ = NULL;
     56 }
     57 
     58 void LoginWebDialog::Show() {
     59   chrome::ShowWebDialog(parent_window_,
     60                         ProfileHelper::GetSigninProfile(),
     61                         this);
     62   is_open_ = true;
     63 }
     64 
     65 void LoginWebDialog::SetDialogSize(int width, int height) {
     66   DCHECK(width >= 0 && height >= 0);
     67   width_ = width;
     68   height_ = height;
     69 }
     70 
     71 void LoginWebDialog::SetDialogTitle(const string16& title) {
     72   title_ = title;
     73 }
     74 
     75 ///////////////////////////////////////////////////////////////////////////////
     76 // LoginWebDialog, protected:
     77 
     78 ui::ModalType LoginWebDialog::GetDialogModalType() const {
     79   return ui::MODAL_TYPE_SYSTEM;
     80 }
     81 
     82 string16 LoginWebDialog::GetDialogTitle() const {
     83   return title_;
     84 }
     85 
     86 GURL LoginWebDialog::GetDialogContentURL() const {
     87   return url_;
     88 }
     89 
     90 void LoginWebDialog::GetWebUIMessageHandlers(
     91     std::vector<WebUIMessageHandler*>* handlers) const {
     92 }
     93 
     94 void LoginWebDialog::GetDialogSize(gfx::Size* size) const {
     95   size->SetSize(width_, height_);
     96 }
     97 
     98 std::string LoginWebDialog::GetDialogArgs() const {
     99   return std::string();
    100 }
    101 
    102 void LoginWebDialog::OnDialogClosed(const std::string& json_retval) {
    103   is_open_ = false;
    104   notification_registrar_.RemoveAll();
    105   if (delegate_)
    106     delegate_->OnDialogClosed();
    107   delete this;
    108 }
    109 
    110 void LoginWebDialog::OnCloseContents(WebContents* source,
    111                                      bool* out_close_dialog) {
    112   if (out_close_dialog)
    113     *out_close_dialog = true;
    114 }
    115 
    116 bool LoginWebDialog::ShouldShowDialogTitle() const {
    117   return true;
    118 }
    119 
    120 bool LoginWebDialog::HandleContextMenu(
    121     const content::ContextMenuParams& params) {
    122   // Disable context menu.
    123   return true;
    124 }
    125 
    126 void LoginWebDialog::Observe(int type,
    127                              const content::NotificationSource& source,
    128                              const content::NotificationDetails& details) {
    129   DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
    130   // TODO(saintlou): Do we need a throbber for Aura?
    131   NOTIMPLEMENTED();
    132 }
    133 
    134 }  // namespace chromeos
    135