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/api/commands/commands_handler.h" | |
12 #include "chrome/common/extensions/api/extension_action/action_info.h" | |
13 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
15 #include "chrome/common/extensions/manifest.h" | 13 #include "chrome/common/extensions/manifest.h" |
16 | 14 |
17 namespace extensions { | 15 namespace extensions { |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 // Manifest keys. | 19 // Manifest keys. |
22 const char kKeyword[] = "keyword"; | 20 const char kKeyword[] = "keyword"; |
23 | 21 |
24 } // namespace | 22 } // namespace |
25 | 23 |
26 // static | 24 // static |
27 const std::string& OmniboxInfo::GetKeyword(const Extension* extension) { | 25 const std::string& OmniboxInfo::GetKeyword(const Extension* extension) { |
28 OmniboxInfo* info = static_cast<OmniboxInfo*>( | 26 OmniboxInfo* info = static_cast<OmniboxInfo*>( |
29 extension->GetManifestData(extension_manifest_keys::kOmnibox)); | 27 extension->GetManifestData(extension_manifest_keys::kOmnibox)); |
30 return info ? info->keyword : EmptyString(); | 28 return info ? info->keyword : EmptyString(); |
31 } | 29 } |
32 | 30 |
33 // static | |
34 bool OmniboxInfo::IsVerboseInstallMessage(const Extension* extension) { | |
35 return !GetKeyword(extension).empty() || | |
36 ActionInfo::GetBrowserActionInfo(extension) || | |
37 (extension->page_action_info() && | |
38 (CommandsInfo::GetPageActionCommand(extension) || | |
39 !extension->page_action_info()->default_icon.empty())); | |
40 } | |
41 | |
42 OmniboxHandler::OmniboxHandler() { | 31 OmniboxHandler::OmniboxHandler() { |
43 } | 32 } |
44 | 33 |
45 OmniboxHandler::~OmniboxHandler() { | 34 OmniboxHandler::~OmniboxHandler() { |
46 } | 35 } |
47 | 36 |
48 bool OmniboxHandler::Parse(Extension* extension, string16* error) { | 37 bool OmniboxHandler::Parse(Extension* extension, string16* error) { |
49 scoped_ptr<OmniboxInfo> info(new OmniboxInfo); | 38 scoped_ptr<OmniboxInfo> info(new OmniboxInfo); |
50 const DictionaryValue* dict = NULL; | 39 const DictionaryValue* dict = NULL; |
51 if (!extension->manifest()->GetDictionary(extension_manifest_keys::kOmnibox, | 40 if (!extension->manifest()->GetDictionary(extension_manifest_keys::kOmnibox, |
52 &dict) || | 41 &dict) || |
53 !dict->GetString(kKeyword, &info->keyword) || | 42 !dict->GetString(kKeyword, &info->keyword) || |
54 info->keyword.empty()) { | 43 info->keyword.empty()) { |
55 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidOmniboxKeyword); | 44 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidOmniboxKeyword); |
56 return false; | 45 return false; |
57 } | 46 } |
58 extension->SetManifestData(extension_manifest_keys::kOmnibox, info.release()); | 47 extension->SetManifestData(extension_manifest_keys::kOmnibox, info.release()); |
59 return true; | 48 return true; |
60 } | 49 } |
61 | 50 |
62 } // namespace extensions | 51 } // namespace extensions |
OLD | NEW |