• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/choose_mobile_network_dialog.h"
6 
7 #include "chrome/browser/chromeos/frame/bubble_window.h"
8 #include "chrome/browser/chromeos/login/user_manager.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/views/html_dialog_view.h"
13 #include "chrome/common/url_constants.h"
14 
15 namespace {
16 
17 // Default width/height of the dialog.
18 const int kDefaultWidth = 350;
19 const int kDefaultHeight = 225;
20 
21 // Custom HtmlDialogView with disabled context menu.
22 class HtmlDialogWithoutContextMenuView : public HtmlDialogView {
23  public:
HtmlDialogWithoutContextMenuView(Profile * profile,HtmlDialogUIDelegate * delegate)24   HtmlDialogWithoutContextMenuView(Profile* profile,
25                                    HtmlDialogUIDelegate* delegate)
26       : HtmlDialogView(profile, delegate) {}
27 
28   // TabContentsDelegate implementation.
HandleContextMenu(const ContextMenuParams & params)29   bool HandleContextMenu(const ContextMenuParams& params) {
30     // Disable context menu.
31     return true;
32   }
33 };
34 
35 }  // namespace
36 
37 namespace chromeos {
38 
39 // static
ShowDialog(gfx::NativeWindow owning_window)40 void ChooseMobileNetworkDialog::ShowDialog(gfx::NativeWindow owning_window) {
41   Profile* profile;
42   if (UserManager::Get()->user_is_logged_in()) {
43     Browser* browser = BrowserList::GetLastActive();
44     DCHECK(browser);
45     profile = browser->profile();
46   } else {
47     profile = ProfileManager::GetDefaultProfile();
48   }
49   HtmlDialogView* html_view = new HtmlDialogWithoutContextMenuView(
50       profile, new ChooseMobileNetworkDialog);
51   html_view->InitDialog();
52   chromeos::BubbleWindow::Create(owning_window,
53                                  gfx::Rect(),
54                                  chromeos::BubbleWindow::STYLE_GENERIC,
55                                  html_view);
56   html_view->window()->Show();
57 }
58 
ChooseMobileNetworkDialog()59 ChooseMobileNetworkDialog::ChooseMobileNetworkDialog() {
60 }
61 
IsDialogModal() const62 bool ChooseMobileNetworkDialog::IsDialogModal() const {
63   return true;
64 }
65 
GetDialogTitle() const66 std::wstring ChooseMobileNetworkDialog::GetDialogTitle() const {
67   return std::wstring();
68 }
69 
GetDialogContentURL() const70 GURL ChooseMobileNetworkDialog::GetDialogContentURL() const {
71   return GURL(chrome::kChromeUIChooseMobileNetworkURL);
72 }
73 
GetWebUIMessageHandlers(std::vector<WebUIMessageHandler * > * handlers) const74 void ChooseMobileNetworkDialog::GetWebUIMessageHandlers(
75     std::vector<WebUIMessageHandler*>* handlers) const {
76 }
77 
GetDialogSize(gfx::Size * size) const78 void ChooseMobileNetworkDialog::GetDialogSize(gfx::Size* size) const {
79   size->SetSize(kDefaultWidth, kDefaultHeight);
80 }
81 
GetDialogArgs() const82 std::string ChooseMobileNetworkDialog::GetDialogArgs() const {
83   return "[]";
84 }
85 
OnDialogClosed(const std::string & json_retval)86 void ChooseMobileNetworkDialog::OnDialogClosed(const std::string& json_retval) {
87   delete this;
88 }
89 
OnCloseContents(TabContents * source,bool * out_close_dialog)90 void ChooseMobileNetworkDialog::OnCloseContents(TabContents* source,
91                                                 bool* out_close_dialog) {
92   if (out_close_dialog)
93     *out_close_dialog = true;
94 }
95 
ShouldShowDialogTitle() const96 bool ChooseMobileNetworkDialog::ShouldShowDialogTitle() const {
97   return false;
98 }
99 
100 }  // namespace chromeos
101