Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/location_bar/location_bar.h" | 5 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" | 10 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" |
| 11 #include "content/public/browser/web_contents.h" | |
| 9 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
| 13 #include "extensions/common/constants.h" | |
| 10 #include "extensions/common/extension_set.h" | 14 #include "extensions/common/extension_set.h" |
| 11 #include "extensions/common/feature_switch.h" | 15 #include "extensions/common/feature_switch.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" | 16 #include "extensions/common/permissions/permissions_data.h" |
| 13 | 17 |
| 14 const char LocationBar::kSecurityChipFeatureVisibilityParam[] = "visibility"; | 18 const char LocationBar::kSecurityChipFeatureVisibilityParam[] = "visibility"; |
| 15 const char LocationBar::kSecurityChipFeatureAnimationParam[] = "animation"; | 19 const char LocationBar::kSecurityChipFeatureAnimationParam[] = "animation"; |
| 16 | 20 |
| 21 namespace { | |
| 22 const base::char16 kLineBreakChars[] = {'\n', '\r', '\t', | |
| 23 0x2028, // Line separator | |
| 24 0x2029, // Paragraph separator | |
| 25 0}; | |
| 26 } // namespace | |
| 27 | |
| 17 LocationBar::LocationBar(Profile* profile) : profile_(profile) { | 28 LocationBar::LocationBar(Profile* profile) : profile_(profile) { |
| 18 } | 29 } |
| 19 | 30 |
| 20 LocationBar::~LocationBar() { | 31 LocationBar::~LocationBar() { |
| 21 } | 32 } |
| 22 | 33 |
| 23 bool LocationBar::IsBookmarkStarHiddenByExtension() const { | 34 bool LocationBar::IsBookmarkStarHiddenByExtension() const { |
| 24 const extensions::ExtensionSet& extension_set = | 35 const extensions::ExtensionSet& extension_set = |
| 25 extensions::ExtensionRegistry::Get(profile_)->enabled_extensions(); | 36 extensions::ExtensionRegistry::Get(profile_)->enabled_extensions(); |
| 26 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); | 37 for (extensions::ExtensionSet::const_iterator i = extension_set.begin(); |
| 27 i != extension_set.end(); ++i) { | 38 i != extension_set.end(); ++i) { |
| 28 if (extensions::UIOverrides::RemovesBookmarkButton(i->get()) && | 39 if (extensions::UIOverrides::RemovesBookmarkButton(i->get()) && |
| 29 ((*i)->permissions_data()->HasAPIPermission( | 40 ((*i)->permissions_data()->HasAPIPermission( |
| 30 extensions::APIPermission::kBookmarkManagerPrivate) || | 41 extensions::APIPermission::kBookmarkManagerPrivate) || |
| 31 extensions::FeatureSwitch::enable_override_bookmarks_ui() | 42 extensions::FeatureSwitch::enable_override_bookmarks_ui() |
| 32 ->IsEnabled())) | 43 ->IsEnabled())) |
| 33 return true; | 44 return true; |
| 34 } | 45 } |
| 35 | 46 |
| 36 return false; | 47 return false; |
| 37 } | 48 } |
| 49 | |
| 50 base::string16 LocationBar::GetExtensionName( | |
| 51 const GURL& url, | |
| 52 content::WebContents* web_contents) const { | |
| 53 if (web_contents && url.SchemeIs(extensions::kExtensionScheme)) { | |
|
Peter Kasting
2016/12/14 22:47:07
Can there be no web_contents? Consider adding a c
meacer
2016/12/16 18:46:17
I don't see an obvious code path that would led to
Peter Kasting
2016/12/20 01:59:31
IIRC, the places where LocationBarView does this a
meacer
2016/12/21 01:38:56
Done, added a CHECK.
| |
| 54 content::BrowserContext* browser_context = | |
| 55 web_contents->GetBrowserContext(); | |
| 56 extensions::ExtensionRegistry* extension_registry = | |
| 57 extensions::ExtensionRegistry::Get(browser_context); | |
| 58 if (extension_registry) { | |
|
Peter Kasting
2016/12/14 22:47:07
Can this actually fail?
meacer
2016/12/16 18:46:17
Looks like it can't, removed the check.
| |
| 59 const extensions::Extension* extension = | |
| 60 extension_registry->enabled_extensions().GetByID(url.host()); | |
| 61 if (extension) { | |
| 62 base::string16 extension_name(base::UTF8ToUTF16(extension->name())); | |
| 63 base::ReplaceChars(extension_name, kLineBreakChars, | |
| 64 base::ASCIIToUTF16(" "), &extension_name); | |
|
Peter Kasting
2016/12/14 22:47:07
Why do you need this? It seems like CollapseWhite
meacer
2016/12/16 18:46:17
This is the rebase of an old CL, and I seem to rem
| |
| 65 return base::CollapseWhitespace(extension_name, false); | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 return base::string16(); | |
| 70 } | |
| OLD | NEW |