| 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/window/dialog_client_view.h" |
| 20 #include "url/origin.h" |
| 21 |
| 22 ChooserDialogView::ChooserDialogView(content::WebContents* web_contents, |
| 23 ChooserController* chooser_controller) |
| 24 : chooser_content_view_(nullptr), |
| 25 web_contents_(web_contents), |
| 26 chooser_controller_(chooser_controller) { |
| 27 // ------------------------------------ |
| 28 // | Chooser dialog title | |
| 29 // | -------------------------------- | |
| 30 // | | option 0 | | |
| 31 // | | option 1 | | |
| 32 // | | option 2 | | |
| 33 // | | | | |
| 34 // | | | | |
| 35 // | | | | |
| 36 // | -------------------------------- | |
| 37 // | [ Connect ] [ Cancel ] | |
| 38 // |----------------------------------| |
| 39 // | Not seeing your device? Get help | |
| 40 // ------------------------------------ |
| 41 |
| 42 DCHECK(web_contents_); |
| 43 |
| 44 chooser_content_view_ = new ChooserContentView(this, chooser_controller_); |
| 45 } |
| 46 |
| 47 ChooserDialogView::~ChooserDialogView() {} |
| 48 |
| 49 base::string16 ChooserDialogView::GetWindowTitle() const { |
| 50 base::string16 chooser_title; |
| 51 url::Origin origin = chooser_controller_->GetOrigin(); |
| 52 content::BrowserContext* browser_context = web_contents_->GetBrowserContext(); |
| 53 extensions::ExtensionRegistry* extension_registry = |
| 54 extensions::ExtensionRegistry::Get(browser_context); |
| 55 if (extension_registry) { |
| 56 const extensions::Extension* extension = |
| 57 extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
| 58 GURL(origin.Serialize())); |
| 59 if (extension) |
| 60 chooser_title = base::UTF8ToUTF16(extension->name()); |
| 61 } |
| 62 |
| 63 if (chooser_title.empty()) { |
| 64 chooser_title = url_formatter::FormatOriginForSecurityDisplay( |
| 65 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); |
| 66 } |
| 67 |
| 68 return l10n_util::GetStringFUTF16(IDS_CHOOSER_BUBBLE_PROMPT, chooser_title); |
| 69 } |
| 70 |
| 71 bool ChooserDialogView::ShouldShowCloseButton() const { |
| 72 return false; |
| 73 } |
| 74 |
| 75 ui::ModalType ChooserDialogView::GetModalType() const { |
| 76 return ui::MODAL_TYPE_CHILD; |
| 77 } |
| 78 |
| 79 base::string16 ChooserDialogView::GetDialogButtonLabel( |
| 80 ui::DialogButton button) const { |
| 81 return chooser_content_view_->GetDialogButtonLabel(button); |
| 82 } |
| 83 |
| 84 bool ChooserDialogView::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 85 return chooser_content_view_->IsDialogButtonEnabled(button); |
| 86 } |
| 87 |
| 88 views::View* ChooserDialogView::CreateFootnoteView() { |
| 89 return chooser_content_view_->CreateFootnoteView(this); |
| 90 } |
| 91 |
| 92 bool ChooserDialogView::Accept() { |
| 93 chooser_content_view_->Accept(); |
| 94 return true; |
| 95 } |
| 96 |
| 97 bool ChooserDialogView::Cancel() { |
| 98 chooser_content_view_->Cancel(); |
| 99 return true; |
| 100 } |
| 101 |
| 102 bool ChooserDialogView::Close() { |
| 103 chooser_content_view_->Close(); |
| 104 return true; |
| 105 } |
| 106 |
| 107 views::View* ChooserDialogView::GetContentsView() { |
| 108 return chooser_content_view_; |
| 109 } |
| 110 |
| 111 views::Widget* ChooserDialogView::GetWidget() { |
| 112 return chooser_content_view_->GetWidget(); |
| 113 } |
| 114 |
| 115 const views::Widget* ChooserDialogView::GetWidget() const { |
| 116 return chooser_content_view_->GetWidget(); |
| 117 } |
| 118 |
| 119 void ChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label, |
| 120 const gfx::Range& range, |
| 121 int event_flags) { |
| 122 chooser_content_view_->StyledLabelLinkClicked(); |
| 123 } |
| 124 |
| 125 void ChooserDialogView::OnSelectionChanged() { |
| 126 GetDialogClientView()->UpdateDialogButtons(); |
| 127 } |
| 128 |
| 129 views::TableView* ChooserDialogView::table_view_for_test() const { |
| 130 return chooser_content_view_->table_view_for_test(); |
| 131 } |
| 132 |
| 133 void ChromeExtensionChooserDialog::ShowDialogImpl( |
| 134 ChooserController* chooser_controller) const { |
| 135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 136 DCHECK(chooser_controller); |
| 137 |
| 138 web_modal::WebContentsModalDialogManager* manager = |
| 139 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 140 if (manager) { |
| 141 constrained_window::ShowWebModalDialogViews( |
| 142 new ChooserDialogView(web_contents_, chooser_controller), |
| 143 web_contents_); |
| 144 } |
| 145 } |
| OLD | NEW |