| 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/net/predictor.h" | 9 #include "chrome/browser/net/predictor.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
| 14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #include "content/public/browser/child_process_security_policy.h" | 17 #include "content/public/browser/child_process_security_policy.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/render_view_host_delegate.h" | 19 #include "content/public/browser/render_view_host_delegate.h" |
| 20 #include "content/public/browser/site_instance.h" | 20 #include "content/public/browser/site_instance.h" |
| 21 | 21 |
| 22 using content::ChildProcessSecurityPolicy; | 22 using content::ChildProcessSecurityPolicy; |
| 23 using content::SiteInstance; | 23 using content::SiteInstance; |
| 24 | 24 |
| 25 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( | 25 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( |
| 26 RenderViewHost* render_view_host, chrome_browser_net::Predictor* predictor) | 26 RenderViewHost* render_view_host, chrome_browser_net::Predictor* predictor) |
| 27 : content::RenderViewHostObserver(render_view_host), | 27 : content::RenderViewHostObserver(render_view_host), |
| 28 predictor_(predictor) { | 28 predictor_(predictor) { |
| 29 SiteInstance* site_instance = render_view_host->site_instance(); | 29 SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 30 profile_ = Profile::FromBrowserContext( | 30 profile_ = Profile::FromBrowserContext( |
| 31 site_instance->GetBrowserContext()); | 31 site_instance->GetBrowserContext()); |
| 32 | 32 |
| 33 InitRenderViewHostForExtensions(); | 33 InitRenderViewHostForExtensions(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() { | 36 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() { |
| 37 RemoveRenderViewHostForExtensions(render_view_host()); | 37 RemoveRenderViewHostForExtensions(render_view_host()); |
| 38 } | 38 } |
| 39 | 39 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 CHECK(process_manager); | 76 CHECK(process_manager); |
| 77 | 77 |
| 78 // TODO(creis): Use this to replace SetInstalledAppForRenderer. | 78 // TODO(creis): Use this to replace SetInstalledAppForRenderer. |
| 79 process_manager->RegisterRenderViewHost(render_view_host(), extension); | 79 process_manager->RegisterRenderViewHost(render_view_host(), extension); |
| 80 | 80 |
| 81 if (extension->is_app()) { | 81 if (extension->is_app()) { |
| 82 // Record which, if any, installed app is associated with this process. | 82 // Record which, if any, installed app is associated with this process. |
| 83 // TODO(aa): Totally lame to store this state in a global map in extension | 83 // TODO(aa): Totally lame to store this state in a global map in extension |
| 84 // service. Can we get it from EPM instead? | 84 // service. Can we get it from EPM instead? |
| 85 profile_->GetExtensionService()->SetInstalledAppForRenderer( | 85 profile_->GetExtensionService()->SetInstalledAppForRenderer( |
| 86 render_view_host()->process()->GetID(), extension); | 86 render_view_host()->GetProcess()->GetID(), extension); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ChromeRenderViewHostObserver::InitRenderViewForExtensions() { | 90 void ChromeRenderViewHostObserver::InitRenderViewForExtensions() { |
| 91 const Extension* extension = GetExtension(); | 91 const Extension* extension = GetExtension(); |
| 92 if (!extension) | 92 if (!extension) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 content::RenderProcessHost* process = render_view_host()->process(); | 95 content::RenderProcessHost* process = render_view_host()->GetProcess(); |
| 96 | 96 |
| 97 if (extension->is_app()) { | 97 if (extension->is_app()) { |
| 98 Send(new ExtensionMsg_ActivateApplication(extension->id())); | 98 Send(new ExtensionMsg_ActivateApplication(extension->id())); |
| 99 // Though we already record the associated process ID for the renderer in | 99 // Though we already record the associated process ID for the renderer in |
| 100 // InitRenderViewHostForExtensions, the process might have crashed and been | 100 // InitRenderViewHostForExtensions, the process might have crashed and been |
| 101 // restarted (hence the re-initialization), so we need to update that | 101 // restarted (hence the re-initialization), so we need to update that |
| 102 // mapping. | 102 // mapping. |
| 103 profile_->GetExtensionService()->SetInstalledAppForRenderer( | 103 profile_->GetExtensionService()->SetInstalledAppForRenderer( |
| 104 process->GetID(), extension); | 104 process->GetID(), extension); |
| 105 } | 105 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 (type == Extension::TYPE_HOSTED_APP && | 125 (type == Extension::TYPE_HOSTED_APP && |
| 126 extension->location() == Extension::COMPONENT)) { | 126 extension->location() == Extension::COMPONENT)) { |
| 127 Send(new ExtensionMsg_ActivateExtension(extension->id())); | 127 Send(new ExtensionMsg_ActivateExtension(extension->id())); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 const Extension* ChromeRenderViewHostObserver::GetExtension() { | 131 const Extension* ChromeRenderViewHostObserver::GetExtension() { |
| 132 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps | 132 // Note that due to ChromeContentBrowserClient::GetEffectiveURL(), hosted apps |
| 133 // (excluding bookmark apps) will have a chrome-extension:// URL for their | 133 // (excluding bookmark apps) will have a chrome-extension:// URL for their |
| 134 // site, so we can ignore that wrinkle here. | 134 // site, so we can ignore that wrinkle here. |
| 135 SiteInstance* site_instance = render_view_host()->site_instance(); | 135 SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 136 const GURL& site = site_instance->GetSite(); | 136 const GURL& site = site_instance->GetSite(); |
| 137 | 137 |
| 138 if (!site.SchemeIs(chrome::kExtensionScheme)) | 138 if (!site.SchemeIs(chrome::kExtensionScheme)) |
| 139 return NULL; | 139 return NULL; |
| 140 | 140 |
| 141 ExtensionService* service = profile_->GetExtensionService(); | 141 ExtensionService* service = profile_->GetExtensionService(); |
| 142 if (!service) | 142 if (!service) |
| 143 return NULL; | 143 return NULL; |
| 144 | 144 |
| 145 // Reload the extension if it has crashed. | 145 // Reload the extension if it has crashed. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 161 if (process_manager) | 161 if (process_manager) |
| 162 process_manager->UnregisterRenderViewHost(rvh); | 162 process_manager->UnregisterRenderViewHost(rvh); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ChromeRenderViewHostObserver::OnFocusedEditableNodeTouched() { | 165 void ChromeRenderViewHostObserver::OnFocusedEditableNodeTouched() { |
| 166 content::NotificationService::current()->Notify( | 166 content::NotificationService::current()->Notify( |
| 167 chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED, | 167 chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED, |
| 168 content::Source<RenderViewHost>(render_view_host()), | 168 content::Source<RenderViewHost>(render_view_host()), |
| 169 content::NotificationService::NoDetails()); | 169 content::NotificationService::NoDetails()); |
| 170 } | 170 } |
| OLD | NEW |