| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 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/ui/views/apps/app_info_dialog/app_info_summary_panel.h" |    5 #include "chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.h" | 
|    6  |    6  | 
|    7 #include <vector> |    7 #include <vector> | 
|    8  |    8  | 
|    9 #include "base/callback_forward.h" |    9 #include "base/callback_forward.h" | 
|   10 #include "base/command_line.h" |   10 #include "base/command_line.h" | 
 |   11 #include "base/file_util.h" | 
|   11 #include "base/i18n/time_formatting.h" |   12 #include "base/i18n/time_formatting.h" | 
|   12 #include "base/logging.h" |   13 #include "base/logging.h" | 
|   13 #include "base/strings/utf_string_conversions.h" |   14 #include "base/strings/utf_string_conversions.h" | 
 |   15 #include "base/task_runner_util.h" | 
|   14 #include "chrome/browser/extensions/extension_service.h" |   16 #include "chrome/browser/extensions/extension_service.h" | 
|   15 #include "chrome/browser/extensions/launch_util.h" |   17 #include "chrome/browser/extensions/launch_util.h" | 
|   16 #include "chrome/browser/profiles/profile.h" |   18 #include "chrome/browser/profiles/profile.h" | 
|   17 #include "chrome/common/chrome_switches.h" |   19 #include "chrome/common/chrome_switches.h" | 
|   18 #include "chrome/common/extensions/extension_constants.h" |   20 #include "chrome/common/extensions/extension_constants.h" | 
 |   21 #include "content/public/browser/browser_thread.h" | 
|   19 #include "extensions/browser/extension_prefs.h" |   22 #include "extensions/browser/extension_prefs.h" | 
|   20 #include "extensions/browser/extension_system.h" |   23 #include "extensions/browser/extension_system.h" | 
|   21 #include "extensions/common/extension.h" |   24 #include "extensions/common/extension.h" | 
|   22 #include "extensions/common/manifest.h" |   25 #include "extensions/common/manifest.h" | 
|   23 #include "grit/generated_resources.h" |   26 #include "grit/generated_resources.h" | 
|   24 #include "ui/base/l10n/l10n_util.h" |   27 #include "ui/base/l10n/l10n_util.h" | 
|   25 #include "ui/base/models/combobox_model.h" |   28 #include "ui/base/models/combobox_model.h" | 
 |   29 #include "ui/base/text/bytes_formatting.h" | 
|   26 #include "ui/views/controls/combobox/combobox.h" |   30 #include "ui/views/controls/combobox/combobox.h" | 
|   27 #include "ui/views/controls/label.h" |   31 #include "ui/views/controls/label.h" | 
|   28 #include "ui/views/layout/box_layout.h" |   32 #include "ui/views/layout/box_layout.h" | 
|   29 #include "ui/views/layout/layout_constants.h" |   33 #include "ui/views/layout/layout_constants.h" | 
|   30 #include "ui/views/view.h" |   34 #include "ui/views/view.h" | 
|   31 #include "ui/views/widget/widget.h" |   35 #include "ui/views/widget/widget.h" | 
|   32  |   36  | 
|   33 // A model for a combobox selecting the launch options for a hosted app. |   37 // A model for a combobox selecting the launch options for a hosted app. | 
|   34 // Displays different options depending on the host OS. |   38 // Displays different options depending on the host OS. | 
|   35 class LaunchOptionsComboboxModel : public ui::ComboboxModel { |   39 class LaunchOptionsComboboxModel : public ui::ComboboxModel { | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  123 base::string16 LaunchOptionsComboboxModel::GetItemAt(int index) { |  127 base::string16 LaunchOptionsComboboxModel::GetItemAt(int index) { | 
|  124   return launch_type_messages_[index]; |  128   return launch_type_messages_[index]; | 
|  125 } |  129 } | 
|  126  |  130  | 
|  127 AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile, |  131 AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile, | 
|  128                                          const extensions::Extension* app) |  132                                          const extensions::Extension* app) | 
|  129     : AppInfoPanel(profile, app), |  133     : AppInfoPanel(profile, app), | 
|  130       description_heading_(NULL), |  134       description_heading_(NULL), | 
|  131       description_label_(NULL), |  135       description_label_(NULL), | 
|  132       details_heading_(NULL), |  136       details_heading_(NULL), | 
 |  137       size_title_(NULL), | 
 |  138       size_value_(NULL), | 
|  133       version_title_(NULL), |  139       version_title_(NULL), | 
|  134       version_value_(NULL), |  140       version_value_(NULL), | 
|  135       installed_time_title_(NULL), |  141       installed_time_title_(NULL), | 
|  136       installed_time_value_(NULL), |  142       installed_time_value_(NULL), | 
|  137       last_run_time_title_(NULL), |  143       last_run_time_title_(NULL), | 
|  138       last_run_time_value_(NULL), |  144       last_run_time_value_(NULL), | 
|  139       launch_options_combobox_(NULL) { |  145       launch_options_combobox_(NULL), | 
 |  146       weak_ptr_factory_(this) { | 
|  140   // Create UI elements. |  147   // Create UI elements. | 
|  141   CreateDescriptionControl(); |  148   CreateDescriptionControl(); | 
|  142   CreateDetailsControl(); |  149   CreateDetailsControl(); | 
|  143   CreateLaunchOptionControl(); |  150   CreateLaunchOptionControl(); | 
|  144  |  151  | 
|  145   // Layout elements. |  152   // Layout elements. | 
|  146   SetLayoutManager( |  153   SetLayoutManager( | 
|  147       new views::BoxLayout(views::BoxLayout::kVertical, |  154       new views::BoxLayout(views::BoxLayout::kVertical, | 
|  148                            0, |  155                            0, | 
|  149                            0, |  156                            0, | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  173  |  180  | 
|  174     description_heading_ = CreateHeading( |  181     description_heading_ = CreateHeading( | 
|  175         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_DESCRIPTION_TITLE)); |  182         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_DESCRIPTION_TITLE)); | 
|  176     description_label_ = new views::Label(text); |  183     description_label_ = new views::Label(text); | 
|  177     description_label_->SetMultiLine(true); |  184     description_label_->SetMultiLine(true); | 
|  178     description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |  185     description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 
|  179   } |  186   } | 
|  180 } |  187 } | 
|  181  |  188  | 
|  182 void AppInfoSummaryPanel::CreateDetailsControl() { |  189 void AppInfoSummaryPanel::CreateDetailsControl() { | 
 |  190   // The size doesn't make sense for component apps. | 
 |  191   if (app_->location() != extensions::Manifest::COMPONENT) { | 
 |  192     size_title_ = new views::Label( | 
 |  193         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LABEL)); | 
 |  194     size_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 
 |  195  | 
 |  196     size_value_ = new views::Label( | 
 |  197         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LOADING_LABEL)); | 
 |  198     size_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 
 |  199  | 
 |  200     StartCalculatingAppSize(); | 
 |  201   } | 
 |  202  | 
|  183   // The version doesn't make sense for bookmark apps. |  203   // The version doesn't make sense for bookmark apps. | 
|  184   if (!app_->from_bookmark()) { |  204   if (!app_->from_bookmark()) { | 
|  185     // Display 'Version: Built-in' for component apps. |  205     // Display 'Version: Built-in' for component apps. | 
|  186     base::string16 version_str = base::ASCIIToUTF16(app_->VersionString()); |  206     base::string16 version_str = base::ASCIIToUTF16(app_->VersionString()); | 
|  187     if (app_->location() == extensions::Manifest::COMPONENT) |  207     if (app_->location() == extensions::Manifest::COMPONENT) | 
|  188       version_str = l10n_util::GetStringUTF16( |  208       version_str = l10n_util::GetStringUTF16( | 
|  189           IDS_APPLICATION_INFO_VERSION_BUILT_IN_LABEL); |  209           IDS_APPLICATION_INFO_VERSION_BUILT_IN_LABEL); | 
|  190  |  210  | 
|  191     version_title_ = new views::Label( |  211     version_title_ = new views::Label( | 
|  192         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_VERSION_LABEL)); |  212         l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_VERSION_LABEL)); | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  268     if (installed_time_title_ && installed_time_value_) { |  288     if (installed_time_title_ && installed_time_value_) { | 
|  269       details_stack->AddChildView( |  289       details_stack->AddChildView( | 
|  270           CreateKeyValueField(installed_time_title_, installed_time_value_)); |  290           CreateKeyValueField(installed_time_title_, installed_time_value_)); | 
|  271     } |  291     } | 
|  272  |  292  | 
|  273     if (last_run_time_title_ && last_run_time_value_) { |  293     if (last_run_time_title_ && last_run_time_value_) { | 
|  274       details_stack->AddChildView( |  294       details_stack->AddChildView( | 
|  275           CreateKeyValueField(last_run_time_title_, last_run_time_value_)); |  295           CreateKeyValueField(last_run_time_title_, last_run_time_value_)); | 
|  276     } |  296     } | 
|  277  |  297  | 
 |  298     if (size_title_ && size_value_) { | 
 |  299       details_stack->AddChildView( | 
 |  300           CreateKeyValueField(size_title_, size_value_)); | 
 |  301     } | 
 |  302  | 
|  278     views::View* vertical_stack = CreateVerticalStack(); |  303     views::View* vertical_stack = CreateVerticalStack(); | 
|  279     vertical_stack->AddChildView(details_heading_); |  304     vertical_stack->AddChildView(details_heading_); | 
|  280     vertical_stack->AddChildView(details_stack); |  305     vertical_stack->AddChildView(details_stack); | 
|  281     AddChildView(vertical_stack); |  306     AddChildView(vertical_stack); | 
|  282   } |  307   } | 
|  283 } |  308 } | 
|  284  |  309  | 
|  285 void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) { |  310 void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) { | 
|  286   if (combobox == launch_options_combobox_) { |  311   if (combobox == launch_options_combobox_) { | 
|  287     SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex( |  312     SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex( | 
|  288         launch_options_combobox_->selected_index())); |  313         launch_options_combobox_->selected_index())); | 
|  289   } else { |  314   } else { | 
|  290     NOTREACHED(); |  315     NOTREACHED(); | 
|  291   } |  316   } | 
|  292 } |  317 } | 
|  293  |  318  | 
 |  319 void AppInfoSummaryPanel::StartCalculatingAppSize() { | 
 |  320   base::PostTaskAndReplyWithResult( | 
 |  321       content::BrowserThread::GetBlockingPool(), | 
 |  322       FROM_HERE, | 
 |  323       base::Bind(&base::ComputeDirectorySize, app_->path()), | 
 |  324       base::Bind(&AppInfoSummaryPanel::OnAppSizeCalculated, AsWeakPtr())); | 
 |  325 } | 
 |  326  | 
 |  327 void AppInfoSummaryPanel::OnAppSizeCalculated(int64 app_size_in_bytes) { | 
 |  328   size_value_->SetText(ui::FormatBytes(app_size_in_bytes)); | 
 |  329 } | 
 |  330  | 
|  294 base::Time AppInfoSummaryPanel::GetInstalledTime() const { |  331 base::Time AppInfoSummaryPanel::GetInstalledTime() const { | 
|  295   return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id()); |  332   return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id()); | 
|  296 } |  333 } | 
|  297  |  334  | 
|  298 base::Time AppInfoSummaryPanel::GetLastLaunchedTime() const { |  335 base::Time AppInfoSummaryPanel::GetLastLaunchedTime() const { | 
|  299   return extensions::ExtensionPrefs::Get(profile_) |  336   return extensions::ExtensionPrefs::Get(profile_) | 
|  300       ->GetLastLaunchTime(app_->id()); |  337       ->GetLastLaunchTime(app_->id()); | 
|  301 } |  338 } | 
|  302  |  339  | 
|  303 extensions::LaunchType AppInfoSummaryPanel::GetLaunchType() const { |  340 extensions::LaunchType AppInfoSummaryPanel::GetLaunchType() const { | 
|  304   return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), |  341   return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), | 
|  305                                    app_); |  342                                    app_); | 
|  306 } |  343 } | 
|  307  |  344  | 
|  308 void AppInfoSummaryPanel::SetLaunchType( |  345 void AppInfoSummaryPanel::SetLaunchType( | 
|  309     extensions::LaunchType launch_type) const { |  346     extensions::LaunchType launch_type) const { | 
|  310   DCHECK(CanSetLaunchType()); |  347   DCHECK(CanSetLaunchType()); | 
|  311   ExtensionService* service = |  348   ExtensionService* service = | 
|  312       extensions::ExtensionSystem::Get(profile_)->extension_service(); |  349       extensions::ExtensionSystem::Get(profile_)->extension_service(); | 
|  313   extensions::SetLaunchType(service, app_->id(), launch_type); |  350   extensions::SetLaunchType(service, app_->id(), launch_type); | 
|  314 } |  351 } | 
|  315  |  352  | 
|  316 bool AppInfoSummaryPanel::CanSetLaunchType() const { |  353 bool AppInfoSummaryPanel::CanSetLaunchType() const { | 
|  317   // V2 apps don't have a launch type, and neither does the Chrome app. |  354   // V2 apps don't have a launch type, and neither does the Chrome app. | 
|  318   return app_->id() != extension_misc::kChromeAppId && !app_->is_platform_app(); |  355   return app_->id() != extension_misc::kChromeAppId && !app_->is_platform_app(); | 
|  319 } |  356 } | 
| OLD | NEW |