Chromium Code Reviews| 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 const Extension* extension = GetExtension(render_view_host); | |
| 40 if (!extension) | |
| 41 return; | |
| 42 | |
| 43 Manifest::Type type = extension->GetType(); | |
|
Devlin
2015/09/23 23:14:17
won't need this.
paulmeyer
2015/09/29 17:24:55
Done.
| |
| 44 int process_id = render_view_host->GetProcess()->GetID(); | |
| 45 | |
| 46 // Components of chrome that are implemented as extensions are allowed to use | |
| 47 // chrome://resources/ URLs. | |
| 48 if (type == Manifest::TYPE_EXTENSION && | |
|
Devlin
2015/09/23 23:14:17
extension->is_extension()
paulmeyer
2015/09/29 17:24:56
Done.
| |
| 49 extension->location() == Manifest::COMPONENT) { | |
|
Devlin
2015/09/23 23:14:17
Manifest::IsComponentLocation(extension->location(
paulmeyer
2015/09/29 17:24:55
Done.
| |
| 50 url::Origin origin = url::Origin::UnsafelyCreateOriginWithoutNormalization( | |
|
Charlie Reis
2015/09/23 22:57:14
Sounds like that's not a preferred way to create O
| |
| 51 content::kChromeUIScheme, content::kChromeUIResourcesHost, 0); | |
| 52 content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin( | |
|
Devlin
2015/09/23 23:14:17
This would be less verbose if we cached it.
paulmeyer
2015/09/29 17:24:56
Done.
| |
| 53 process_id, origin); | |
| 54 } | |
| 55 | |
| 56 // Extensions, legacy packaged apps, and platform apps are allowed to use | |
|
Charlie Reis
2015/09/23 22:57:14
nit: component platform apps
paulmeyer
2015/09/29 17:24:56
Done.
| |
| 57 // chrome://favicon/ and chrome://extension-icon/ URLs. Hosted apps are not | |
| 58 // allowed because they are served via web servers (and are generally never | |
| 59 // given access to Chrome APIs). | |
| 60 if (type == Manifest::TYPE_EXTENSION || | |
|
Devlin
2015/09/23 23:14:17
is_extension(), analogous for below
paulmeyer
2015/09/29 17:24:55
Done.
| |
| 61 type == Manifest::TYPE_LEGACY_PACKAGED_APP || | |
| 62 (type == Manifest::TYPE_PLATFORM_APP && | |
| 63 extension->location() == Manifest::COMPONENT)) { | |
| 64 content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin( | |
| 65 process_id, url::Origin(GURL(chrome::kChromeUIFaviconURL))); | |
| 66 content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin( | |
| 67 process_id, url::Origin(GURL(chrome::kChromeUIExtensionIconURL))); | |
| 68 } | |
| 69 | |
| 36 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); | 70 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); |
|
Devlin
2015/09/23 23:14:17
I think I'd prefer to do this initialization first
paulmeyer
2015/09/29 17:24:56
Done.
| |
| 37 } | 71 } |
| 38 | 72 |
| 39 bool ChromeExtensionWebContentsObserver::OnMessageReceived( | 73 bool ChromeExtensionWebContentsObserver::OnMessageReceived( |
| 40 const IPC::Message& message, | 74 const IPC::Message& message, |
| 41 content::RenderFrameHost* render_frame_host) { | 75 content::RenderFrameHost* render_frame_host) { |
| 42 if (ExtensionWebContentsObserver::OnMessageReceived(message, | 76 if (ExtensionWebContentsObserver::OnMessageReceived(message, |
| 43 render_frame_host)) { | 77 render_frame_host)) { |
| 44 return true; | 78 return true; |
| 45 } | 79 } |
| 46 | 80 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // TODO(yoz): This reload doesn't happen synchronously for unpacked | 132 // TODO(yoz): This reload doesn't happen synchronously for unpacked |
| 99 // extensions. It seems to be fast enough, but there is a race. | 133 // extensions. It seems to be fast enough, but there is a race. |
| 100 // We should delay loading until the extension has reloaded. | 134 // We should delay loading until the extension has reloaded. |
| 101 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { | 135 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { |
| 102 ExtensionSystem::Get(browser_context())-> | 136 ExtensionSystem::Get(browser_context())-> |
| 103 extension_service()->ReloadExtension(extension_id); | 137 extension_service()->ReloadExtension(extension_id); |
| 104 } | 138 } |
| 105 } | 139 } |
| 106 | 140 |
| 107 } // namespace extensions | 141 } // namespace extensions |
| OLD | NEW |