Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / extensions / renderer / extension_injection_host.cc
blob3761964f699b0be2e43999f8aa521f52492843ec
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/renderer/extension_injection_host.h"
7 #include "content/public/renderer/render_frame.h"
8 #include "extensions/common/extension_set.h"
9 #include "extensions/common/manifest_handlers/csp_info.h"
10 #include "extensions/renderer/extension_frame_helper.h"
12 namespace extensions {
14 ExtensionInjectionHost::ExtensionInjectionHost(
15 const Extension* extension)
16 : InjectionHost(HostID(HostID::EXTENSIONS, extension->id())),
17 extension_(extension) {
20 ExtensionInjectionHost::~ExtensionInjectionHost() {
23 // static
24 scoped_ptr<const InjectionHost> ExtensionInjectionHost::Create(
25 const std::string& extension_id,
26 const ExtensionSet* extensions) {
27 const Extension* extension = extensions->GetByID(extension_id);
28 if (!extension)
29 return scoped_ptr<const ExtensionInjectionHost>();
30 return scoped_ptr<const ExtensionInjectionHost>(
31 new ExtensionInjectionHost(extension));
34 std::string ExtensionInjectionHost::GetContentSecurityPolicy() const {
35 return CSPInfo::GetContentSecurityPolicy(extension_);
38 const GURL& ExtensionInjectionHost::url() const {
39 return extension_->url();
42 const std::string& ExtensionInjectionHost::name() const {
43 return extension_->name();
46 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame(
47 const GURL& document_url,
48 content::RenderFrame* render_frame,
49 int tab_id,
50 bool is_declarative) const {
51 // If we don't have a tab id, we have no UI surface to ask for user consent.
52 // For now, we treat this as an automatic allow.
53 if (tab_id == -1)
54 return PermissionsData::ACCESS_ALLOWED;
56 const std::string& extension_id =
57 ExtensionFrameHelper::Get(render_frame)->tab_extension_owner_id();
58 // We don't allow injections in any frame of an extension page (unless it's by
59 // the owning extension).
60 if (!extension_id.empty() && extension_id != extension_->id())
61 return PermissionsData::ACCESS_DENIED;
63 // Declarative user scripts use "page access" (from "permissions" section in
64 // manifest) whereas non-declarative user scripts use custom
65 // "content script access" logic.
66 if (is_declarative) {
67 return extension_->permissions_data()->GetPageAccess(
68 extension_,
69 document_url,
70 tab_id,
71 -1, // no process id
72 nullptr /* ignore error */);
73 } else {
74 return extension_->permissions_data()->GetContentScriptAccess(
75 extension_,
76 document_url,
77 tab_id,
78 -1, // no process id
79 nullptr /* ignore error */);
83 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const {
84 // We notify the browser of any injection if the extension has no withheld
85 // permissions (i.e., the permissions weren't restricted), but would have
86 // otherwise been affected by the scripts-require-action feature.
87 return extension_->permissions_data()->withheld_permissions()->IsEmpty() &&
88 PermissionsData::ScriptsMayRequireActionForExtension(
89 extension_,
90 extension_->permissions_data()->active_permissions().get());
93 } // namespace extensions