Commit 867f72e5 authored by wittman@chromium.org's avatar wittman@chromium.org

Copy ui_overrides files from settings_overrides to preserve history

This change is in support of later changes moving the bookmarks_ui
manifest key from chrome_settings_overrides to chrome_ui_overrides.

BUG=349049
R=kalman@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255660 0039d316-1c4b-4281-b951-d872f2087c98
parent 33940aae
<h1>Settings Overrides</h1>
<p>
Settings overrides are a way for extensions to override selected Chrome settings
and user interface properties.
</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>
<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>
<p>
An extension can override one or more of the following properties in the
manifest:
</p>
<ul>
{{#f:apis.manifestTypes.byName.ChromeSettingsOverrides.properties}}
<li>
<p id="{{f.name}}"><b><code>{{f.name}}</code> ({{+partials.variable_type type:f/}})</b></p>
<p>{{f.description}}</p>
{{?f.properties}}
<table>
<tr><th>Type</th><th>Attribute</th><th>Description</th></tr>
{{+partials.type_item
title:f.strings.properties
display_name:display_name
items:f.properties
item_partial:(partials.parameter_full hideParamTOC:true)/}}
</table>
{{/}}
{{/}}
</ul>
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_UI_OVERRIDES_HANDLER_H_
#define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_UI_OVERRIDES_HANDLER_H_
#include "chrome/common/extensions/api/manifest_types.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handler.h"
namespace extensions {
class ManifestPermission;
// SettingsOverride is associated with "chrome_settings_overrides" manifest key.
// An extension can add a search engine as default or non-default, overwrite the
// homepage and append a startup page to the list.
struct SettingsOverrides : public Extension::ManifestData {
SettingsOverrides();
virtual ~SettingsOverrides();
static const SettingsOverrides* Get(const Extension* extension);
static bool RemovesBookmarkButton(
const SettingsOverrides& settings_overrides);
static bool RemovesBookmarkShortcut(
const SettingsOverrides& settings_overrides);
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;
private:
DISALLOW_COPY_AND_ASSIGN(SettingsOverrides);
};
class SettingsOverridesHandler : public ManifestHandler {
public:
SettingsOverridesHandler();
virtual ~SettingsOverridesHandler();
virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE;
virtual bool Validate(const Extension* extension,
std::string* error,
std::vector<InstallWarning>* warnings) const OVERRIDE;
virtual ManifestPermission* CreatePermission() OVERRIDE;
virtual ManifestPermission* CreateInitialRequiredPermission(
const Extension* extension) OVERRIDE;
private:
class ManifestPermissionImpl;
virtual const std::vector<std::string> Keys() const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(SettingsOverridesHandler);
};
} // namespace extensions
#endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLERS_UI_OVERRIDES_HANDLER_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "base/json/json_string_value_serializer.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kManifest[] = "{"
" \"version\" : \"1.0.0.0\","
" \"name\" : \"Test\","
" \"chrome_settings_overrides\" : {"
" \"homepage\" : \"http://www.homepage.com\","
" \"search_provider\" : {"
" \"name\" : \"first\","
" \"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[] = "{"
" \"version\" : \"1.0.0.0\","
" \"name\" : \"Test\","
" \"chrome_settings_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::Extension;
using extensions::Manifest;
using extensions::SettingsOverrides;
namespace manifest_keys = extensions::manifest_keys;
class OverrideSettingsTest : public testing::Test {
};
TEST_F(OverrideSettingsTest, ParseManifest) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
std::string manifest(kManifest);
JSONStringValueSerializer json(&manifest);
std::string error;
scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
scoped_refptr<Extension> extension = Extension::Create(
base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
Manifest::INVALID_LOCATION,
*static_cast<base::DictionaryValue*>(root.get()),
Extension::NO_FLAGS,
&error);
ASSERT_TRUE(extension);
#if defined(OS_WIN)
ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
SettingsOverrides* settings_override = static_cast<SettingsOverrides*>(
extension->GetManifestData(manifest_keys::kSettingsOverride));
ASSERT_TRUE(settings_override);
ASSERT_TRUE(settings_override->search_engine);
EXPECT_TRUE(settings_override->search_engine->is_default);
const ChromeSettingsOverrides::Search_provider* search_engine =
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) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
std::string manifest(kBrokenManifest);
JSONStringValueSerializer json(&manifest);
std::string error;
scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
ASSERT_TRUE(root);
ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
scoped_refptr<Extension> extension = Extension::Create(
base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
Manifest::INVALID_LOCATION,
*static_cast<base::DictionaryValue*>(root.get()),
Extension::NO_FLAGS,
&error);
#if defined(OS_WIN)
EXPECT_FALSE(extension);
EXPECT_EQ(
std::string(extensions::manifest_errors::kInvalidEmptySettingsOverrides),
error);
#else
EXPECT_TRUE(extension);
EXPECT_FALSE(
extension->manifest()->HasPath(manifest_keys::kSettingsOverride));
#endif
}
} // namespace
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