1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/common/manifest_handlers/csp_info.h"
6 #include "extensions/renderer/extension_injection_host.h"
10 ExtensionInjectionHost::ExtensionInjectionHost(
11 const scoped_refptr
<const Extension
>& extension
)
12 : InjectionHost(HostID(HostID::EXTENSIONS
, extension
->id())),
13 extension_(extension
) {
16 ExtensionInjectionHost::~ExtensionInjectionHost() {
19 const std::string
& ExtensionInjectionHost::GetContentSecurityPolicy() const {
20 return CSPInfo::GetContentSecurityPolicy(extension_
.get());
23 const GURL
& ExtensionInjectionHost::url() const {
24 return extension_
->url();
27 const std::string
& ExtensionInjectionHost::name() const {
28 return extension_
->name();
31 PermissionsData::AccessType
ExtensionInjectionHost::CanExecuteOnFrame(
32 const GURL
& document_url
,
33 const GURL
& top_frame_url
,
35 bool is_declarative
) const {
36 // Declarative user scripts use "page access" (from "permissions" section in
37 // manifest) whereas non-declarative user scripts use custom
38 // "content script access" logic.
40 return extension_
->permissions_data()->GetPageAccess(
46 nullptr /* ignore error */);
48 return extension_
->permissions_data()->GetContentScriptAccess(
54 nullptr /* ignore error */);
58 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const {
59 // We notify the browser of any injection if the extension has no withheld
60 // permissions (i.e., the permissions weren't restricted), but would have
61 // otherwise been affected by the scripts-require-action feature.
62 return extension_
->permissions_data()->withheld_permissions()->IsEmpty() &&
63 PermissionsData::ScriptsMayRequireActionForExtension(
65 extension_
->permissions_data()->active_permissions().get());
68 } // namespace extensions