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