OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2010 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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/frame/LocalDOMWindow.h" | 37 #include "core/frame/LocalDOMWindow.h" |
38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
39 #include "core/loader/FrameLoader.h" | 39 #include "core/loader/FrameLoader.h" |
40 #include "platform/weborigin/KURL.h" | 40 #include "platform/weborigin/KURL.h" |
41 #include "platform/weborigin/SecurityOrigin.h" | 41 #include "platform/weborigin/SecurityOrigin.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 Location::Location(LocalFrame* frame) | 45 Location::Location(Frame* frame) |
46 : DOMWindowProperty(frame) | 46 : m_frame(frame) |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 void Location::trace(Visitor* visitor) | 50 void Location::trace(Visitor* visitor) |
51 { | 51 { |
52 DOMWindowProperty::trace(visitor); | 52 visitor->trace(m_frame); |
53 } | 53 } |
54 | 54 |
55 inline const KURL& Location::url() const | 55 inline const KURL& Location::url() const |
56 { | 56 { |
57 ASSERT(m_frame); | 57 ASSERT(m_frame && m_frame->isLocalFrame()); |
haraken
2015/02/03 00:56:09
This ASSERT would be redundant, since toLocalFrame
Nate Chapin
2015/02/03 19:17:21
Done.
| |
58 | 58 |
59 const KURL& url = m_frame->document()->url(); | 59 const KURL& url = toLocalFrame(m_frame)->document()->url(); |
60 if (!url.isValid()) | 60 if (!url.isValid()) |
61 return blankURL(); // Use "about:blank" while the page is still loading (before we have a frame). | 61 return blankURL(); // Use "about:blank" while the page is still loading (before we have a frame). |
62 | 62 |
63 return url; | 63 return url; |
64 } | 64 } |
65 | 65 |
66 String Location::href() const | 66 String Location::href() const |
67 { | 67 { |
68 if (!m_frame) | 68 if (!m_frame) |
69 return String(); | 69 return String(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 { | 142 { |
143 if (!m_frame) | 143 if (!m_frame) |
144 return; | 144 return; |
145 setLocation(url, callingWindow, enteredWindow); | 145 setLocation(url, callingWindow, enteredWindow); |
146 } | 146 } |
147 | 147 |
148 void Location::setProtocol(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& protocol, ExceptionState& exceptionState) | 148 void Location::setProtocol(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& protocol, ExceptionState& exceptionState) |
149 { | 149 { |
150 if (!m_frame) | 150 if (!m_frame) |
151 return; | 151 return; |
152 KURL url = m_frame->document()->url(); | 152 ASSERT(m_frame->isLocalFrame()); |
haraken
2015/02/03 00:56:09
Ditto. The same comment for other parts in this fi
Nate Chapin
2015/02/03 19:17:21
Done.
| |
153 KURL url = toLocalFrame(m_frame)->document()->url(); | |
153 if (!url.setProtocol(protocol)) { | 154 if (!url.setProtocol(protocol)) { |
154 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an invalid protocol."); | 155 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an invalid protocol."); |
155 return; | 156 return; |
156 } | 157 } |
157 setLocation(url.string(), callingWindow, enteredWindow); | 158 setLocation(url.string(), callingWindow, enteredWindow); |
158 } | 159 } |
159 | 160 |
160 void Location::setHost(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& host) | 161 void Location::setHost(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& host) |
161 { | 162 { |
162 if (!m_frame) | 163 if (!m_frame) |
163 return; | 164 return; |
164 KURL url = m_frame->document()->url(); | 165 ASSERT(m_frame->isLocalFrame()); |
166 KURL url = toLocalFrame(m_frame)->document()->url(); | |
165 url.setHostAndPort(host); | 167 url.setHostAndPort(host); |
166 setLocation(url.string(), callingWindow, enteredWindow); | 168 setLocation(url.string(), callingWindow, enteredWindow); |
167 } | 169 } |
168 | 170 |
169 void Location::setHostname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& hostname) | 171 void Location::setHostname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& hostname) |
170 { | 172 { |
171 if (!m_frame) | 173 if (!m_frame) |
172 return; | 174 return; |
173 KURL url = m_frame->document()->url(); | 175 ASSERT(m_frame->isLocalFrame()); |
176 KURL url = toLocalFrame(m_frame)->document()->url(); | |
174 url.setHost(hostname); | 177 url.setHost(hostname); |
175 setLocation(url.string(), callingWindow, enteredWindow); | 178 setLocation(url.string(), callingWindow, enteredWindow); |
176 } | 179 } |
177 | 180 |
178 void Location::setPort(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& portString) | 181 void Location::setPort(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& portString) |
179 { | 182 { |
180 if (!m_frame) | 183 if (!m_frame) |
181 return; | 184 return; |
182 KURL url = m_frame->document()->url(); | 185 ASSERT(m_frame->isLocalFrame()); |
186 KURL url = toLocalFrame(m_frame)->document()->url(); | |
183 url.setPort(portString); | 187 url.setPort(portString); |
184 setLocation(url.string(), callingWindow, enteredWindow); | 188 setLocation(url.string(), callingWindow, enteredWindow); |
185 } | 189 } |
186 | 190 |
187 void Location::setPathname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& pathname) | 191 void Location::setPathname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere dWindow, const String& pathname) |
188 { | 192 { |
189 if (!m_frame) | 193 if (!m_frame) |
190 return; | 194 return; |
191 KURL url = m_frame->document()->url(); | 195 ASSERT(m_frame->isLocalFrame()); |
196 KURL url = toLocalFrame(m_frame)->document()->url(); | |
192 url.setPath(pathname); | 197 url.setPath(pathname); |
193 setLocation(url.string(), callingWindow, enteredWindow); | 198 setLocation(url.string(), callingWindow, enteredWindow); |
194 } | 199 } |
195 | 200 |
196 void Location::setSearch(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredW indow, const String& search) | 201 void Location::setSearch(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredW indow, const String& search) |
197 { | 202 { |
198 if (!m_frame) | 203 if (!m_frame) |
199 return; | 204 return; |
200 KURL url = m_frame->document()->url(); | 205 ASSERT(m_frame->isLocalFrame()); |
206 KURL url = toLocalFrame(m_frame)->document()->url(); | |
201 url.setQuery(search); | 207 url.setQuery(search); |
202 setLocation(url.string(), callingWindow, enteredWindow); | 208 setLocation(url.string(), callingWindow, enteredWindow); |
203 } | 209 } |
204 | 210 |
205 void Location::setHash(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& hash) | 211 void Location::setHash(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin dow, const String& hash) |
206 { | 212 { |
207 if (!m_frame) | 213 if (!m_frame) |
208 return; | 214 return; |
209 KURL url = m_frame->document()->url(); | 215 ASSERT(m_frame->isLocalFrame()); |
216 KURL url = toLocalFrame(m_frame)->document()->url(); | |
210 String oldFragmentIdentifier = url.fragmentIdentifier(); | 217 String oldFragmentIdentifier = url.fragmentIdentifier(); |
211 String newFragmentIdentifier = hash; | 218 String newFragmentIdentifier = hash; |
212 if (hash[0] == '#') | 219 if (hash[0] == '#') |
213 newFragmentIdentifier = hash.substring(1); | 220 newFragmentIdentifier = hash.substring(1); |
214 url.setFragmentIdentifier(newFragmentIdentifier); | 221 url.setFragmentIdentifier(newFragmentIdentifier); |
215 // Note that by parsing the URL and *then* comparing fragments, we are | 222 // Note that by parsing the URL and *then* comparing fragments, we are |
216 // comparing fragments post-canonicalization, and so this handles the | 223 // comparing fragments post-canonicalization, and so this handles the |
217 // cases where fragment identifiers are ignored or invalid. | 224 // cases where fragment identifiers are ignored or invalid. |
218 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) | 225 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) |
219 return; | 226 return; |
(...skipping 11 matching lines...) Expand all Loading... | |
231 { | 238 { |
232 if (!m_frame) | 239 if (!m_frame) |
233 return; | 240 return; |
234 setLocation(url, callingWindow, enteredWindow, SetLocation::ReplaceThisFrame ); | 241 setLocation(url, callingWindow, enteredWindow, SetLocation::ReplaceThisFrame ); |
235 } | 242 } |
236 | 243 |
237 void Location::reload(LocalDOMWindow* callingWindow) | 244 void Location::reload(LocalDOMWindow* callingWindow) |
238 { | 245 { |
239 if (!m_frame) | 246 if (!m_frame) |
240 return; | 247 return; |
241 if (protocolIsJavaScript(m_frame->document()->url())) | 248 ASSERT(m_frame->isLocalFrame()); |
249 if (protocolIsJavaScript(toLocalFrame(m_frame)->document()->url())) | |
242 return; | 250 return; |
243 m_frame->reload(NormalReload, ClientRedirect); | 251 m_frame->reload(NormalReload, ClientRedirect); |
244 } | 252 } |
245 | 253 |
246 void Location::setLocation(const String& url, LocalDOMWindow* callingWindow, Loc alDOMWindow* enteredWindow, SetLocation locationPolicy) | 254 void Location::setLocation(const String& url, LocalDOMWindow* callingWindow, Loc alDOMWindow* enteredWindow, SetLocation locationPolicy) |
247 { | 255 { |
248 ASSERT(m_frame); | 256 ASSERT(m_frame); |
249 if (!m_frame || !m_frame->host()) | 257 if (!m_frame || !m_frame->host()) |
250 return; | 258 return; |
251 | 259 |
(...skipping 17 matching lines...) Expand all Loading... | |
269 argv.append("LocalDOMWindow"); | 277 argv.append("LocalDOMWindow"); |
270 argv.append("url"); | 278 argv.append("url"); |
271 argv.append(enteredDocument->url()); | 279 argv.append(enteredDocument->url()); |
272 argv.append(completedURL); | 280 argv.append(completedURL); |
273 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); | 281 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); |
274 } | 282 } |
275 m_frame->navigate(*callingWindow->document(), completedURL, locationPolicy = = SetLocation::ReplaceThisFrame); | 283 m_frame->navigate(*callingWindow->document(), completedURL, locationPolicy = = SetLocation::ReplaceThisFrame); |
276 } | 284 } |
277 | 285 |
278 } // namespace blink | 286 } // namespace blink |
OLD | NEW |