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
3 // found in the LICENSE file.
5 #include "extensions/common/manifest_handlers/launcher_page_info.h"
7 #include "base/files/file_util.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "extensions/common/manifest.h"
10 #include "extensions/common/manifest_constants.h"
11 #include "grit/extensions_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
14 namespace extensions
{
16 LauncherPageHandler::LauncherPageHandler() {
19 LauncherPageHandler::~LauncherPageHandler() {
23 LauncherPageInfo
* LauncherPageHandler::GetInfo(const Extension
* extension
) {
24 return static_cast<LauncherPageInfo
*>(
25 extension
->GetManifestData(manifest_keys::kLauncherPage
));
28 bool LauncherPageHandler::Parse(Extension
* extension
, base::string16
* error
) {
29 const extensions::Manifest
* manifest
= extension
->manifest();
30 scoped_ptr
<LauncherPageInfo
> launcher_page_info(new LauncherPageInfo
);
31 const base::DictionaryValue
* launcher_page_dict
= NULL
;
32 if (!manifest
->GetDictionary(manifest_keys::kLauncherPage
,
33 &launcher_page_dict
)) {
34 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidLauncherPage
);
38 if (!manifest
->HasPath(extensions::manifest_keys::kLauncherPagePage
)) {
39 *error
= base::ASCIIToUTF16(manifest_errors::kLauncherPagePageRequired
);
43 std::string launcher_page_page
;
44 if (!manifest
->GetString(extensions::manifest_keys::kLauncherPagePage
,
45 &launcher_page_page
)) {
46 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidLauncherPagePage
);
50 launcher_page_info
->page
= launcher_page_page
;
52 extension
->SetManifestData(manifest_keys::kLauncherPage
,
53 launcher_page_info
.release());
57 bool LauncherPageHandler::Validate(
58 const Extension
* extension
,
60 std::vector
<InstallWarning
>* warnings
) const {
61 LauncherPageInfo
* info
= GetInfo(extension
);
62 const base::FilePath path
= extension
->GetResource(info
->page
).GetFilePath();
63 if (!base::PathExists(path
)) {
64 *error
= l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_LAUNCHER_PAGE_FAILED
,
65 base::UTF8ToUTF16(info
->page
));
72 const std::vector
<std::string
> LauncherPageHandler::Keys() const {
73 return SingleKey(manifest_keys::kLauncherPage
);
76 } // namespace extensions