Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/web_applications/web_app.cc

Issue 9374009: Install platform apps into a separate data directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/web_applications/web_app.h" 5 #include "chrome/browser/web_applications/web_app.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 using content::BrowserThread; 17 using content::BrowserThread;
18 18
19 namespace { 19 namespace {
20 20
21 // Allow tests to disable shortcut creation, to prevent developers desktops 21 // Allow tests to disable shortcut creation, to prevent developers desktops
22 // becoming overrun with shortcuts. 22 // becoming overrun with shortcuts.
23 bool disable_shortcut_creation_for_tests = false; 23 bool disable_shortcut_creation_for_tests = false;
24 24
25 // Returns relative directory of given web app url. 25 // Returns relative directory of given web app url.
26 FilePath GetWebAppDir(const ShellIntegration::ShortcutInfo& info) { 26 FilePath GetWebAppDir(const std::string& extension_id, const GURL& url) {
27 if (!info.extension_id.empty()) { 27 if (!extension_id.empty()) {
28 std::string app_name = 28 std::string app_name =
29 web_app::GenerateApplicationNameFromExtensionId(info.extension_id); 29 web_app::GenerateApplicationNameFromExtensionId(extension_id);
30 #if defined(OS_WIN) 30 #if defined(OS_WIN)
31 return FilePath(UTF8ToWide(app_name)); 31 return FilePath(UTF8ToWide(app_name));
32 #elif defined(OS_POSIX) 32 #elif defined(OS_POSIX)
33 return FilePath(app_name); 33 return FilePath(app_name);
34 #endif 34 #endif
35 } else { 35 } else {
36 FilePath::StringType host; 36 FilePath::StringType host;
37 FilePath::StringType scheme_port; 37 FilePath::StringType scheme_port;
38 38
39 #if defined(OS_WIN) 39 #if defined(OS_WIN)
40 host = UTF8ToWide(info.url.host()); 40 host = UTF8ToWide(url.host());
41 scheme_port = (info.url.has_scheme() ? UTF8ToWide(info.url.scheme()) 41 scheme_port = (url.has_scheme() ? UTF8ToWide(url.scheme())
42 : L"http") + FILE_PATH_LITERAL("_") + 42 : L"http") + FILE_PATH_LITERAL("_") +
43 (info.url.has_port() ? UTF8ToWide(info.url.port()) : L"80"); 43 (url.has_port() ? UTF8ToWide(url.port()) : L"80");
44 #elif defined(OS_POSIX) 44 #elif defined(OS_POSIX)
45 host = info.url.host(); 45 host = url.host();
46 scheme_port = info.url.scheme() + FILE_PATH_LITERAL("_") + info.url.port(); 46 scheme_port = url.scheme() + FILE_PATH_LITERAL("_") + url.port();
47 #endif 47 #endif
48 48
49 return FilePath(host).Append(scheme_port); 49 return FilePath(host).Append(scheme_port);
50 } 50 }
51 } 51 }
52 52
53 #if defined(TOOLKIT_VIEWS) 53 #if defined(TOOLKIT_VIEWS)
54 // Predicator for sorting images from largest to smallest. 54 // Predicator for sorting images from largest to smallest.
55 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, 55 bool IconPrecedes(const WebApplicationInfo::IconInfo& left,
56 const WebApplicationInfo::IconInfo& right) { 56 const WebApplicationInfo::IconInfo& right) {
57 return left.width < right.width; 57 return left.width < right.width;
58 } 58 }
59 #endif 59 #endif
60 60
61 } // namespace 61 } // namespace
62 62
63 namespace web_app { 63 namespace web_app {
64 64
65 // The following string is used to build the directory name for 65 // The following string is used to build the directory name for
66 // shortcuts to chrome applications (the kind which are installed 66 // shortcuts to chrome applications (the kind which are installed
67 // from a CRX). Application shortcuts to URLs use the {host}_{path} 67 // from a CRX). Application shortcuts to URLs use the {host}_{path}
68 // for the name of this directory. Hosts can't include an underscore. 68 // for the name of this directory. Hosts can't include an underscore.
69 // By starting this string with an underscore, we ensure that there 69 // By starting this string with an underscore, we ensure that there
70 // are no naming conflicts. 70 // are no naming conflicts.
71 static const char* kCrxAppPrefix = "_crx_"; 71 static const char* kCrxAppPrefix = "_crx_";
72 72
73 namespace internals { 73 namespace internals {
74 74
75 // Returns data directory for given web app url
76 FilePath GetWebAppDataDirectory(const FilePath& root_dir,
77 const ShellIntegration::ShortcutInfo& info) {
78 return root_dir.Append(GetWebAppDir(info));
79 }
80
81 FilePath GetSanitizedFileName(const string16& name) { 75 FilePath GetSanitizedFileName(const string16& name) {
82 #if defined(OS_WIN) 76 #if defined(OS_WIN)
83 string16 file_name = name; 77 string16 file_name = name;
84 #else 78 #else
85 std::string file_name = UTF16ToUTF8(name); 79 std::string file_name = UTF16ToUTF8(name);
86 #endif 80 #endif
87 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); 81 file_util::ReplaceIllegalCharactersInPath(&file_name, '_');
88 return FilePath(file_name); 82 return FilePath(file_name);
89 } 83 }
90 84
91 } // namespace internals 85 } // namespace internals
92 86
87 FilePath GetWebAppDataDirectory(const FilePath& profile_path,
88 const std::string& extension_id,
89 const GURL& url) {
90 return GetDataDir(profile_path).Append(GetWebAppDir(extension_id, url));
91 }
92
93 std::string GenerateApplicationNameFromInfo( 93 std::string GenerateApplicationNameFromInfo(
94 const ShellIntegration::ShortcutInfo& shortcut_info) { 94 const ShellIntegration::ShortcutInfo& shortcut_info) {
95 if (!shortcut_info.extension_id.empty()) { 95 if (!shortcut_info.extension_id.empty()) {
96 return web_app::GenerateApplicationNameFromExtensionId( 96 return web_app::GenerateApplicationNameFromExtensionId(
97 shortcut_info.extension_id); 97 shortcut_info.extension_id);
98 } else { 98 } else {
99 return web_app::GenerateApplicationNameFromURL( 99 return web_app::GenerateApplicationNameFromURL(
100 shortcut_info.url); 100 shortcut_info.url);
101 } 101 }
102 } 102 }
(...skipping 22 matching lines...) Expand all
125 void CreateShortcut( 125 void CreateShortcut(
126 const FilePath& data_dir, 126 const FilePath& data_dir,
127 const ShellIntegration::ShortcutInfo& shortcut_info) { 127 const ShellIntegration::ShortcutInfo& shortcut_info) {
128 if (disable_shortcut_creation_for_tests) 128 if (disable_shortcut_creation_for_tests)
129 return; 129 return;
130 130
131 BrowserThread::PostTask( 131 BrowserThread::PostTask(
132 BrowserThread::FILE, 132 BrowserThread::FILE,
133 FROM_HERE, 133 FROM_HERE,
134 base::Bind(&internals::CreateShortcutTask, 134 base::Bind(&internals::CreateShortcutTask,
135 web_app::internals::GetWebAppDataDirectory( 135 GetWebAppDataDirectory(
136 web_app::GetDataDir(data_dir), 136 data_dir,
137 shortcut_info), 137 shortcut_info.extension_id,
138 shortcut_info.url),
138 data_dir, 139 data_dir,
139 shortcut_info)); 140 shortcut_info));
140 } 141 }
141 142
142 void SetDisableShortcutCreationForTests(bool disable) { 143 void SetDisableShortcutCreationForTests(bool disable) {
143 disable_shortcut_creation_for_tests = disable; 144 disable_shortcut_creation_for_tests = disable;
144 } 145 }
145 146
146 bool IsValidUrl(const GURL& url) { 147 bool IsValidUrl(const GURL& url) {
147 static const char* const kValidUrlSchemes[] = { 148 static const char* const kValidUrlSchemes[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 184
184 #if defined(TOOLKIT_USES_GTK) 185 #if defined(TOOLKIT_USES_GTK)
185 std::string GetWMClassFromAppName(std::string app_name) { 186 std::string GetWMClassFromAppName(std::string app_name) {
186 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); 187 file_util::ReplaceIllegalCharactersInPath(&app_name, '_');
187 TrimString(app_name, "_", &app_name); 188 TrimString(app_name, "_", &app_name);
188 return app_name; 189 return app_name;
189 } 190 }
190 #endif 191 #endif
191 192
192 } // namespace web_app 193 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698