diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 22:02:00 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 22:02:00 +0000 |
commit | 1f7de25c0151055c3017479e7615ba3cf3ff4981 (patch) | |
tree | 296ba8b342d12c90514a8326915bb0e780ba8a70 /extensions/common | |
parent | 7cb4d1466a432de26f7ab2db2d7337b260caa692 (diff) | |
download | chromium_src-1f7de25c0151055c3017479e7615ba3cf3ff4981.zip chromium_src-1f7de25c0151055c3017479e7615ba3cf3ff4981.tar.gz chromium_src-1f7de25c0151055c3017479e7615ba3cf3ff4981.tar.bz2 |
Move chrome/common/extensions/incognito_handler.h to src/extensions
Part of moving ExtensionProcessManager to src/extensions
BUG=313481
TEST=compiles
R=yoz@chromium.org
TBR=finnur@chromium.org for chrome/browser/ui/webui/extensions
Review URL: https://codereview.chromium.org/61823004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common')
-rw-r--r-- | extensions/common/manifest_handlers/incognito_info.cc | 76 | ||||
-rw-r--r-- | extensions/common/manifest_handlers/incognito_info.h | 43 |
2 files changed, 119 insertions, 0 deletions
diff --git a/extensions/common/manifest_handlers/incognito_info.cc b/extensions/common/manifest_handlers/incognito_info.cc new file mode 100644 index 0000000..686c84b --- /dev/null +++ b/extensions/common/manifest_handlers/incognito_info.cc @@ -0,0 +1,76 @@ +// Copyright (c) 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 "extensions/common/manifest_handlers/incognito_info.h" + +#include "base/memory/scoped_ptr.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/common/extensions/extension.h" +#include "extensions/common/manifest_constants.h" + +namespace extensions { + +namespace keys = manifest_keys; + +IncognitoInfo::IncognitoInfo(bool incognito_split_mode) + : split_mode(incognito_split_mode) { +} + +IncognitoInfo::~IncognitoInfo() { +} + +// static +bool IncognitoInfo::IsSplitMode(const Extension* extension) { + IncognitoInfo* info = static_cast<IncognitoInfo*>( + extension->GetManifestData(keys::kIncognito)); + return info ? info->split_mode : false; +} + +IncognitoHandler::IncognitoHandler() { +} + +IncognitoHandler::~IncognitoHandler() { +} + +bool IncognitoHandler::Parse(Extension* extension, string16* error) { + if (!extension->manifest()->HasKey(keys::kIncognito)) { + // Extensions and Chrome apps default to spanning mode. + // Hosted and legacy packaged apps default to split mode. + extension->SetManifestData( + keys::kIncognito, + new IncognitoInfo(extension->is_hosted_app() || + extension->is_legacy_packaged_app())); + return true; + } + + bool split_mode = false; + std::string incognito_string; + if (!extension->manifest()->GetString(keys::kIncognito, &incognito_string)) { + *error = ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); + return false; + } + + if (incognito_string == manifest_values::kIncognitoSplit) + split_mode = true; + else if (incognito_string != manifest_values::kIncognitoSpanning) { + // If incognito_string == kIncognitoSpanning, it is valid and + // split_mode remains false. + *error = ASCIIToUTF16(manifest_errors::kInvalidIncognitoBehavior); + return false; + } + + extension->SetManifestData(keys::kIncognito, new IncognitoInfo(split_mode)); + return true; +} + +bool IncognitoHandler::AlwaysParseForType(Manifest::Type type) const { + return true; +} + +const std::vector<std::string> IncognitoHandler::Keys() const { + return SingleKey(keys::kIncognito); +} + +} // namespace extensions diff --git a/extensions/common/manifest_handlers/incognito_info.h b/extensions/common/manifest_handlers/incognito_info.h new file mode 100644 index 0000000..b275761 --- /dev/null +++ b/extensions/common/manifest_handlers/incognito_info.h @@ -0,0 +1,43 @@ +// Copyright (c) 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 EXTENSIONS_COMMON_MANIFEST_HANDLERS_INCOGNITO_INFO_H_ +#define EXTENSIONS_COMMON_MANIFEST_HANDLERS_INCOGNITO_INFO_H_ + +#include "base/strings/string16.h" +#include "chrome/common/extensions/extension.h" +#include "extensions/common/manifest_handler.h" + +namespace extensions { + +struct IncognitoInfo : public Extension::ManifestData { + explicit IncognitoInfo(bool split_mode); + virtual ~IncognitoInfo(); + + // If true, a separate process will be used for the extension in incognito + // mode. + bool split_mode; + + // Return the incognito mode information for the given |extension|. + static bool IsSplitMode(const Extension* extension); +}; + +// Parses the "incognito" manifest key. +class IncognitoHandler : public ManifestHandler { + public: + IncognitoHandler(); + virtual ~IncognitoHandler(); + + virtual bool Parse(Extension* extension, string16* error) OVERRIDE; + virtual bool AlwaysParseForType(Manifest::Type type) const OVERRIDE; + + private: + virtual const std::vector<std::string> Keys() const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(IncognitoHandler); +}; + +} // namespace extensions + +#endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_INCOGNITO_INFO_H_ |