| 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 const KURL& url = toLocalFrame(m_frame)->document()->url(); |
| 58 | |
| 59 const KURL& url = m_frame->document()->url(); | |
| 60 if (!url.isValid()) | 58 if (!url.isValid()) |
| 61 return blankURL(); // Use "about:blank" while the page is still loading
(before we have a frame). | 59 return blankURL(); // Use "about:blank" while the page is still loading
(before we have a frame). |
| 62 | 60 |
| 63 return url; | 61 return url; |
| 64 } | 62 } |
| 65 | 63 |
| 66 String Location::href() const | 64 String Location::href() const |
| 67 { | 65 { |
| 68 if (!m_frame) | 66 if (!m_frame) |
| 69 return String(); | 67 return String(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 { | 140 { |
| 143 if (!m_frame) | 141 if (!m_frame) |
| 144 return; | 142 return; |
| 145 setLocation(url, callingWindow, enteredWindow); | 143 setLocation(url, callingWindow, enteredWindow); |
| 146 } | 144 } |
| 147 | 145 |
| 148 void Location::setProtocol(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& protocol, ExceptionState& exceptionState) | 146 void Location::setProtocol(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& protocol, ExceptionState& exceptionState) |
| 149 { | 147 { |
| 150 if (!m_frame) | 148 if (!m_frame) |
| 151 return; | 149 return; |
| 152 KURL url = m_frame->document()->url(); | 150 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 153 if (!url.setProtocol(protocol)) { | 151 if (!url.setProtocol(protocol)) { |
| 154 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an
invalid protocol."); | 152 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an
invalid protocol."); |
| 155 return; | 153 return; |
| 156 } | 154 } |
| 157 setLocation(url.string(), callingWindow, enteredWindow); | 155 setLocation(url.string(), callingWindow, enteredWindow); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void Location::setHost(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& host) | 158 void Location::setHost(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& host) |
| 161 { | 159 { |
| 162 if (!m_frame) | 160 if (!m_frame) |
| 163 return; | 161 return; |
| 164 KURL url = m_frame->document()->url(); | 162 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 165 url.setHostAndPort(host); | 163 url.setHostAndPort(host); |
| 166 setLocation(url.string(), callingWindow, enteredWindow); | 164 setLocation(url.string(), callingWindow, enteredWindow); |
| 167 } | 165 } |
| 168 | 166 |
| 169 void Location::setHostname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& hostname) | 167 void Location::setHostname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& hostname) |
| 170 { | 168 { |
| 171 if (!m_frame) | 169 if (!m_frame) |
| 172 return; | 170 return; |
| 173 KURL url = m_frame->document()->url(); | 171 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 174 url.setHost(hostname); | 172 url.setHost(hostname); |
| 175 setLocation(url.string(), callingWindow, enteredWindow); | 173 setLocation(url.string(), callingWindow, enteredWindow); |
| 176 } | 174 } |
| 177 | 175 |
| 178 void Location::setPort(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& portString) | 176 void Location::setPort(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& portString) |
| 179 { | 177 { |
| 180 if (!m_frame) | 178 if (!m_frame) |
| 181 return; | 179 return; |
| 182 KURL url = m_frame->document()->url(); | 180 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 183 url.setPort(portString); | 181 url.setPort(portString); |
| 184 setLocation(url.string(), callingWindow, enteredWindow); | 182 setLocation(url.string(), callingWindow, enteredWindow); |
| 185 } | 183 } |
| 186 | 184 |
| 187 void Location::setPathname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& pathname) | 185 void Location::setPathname(LocalDOMWindow* callingWindow, LocalDOMWindow* entere
dWindow, const String& pathname) |
| 188 { | 186 { |
| 189 if (!m_frame) | 187 if (!m_frame) |
| 190 return; | 188 return; |
| 191 KURL url = m_frame->document()->url(); | 189 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 192 url.setPath(pathname); | 190 url.setPath(pathname); |
| 193 setLocation(url.string(), callingWindow, enteredWindow); | 191 setLocation(url.string(), callingWindow, enteredWindow); |
| 194 } | 192 } |
| 195 | 193 |
| 196 void Location::setSearch(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredW
indow, const String& search) | 194 void Location::setSearch(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredW
indow, const String& search) |
| 197 { | 195 { |
| 198 if (!m_frame) | 196 if (!m_frame) |
| 199 return; | 197 return; |
| 200 KURL url = m_frame->document()->url(); | 198 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 201 url.setQuery(search); | 199 url.setQuery(search); |
| 202 setLocation(url.string(), callingWindow, enteredWindow); | 200 setLocation(url.string(), callingWindow, enteredWindow); |
| 203 } | 201 } |
| 204 | 202 |
| 205 void Location::setHash(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& hash) | 203 void Location::setHash(LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWin
dow, const String& hash) |
| 206 { | 204 { |
| 207 if (!m_frame) | 205 if (!m_frame) |
| 208 return; | 206 return; |
| 209 KURL url = m_frame->document()->url(); | 207 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 210 String oldFragmentIdentifier = url.fragmentIdentifier(); | 208 String oldFragmentIdentifier = url.fragmentIdentifier(); |
| 211 String newFragmentIdentifier = hash; | 209 String newFragmentIdentifier = hash; |
| 212 if (hash[0] == '#') | 210 if (hash[0] == '#') |
| 213 newFragmentIdentifier = hash.substring(1); | 211 newFragmentIdentifier = hash.substring(1); |
| 214 url.setFragmentIdentifier(newFragmentIdentifier); | 212 url.setFragmentIdentifier(newFragmentIdentifier); |
| 215 // Note that by parsing the URL and *then* comparing fragments, we are | 213 // Note that by parsing the URL and *then* comparing fragments, we are |
| 216 // comparing fragments post-canonicalization, and so this handles the | 214 // comparing fragments post-canonicalization, and so this handles the |
| 217 // cases where fragment identifiers are ignored or invalid. | 215 // cases where fragment identifiers are ignored or invalid. |
| 218 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) | 216 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) |
| 219 return; | 217 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 231 { | 229 { |
| 232 if (!m_frame) | 230 if (!m_frame) |
| 233 return; | 231 return; |
| 234 setLocation(url, callingWindow, enteredWindow, SetLocation::ReplaceThisFrame
); | 232 setLocation(url, callingWindow, enteredWindow, SetLocation::ReplaceThisFrame
); |
| 235 } | 233 } |
| 236 | 234 |
| 237 void Location::reload(LocalDOMWindow* callingWindow) | 235 void Location::reload(LocalDOMWindow* callingWindow) |
| 238 { | 236 { |
| 239 if (!m_frame) | 237 if (!m_frame) |
| 240 return; | 238 return; |
| 241 if (protocolIsJavaScript(m_frame->document()->url())) | 239 if (protocolIsJavaScript(toLocalFrame(m_frame)->document()->url())) |
| 242 return; | 240 return; |
| 243 m_frame->reload(NormalReload, ClientRedirect); | 241 m_frame->reload(NormalReload, ClientRedirect); |
| 244 } | 242 } |
| 245 | 243 |
| 246 void Location::setLocation(const String& url, LocalDOMWindow* callingWindow, Loc
alDOMWindow* enteredWindow, SetLocation locationPolicy) | 244 void Location::setLocation(const String& url, LocalDOMWindow* callingWindow, Loc
alDOMWindow* enteredWindow, SetLocation locationPolicy) |
| 247 { | 245 { |
| 248 ASSERT(m_frame); | 246 ASSERT(m_frame); |
| 249 if (!m_frame || !m_frame->host()) | 247 if (!m_frame || !m_frame->host()) |
| 250 return; | 248 return; |
| 251 | 249 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 269 argv.append("LocalDOMWindow"); | 267 argv.append("LocalDOMWindow"); |
| 270 argv.append("url"); | 268 argv.append("url"); |
| 271 argv.append(enteredDocument->url()); | 269 argv.append(enteredDocument->url()); |
| 272 argv.append(completedURL); | 270 argv.append(completedURL); |
| 273 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); | 271 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); |
| 274 } | 272 } |
| 275 m_frame->navigate(*callingWindow->document(), completedURL, locationPolicy =
= SetLocation::ReplaceThisFrame); | 273 m_frame->navigate(*callingWindow->document(), completedURL, locationPolicy =
= SetLocation::ReplaceThisFrame); |
| 276 } | 274 } |
| 277 | 275 |
| 278 } // namespace blink | 276 } // namespace blink |
| OLD | NEW |