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/renderer/content_settings_observer.h" | 5 #include "chrome/renderer/content_settings_observer.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
9 #include "content/common/database_messages.h" | 9 #include "content/common/database_messages.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 ContentSettingsObserver* observer = ContentSettingsObserver::Get(opener); | 137 ContentSettingsObserver* observer = ContentSettingsObserver::Get(opener); |
138 SetContentSettings(observer->current_content_settings_); | 138 SetContentSettings(observer->current_content_settings_); |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 bool ContentSettingsObserver::AllowDatabase(WebFrame* frame, | 143 bool ContentSettingsObserver::AllowDatabase(WebFrame* frame, |
144 const WebString& name, | 144 const WebString& name, |
145 const WebString& display_name, | 145 const WebString& display_name, |
146 unsigned long estimated_size) { | 146 unsigned long estimated_size) { |
147 WebSecurityOrigin origin = frame->securityOrigin(); | 147 if (frame->securityOrigin().isEmpty() || |
148 if (origin.isEmpty()) | 148 frame->top()->securityOrigin().isEmpty()) |
149 return false; // Uninitialized document? | 149 return false; // Uninitialized document. |
150 | 150 |
151 bool result = false; | 151 bool result = false; |
152 Send(new ViewHostMsg_AllowDatabase( | 152 Send(new ViewHostMsg_AllowDatabase( |
153 routing_id(), GURL(origin.toString()), name, display_name, &result)); | 153 routing_id(), GURL(frame->securityOrigin().toString()), |
| 154 GURL(frame->top()->securityOrigin().toString()), |
| 155 name, display_name, &result)); |
154 return result; | 156 return result; |
155 } | 157 } |
156 | 158 |
157 bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) { | 159 bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) { |
158 WebSecurityOrigin origin = frame->securityOrigin(); | 160 if (frame->securityOrigin().isEmpty() || |
159 if (origin.isEmpty()) | 161 frame->top()->securityOrigin().isEmpty()) |
160 return false; // Uninitialized document? | 162 return false; // Uninitialized document. |
161 | 163 |
162 bool result = false; | 164 bool result = false; |
163 Send(new ViewHostMsg_AllowFileSystem( | 165 Send(new ViewHostMsg_AllowFileSystem( |
164 routing_id(), GURL(origin.toString()), &result)); | 166 routing_id(), GURL(frame->securityOrigin().toString()), |
| 167 GURL(frame->top()->securityOrigin().toString()), &result)); |
165 return result; | 168 return result; |
166 } | 169 } |
167 | 170 |
168 bool ContentSettingsObserver::AllowImages(WebFrame* frame, | 171 bool ContentSettingsObserver::AllowImages(WebFrame* frame, |
169 bool enabled_per_settings) { | 172 bool enabled_per_settings) { |
170 if (enabled_per_settings && | 173 if (enabled_per_settings && |
171 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | 174 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { |
172 return true; | 175 return true; |
173 } | 176 } |
174 | 177 |
175 if (IsWhitelistedForContentSettings(frame)) | 178 if (IsWhitelistedForContentSettings(frame)) |
176 return true; | 179 return true; |
177 | 180 |
178 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 181 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
179 return false; // Other protocols fall through here. | 182 return false; // Other protocols fall through here. |
180 } | 183 } |
181 | 184 |
182 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 185 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
183 const WebString& name, | 186 const WebString& name, |
184 const WebSecurityOrigin& origin) { | 187 const WebSecurityOrigin& origin) { |
| 188 if (frame->securityOrigin().isEmpty() || |
| 189 frame->top()->securityOrigin().isEmpty()) |
| 190 return false; // Uninitialized document. |
| 191 |
185 bool result = false; | 192 bool result = false; |
186 Send(new ViewHostMsg_AllowIndexedDB( | 193 Send(new ViewHostMsg_AllowIndexedDB( |
187 routing_id(), origin.databaseIdentifier(), name, &result)); | 194 routing_id(), GURL(frame->securityOrigin().toString()), |
| 195 GURL(frame->top()->securityOrigin().toString()), |
| 196 name, &result)); |
188 return result; | 197 return result; |
189 } | 198 } |
190 | 199 |
191 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, | 200 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, |
192 bool enabled_per_settings) { | 201 bool enabled_per_settings) { |
193 return enabled_per_settings; | 202 return enabled_per_settings; |
194 } | 203 } |
195 | 204 |
196 bool ContentSettingsObserver::AllowScript(WebFrame* frame, | 205 bool ContentSettingsObserver::AllowScript(WebFrame* frame, |
197 bool enabled_per_settings) { | 206 bool enabled_per_settings) { |
198 if (enabled_per_settings && | 207 if (enabled_per_settings && |
199 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { | 208 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { |
200 return true; | 209 return true; |
201 } | 210 } |
202 | 211 |
203 if (IsWhitelistedForContentSettings(frame)) | 212 if (IsWhitelistedForContentSettings(frame)) |
204 return true; | 213 return true; |
205 | 214 |
206 return false; // Other protocols fall through here. | 215 return false; // Other protocols fall through here. |
207 } | 216 } |
208 | 217 |
209 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { | 218 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { |
| 219 if (frame->securityOrigin().isEmpty() || |
| 220 frame->top()->securityOrigin().isEmpty()) |
| 221 return false; // Uninitialized document. |
210 bool result = false; | 222 bool result = false; |
| 223 |
211 Send(new ViewHostMsg_AllowDOMStorage( | 224 Send(new ViewHostMsg_AllowDOMStorage( |
212 routing_id(), frame->url(), | 225 routing_id(), GURL(frame->securityOrigin().toString()), |
| 226 GURL(frame->top()->securityOrigin().toString()), |
213 local ? DOM_STORAGE_LOCAL : DOM_STORAGE_SESSION, | 227 local ? DOM_STORAGE_LOCAL : DOM_STORAGE_SESSION, |
214 &result)); | 228 &result)); |
215 return result; | 229 return result; |
216 } | 230 } |
217 | 231 |
218 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { | 232 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { |
219 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); | 233 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
220 } | 234 } |
221 | 235 |
222 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { | 236 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { |
(...skipping 14 matching lines...) Expand all Loading... |
237 ContentSettingsType settings_type) { | 251 ContentSettingsType settings_type) { |
238 // CONTENT_SETTING_ASK is only valid for cookies. | 252 // CONTENT_SETTING_ASK is only valid for cookies. |
239 return current_content_settings_.settings[settings_type] != | 253 return current_content_settings_.settings[settings_type] != |
240 CONTENT_SETTING_BLOCK; | 254 CONTENT_SETTING_BLOCK; |
241 } | 255 } |
242 | 256 |
243 void ContentSettingsObserver::ClearBlockedContentSettings() { | 257 void ContentSettingsObserver::ClearBlockedContentSettings() { |
244 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 258 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
245 content_blocked_[i] = false; | 259 content_blocked_[i] = false; |
246 } | 260 } |
OLD | NEW |