| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 String Location::hash() const | 130 String Location::hash() const |
| 131 { | 131 { |
| 132 if (!m_frame) | 132 if (!m_frame) |
| 133 return String(); | 133 return String(); |
| 134 | 134 |
| 135 return DOMURLUtilsReadOnly::hash(url()); | 135 return DOMURLUtilsReadOnly::hash(url()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void Location::setHref(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& url) | 138 void Location::setHref(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& url, ExceptionState& exceptionState) |
| 139 { | 139 { |
| 140 if (!m_frame) | 140 if (!m_frame) |
| 141 return; | 141 return; |
| 142 setLocation(url, currentWindow, enteredWindow); | 142 setLocation(url, currentWindow, enteredWindow, &exceptionState); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void Location::setProtocol(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& protocol, ExceptionState& exceptionState) | 145 void Location::setProtocol(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& protocol, ExceptionState& exceptionState) |
| 146 { | 146 { |
| 147 if (!m_frame) | 147 if (!m_frame) |
| 148 return; | 148 return; |
| 149 KURL url = toLocalFrame(m_frame)->document()->url(); | 149 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 150 if (!url.setProtocol(protocol)) { | 150 if (!url.setProtocol(protocol)) { |
| 151 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an
invalid protocol."); | 151 exceptionState.throwDOMException(SyntaxError, "'" + protocol + "' is an
invalid protocol."); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 setLocation(url.getString(), currentWindow, enteredWindow); | 154 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void Location::setHost(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& host) | 157 void Location::setHost(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& host, ExceptionState& exceptionState) |
| 158 { | 158 { |
| 159 if (!m_frame) | 159 if (!m_frame) |
| 160 return; | 160 return; |
| 161 KURL url = toLocalFrame(m_frame)->document()->url(); | 161 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 162 url.setHostAndPort(host); | 162 url.setHostAndPort(host); |
| 163 setLocation(url.getString(), currentWindow, enteredWindow); | 163 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void Location::setHostname(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& hostname) | 166 void Location::setHostname(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& hostname, ExceptionState& exceptionState) |
| 167 { | 167 { |
| 168 if (!m_frame) | 168 if (!m_frame) |
| 169 return; | 169 return; |
| 170 KURL url = toLocalFrame(m_frame)->document()->url(); | 170 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 171 url.setHost(hostname); | 171 url.setHost(hostname); |
| 172 setLocation(url.getString(), currentWindow, enteredWindow); | 172 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void Location::setPort(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& portString) | 175 void Location::setPort(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& portString, ExceptionState& exceptionState) |
| 176 { | 176 { |
| 177 if (!m_frame) | 177 if (!m_frame) |
| 178 return; | 178 return; |
| 179 KURL url = toLocalFrame(m_frame)->document()->url(); | 179 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 180 url.setPort(portString); | 180 url.setPort(portString); |
| 181 setLocation(url.getString(), currentWindow, enteredWindow); | 181 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void Location::setPathname(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& pathname) | 184 void Location::setPathname(LocalDOMWindow* currentWindow, LocalDOMWindow* entere
dWindow, const String& pathname, ExceptionState& exceptionState) |
| 185 { | 185 { |
| 186 if (!m_frame) | 186 if (!m_frame) |
| 187 return; | 187 return; |
| 188 KURL url = toLocalFrame(m_frame)->document()->url(); | 188 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 189 url.setPath(pathname); | 189 url.setPath(pathname); |
| 190 setLocation(url.getString(), currentWindow, enteredWindow); | 190 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void Location::setSearch(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredW
indow, const String& search) | 193 void Location::setSearch(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredW
indow, const String& search, ExceptionState& exceptionState) |
| 194 { | 194 { |
| 195 if (!m_frame) | 195 if (!m_frame) |
| 196 return; | 196 return; |
| 197 KURL url = toLocalFrame(m_frame)->document()->url(); | 197 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 198 url.setQuery(search); | 198 url.setQuery(search); |
| 199 setLocation(url.getString(), currentWindow, enteredWindow); | 199 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void Location::setHash(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& hash) | 202 void Location::setHash(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& hash, ExceptionState& exceptionState) |
| 203 { | 203 { |
| 204 if (!m_frame) | 204 if (!m_frame) |
| 205 return; | 205 return; |
| 206 KURL url = toLocalFrame(m_frame)->document()->url(); | 206 KURL url = toLocalFrame(m_frame)->document()->url(); |
| 207 String oldFragmentIdentifier = url.fragmentIdentifier(); | 207 String oldFragmentIdentifier = url.fragmentIdentifier(); |
| 208 String newFragmentIdentifier = hash; | 208 String newFragmentIdentifier = hash; |
| 209 if (hash[0] == '#') | 209 if (hash[0] == '#') |
| 210 newFragmentIdentifier = hash.substring(1); | 210 newFragmentIdentifier = hash.substring(1); |
| 211 url.setFragmentIdentifier(newFragmentIdentifier); | 211 url.setFragmentIdentifier(newFragmentIdentifier); |
| 212 // Note that by parsing the URL and *then* comparing fragments, we are | 212 // Note that by parsing the URL and *then* comparing fragments, we are |
| 213 // comparing fragments post-canonicalization, and so this handles the | 213 // comparing fragments post-canonicalization, and so this handles the |
| 214 // cases where fragment identifiers are ignored or invalid. | 214 // cases where fragment identifiers are ignored or invalid. |
| 215 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) | 215 if (equalIgnoringNullity(oldFragmentIdentifier, url.fragmentIdentifier())) |
| 216 return; | 216 return; |
| 217 setLocation(url.getString(), currentWindow, enteredWindow); | 217 setLocation(url.getString(), currentWindow, enteredWindow, &exceptionState); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void Location::assign(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWind
ow, const String& url, ExceptionState& exceptionState) | 220 void Location::assign(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWind
ow, const String& url, ExceptionState& exceptionState) |
| 221 { | 221 { |
| 222 if (!m_frame) | 222 if (!m_frame) |
| 223 return; | 223 return; |
| 224 setLocation(url, currentWindow, enteredWindow, &exceptionState); | 224 setLocation(url, currentWindow, enteredWindow, &exceptionState); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void Location::replace(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& url, ExceptionState& exceptionState) | 227 void Location::replace(LocalDOMWindow* currentWindow, LocalDOMWindow* enteredWin
dow, const String& url, ExceptionState& exceptionState) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 239 return; | 239 return; |
| 240 m_frame->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirect); | 240 m_frame->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirect); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void Location::setLocation(const String& url, LocalDOMWindow* currentWindow, Loc
alDOMWindow* enteredWindow, ExceptionState* exceptionState, SetLocation location
Policy) | 243 void Location::setLocation(const String& url, LocalDOMWindow* currentWindow, Loc
alDOMWindow* enteredWindow, ExceptionState* exceptionState, SetLocation location
Policy) |
| 244 { | 244 { |
| 245 ASSERT(m_frame); | 245 ASSERT(m_frame); |
| 246 if (!m_frame || !m_frame->host()) | 246 if (!m_frame || !m_frame->host()) |
| 247 return; | 247 return; |
| 248 | 248 |
| 249 if (!currentWindow->frame() || !currentWindow->frame()->canNavigate(*m_frame
)) | 249 if (!currentWindow->frame()) |
| 250 return; | 250 return; |
| 251 | 251 |
| 252 if (!currentWindow->frame()->canNavigate(*m_frame)) { |
| 253 if (exceptionState) |
| 254 exceptionState->throwSecurityError("The current window does not have
permission to navigate the target frame to '" + url + "'."); |
| 255 return; |
| 256 } |
| 257 |
| 252 Document* enteredDocument = enteredWindow->document(); | 258 Document* enteredDocument = enteredWindow->document(); |
| 253 if (!enteredDocument) | 259 if (!enteredDocument) |
| 254 return; | 260 return; |
| 255 | 261 |
| 256 KURL completedURL = enteredDocument->completeURL(url); | 262 KURL completedURL = enteredDocument->completeURL(url); |
| 257 if (completedURL.isNull()) | 263 if (completedURL.isNull()) |
| 258 return; | 264 return; |
| 259 if (exceptionState && !completedURL.isValid()) { | 265 if (exceptionState && !completedURL.isValid()) { |
| 260 exceptionState->throwDOMException(SyntaxError, "'" + url + "' is not a v
alid URL."); | 266 exceptionState->throwDOMException(SyntaxError, "'" + url + "' is not a v
alid URL."); |
| 261 return; | 267 return; |
| 262 } | 268 } |
| 263 | 269 |
| 264 if (m_frame->domWindow()->isInsecureScriptAccess(*currentWindow, completedUR
L)) | 270 if (m_frame->domWindow()->isInsecureScriptAccess(*currentWindow, completedUR
L)) |
| 265 return; | 271 return; |
| 266 | 272 |
| 267 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo
ggerIfIsolatedWorld(); | 273 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLo
ggerIfIsolatedWorld(); |
| 268 if (activityLogger) { | 274 if (activityLogger) { |
| 269 Vector<String> argv; | 275 Vector<String> argv; |
| 270 argv.append("LocalDOMWindow"); | 276 argv.append("LocalDOMWindow"); |
| 271 argv.append("url"); | 277 argv.append("url"); |
| 272 argv.append(enteredDocument->url()); | 278 argv.append(enteredDocument->url()); |
| 273 argv.append(completedURL); | 279 argv.append(completedURL); |
| 274 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); | 280 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data()); |
| 275 } | 281 } |
| 276 m_frame->navigate(*currentWindow->document(), completedURL, locationPolicy =
= SetLocation::ReplaceThisFrame, UserGestureStatus::None); | 282 m_frame->navigate(*currentWindow->document(), completedURL, locationPolicy =
= SetLocation::ReplaceThisFrame, UserGestureStatus::None); |
| 277 } | 283 } |
| 278 | 284 |
| 279 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |