| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/extension_injection_host.h" | 5 #include "extensions/renderer/extension_injection_host.h" |
| 6 | 6 |
| 7 #include "content/public/renderer/render_frame.h" | 7 #include "content/public/renderer/render_frame.h" |
| 8 #include "extensions/common/constants.h" |
| 8 #include "extensions/common/extension_set.h" | 9 #include "extensions/common/extension_set.h" |
| 9 #include "extensions/common/manifest_handlers/csp_info.h" | 10 #include "extensions/common/manifest_handlers/csp_info.h" |
| 10 #include "extensions/renderer/extension_frame_helper.h" | 11 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 11 | 13 |
| 12 namespace extensions { | 14 namespace extensions { |
| 13 | 15 |
| 14 ExtensionInjectionHost::ExtensionInjectionHost( | 16 ExtensionInjectionHost::ExtensionInjectionHost( |
| 15 const Extension* extension) | 17 const Extension* extension) |
| 16 : InjectionHost(HostID(HostID::EXTENSIONS, extension->id())), | 18 : InjectionHost(HostID(HostID::EXTENSIONS, extension->id())), |
| 17 extension_(extension) { | 19 extension_(extension) { |
| 18 } | 20 } |
| 19 | 21 |
| 20 ExtensionInjectionHost::~ExtensionInjectionHost() { | 22 ExtensionInjectionHost::~ExtensionInjectionHost() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 46 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame( | 48 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame( |
| 47 const GURL& document_url, | 49 const GURL& document_url, |
| 48 content::RenderFrame* render_frame, | 50 content::RenderFrame* render_frame, |
| 49 int tab_id, | 51 int tab_id, |
| 50 bool is_declarative) const { | 52 bool is_declarative) const { |
| 51 // If we don't have a tab id, we have no UI surface to ask for user consent. | 53 // 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. | 54 // For now, we treat this as an automatic allow. |
| 53 if (tab_id == -1) | 55 if (tab_id == -1) |
| 54 return PermissionsData::ACCESS_ALLOWED; | 56 return PermissionsData::ACCESS_ALLOWED; |
| 55 | 57 |
| 56 const std::string& extension_id = | 58 blink::WebSecurityOrigin top_frame_security_origin = |
| 57 ExtensionFrameHelper::Get(render_frame)->tab_extension_owner_id(); | 59 render_frame->GetWebFrame()->top()->securityOrigin(); |
| 58 // We don't allow injections in any frame of an extension page (unless it's by | 60 if (top_frame_security_origin.protocol().utf8() == kExtensionScheme && |
| 59 // the owning extension). | 61 top_frame_security_origin.host().utf8() != extension_->id()) |
| 60 if (!extension_id.empty() && extension_id != extension_->id()) | |
| 61 return PermissionsData::ACCESS_DENIED; | 62 return PermissionsData::ACCESS_DENIED; |
| 62 | 63 |
| 63 // Declarative user scripts use "page access" (from "permissions" section in | 64 // Declarative user scripts use "page access" (from "permissions" section in |
| 64 // manifest) whereas non-declarative user scripts use custom | 65 // manifest) whereas non-declarative user scripts use custom |
| 65 // "content script access" logic. | 66 // "content script access" logic. |
| 66 if (is_declarative) { | 67 if (is_declarative) { |
| 67 return extension_->permissions_data()->GetPageAccess( | 68 return extension_->permissions_data()->GetPageAccess( |
| 68 extension_, | 69 extension_, |
| 69 document_url, | 70 document_url, |
| 70 tab_id, | 71 tab_id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 // We notify the browser of any injection if the extension has no withheld | 85 // 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 // permissions (i.e., the permissions weren't restricted), but would have |
| 86 // otherwise been affected by the scripts-require-action feature. | 87 // otherwise been affected by the scripts-require-action feature. |
| 87 return extension_->permissions_data()->withheld_permissions()->IsEmpty() && | 88 return extension_->permissions_data()->withheld_permissions()->IsEmpty() && |
| 88 PermissionsData::ScriptsMayRequireActionForExtension( | 89 PermissionsData::ScriptsMayRequireActionForExtension( |
| 89 extension_, | 90 extension_, |
| 90 extension_->permissions_data()->active_permissions().get()); | 91 extension_->permissions_data()->active_permissions().get()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 } // namespace extensions | 94 } // namespace extensions |
| OLD | NEW |