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/chooser_controller/chooser_controller.h" | 5 #include "chrome/browser/chooser_controller/chooser_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/grit/generated_resources.h" | |
| 9 #include "components/url_formatter/elide_url.h" | |
| 7 #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" | |
| 12 #include "extensions/browser/extension_registry.h" | |
| 13 #include "extensions/common/constants.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "url/gurl.h" | |
| 8 #include "url/origin.h" | 16 #include "url/origin.h" |
| 9 | 17 |
| 10 ChooserController::ChooserController(content::RenderFrameHost* owner) | 18 ChooserController::ChooserController(content::RenderFrameHost* owner) |
| 11 : owning_frame_(owner) {} | 19 : owning_frame_(owner) {} |
| 12 | 20 |
| 13 ChooserController::~ChooserController() {} | 21 ChooserController::~ChooserController() {} |
| 14 | 22 |
| 15 url::Origin ChooserController::GetOrigin() const { | 23 base::string16 ChooserController::GetTitle() const { |
| 16 return owning_frame_ ? owning_frame_->GetLastCommittedOrigin() | 24 if (!owning_frame_) |
| 17 : url::Origin(); | 25 return base::string16(); |
| 26 | |
| 27 base::string16 title_prefix; | |
| 28 url::Origin origin = owning_frame_->GetLastCommittedOrigin(); | |
| 29 if (origin.scheme() == extensions::kExtensionScheme) { | |
| 30 content::WebContents* web_contents = | |
| 31 content::WebContents::FromRenderFrameHost(owning_frame_); | |
| 32 content::BrowserContext* browser_context = | |
| 33 web_contents->GetBrowserContext(); | |
| 34 extensions::ExtensionRegistry* extension_registry = | |
| 35 extensions::ExtensionRegistry::Get(browser_context); | |
| 36 if (extension_registry) { | |
| 37 const extensions::Extension* extension = | |
| 38 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | |
| 39 GURL(origin.Serialize())); | |
|
Reilly Grant (use Gerrit)
2016/07/12 00:12:05
You can use extension_registry->enabled_extensions
juncai
2016/07/12 01:14:43
Done.
| |
| 40 if (extension) | |
| 41 title_prefix = base::UTF8ToUTF16(extension->name()); | |
|
Reilly Grant (use Gerrit)
2016/07/12 00:12:05
No need to set title_prefix here, just return l10n
juncai
2016/07/12 01:14:43
Done.
| |
| 42 } | |
| 43 } | |
| 44 | |
| 45 if (title_prefix.empty()) { | |
| 46 title_prefix = url_formatter::FormatOriginForSecurityDisplay( | |
| 47 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC); | |
| 48 return l10n_util::GetStringFUTF16(IDS_DEVICE_CHOOSER_PROMPT_ORIGIN, | |
| 49 title_prefix); | |
| 50 } else { | |
| 51 return l10n_util::GetStringFUTF16(IDS_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME, | |
| 52 title_prefix); | |
| 53 } | |
| 18 } | 54 } |
| OLD | NEW |