96
bool JSLocation::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)
97
bool JSLocation::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
99
Frame* frame = impl()->frame();
101
descriptor.setUndefined();
105
// When accessing Location cross-domain, functions are always the native built-in ones.
106
// See JSDOMWindow::getOwnPropertySlotDelegate for additional details.
108
// Our custom code is only needed to implement the Window cross-domain scheme, so if access is
109
// allowed, return false so the normal lookup will take place.
111
if (allowsAccessFromFrame(exec, frame, message))
114
// Check for the few functions that we allow, even when called cross-domain.
115
const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
117
if (entry && (entry->attributes() & Function)) {
118
if (entry->function() == jsLocationPrototypeFunctionReplace) {
119
slot.setCustom(this, nonCachingStaticReplaceFunctionGetter);
120
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
122
} else if (entry->function() == jsLocationPrototypeFunctionReload) {
123
slot.setCustom(this, nonCachingStaticReloadFunctionGetter);
124
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
126
} else if (entry->function() == jsLocationPrototypeFunctionAssign) {
127
slot.setCustom(this, nonCachingStaticAssignFunctionGetter);
128
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
133
// FIXME: Other implementers of the Window cross-domain scheme (Window, History) allow toString,
134
// but for now we have decided not to, partly because it seems silly to return "[Object Location]" in
135
// such cases when normally the string form of Location would be the URL.
137
printErrorMessageForFrame(frame, message);
138
descriptor.setUndefined();
142
bool JSLocation::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
98
144
Frame* frame = impl()->frame();
148
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
102
151
bool sameDomainAccess = allowsAccessFromFrame(exec, frame);
104
153
const HashEntry* entry = JSLocation::s_info.propHashTable(exec)->entry(exec, propertyName);
125
174
return Base::deleteProperty(exec, propertyName);
128
bool JSLocation::customGetPropertyNames(ExecState* exec, PropertyNameArray&)
177
void JSLocation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
130
179
// Only allow the location object to enumerated by frames in the same origin.
131
180
if (!allowsAccessFromFrame(exec, impl()->frame()))
136
static void navigateIfAllowed(ExecState* exec, Frame* frame, const KURL& url, bool lockHistory)
138
Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
139
if (!url.protocolIs("javascript") || allowsAccessFromFrame(exec, frame)) {
140
bool userGesture = activeFrame->script()->processingUserGesture();
141
frame->loader()->scheduleLocationChange(url.string(), activeFrame->loader()->outgoingReferrer(), lockHistory, userGesture);
145
void JSLocation::setHref(ExecState* exec, JSValuePtr value)
147
Frame* frame = impl()->frame();
150
Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
153
if (!activeFrame->loader()->shouldAllowNavigation(frame))
156
KURL url = activeFrame->loader()->completeURL(value->toString(exec));
157
navigateIfAllowed(exec, frame, url, false);
160
void JSLocation::setProtocol(ExecState* exec, JSValuePtr value)
162
Frame* frame = impl()->frame();
165
KURL url = frame->loader()->url();
166
url.setProtocol(value->toString(exec));
168
navigateIfAllowed(exec, frame, url, false);
171
void JSLocation::setHost(ExecState* exec, JSValuePtr value)
173
Frame* frame = impl()->frame();
176
KURL url = frame->loader()->url();
177
url.setHostAndPort(value->toString(exec));
179
navigateIfAllowed(exec, frame, url, false);
182
void JSLocation::setHostname(ExecState* exec, JSValuePtr value)
184
Frame* frame = impl()->frame();
187
KURL url = frame->loader()->url();
188
url.setHost(value->toString(exec));
190
navigateIfAllowed(exec, frame, url, false);
193
void JSLocation::setPort(ExecState* exec, JSValuePtr value)
182
Base::getOwnPropertyNames(exec, propertyNames);
185
void JSLocation::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
187
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
189
Base::defineGetter(exec, propertyName, getterFunction, attributes);
192
static void navigateIfAllowed(ExecState* exec, Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList)
194
Frame* lexicalFrame = toLexicalFrame(exec);
198
if (!protocolIsJavaScript(url) || allowsAccessFromFrame(exec, frame))
199
frame->loader()->scheduleLocationChange(url.string(), lexicalFrame->loader()->outgoingReferrer(), lockHistory, lockBackForwardList, processingUserGesture(exec));
202
void JSLocation::setHref(ExecState* exec, JSValue value)
204
Frame* frame = impl()->frame();
207
KURL url = completeURL(exec, value.toString(exec));
211
if (!shouldAllowNavigation(exec, frame))
214
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
217
void JSLocation::setProtocol(ExecState* exec, JSValue value)
219
Frame* frame = impl()->frame();
222
KURL url = frame->loader()->url();
223
url.setProtocol(value.toString(exec));
225
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
228
void JSLocation::setHost(ExecState* exec, JSValue value)
230
Frame* frame = impl()->frame();
233
KURL url = frame->loader()->url();
234
url.setHostAndPort(value.toString(exec));
236
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
239
void JSLocation::setHostname(ExecState* exec, JSValue value)
241
Frame* frame = impl()->frame();
244
KURL url = frame->loader()->url();
245
url.setHost(value.toString(exec));
247
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
250
void JSLocation::setPort(ExecState* exec, JSValue value)
195
252
Frame* frame = impl()->frame();
198
255
KURL url = frame->loader()->url();
199
256
// FIXME: Could make this a little less ugly if String provided a toUnsignedShort function.
200
const UString& portString = value->toString(exec);
257
const UString& portString = value.toString(exec);
201
258
int port = charactersToInt(portString.data(), portString.size());
202
259
if (port < 0 || port > 0xFFFF)
204
261
url.setPort(port);
206
navigateIfAllowed(exec, frame, url, false);
209
void JSLocation::setPathname(ExecState* exec, JSValuePtr value)
211
Frame* frame = impl()->frame();
214
KURL url = frame->loader()->url();
215
url.setPath(value->toString(exec));
217
navigateIfAllowed(exec, frame, url, false);
220
void JSLocation::setSearch(ExecState* exec, JSValuePtr value)
222
Frame* frame = impl()->frame();
225
KURL url = frame->loader()->url();
226
url.setQuery(value->toString(exec));
228
navigateIfAllowed(exec, frame, url, false);
231
void JSLocation::setHash(ExecState* exec, JSValuePtr value)
233
Frame* frame = impl()->frame();
236
KURL url = frame->loader()->url();
237
String oldRef = url.ref();
238
String str = value->toString(exec);
263
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
266
void JSLocation::setPathname(ExecState* exec, JSValue value)
268
Frame* frame = impl()->frame();
271
KURL url = frame->loader()->url();
272
url.setPath(value.toString(exec));
274
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
277
void JSLocation::setSearch(ExecState* exec, JSValue value)
279
Frame* frame = impl()->frame();
282
KURL url = frame->loader()->url();
283
url.setQuery(value.toString(exec));
285
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
288
void JSLocation::setHash(ExecState* exec, JSValue value)
290
Frame* frame = impl()->frame();
293
KURL url = frame->loader()->url();
294
String oldFragmentIdentifier = url.fragmentIdentifier();
295
String str = value.toString(exec);
239
296
if (str.startsWith("#"))
240
297
str = str.substring(1);
241
if (oldRef == str || (oldRef.isNull() && str.isEmpty()))
298
if (equalIgnoringNullity(oldFragmentIdentifier, str))
245
navigateIfAllowed(exec, frame, url, false);
248
JSValuePtr JSLocation::replace(ExecState* exec, const ArgList& args)
250
Frame* frame = impl()->frame();
252
return jsUndefined();
254
Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
256
return jsUndefined();
257
if (!activeFrame->loader()->shouldAllowNavigation(frame))
258
return jsUndefined();
260
navigateIfAllowed(exec, frame, activeFrame->loader()->completeURL(args.at(exec, 0)->toString(exec)), true);
261
return jsUndefined();
264
JSValuePtr JSLocation::reload(ExecState* exec, const ArgList&)
266
Frame* frame = impl()->frame();
268
return jsUndefined();
270
JSDOMWindow* window = toJSDOMWindow(frame);
271
if (!window->allowsAccessFrom(exec))
272
return jsUndefined();
274
if (!frame->loader()->url().protocolIs("javascript") || (window && window->allowsAccessFrom(exec))) {
275
bool userGesture = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame()->script()->processingUserGesture();
276
frame->loader()->scheduleRefresh(userGesture);
278
return jsUndefined();
281
JSValuePtr JSLocation::assign(ExecState* exec, const ArgList& args)
283
Frame* frame = impl()->frame();
285
return jsUndefined();
287
Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
289
return jsUndefined();
290
if (!activeFrame->loader()->shouldAllowNavigation(frame))
300
url.setFragmentIdentifier(str);
302
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
305
JSValue JSLocation::replace(ExecState* exec, const ArgList& args)
307
Frame* frame = impl()->frame();
309
return jsUndefined();
311
KURL url = completeURL(exec, args.at(0).toString(exec));
313
return jsUndefined();
315
if (!shouldAllowNavigation(exec, frame))
316
return jsUndefined();
318
navigateIfAllowed(exec, frame, url, true, true);
319
return jsUndefined();
322
JSValue JSLocation::reload(ExecState* exec, const ArgList&)
324
Frame* frame = impl()->frame();
325
if (!frame || !allowsAccessFromFrame(exec, frame))
326
return jsUndefined();
328
if (!protocolIsJavaScript(frame->loader()->url()))
329
frame->loader()->scheduleRefresh(processingUserGesture(exec));
330
return jsUndefined();
333
JSValue JSLocation::assign(ExecState* exec, const ArgList& args)
335
Frame* frame = impl()->frame();
337
return jsUndefined();
339
KURL url = completeURL(exec, args.at(0).toString(exec));
341
return jsUndefined();
343
if (!shouldAllowNavigation(exec, frame))
291
344
return jsUndefined();
293
346
// We want a new history item if this JS was called via a user gesture
294
navigateIfAllowed(exec, frame, activeFrame->loader()->completeURL(args.at(exec, 0)->toString(exec)), false);
347
navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
295
348
return jsUndefined();
298
JSValuePtr JSLocation::toString(ExecState* exec, const ArgList&)
351
JSValue JSLocation::toString(ExecState* exec, const ArgList&)
300
353
Frame* frame = impl()->frame();
302
return jsUndefined();
303
if (!allowsAccessFromFrame(exec, frame))
354
if (!frame || !allowsAccessFromFrame(exec, frame))
304
355
return jsUndefined();
306
357
return jsString(exec, impl()->toString());
360
bool JSLocationPrototype::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue, PutPropertySlot&)
362
return (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf);
365
void JSLocationPrototype::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
367
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
369
Base::defineGetter(exec, propertyName, getterFunction, attributes);
309
372
} // namespace WebCore