| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/chrome_render_view_host_observer.h" | 5 #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/net/predictor.h" | 10 #include "chrome/browser/net/predictor.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_messages.h" | 15 #include "chrome/common/extensions/extension_messages.h" |
| 16 #include "chrome/common/extensions/manifest.h" |
| 15 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/child_process_security_policy.h" | 19 #include "content/public/browser/child_process_security_policy.h" |
| 18 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/site_instance.h" | 23 #include "content/public/browser/site_instance.h" |
| 22 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
| 23 | 25 |
| 24 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 25 #include "base/win/win_util.h" | 27 #include "base/win/win_util.h" |
| 26 #endif // OS_WIN | 28 #endif // OS_WIN |
| 27 | 29 |
| 28 using content::ChildProcessSecurityPolicy; | 30 using content::ChildProcessSecurityPolicy; |
| 29 using content::RenderViewHost; | 31 using content::RenderViewHost; |
| 30 using content::SiteInstance; | 32 using content::SiteInstance; |
| 31 using extensions::Extension; | 33 using extensions::Extension; |
| 34 using extensions::Manifest; |
| 32 | 35 |
| 33 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( | 36 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( |
| 34 RenderViewHost* render_view_host, chrome_browser_net::Predictor* predictor) | 37 RenderViewHost* render_view_host, chrome_browser_net::Predictor* predictor) |
| 35 : content::RenderViewHostObserver(render_view_host), | 38 : content::RenderViewHostObserver(render_view_host), |
| 36 predictor_(predictor) { | 39 predictor_(predictor) { |
| 37 SiteInstance* site_instance = render_view_host->GetSiteInstance(); | 40 SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 38 profile_ = Profile::FromBrowserContext( | 41 profile_ = Profile::FromBrowserContext( |
| 39 site_instance->GetBrowserContext()); | 42 site_instance->GetBrowserContext()); |
| 40 | 43 |
| 41 InitRenderViewForExtensions(); | 44 InitRenderViewForExtensions(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 81 } |
| 79 | 82 |
| 80 void ChromeRenderViewHostObserver::InitRenderViewForExtensions() { | 83 void ChromeRenderViewHostObserver::InitRenderViewForExtensions() { |
| 81 const Extension* extension = GetExtension(); | 84 const Extension* extension = GetExtension(); |
| 82 if (!extension) | 85 if (!extension) |
| 83 return; | 86 return; |
| 84 | 87 |
| 85 content::RenderProcessHost* process = render_view_host()->GetProcess(); | 88 content::RenderProcessHost* process = render_view_host()->GetProcess(); |
| 86 | 89 |
| 87 // Some extensions use chrome:// URLs. | 90 // Some extensions use chrome:// URLs. |
| 88 Extension::Type type = extension->GetType(); | 91 Manifest::Type type = extension->GetType(); |
| 89 if (type == Extension::TYPE_EXTENSION || | 92 if (type == Manifest::TYPE_EXTENSION || |
| 90 type == Extension::TYPE_LEGACY_PACKAGED_APP) { | 93 type == Manifest::TYPE_LEGACY_PACKAGED_APP) { |
| 91 ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 94 ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
| 92 process->GetID(), chrome::kChromeUIScheme); | 95 process->GetID(), chrome::kChromeUIScheme); |
| 93 | 96 |
| 94 if (extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 97 if (extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 95 extension_prefs()->AllowFileAccess(extension->id())) { | 98 extension_prefs()->AllowFileAccess(extension->id())) { |
| 96 ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 99 ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
| 97 process->GetID(), chrome::kFileScheme); | 100 process->GetID(), chrome::kFileScheme); |
| 98 } | 101 } |
| 99 } | 102 } |
| 100 | 103 |
| 101 switch (type) { | 104 switch (type) { |
| 102 case Extension::TYPE_EXTENSION: | 105 case Manifest::TYPE_EXTENSION: |
| 103 case Extension::TYPE_USER_SCRIPT: | 106 case Manifest::TYPE_USER_SCRIPT: |
| 104 case Extension::TYPE_HOSTED_APP: | 107 case Manifest::TYPE_HOSTED_APP: |
| 105 case Extension::TYPE_LEGACY_PACKAGED_APP: | 108 case Manifest::TYPE_LEGACY_PACKAGED_APP: |
| 106 case Extension::TYPE_PLATFORM_APP: | 109 case Manifest::TYPE_PLATFORM_APP: |
| 107 // Always send a Loaded message before ActivateExtension so that | 110 // Always send a Loaded message before ActivateExtension so that |
| 108 // ExtensionDispatcher knows what Extension is active, not just its ID. | 111 // ExtensionDispatcher knows what Extension is active, not just its ID. |
| 109 // This is important for classifying the Extension's JavaScript context | 112 // This is important for classifying the Extension's JavaScript context |
| 110 // correctly (see ExtensionDispatcher::ClassifyJavaScriptContext). | 113 // correctly (see ExtensionDispatcher::ClassifyJavaScriptContext). |
| 111 Send(new ExtensionMsg_Loaded( | 114 Send(new ExtensionMsg_Loaded( |
| 112 std::vector<ExtensionMsg_Loaded_Params>( | 115 std::vector<ExtensionMsg_Loaded_Params>( |
| 113 1, ExtensionMsg_Loaded_Params(extension)))); | 116 1, ExtensionMsg_Loaded_Params(extension)))); |
| 114 Send(new ExtensionMsg_ActivateExtension(extension->id())); | 117 Send(new ExtensionMsg_ActivateExtension(extension->id())); |
| 115 break; | 118 break; |
| 116 | 119 |
| 117 case Extension::TYPE_UNKNOWN: | 120 case Manifest::TYPE_UNKNOWN: |
| 118 case Extension::TYPE_THEME: | 121 case Manifest::TYPE_THEME: |
| 119 break; | 122 break; |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 const Extension* ChromeRenderViewHostObserver::GetExtension() { | 126 const Extension* ChromeRenderViewHostObserver::GetExtension() { |
| 124 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps | 127 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps |
| 125 // (excluding bookmark apps) will have a chrome-extension:// URL for their | 128 // (excluding bookmark apps) will have a chrome-extension:// URL for their |
| 126 // site, so we can ignore that wrinkle here. | 129 // site, so we can ignore that wrinkle here. |
| 127 SiteInstance* site_instance = render_view_host()->GetSiteInstance(); | 130 SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 128 const GURL& site = site_instance->GetSiteURL(); | 131 const GURL& site = site_instance->GetSiteURL(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 content::NotificationService::current()->Notify( | 166 content::NotificationService::current()->Notify( |
| 164 chrome::NOTIFICATION_FOCUSED_NODE_TOUCHED, | 167 chrome::NOTIFICATION_FOCUSED_NODE_TOUCHED, |
| 165 content::Source<RenderViewHost>(render_view_host()), | 168 content::Source<RenderViewHost>(render_view_host()), |
| 166 content::Details<bool>(&editable)); | 169 content::Details<bool>(&editable)); |
| 167 } else { | 170 } else { |
| 168 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
| 169 base::win::DismissVirtualKeyboard(); | 172 base::win::DismissVirtualKeyboard(); |
| 170 #endif | 173 #endif |
| 171 } | 174 } |
| 172 } | 175 } |
| OLD | NEW |