Home | History | Annotate | Download | only in extensions
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/extensions/extension_process_policy.h"
      6 
      7 #include "chrome/common/extensions/extension.h"
      8 #include "chrome/common/extensions/extension_set.h"
      9 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
     10 
     11 namespace extensions {
     12 
     13 const extensions::Extension* GetNonBookmarkAppExtension(
     14     const ExtensionSet& extensions, const GURL& url) {
     15   // Exclude bookmark apps, which do not use the app process model.
     16   const extensions::Extension* extension =
     17       extensions.GetExtensionOrAppByURL(url);
     18   if (extension && extension->from_bookmark())
     19     extension = NULL;
     20   return extension;
     21 }
     22 
     23 bool CrossesExtensionProcessBoundary(
     24     const ExtensionSet& extensions,
     25     const GURL& old_url,
     26     const GURL& new_url,
     27     bool should_consider_workaround) {
     28   const extensions::Extension* old_url_extension = GetNonBookmarkAppExtension(
     29       extensions,
     30       old_url);
     31   const extensions::Extension* new_url_extension = GetNonBookmarkAppExtension(
     32       extensions,
     33       new_url);
     34 
     35   // TODO(creis): Temporary workaround for crbug.com/59285: Do not swap process
     36   // to navigate from a hosted app to a normal page or another hosted app
     37   // (unless either is the web store).  This is because some OAuth providers
     38   // use non-app popups that communicate with non-app iframes inside the app
     39   // (e.g., Facebook).  This would require out-of-process iframes to support.
     40   // See http://crbug.com/99379.
     41   // Note that we skip this exception for isolated apps, which require strict
     42   // process separation from non-app pages.
     43   if (should_consider_workaround) {
     44     bool old_url_is_hosted_app = old_url_extension &&
     45         !old_url_extension->web_extent().is_empty() &&
     46         !AppIsolationInfo::HasIsolatedStorage(old_url_extension);
     47     bool new_url_is_normal_or_hosted = !new_url_extension ||
     48         (!new_url_extension->web_extent().is_empty() &&
     49          !AppIsolationInfo::HasIsolatedStorage(new_url_extension));
     50     bool either_is_web_store =
     51         (old_url_extension &&
     52         old_url_extension->id() == extension_misc::kWebStoreAppId) ||
     53         (new_url_extension &&
     54         new_url_extension->id() == extension_misc::kWebStoreAppId);
     55     if (old_url_is_hosted_app &&
     56         new_url_is_normal_or_hosted &&
     57         !either_is_web_store)
     58       return false;
     59   }
     60 
     61   return old_url_extension != new_url_extension;
     62 }
     63 
     64 }  // namespace extensions
     65