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); |
38 | |
39 // Some extensions use "chrome://favicon/" and "chrome://extension-icon" URLs. | |
Charlie Reis
2015/09/22 17:38:15
Why are these cases handled here vs chrome://resou
paulmeyer
2015/09/22 22:13:57
The reason was because the host constants are from
| |
40 const Extension* extension = GetExtension(render_view_host); | |
41 if (extension) { | |
42 Manifest::Type type = extension->GetType(); | |
43 if (type == Manifest::TYPE_EXTENSION || | |
44 type == Manifest::TYPE_LEGACY_PACKAGED_APP || | |
45 (type == Manifest::TYPE_PLATFORM_APP && | |
46 extension->location() == Manifest::COMPONENT)) { | |
Charlie Reis
2015/09/22 17:38:15
This block is subtle in terms of which types of ex
paulmeyer
2015/09/22 22:13:56
Done.
| |
47 int process_id = render_view_host->GetProcess()->GetID(); | |
48 content::ChildProcessSecurityPolicy::GetInstance()->GrantSchemeHost( | |
49 process_id, content::kChromeUIScheme, chrome::kChromeUIFaviconHost); | |
50 content::ChildProcessSecurityPolicy::GetInstance()->GrantSchemeHost( | |
51 process_id, content::kChromeUIScheme, | |
52 chrome::kChromeUIExtensionIconHost); | |
53 } | |
54 } | |
55 | |
36 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); | 56 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); |
37 } | 57 } |
38 | 58 |
39 bool ChromeExtensionWebContentsObserver::OnMessageReceived( | 59 bool ChromeExtensionWebContentsObserver::OnMessageReceived( |
40 const IPC::Message& message, | 60 const IPC::Message& message, |
41 content::RenderFrameHost* render_frame_host) { | 61 content::RenderFrameHost* render_frame_host) { |
42 if (ExtensionWebContentsObserver::OnMessageReceived(message, | 62 if (ExtensionWebContentsObserver::OnMessageReceived(message, |
43 render_frame_host)) { | 63 render_frame_host)) { |
44 return true; | 64 return true; |
45 } | 65 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 // TODO(yoz): This reload doesn't happen synchronously for unpacked | 118 // TODO(yoz): This reload doesn't happen synchronously for unpacked |
99 // extensions. It seems to be fast enough, but there is a race. | 119 // extensions. It seems to be fast enough, but there is a race. |
100 // We should delay loading until the extension has reloaded. | 120 // We should delay loading until the extension has reloaded. |
101 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { | 121 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { |
102 ExtensionSystem::Get(browser_context())-> | 122 ExtensionSystem::Get(browser_context())-> |
103 extension_service()->ReloadExtension(extension_id); | 123 extension_service()->ReloadExtension(extension_id); |
104 } | 124 } |
105 } | 125 } |
106 | 126 |
107 } // namespace extensions | 127 } // namespace extensions |
OLD | NEW |