blob: ece5388b51c023dcaaa441a7cf0282c1c273a5e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (c) 2012 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/common/extensions/api/omnibox/omnibox_handler.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/extensions/api/commands/commands_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
namespace extensions {
namespace {
// Manifest keys.
const char kKeyword[] = "keyword";
} // namespace
// static
const std::string& OmniboxInfo::GetKeyword(const Extension* extension) {
OmniboxInfo* info = static_cast<OmniboxInfo*>(
extension->GetManifestData(extension_manifest_keys::kOmnibox));
return info ? info->keyword : EmptyString();
}
// static
bool OmniboxInfo::IsVerboseInstallMessage(const Extension* extension) {
return !GetKeyword(extension).empty() ||
extension->browser_action_info() ||
(extension->page_action_info() &&
(CommandsInfo::GetPageActionCommand(extension) ||
!extension->page_action_info()->default_icon.empty()));
}
OmniboxHandler::OmniboxHandler() {
}
OmniboxHandler::~OmniboxHandler() {
}
bool OmniboxHandler::Parse(const base::Value* value,
Extension* extension,
string16* error) {
scoped_ptr<OmniboxInfo> info(new OmniboxInfo);
const DictionaryValue* dict = NULL;
if (!value->GetAsDictionary(&dict) ||
!dict->GetString(kKeyword, &info->keyword) ||
info->keyword.empty()) {
*error = ASCIIToUTF16(extension_manifest_errors::kInvalidOmniboxKeyword);
return false;
}
extension->SetManifestData(extension_manifest_keys::kOmnibox, info.release());
return true;
}
} // namespace extensions
|