Commit e59d5715 authored by wittman@chromium.org's avatar wittman@chromium.org

Move bookmarks_ui manifest key from chrome_settings_overrides to chrome_ui_overrides

Separates bookmark UI overrides from settings overrides to avoid
future conflict in requirements/goals of the two different pieces of
functionality.

Retains deprecated support under chrome_settings_overrides for
backwards compatibility. This will be removed for the M36 release.

BUG=349049
R=kalman@chromium.org, pkasting@chromium.org, vasilii@chromium.org

Review URL: https://codereview.chromium.org/183883033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255959 0039d316-1c4b-4281-b951-d872f2087c98
parent a6e8a0af
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/ui/accelerator_utils.h" #include "chrome/browser/ui/accelerator_utils.h"
#include "chrome/common/extensions/api/commands/commands_handler.h" #include "chrome/common/extensions/api/commands/commands_handler.h"
#include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h" #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h" #include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -172,12 +173,16 @@ CommandService* CommandService::Get(content::BrowserContext* context) { ...@@ -172,12 +173,16 @@ CommandService* CommandService::Get(content::BrowserContext* context) {
// static // static
bool CommandService::RemovesBookmarkShortcut( bool CommandService::RemovesBookmarkShortcut(
const extensions::Extension* extension) { const extensions::Extension* extension) {
using extensions::UIOverrides;
using extensions::SettingsOverrides; using extensions::SettingsOverrides;
const UIOverrides* ui_overrides = UIOverrides::Get(extension);
const SettingsOverrides* settings_overrides = const SettingsOverrides* settings_overrides =
SettingsOverrides::Get(extension); SettingsOverrides::Get(extension);
return settings_overrides && return ((settings_overrides &&
SettingsOverrides::RemovesBookmarkShortcut(*settings_overrides) && SettingsOverrides::RemovesBookmarkShortcut(*settings_overrides)) ||
(ui_overrides &&
UIOverrides::RemovesBookmarkShortcut(*ui_overrides))) &&
(extensions::PermissionsData::HasAPIPermission( (extensions::PermissionsData::HasAPIPermission(
extension, extension,
extensions::APIPermission::kBookmarkManagerPrivate) || extensions::APIPermission::kBookmarkManagerPrivate) ||
......
...@@ -241,17 +241,9 @@ IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_DontOverwriteSystemShortcuts) { ...@@ -241,17 +241,9 @@ IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_DontOverwriteSystemShortcuts) {
ASSERT_TRUE(result); ASSERT_TRUE(result);
} }
#if defined(OS_WIN)
// TODO(wittman): Enable the test once the bookmarks aren't a part of Settings
// Overrides API.
#define MAYBE_OverwriteBookmarkShortcut OverwriteBookmarkShortcut
#else
#define MAYBE_OverwriteBookmarkShortcut DISABLED_OverwriteBookmarkShortcut
#endif
// This test validates that an extension can override the Chrome bookmark // This test validates that an extension can override the Chrome bookmark
// shortcut if it has requested to do so. // shortcut if it has requested to do so.
IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_OverwriteBookmarkShortcut) { IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) {
ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h" #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
#include "extensions/browser/extension_system.h" #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
#include "extensions/common/feature_switch.h" #include "extensions/common/feature_switch.h"
#include "extensions/common/permissions/permissions_data.h" #include "extensions/common/permissions/permissions_data.h"
...@@ -20,21 +21,19 @@ LocationBar::~LocationBar() { ...@@ -20,21 +21,19 @@ LocationBar::~LocationBar() {
} }
bool LocationBar::IsBookmarkStarHiddenByExtension() const { bool LocationBar::IsBookmarkStarHiddenByExtension() const {
const ExtensionService* extension_service = const extensions::ExtensionSet& extension_set =
extensions::ExtensionSystem::Get(profile_)->extension_service(); extensions::ExtensionRegistry::Get(profile_)->enabled_extensions();
// Extension service may be NULL during unit test execution. for (extensions::ExtensionSet::const_iterator i = extension_set.begin();
if (!extension_service) i != extension_set.end(); ++i) {
return false; using extensions::UIOverrides;
const extensions::ExtensionSet* extension_set =
extension_service->extensions();
for (extensions::ExtensionSet::const_iterator i = extension_set->begin();
i != extension_set->end(); ++i) {
using extensions::SettingsOverrides; using extensions::SettingsOverrides;
const UIOverrides* ui_overrides = UIOverrides::Get(i->get());
const SettingsOverrides* settings_overrides = const SettingsOverrides* settings_overrides =
SettingsOverrides::Get(i->get()); SettingsOverrides::Get(i->get());
if (settings_overrides && if (((settings_overrides &&
SettingsOverrides::RemovesBookmarkButton(*settings_overrides) && SettingsOverrides::RemovesBookmarkButton(*settings_overrides)) ||
(ui_overrides &&
UIOverrides::RemovesBookmarkButton(*ui_overrides))) &&
(extensions::PermissionsData::HasAPIPermission( (extensions::PermissionsData::HasAPIPermission(
*i, *i,
extensions::APIPermission::kBookmarkManagerPrivate) || extensions::APIPermission::kBookmarkManagerPrivate) ||
......
...@@ -214,6 +214,8 @@ ...@@ -214,6 +214,8 @@
'common/extensions/manifest_handlers/settings_overrides_handler.h', 'common/extensions/manifest_handlers/settings_overrides_handler.h',
'common/extensions/manifest_handlers/theme_handler.cc', 'common/extensions/manifest_handlers/theme_handler.cc',
'common/extensions/manifest_handlers/theme_handler.h', 'common/extensions/manifest_handlers/theme_handler.h',
'common/extensions/manifest_handlers/ui_overrides_handler.cc',
'common/extensions/manifest_handlers/ui_overrides_handler.h',
'common/extensions/manifest_url_handler.cc', 'common/extensions/manifest_url_handler.cc',
'common/extensions/manifest_url_handler.h', 'common/extensions/manifest_url_handler.h',
'common/extensions/message_bundle.cc', 'common/extensions/message_bundle.cc',
......
...@@ -1809,6 +1809,7 @@ ...@@ -1809,6 +1809,7 @@
'common/extensions/manifest_handlers/exclude_matches_manifest_unittest.cc', 'common/extensions/manifest_handlers/exclude_matches_manifest_unittest.cc',
'common/extensions/manifest_handlers/externally_connectable_unittest.cc', 'common/extensions/manifest_handlers/externally_connectable_unittest.cc',
'common/extensions/manifest_handlers/settings_overrides_handler_unittest.cc', 'common/extensions/manifest_handlers/settings_overrides_handler_unittest.cc',
'common/extensions/manifest_handlers/ui_overrides_handler_unittest.cc',
'common/extensions/manifest_tests/extension_manifest_test.cc', 'common/extensions/manifest_tests/extension_manifest_test.cc',
'common/extensions/manifest_tests/extension_manifests_background_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_background_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_chromepermission_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_chromepermission_unittest.cc',
......
...@@ -83,6 +83,18 @@ ...@@ -83,6 +83,18 @@
"channel": "dev", "channel": "dev",
"extension_types": ["extension"], "extension_types": ["extension"],
"platforms": ["win"] "platforms": ["win"]
}, { // TODO(wittman): remove this section for M36.
"channel": "stable",
"extension_types": ["extension"],
"whitelist": [
"CB2E4E7174A398FCB3AFA6840500C2E1D22DA7B2", // Bookmark Manager
"D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900
"D57DE394F36DC1C3220E7604C575D29C51A6C495" // http://crbug.com/319444
]
}],
"chrome_ui_overrides": [{
"channel": "dev",
"extension_types": ["extension"]
}, { }, {
"channel": "stable", "channel": "stable",
"extension_types": ["extension"], "extension_types": ["extension"],
......
...@@ -43,10 +43,12 @@ ...@@ -43,10 +43,12 @@
"type": "object", "type": "object",
"description": "Chrome settings which can be overriden by an extension.", "description": "Chrome settings which can be overriden by an extension.",
"properties": { "properties": {
// TODO(wittman): Remove for M36.
"bookmarks_ui": { "bookmarks_ui": {
"type": "object", "type": "object",
"description": "Settings to permit bookmarks user interface customization by extensions.", "description": "Settings to permit bookmarks user interface customization by extensions.",
"optional": true, "optional": true,
"nodoc": true,
"properties": { "properties": {
"remove_button": { "remove_button": {
"type": "boolean", "type": "boolean",
...@@ -55,10 +57,9 @@ ...@@ -55,10 +57,9 @@
}, },
"remove_bookmark_shortcut": { "remove_bookmark_shortcut": {
"type": "boolean", "type": "boolean",
"description": "If <code>true</code>, the built-in \"Bookmark this page...\" shortcut key is removed and the extension is permitted to override the shortcut by binding it in the commands section of the manifest.", "description": "If <code>true</code>, the built-in \"Bookmark this page...\" shortcut key is removed and the extension is permitted to override the shortcut by binding it in the commands section of the manifest. The corresponding menu item is also removed or overridden as well.",
"optional": true "optional": true
}, },
// TODO(wittman): Remove for M36.
"hide_bookmark_button": { "hide_bookmark_button": {
"type": "boolean", "type": "boolean",
"description": "Deprecated. Use remove_button instead.", "description": "Deprecated. Use remove_button instead.",
...@@ -151,6 +152,30 @@ ...@@ -151,6 +152,30 @@
} }
} }
}, },
{
"id": "ChromeUIOverrides",
"type": "object",
"description": "Chrome user interface features which can be overriden by an extension.",
"properties": {
"bookmarks_ui": {
"type": "object",
"description": "Settings to permit bookmarks user interface customization by extensions.",
"optional": true,
"properties": {
"remove_button": {
"type": "boolean",
"description": "If <code>true</code>, the built-in bookmark button will be removed from the user interface.",
"optional": true
},
"remove_bookmark_shortcut": {
"type": "boolean",
"description": "If <code>true</code>, the built-in \"Bookmark this page...\" shortcut key is removed and the extension is permitted to override the shortcut by binding it in the commands section of the manifest.",
"optional": true
}
}
}
}
},
{ {
"id": "SocketHostPatterns", "id": "SocketHostPatterns",
"description": "<p>A single string or a list of strings representing host:port patterns.</p>", "description": "<p>A single string or a list of strings representing host:port patterns.</p>",
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/common/extensions/manifest_handlers/nacl_modules_handler.h" #include "chrome/common/extensions/manifest_handlers/nacl_modules_handler.h"
#include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h" #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.h"
#include "chrome/common/extensions/manifest_handlers/theme_handler.h" #include "chrome/common/extensions/manifest_handlers/theme_handler.h"
#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "chrome/common/extensions/manifest_url_handler.h" #include "chrome/common/extensions/manifest_url_handler.h"
#include "chrome/common/extensions/mime_types_handler.h" #include "chrome/common/extensions/mime_types_handler.h"
#include "extensions/common/manifest_handlers/requirements_info.h" #include "extensions/common/manifest_handlers/requirements_info.h"
...@@ -77,6 +78,7 @@ void RegisterChromeManifestHandlers() { ...@@ -77,6 +78,7 @@ void RegisterChromeManifestHandlers() {
(new SystemIndicatorHandler)->Register(); (new SystemIndicatorHandler)->Register();
(new ThemeHandler)->Register(); (new ThemeHandler)->Register();
(new TtsEngineManifestHandler)->Register(); (new TtsEngineManifestHandler)->Register();
(new UIOverridesHandler)->Register();
(new UpdateURLHandler)->Register(); (new UpdateURLHandler)->Register();
(new UrlHandlersParser)->Register(); (new UrlHandlersParser)->Register();
(new URLOverridesHandler)->Register(); (new URLOverridesHandler)->Register();
......
<h1>Settings Overrides</h1> <h1>Settings Overrides</h1>
<p> <p>
Settings overrides are a way for extensions to override selected Chrome settings Settings overrides are a way for extensions to override selected Chrome settings.
and user interface properties.
</p> </p>
<h2 id="bookmarks">Bookmarks User Interface</h2>
<p>
Register the settings you want to override in the
<a href="manifest.html">extension manifest</a> like this:
</p>
<pre>{
"name": "My extension",
...
<b>
"chrome_settings_overrides" : {
"bookmarks_ui": {
"remove_button": "true",
"remove_bookmark_shortcut": "true"
}
}</b>,
...
}</pre>
<p>
<ul>
<li>
<a href="#bookmarks_ui">Bookmark button</a>: the "star" button that is used
to bookmark pages. Extensions may remove this button using the settings
overrides, and optionally replace it with a browser action or page action.
</li>
<li>
<a href="#bookmarks_ui">Bookmark shortcut</a>: the shortcut key that is
used to bookmark a page (Ctrl-D on Windows). Extensions may remove this
shortcut via the settings overrides, and optionally bind their own command
to it using the <code>commands</code> section of the manifest.
</li>
</ul>
</p>
<p class="note">
<b>Note:</b> Settings overrides for <code>bookmarks_ui</code> are only enabled
in the Chrome Dev release, and Chrome must be started with the
<code>--enable-override-bookmarks-ui=1</code> command line flag to enable
bookmarks user interface overrides.</p>
<h2 id="others">Homepage, Search Provider, and Startup Pages</h2> <h2 id="others">Homepage, Search Provider, and Startup Pages</h2>
<p> <p>
Here is an example how <a href="#homepage">homepage</a>, <a Here is an example how <a href="#homepage">homepage</a>, <a
......
<h1>Settings Overrides</h1> <h1>User Interface Overrides</h1>
<p> <p>
Settings overrides are a way for extensions to override selected Chrome settings User interface overrides are a way for extensions to override selected Chrome
and user interface properties. user interface properties.
</p> </p>
<h2 id="bookmarks">Bookmarks User Interface</h2> <h2 id="bookmarks">Bookmarks User Interface</h2>
<p> <p>
Register the settings you want to override in the Register the user interface properties you want to override in the
<a href="manifest.html">extension manifest</a> like this: <a href="manifest.html">extension manifest</a> like this:
</p> </p>
...@@ -15,7 +15,7 @@ Register the settings you want to override in the ...@@ -15,7 +15,7 @@ Register the settings you want to override in the
"name": "My extension", "name": "My extension",
... ...
<b> <b>
"chrome_settings_overrides" : { "chrome_ui_overrides" : {
"bookmarks_ui": { "bookmarks_ui": {
"remove_button": "true", "remove_button": "true",
"remove_bookmark_shortcut": "true" "remove_bookmark_shortcut": "true"
...@@ -33,10 +33,12 @@ Register the settings you want to override in the ...@@ -33,10 +33,12 @@ Register the settings you want to override in the
</li> </li>
<li> <li>
<a href="#bookmarks_ui">Bookmark shortcut</a>: the shortcut key that is <a href="#bookmarks_ui">Bookmark shortcut</a>: the shortcut key that is used
used to bookmark a page (Ctrl-D on Windows). Extensions may remove this to bookmark a page (Ctrl-D on Windows). Extensions may remove this shortcut
shortcut via the settings overrides, and optionally bind their own command via the settings overrides, and optionally bind their own command to it
to it using the <code>commands</code> section of the manifest. using the <code>commands</code> section of the manifest. If the shortcut key
is removed or rebound, the corresponding menu item as also removed or
overridden respectively.
</li> </li>
</ul> </ul>
</p> </p>
...@@ -47,48 +49,6 @@ in the Chrome Dev release, and Chrome must be started with the ...@@ -47,48 +49,6 @@ in the Chrome Dev release, and Chrome must be started with the
<code>--enable-override-bookmarks-ui=1</code> command line flag to enable <code>--enable-override-bookmarks-ui=1</code> command line flag to enable
bookmarks user interface overrides.</p> bookmarks user interface overrides.</p>
<h2 id="others">Homepage, Search Provider, and Startup Pages</h2>
<p>
Here is an example how <a href="#homepage">homepage</a>, <a
href="#search_provider">search provider</a> and <a href="#startup_pages">startup
pages</a> can be modified in the <a href="manifest.html">extension
manifest</a>.</p>
<pre>{
"name": "My extension",
...
"chrome_settings_overrides": {
"homepage": "http://www.homepage.com",
"search_provider": {
"name": "name.__MSG_url_domain__",
"keyword": "keyword.__MSG_url_domain__",
"search_url": "http://www.foo.__MSG_url_domain__/s?q={searchTerms}",
"favicon_url": "http://www.foo.__MSG_url_domain__/favicon.ico",
"suggest_url": "http://www.foo.__MSG_url_domain__/suggest?q={searchTerms}",
"instant_url": "http://www.foo.__MSG_url_domain__/instant?q={searchTerms}",
"image_url": "http://www.foo.__MSG_url_domain__/image?q={searchTerms}",
"search_url_post_params": "search_lang=__MSG_url_domain__",
"suggest_url_post_params": "suggest_lang=__MSG_url_domain__",
"instant_url_post_params": "instant_lang=__MSG_url_domain__",
"image_url_post_params": "image_lang=__MSG_url_domain__",
"alternate_urls": [
"http://www.moo.__MSG_url_domain__/s?q={searchTerms}",
"http://www.noo.__MSG_url_domain__/s?q={searchTerms}"
],
"encoding": "UTF-8",
"is_default": true
},
"startup_pages": ["http://www.startup.com"]
},
"default_locale": "de",
...
}</pre>
<p class="note">
<b>Note:</b> Settings overrides for <code>homepage</code>,
<code>search_provider</code>, and <code>startup_pages</code> are only enabled
in the Chrome Dev release.</p>
<h2 id="reference">Reference</h2> <h2 id="reference">Reference</h2>
<p> <p>
An extension can override one or more of the following properties in the An extension can override one or more of the following properties in the
...@@ -96,7 +56,7 @@ manifest: ...@@ -96,7 +56,7 @@ manifest:
</p> </p>
<ul> <ul>
{{#f:apis.manifestTypes.byName.ChromeSettingsOverrides.properties}} {{#f:apis.manifestTypes.byName.ChromeUIOverrides.properties}}
<li> <li>
<p id="{{f.name}}"><b><code>{{f.name}}</code> ({{+partials.variable_type type:f/}})</b></p> <p id="{{f.name}}"><b><code>{{f.name}}</code> ({{+partials.variable_type type:f/}})</b></p>
<p>{{f.description}}</p> <p>{{f.description}}</p>
...@@ -112,4 +72,3 @@ manifest: ...@@ -112,4 +72,3 @@ manifest:
{{/}} {{/}}
{{/}} {{/}}
</ul> </ul>
...@@ -25,6 +25,15 @@ ...@@ -25,6 +25,15 @@
"documentation": "settings_override.html", "documentation": "settings_override.html",
"example": {} "example": {}
}, },
"chrome_ui_overrides": {
"documentation": "ui_override.html",
"example": {
"bookmarks_ui": {
"remove_button": true,
"remove_bookmark_shortcut": true
}
}
},
"chrome_url_overrides": { "chrome_url_overrides": {
"documentation": "override.html", "documentation": "override.html",
"example": {} "example": {}
......
{{+partials.standard_extensions_article article:intros.ui_override/}}
...@@ -261,8 +261,9 @@ bool SettingsOverridesHandler::Parse(Extension* extension, ...@@ -261,8 +261,9 @@ bool SettingsOverridesHandler::Parse(Extension* extension,
info->startup_pages = ParseStartupPage(*settings, error); info->startup_pages = ParseStartupPage(*settings, error);
if (!info->bookmarks_ui && !info->homepage && if (!info->bookmarks_ui && !info->homepage &&
!info->search_engine && info->startup_pages.empty()) { !info->search_engine && info->startup_pages.empty()) {
*error = *error = ErrorUtils::FormatErrorMessageUTF16(
base::ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); manifest_errors::kInvalidEmptyDictionary,
manifest_keys::kSettingsOverride);
return false; return false;
} }
info->manifest_permission.reset(new ManifestPermissionImpl( info->manifest_permission.reset(new ManifestPermissionImpl(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/extensions/features/feature_channel.h" #include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/extensions/manifest_url_handler.h" #include "chrome/common/extensions/manifest_url_handler.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -120,7 +121,9 @@ TEST_F(OverrideSettingsTest, ParseBrokenManifest) { ...@@ -120,7 +121,9 @@ TEST_F(OverrideSettingsTest, ParseBrokenManifest) {
#if defined(OS_WIN) #if defined(OS_WIN)
EXPECT_FALSE(extension); EXPECT_FALSE(extension);
EXPECT_EQ( EXPECT_EQ(
std::string(extensions::manifest_errors::kInvalidEmptySettingsOverrides), extensions::ErrorUtils::FormatErrorMessage(
extensions::manifest_errors::kInvalidEmptyDictionary,
extensions::manifest_keys::kSettingsOverride),
error); error);
#else #else
EXPECT_TRUE(extension); EXPECT_TRUE(extension);
......
...@@ -13,37 +13,30 @@ namespace extensions { ...@@ -13,37 +13,30 @@ namespace extensions {
class ManifestPermission; class ManifestPermission;
// SettingsOverride is associated with "chrome_settings_overrides" manifest key. // UIOverrides is associated with "chrome_ui_overrides" manifest key, and
// An extension can add a search engine as default or non-default, overwrite the // represents manifest settings to override aspects of the Chrome user
// homepage and append a startup page to the list. // interface.
struct SettingsOverrides : public Extension::ManifestData { struct UIOverrides : public Extension::ManifestData {
SettingsOverrides(); UIOverrides();
virtual ~SettingsOverrides(); virtual ~UIOverrides();
static const SettingsOverrides* Get(const Extension* extension); static const UIOverrides* Get(const Extension* extension);
static bool RemovesBookmarkButton( static bool RemovesBookmarkButton(const UIOverrides& ui_overrides);
const SettingsOverrides& settings_overrides); static bool RemovesBookmarkShortcut(const UIOverrides& ui_overrides);
static bool RemovesBookmarkShortcut(
const SettingsOverrides& settings_overrides); scoped_ptr<api::manifest_types::ChromeUIOverrides::Bookmarks_ui> bookmarks_ui;
scoped_ptr<api::manifest_types::ChromeSettingsOverrides::Bookmarks_ui>
bookmarks_ui;
scoped_ptr<api::manifest_types::ChromeSettingsOverrides::Search_provider>
search_engine;
scoped_ptr<GURL> homepage;
std::vector<GURL> startup_pages;
scoped_ptr<ManifestPermission> manifest_permission; scoped_ptr<ManifestPermission> manifest_permission;
private: private:
DISALLOW_COPY_AND_ASSIGN(SettingsOverrides); DISALLOW_COPY_AND_ASSIGN(UIOverrides);
}; };
class SettingsOverridesHandler : public ManifestHandler { class UIOverridesHandler : public ManifestHandler {
public: public:
SettingsOverridesHandler(); UIOverridesHandler();
virtual ~SettingsOverridesHandler(); virtual ~UIOverridesHandler();
virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
virtual bool Validate(const Extension* extension, virtual bool Validate(const Extension* extension,
...@@ -59,7 +52,7 @@ class SettingsOverridesHandler : public ManifestHandler { ...@@ -59,7 +52,7 @@ class SettingsOverridesHandler : public ManifestHandler {
virtual const std::vector<std::string> Keys() const OVERRIDE; virtual const std::vector<std::string> Keys() const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(SettingsOverridesHandler); DISALLOW_COPY_AND_ASSIGN(UIOverridesHandler);
}; };
} // namespace extensions } // namespace extensions
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "base/command_line.h"
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/extensions/features/feature_channel.h" #include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/extensions/manifest_url_handler.h" #include "chrome/common/extensions/manifest_url_handler.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -17,50 +19,37 @@ namespace { ...@@ -17,50 +19,37 @@ namespace {
const char kManifest[] = "{" const char kManifest[] = "{"
" \"version\" : \"1.0.0.0\"," " \"version\" : \"1.0.0.0\","
" \"name\" : \"Test\"," " \"name\" : \"Test\","
" \"chrome_settings_overrides\" : {" " \"chrome_ui_overrides\" : {"
" \"homepage\" : \"http://www.homepage.com\"," " \"bookmarks_ui\" : {"
" \"search_provider\" : {" " \"remove_button\" : true,"
" \"name\" : \"first\"," " \"remove_bookmark_shortcut\" : true"
" \"keyword\" : \"firstkey\"," " }"
" \"search_url\" : \"http://www.foo.com/s?q={searchTerms}\","
" \"favicon_url\" : \"http://www.foo.com/favicon.ico\","
" \"suggest_url\" : \"http://www.foo.com/s?q={searchTerms}\","
" \"encoding\" : \"UTF-8\","
" \"is_default\" : true"
" },"
" \"startup_pages\" : [\"http://www.startup.com\"]"
" }" " }"
"}"; "}";
const char kBrokenManifest[] = "{" const char kBrokenManifest[] = "{"
" \"version\" : \"1.0.0.0\"," " \"version\" : \"1.0.0.0\","
" \"name\" : \"Test\"," " \"name\" : \"Test\","
" \"chrome_settings_overrides\" : {" " \"chrome_ui_overrides\" : {"
" \"homepage\" : \"{invalid}\","
" \"search_provider\" : {"
" \"name\" : \"first\","
" \"keyword\" : \"firstkey\","
" \"search_url\" : \"{invalid}/s?q={searchTerms}\","
" \"favicon_url\" : \"{invalid}/favicon.ico\","
" \"encoding\" : \"UTF-8\","
" \"is_default\" : true"
" },"
" \"startup_pages\" : [\"{invalid}\"]"
" }" " }"
"}"; "}";
using extensions::api::manifest_types::ChromeSettingsOverrides; using extensions::api::manifest_types::ChromeUIOverrides;
using extensions::Extension; using extensions::Extension;
using extensions::Manifest; using extensions::Manifest;
using extensions::SettingsOverrides; using extensions::UIOverrides;
namespace manifest_keys = extensions::manifest_keys; namespace manifest_keys = extensions::manifest_keys;
class OverrideSettingsTest : public testing::Test { class UIOverrideTest : public testing::Test {
}; };
TEST_F(OverrideSettingsTest, ParseManifest) { TEST_F(UIOverrideTest, ParseManifest) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
// This functionality requires a feature flag.
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
"--enable-override-bookmarks-ui",
"1");
std::string manifest(kManifest); std::string manifest(kManifest);
JSONStringValueSerializer json(&manifest); JSONStringValueSerializer json(&manifest);
std::string error; std::string error;
...@@ -73,38 +62,23 @@ TEST_F(OverrideSettingsTest, ParseManifest) { ...@@ -73,38 +62,23 @@ TEST_F(OverrideSettingsTest, ParseManifest) {
*static_cast<base::DictionaryValue*>(root.get()), *static_cast<base::DictionaryValue*>(root.get()),
Extension::NO_FLAGS, Extension::NO_FLAGS,
&error); &error);
ASSERT_TRUE(extension); ASSERT_TRUE(extension) << error;
#if defined(OS_WIN) ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride));
ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
SettingsOverrides* settings_override = static_cast<SettingsOverrides*>( UIOverrides* ui_override = static_cast<UIOverrides*>(
extension->GetManifestData(manifest_keys::kSettingsOverride)); extension->GetManifestData(manifest_keys::kUIOverride));
ASSERT_TRUE(settings_override); ASSERT_TRUE(ui_override);
ASSERT_TRUE(settings_override->search_engine); ASSERT_TRUE(ui_override->bookmarks_ui);
EXPECT_TRUE(settings_override->search_engine->is_default); EXPECT_TRUE(ui_override->bookmarks_ui->remove_button);
const ChromeSettingsOverrides::Search_provider* search_engine = EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut);
settings_override->search_engine.get();
EXPECT_EQ("first", search_engine->name);
EXPECT_EQ("firstkey", search_engine->keyword);
EXPECT_EQ("http://www.foo.com/s?q={searchTerms}", search_engine->search_url);
EXPECT_EQ("http://www.foo.com/favicon.ico", search_engine->favicon_url);
EXPECT_EQ("http://www.foo.com/s?q={searchTerms}",
*search_engine->suggest_url);
EXPECT_EQ("UTF-8", search_engine->encoding);
EXPECT_EQ(std::vector<GURL>(1, GURL("http://www.startup.com")),
settings_override->startup_pages);
ASSERT_TRUE(settings_override->homepage);
EXPECT_EQ(GURL("http://www.homepage.com"), *settings_override->homepage);
#else
EXPECT_FALSE(
extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
#endif
} }
TEST_F(OverrideSettingsTest, ParseBrokenManifest) { TEST_F(UIOverrideTest, ParseBrokenManifest) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
// This functionality requires a feature flag.
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
"--enable-override-bookmarks-ui",
"1");
std::string manifest(kBrokenManifest); std::string manifest(kBrokenManifest);
JSONStringValueSerializer json(&manifest); JSONStringValueSerializer json(&manifest);
std::string error; std::string error;
...@@ -117,16 +91,12 @@ TEST_F(OverrideSettingsTest, ParseBrokenManifest) { ...@@ -117,16 +91,12 @@ TEST_F(OverrideSettingsTest, ParseBrokenManifest) {
*static_cast<base::DictionaryValue*>(root.get()), *static_cast<base::DictionaryValue*>(root.get()),
Extension::NO_FLAGS, Extension::NO_FLAGS,
&error); &error);
#if defined(OS_WIN)
EXPECT_FALSE(extension); EXPECT_FALSE(extension);
EXPECT_EQ( EXPECT_EQ(
std::string(extensions::manifest_errors::kInvalidEmptySettingsOverrides), extensions::ErrorUtils::FormatErrorMessage(
extensions::manifest_errors::kInvalidEmptyDictionary,
extensions::manifest_keys::kUIOverride),
error); error);
#else
EXPECT_TRUE(extension);
EXPECT_FALSE(
extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
#endif
} }
} // namespace } // namespace
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"scripts": ["background.js"] "scripts": ["background.js"]
}, },
"permissions": ["activeTab"], "permissions": ["activeTab"],
"chrome_settings_overrides": { "chrome_ui_overrides": {
"bookmarks_ui": { "bookmarks_ui": {
"remove_bookmark_shortcut": true "remove_bookmark_shortcut": true
} }
......
...@@ -17,7 +17,7 @@ const char kBackgroundPageLegacy[] = "background_page"; ...@@ -17,7 +17,7 @@ const char kBackgroundPageLegacy[] = "background_page";
const char kBackgroundPersistent[] = "background.persistent"; const char kBackgroundPersistent[] = "background.persistent";
const char kBackgroundScripts[] = "background.scripts"; const char kBackgroundScripts[] = "background.scripts";
const char kBluetooth[] = "bluetooth"; const char kBluetooth[] = "bluetooth";
const char kBookmarkUI[] = "chrome_settings_overrides.bookmarks_ui"; const char kBookmarkUI[] = "chrome_ui_overrides.bookmarks_ui";
const char kBrowserAction[] = "browser_action"; const char kBrowserAction[] = "browser_action";
const char kChromeURLOverrides[] = "chrome_url_overrides"; const char kChromeURLOverrides[] = "chrome_url_overrides";
const char kCommands[] = "commands"; const char kCommands[] = "commands";
...@@ -157,6 +157,7 @@ const char kTtsVoicesLang[] = "lang"; ...@@ -157,6 +157,7 @@ const char kTtsVoicesLang[] = "lang";
const char kTtsVoicesRemote[] = "remote"; const char kTtsVoicesRemote[] = "remote";
const char kTtsVoicesVoiceName[] = "voice_name"; const char kTtsVoicesVoiceName[] = "voice_name";
const char kType[] = "type"; const char kType[] = "type";
const char kUIOverride[] = "chrome_ui_overrides";
const char kUpdateURL[] = "update_url"; const char kUpdateURL[] = "update_url";
const char kUrlHandlers[] = "url_handlers"; const char kUrlHandlers[] = "url_handlers";
const char kUrlHandlerTitle[] = "title"; const char kUrlHandlerTitle[] = "title";
...@@ -313,6 +314,7 @@ const char kInvalidDisplayInLauncher[] = ...@@ -313,6 +314,7 @@ const char kInvalidDisplayInLauncher[] =
"Invalid value for 'display_in_launcher'."; "Invalid value for 'display_in_launcher'.";
const char kInvalidDisplayInNewTabPage[] = const char kInvalidDisplayInNewTabPage[] =
"Invalid value for 'display_in_new_tab_page'."; "Invalid value for 'display_in_new_tab_page'.";
const char kInvalidEmptyDictionary[] = "Empty dictionary for '*'.";
const char kInvalidExcludeMatch[] = const char kInvalidExcludeMatch[] =
"Invalid value for 'content_scripts[*].exclude_matches[*]': *"; "Invalid value for 'content_scripts[*].exclude_matches[*]': *";
const char kInvalidExcludeMatches[] = const char kInvalidExcludeMatches[] =
...@@ -558,8 +560,6 @@ const char kInvalidSearchEngineURL[] = ...@@ -558,8 +560,6 @@ const char kInvalidSearchEngineURL[] =
"Invalid URL [*] for 'chrome_settings_overrides.search_provider'."; "Invalid URL [*] for 'chrome_settings_overrides.search_provider'.";
const char kInvalidServiceWorkerScript[] = const char kInvalidServiceWorkerScript[] =
"Invalid value for 'service_worker.script'."; "Invalid value for 'service_worker.script'.";
const char kInvalidEmptySettingsOverrides[] =
"Empty dictionary for 'chrome_settings_overrides'.";
const char kInvalidShortName[] = const char kInvalidShortName[] =
"Invalid value for 'short_name'."; "Invalid value for 'short_name'.";
const char kInvalidSignature[] = const char kInvalidSignature[] =
......
...@@ -165,6 +165,7 @@ extern const char kTtsVoicesLang[]; ...@@ -165,6 +165,7 @@ extern const char kTtsVoicesLang[];
extern const char kTtsVoicesRemote[]; extern const char kTtsVoicesRemote[];
extern const char kTtsVoicesVoiceName[]; extern const char kTtsVoicesVoiceName[];
extern const char kType[]; extern const char kType[];
extern const char kUIOverride[];
extern const char kUpdateURL[]; extern const char kUpdateURL[];
extern const char kUrlHandlers[]; extern const char kUrlHandlers[];
extern const char kUrlHandlerTitle[]; extern const char kUrlHandlerTitle[];
...@@ -276,6 +277,7 @@ extern const char kInvalidDescription[]; ...@@ -276,6 +277,7 @@ extern const char kInvalidDescription[];
extern const char kInvalidDevToolsPage[]; extern const char kInvalidDevToolsPage[];
extern const char kInvalidDisplayInLauncher[]; extern const char kInvalidDisplayInLauncher[];
extern const char kInvalidDisplayInNewTabPage[]; extern const char kInvalidDisplayInNewTabPage[];
extern const char kInvalidEmptyDictionary[];
extern const char kInvalidExcludeMatch[]; extern const char kInvalidExcludeMatch[];
extern const char kInvalidExcludeMatches[]; extern const char kInvalidExcludeMatches[];
extern const char kInvalidExport[]; extern const char kInvalidExport[];
...@@ -395,7 +397,6 @@ extern const char kInvalidSandboxedPagesCSP[]; ...@@ -395,7 +397,6 @@ extern const char kInvalidSandboxedPagesCSP[];
extern const char kInvalidScriptBadge[]; extern const char kInvalidScriptBadge[];
extern const char kInvalidSearchEngineURL[]; extern const char kInvalidSearchEngineURL[];
extern const char kInvalidServiceWorkerScript[]; extern const char kInvalidServiceWorkerScript[];
extern const char kInvalidEmptySettingsOverrides[];
extern const char kInvalidShortName[]; extern const char kInvalidShortName[];
extern const char kInvalidSignature[]; extern const char kInvalidSignature[];
extern const char kInvalidSpellcheck[]; extern const char kInvalidSpellcheck[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment