OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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/extension_action/browser_action_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/grit/generated_resources.h" | |
11 #include "extensions/common/extension.h" | |
12 #include "extensions/common/feature_switch.h" | |
13 #include "extensions/common/file_util.h" | |
14 #include "extensions/common/manifest.h" | |
15 #include "extensions/common/manifest_constants.h" | |
16 | |
17 namespace extensions { | |
18 | |
19 BrowserActionHandler::BrowserActionHandler() { | |
20 } | |
21 | |
22 BrowserActionHandler::~BrowserActionHandler() { | |
23 } | |
24 | |
25 bool BrowserActionHandler::Parse(Extension* extension, | |
26 base::string16* error) { | |
27 const base::DictionaryValue* dict = NULL; | |
28 if (!extension->manifest()->GetDictionary( | |
29 manifest_keys::kBrowserAction, &dict)) { | |
30 *error = base::ASCIIToUTF16(manifest_errors::kInvalidBrowserAction); | |
31 return false; | |
32 } | |
33 | |
34 scoped_ptr<ActionInfo> action_info = ActionInfo::Load(extension, dict, error); | |
35 if (!action_info.get()) | |
36 return false; // Failed to parse browser action definition. | |
37 | |
38 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); | |
39 | |
40 return true; | |
41 } | |
42 | |
43 bool BrowserActionHandler::Validate( | |
44 const Extension* extension, | |
45 std::string* error, | |
46 std::vector<InstallWarning>* warnings) const { | |
47 const ActionInfo* action = ActionInfo::GetBrowserActionInfo(extension); | |
48 if (action && !action->default_icon.empty() && | |
49 !file_util::ValidateExtensionIconSet( | |
50 action->default_icon, | |
51 extension, | |
52 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, | |
53 error)) { | |
54 return false; | |
55 } | |
56 return true; | |
57 } | |
58 | |
59 const std::vector<std::string> BrowserActionHandler::Keys() const { | |
60 return SingleKey(manifest_keys::kBrowserAction); | |
61 } | |
62 | |
63 } // namespace extensions | |
OLD | NEW |