f3fcdf0a473ba08fcb4ae4a4e8352724bee7c783
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / api / system_indicator / system_indicator_handler.cc
1 // Copyright (c) 2013 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.
4
5 #include "chrome/common/extensions/api/system_indicator/system_indicator_handler.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/common/extensions/api/extension_action/action_info.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/permissions/api_permission_set.h"
14 #include "extensions/common/permissions/permissions_data.h"
15
16 namespace extensions {
17
18 SystemIndicatorHandler::SystemIndicatorHandler() {
19 }
20
21 SystemIndicatorHandler::~SystemIndicatorHandler() {
22 }
23
24 bool SystemIndicatorHandler::Parse(Extension* extension,
25                                    base::string16* error) {
26   const base::DictionaryValue* system_indicator_value = NULL;
27   if (!extension->manifest()->GetDictionary(
28           manifest_keys::kSystemIndicator, &system_indicator_value)) {
29     *error = base::ASCIIToUTF16(manifest_errors::kInvalidSystemIndicator);
30     return false;
31   }
32
33   scoped_ptr<ActionInfo> action_info = ActionInfo::Load(
34       extension, system_indicator_value, error);
35
36   if (!action_info.get())
37     return false;
38
39   // Because the manifest was successfully parsed, auto-grant the permission.
40   // TODO(dewittj) Add this for all extension action APIs.
41   PermissionsData::GetInitialAPIPermissions(extension)->insert(
42       APIPermission::kSystemIndicator);
43
44   ActionInfo::SetSystemIndicatorInfo(extension, action_info.release());
45   return true;
46 }
47
48 const std::vector<std::string> SystemIndicatorHandler::Keys() const {
49   return SingleKey(manifest_keys::kSystemIndicator);
50 }
51
52 }  // namespace extensions