blob: 7e5be2c366f197d7a2f9fad9a4fbbb02d0bfe84f (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright (c) 2010 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_frame/policy_settings.h"
#include "base/logging.h"
#include "base/registry.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/policy_constants.h"
#include "chrome_frame/utils.h"
PolicySettings::RendererForUrl PolicySettings::GetRendererForUrl(
const wchar_t* url) {
RendererForUrl renderer = default_renderer_;
std::vector<std::wstring>::const_iterator it;
for (it = renderer_exclusion_list_.begin();
it != renderer_exclusion_list_.end(); ++it) {
if (MatchPattern(url, (*it))) {
renderer = (renderer == RENDER_IN_HOST) ?
RENDER_IN_CHROME_FRAME : RENDER_IN_HOST;
break;
}
}
return renderer;
}
PolicySettings::RendererForUrl PolicySettings::GetRendererForContentType(
const wchar_t* content_type) {
DCHECK(content_type);
RendererForUrl renderer = RENDERER_NOT_SPECIFIED;
std::vector<std::wstring>::const_iterator it;
for (it = content_type_list_.begin();
it != content_type_list_.end(); ++it) {
if (lstrcmpiW(content_type, (*it).c_str()) == 0) {
renderer = RENDER_IN_CHROME_FRAME;
break;
}
}
return renderer;
}
void PolicySettings::RefreshFromRegistry() {
default_renderer_ = RENDERER_NOT_SPECIFIED;
renderer_exclusion_list_.clear();
RegKey config_key;
DWORD value = RENDERER_NOT_SPECIFIED;
HKEY root_key[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
std::wstring settings_value(
ASCIIToWide(policy::key::kChromeFrameRendererSettings));
for (int i = 0; i < arraysize(root_key); ++i) {
if (config_key.Open(root_key[i], policy::kRegistrySubKey, KEY_READ) &&
config_key.ReadValueDW(settings_value.c_str(), &value)) {
break;
} else {
config_key.Close();
}
}
DCHECK(value == RENDERER_NOT_SPECIFIED ||
value == RENDER_IN_HOST ||
value == RENDER_IN_CHROME_FRAME) <<
"invalid default renderer setting: " << value;
if (value != RENDER_IN_HOST && value != RENDER_IN_CHROME_FRAME) {
DLOG(INFO) << "default renderer not specified via policy";
} else {
default_renderer_ = static_cast<RendererForUrl>(value);
const char* exclusion_list_name = (default_renderer_ == RENDER_IN_HOST) ?
policy::key::kRenderInChromeFrameList :
policy::key::kRenderInHostList;
EnumerateKeyValues(config_key.Handle(),
ASCIIToWide(exclusion_list_name).c_str(), &renderer_exclusion_list_);
DLOG(INFO) << "Default renderer as specified via policy: " <<
default_renderer_ << " exclusion list size: " <<
renderer_exclusion_list_.size();
}
std::wstring sub_key(policy::kRegistrySubKey);
sub_key += L"\\";
sub_key += ASCIIToWide(policy::key::kChromeFrameContentTypes);
for (int i = 0; i < arraysize(root_key) && content_type_list_.size() == 0;
++i) {
EnumerateKeyValues(root_key[i], sub_key.c_str(), &content_type_list_);
}
}
|