Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/ui/views/extensions/chooser_dialog_view.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" | |
| 9 #include "chrome/browser/ui/views/chooser_content_view.h" | |
| 10 #include "chrome/grit/generated_resources.h" | |
| 11 #include "components/chooser_controller/chooser_controller.h" | |
| 12 #include "components/constrained_window/constrained_window_views.h" | |
| 13 #include "components/url_formatter/elide_url.h" | |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 #include "extensions/browser/extension_registry.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 18 #include "ui/views/controls/styled_label.h" | |
| 19 #include "ui/views/controls/table/table_view.h" | |
| 20 #include "ui/views/layout/box_layout.h" | |
| 21 #include "ui/views/layout/layout_constants.h" | |
| 22 #include "ui/views/window/dialog_client_view.h" | |
| 23 #include "url/origin.h" | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 const int kChooserDialogWidth = 300; | |
|
msw
2016/06/08 01:16:32
nit: these are shared between dialog & bubble, add
juncai
2016/06/09 01:59:53
Done.
| |
| 28 | |
| 29 const int kChooserDialogHeight = 200; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 ChooserDialogView::ChooserDialogView(content::WebContents* web_contents, | |
| 34 ChooserController* chooser_controller) | |
| 35 : web_contents_(web_contents), chooser_controller_(chooser_controller) { | |
| 36 // ------------------------------------ | |
|
msw
2016/06/08 01:16:32
I'm starting to wonder if ChooserView should imple
juncai
2016/06/09 01:59:53
Changed ChooserContentView to be a subclass of vie
| |
| 37 // | Chooser dialog title | | |
| 38 // | -------------------------------- | | |
| 39 // | | option 0 | | | |
| 40 // | | option 1 | | | |
| 41 // | | option 2 | | | |
| 42 // | | | | | |
| 43 // | | | | | |
| 44 // | | | | | |
| 45 // | -------------------------------- | | |
| 46 // | [ Connect ] [ Cancel ] | | |
| 47 // |----------------------------------| | |
| 48 // | Not seeing your device? Get help | | |
| 49 // ------------------------------------ | |
| 50 | |
| 51 DCHECK(web_contents_); | |
| 52 | |
| 53 chooser_content_view_.reset( | |
| 54 new ChooserContentView(this, chooser_controller_)); | |
| 55 | |
| 56 table_view_ = chooser_content_view_->table_view(); | |
|
msw
2016/06/08 01:16:32
ditto nit (from other CL): remove this member.
juncai
2016/06/09 01:59:53
Done.
| |
| 57 table_model_ = table_view_->model(); | |
|
msw
2016/06/08 01:16:32
ditto nit (from other CL): remove this member.
juncai
2016/06/09 01:59:53
Done.
| |
| 58 | |
| 59 views::BoxLayout* layout = new views::BoxLayout( | |
| 60 views::BoxLayout::kVertical, 0, 0, views::kRelatedControlVerticalSpacing); | |
| 61 SetLayoutManager(layout); | |
| 62 views::View* table_parent = table_view_->CreateParentIfNecessary(); | |
| 63 AddChildView(table_parent); | |
| 64 layout->SetFlexForView(table_parent, 1); | |
| 65 } | |
| 66 | |
| 67 ChooserDialogView::~ChooserDialogView() { | |
| 68 table_view_->SetModel(nullptr); | |
|
msw
2016/06/08 01:16:32
Do these in the ChooserView dtor?
juncai
2016/06/09 01:59:53
Done.
| |
| 69 table_model_->SetObserver(nullptr); | |
| 70 } | |
| 71 | |
| 72 gfx::Size ChooserDialogView::GetPreferredSize() const { | |
| 73 return gfx::Size(kChooserDialogWidth, kChooserDialogHeight); | |
| 74 } | |
| 75 | |
| 76 base::string16 ChooserDialogView::GetWindowTitle() const { | |
| 77 base::string16 chooser_title; | |
| 78 url::Origin origin = chooser_controller_->GetOrigin(); | |
| 79 content::BrowserContext* browser_context = web_contents_->GetBrowserContext(); | |
| 80 extensions::ExtensionRegistry* extension_registry = | |
| 81 extensions::ExtensionRegistry::Get(browser_context); | |
| 82 if (extension_registry) { | |
| 83 const extensions::Extension* extension = | |
| 84 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | |
| 85 GURL(origin.Serialize())); | |
| 86 if (extension) | |
| 87 chooser_title = base::UTF8ToUTF16(extension->name()); | |
| 88 } | |
| 89 | |
| 90 if (chooser_title.empty()) { | |
| 91 chooser_title = url_formatter::FormatOriginForSecurityDisplay( | |
| 92 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | |
| 93 } | |
| 94 | |
| 95 return l10n_util::GetStringFUTF16(IDS_CHOOSER_BUBBLE_PROMPT, chooser_title); | |
| 96 } | |
| 97 | |
| 98 bool ChooserDialogView::ShouldShowCloseButton() const { | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 ui::ModalType ChooserDialogView::GetModalType() const { | |
| 103 return ui::MODAL_TYPE_CHILD; | |
| 104 } | |
| 105 | |
| 106 base::string16 ChooserDialogView::GetDialogButtonLabel( | |
| 107 ui::DialogButton button) const { | |
| 108 return chooser_content_view_->GetDialogButtonLabel(button); | |
| 109 } | |
| 110 | |
| 111 bool ChooserDialogView::IsDialogButtonEnabled(ui::DialogButton button) const { | |
| 112 return chooser_content_view_->IsDialogButtonEnabled(button); | |
| 113 } | |
| 114 | |
| 115 views::View* ChooserDialogView::CreateFootnoteView() { | |
| 116 return chooser_content_view_->CreateFootnoteView(this); | |
| 117 } | |
| 118 | |
| 119 bool ChooserDialogView::Accept() { | |
| 120 if (chooser_controller_) | |
| 121 chooser_controller_->Select(table_view_->selection_model().active()); | |
| 122 return true; | |
| 123 } | |
| 124 | |
| 125 bool ChooserDialogView::Cancel() { | |
| 126 if (chooser_controller_) | |
| 127 chooser_controller_->Cancel(); | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 bool ChooserDialogView::Close() { | |
| 132 if (chooser_controller_) | |
| 133 chooser_controller_->Close(); | |
| 134 return true; | |
| 135 } | |
| 136 | |
| 137 void ChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label, | |
| 138 const gfx::Range& range, | |
| 139 int event_flags) { | |
| 140 chooser_controller_->OpenHelpCenterUrl(); | |
| 141 } | |
| 142 | |
| 143 void ChooserDialogView::OnSelectionChanged() { | |
| 144 GetDialogClientView()->UpdateDialogButtons(); | |
| 145 } | |
| 146 | |
| 147 void ChromeExtensionChooserDialog::ShowDialogImpl( | |
|
msw
2016/06/08 01:16:32
Do we need to split ShowDialog and ShowDialogImpl?
juncai
2016/06/09 01:59:53
This is a similar pattern as:
https://cs.chromium.
msw
2016/06/09 18:40:04
Acknowledged; thanks for the explanation.
| |
| 148 ChooserController* chooser_controller) const { | |
| 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 150 DCHECK(chooser_controller); | |
| 151 | |
| 152 web_modal::WebContentsModalDialogManager* manager = | |
| 153 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); | |
| 154 if (manager) { | |
| 155 constrained_window::ShowWebModalDialogViews( | |
| 156 new ChooserDialogView(web_contents_, chooser_controller), | |
| 157 web_contents_); | |
| 158 } | |
| 159 } | |
| OLD | NEW |