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

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: rebase, address review comments 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) 2012 The Chromium Authors. All rights reserved. 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 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 // Returns relative directory of given web app url. 21 // Returns relative directory of given web app url.
22 FilePath GetWebAppDir(const ShellIntegration::ShortcutInfo& info) { 22 FilePath GetWebAppDir(const std::string& extension_id, const GURL& url) {
23 if (!info.extension_id.empty()) { 23 if (!extension_id.empty()) {
24 std::string app_name = 24 std::string app_name =
25 web_app::GenerateApplicationNameFromExtensionId(info.extension_id); 25 web_app::GenerateApplicationNameFromExtensionId(extension_id);
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 return FilePath(UTF8ToUTF16(app_name)); 27 return FilePath(UTF8ToUTF16(app_name));
28 #elif defined(OS_POSIX) 28 #elif defined(OS_POSIX)
29 return FilePath(app_name); 29 return FilePath(app_name);
30 #endif 30 #endif
31 } else { 31 } else {
32 FilePath::StringType host; 32 FilePath::StringType host;
33 FilePath::StringType scheme_port; 33 FilePath::StringType scheme_port;
34 34
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 host = UTF8ToUTF16(info.url.host()); 36 host = UTF8ToUTF16(url.host());
37 scheme_port = (info.url.has_scheme() ? UTF8ToUTF16(info.url.scheme()) 37 scheme_port = (url.has_scheme() ? UTF8ToUTF16(url.scheme())
38 : L"http") + FILE_PATH_LITERAL("_") + 38 : L"http") + FILE_PATH_LITERAL("_") +
39 (info.url.has_port() ? UTF8ToUTF16(info.url.port()) : L"80"); 39 (url.has_port() ? UTF8ToUTF16(url.port()) : L"80");
40 #elif defined(OS_POSIX) 40 #elif defined(OS_POSIX)
41 host = info.url.host(); 41 host = url.host();
42 scheme_port = info.url.scheme() + FILE_PATH_LITERAL("_") + info.url.port(); 42 scheme_port = url.scheme() + FILE_PATH_LITERAL("_") + url.port();
43 #endif 43 #endif
44 44
45 return FilePath(host).Append(scheme_port); 45 return FilePath(host).Append(scheme_port);
46 } 46 }
47 } 47 }
48 48
49 #if defined(TOOLKIT_VIEWS) 49 #if defined(TOOLKIT_VIEWS)
50 // Predicator for sorting images from largest to smallest. 50 // Predicator for sorting images from largest to smallest.
51 bool IconPrecedes(const WebApplicationInfo::IconInfo& left, 51 bool IconPrecedes(const WebApplicationInfo::IconInfo& left,
52 const WebApplicationInfo::IconInfo& right) { 52 const WebApplicationInfo::IconInfo& right) {
53 return left.width < right.width; 53 return left.width < right.width;
54 } 54 }
55 #endif 55 #endif
56 56
57 } // namespace 57 } // namespace
58 58
59 namespace web_app { 59 namespace web_app {
60 60
61 // The following string is used to build the directory name for 61 // The following string is used to build the directory name for
62 // shortcuts to chrome applications (the kind which are installed 62 // shortcuts to chrome applications (the kind which are installed
63 // from a CRX). Application shortcuts to URLs use the {host}_{path} 63 // from a CRX). Application shortcuts to URLs use the {host}_{path}
64 // for the name of this directory. Hosts can't include an underscore. 64 // for the name of this directory. Hosts can't include an underscore.
65 // By starting this string with an underscore, we ensure that there 65 // By starting this string with an underscore, we ensure that there
66 // are no naming conflicts. 66 // are no naming conflicts.
67 static const char* kCrxAppPrefix = "_crx_"; 67 static const char* kCrxAppPrefix = "_crx_";
68 68
69 namespace internals { 69 namespace internals {
70 70
71 // Returns data directory for given web app url
72 FilePath GetWebAppDataDirectory(const FilePath& root_dir,
73 const ShellIntegration::ShortcutInfo& info) {
74 return root_dir.Append(GetWebAppDir(info));
75 }
76
77 FilePath GetSanitizedFileName(const string16& name) { 71 FilePath GetSanitizedFileName(const string16& name) {
78 #if defined(OS_WIN) 72 #if defined(OS_WIN)
79 string16 file_name = name; 73 string16 file_name = name;
80 #else 74 #else
81 std::string file_name = UTF16ToUTF8(name); 75 std::string file_name = UTF16ToUTF8(name);
82 #endif 76 #endif
83 file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); 77 file_util::ReplaceIllegalCharactersInPath(&file_name, '_');
84 return FilePath(file_name); 78 return FilePath(file_name);
85 } 79 }
86 80
87 } // namespace internals 81 } // namespace internals
88 82
83 FilePath GetWebAppDataDirectory(const FilePath& profile_path,
84 const std::string& extension_id,
85 const GURL& url) {
86 return GetDataDir(profile_path).Append(GetWebAppDir(extension_id, url));
87 }
88
89 std::string GenerateApplicationNameFromInfo( 89 std::string GenerateApplicationNameFromInfo(
90 const ShellIntegration::ShortcutInfo& shortcut_info) { 90 const ShellIntegration::ShortcutInfo& shortcut_info) {
91 if (!shortcut_info.extension_id.empty()) { 91 if (!shortcut_info.extension_id.empty()) {
92 return web_app::GenerateApplicationNameFromExtensionId( 92 return web_app::GenerateApplicationNameFromExtensionId(
93 shortcut_info.extension_id); 93 shortcut_info.extension_id);
94 } else { 94 } else {
95 return web_app::GenerateApplicationNameFromURL( 95 return web_app::GenerateApplicationNameFromURL(
96 shortcut_info.url); 96 shortcut_info.url);
97 } 97 }
98 } 98 }
(...skipping 19 matching lines...) Expand all
118 return app_name.substr(prefix.length()); 118 return app_name.substr(prefix.length());
119 } 119 }
120 120
121 void CreateShortcut( 121 void CreateShortcut(
122 const FilePath& data_dir, 122 const FilePath& data_dir,
123 const ShellIntegration::ShortcutInfo& shortcut_info) { 123 const ShellIntegration::ShortcutInfo& shortcut_info) {
124 BrowserThread::PostTask( 124 BrowserThread::PostTask(
125 BrowserThread::FILE, 125 BrowserThread::FILE,
126 FROM_HERE, 126 FROM_HERE,
127 base::Bind(&internals::CreateShortcutTask, 127 base::Bind(&internals::CreateShortcutTask,
128 web_app::internals::GetWebAppDataDirectory( 128 GetWebAppDataDirectory(
129 web_app::GetDataDir(data_dir), 129 data_dir,
130 shortcut_info), 130 shortcut_info.extension_id,
131 shortcut_info.url),
131 data_dir, 132 data_dir,
132 shortcut_info)); 133 shortcut_info));
133 } 134 }
134 135
135 bool IsValidUrl(const GURL& url) { 136 bool IsValidUrl(const GURL& url) {
136 static const char* const kValidUrlSchemes[] = { 137 static const char* const kValidUrlSchemes[] = {
137 chrome::kFileScheme, 138 chrome::kFileScheme,
138 chrome::kFtpScheme, 139 chrome::kFtpScheme,
139 chrome::kHttpScheme, 140 chrome::kHttpScheme,
140 chrome::kHttpsScheme, 141 chrome::kHttpsScheme,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 173
173 #if defined(TOOLKIT_USES_GTK) 174 #if defined(TOOLKIT_USES_GTK)
174 std::string GetWMClassFromAppName(std::string app_name) { 175 std::string GetWMClassFromAppName(std::string app_name) {
175 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); 176 file_util::ReplaceIllegalCharactersInPath(&app_name, '_');
176 TrimString(app_name, "_", &app_name); 177 TrimString(app_name, "_", &app_name);
177 return app_name; 178 return app_name;
178 } 179 }
179 #endif 180 #endif
180 181
181 } // namespace web_app 182 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698