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