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

Side by Side Diff: third_party/WebKit/Source/core/frame/History.cpp

Issue 2375873003: Make DOMWindowProperty::m_frame private (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 { 61 {
62 } 62 }
63 63
64 DEFINE_TRACE(History) 64 DEFINE_TRACE(History)
65 { 65 {
66 DOMWindowProperty::trace(visitor); 66 DOMWindowProperty::trace(visitor);
67 } 67 }
68 68
69 unsigned History::length() const 69 unsigned History::length() const
70 { 70 {
71 if (!m_frame || !m_frame->loader().client()) 71 if (!frame() || !frame()->loader().client())
72 return 0; 72 return 0;
73 return m_frame->loader().client()->backForwardLength(); 73 return frame()->loader().client()->backForwardLength();
74 } 74 }
75 75
76 SerializedScriptValue* History::state() 76 SerializedScriptValue* History::state()
77 { 77 {
78 m_lastStateObjectRequested = stateInternal(); 78 m_lastStateObjectRequested = stateInternal();
79 return m_lastStateObjectRequested.get(); 79 return m_lastStateObjectRequested.get();
80 } 80 }
81 81
82 SerializedScriptValue* History::stateInternal() const 82 SerializedScriptValue* History::stateInternal() const
83 { 83 {
84 if (!m_frame) 84 if (!frame())
85 return 0; 85 return 0;
86 86
87 if (HistoryItem* historyItem = m_frame->loader().currentItem()) 87 if (HistoryItem* historyItem = frame()->loader().currentItem())
88 return historyItem->stateObject(); 88 return historyItem->stateObject();
89 89
90 return 0; 90 return 0;
91 } 91 }
92 92
93 void History::setScrollRestoration(const String& value) 93 void History::setScrollRestoration(const String& value)
94 { 94 {
95 ASSERT(value == "manual" || value == "auto"); 95 ASSERT(value == "manual" || value == "auto");
96 if (!m_frame || !m_frame->loader().client()) 96 if (!frame() || !frame()->loader().client())
97 return; 97 return;
98 98
99 HistoryScrollRestorationType scrollRestoration = value == "manual" ? ScrollR estorationManual : ScrollRestorationAuto; 99 HistoryScrollRestorationType scrollRestoration = value == "manual" ? ScrollR estorationManual : ScrollRestorationAuto;
100 if (scrollRestoration == scrollRestorationInternal()) 100 if (scrollRestoration == scrollRestorationInternal())
101 return; 101 return;
102 102
103 if (HistoryItem* historyItem = m_frame->loader().currentItem()) { 103 if (HistoryItem* historyItem = frame()->loader().currentItem()) {
104 historyItem->setScrollRestorationType(scrollRestoration); 104 historyItem->setScrollRestorationType(scrollRestoration);
105 m_frame->loader().client()->didUpdateCurrentHistoryItem(); 105 frame()->loader().client()->didUpdateCurrentHistoryItem();
106 } 106 }
107 } 107 }
108 108
109 String History::scrollRestoration() 109 String History::scrollRestoration()
110 { 110 {
111 return scrollRestorationInternal() == ScrollRestorationManual ? "manual" : " auto"; 111 return scrollRestorationInternal() == ScrollRestorationManual ? "manual" : " auto";
112 } 112 }
113 113
114 HistoryScrollRestorationType History::scrollRestorationInternal() const 114 HistoryScrollRestorationType History::scrollRestorationInternal() const
115 { 115 {
116 if (m_frame) { 116 if (frame()) {
117 if (HistoryItem* historyItem = m_frame->loader().currentItem()) 117 if (HistoryItem* historyItem = frame()->loader().currentItem())
118 return historyItem->scrollRestorationType(); 118 return historyItem->scrollRestorationType();
119 } 119 }
120 120
121 return ScrollRestorationAuto; 121 return ScrollRestorationAuto;
122 } 122 }
123 123
124 bool History::stateChanged() const 124 bool History::stateChanged() const
125 { 125 {
126 return m_lastStateObjectRequested != stateInternal(); 126 return m_lastStateObjectRequested != stateInternal();
127 } 127 }
128 128
129 bool History::isSameAsCurrentState(SerializedScriptValue* state) const 129 bool History::isSameAsCurrentState(SerializedScriptValue* state) const
130 { 130 {
131 return state == stateInternal(); 131 return state == stateInternal();
132 } 132 }
133 133
134 void History::back(ExecutionContext* context) 134 void History::back(ExecutionContext* context)
135 { 135 {
136 go(context, -1); 136 go(context, -1);
137 } 137 }
138 138
139 void History::forward(ExecutionContext* context) 139 void History::forward(ExecutionContext* context)
140 { 140 {
141 go(context, 1); 141 go(context, 1);
142 } 142 }
143 143
144 void History::go(ExecutionContext* context, int delta) 144 void History::go(ExecutionContext* context, int delta)
145 { 145 {
146 if (!m_frame || !m_frame->loader().client()) 146 if (!frame() || !frame()->loader().client())
147 return; 147 return;
148 148
149 ASSERT(isMainThread()); 149 ASSERT(isMainThread());
150 Document* activeDocument = toDocument(context); 150 Document* activeDocument = toDocument(context);
151 if (!activeDocument) 151 if (!activeDocument)
152 return; 152 return;
153 153
154 if (!activeDocument->frame() || !activeDocument->frame()->canNavigate(*m_fra me)) 154 if (!activeDocument->frame() || !activeDocument->frame()->canNavigate(*frame ()))
155 return; 155 return;
156 if (!NavigationDisablerForUnload::isNavigationAllowed()) 156 if (!NavigationDisablerForUnload::isNavigationAllowed())
157 return; 157 return;
158 158
159 // We intentionally call reload() for the current frame if delta is zero. 159 // We intentionally call reload() for the current frame if delta is zero.
160 // Otherwise, navigation happens on the root frame. 160 // Otherwise, navigation happens on the root frame.
161 // This behavior is designed in the following spec. 161 // This behavior is designed in the following spec.
162 // https://html.spec.whatwg.org/multipage/browsers.html#dom-history-go 162 // https://html.spec.whatwg.org/multipage/browsers.html#dom-history-go
163 if (delta) 163 if (delta)
164 m_frame->loader().client()->navigateBackForward(delta); 164 frame()->loader().client()->navigateBackForward(delta);
165 else 165 else
166 m_frame->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirec t); 166 frame()->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirec t);
167 } 167 }
168 168
169 KURL History::urlForState(const String& urlString) 169 KURL History::urlForState(const String& urlString)
170 { 170 {
171 Document* document = m_frame->document(); 171 Document* document = frame()->document();
172 172
173 if (urlString.isNull()) 173 if (urlString.isNull())
174 return document->url(); 174 return document->url();
175 if (urlString.isEmpty()) 175 if (urlString.isEmpty())
176 return document->baseURL(); 176 return document->baseURL();
177 177
178 return KURL(document->baseURL(), urlString); 178 return KURL(document->baseURL(), urlString);
179 } 179 }
180 180
181 bool History::canChangeToUrl(const KURL& url, SecurityOrigin* documentOrigin, co nst KURL& documentURL) 181 bool History::canChangeToUrl(const KURL& url, SecurityOrigin* documentOrigin, co nst KURL& documentURL)
(...skipping 15 matching lines...) Expand all
197 197
198 RefPtr<SecurityOrigin> requestedOrigin = SecurityOrigin::create(url); 198 RefPtr<SecurityOrigin> requestedOrigin = SecurityOrigin::create(url);
199 if (requestedOrigin->isUnique() || !requestedOrigin->isSameSchemeHostPort(do cumentOrigin)) 199 if (requestedOrigin->isUnique() || !requestedOrigin->isSameSchemeHostPort(do cumentOrigin))
200 return false; 200 return false;
201 201
202 return true; 202 return true;
203 } 203 }
204 204
205 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat ionType, FrameLoadType type, ExceptionState& exceptionState) 205 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat ionType, FrameLoadType type, ExceptionState& exceptionState)
206 { 206 {
207 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) 207 if (!frame() || !frame()->page() || !frame()->loader().documentLoader())
208 return; 208 return;
209 209
210 KURL fullURL = urlForState(urlString); 210 KURL fullURL = urlForState(urlString);
211 if (!canChangeToUrl(fullURL, m_frame->document()->getSecurityOrigin(), m_fra me->document()->url())) { 211 if (!canChangeToUrl(fullURL, frame()->document()->getSecurityOrigin(), frame ()->document()->url())) {
212 // We can safely expose the URL to JavaScript, as a) no redirection take s place: JavaScript already had this URL, b) JavaScript can only access a same-o rigin History object. 212 // We can safely expose the URL to JavaScript, as a) no redirection take s place: JavaScript already had this URL, b) JavaScript can only access a same-o rigin History object.
213 exceptionState.throwSecurityError("A history state object with URL '" + fullURL.elidedString() + "' cannot be created in a document with origin '" + m_f rame->document()->getSecurityOrigin()->toString() + "' and URL '" + m_frame->doc ument()->url().elidedString() + "'."); 213 exceptionState.throwSecurityError("A history state object with URL '" + fullURL.elidedString() + "' cannot be created in a document with origin '" + fra me()->document()->getSecurityOrigin()->toString() + "' and URL '" + frame()->doc ument()->url().elidedString() + "'.");
214 return; 214 return;
215 } 215 }
216 216
217 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, std::move(data), restorationType, type, m_frame->document()); 217 frame()->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, std::move(data), restorationType, type, frame()->document());
218 } 218 }
219 219
220 } // namespace blink 220 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/DOMWindowProperty.h ('k') | third_party/WebKit/Source/core/frame/Navigator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698