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

Side by Side Diff: third_party/WebKit/Source/modules/storage/DOMWindowStorage.cpp

Issue 2617703003: Remove ContextClient from DOMWindowStorage (Closed)
Patch Set: temp Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/modules/storage/DOMWindowStorage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/storage/DOMWindowStorage.h" 5 #include "modules/storage/DOMWindowStorage.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/FrameHost.h" 8 #include "core/frame/FrameHost.h"
9 #include "core/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "core/frame/Settings.h" 11 #include "core/frame/Settings.h"
12 #include "core/page/Page.h" 12 #include "core/page/Page.h"
13 #include "modules/storage/Storage.h" 13 #include "modules/storage/Storage.h"
14 #include "modules/storage/StorageNamespace.h" 14 #include "modules/storage/StorageNamespace.h"
15 #include "modules/storage/StorageNamespaceController.h" 15 #include "modules/storage/StorageNamespaceController.h"
16 #include "wtf/PassRefPtr.h" 16 #include "wtf/PassRefPtr.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 DOMWindowStorage::DOMWindowStorage(LocalDOMWindow& window) 20 DOMWindowStorage::DOMWindowStorage(LocalDOMWindow& window)
21 : ContextClient(window.frame()), m_window(&window) {} 21 : Supplement<LocalDOMWindow>(window) {}
22 22
23 DEFINE_TRACE(DOMWindowStorage) { 23 DEFINE_TRACE(DOMWindowStorage) {
24 visitor->trace(m_window); 24 visitor->trace(m_window);
25 visitor->trace(m_sessionStorage); 25 visitor->trace(m_sessionStorage);
26 visitor->trace(m_localStorage); 26 visitor->trace(m_localStorage);
27 Supplement<LocalDOMWindow>::trace(visitor); 27 Supplement<LocalDOMWindow>::trace(visitor);
28 ContextClient::trace(visitor);
29 } 28 }
30 29
31 // static 30 // static
32 const char* DOMWindowStorage::supplementName() { 31 const char* DOMWindowStorage::supplementName() {
33 return "DOMWindowStorage"; 32 return "DOMWindowStorage";
34 } 33 }
35 34
36 // static 35 // static
37 DOMWindowStorage& DOMWindowStorage::from(LocalDOMWindow& window) { 36 DOMWindowStorage& DOMWindowStorage::from(LocalDOMWindow& window) {
38 DOMWindowStorage* supplement = static_cast<DOMWindowStorage*>( 37 DOMWindowStorage* supplement = static_cast<DOMWindowStorage*>(
(...skipping 12 matching lines...) Expand all
51 } 50 }
52 51
53 // static 52 // static
54 Storage* DOMWindowStorage::localStorage(DOMWindow& window, 53 Storage* DOMWindowStorage::localStorage(DOMWindow& window,
55 ExceptionState& exceptionState) { 54 ExceptionState& exceptionState) {
56 return from(toLocalDOMWindow(window)).localStorage(exceptionState); 55 return from(toLocalDOMWindow(window)).localStorage(exceptionState);
57 } 56 }
58 57
59 Storage* DOMWindowStorage::sessionStorage( 58 Storage* DOMWindowStorage::sessionStorage(
60 ExceptionState& exceptionState) const { 59 ExceptionState& exceptionState) const {
61 if (!m_window->isCurrentlyDisplayedInFrame()) 60 if (!host()->frame())
haraken 2017/01/06 01:54:40 This is checking if the frame is detached. It can
62 return nullptr; 61 return nullptr;
63 62
64 Document* document = m_window->document(); 63 Document* document = host()->frame()->document();
65 if (!document) 64 DCHECK(document);
66 return nullptr;
67
68 String accessDeniedMessage = "Access is denied for this document."; 65 String accessDeniedMessage = "Access is denied for this document.";
69 if (!document->getSecurityOrigin()->canAccessLocalStorage()) { 66 if (!document->getSecurityOrigin()->canAccessLocalStorage()) {
70 if (document->isSandboxed(SandboxOrigin)) 67 if (document->isSandboxed(SandboxOrigin))
71 exceptionState.throwSecurityError( 68 exceptionState.throwSecurityError(
72 "The document is sandboxed and lacks the 'allow-same-origin' flag."); 69 "The document is sandboxed and lacks the 'allow-same-origin' flag.");
73 else if (document->url().protocolIs("data")) 70 else if (document->url().protocolIs("data"))
74 exceptionState.throwSecurityError( 71 exceptionState.throwSecurityError(
75 "Storage is disabled inside 'data:' URLs."); 72 "Storage is disabled inside 'data:' URLs.");
76 else 73 else
77 exceptionState.throwSecurityError(accessDeniedMessage); 74 exceptionState.throwSecurityError(accessDeniedMessage);
78 return nullptr; 75 return nullptr;
79 } 76 }
80 77
81 if (m_sessionStorage) { 78 if (m_sessionStorage) {
82 if (!m_sessionStorage->area()->canAccessStorage(m_window->frame())) { 79 if (!m_sessionStorage->area()->canAccessStorage(document->frame())) {
83 exceptionState.throwSecurityError(accessDeniedMessage); 80 exceptionState.throwSecurityError(accessDeniedMessage);
84 return nullptr; 81 return nullptr;
85 } 82 }
86 return m_sessionStorage; 83 return m_sessionStorage;
87 } 84 }
88 85
89 Page* page = document->page(); 86 Page* page = document->page();
90 if (!page) 87 if (!page)
91 return nullptr; 88 return nullptr;
92 89
93 StorageArea* storageArea = 90 StorageArea* storageArea =
94 StorageNamespaceController::from(page)->sessionStorage()->storageArea( 91 StorageNamespaceController::from(page)->sessionStorage()->storageArea(
95 document->getSecurityOrigin()); 92 document->getSecurityOrigin());
96 if (!storageArea->canAccessStorage(m_window->frame())) { 93 if (!storageArea->canAccessStorage(document->frame())) {
97 exceptionState.throwSecurityError(accessDeniedMessage); 94 exceptionState.throwSecurityError(accessDeniedMessage);
98 return nullptr; 95 return nullptr;
99 } 96 }
100 97
101 m_sessionStorage = Storage::create(m_window->frame(), storageArea); 98 m_sessionStorage = Storage::create(document->frame(), storageArea);
102 return m_sessionStorage; 99 return m_sessionStorage;
103 } 100 }
104 101
105 Storage* DOMWindowStorage::localStorage(ExceptionState& exceptionState) const { 102 Storage* DOMWindowStorage::localStorage(ExceptionState& exceptionState) const {
106 if (!m_window->isCurrentlyDisplayedInFrame()) 103 if (!host()->frame())
haraken 2017/01/06 01:54:40 Ditto.
107 return nullptr; 104 return nullptr;
108 Document* document = m_window->document(); 105
109 if (!document) 106 Document* document = host()->frame()->document();
110 return nullptr; 107 DCHECK(document);
111 String accessDeniedMessage = "Access is denied for this document."; 108 String accessDeniedMessage = "Access is denied for this document.";
112 if (!document->getSecurityOrigin()->canAccessLocalStorage()) { 109 if (!document->getSecurityOrigin()->canAccessLocalStorage()) {
113 if (document->isSandboxed(SandboxOrigin)) 110 if (document->isSandboxed(SandboxOrigin))
114 exceptionState.throwSecurityError( 111 exceptionState.throwSecurityError(
115 "The document is sandboxed and lacks the 'allow-same-origin' flag."); 112 "The document is sandboxed and lacks the 'allow-same-origin' flag.");
116 else if (document->url().protocolIs("data")) 113 else if (document->url().protocolIs("data"))
117 exceptionState.throwSecurityError( 114 exceptionState.throwSecurityError(
118 "Storage is disabled inside 'data:' URLs."); 115 "Storage is disabled inside 'data:' URLs.");
119 else 116 else
120 exceptionState.throwSecurityError(accessDeniedMessage); 117 exceptionState.throwSecurityError(accessDeniedMessage);
121 return nullptr; 118 return nullptr;
122 } 119 }
123 if (m_localStorage) { 120 if (m_localStorage) {
124 if (!m_localStorage->area()->canAccessStorage(m_window->frame())) { 121 if (!m_localStorage->area()->canAccessStorage(m_window->frame())) {
125 exceptionState.throwSecurityError(accessDeniedMessage); 122 exceptionState.throwSecurityError(accessDeniedMessage);
126 return nullptr; 123 return nullptr;
127 } 124 }
128 return m_localStorage; 125 return m_localStorage;
129 } 126 }
130 // FIXME: Seems this check should be much higher? 127 // FIXME: Seems this check should be much higher?
131 FrameHost* host = document->frameHost(); 128 FrameHost* host = document->frameHost();
132 if (!host || !host->settings().getLocalStorageEnabled()) 129 if (!host || !host->settings().getLocalStorageEnabled())
133 return nullptr; 130 return nullptr;
134 StorageArea* storageArea = 131 StorageArea* storageArea =
135 StorageNamespace::localStorageArea(document->getSecurityOrigin()); 132 StorageNamespace::localStorageArea(document->getSecurityOrigin());
136 if (!storageArea->canAccessStorage(m_window->frame())) { 133 if (!storageArea->canAccessStorage(document->frame())) {
137 exceptionState.throwSecurityError(accessDeniedMessage); 134 exceptionState.throwSecurityError(accessDeniedMessage);
138 return nullptr; 135 return nullptr;
139 } 136 }
140 m_localStorage = Storage::create(m_window->frame(), storageArea); 137 m_localStorage = Storage::create(document->frame(), storageArea);
141 return m_localStorage; 138 return m_localStorage;
142 } 139 }
143 140
144 } // namespace blink 141 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/storage/DOMWindowStorage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698