Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / extension_process_policy.cc
blob00256c4989309a890029025ba3a6b99b0ba3bc0d
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.
5 #include "chrome/common/extensions/extension_process_policy.h"
7 #include "chrome/common/extensions/extension_set.h"
9 namespace extensions {
11 const extensions::Extension* GetNonBookmarkAppExtension(
12 const ExtensionSet& extensions, const ExtensionURLInfo& url) {
13 // Exclude bookmark apps, which do not use the app process model.
14 const extensions::Extension* extension =
15 extensions.GetExtensionOrAppByURL(url);
16 if (extension && extension->from_bookmark())
17 extension = NULL;
18 return extension;
21 bool CrossesExtensionProcessBoundary(
22 const ExtensionSet& extensions,
23 const ExtensionURLInfo& old_url,
24 const ExtensionURLInfo& new_url,
25 bool should_consider_workaround) {
26 const extensions::Extension* old_url_extension = GetNonBookmarkAppExtension(
27 extensions,
28 old_url);
29 const extensions::Extension* new_url_extension = GetNonBookmarkAppExtension(
30 extensions,
31 new_url);
33 // TODO(creis): Temporary workaround for crbug.com/59285: Do not swap process
34 // to navigate from a hosted app to a normal page or another hosted app
35 // (unless either is the web store). This is because some OAuth providers
36 // use non-app popups that communicate with non-app iframes inside the app
37 // (e.g., Facebook). This would require out-of-process iframes to support.
38 // See http://crbug.com/99379.
39 // Note that we skip this exception for isolated apps, which require strict
40 // process separation from non-app pages.
41 if (should_consider_workaround) {
42 bool old_url_is_hosted_app = old_url_extension &&
43 !old_url_extension->web_extent().is_empty() &&
44 !old_url_extension->is_storage_isolated();
45 bool new_url_is_normal_or_hosted = !new_url_extension ||
46 (!new_url_extension->web_extent().is_empty() &&
47 !new_url_extension->is_storage_isolated());
48 bool either_is_web_store =
49 (old_url_extension &&
50 old_url_extension->id() == extension_misc::kWebStoreAppId) ||
51 (new_url_extension &&
52 new_url_extension->id() == extension_misc::kWebStoreAppId);
53 if (old_url_is_hosted_app &&
54 new_url_is_normal_or_hosted &&
55 !either_is_web_store)
56 return false;
59 return old_url_extension != new_url_extension;
62 } // namespace extensions