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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2012 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/content_settings/content_settings_platform_app_provider.h"
#include "chrome/browser/content_settings/content_settings_rule.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_pattern.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_set.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
using extensions::UnloadedExtensionInfo;
namespace content_settings {
PlatformAppProvider::PlatformAppProvider(ExtensionService* extension_service)
: registrar_(new content::NotificationRegistrar) {
// Whitelist all extensions loaded so far.
const ExtensionSet* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->plugins().size() > 0)
SetContentSettingForExtension(*it, CONTENT_SETTING_ALLOW);
}
Profile* profile = extension_service->profile();
registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
content::Source<Profile>(profile));
registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(profile));
registrar_->Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile));
}
PlatformAppProvider::~PlatformAppProvider() {
DCHECK(!registrar_.get());
}
RuleIterator* PlatformAppProvider::GetRuleIterator(
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
bool incognito) const {
return value_map_.GetRuleIterator(content_type, resource_identifier, &lock_);
}
bool PlatformAppProvider::SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
Value* value) {
return false;
}
void PlatformAppProvider::ClearAllContentSettingsRules(
ContentSettingsType content_type) {}
void PlatformAppProvider::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: {
const ExtensionHost* host =
content::Details<ExtensionHost>(details).ptr();
if (host->extension()->is_platform_app())
SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
break;
}
case chrome::NOTIFICATION_EXTENSION_LOADED: {
const extensions::Extension* extension =
content::Details<extensions::Extension>(details).ptr();
if (extension->plugins().size() > 0)
SetContentSettingForExtension(extension, CONTENT_SETTING_ALLOW);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
const UnloadedExtensionInfo& info =
*(content::Details<UnloadedExtensionInfo>(details).ptr());
if (info.extension->plugins().size() > 0)
SetContentSettingForExtension(info.extension, CONTENT_SETTING_DEFAULT);
break;
}
default:
NOTREACHED();
}
}
void PlatformAppProvider::ShutdownOnUIThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
RemoveAllObservers();
registrar_.reset();
}
void PlatformAppProvider::SetContentSettingForExtension(
const extensions::Extension* extension,
ContentSetting setting) {
scoped_ptr<ContentSettingsPattern::BuilderInterface> pattern_builder(
ContentSettingsPattern::CreateBuilder(false));
pattern_builder->WithScheme(chrome::kExtensionScheme);
pattern_builder->WithHost(extension->id());
pattern_builder->WithPathWildcard();
ContentSettingsPattern primary_pattern = pattern_builder->Build();
ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard();
{
base::AutoLock lock(lock_);
if (setting == CONTENT_SETTING_DEFAULT) {
value_map_.DeleteValue(primary_pattern,
secondary_pattern,
CONTENT_SETTINGS_TYPE_PLUGINS,
ResourceIdentifier(""));
} else {
value_map_.SetValue(primary_pattern,
secondary_pattern,
CONTENT_SETTINGS_TYPE_PLUGINS,
ResourceIdentifier(""),
Value::CreateIntegerValue(setting));
}
}
NotifyObservers(primary_pattern,
secondary_pattern,
CONTENT_SETTINGS_TYPE_PLUGINS,
ResourceIdentifier(""));
}
} // namespace content_settings
|