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