Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Commit 2cb9669

Browse files
Make platform apps get isolated storage by default.
Also centralizes the checks for when isolated storage is applicable to happen in Extension::LoadAppIsolation, so that Extension::is_storage_isolated() don't have to check for the experimental permission anymore. [email protected] Review URL: http://codereview.chromium.org/10349015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135269 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 37409da commit 2cb9669

File tree

11 files changed

+110
-19
lines changed

11 files changed

+110
-19
lines changed

chrome/browser/extensions/extension_service.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,7 @@ bool ExtensionService::UninstallExtension(
826826

827827
GURL launch_web_url_origin(extension->launch_web_url());
828828
launch_web_url_origin = launch_web_url_origin.GetOrigin();
829-
bool is_storage_isolated =
830-
(extension->is_storage_isolated() &&
831-
extension->HasAPIPermission(ExtensionAPIPermission::kExperimental));
829+
bool is_storage_isolated = extension->is_storage_isolated();
832830

833831
if (extension->is_hosted_app() &&
834832
!profile_->GetExtensionSpecialStoragePolicy()->

chrome/browser/extensions/platform_app_browsertest.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "base/command_line.h"
66
#include "base/stringprintf.h"
77
#include "base/utf_string_conversions.h"
8+
#include "chrome/browser/automation/automation_util.h"
89
#include "chrome/browser/extensions/extension_apitest.h"
910
#include "chrome/browser/extensions/extension_browsertest.h"
1011
#include "chrome/browser/extensions/extension_host.h"
@@ -179,3 +180,34 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
179180
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) {
180181
ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_;
181182
}
183+
184+
// Tests that platform apps have isolated storage by default.
185+
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) {
186+
ASSERT_TRUE(StartTestServer());
187+
188+
// Load a (non-app) page under the "localhost" origin that sets a cookie.
189+
GURL set_cookie_url = test_server()->GetURL(
190+
"files/extensions/platform_apps/isolation/set_cookie.html");
191+
GURL::Replacements replace_host;
192+
std::string host_str("localhost"); // Must stay in scope with replace_host.
193+
replace_host.SetHostStr(host_str);
194+
set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
195+
196+
ui_test_utils::NavigateToURLWithDisposition(
197+
browser(), set_cookie_url,
198+
CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
199+
200+
// Make sure the cookie is set.
201+
int cookie_size;
202+
std::string cookie_value;
203+
automation_util::GetCookies(
204+
set_cookie_url,
205+
browser()->GetWebContentsAt(0),
206+
&cookie_size,
207+
&cookie_value);
208+
ASSERT_EQ("testCookie=1", cookie_value);
209+
210+
// Let the platform app request the same URL, and make sure that it doesn't
211+
// see the cookie.
212+
ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
213+
}

chrome/browser/profiles/off_the_record_profile_impl.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ net::URLRequestContextGetter*
282282
if (GetExtensionService()) {
283283
const Extension* installed_app = GetExtensionService()->
284284
GetInstalledAppForRenderer(renderer_child_id);
285-
if (installed_app != NULL && installed_app->is_storage_isolated() &&
286-
installed_app->HasAPIPermission(
287-
ExtensionAPIPermission::kExperimental)) {
285+
if (installed_app != NULL && installed_app->is_storage_isolated()) {
288286
return GetRequestContextForIsolatedApp(installed_app->id());
289287
}
290288
}

chrome/browser/profiles/profile_impl.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include "chrome/common/chrome_paths_internal.h"
7676
#include "chrome/common/chrome_switches.h"
7777
#include "chrome/common/chrome_version_info.h"
78-
#include "chrome/common/extensions/extension_permission_set.h"
7978
#include "chrome/common/pref_names.h"
8079
#include "chrome/common/url_constants.h"
8180
#include "content/public/browser/browser_thread.h"
@@ -704,9 +703,7 @@ net::URLRequestContextGetter* ProfileImpl::GetRequestContextForRenderProcess(
704703
if (extension_service) {
705704
const Extension* installed_app = extension_service->
706705
GetInstalledAppForRenderer(renderer_child_id);
707-
if (installed_app != NULL && installed_app->is_storage_isolated() &&
708-
installed_app->HasAPIPermission(
709-
ExtensionAPIPermission::kExperimental)) {
706+
if (installed_app != NULL && installed_app->is_storage_isolated()) {
710707
return GetRequestContextForIsolatedApp(installed_app->id());
711708
}
712709
}

chrome/common/extensions/api/_manifest_features.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"channel": "stable",
1212
"extension_types": ["packaged_app", "hosted_app"]
1313
},
14+
"app.isolation": {
15+
"channel": "stable",
16+
// Platform apps always have isolated storage, thus they cannot specify it
17+
// via the manifest.
18+
"extension_types": ["packaged_app", "hosted_app"]
19+
},
1420
"background": {
1521
"channel": "stable",
1622
"extension_types": [

chrome/common/extensions/extension.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,21 @@ bool Extension::LoadContentSecurityPolicy(string16* error) {
26952695
return true;
26962696
}
26972697

2698-
bool Extension::LoadAppIsolation(string16* error) {
2698+
bool Extension::LoadAppIsolation(
2699+
const ExtensionAPIPermissionSet& api_permissions, string16* error) {
2700+
// Platform apps always get isolated storage.
2701+
if (is_platform_app()) {
2702+
is_storage_isolated_ = true;
2703+
return true;
2704+
}
2705+
2706+
// Other apps only get it if it is requested _and_ experimental APIs are
2707+
// enabled.
2708+
if (!api_permissions.count(ExtensionAPIPermission::kExperimental) ||
2709+
!is_app()) {
2710+
return true;
2711+
}
2712+
26992713
Value* temp = NULL;
27002714
if (!manifest_->Get(keys::kIsolation, &temp))
27012715
return true;
@@ -3082,9 +3096,7 @@ bool Extension::InitFromValue(int flags, string16* error) {
30823096
return false;
30833097
}
30843098

3085-
// App isolation.
3086-
if (api_permissions.count(ExtensionAPIPermission::kExperimental) &&
3087-
is_app() && !LoadAppIsolation(error))
3099+
if (!LoadAppIsolation(api_permissions, error))
30883100
return false;
30893101

30903102
if (!LoadSharedFeatures(api_permissions, error))

chrome/common/extensions/extension.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
677677
bool is_platform_app() const;
678678
bool is_hosted_app() const;
679679
bool is_packaged_app() const;
680-
bool is_storage_isolated() const { return is_app() && is_storage_isolated_; }
680+
bool is_storage_isolated() const { return is_storage_isolated_; }
681681
const URLPatternSet& web_extent() const { return extent_; }
682682
const std::string& launch_local_path() const { return launch_local_path_; }
683683
const std::string& launch_web_url() const { return launch_web_url_; }
@@ -751,7 +751,8 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
751751
// extension from the manifest.
752752

753753
bool CheckMinimumChromeVersion(string16* error);
754-
bool LoadAppIsolation(string16* error);
754+
bool LoadAppIsolation(const ExtensionAPIPermissionSet& api_permissions,
755+
string16* error);
755756

756757
bool LoadRequiredFeatures(string16* error);
757758
bool LoadName(string16* error);

chrome/common/extensions/manifest_tests/extension_manifests_platformapp_unittest.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ TEST_F(ExtensionManifestTest, PlatformApps) {
2020

2121
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps);
2222

23-
LoadAndExpectSuccess("init_valid_platform_app.json");
24-
2523
scoped_refptr<Extension> extension =
26-
LoadAndExpectSuccess("init_invalid_platform_app_1.json");
24+
LoadAndExpectSuccess("init_valid_platform_app.json");
25+
EXPECT_TRUE(extension->is_storage_isolated());
26+
27+
extension = LoadAndExpectSuccess("init_invalid_platform_app_1.json");
2728
ASSERT_TRUE(extension);
2829
ASSERT_EQ(1u, extension->install_warnings().size());
2930
EXPECT_EQ("'app.launch' is not allowed for specified package type "
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Platform App Test: isolated storage",
3+
"platform_app": true,
4+
"version": "1",
5+
"manifest_version": 2,
6+
"background": {
7+
"scripts": ["test.js"]
8+
},
9+
"permissions": [
10+
"http://localhost/"
11+
]
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<body>
3+
<script>
4+
// Tomorrow.
5+
var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);
6+
document.cookie = 'testCookie=1; path=/; expires=' + expire + ';'
7+
</script>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)