Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: content/browser/in_process_webkit/dom_storage_area.cc

Issue 6915017: Chrome side to allow WebKit layer to use WebPermissionClient to check if access to local storage ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_area.h" 5 #include "content/browser/in_process_webkit/dom_storage_area.h"
6 6
7 #include "base/task.h" 7 #include "base/task.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "content/browser/in_process_webkit/dom_storage_context.h" 8 #include "content/browser/in_process_webkit/dom_storage_context.h"
10 #include "content/browser/in_process_webkit/dom_storage_namespace.h" 9 #include "content/browser/in_process_webkit/dom_storage_namespace.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
15 #include "webkit/glue/webkit_glue.h" 14 #include "webkit/glue/webkit_glue.h"
16 15
17 using WebKit::WebSecurityOrigin; 16 using WebKit::WebSecurityOrigin;
18 using WebKit::WebStorageArea; 17 using WebKit::WebStorageArea;
19 using WebKit::WebString; 18 using WebKit::WebString;
20 using WebKit::WebURL; 19 using WebKit::WebURL;
21 20
22 DOMStorageArea::DOMStorageArea( 21 DOMStorageArea::DOMStorageArea(
23 const string16& origin, 22 const string16& origin,
24 int64 id, 23 int64 id,
25 DOMStorageNamespace* owner, 24 DOMStorageNamespace* owner)
26 HostContentSettingsMap* host_content_settings_map)
27 : origin_(origin), 25 : origin_(origin),
28 origin_url_(origin), 26 origin_url_(origin),
29 id_(id), 27 id_(id),
30 owner_(owner), 28 owner_(owner) {
31 host_content_settings_map_(host_content_settings_map) {
32 DCHECK(owner_); 29 DCHECK(owner_);
33 DCHECK(host_content_settings_map_);
34 } 30 }
35 31
36 DOMStorageArea::~DOMStorageArea() { 32 DOMStorageArea::~DOMStorageArea() {
37 } 33 }
38 34
39 unsigned DOMStorageArea::Length() { 35 unsigned DOMStorageArea::Length() {
40 CreateWebStorageAreaIfNecessary(); 36 CreateWebStorageAreaIfNecessary();
41 return storage_area_->length(); 37 return storage_area_->length();
42 } 38 }
43 39
44 NullableString16 DOMStorageArea::Key(unsigned index) { 40 NullableString16 DOMStorageArea::Key(unsigned index) {
45 CreateWebStorageAreaIfNecessary(); 41 CreateWebStorageAreaIfNecessary();
46 return storage_area_->key(index); 42 return storage_area_->key(index);
47 } 43 }
48 44
49 NullableString16 DOMStorageArea::GetItem(const string16& key) { 45 NullableString16 DOMStorageArea::GetItem(const string16& key) {
50 CreateWebStorageAreaIfNecessary(); 46 CreateWebStorageAreaIfNecessary();
51 return storage_area_->getItem(key); 47 return storage_area_->getItem(key);
52 } 48 }
53 49
54 NullableString16 DOMStorageArea::SetItem( 50 NullableString16 DOMStorageArea::SetItem(
55 const string16& key, const string16& value, 51 const string16& key, const string16& value,
56 WebStorageArea::Result* result) { 52 WebStorageArea::Result* result) {
57 if (!CheckContentSetting(key, value)) {
58 *result = WebStorageArea::ResultBlockedByPolicy;
59 return NullableString16(true); // Ignored if the content was blocked.
60 }
61
62 CreateWebStorageAreaIfNecessary(); 53 CreateWebStorageAreaIfNecessary();
63 WebString old_value; 54 WebString old_value;
64 storage_area_->setItem(key, value, WebURL(), *result, old_value); 55 storage_area_->setItem(key, value, WebURL(), *result, old_value);
65 return old_value; 56 return old_value;
66 } 57 }
67 58
68 NullableString16 DOMStorageArea::RemoveItem(const string16& key) { 59 NullableString16 DOMStorageArea::RemoveItem(const string16& key) {
69 CreateWebStorageAreaIfNecessary(); 60 CreateWebStorageAreaIfNecessary();
70 WebString old_value; 61 WebString old_value;
71 storage_area_->removeItem(key, WebURL(), old_value); 62 storage_area_->removeItem(key, WebURL(), old_value);
72 return old_value; 63 return old_value;
73 } 64 }
74 65
75 bool DOMStorageArea::Clear() { 66 bool DOMStorageArea::Clear() {
76 CreateWebStorageAreaIfNecessary(); 67 CreateWebStorageAreaIfNecessary();
77 bool somethingCleared; 68 bool somethingCleared;
78 storage_area_->clear(WebURL(), somethingCleared); 69 storage_area_->clear(WebURL(), somethingCleared);
79 return somethingCleared; 70 return somethingCleared;
80 } 71 }
81 72
82 void DOMStorageArea::PurgeMemory() { 73 void DOMStorageArea::PurgeMemory() {
83 storage_area_.reset(); 74 storage_area_.reset();
84 } 75 }
85 76
86 void DOMStorageArea::CreateWebStorageAreaIfNecessary() { 77 void DOMStorageArea::CreateWebStorageAreaIfNecessary() {
87 if (!storage_area_.get()) 78 if (!storage_area_.get())
88 storage_area_.reset(owner_->CreateWebStorageArea(origin_)); 79 storage_area_.reset(owner_->CreateWebStorageArea(origin_));
89 } 80 }
90
91 bool DOMStorageArea::CheckContentSetting(
92 const string16& key, const string16& value) {
93 ContentSetting content_setting =
94 host_content_settings_map_->GetContentSetting(
95 origin_url_, CONTENT_SETTINGS_TYPE_COOKIES, "");
96 return (content_setting != CONTENT_SETTING_BLOCK);
97 }
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/dom_storage_area.h ('k') | content/browser/in_process_webkit/dom_storage_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698