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