// 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 "chrome/common/extensions/csp_handler.h" #include "base/memory/scoped_ptr.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/extensions/csp_validator.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/manifest_handlers/sandboxed_page_info.h" namespace keys = extension_manifest_keys; namespace errors = extension_manifest_errors; using extensions::csp_validator::ContentSecurityPolicyIsLegal; using extensions::csp_validator::ContentSecurityPolicyIsSecure; namespace extensions { namespace { const char kDefaultContentSecurityPolicy[] = "script-src 'self' chrome-extension-resource:; object-src 'self'"; #define PLATFORM_APP_LOCAL_CSP_SOURCES \ "'self' data: chrome-extension-resource:" const char kDefaultPlatformAppContentSecurityPolicy[] = // Platform apps can only use local resources by default. "default-src 'self' chrome-extension-resource:;" // For remote resources, they can fetch them via XMLHttpRequest. "connect-src *;" // And serve them via data: or same-origin (blob:, filesystem:) URLs "style-src " PLATFORM_APP_LOCAL_CSP_SOURCES " 'unsafe-inline';" "img-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" "frame-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" "font-src " PLATFORM_APP_LOCAL_CSP_SOURCES ";" // Media can be loaded from remote resources since: // 1.