#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_tab.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/permission_message_provider.h"
#include "extensions/common/permissions/permission_set.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
class PermissionsScrollView : public views::ScrollView {
public:
PermissionsScrollView(int min_height,
int max_height,
const extensions::Extension* app);
private:
virtual ~PermissionsScrollView();
};
PermissionsScrollView::PermissionsScrollView(int min_height,
int max_height,
const extensions::Extension* app) {
ClipHeightTo(min_height, max_height);
SetVerticalScrollBar(new views::OverlayScrollBar(false));
views::View* inner_scrollable_view = new views::View();
this->SetContents(inner_scrollable_view);
std::vector<base::string16> permission_messages =
extensions::PermissionMessageProvider::Get()->GetWarningMessages(
app->GetActivePermissions(), app->GetType());
views::GridLayout* layout =
views::GridLayout::CreatePanel(inner_scrollable_view);
inner_scrollable_view->SetLayoutManager(layout);
static const int kPermissionBulletsColumnSetId = 1;
views::ColumnSet* permission_bullets_column_set =
layout->AddColumnSet(kPermissionBulletsColumnSetId);
permission_bullets_column_set->AddPaddingColumn(0, 10);
permission_bullets_column_set->AddColumn(views::GridLayout::LEADING,
views::GridLayout::LEADING,
0,
views::GridLayout::USE_PREF,
0,
0);
permission_bullets_column_set->AddPaddingColumn(0, 5);
permission_bullets_column_set->AddColumn(views::GridLayout::LEADING,
views::GridLayout::LEADING,
0,
views::GridLayout::USE_PREF,
0,
0);
for (std::vector<base::string16>::const_iterator it =
permission_messages.begin();
it != permission_messages.end();
++it) {
views::Label* permission_label = new views::Label(*it);
permission_label->SetMultiLine(true);
permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
permission_label->SizeToFit(250);
layout->StartRow(0, kPermissionBulletsColumnSetId);
layout->AddView(new views::Label(l10n_util::GetStringFUTF16(
IDS_EXTENSION_PERMISSION_LINE, base::string16())));
layout->AddView(permission_label);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
}
}
PermissionsScrollView::~PermissionsScrollView() {}
AppInfoPermissionsTab::AppInfoPermissionsTab(
gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app,
const base::Closure& close_callback)
: AppInfoTab(parent_window, profile, app, close_callback) {
views::GridLayout* layout = views::GridLayout::CreatePanel(this);
SetLayoutManager(layout);
static const int kPermissionsColumnSetId = 0;
views::ColumnSet* permissions_column_set =
layout->AddColumnSet(kPermissionsColumnSetId);
permissions_column_set->AddColumn(views::GridLayout::LEADING,
views::GridLayout::LEADING,
0,
views::GridLayout::USE_PREF,
0,
0);
views::Label* required_permissions_heading = new views::Label(
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_CAN_ACCESS));
required_permissions_heading->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->StartRow(0, kPermissionsColumnSetId);
layout->AddView(required_permissions_heading);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, kPermissionsColumnSetId);
layout->AddView(new PermissionsScrollView(0, 100, app));
layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
}
AppInfoPermissionsTab::~AppInfoPermissionsTab() {}