Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/extensions/chooser_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/chooser_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/chooser_controller/chooser_controller.h" | 8 #include "chrome/browser/chooser_controller/chooser_controller.h" |
| 9 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" | 9 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" |
| 10 #include "chrome/browser/ui/views/chooser_content_view.h" | 10 #include "chrome/browser/ui/views/chooser_content_view.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/constrained_window/constrained_window_views.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" | 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #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" | 15 #include "ui/views/controls/styled_label.h" |
| 19 #include "ui/views/window/dialog_client_view.h" | 16 #include "ui/views/window/dialog_client_view.h" |
| 20 | 17 |
| 21 ChooserDialogView::ChooserDialogView( | 18 ChooserDialogView::ChooserDialogView( |
| 22 content::WebContents* web_contents, | |
| 23 std::unique_ptr<ChooserController> chooser_controller) | 19 std::unique_ptr<ChooserController> chooser_controller) |
| 24 : web_contents_(web_contents), chooser_content_view_(nullptr) { | 20 : chooser_content_view_(nullptr) { |
|
Reilly Grant (use Gerrit)
2016/07/11 21:48:03
This doesn't need to be initialized here because i
juncai
2016/07/11 23:16:44
Done.
| |
| 25 // ------------------------------------ | 21 // ------------------------------------ |
| 26 // | Chooser dialog title | | 22 // | Chooser dialog title | |
| 27 // | -------------------------------- | | 23 // | -------------------------------- | |
| 28 // | | option 0 | | | 24 // | | option 0 | | |
| 29 // | | option 1 | | | 25 // | | option 1 | | |
| 30 // | | option 2 | | | 26 // | | option 2 | | |
| 31 // | | | | | 27 // | | | | |
| 32 // | | | | | 28 // | | | | |
| 33 // | | | | | 29 // | | | | |
| 34 // | -------------------------------- | | 30 // | -------------------------------- | |
| 35 // | [ Connect ] [ Cancel ] | | 31 // | [ Connect ] [ Cancel ] | |
| 36 // |----------------------------------| | 32 // |----------------------------------| |
| 37 // | Not seeing your device? Get help | | 33 // | Not seeing your device? Get help | |
| 38 // ------------------------------------ | 34 // ------------------------------------ |
| 39 | 35 |
| 40 DCHECK(web_contents_); | |
| 41 DCHECK(chooser_controller); | 36 DCHECK(chooser_controller); |
| 42 origin_ = chooser_controller->GetOrigin(); | |
| 43 chooser_content_view_ = | 37 chooser_content_view_ = |
| 44 new ChooserContentView(this, std::move(chooser_controller)); | 38 new ChooserContentView(this, std::move(chooser_controller)); |
| 45 } | 39 } |
| 46 | 40 |
| 47 ChooserDialogView::~ChooserDialogView() {} | 41 ChooserDialogView::~ChooserDialogView() {} |
| 48 | 42 |
| 49 base::string16 ChooserDialogView::GetWindowTitle() const { | 43 base::string16 ChooserDialogView::GetWindowTitle() const { |
| 50 base::string16 chooser_title; | 44 return chooser_content_view_->GetWindowTitle(); |
| 51 content::BrowserContext* browser_context = web_contents_->GetBrowserContext(); | |
| 52 extensions::ExtensionRegistry* extension_registry = | |
| 53 extensions::ExtensionRegistry::Get(browser_context); | |
| 54 if (extension_registry) { | |
| 55 const extensions::Extension* extension = | |
| 56 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | |
| 57 GURL(origin_.Serialize())); | |
| 58 if (extension) | |
| 59 chooser_title = base::UTF8ToUTF16(extension->name()); | |
| 60 } | |
| 61 | |
| 62 if (chooser_title.empty()) { | |
| 63 chooser_title = url_formatter::FormatOriginForSecurityDisplay( | |
| 64 origin_, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | |
| 65 } | |
| 66 | |
| 67 return l10n_util::GetStringFUTF16(IDS_DEVICE_CHOOSER_PROMPT, chooser_title); | |
| 68 } | 45 } |
| 69 | 46 |
| 70 bool ChooserDialogView::ShouldShowCloseButton() const { | 47 bool ChooserDialogView::ShouldShowCloseButton() const { |
| 71 return false; | 48 return false; |
| 72 } | 49 } |
| 73 | 50 |
| 74 ui::ModalType ChooserDialogView::GetModalType() const { | 51 ui::ModalType ChooserDialogView::GetModalType() const { |
| 75 return ui::MODAL_TYPE_CHILD; | 52 return ui::MODAL_TYPE_CHILD; |
| 76 } | 53 } |
| 77 | 54 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 108 |
| 132 void ChromeExtensionChooserDialog::ShowDialogImpl( | 109 void ChromeExtensionChooserDialog::ShowDialogImpl( |
| 133 std::unique_ptr<ChooserController> chooser_controller) const { | 110 std::unique_ptr<ChooserController> chooser_controller) const { |
| 134 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 135 DCHECK(chooser_controller); | 112 DCHECK(chooser_controller); |
| 136 | 113 |
| 137 web_modal::WebContentsModalDialogManager* manager = | 114 web_modal::WebContentsModalDialogManager* manager = |
| 138 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); | 115 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 139 if (manager) { | 116 if (manager) { |
| 140 constrained_window::ShowWebModalDialogViews( | 117 constrained_window::ShowWebModalDialogViews( |
| 141 new ChooserDialogView(web_contents_, std::move(chooser_controller)), | 118 new ChooserDialogView(std::move(chooser_controller)), web_contents_); |
| 142 web_contents_); | |
| 143 } | 119 } |
| 144 } | 120 } |
| OLD | NEW |