| 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/chooser_controller/chooser_controller.h" | 5 #include "chrome/browser/chooser_controller/chooser_controller.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" | 
| 9 #include "components/url_formatter/elide_url.h" | 9 #include "components/url_formatter/elide_url.h" | 
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" | 
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" | 
| 12 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" | 
| 13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" | 
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" | 
| 15 #include "url/origin.h" | 15 #include "url/origin.h" | 
| 16 | 16 | 
| 17 ChooserController::ChooserController(content::RenderFrameHost* owner, | 17 namespace { | 
| 18                                      int title_string_id_origin, |  | 
| 19                                      int title_string_id_extension) |  | 
| 20     : owning_frame_(owner), |  | 
| 21       title_string_id_origin_(title_string_id_origin), |  | 
| 22       title_string_id_extension_(title_string_id_extension) {} |  | 
| 23 | 18 | 
| 24 ChooserController::~ChooserController() {} | 19 base::string16 CreateTitle(content::RenderFrameHost* render_frame_host, | 
| 25 | 20                            int title_string_id_origin, | 
| 26 base::string16 ChooserController::GetTitle() const { | 21                            int title_string_id_extension) { | 
| 27   if (!owning_frame_) | 22   url::Origin origin = render_frame_host->GetLastCommittedOrigin(); | 
| 28     return base::string16(); |  | 
| 29 |  | 
| 30   url::Origin origin = owning_frame_->GetLastCommittedOrigin(); |  | 
| 31 | 23 | 
| 32   if (origin.scheme() == extensions::kExtensionScheme) { | 24   if (origin.scheme() == extensions::kExtensionScheme) { | 
| 33     content::WebContents* web_contents = | 25     content::WebContents* web_contents = | 
| 34         content::WebContents::FromRenderFrameHost(owning_frame_); | 26         content::WebContents::FromRenderFrameHost(render_frame_host); | 
| 35     content::BrowserContext* browser_context = | 27     content::BrowserContext* browser_context = | 
| 36         web_contents->GetBrowserContext(); | 28         web_contents->GetBrowserContext(); | 
| 37     extensions::ExtensionRegistry* extension_registry = | 29     extensions::ExtensionRegistry* extension_registry = | 
| 38         extensions::ExtensionRegistry::Get(browser_context); | 30         extensions::ExtensionRegistry::Get(browser_context); | 
| 39     if (extension_registry) { | 31     if (extension_registry) { | 
| 40       const extensions::Extension* extension = | 32       const extensions::Extension* extension = | 
| 41           extension_registry->enabled_extensions().GetByID(origin.host()); | 33           extension_registry->enabled_extensions().GetByID(origin.host()); | 
| 42       if (extension) { | 34       if (extension) { | 
| 43         return l10n_util::GetStringFUTF16(title_string_id_extension_, | 35         return l10n_util::GetStringFUTF16(title_string_id_extension, | 
| 44                                           base::UTF8ToUTF16(extension->name())); | 36                                           base::UTF8ToUTF16(extension->name())); | 
| 45       } | 37       } | 
| 46     } | 38     } | 
| 47   } | 39   } | 
| 48 | 40 | 
| 49   return l10n_util::GetStringFUTF16( | 41   return l10n_util::GetStringFUTF16( | 
| 50       title_string_id_origin_, | 42       title_string_id_origin, | 
| 51       url_formatter::FormatOriginForSecurityDisplay( | 43       url_formatter::FormatOriginForSecurityDisplay( | 
| 52           origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 44           origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 
| 53 } | 45 } | 
| 54 | 46 | 
|  | 47 }  // namespace | 
|  | 48 | 
|  | 49 ChooserController::ChooserController(content::RenderFrameHost* owner, | 
|  | 50                                      int title_string_id_origin, | 
|  | 51                                      int title_string_id_extension) { | 
|  | 52   if (owner) { | 
|  | 53     title_ = | 
|  | 54         CreateTitle(owner, title_string_id_origin, title_string_id_extension); | 
|  | 55   } | 
|  | 56 } | 
|  | 57 | 
|  | 58 ChooserController::~ChooserController() {} | 
|  | 59 | 
|  | 60 base::string16 ChooserController::GetTitle() const { | 
|  | 61   return title_; | 
|  | 62 } | 
|  | 63 | 
| 55 bool ChooserController::ShouldShowIconBeforeText() const { | 64 bool ChooserController::ShouldShowIconBeforeText() const { | 
| 56   return false; | 65   return false; | 
| 57 } | 66 } | 
| 58 | 67 | 
| 59 bool ChooserController::ShouldShowFootnoteView() const { | 68 bool ChooserController::ShouldShowFootnoteView() const { | 
| 60   return true; | 69   return true; | 
| 61 } | 70 } | 
| 62 | 71 | 
| 63 bool ChooserController::AllowMultipleSelection() const { | 72 bool ChooserController::AllowMultipleSelection() const { | 
| 64   return false; | 73   return false; | 
| 65 } | 74 } | 
| 66 | 75 | 
| 67 int ChooserController::GetSignalStrengthLevel(size_t index) const { | 76 int ChooserController::GetSignalStrengthLevel(size_t index) const { | 
| 68   return -1; | 77   return -1; | 
| 69 } | 78 } | 
| 70 | 79 | 
| 71 bool ChooserController::IsConnected(size_t index) const { | 80 bool ChooserController::IsConnected(size_t index) const { | 
| 72   return false; | 81   return false; | 
| 73 } | 82 } | 
| 74 | 83 | 
| 75 bool ChooserController::IsPaired(size_t index) const { | 84 bool ChooserController::IsPaired(size_t index) const { | 
| 76   return false; | 85   return false; | 
| 77 } | 86 } | 
| 78 | 87 | 
| 79 void ChooserController::OpenAdapterOffHelpUrl() const { | 88 void ChooserController::OpenAdapterOffHelpUrl() const { | 
| 80   NOTREACHED(); | 89   NOTREACHED(); | 
| 81 } | 90 } | 
| OLD | NEW | 
|---|