| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/error_console/error_console.h" | 10 #include "chrome/browser/extensions/error_console/error_console.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 policy->GrantOrigin(process_id, | 75 policy->GrantOrigin(process_id, |
| 76 url::Origin(GURL(chrome::kChromeUIFaviconURL))); | 76 url::Origin(GURL(chrome::kChromeUIFaviconURL))); |
| 77 policy->GrantOrigin(process_id, | 77 policy->GrantOrigin(process_id, |
| 78 url::Origin(GURL(chrome::kChromeUIExtensionIconURL))); | 78 url::Origin(GURL(chrome::kChromeUIExtensionIconURL))); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ChromeExtensionWebContentsObserver::DidFinishNavigation( | 82 void ChromeExtensionWebContentsObserver::DidFinishNavigation( |
| 83 content::NavigationHandle* navigation_handle) { | 83 content::NavigationHandle* navigation_handle) { |
| 84 ExtensionWebContentsObserver::DidFinishNavigation(navigation_handle); | 84 ExtensionWebContentsObserver::DidFinishNavigation(navigation_handle); |
| 85 if (navigation_handle->HasCommitted()) | |
| 86 SetExtensionIsolationTrial(navigation_handle->GetRenderFrameHost()); | |
| 87 } | 85 } |
| 88 | 86 |
| 89 bool ChromeExtensionWebContentsObserver::OnMessageReceived( | 87 bool ChromeExtensionWebContentsObserver::OnMessageReceived( |
| 90 const IPC::Message& message, | 88 const IPC::Message& message, |
| 91 content::RenderFrameHost* render_frame_host) { | 89 content::RenderFrameHost* render_frame_host) { |
| 92 if (ExtensionWebContentsObserver::OnMessageReceived(message, | 90 if (ExtensionWebContentsObserver::OnMessageReceived(message, |
| 93 render_frame_host)) { | 91 render_frame_host)) { |
| 94 return true; | 92 return true; |
| 95 } | 93 } |
| 96 | 94 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Reload the extension if it has crashed. | 145 // Reload the extension if it has crashed. |
| 148 // TODO(yoz): This reload doesn't happen synchronously for unpacked | 146 // TODO(yoz): This reload doesn't happen synchronously for unpacked |
| 149 // extensions. It seems to be fast enough, but there is a race. | 147 // extensions. It seems to be fast enough, but there is a race. |
| 150 // We should delay loading until the extension has reloaded. | 148 // We should delay loading until the extension has reloaded. |
| 151 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { | 149 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { |
| 152 ExtensionSystem::Get(browser_context())-> | 150 ExtensionSystem::Get(browser_context())-> |
| 153 extension_service()->ReloadExtension(extension_id); | 151 extension_service()->ReloadExtension(extension_id); |
| 154 } | 152 } |
| 155 } | 153 } |
| 156 | 154 |
| 157 void ChromeExtensionWebContentsObserver::SetExtensionIsolationTrial( | |
| 158 content::RenderFrameHost* render_frame_host) { | |
| 159 content::RenderFrameHost* parent = render_frame_host->GetParent(); | |
| 160 if (!parent) | |
| 161 return; | |
| 162 | |
| 163 GURL frame_url = render_frame_host->GetLastCommittedURL(); | |
| 164 GURL parent_url = parent->GetLastCommittedURL(); | |
| 165 | |
| 166 content::BrowserContext* browser_context = | |
| 167 render_frame_host->GetSiteInstance()->GetBrowserContext(); | |
| 168 extensions::ExtensionRegistry* registry = | |
| 169 extensions::ExtensionRegistry::Get(browser_context); | |
| 170 | |
| 171 bool frame_is_extension = false; | |
| 172 if (frame_url.SchemeIs(extensions::kExtensionScheme)) { | |
| 173 const extensions::Extension* frame_extension = | |
| 174 registry->enabled_extensions().GetExtensionOrAppByURL(frame_url); | |
| 175 if (frame_extension && !frame_extension->is_hosted_app()) | |
| 176 frame_is_extension = true; | |
| 177 } | |
| 178 | |
| 179 bool parent_is_extension = false; | |
| 180 if (parent_url.SchemeIs(extensions::kExtensionScheme)) { | |
| 181 const extensions::Extension* parent_extension = | |
| 182 registry->enabled_extensions().GetExtensionOrAppByURL(parent_url); | |
| 183 if (parent_extension && !parent_extension->is_hosted_app()) | |
| 184 parent_is_extension = true; | |
| 185 } | |
| 186 | |
| 187 // If this is a case where an out-of-process iframe would be possible, then | |
| 188 // create a synthetic field trial for this client. The trial will indicate | |
| 189 // whether the client is manually using a flag to create OOPIFs | |
| 190 // (--site-per-process or --isolate-extensions), whether a field trial made | |
| 191 // OOPIFs possible, or whether they are in default mode and will not have an | |
| 192 // OOPIF. | |
| 193 if (parent_is_extension != frame_is_extension) { | |
| 194 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 195 ::switches::kSitePerProcess)) { | |
| 196 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | |
| 197 "SiteIsolationExtensionsActive", "SitePerProcessFlag"); | |
| 198 } else if (extensions::IsIsolateExtensionsEnabled()) { | |
| 199 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 200 switches::kIsolateExtensions)) { | |
| 201 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | |
| 202 "SiteIsolationExtensionsActive", "IsolateExtensionsFlag"); | |
| 203 } else { | |
| 204 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | |
| 205 "SiteIsolationExtensionsActive", "FieldTrial"); | |
| 206 } | |
| 207 } else { | |
| 208 if (!base::FieldTrialList::FindFullName("SiteIsolationExtensions") | |
| 209 .empty()) { | |
| 210 // The field trial is active, but we are in a control group with oopifs | |
| 211 // disabled. | |
| 212 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | |
| 213 "SiteIsolationExtensionsActive", "Control"); | |
| 214 } else { | |
| 215 // The field trial is not active for this version. | |
| 216 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( | |
| 217 "SiteIsolationExtensionsActive", "Default"); | |
| 218 } | |
| 219 } | |
| 220 | |
| 221 if (rappor::RapporServiceImpl* rappor = | |
| 222 g_browser_process->rappor_service()) { | |
| 223 const std::string& extension_id = | |
| 224 parent_is_extension ? parent_url.host() : frame_url.host(); | |
| 225 rappor->RecordSampleString("Extensions.AffectedByIsolateExtensions", | |
| 226 rappor::UMA_RAPPOR_TYPE, extension_id); | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 } // namespace extensions | 155 } // namespace extensions |
| OLD | NEW |