summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications
diff options
context:
space:
mode:
authorskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-14 14:58:14 +0000
committerskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-14 14:58:14 +0000
commit2f1c09dae70520ee65dab0d064c396649e8b0fd2 (patch)
treee20aa45b4c8de6d21972e8c4083c921210f90490 /chrome/browser/web_applications
parent29407d3b243e8fe141669aebd7b39759bac0d369 (diff)
downloadchromium_src-2f1c09dae70520ee65dab0d064c396649e8b0fd2.zip
chromium_src-2f1c09dae70520ee65dab0d064c396649e8b0fd2.tar.gz
chromium_src-2f1c09dae70520ee65dab0d064c396649e8b0fd2.tar.bz2
Set Browser::app_name_ in a reasonable way for extension apps.
BUG=67702 TEST=BrowserTest.OpenAppWindowLikeNtp,BrowserTest.AppIdSwitch,manually open a few apps and see that windows taskbar hilights the right window. Review URL: http://codereview.chromium.org/6086004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_applications')
-rw-r--r--chrome/browser/web_applications/web_app.cc67
-rw-r--r--chrome/browser/web_applications/web_app.h5
2 files changed, 54 insertions, 18 deletions
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index 2c619e2..785e6ea 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -29,6 +29,7 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_plugin_util.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/web_apps.h"
@@ -90,27 +91,37 @@ FilePath GetSanitizedFileName(const string16& name) {
#endif // defined(OS_WIN)
// Returns relative directory of given web app url.
-FilePath GetWebAppDir(const GURL& url) {
- FilePath::StringType host;
- FilePath::StringType scheme_port;
+FilePath GetWebAppDir(const ShellIntegration::ShortcutInfo& info) {
+ if (!info.extension_id.empty()) {
+ std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
+ UTF16ToUTF8(info.extension_id));
+#if defined(OS_WIN)
+ return FilePath(UTF8ToWide(app_name));
+#elif defined(OS_POSIX)
+ return FilePath(app_name);
+#endif
+ } else {
+ FilePath::StringType host;
+ FilePath::StringType scheme_port;
#if defined(OS_WIN)
- host = UTF8ToWide(url.host());
- scheme_port = (url.has_scheme() ? UTF8ToWide(url.scheme()) : L"http") +
- FILE_PATH_LITERAL("_") +
- (url.has_port() ? UTF8ToWide(url.port()) : L"80");
+ host = UTF8ToWide(info.url.host());
+ scheme_port = (info.url.has_scheme() ? UTF8ToWide(info.url.scheme())
+ : L"http") + FILE_PATH_LITERAL("_") +
+ (info.url.has_port() ? UTF8ToWide(info.url.port()) : L"80");
#elif defined(OS_POSIX)
- host = url.host();
- scheme_port = url.scheme() + FILE_PATH_LITERAL("_") + url.port();
+ host = info.url.host();
+ scheme_port = info.url.scheme() + FILE_PATH_LITERAL("_") + info.url.port();
#endif
- return FilePath(host).Append(scheme_port);
+ return FilePath(host).Append(scheme_port);
+ }
}
// Returns data directory for given web app url
FilePath GetWebAppDataDirectory(const FilePath& root_dir,
- const GURL& url) {
- return root_dir.Append(GetWebAppDir(url));
+ const ShellIntegration::ShortcutInfo& info) {
+ return root_dir.Append(GetWebAppDir(info));
}
#if defined(TOOLKIT_VIEWS)
@@ -242,8 +253,9 @@ CreateShortcutTask::CreateShortcutTask(
const FilePath& profile_path,
const ShellIntegration::ShortcutInfo& shortcut_info,
web_app::CreateShortcutCallback* callback)
- : web_app_path_(GetWebAppDataDirectory(web_app::GetDataDir(profile_path),
- shortcut_info.url)),
+ : web_app_path_(GetWebAppDataDirectory(
+ web_app::GetDataDir(profile_path),
+ shortcut_info)),
profile_path_(profile_path),
shortcut_info_(shortcut_info),
callback_(callback),
@@ -376,9 +388,16 @@ bool CreateShortcutTask::CreateShortcut() {
shortcut_info_.description.resize(MAX_PATH - 1);
// Generates app id from web app url and profile path.
+ std::string app_name;
+ if (!shortcut_info_.extension_id.empty()) {
+ app_name = web_app::GenerateApplicationNameFromExtensionId(
+ UTF16ToUTF8(shortcut_info_.extension_id));
+ } else {
+ app_name = web_app::GenerateApplicationNameFromURL(
+ shortcut_info_.url);
+ }
std::wstring app_id = ShellIntegration::GetAppId(
- UTF8ToWide(web_app::GenerateApplicationNameFromURL(shortcut_info_.url)),
- profile_path_);
+ UTF8ToWide(app_name), profile_path_);
FilePath shortcut_to_pin;
@@ -615,7 +634,7 @@ void UpdateShortcutWorker::UpdateShortcutsOnFileThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FilePath web_app_path = GetWebAppDataDirectory(
- web_app::GetDataDir(profile_path_), shortcut_info_.url);
+ web_app::GetDataDir(profile_path_), shortcut_info_);
// Ensure web_app_path exists. web_app_path could be missing for a legacy
// shortcut created by gears.
@@ -685,6 +704,14 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(UpdateShortcutWorker);
namespace web_app {
+// The following string is used to build the directory name for
+// shortcuts to chrome applications (the kind which are installed
+// from a CRX). Application shortcuts to URLs use the {host}_{path}
+// for the name of this directory. Hosts can't include an underscore.
+// By starting this string with an underscore, we ensure that there
+// are no naming conflicts.
+static const char* kCrxAppPrefix = "_crx_";
+
std::string GenerateApplicationNameFromURL(const GURL& url) {
std::string t;
t.append(url.host());
@@ -693,6 +720,12 @@ std::string GenerateApplicationNameFromURL(const GURL& url) {
return t;
}
+std::string GenerateApplicationNameFromExtensionId(const std::string& id) {
+ std::string t(web_app::kCrxAppPrefix);
+ t.append(id);
+ return t;
+}
+
void CreateShortcut(
const FilePath& data_dir,
const ShellIntegration::ShortcutInfo& shortcut_info,
diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h
index 4734b7e..76b666c 100644
--- a/chrome/browser/web_applications/web_app.h
+++ b/chrome/browser/web_applications/web_app.h
@@ -24,6 +24,9 @@ namespace web_app {
// as app id for BrowserWindow, shortcut and jump list.
std::string GenerateApplicationNameFromURL(const GURL& url);
+// Compute a deterministic name based on an extension/apps's id.
+std::string GenerateApplicationNameFromExtensionId(const std::string& id);
+
// Callback after user dismisses CreateShortcutView. "true" indicates
// shortcut is created successfully. Otherwise, it is false.
typedef Callback1<bool>::Type CreateShortcutCallback;
@@ -32,7 +35,7 @@ typedef Callback1<bool>::Type CreateShortcutCallback;
// |profile_path| is used as root directory for persisted data such as icon.
// Directory layout is similar to what Gears has, i.e. an web application's
// file is stored under "#/host_name/scheme_port", where '#' is the
-// |root_dir|.
+// |root_dir|. A crx based app uses a directory named _crx_<app id>.
void CreateShortcut(
const FilePath& profile_path,
const ShellIntegration::ShortcutInfo& shortcut_info,