blob: 5ed1a5e416879dc33eb3c71f30a6ea3a2693bf50 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (c) 2009 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/browser/extensions/external_pref_extension_provider.h"
#include "base/file_path.h"
#include "base/string_util.h"
#include "base/version.h"
// Constants for keeping track of extension preferences.
const wchar_t kLocation[] = L"location";
const wchar_t kState[] = L"state";
const wchar_t kExternalCrx[] = L"external_crx";
const wchar_t kExternalVersion[] = L"external_version";
ExternalPrefExtensionProvider::ExternalPrefExtensionProvider(
DictionaryValue* prefs) {
DCHECK(prefs);
prefs_.reset(prefs);
}
ExternalPrefExtensionProvider::~ExternalPrefExtensionProvider() {
}
void ExternalPrefExtensionProvider::VisitRegisteredExtension(
Visitor* visitor, const std::set<std::string>& ids_to_ignore) const {
for (DictionaryValue::key_iterator i = prefs_->begin_keys();
i != prefs_->end_keys(); ++i) {
const std::wstring& extension_id = *i;
if (ids_to_ignore.find(WideToASCII(extension_id)) != ids_to_ignore.end())
continue;
DictionaryValue* extension = NULL;
if (!prefs_->GetDictionary(extension_id, &extension)) {
continue;
}
int location;
if (extension->GetInteger(kLocation, &location) &&
location != Extension::EXTERNAL_PREF) {
continue;
}
int state;
if (extension->GetInteger(kState, &state) &&
state == Extension::KILLBIT) {
continue;
}
FilePath::StringType external_crx;
std::string external_version;
if (!extension->GetString(kExternalCrx, &external_crx) ||
!extension->GetString(kExternalVersion, &external_version)) {
LOG(WARNING) << "Malformed extension dictionary for extension: "
<< extension_id.c_str();
continue;
}
scoped_ptr<Version> version;
version.reset(Version::GetVersionFromString(external_version));
visitor->OnExternalExtensionFound(
WideToASCII(extension_id), version.get(), FilePath(external_crx));
}
}
Version* ExternalPrefExtensionProvider::RegisteredVersion(
std::string id, Extension::Location* location) const {
DictionaryValue* extension = NULL;
if (!prefs_->GetDictionary(ASCIIToWide(id), &extension))
return NULL;
std::string external_version;
if (!extension->GetString(kExternalVersion, &external_version))
return NULL;
if (location)
*location = Extension::EXTERNAL_PREF;
return Version::GetVersionFromString(external_version);
}
|