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

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

Issue 2746313002: Remove RenderFrameHost pointer from ChooserController. (Closed)
Patch Set: 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 ChooserController::ChooserController(content::RenderFrameHost* owner,
18 int title_string_id_origin, 18 int title_string_id_origin,
19 int title_string_id_extension) 19 int title_string_id_extension) {
20 : owning_frame_(owner), 20 if (owner) {
21 title_string_id_origin_(title_string_id_origin), 21 url::Origin origin = owner->GetLastCommittedOrigin();
22 title_string_id_extension_(title_string_id_extension) {} 22
23 if (origin.scheme() == extensions::kExtensionScheme) {
24 content::WebContents* web_contents =
25 content::WebContents::FromRenderFrameHost(owner);
26 content::BrowserContext* browser_context =
27 web_contents->GetBrowserContext();
28 extensions::ExtensionRegistry* extension_registry =
29 extensions::ExtensionRegistry::Get(browser_context);
30 if (extension_registry) {
31 const extensions::Extension* extension =
32 extension_registry->enabled_extensions().GetByID(origin.host());
33 if (extension) {
34 title_ = l10n_util::GetStringFUTF16(
35 title_string_id_extension, base::UTF8ToUTF16(extension->name()));
36 }
37 }
38 } else {
39 title_ = l10n_util::GetStringFUTF16(
msw 2017/03/13 23:48:51 We should also assign this value to |title_| if th
Reilly Grant (use Gerrit) 2017/03/14 20:44:10 Done.
40 title_string_id_origin,
41 url_formatter::FormatOriginForSecurityDisplay(
42 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
43 }
44 }
45 }
23 46
24 ChooserController::~ChooserController() {} 47 ChooserController::~ChooserController() {}
25 48
26 base::string16 ChooserController::GetTitle() const { 49 base::string16 ChooserController::GetTitle() const {
27 if (!owning_frame_) 50 return title_;
28 return base::string16();
29
30 url::Origin origin = owning_frame_->GetLastCommittedOrigin();
31
32 if (origin.scheme() == extensions::kExtensionScheme) {
33 content::WebContents* web_contents =
34 content::WebContents::FromRenderFrameHost(owning_frame_);
35 content::BrowserContext* browser_context =
36 web_contents->GetBrowserContext();
37 extensions::ExtensionRegistry* extension_registry =
38 extensions::ExtensionRegistry::Get(browser_context);
39 if (extension_registry) {
40 const extensions::Extension* extension =
41 extension_registry->enabled_extensions().GetByID(origin.host());
42 if (extension) {
43 return l10n_util::GetStringFUTF16(title_string_id_extension_,
44 base::UTF8ToUTF16(extension->name()));
45 }
46 }
47 }
48
49 return l10n_util::GetStringFUTF16(
50 title_string_id_origin_,
51 url_formatter::FormatOriginForSecurityDisplay(
52 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
53 } 51 }
54 52
55 bool ChooserController::ShouldShowIconBeforeText() const { 53 bool ChooserController::ShouldShowIconBeforeText() const {
56 return false; 54 return false;
57 } 55 }
58 56
59 bool ChooserController::ShouldShowFootnoteView() const { 57 bool ChooserController::ShouldShowFootnoteView() const {
60 return true; 58 return true;
61 } 59 }
62 60
63 bool ChooserController::AllowMultipleSelection() const { 61 bool ChooserController::AllowMultipleSelection() const {
64 return false; 62 return false;
65 } 63 }
66 64
67 int ChooserController::GetSignalStrengthLevel(size_t index) const { 65 int ChooserController::GetSignalStrengthLevel(size_t index) const {
68 return -1; 66 return -1;
69 } 67 }
70 68
71 bool ChooserController::IsConnected(size_t index) const { 69 bool ChooserController::IsConnected(size_t index) const {
72 return false; 70 return false;
73 } 71 }
74 72
75 bool ChooserController::IsPaired(size_t index) const { 73 bool ChooserController::IsPaired(size_t index) const {
76 return false; 74 return false;
77 } 75 }
78 76
79 void ChooserController::OpenAdapterOffHelpUrl() const { 77 void ChooserController::OpenAdapterOffHelpUrl() const {
80 NOTREACHED(); 78 NOTREACHED();
81 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698