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 "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 5 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
6 | 6 |
7 #include "chrome/browser/extensions/error_console/error_console.h" | 7 #include "chrome/browser/extensions/error_console/error_console.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/window_controller.h" | 9 #include "chrome/browser/extensions/window_controller.h" |
10 #include "chrome/common/extensions/chrome_extension_messages.h" | 10 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 11 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/child_process_security_policy.h" |
12 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
13 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
15 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
16 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
17 #include "extensions/common/extension_messages.h" | 19 #include "extensions/common/extension_messages.h" |
18 #include "extensions/common/extension_urls.h" | 20 #include "extensions/common/extension_urls.h" |
19 | 21 |
20 using content::BrowserContext; | 22 using content::BrowserContext; |
21 | 23 |
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
23 extensions::ChromeExtensionWebContentsObserver); | 25 extensions::ChromeExtensionWebContentsObserver); |
24 | 26 |
25 namespace extensions { | 27 namespace extensions { |
26 | 28 |
27 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver( | 29 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver( |
28 content::WebContents* web_contents) | 30 content::WebContents* web_contents) |
29 : ExtensionWebContentsObserver(web_contents) {} | 31 : ExtensionWebContentsObserver(web_contents) {} |
30 | 32 |
31 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {} | 33 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {} |
32 | 34 |
33 void ChromeExtensionWebContentsObserver::RenderViewCreated( | 35 void ChromeExtensionWebContentsObserver::RenderViewCreated( |
34 content::RenderViewHost* render_view_host) { | 36 content::RenderViewHost* render_view_host) { |
35 ReloadIfTerminated(render_view_host); | 37 ReloadIfTerminated(render_view_host); |
36 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); | 38 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); |
| 39 |
| 40 const Extension* extension = GetExtension(render_view_host); |
| 41 if (!extension) |
| 42 return; |
| 43 |
| 44 int process_id = render_view_host->GetProcess()->GetID(); |
| 45 auto policy = content::ChildProcessSecurityPolicy::GetInstance(); |
| 46 |
| 47 // Components of chrome that are implemented as extensions or platform apps |
| 48 // are allowed to use chrome://resources/ URLs. |
| 49 if ((extension->is_extension() || extension->is_platform_app()) && |
| 50 Manifest::IsComponentLocation(extension->location())) { |
| 51 policy->GrantOrigin(process_id, |
| 52 url::Origin(GURL(content::kChromeUIResourcesURL))); |
| 53 } |
| 54 |
| 55 // Extensions, legacy packaged apps, and component platform apps are allowed |
| 56 // to use chrome://favicon/ and chrome://extension-icon/ URLs. Hosted apps are |
| 57 // not allowed because they are served via web servers (and are generally |
| 58 // never given access to Chrome APIs). |
| 59 if (extension->is_extension() || |
| 60 extension->is_legacy_packaged_app() || |
| 61 (extension->is_platform_app() && |
| 62 Manifest::IsComponentLocation(extension->location()))) { |
| 63 policy->GrantOrigin(process_id, |
| 64 url::Origin(GURL(chrome::kChromeUIFaviconURL))); |
| 65 policy->GrantOrigin(process_id, |
| 66 url::Origin(GURL(chrome::kChromeUIExtensionIconURL))); |
| 67 } |
37 } | 68 } |
38 | 69 |
39 bool ChromeExtensionWebContentsObserver::OnMessageReceived( | 70 bool ChromeExtensionWebContentsObserver::OnMessageReceived( |
40 const IPC::Message& message, | 71 const IPC::Message& message, |
41 content::RenderFrameHost* render_frame_host) { | 72 content::RenderFrameHost* render_frame_host) { |
42 if (ExtensionWebContentsObserver::OnMessageReceived(message, | 73 if (ExtensionWebContentsObserver::OnMessageReceived(message, |
43 render_frame_host)) { | 74 render_frame_host)) { |
44 return true; | 75 return true; |
45 } | 76 } |
46 | 77 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // TODO(yoz): This reload doesn't happen synchronously for unpacked | 129 // TODO(yoz): This reload doesn't happen synchronously for unpacked |
99 // extensions. It seems to be fast enough, but there is a race. | 130 // extensions. It seems to be fast enough, but there is a race. |
100 // We should delay loading until the extension has reloaded. | 131 // We should delay loading until the extension has reloaded. |
101 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { | 132 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { |
102 ExtensionSystem::Get(browser_context())-> | 133 ExtensionSystem::Get(browser_context())-> |
103 extension_service()->ReloadExtension(extension_id); | 134 extension_service()->ReloadExtension(extension_id); |
104 } | 135 } |
105 } | 136 } |
106 | 137 |
107 } // namespace extensions | 138 } // namespace extensions |
OLD | NEW |