Chromium Code Reviews| Index: chrome/browser/ui/views/apps/app_info_dialog/arc_app_info_links_panel.cc |
| diff --git a/chrome/browser/ui/views/apps/app_info_dialog/arc_app_info_links_panel.cc b/chrome/browser/ui/views/apps/app_info_dialog/arc_app_info_links_panel.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..08fd77fa2176e644dbfd39d1d17ae52401d0caba |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/apps/app_info_dialog/arc_app_info_links_panel.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/apps/app_info_dialog/arc_app_info_links_panel.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/arc/common/app.mojom.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/views/controls/link.h" |
| +#include "ui/views/layout/box_layout.h" |
| +#include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/view.h" |
| + |
| +namespace { |
| +constexpr char kArcChromePackageName[] = "org.chromium.arc.intent_helper"; |
| +} |
| + |
| +ArcAppInfoLinksPanel::ArcAppInfoLinksPanel(Profile* profile, |
| + const extensions::Extension* app) |
| + : AppInfoPanel(profile, app), manage_link_(nullptr) { |
| + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| + views::kRelatedControlVerticalSpacing)); |
| + manage_link_ = new views::Link( |
| + l10n_util::GetStringUTF16(IDS_ARC_APPLICATION_INFO_MANAGE_LINK)); |
| + manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + manage_link_->set_listener(this); |
| + AddChildView(manage_link_); |
| + |
| + ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(profile_); |
| + DCHECK(arc_prefs); |
| + arc_prefs->AddObserver(this); |
|
Peter Kasting
2016/06/23 07:07:20
Nit: If this is going to be the same pointer as in
mtomasz
2016/06/23 08:51:56
Done.
|
| + |
| + std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| + ArcAppListPrefs::Get(profile)->GetApp(arc::kSettingsAppId); |
| + if (app_info) |
| + UpdateLink(app_info->ready); |
| +} |
| + |
| +ArcAppInfoLinksPanel::~ArcAppInfoLinksPanel() { |
| + ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); |
| + DCHECK(arc_prefs); |
| + arc_prefs->RemoveObserver(this); |
| +} |
| + |
| +void ArcAppInfoLinksPanel::LinkClicked(views::Link* source, int event_flags) { |
| + if (source == manage_link_) { |
| + if (arc::ShowPackageInfoOnPage( |
| + kArcChromePackageName, |
| + arc::mojom::ShowPackageInfoPage::MANAGE_LINKS)) { |
| + Close(); |
| + } |
| + } else { |
| + NOTREACHED(); |
|
Peter Kasting
2016/06/23 07:07:20
Don't put this in an else, as this is effectively
mtomasz
2016/06/23 08:51:56
Done.
|
| + } |
| +} |
| + |
| +void ArcAppInfoLinksPanel::OnAppReadyChanged(const std::string& app_id, |
| + bool ready) { |
| + if (app_id == arc::kSettingsAppId) |
| + UpdateLink(ready); |
| +} |
| + |
| +void ArcAppInfoLinksPanel::OnAppRemoved(const std::string& app_id) { |
| + if (app_id == arc::kSettingsAppId) |
| + UpdateLink(false); |
| +} |
| + |
| +void ArcAppInfoLinksPanel::OnAppRegistered( |
| + const std::string& app_id, |
| + const ArcAppListPrefs::AppInfo& app_info) { |
| + if (app_id == arc::kSettingsAppId) |
| + UpdateLink(app_info.ready); |
| +} |
| + |
| +void ArcAppInfoLinksPanel::UpdateLink(bool enabled) { |
| + manage_link_->SetEnabled(enabled); |
| +} |