Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: chrome/browser/chooser_controller/chooser_controller.cc

Issue 2122073004: Display extension name on device chooser title (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_chooser_controller_to_chrome_browser
Patch Set: address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() {
16 return owning_frame_ ? owning_frame_->GetLastCommittedOrigin() 24 return l10n_util::GetStringFUTF16(
17 : url::Origin(); 25 title_prefix_has_quote_ ? IDS_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME
26 : IDS_DEVICE_CHOOSER_PROMPT_ORIGIN,
27 GetTitlePrefix());
18 } 28 }
29
30 base::string16 ChooserController::GetTitlePrefix() {
31 if (!owning_frame_)
32 return base::string16();
33
34 base::string16 title_prefix;
35 url::Origin origin = owning_frame_->GetLastCommittedOrigin();
36 if (origin.scheme() == extensions::kExtensionScheme) {
37 content::WebContents* web_contents =
38 content::WebContents::FromRenderFrameHost(owning_frame_);
39 content::BrowserContext* browser_context =
40 web_contents->GetBrowserContext();
41 extensions::ExtensionRegistry* extension_registry =
42 extensions::ExtensionRegistry::Get(browser_context);
43 if (extension_registry) {
44 const extensions::Extension* extension =
45 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
46 GURL(origin.Serialize()));
47 if (extension)
48 title_prefix = base::UTF8ToUTF16(extension->name());
49 }
50 }
51
52 if (title_prefix.empty()) {
53 title_prefix = url_formatter::FormatOriginForSecurityDisplay(
54 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
55 title_prefix_has_quote_ = false;
Reilly Grant (use Gerrit) 2016/07/11 23:31:40 This field is suspicious. Please just move the bod
juncai 2016/07/12 00:00:42 Done.
56 }
57
58 return title_prefix;
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698