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

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

Issue 2746313002: Remove RenderFrameHost pointer from ChooserController. (Closed)
Patch Set: Address comments. Created 3 years, 9 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/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();
juncai 2017/03/14 20:57:22 This if condition is not checked in the new code,
Reilly Grant (use Gerrit) 2017/03/14 21:21:01 Fixed.
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 : title_(CreateTitle(owner,
53 title_string_id_origin,
54 title_string_id_extension)) {}
55
56 ChooserController::~ChooserController() {}
57
58 base::string16 ChooserController::GetTitle() const {
59 return title_;
60 }
61
55 bool ChooserController::ShouldShowIconBeforeText() const { 62 bool ChooserController::ShouldShowIconBeforeText() const {
56 return false; 63 return false;
57 } 64 }
58 65
59 bool ChooserController::ShouldShowFootnoteView() const { 66 bool ChooserController::ShouldShowFootnoteView() const {
60 return true; 67 return true;
61 } 68 }
62 69
63 bool ChooserController::AllowMultipleSelection() const { 70 bool ChooserController::AllowMultipleSelection() const {
64 return false; 71 return false;
65 } 72 }
66 73
67 int ChooserController::GetSignalStrengthLevel(size_t index) const { 74 int ChooserController::GetSignalStrengthLevel(size_t index) const {
68 return -1; 75 return -1;
69 } 76 }
70 77
71 bool ChooserController::IsConnected(size_t index) const { 78 bool ChooserController::IsConnected(size_t index) const {
72 return false; 79 return false;
73 } 80 }
74 81
75 bool ChooserController::IsPaired(size_t index) const { 82 bool ChooserController::IsPaired(size_t index) const {
76 return false; 83 return false;
77 } 84 }
78 85
79 void ChooserController::OpenAdapterOffHelpUrl() const { 86 void ChooserController::OpenAdapterOffHelpUrl() const {
80 NOTREACHED(); 87 NOTREACHED();
81 } 88 }
OLDNEW
« no previous file with comments | « chrome/browser/chooser_controller/chooser_controller.h ('k') | chrome/browser/chooser_controller/mock_chooser_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698