WebCore/ChangeLog

 12010-12-31 Adam Barth <abarth@webkit.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Move V8 to WebCore Location implementation
 6 https://bugs.webkit.org/show_bug.cgi?id=51768
 7
 8 * bindings/generic/BindingFrame.h:
 9 * bindings/generic/BindingLocation.h:
 10 * bindings/v8/V8Binding.h:
 11 * bindings/v8/V8DOMWindowShell.cpp:
 12 (WebCore::V8DOMWindowShell::setLocation):
 13 * bindings/v8/V8Utilities.cpp:
 14 * bindings/v8/V8Utilities.h:
 15 * bindings/v8/custom/V8LocationCustom.cpp:
 16 (WebCore::V8Location::hashAccessorSetter):
 17 (WebCore::V8Location::hostAccessorSetter):
 18 (WebCore::V8Location::hostnameAccessorSetter):
 19 (WebCore::V8Location::hrefAccessorSetter):
 20 (WebCore::V8Location::pathnameAccessorSetter):
 21 (WebCore::V8Location::portAccessorSetter):
 22 (WebCore::V8Location::protocolAccessorSetter):
 23 (WebCore::V8Location::searchAccessorSetter):
 24 (WebCore::V8Location::reloadCallback):
 25 (WebCore::V8Location::replaceCallback):
 26 (WebCore::V8Location::assignCallback):
 27
1282010-12-29 Zhenyao Mo <zmo@google.com>
229
330 Reviewed by Kenneth Russell.
74821

WebCore/bindings/generic/BindingFrame.h

3131#ifndef BindingFrame_h
3232#define BindingFrame_h
3333
34 #include "Frame.h"
35 #include "GenericBinding.h"
36 
37 namespace WebCore {
38 
39 template <class Binding>
40 class BindingFrame {
41 public:
42  static void navigateIfAllowed(State<Binding>*, Frame*, const KURL&, bool lockHistory, bool lockBackForwardList);
43 };
44 
45 template <class Binding>
46 void BindingFrame<Binding>::navigateIfAllowed(State<Binding>* state, Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList)
47 {
48  Frame* activeFrame = state->activeFrame();
49  if (!activeFrame)
50  return;
51  if (!protocolIsJavaScript(url) || state->allowsAccessFromFrame(frame))
52  frame->navigationScheduler()->scheduleLocationChange(activeFrame->document()->securityOrigin(),
53  url.string(), activeFrame->loader()->outgoingReferrer(), lockHistory, lockBackForwardList);
54 }
55 
56 } // namespace WebCore
 34// FIXME: Remove this file.
5735
5836#endif // BindingFrame_h
74821

WebCore/bindings/generic/BindingLocation.h

3131#ifndef BindingLocation_h
3232#define BindingLocation_h
3333
34 #include "BindingSecurity.h"
35 #include "GenericBinding.h"
36 #include "Location.h"
37 
38 namespace WebCore {
39 
40 template <class Binding>
41 class BindingLocation {
42 public:
43  static void replace(State<Binding>*, Location*, const String& url);
44 };
45 
46 template <class Binding>
47 void BindingLocation<Binding>::replace(State<Binding>* state, Location* location, const String& url)
48 {
49  Frame* frame = location->frame();
50  if (!frame)
51  return;
52 
53  KURL fullURL = completeURL(state, url);
54  if (fullURL.isNull())
55  return;
56 
57  if (!BindingSecurity<Binding>::shouldAllowNavigation(state, frame))
58  return;
59 
60  Binding::Frame::navigateIfAllowed(state, frame, fullURL, true, true);
61 }
62 
63 } // namespace WebCore
 34// FIXME: Remove this file.
6435
6536#endif // BindingLocation_h
74821

WebCore/bindings/v8/V8Binding.h

3131#ifndef V8Binding_h
3232#define V8Binding_h
3333
34 #include "BindingFrame.h"
35 #include "BindingLocation.h"
3634#include "BindingSecurity.h"
3735#include "MathExtras.h"
3836#include "PlatformString.h"

@@namespace WebCore {
4543
4644 class EventListener;
4745 class EventTarget;
48  class V8BindingDOMWindow;
4946
50  // Instantiate binding template classes for V8.
 47 // FIXME: Remove V8Binding.
5148 class V8Binding {
52  public:
53  typedef v8::Handle<v8::Value> Value;
54  typedef V8BindingDOMWindow DOMWindow;
55  typedef BindingFrame<V8Binding> Frame;
56  typedef BindingLocation<V8Binding> Location;
57 
58  static Value emptyScriptValue() { return v8::Local<v8::Value>(); }
5949 };
6050 typedef BindingSecurity<V8Binding> V8BindingSecurity;
6151
74821

WebCore/bindings/v8/V8DOMWindowShell.cpp

@@v8::Local<v8::Object> V8DOMWindowShell::
578578 return notHandledByInterceptor();
579579}
580580
581 void V8DOMWindowShell::setLocation(DOMWindow* window, const String& relativeURL)
 581void V8DOMWindowShell::setLocation(DOMWindow* window, const String& locationString)
582582{
583  Frame* frame = window->frame();
584  if (!frame)
585  return;
586 
587  KURL url = completeURL(relativeURL);
588  if (url.isNull())
589  return;
590 
591  if (!shouldAllowNavigation(frame))
592  return;
593 
594  navigateIfAllowed(frame, url, false, false);
 583 State<V8Binding>* state = V8BindingState::Only();
 584 window->setLocation(locationString, state->activeWindow(), state->firstWindow());
595585}
596586
597587} // WebCore
74821

WebCore/bindings/v8/V8Utilities.cpp

@@KURL completeURL(const String& relativeU
114114 return completeURL(V8BindingState::Only(), relativeURL);
115115}
116116
117 void navigateIfAllowed(Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList)
118 {
119  return V8Binding::Frame::navigateIfAllowed(V8BindingState::Only(), frame, url, lockHistory, lockBackForwardList);
120 }
121 
122117ScriptExecutionContext* getScriptExecutionContext()
123118{
124119#if ENABLE(WORKERS)
74821

WebCore/bindings/v8/V8Utilities.h

@@namespace WebCore {
5252 bool processingUserGesture();
5353 bool shouldAllowNavigation(Frame*);
5454 KURL completeURL(const String& relativeURL);
55  void navigateIfAllowed(Frame*, const KURL&, bool lockHistory, bool lockBackForwardList);
5655
5756 ScriptExecutionContext* getScriptExecutionContext();
5857
74821

WebCore/bindings/v8/custom/V8LocationCustom.cpp

4848
4949namespace WebCore {
5050
51 // Notes about V8/JSC porting of this file.
52 // This class is not very JS-engine specific. If we can move a couple of
53 // methods to the scriptController, we should be able to unify the code
54 // between JSC and V8:
55 // toCallingFrame() - in JSC, this needs an ExecState.
56 // isSafeScript()
57 // Since JSC and V8 have different mechanisms for getting at the calling frame,
58 // we're just making all these custom for now. The functionality is simple
59 // and mirrors JSLocationCustom.cpp.
60 
6151void V8Location::hashAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
6252{
6353 INC_STATS("DOM.Location.hash._set");
64  v8::Handle<v8::Object> holder = info.Holder();
65  Location* imp = V8Location::toNative(holder);
66  String hash = toWebCoreString(value);
 54 Location* impl = V8Location::toNative(info.Holder());
 55 State<V8Binding>* state = V8BindingState::Only();
6756
68  Frame* frame = imp->frame();
69  if (!frame)
70  return;
71 
72  KURL url = frame->loader()->url();
73  String oldRef = url.fragmentIdentifier();
74 
75  if (hash.startsWith("#"))
76  hash = hash.substring(1);
77 
78  // Note that by parsing the URL and *then* comparing fragments, we are
79  // comparing fragments post-canonicalization, and so this handles the
80  // cases where fragment identifiers are ignored or invalid.
81  url.setFragmentIdentifier(hash);
82  String newRef = url.fragmentIdentifier();
83  if (oldRef == newRef || (oldRef.isNull() && newRef.isEmpty()))
84  return;
 57 // FIXME: Handle exceptions correctly.
 58 String hash = toWebCoreString(value);
8559
86  navigateIfAllowed(frame, url, false, false);
 60 impl->setHash(hash, state->activeWindow(), state->firstWindow());
8761}
8862
8963void V8Location::hostAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
9064{
9165 INC_STATS("DOM.Location.host._set");
92  v8::Handle<v8::Object> holder = info.Holder();
93  Location* imp = V8Location::toNative(holder);
94  String host = toWebCoreString(value);
 66 Location* impl = V8Location::toNative(info.Holder());
 67 State<V8Binding>* state = V8BindingState::Only();
9568
96  Frame* frame = imp->frame();
97  if (!frame)
98  return;
99 
100  KURL url = frame->loader()->url();
101  String newHost = host.left(host.find(":"));
102  String newPort = host.substring(host.find(":") + 1);
103  url.setHost(newHost);
104  url.setPort(newPort.toUInt());
 69 // FIXME: Handle exceptions correctly.
 70 String host = toWebCoreString(value);
10571
106  navigateIfAllowed(frame, url, false, false);
 72 impl->setHost(host, state->activeWindow(), state->firstWindow());
10773}
10874
10975void V8Location::hostnameAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
11076{
11177 INC_STATS("DOM.Location.hostname._set");
112  v8::Handle<v8::Object> holder = info.Holder();
113  Location* imp = V8Location::toNative(holder);
114  String hostname = toWebCoreString(value);
 78 Location* impl = V8Location::toNative(info.Holder());
 79 State<V8Binding>* state = V8BindingState::Only();
11580
116  Frame* frame = imp->frame();
117  if (!frame)
118  return;
119 
120  KURL url = frame->loader()->url();
121  url.setHost(hostname);
 81 // FIXME: Handle exceptions correctly.
 82 String hostname = toWebCoreString(value);
12283
123  navigateIfAllowed(frame, url, false, false);
 84 impl->setHostname(hostname, state->activeWindow(), state->firstWindow());
12485}
12586
12687void V8Location::hrefAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
12788{
12889 INC_STATS("DOM.Location.href._set");
129  v8::Handle<v8::Object> holder = info.Holder();
130  Location* imp = V8Location::toNative(holder);
131 
132  Frame* frame = imp->frame();
133  if (!frame)
134  return;
135 
136  KURL url = completeURL(toWebCoreString(value));
137  if (url.isNull())
138  return;
 90 Location* impl = V8Location::toNative(info.Holder());
 91 State<V8Binding>* state = V8BindingState::Only();
13992
140  if (!shouldAllowNavigation(frame))
141  return;
 93 // FIXME: Handle exceptions correctly.
 94 String href = toWebCoreString(value);
14295
143  navigateIfAllowed(frame, url, false, false);
 96 impl->setHref(href, state->activeWindow(), state->firstWindow());
14497}
14598
14699void V8Location::pathnameAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
147100{
148101 INC_STATS("DOM.Location.pathname._set");
149  v8::Handle<v8::Object> holder = info.Holder();
150  Location* imp = V8Location::toNative(holder);
151  String pathname = toWebCoreString(value);
152 
153  Frame* frame = imp->frame();
154  if (!frame)
155  return;
 102 Location* impl = V8Location::toNative(info.Holder());
 103 State<V8Binding>* state = V8BindingState::Only();
156104
157  KURL url = frame->loader()->url();
158  url.setPath(pathname);
 105 // FIXME: Handle exceptions correctly.
 106 String pathname = toWebCoreString(value);
159107
160  navigateIfAllowed(frame, url, false, false);
 108 impl->setPathname(pathname, state->activeWindow(), state->firstWindow());
161109}
162110
163111void V8Location::portAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
164112{
165113 INC_STATS("DOM.Location.port._set");
166  v8::Handle<v8::Object> holder = info.Holder();
167  Location* imp = V8Location::toNative(holder);
168  String port = toWebCoreString(value);
169 
170  Frame* frame = imp->frame();
171  if (!frame)
172  return;
 114 Location* impl = V8Location::toNative(info.Holder());
 115 State<V8Binding>* state = V8BindingState::Only();
173116
174  KURL url = frame->loader()->url();
175  url.setPort(port.toUInt());
 117 // FIXME: Handle exceptions correctly.
 118 String port = toWebCoreString(value);
176119
177  navigateIfAllowed(frame, url, false, false);
 120 impl->setPort(port, state->activeWindow(), state->firstWindow());
178121}
179122
180123void V8Location::protocolAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
181124{
182125 INC_STATS("DOM.Location.protocol._set");
183  v8::Handle<v8::Object> holder = info.Holder();
184  Location* imp = V8Location::toNative(holder);
185  String protocol = toWebCoreString(value);
 126 Location* impl = V8Location::toNative(info.Holder());
 127 State<V8Binding>* state = V8BindingState::Only();
186128
187  Frame* frame = imp->frame();
188  if (!frame)
189  return;
190 
191  KURL url = frame->loader()->url();
192  if (!url.setProtocol(protocol)) {
193  throwError("Can't set protocol", V8Proxy::SyntaxError);
194  return;
195  }
 129 // FIXME: Handle exceptions correctly.
 130 String protocol = toWebCoreString(value);
196131
197  navigateIfAllowed(frame, url, false, false);
 132 ExceptionCode ec = 0;
 133 impl->setProtocol(protocol, state->activeWindow(), state->firstWindow(), ec);
 134 if (UNLIKELY(ec))
 135 V8Proxy::setDOMException(ec);
198136}
199137
200138void V8Location::searchAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
201139{
202140 INC_STATS("DOM.Location.search._set");
203  v8::Handle<v8::Object> holder = info.Holder();
204  Location* imp = V8Location::toNative(holder);
205  String query = toWebCoreString(value);
206 
207  Frame* frame = imp->frame();
208  if (!frame)
209  return;
 141 Location* impl = V8Location::toNative(info.Holder());
 142 State<V8Binding>* state = V8BindingState::Only();
210143
211  KURL url = frame->loader()->url();
212  url.setQuery(query);
 144 // FIXME: Handle exceptions correctly.
 145 String search = toWebCoreString(value);
213146
214  navigateIfAllowed(frame, url, false, false);
 147 impl->setSearch(search, state->activeWindow(), state->firstWindow());
215148}
216149
217150v8::Handle<v8::Value> V8Location::reloadAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)

@@v8::Handle<v8::Value> V8Location::assign
271204
272205v8::Handle<v8::Value> V8Location::reloadCallback(const v8::Arguments& args)
273206{
274  // FIXME: we ignore the "forceget" parameter.
275 
276207 INC_STATS("DOM.Location.reload");
277  v8::Handle<v8::Object> holder = args.Holder();
278  Location* imp = V8Location::toNative(holder);
 208 Location* impl = V8Location::toNative(args.Holder());
 209 State<V8Binding>* state = V8BindingState::Only();
279210
280  Frame* frame = imp->frame();
281  if (!frame || !ScriptController::isSafeScript(frame))
282  return v8::Undefined();
283 
284  if (!protocolIsJavaScript(frame->loader()->url()))
285  frame->navigationScheduler()->scheduleRefresh();
 211 impl->reload(state->activeWindow());
286212 return v8::Undefined();
287213}
288214
289215v8::Handle<v8::Value> V8Location::replaceCallback(const v8::Arguments& args)
290216{
291217 INC_STATS("DOM.Location.replace");
292  v8::Handle<v8::Object> holder = args.Holder();
293  Location* imp = V8Location::toNative(holder);
294  V8Binding::Location::replace(V8BindingState::Only(), imp, toWebCoreString(args[0]));
 218 Location* impl = V8Location::toNative(args.Holder());
 219 State<V8Binding>* state = V8BindingState::Only();
 220
 221 // FIXME: Handle exceptions correctly.
 222 String urlString = toWebCoreString(args[0]);
 223
 224 impl->replace(urlString, state->activeWindow(), state->firstWindow());
295225 return v8::Undefined();
296226}
297227
298228v8::Handle<v8::Value> V8Location::assignCallback(const v8::Arguments& args)
299229{
300230 INC_STATS("DOM.Location.assign");
301  v8::Handle<v8::Object> holder = args.Holder();
302  Location* imp = V8Location::toNative(holder);
 231 Location* impl = V8Location::toNative(args.Holder());
 232 State<V8Binding>* state = V8BindingState::Only();
303233
304  Frame* frame = imp->frame();
305  if (!frame)
306  return v8::Undefined();
307 
308  KURL url = completeURL(toWebCoreString(args[0]));
309  if (url.isNull())
310  return v8::Undefined();
311 
312  if (!shouldAllowNavigation(frame))
313  return v8::Undefined();
 234 // FIXME: Handle exceptions correctly.
 235 String urlString = toWebCoreString(args[0]);
314236
315  navigateIfAllowed(frame, url, false, false);
 237 impl->assign(urlString, state->activeWindow(), state->firstWindow());
316238 return v8::Undefined();
317239}
318240
74821