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

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: rebase 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 "ui/base/l10n/l10n_util.h"
14 #include "url/gurl.h"
8 #include "url/origin.h" 15 #include "url/origin.h"
9 16
10 ChooserController::ChooserController(content::RenderFrameHost* owner) 17 ChooserController::ChooserController(content::RenderFrameHost* owner)
11 : owning_frame_(owner) {} 18 : owning_frame_(owner) {}
12 19
13 ChooserController::~ChooserController() {} 20 ChooserController::~ChooserController() {}
14 21
15 url::Origin ChooserController::GetOrigin() const { 22 base::string16 ChooserController::GetTitle() const {
16 return owning_frame_ ? owning_frame_->GetLastCommittedOrigin() 23 return l10n_util::GetStringFUTF16(IDS_DEVICE_CHOOSER_PROMPT,
17 : url::Origin(); 24 GetTitlePrefix());
18 } 25 }
26
27 base::string16 ChooserController::GetTitlePrefix() const {
28 if (!owning_frame_)
29 return base::string16();
30
31 base::string16 title_prefix;
32 url::Origin last_committed_origin = owning_frame_->GetLastCommittedOrigin();
33 content::WebContents* web_contents =
34 content::WebContents::FromRenderFrameHost(owning_frame_);
35 content::BrowserContext* browser_context = web_contents->GetBrowserContext();
36 extensions::ExtensionRegistry* extension_registry =
37 extensions::ExtensionRegistry::Get(browser_context);
38 if (extension_registry) {
39 const extensions::Extension* extension =
40 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
41 GURL(last_committed_origin.Serialize()));
42 if (extension)
43 title_prefix = base::UTF8ToUTF16(extension->name());
44 }
45
46 if (title_prefix.empty()) {
Reilly Grant (use Gerrit) 2016/07/11 21:48:03 We can determine if this is an extension URL or no
juncai 2016/07/11 23:16:44 Done.
47 title_prefix = url_formatter::FormatOriginForSecurityDisplay(
48 last_committed_origin,
49 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
50 } else {
51 // Add quote if the it is a Chrome app/extension name.
Reilly Grant (use Gerrit) 2016/07/11 21:48:02 Quotation marks need to be localized. Instead of r
juncai 2016/07/11 23:16:44 Done.
52 title_prefix.insert(title_prefix.begin(), '"');
53 title_prefix.insert(title_prefix.end(), '"');
54 }
55
56 return title_prefix;
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698