OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/extension_web_contents_observer.h" | 5 #include "extensions/browser/extension_web_contents_observer.h" |
6 | 6 |
7 #include "content/public/browser/child_process_security_policy.h" | 7 #include "content/public/browser/child_process_security_policy.h" |
8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return web_contents(); | 68 return web_contents(); |
69 } | 69 } |
70 | 70 |
71 void ExtensionWebContentsObserver::RenderViewCreated( | 71 void ExtensionWebContentsObserver::RenderViewCreated( |
72 content::RenderViewHost* render_view_host) { | 72 content::RenderViewHost* render_view_host) { |
73 // TODO(devlin): Most/all of this should move to RenderFrameCreated. | 73 // TODO(devlin): Most/all of this should move to RenderFrameCreated. |
74 const Extension* extension = GetExtension(render_view_host); | 74 const Extension* extension = GetExtension(render_view_host); |
75 if (!extension) | 75 if (!extension) |
76 return; | 76 return; |
77 | 77 |
78 content::RenderProcessHost* process = render_view_host->GetProcess(); | |
79 | |
80 // Some extensions use chrome:// URLs. | |
81 // This is a temporary solution. Replace it with access to chrome-static:// | |
82 // once it is implemented. See: crbug.com/226927. | |
83 Manifest::Type type = extension->GetType(); | 78 Manifest::Type type = extension->GetType(); |
84 if (type == Manifest::TYPE_EXTENSION || | |
85 type == Manifest::TYPE_LEGACY_PACKAGED_APP || | |
86 (type == Manifest::TYPE_PLATFORM_APP && | |
87 extension->location() == Manifest::COMPONENT)) { | |
88 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | |
89 process->GetID(), content::kChromeUIScheme); | |
90 } | |
91 | 79 |
92 // Some extensions use file:// URLs. | 80 // Some extensions use file:// URLs. |
93 if (type == Manifest::TYPE_EXTENSION || | 81 if (type == Manifest::TYPE_EXTENSION || |
94 type == Manifest::TYPE_LEGACY_PACKAGED_APP) { | 82 type == Manifest::TYPE_LEGACY_PACKAGED_APP) { |
95 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); | 83 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); |
96 if (prefs->AllowFileAccess(extension->id())) { | 84 if (prefs->AllowFileAccess(extension->id())) { |
97 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 85 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
98 process->GetID(), url::kFileScheme); | 86 render_view_host->GetProcess()->GetID(), url::kFileScheme); |
99 } | 87 } |
100 } | 88 } |
101 | 89 |
102 // Tells the new view that it's hosted in an extension process. | 90 // Tells the new view that it's hosted in an extension process. |
103 // | 91 // |
104 // This will often be a rendant IPC, because activating extensions happens at | 92 // This will often be a rendant IPC, because activating extensions happens at |
105 // the process level, not at the view level. However, without some mild | 93 // the process level, not at the view level. However, without some mild |
106 // refactoring this isn't trivial to do, and this way is simpler. | 94 // refactoring this isn't trivial to do, and this way is simpler. |
107 // | 95 // |
108 // Plus, we can delete the concept of activating an extension once site | 96 // Plus, we can delete the concept of activating an extension once site |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Since this is called for all existing RenderFrameHosts during the | 196 // Since this is called for all existing RenderFrameHosts during the |
209 // ExtensionWebContentsObserver's creation, it's possible that not all hosts | 197 // ExtensionWebContentsObserver's creation, it's possible that not all hosts |
210 // are ready. | 198 // are ready. |
211 // We only initialize the frame if the renderer counterpart is live; otherwise | 199 // We only initialize the frame if the renderer counterpart is live; otherwise |
212 // we wait for the RenderFrameCreated notification. | 200 // we wait for the RenderFrameCreated notification. |
213 if (render_frame_host->IsRenderFrameLive()) | 201 if (render_frame_host->IsRenderFrameLive()) |
214 InitializeRenderFrame(render_frame_host); | 202 InitializeRenderFrame(render_frame_host); |
215 } | 203 } |
216 | 204 |
217 } // namespace extensions | 205 } // namespace extensions |
OLD | NEW |