| 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 "content/browser/in_process_webkit/dom_storage_message_filter.h" | 5 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" |
| 6 | 6 |
| 7 #include "base/nullable_string16.h" | 7 #include "base/nullable_string16.h" |
| 8 #include "content/browser/browser_thread.h" | 8 #include "content/browser/browser_thread.h" |
| 9 #include "content/browser/in_process_webkit/dom_storage_area.h" | 9 #include "content/browser/in_process_webkit/dom_storage_area.h" |
| 10 #include "content/browser/in_process_webkit/dom_storage_context.h" | 10 #include "content/browser/in_process_webkit/dom_storage_context.h" |
| 11 #include "content/browser/in_process_webkit/dom_storage_namespace.h" | 11 #include "content/browser/in_process_webkit/dom_storage_namespace.h" |
| 12 #include "content/browser/renderer_host/render_view_host_notification_task.h" | |
| 13 #include "content/common/dom_storage_messages.h" | 12 #include "content/common/dom_storage_messages.h" |
| 14 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 15 | 14 |
| 16 using WebKit::WebStorageArea; | 15 using WebKit::WebStorageArea; |
| 17 | 16 |
| 18 DOMStorageMessageFilter* DOMStorageMessageFilter::storage_event_message_filter = | 17 DOMStorageMessageFilter* DOMStorageMessageFilter::storage_event_message_filter = |
| 19 NULL; | 18 NULL; |
| 20 const GURL* DOMStorageMessageFilter::storage_event_url_ = NULL; | 19 const GURL* DOMStorageMessageFilter::storage_event_url_ = NULL; |
| 21 | 20 |
| 22 DOMStorageMessageFilter:: | 21 DOMStorageMessageFilter:: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 DOMStorageMessageFilter:: | 33 DOMStorageMessageFilter:: |
| 35 ScopedStorageEventContext::~ScopedStorageEventContext() { | 34 ScopedStorageEventContext::~ScopedStorageEventContext() { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 37 DCHECK(storage_event_message_filter); | 36 DCHECK(storage_event_message_filter); |
| 38 DCHECK(storage_event_url_); | 37 DCHECK(storage_event_url_); |
| 39 storage_event_message_filter = NULL; | 38 storage_event_message_filter = NULL; |
| 40 storage_event_url_ = NULL; | 39 storage_event_url_ = NULL; |
| 41 } | 40 } |
| 42 | 41 |
| 43 DOMStorageMessageFilter::DOMStorageMessageFilter( | 42 DOMStorageMessageFilter::DOMStorageMessageFilter( |
| 44 int process_id, WebKitContext* webkit_context, | 43 int process_id, WebKitContext* webkit_context) |
| 45 HostContentSettingsMap* host_content_settings_map) | |
| 46 : webkit_context_(webkit_context), | 44 : webkit_context_(webkit_context), |
| 47 process_id_(process_id), | 45 process_id_(process_id) { |
| 48 host_content_settings_map_(host_content_settings_map) { | |
| 49 } | 46 } |
| 50 | 47 |
| 51 DOMStorageMessageFilter::~DOMStorageMessageFilter() { | 48 DOMStorageMessageFilter::~DOMStorageMessageFilter() { |
| 52 // This is not always true during testing. | 49 // This is not always true during testing. |
| 53 if (peer_handle()) | 50 if (peer_handle()) |
| 54 Context()->UnregisterMessageFilter(this); | 51 Context()->UnregisterMessageFilter(this); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void DOMStorageMessageFilter::OnChannelConnected(int32 peer_pid) { | 54 void DOMStorageMessageFilter::OnChannelConnected(int32 peer_pid) { |
| 58 BrowserMessageFilter::OnChannelConnected(peer_pid); | 55 BrowserMessageFilter::OnChannelConnected(peer_pid); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const string16& origin, | 111 const string16& origin, |
| 115 int64* storage_area_id) { | 112 int64* storage_area_id) { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 117 | 114 |
| 118 DOMStorageNamespace* storage_namespace = | 115 DOMStorageNamespace* storage_namespace = |
| 119 Context()->GetStorageNamespace(namespace_id, true); | 116 Context()->GetStorageNamespace(namespace_id, true); |
| 120 if (!storage_namespace) { | 117 if (!storage_namespace) { |
| 121 *storage_area_id = DOMStorageContext::kInvalidStorageId; | 118 *storage_area_id = DOMStorageContext::kInvalidStorageId; |
| 122 return; | 119 return; |
| 123 } | 120 } |
| 124 DOMStorageArea* storage_area = storage_namespace->GetStorageArea( | 121 DOMStorageArea* storage_area = storage_namespace->GetStorageArea(origin); |
| 125 origin, host_content_settings_map_); | |
| 126 *storage_area_id = storage_area->id(); | 122 *storage_area_id = storage_area->id(); |
| 127 } | 123 } |
| 128 | 124 |
| 129 void DOMStorageMessageFilter::OnLength(int64 storage_area_id, | 125 void DOMStorageMessageFilter::OnLength(int64 storage_area_id, |
| 130 unsigned* length) { | 126 unsigned* length) { |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 132 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 128 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 133 if (!storage_area) { | 129 if (!storage_area) { |
| 134 *length = 0; | 130 *length = 0; |
| 135 } else { | 131 } else { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 168 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 164 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 169 if (!storage_area) { | 165 if (!storage_area) { |
| 170 *old_value = NullableString16(true); | 166 *old_value = NullableString16(true); |
| 171 *result = WebKit::WebStorageArea::ResultOK; | 167 *result = WebKit::WebStorageArea::ResultOK; |
| 172 return; | 168 return; |
| 173 } | 169 } |
| 174 | 170 |
| 175 ScopedStorageEventContext scope(this, &url); | 171 ScopedStorageEventContext scope(this, &url); |
| 176 *old_value = storage_area->SetItem(key, value, result); | 172 *old_value = storage_area->SetItem(key, value, result); |
| 177 | |
| 178 // If content was blocked, tell the UI to display the blocked content icon. | |
| 179 if (render_view_id == MSG_ROUTING_CONTROL) { | |
| 180 DLOG(WARNING) << "setItem was not given a proper routing id"; | |
| 181 } else { | |
| 182 CallRenderViewHostContentSettingsDelegate( | |
| 183 process_id_, render_view_id, | |
| 184 &RenderViewHostDelegate::ContentSettings::OnLocalStorageAccessed, | |
| 185 url, storage_area->owner()->dom_storage_type(), | |
| 186 *result == WebStorageArea::ResultBlockedByPolicy); | |
| 187 } | |
| 188 } | 173 } |
| 189 | 174 |
| 190 void DOMStorageMessageFilter::OnRemoveItem( | 175 void DOMStorageMessageFilter::OnRemoveItem( |
| 191 int64 storage_area_id, const string16& key, const GURL& url, | 176 int64 storage_area_id, const string16& key, const GURL& url, |
| 192 NullableString16* old_value) { | 177 NullableString16* old_value) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 194 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 179 DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 195 if (!storage_area) { | 180 if (!storage_area) { |
| 196 *old_value = NullableString16(true); | 181 *old_value = NullableString16(true); |
| 197 return; | 182 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 220 const DOMStorageContext::MessageFilterSet* set = | 205 const DOMStorageContext::MessageFilterSet* set = |
| 221 Context()->GetMessageFilterSet(); | 206 Context()->GetMessageFilterSet(); |
| 222 DOMStorageContext::MessageFilterSet::const_iterator cur = set->begin(); | 207 DOMStorageContext::MessageFilterSet::const_iterator cur = set->begin(); |
| 223 while (cur != set->end()) { | 208 while (cur != set->end()) { |
| 224 // The renderer that generates the event handles it itself. | 209 // The renderer that generates the event handles it itself. |
| 225 if (*cur != this) | 210 if (*cur != this) |
| 226 (*cur)->Send(new DOMStorageMsg_Event(params)); | 211 (*cur)->Send(new DOMStorageMsg_Event(params)); |
| 227 ++cur; | 212 ++cur; |
| 228 } | 213 } |
| 229 } | 214 } |
| OLD | NEW |