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/grit/generated_resources.h" | |
| 10 #include "components/chooser_controller/chooser_controller.h" | |
| 11 #include "components/constrained_window/constrained_window_views.h" | |
| 12 #include "components/url_formatter/elide_url.h" | |
| 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 #include "extensions/browser/extension_registry.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/views/controls/table/table_view.h" | |
| 18 #include "url/origin.h" | |
| 19 | |
| 20 ChooserDialogView::ChooserDialogView(content::WebContents* web_contents, | |
| 21 ChooserController* controller) | |
| 22 : ChooserContentView(nullptr, views::BubbleBorder::FLOAT, controller), | |
| 23 web_contents_(web_contents) {} | |
| 24 | |
| 25 ChooserDialogView::~ChooserDialogView() {} | |
| 26 | |
| 27 base::string16 ChooserDialogView::GetWindowTitle() const { | |
| 28 base::string16 chooser_title; | |
| 29 url::Origin origin = chooser_controller()->GetOrigin(); | |
| 30 content::BrowserContext* browser_context = web_contents_->GetBrowserContext(); | |
| 31 extensions::ExtensionRegistry* extension_registry = | |
| 32 extensions::ExtensionRegistry::Get(browser_context); | |
| 33 if (extension_registry) { | |
| 34 const extensions::Extension* extension = | |
| 35 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | |
| 36 GURL(origin.Serialize())); | |
| 37 if (extension) | |
| 38 chooser_title = base::UTF8ToUTF16(extension->name()); | |
| 39 } | |
| 40 | |
| 41 if (chooser_title.empty()) { | |
| 42 chooser_title = url_formatter::FormatOriginForSecurityDisplay( | |
| 43 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | |
| 44 } | |
| 45 | |
| 46 return l10n_util::GetStringFUTF16(IDS_CHOOSER_BUBBLE_PROMPT, chooser_title); | |
| 47 } | |
| 48 | |
| 49 ui::ModalType ChooserDialogView::GetModalType() const { | |
| 50 return ui::MODAL_TYPE_CHILD; | |
| 51 } | |
| 52 | |
| 53 void ChooserDialogView::DeleteDelegate() { | |
| 54 delete this; | |
|
msw
2016/06/03 19:46:24
Is this actually needed? DialogDelegateView::Delet
juncai
2016/06/07 23:19:39
removed.
Done.
| |
| 55 } | |
| 56 | |
| 57 bool ChooserDialogView::Accept() { | |
| 58 if (chooser_controller()) | |
| 59 chooser_controller()->Select(table_view()->selection_model().active()); | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 bool ChooserDialogView::Cancel() { | |
| 64 if (chooser_controller()) | |
| 65 chooser_controller()->Cancel(); | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 69 bool ChooserDialogView::Close() { | |
| 70 if (chooser_controller()) | |
| 71 chooser_controller()->Close(); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void ChromeExtensionChooserDialog::ShowDialog( | |
| 76 ChooserController* chooser_controller) const { | |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 78 | |
| 79 web_modal::WebContentsModalDialogManager* manager = | |
| 80 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); | |
| 81 if (manager) | |
| 82 constrained_window::ShowWebModalDialogViews( | |
| 83 new ChooserDialogView(web_contents_, chooser_controller), | |
| 84 web_contents_); | |
| 85 } | |
| OLD | NEW |