// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/site_details.h" #include "base/metrics/histogram.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "url/origin.h" #if defined(ENABLE_EXTENSIONS) #include "extensions/browser/extension_registry.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #endif using content::BrowserContext; using content::BrowserThread; using content::RenderFrameHost; using content::RenderProcessHost; using content::SiteInstance; using content::WebContents; namespace { bool ShouldIsolate(BrowserContext* browser_context, const IsolationScenario* scenario, const GURL& site) { switch (scenario->policy) { case ISOLATE_NOTHING: return false; case ISOLATE_ALL_SITES: return true; case ISOLATE_HTTPS_SITES: // Note: For estimation purposes "isolate https sites" is really // implemented as "isolate non-http sites". This means that, for example, // the New Tab Page gets counted as two processes under this policy, and // extensions are isolated as well. return !site.SchemeIs(url::kHttpScheme); case ISOLATE_EXTENSIONS: { #if !defined(ENABLE_EXTENSIONS) return false; #else if (!site.SchemeIs(extensions::kExtensionScheme)) return false; extensions::ExtensionRegistry* registry = extensions::ExtensionRegistry::Get(browser_context); const extensions::Extension* extension = registry->enabled_extensions().GetExtensionOrAppByURL(site); return extension && !extension->is_hosted_app(); #endif } } NOTREACHED(); return true; } // Walk the frame tree and update |scenario|'s data for the given frame. Memoize // each frame's computed URL in |frame_urls| so it can be reused when visiting // its children. void CollectForScenario(std::map* frame_urls, SiteInstance* primary, IsolationScenario* scenario, RenderFrameHost* frame) { BrowserContext* context = primary->GetBrowserContext(); // Determine the site from the frame's origin, with a fallback to the // frame's URL. In cases like