OLD | NEW |
---|---|
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 const String& aString = a.getString(); | 53 const String& aString = a.getString(); |
54 const String& bString = b.getString(); | 54 const String& bString = b.getString(); |
55 for (int i = 0; i < aLength; ++i) { | 55 for (int i = 0; i < aLength; ++i) { |
56 if (aString[i] != bString[i]) | 56 if (aString[i] != bString[i]) |
57 return false; | 57 return false; |
58 } | 58 } |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 bool equalIgnoringQueryAndFragment(const KURL& a, const KURL& b) | |
63 { | |
64 int aLength = a.getString().length(); | |
65 if (a.parsed().ref.len >= 0) | |
66 aLength = a.parsed().ref.begin - 1; | |
67 if (a.parsed().query.len >= 0 && a.parsed().query.begin <= aLength) | |
68 aLength = a.parsed().query.begin - 1; | |
69 | |
70 int bLength = b.getString().length(); | |
71 if (b.parsed().ref.len >= 0) | |
72 bLength = b.parsed().ref.begin - 1; | |
73 if (b.parsed().query.len >= 0 && b.parsed().query.begin <= bLength) | |
74 bLength = b.parsed().query.begin - 1; | |
75 | |
76 if (aLength != bLength) | |
77 return false; | |
78 | |
79 const String& aString = a.getString(); | |
80 const String& bString = b.getString(); | |
81 for (int i = 0; i < aLength; ++i) { | |
82 if (aString[i] != bString[i]) | |
83 return false; | |
84 } | |
85 return true; | |
86 } | |
Mike West
2016/06/14 08:44:59
You can write this more simply by copy/pasting `eq
| |
87 | |
62 } // namespace | 88 } // namespace |
63 | 89 |
64 History::History(LocalFrame* frame) | 90 History::History(LocalFrame* frame) |
65 : DOMWindowProperty(frame) | 91 : DOMWindowProperty(frame) |
66 , m_lastStateObjectRequested(nullptr) | 92 , m_lastStateObjectRequested(nullptr) |
67 { | 93 { |
68 } | 94 } |
69 | 95 |
70 DEFINE_TRACE(History) | 96 DEFINE_TRACE(History) |
71 { | 97 { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 if (!url.isValid()) | 215 if (!url.isValid()) |
190 return false; | 216 return false; |
191 | 217 |
192 if (documentOrigin->isGrantedUniversalAccess()) | 218 if (documentOrigin->isGrantedUniversalAccess()) |
193 return true; | 219 return true; |
194 | 220 |
195 // We allow sandboxed documents, `data:`/`file:` URLs, etc. to use | 221 // We allow sandboxed documents, `data:`/`file:` URLs, etc. to use |
196 // 'pushState'/'replaceState' to modify the URL fragment: see | 222 // 'pushState'/'replaceState' to modify the URL fragment: see |
197 // https://crbug.com/528681 for the compatibility concerns. | 223 // https://crbug.com/528681 for the compatibility concerns. |
198 if (documentOrigin->isUnique() || documentOrigin->isLocal()) | 224 if (documentOrigin->isUnique() || documentOrigin->isLocal()) |
199 return equalIgnoringFragmentIdentifier(url, documentURL); | 225 return equalIgnoringQueryAndFragment(url, documentURL); |
200 | 226 |
201 if (!equalIgnoringPathQueryAndFragment(url, documentURL)) | 227 if (!equalIgnoringPathQueryAndFragment(url, documentURL)) |
202 return false; | 228 return false; |
203 | 229 |
204 RefPtr<SecurityOrigin> requestedOrigin = SecurityOrigin::create(url); | 230 RefPtr<SecurityOrigin> requestedOrigin = SecurityOrigin::create(url); |
205 if (requestedOrigin->isUnique() || !requestedOrigin->isSameSchemeHostPort(do cumentOrigin)) | 231 if (requestedOrigin->isUnique() || !requestedOrigin->isSameSchemeHostPort(do cumentOrigin)) |
206 return false; | 232 return false; |
207 | 233 |
208 return true; | 234 return true; |
209 } | 235 } |
210 | 236 |
211 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat ionType, FrameLoadType type, ExceptionState& exceptionState) | 237 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat ionType, FrameLoadType type, ExceptionState& exceptionState) |
212 { | 238 { |
213 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) | 239 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) |
214 return; | 240 return; |
215 | 241 |
216 KURL fullURL = urlForState(urlString); | 242 KURL fullURL = urlForState(urlString); |
217 if (!canChangeToUrl(fullURL, m_frame->document()->getSecurityOrigin(), m_fra me->document()->url())) { | 243 if (!canChangeToUrl(fullURL, m_frame->document()->getSecurityOrigin(), m_fra me->document()->url())) { |
218 // 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. | 244 // 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. |
219 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() + "'."); | 245 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() + "'."); |
220 return; | 246 return; |
221 } | 247 } |
222 | 248 |
223 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, data, restorationType, type, m_frame->document()); | 249 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, data, restorationType, type, m_frame->document()); |
224 } | 250 } |
225 | 251 |
226 } // namespace blink | 252 } // namespace blink |
OLD | NEW |