Home | History | Annotate | Download | only in charger_replace
      1 // Copyright (c) 2013 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/charger_replace/charger_link_dialog.h"
      6 
      7 #include "base/json/json_writer.h"
      8 #include "base/prefs/pref_service.h"
      9 #include "chrome/browser/browser_process.h"
     10 #include "chrome/browser/profiles/profile_manager.h"
     11 #include "chrome/browser/ui/browser_dialogs.h"
     12 #include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
     13 #include "chrome/common/pref_names.h"
     14 #include "chrome/common/url_constants.h"
     15 #include "grit/generated_resources.h"
     16 #include "ui/base/l10n/l10n_util.h"
     17 #include "ui/gfx/size.h"
     18 
     19 using content::WebContents;
     20 using content::WebUIMessageHandler;
     21 
     22 namespace chromeos {
     23 
     24 namespace {
     25 
     26 const int kDefaultDialogWidth = 1200;
     27 const int kDefaultDialogHeight = 650;
     28 
     29 }  // namespace
     30 
     31 ChargerLinkDialog::ChargerLinkDialog(gfx::NativeWindow parent_window,
     32                                      std::string url)
     33     : parent_window_(parent_window),
     34       url_(url) {
     35 }
     36 
     37 ChargerLinkDialog::~ChargerLinkDialog() {
     38 }
     39 
     40 void ChargerLinkDialog::Show() {
     41   // We show the dialog for the active user, so that the dialog will get
     42   // displayed immediately. The parent window is a system modal/lock container
     43   // and does not belong to any user.
     44   chrome::ShowWebDialog(parent_window_,
     45                         ProfileManager::GetActiveUserProfile(),
     46                         this);
     47 }
     48 
     49 ui::ModalType ChargerLinkDialog::GetDialogModalType() const {
     50   return ui::MODAL_TYPE_SYSTEM;
     51 }
     52 
     53 base::string16 ChargerLinkDialog::GetDialogTitle() const {
     54   return l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_DIALOG_TITLE);
     55 }
     56 
     57 GURL ChargerLinkDialog::GetDialogContentURL() const {
     58   return GURL(url_);
     59 }
     60 
     61 void ChargerLinkDialog::GetWebUIMessageHandlers(
     62     std::vector<WebUIMessageHandler*>* handlers) const {
     63 }
     64 
     65 void ChargerLinkDialog::GetDialogSize(gfx::Size* size) const {
     66   size->SetSize(kDefaultDialogWidth, kDefaultDialogHeight);
     67 }
     68 
     69 std::string ChargerLinkDialog::GetDialogArgs() const {
     70   return std::string();
     71 }
     72 
     73 void ChargerLinkDialog::OnDialogClosed(const std::string& json_retval) {
     74   delete this;
     75 }
     76 
     77 void ChargerLinkDialog::OnCloseContents(WebContents* source,
     78                                                bool* out_close_dialog) {
     79   if (out_close_dialog)
     80     *out_close_dialog = true;
     81 }
     82 
     83 bool ChargerLinkDialog::ShouldShowDialogTitle() const {
     84   return true;
     85 }
     86 
     87 bool ChargerLinkDialog::HandleContextMenu(
     88     const content::ContextMenuParams& params) {
     89   // Disable context menu.
     90   return true;
     91 }
     92 
     93 }  // namespace chromeos
     94