OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/content_settings/content_settings_extension_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
6 | 6 |
7 #include "chrome/browser/content_settings/content_settings_details.h" | 7 #include "chrome/browser/content_settings/content_settings_details.h" |
8 #include "chrome/browser/extensions/extension_content_settings_store.h" | 8 #include "chrome/browser/extensions/extension_content_settings_store.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "content/common/notification_details.h" | 10 #include "content/common/notification_details.h" |
11 #include "content/common/notification_service.h" | 11 #include "content/common/notification_service.h" |
12 #include "content/common/notification_source.h" | 12 #include "content/common/notification_source.h" |
13 | 13 |
14 namespace content_settings { | 14 namespace content_settings { |
15 | 15 |
16 ExtensionProvider::ExtensionProvider( | 16 ExtensionProvider::ExtensionProvider( |
17 Profile* profile, | 17 HostContentSettingsMap* map, |
18 ExtensionContentSettingsStore* extensions_settings, | 18 ExtensionContentSettingsStore* extensions_settings, |
19 bool incognito) | 19 bool incognito) |
20 : profile_(profile), | 20 : map_(map), |
21 incognito_(incognito), | 21 incognito_(incognito), |
22 extensions_settings_(extensions_settings) { | 22 extensions_settings_(extensions_settings) { |
23 DCHECK(extensions_settings); | |
24 extensions_settings_->AddObserver(this); | 23 extensions_settings_->AddObserver(this); |
25 } | 24 } |
26 | 25 |
27 ExtensionProvider::~ExtensionProvider() { | 26 ExtensionProvider::~ExtensionProvider() { |
28 if (extensions_settings_) | 27 DCHECK(!map_); |
29 extensions_settings_->RemoveObserver(this); | |
30 } | 28 } |
31 | 29 |
32 ContentSetting ExtensionProvider::GetContentSetting( | 30 ContentSetting ExtensionProvider::GetContentSetting( |
33 const GURL& embedded_url, | 31 const GURL& embedded_url, |
34 const GURL& top_level_url, | 32 const GURL& top_level_url, |
35 ContentSettingsType content_type, | 33 ContentSettingsType content_type, |
36 const ResourceIdentifier& resource_identifier) const { | 34 const ResourceIdentifier& resource_identifier) const { |
37 // TODO(markusheintz): Instead of getting the effective setting every time | 35 // TODO(markusheintz): Instead of getting the effective setting every time |
38 // effective patterns could be cached in here. | 36 // effective patterns could be cached in here. |
39 DCHECK(extensions_settings_); | 37 DCHECK(extensions_settings_); |
40 return extensions_settings_->GetEffectiveContentSetting( | 38 return extensions_settings_->GetEffectiveContentSetting( |
41 embedded_url, | 39 embedded_url, |
42 top_level_url, | 40 top_level_url, |
43 content_type, | 41 content_type, |
44 resource_identifier, | 42 resource_identifier, |
45 incognito_); | 43 incognito_); |
46 } | 44 } |
47 | 45 |
48 void ExtensionProvider::GetAllContentSettingsRules( | 46 void ExtensionProvider::GetAllContentSettingsRules( |
49 ContentSettingsType content_type, | 47 ContentSettingsType content_type, |
50 const ResourceIdentifier& resource_identifier, | 48 const ResourceIdentifier& resource_identifier, |
51 Rules* content_setting_rules) const { | 49 Rules* content_setting_rules) const { |
52 DCHECK(extensions_settings_); | |
53 return extensions_settings_->GetContentSettingsForContentType( | 50 return extensions_settings_->GetContentSettingsForContentType( |
54 content_type, resource_identifier, incognito_, content_setting_rules); | 51 content_type, resource_identifier, incognito_, content_setting_rules); |
55 } | 52 } |
56 | 53 |
54 void ExtensionProvider::ShutdownOnUIThread() { | |
55 extensions_settings_->RemoveObserver(this); | |
56 map_ = NULL; | |
57 } | |
58 | |
57 void ExtensionProvider::NotifyObservers( | 59 void ExtensionProvider::NotifyObservers( |
58 const ContentSettingsDetails& details) { | 60 const ContentSettingsDetails& details) { |
battre
2011/07/06 09:12:05
should we DCHECK on the map_ here?
Bernhard Bauer
2011/07/06 12:06:51
Done.
| |
59 if (profile_ == NULL) | |
60 return; | |
61 NotificationService::current()->Notify( | 61 NotificationService::current()->Notify( |
62 NotificationType::CONTENT_SETTINGS_CHANGED, | 62 NotificationType::CONTENT_SETTINGS_CHANGED, |
63 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 63 Source<HostContentSettingsMap>(map_), |
64 Details<const ContentSettingsDetails>(&details)); | 64 Details<const ContentSettingsDetails>(&details)); |
65 } | 65 } |
66 | 66 |
67 void ExtensionProvider::OnContentSettingChanged( | 67 void ExtensionProvider::OnContentSettingChanged( |
68 const std::string& extension_id, | 68 const std::string& extension_id, |
69 bool incognito) { | 69 bool incognito) { |
70 if (incognito_ != incognito) | 70 if (incognito_ != incognito) |
71 return; | 71 return; |
72 // TODO(markusheintz): Be more concise. | 72 // TODO(markusheintz): Be more concise. |
73 ContentSettingsDetails details(ContentSettingsPattern(), | 73 ContentSettingsDetails details(ContentSettingsPattern(), |
74 ContentSettingsPattern(), | 74 ContentSettingsPattern(), |
75 CONTENT_SETTINGS_TYPE_DEFAULT, | 75 CONTENT_SETTINGS_TYPE_DEFAULT, |
76 std::string()); | 76 std::string()); |
77 NotifyObservers(details); | 77 NotifyObservers(details); |
78 } | 78 } |
79 | 79 |
80 void ExtensionProvider::OnDestruction() { | |
81 DCHECK(extensions_settings_); | |
82 extensions_settings_ = NULL; | |
83 } | |
84 | |
85 } // namespace content_settings | 80 } // namespace content_settings |
OLD | NEW |