Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / apps / app_info_dialog / app_info_summary_panel.cc
index 3a638f2..d131b35 100644 (file)
@@ -8,18 +8,25 @@
 
 #include "base/callback_forward.h"
 #include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/i18n/time_formatting.h"
 #include "base/logging.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/task_runner_util.h"
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/extensions/launch_util.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/browser_thread.h"
 #include "extensions/browser/extension_prefs.h"
 #include "extensions/browser/extension_system.h"
 #include "extensions/common/extension.h"
-#include "grit/generated_resources.h"
+#include "extensions/common/manifest.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/models/combobox_model.h"
+#include "ui/base/text/bytes_formatting.h"
 #include "ui/views/controls/combobox/combobox.h"
 #include "ui/views/controls/label.h"
 #include "ui/views/layout/box_layout.h"
@@ -126,9 +133,20 @@ AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile,
     : AppInfoPanel(profile, app),
       description_heading_(NULL),
       description_label_(NULL),
-      launch_options_combobox_(NULL) {
+      details_heading_(NULL),
+      size_title_(NULL),
+      size_value_(NULL),
+      version_title_(NULL),
+      version_value_(NULL),
+      installed_time_title_(NULL),
+      installed_time_value_(NULL),
+      last_run_time_title_(NULL),
+      last_run_time_value_(NULL),
+      launch_options_combobox_(NULL),
+      weak_ptr_factory_(this) {
   // Create UI elements.
   CreateDescriptionControl();
+  CreateDetailsControl();
   CreateLaunchOptionControl();
 
   // Layout elements.
@@ -139,6 +157,7 @@ AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile,
                            views::kUnrelatedControlVerticalSpacing));
 
   LayoutDescriptionControl();
+  LayoutDetailsControl();
 
   if (launch_options_combobox_)
     AddChildView(launch_options_combobox_);
@@ -167,6 +186,73 @@ void AppInfoSummaryPanel::CreateDescriptionControl() {
   }
 }
 
+void AppInfoSummaryPanel::CreateDetailsControl() {
+  // The size doesn't make sense for component apps.
+  if (app_->location() != extensions::Manifest::COMPONENT) {
+    size_title_ = new views::Label(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LABEL));
+    size_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+    size_value_ = new views::Label(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LOADING_LABEL));
+    size_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+    StartCalculatingAppSize();
+  }
+
+  // The version doesn't make sense for bookmark apps.
+  if (!app_->from_bookmark()) {
+    // Display 'Version: Built-in' for component apps.
+    base::string16 version_str = base::ASCIIToUTF16(app_->VersionString());
+    if (app_->location() == extensions::Manifest::COMPONENT)
+      version_str = l10n_util::GetStringUTF16(
+          IDS_APPLICATION_INFO_VERSION_BUILT_IN_LABEL);
+
+    version_title_ = new views::Label(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_VERSION_LABEL));
+    version_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+    version_value_ = new views::Label(version_str);
+    version_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+  }
+
+  // The install date doesn't make sense for component apps.
+  if (app_->location() != extensions::Manifest::COMPONENT) {
+    installed_time_title_ = new views::Label(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_INSTALLED_LABEL));
+    installed_time_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+    installed_time_value_ =
+        new views::Label(base::TimeFormatShortDate(GetInstalledTime()));
+    installed_time_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+  }
+
+  // The last run time is currently incorrect for component and hosted apps,
+  // since it is not updated when they are accessed outside of their shortcuts.
+  // TODO(sashab): Update the run time for these correctly: crbug.com/398716
+  if (app_->location() != extensions::Manifest::COMPONENT &&
+      !app_->is_hosted_app()) {
+    last_run_time_title_ = new views::Label(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_LAST_RUN_LABEL));
+    last_run_time_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+    // Display 'Never' if the app has never been run.
+    base::string16 last_run_value_str =
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_LAST_RUN_NEVER_LABEL);
+    if (GetLastLaunchedTime() != base::Time())
+      last_run_value_str = base::TimeFormatShortDate(GetLastLaunchedTime());
+
+    last_run_time_value_ = new views::Label(last_run_value_str);
+    last_run_time_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+  }
+
+  // Only generate the heading if we have at least one field to display.
+  if (version_title_ || installed_time_title_ || last_run_time_title_) {
+    details_heading_ = CreateHeading(
+        l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_DETAILS_TITLE));
+  }
+}
+
 void AppInfoSummaryPanel::CreateLaunchOptionControl() {
   if (CanSetLaunchType()) {
     launch_options_combobox_model_.reset(new LaunchOptionsComboboxModel());
@@ -189,6 +275,38 @@ void AppInfoSummaryPanel::LayoutDescriptionControl() {
   }
 }
 
+void AppInfoSummaryPanel::LayoutDetailsControl() {
+  if (details_heading_) {
+    views::View* details_stack =
+        CreateVerticalStack(views::kRelatedControlSmallVerticalSpacing);
+
+    if (version_title_ && version_value_) {
+      details_stack->AddChildView(
+          CreateKeyValueField(version_title_, version_value_));
+    }
+
+    if (installed_time_title_ && installed_time_value_) {
+      details_stack->AddChildView(
+          CreateKeyValueField(installed_time_title_, installed_time_value_));
+    }
+
+    if (last_run_time_title_ && last_run_time_value_) {
+      details_stack->AddChildView(
+          CreateKeyValueField(last_run_time_title_, last_run_time_value_));
+    }
+
+    if (size_title_ && size_value_) {
+      details_stack->AddChildView(
+          CreateKeyValueField(size_title_, size_value_));
+    }
+
+    views::View* vertical_stack = CreateVerticalStack();
+    vertical_stack->AddChildView(details_heading_);
+    vertical_stack->AddChildView(details_stack);
+    AddChildView(vertical_stack);
+  }
+}
+
 void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) {
   if (combobox == launch_options_combobox_) {
     SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex(
@@ -198,6 +316,27 @@ void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) {
   }
 }
 
+void AppInfoSummaryPanel::StartCalculatingAppSize() {
+  base::PostTaskAndReplyWithResult(
+      content::BrowserThread::GetBlockingPool(),
+      FROM_HERE,
+      base::Bind(&base::ComputeDirectorySize, app_->path()),
+      base::Bind(&AppInfoSummaryPanel::OnAppSizeCalculated, AsWeakPtr()));
+}
+
+void AppInfoSummaryPanel::OnAppSizeCalculated(int64 app_size_in_bytes) {
+  size_value_->SetText(ui::FormatBytes(app_size_in_bytes));
+}
+
+base::Time AppInfoSummaryPanel::GetInstalledTime() const {
+  return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id());
+}
+
+base::Time AppInfoSummaryPanel::GetLastLaunchedTime() const {
+  return extensions::ExtensionPrefs::Get(profile_)
+      ->GetLastLaunchTime(app_->id());
+}
+
 extensions::LaunchType AppInfoSummaryPanel::GetLaunchType() const {
   return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_),
                                    app_);
@@ -212,6 +351,6 @@ void AppInfoSummaryPanel::SetLaunchType(
 }
 
 bool AppInfoSummaryPanel::CanSetLaunchType() const {
-  // V2 apps don't have a launch type.
-  return !app_->is_platform_app();
+  // V2 apps don't have a launch type, and neither does the Chrome app.
+  return app_->id() != extension_misc::kChromeAppId && !app_->is_platform_app();
 }