OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
5 * Copyright (C) 2009 Adam Barth. All rights reserved. | 5 * Copyright (C) 2009 Adam Barth. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * | 10 * |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "platform/UserGestureIndicator.h" | 49 #include "platform/UserGestureIndicator.h" |
50 #include "platform/scheduler/CancellableTaskFactory.h" | 50 #include "platform/scheduler/CancellableTaskFactory.h" |
51 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
52 #include "public/platform/WebScheduler.h" | 52 #include "public/platform/WebScheduler.h" |
53 #include "wtf/CurrentTime.h" | 53 #include "wtf/CurrentTime.h" |
54 | 54 |
55 namespace blink { | 55 namespace blink { |
56 | 56 |
57 unsigned NavigationDisablerForBeforeUnload::s_navigationDisableCount = 0; | 57 unsigned NavigationDisablerForBeforeUnload::s_navigationDisableCount = 0; |
58 | 58 |
59 class ScheduledNavigation : public NoBaseWillBeGarbageCollectedFinalized<Schedul
edNavigation> { | 59 class ScheduledNavigation : public GarbageCollectedFinalized<ScheduledNavigation
> { |
60 WTF_MAKE_NONCOPYABLE(ScheduledNavigation); USING_FAST_MALLOC_WILL_BE_REMOVED
(ScheduledNavigation); | 60 WTF_MAKE_NONCOPYABLE(ScheduledNavigation); |
61 public: | 61 public: |
62 ScheduledNavigation(double delay, Document* originDocument, bool replacesCur
rentItem, bool isLocationChange) | 62 ScheduledNavigation(double delay, Document* originDocument, bool replacesCur
rentItem, bool isLocationChange) |
63 : m_delay(delay) | 63 : m_delay(delay) |
64 , m_originDocument(originDocument) | 64 , m_originDocument(originDocument) |
65 , m_replacesCurrentItem(replacesCurrentItem) | 65 , m_replacesCurrentItem(replacesCurrentItem) |
66 , m_isLocationChange(isLocationChange) | 66 , m_isLocationChange(isLocationChange) |
67 , m_wasUserGesture(UserGestureIndicator::processingUserGesture()) | 67 , m_wasUserGesture(UserGestureIndicator::processingUserGesture()) |
68 { | 68 { |
69 if (m_wasUserGesture) | 69 if (m_wasUserGesture) |
70 m_userGestureToken = UserGestureIndicator::currentToken(); | 70 m_userGestureToken = UserGestureIndicator::currentToken(); |
(...skipping 18 matching lines...) Expand all Loading... |
89 DEFINE_INLINE_VIRTUAL_TRACE() | 89 DEFINE_INLINE_VIRTUAL_TRACE() |
90 { | 90 { |
91 visitor->trace(m_originDocument); | 91 visitor->trace(m_originDocument); |
92 } | 92 } |
93 | 93 |
94 protected: | 94 protected: |
95 void clearUserGesture() { m_wasUserGesture = false; } | 95 void clearUserGesture() { m_wasUserGesture = false; } |
96 | 96 |
97 private: | 97 private: |
98 double m_delay; | 98 double m_delay; |
99 RefPtrWillBeMember<Document> m_originDocument; | 99 Member<Document> m_originDocument; |
100 bool m_replacesCurrentItem; | 100 bool m_replacesCurrentItem; |
101 bool m_isLocationChange; | 101 bool m_isLocationChange; |
102 bool m_wasUserGesture; | 102 bool m_wasUserGesture; |
103 RefPtr<UserGestureToken> m_userGestureToken; | 103 RefPtr<UserGestureToken> m_userGestureToken; |
104 }; | 104 }; |
105 | 105 |
106 class ScheduledURLNavigation : public ScheduledNavigation { | 106 class ScheduledURLNavigation : public ScheduledNavigation { |
107 protected: | 107 protected: |
108 ScheduledURLNavigation(double delay, Document* originDocument, const String&
url, bool replacesCurrentItem, bool isLocationChange) | 108 ScheduledURLNavigation(double delay, Document* originDocument, const String&
url, bool replacesCurrentItem, bool isLocationChange) |
109 : ScheduledNavigation(delay, originDocument, replacesCurrentItem, isLoca
tionChange) | 109 : ScheduledNavigation(delay, originDocument, replacesCurrentItem, isLoca
tionChange) |
(...skipping 15 matching lines...) Expand all Loading... |
125 | 125 |
126 String url() const { return m_url; } | 126 String url() const { return m_url; } |
127 | 127 |
128 private: | 128 private: |
129 String m_url; | 129 String m_url; |
130 ContentSecurityPolicyDisposition m_shouldCheckMainWorldContentSecurityPolicy
; | 130 ContentSecurityPolicyDisposition m_shouldCheckMainWorldContentSecurityPolicy
; |
131 }; | 131 }; |
132 | 132 |
133 class ScheduledRedirect final : public ScheduledURLNavigation { | 133 class ScheduledRedirect final : public ScheduledURLNavigation { |
134 public: | 134 public: |
135 static PassOwnPtrWillBeRawPtr<ScheduledRedirect> create(double delay, Docume
nt* originDocument, const String& url, bool replacesCurrentItem) | 135 static RawPtr<ScheduledRedirect> create(double delay, Document* originDocume
nt, const String& url, bool replacesCurrentItem) |
136 { | 136 { |
137 return adoptPtrWillBeNoop(new ScheduledRedirect(delay, originDocument, u
rl, replacesCurrentItem)); | 137 return new ScheduledRedirect(delay, originDocument, url, replacesCurrent
Item); |
138 } | 138 } |
139 | 139 |
140 bool shouldStartTimer(LocalFrame* frame) override { return frame->document()
->loadEventFinished(); } | 140 bool shouldStartTimer(LocalFrame* frame) override { return frame->document()
->loadEventFinished(); } |
141 | 141 |
142 void fire(LocalFrame* frame) override | 142 void fire(LocalFrame* frame) override |
143 { | 143 { |
144 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); | 144 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); |
145 FrameLoadRequest request(originDocument(), url(), "_self"); | 145 FrameLoadRequest request(originDocument(), url(), "_self"); |
146 request.setReplacesCurrentItem(replacesCurrentItem()); | 146 request.setReplacesCurrentItem(replacesCurrentItem()); |
147 if (equalIgnoringFragmentIdentifier(frame->document()->url(), request.re
sourceRequest().url())) | 147 if (equalIgnoringFragmentIdentifier(frame->document()->url(), request.re
sourceRequest().url())) |
148 request.resourceRequest().setCachePolicy(ValidatingCacheData); | 148 request.resourceRequest().setCachePolicy(ValidatingCacheData); |
149 request.setClientRedirect(ClientRedirect); | 149 request.setClientRedirect(ClientRedirect); |
150 frame->loader().load(request); | 150 frame->loader().load(request); |
151 } | 151 } |
152 | 152 |
153 private: | 153 private: |
154 ScheduledRedirect(double delay, Document* originDocument, const String& url,
bool replacesCurrentItem) | 154 ScheduledRedirect(double delay, Document* originDocument, const String& url,
bool replacesCurrentItem) |
155 : ScheduledURLNavigation(delay, originDocument, url, replacesCurrentItem
, false) | 155 : ScheduledURLNavigation(delay, originDocument, url, replacesCurrentItem
, false) |
156 { | 156 { |
157 clearUserGesture(); | 157 clearUserGesture(); |
158 } | 158 } |
159 }; | 159 }; |
160 | 160 |
161 class ScheduledLocationChange final : public ScheduledURLNavigation { | 161 class ScheduledLocationChange final : public ScheduledURLNavigation { |
162 public: | 162 public: |
163 static PassOwnPtrWillBeRawPtr<ScheduledLocationChange> create(Document* orig
inDocument, const String& url, bool replacesCurrentItem) | 163 static RawPtr<ScheduledLocationChange> create(Document* originDocument, cons
t String& url, bool replacesCurrentItem) |
164 { | 164 { |
165 return adoptPtrWillBeNoop(new ScheduledLocationChange(originDocument, ur
l, replacesCurrentItem)); | 165 return new ScheduledLocationChange(originDocument, url, replacesCurrentI
tem); |
166 } | 166 } |
167 | 167 |
168 private: | 168 private: |
169 ScheduledLocationChange(Document* originDocument, const String& url, bool re
placesCurrentItem) | 169 ScheduledLocationChange(Document* originDocument, const String& url, bool re
placesCurrentItem) |
170 : ScheduledURLNavigation(0.0, originDocument, url, replacesCurrentItem,
!protocolIsJavaScript(url)) { } | 170 : ScheduledURLNavigation(0.0, originDocument, url, replacesCurrentItem,
!protocolIsJavaScript(url)) { } |
171 }; | 171 }; |
172 | 172 |
173 class ScheduledReload final : public ScheduledNavigation { | 173 class ScheduledReload final : public ScheduledNavigation { |
174 public: | 174 public: |
175 static PassOwnPtrWillBeRawPtr<ScheduledReload> create() | 175 static RawPtr<ScheduledReload> create() |
176 { | 176 { |
177 return adoptPtrWillBeNoop(new ScheduledReload); | 177 return adoptPtrWillBeNoop(new ScheduledReload); |
178 } | 178 } |
179 | 179 |
180 void fire(LocalFrame* frame) override | 180 void fire(LocalFrame* frame) override |
181 { | 181 { |
182 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); | 182 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); |
183 ResourceRequest resourceRequest = | 183 ResourceRequest resourceRequest = |
184 frame->loader().resourceRequestForReload(FrameLoadTypeReload, KURL()
, ClientRedirect); | 184 frame->loader().resourceRequestForReload(FrameLoadTypeReload, KURL()
, ClientRedirect); |
185 if (resourceRequest.isNull()) | 185 if (resourceRequest.isNull()) |
186 return; | 186 return; |
187 FrameLoadRequest request = FrameLoadRequest(nullptr, resourceRequest); | 187 FrameLoadRequest request = FrameLoadRequest(nullptr, resourceRequest); |
188 request.setClientRedirect(ClientRedirect); | 188 request.setClientRedirect(ClientRedirect); |
189 frame->loader().load(request, FrameLoadTypeReload); | 189 frame->loader().load(request, FrameLoadTypeReload); |
190 } | 190 } |
191 | 191 |
192 private: | 192 private: |
193 ScheduledReload() | 193 ScheduledReload() |
194 : ScheduledNavigation(0.0, nullptr, true, true) | 194 : ScheduledNavigation(0.0, nullptr, true, true) |
195 { | 195 { |
196 } | 196 } |
197 }; | 197 }; |
198 | 198 |
199 class ScheduledPageBlock final : public ScheduledURLNavigation { | 199 class ScheduledPageBlock final : public ScheduledURLNavigation { |
200 public: | 200 public: |
201 static PassOwnPtrWillBeRawPtr<ScheduledPageBlock> create(Document* originDoc
ument, const String& url) | 201 static RawPtr<ScheduledPageBlock> create(Document* originDocument, const Str
ing& url) |
202 { | 202 { |
203 return adoptPtrWillBeNoop(new ScheduledPageBlock(originDocument, url)); | 203 return new ScheduledPageBlock(originDocument, url); |
204 } | 204 } |
205 | 205 |
206 void fire(LocalFrame* frame) override | 206 void fire(LocalFrame* frame) override |
207 { | 207 { |
208 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); | 208 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); |
209 SubstituteData substituteData(SharedBuffer::create(), "text/plain", "UTF
-8", KURL(), ForceSynchronousLoad); | 209 SubstituteData substituteData(SharedBuffer::create(), "text/plain", "UTF
-8", KURL(), ForceSynchronousLoad); |
210 FrameLoadRequest request(originDocument(), url(), substituteData); | 210 FrameLoadRequest request(originDocument(), url(), substituteData); |
211 request.setReplacesCurrentItem(true); | 211 request.setReplacesCurrentItem(true); |
212 request.setClientRedirect(ClientRedirect); | 212 request.setClientRedirect(ClientRedirect); |
213 frame->loader().load(request); | 213 frame->loader().load(request); |
214 } | 214 } |
215 private: | 215 private: |
216 ScheduledPageBlock(Document* originDocument, const String& url) | 216 ScheduledPageBlock(Document* originDocument, const String& url) |
217 : ScheduledURLNavigation(0.0, originDocument, url, true, true) | 217 : ScheduledURLNavigation(0.0, originDocument, url, true, true) |
218 { | 218 { |
219 } | 219 } |
220 | 220 |
221 }; | 221 }; |
222 | 222 |
223 class ScheduledFormSubmission final : public ScheduledNavigation { | 223 class ScheduledFormSubmission final : public ScheduledNavigation { |
224 public: | 224 public: |
225 static PassOwnPtrWillBeRawPtr<ScheduledFormSubmission> create(Document* docu
ment, PassRefPtrWillBeRawPtr<FormSubmission> submission, bool replacesCurrentIte
m) | 225 static RawPtr<ScheduledFormSubmission> create(Document* document, RawPtr<For
mSubmission> submission, bool replacesCurrentItem) |
226 { | 226 { |
227 return adoptPtrWillBeNoop(new ScheduledFormSubmission(document, submissi
on, replacesCurrentItem)); | 227 return new ScheduledFormSubmission(document, submission, replacesCurrent
Item); |
228 } | 228 } |
229 | 229 |
230 void fire(LocalFrame* frame) override | 230 void fire(LocalFrame* frame) override |
231 { | 231 { |
232 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); | 232 OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicat
or(); |
233 FrameLoadRequest frameRequest(originDocument()); | 233 FrameLoadRequest frameRequest(originDocument()); |
234 m_submission->populateFrameLoadRequest(frameRequest); | 234 m_submission->populateFrameLoadRequest(frameRequest); |
235 frameRequest.setReplacesCurrentItem(replacesCurrentItem()); | 235 frameRequest.setReplacesCurrentItem(replacesCurrentItem()); |
236 frameRequest.setTriggeringEvent(m_submission->event()); | 236 frameRequest.setTriggeringEvent(m_submission->event()); |
237 frameRequest.setForm(m_submission->form()); | 237 frameRequest.setForm(m_submission->form()); |
238 frame->loader().load(frameRequest); | 238 frame->loader().load(frameRequest); |
239 } | 239 } |
240 | 240 |
241 DEFINE_INLINE_VIRTUAL_TRACE() | 241 DEFINE_INLINE_VIRTUAL_TRACE() |
242 { | 242 { |
243 visitor->trace(m_submission); | 243 visitor->trace(m_submission); |
244 ScheduledNavigation::trace(visitor); | 244 ScheduledNavigation::trace(visitor); |
245 } | 245 } |
246 | 246 |
247 private: | 247 private: |
248 ScheduledFormSubmission(Document* document, PassRefPtrWillBeRawPtr<FormSubmi
ssion> submission, bool replacesCurrentItem) | 248 ScheduledFormSubmission(Document* document, RawPtr<FormSubmission> submissio
n, bool replacesCurrentItem) |
249 : ScheduledNavigation(0, document, replacesCurrentItem, true) | 249 : ScheduledNavigation(0, document, replacesCurrentItem, true) |
250 , m_submission(submission) | 250 , m_submission(submission) |
251 { | 251 { |
252 ASSERT(m_submission->form()); | 252 ASSERT(m_submission->form()); |
253 } | 253 } |
254 | 254 |
255 RefPtrWillBeMember<FormSubmission> m_submission; | 255 Member<FormSubmission> m_submission; |
256 }; | 256 }; |
257 | 257 |
258 NavigationScheduler::NavigationScheduler(LocalFrame* frame) | 258 NavigationScheduler::NavigationScheduler(LocalFrame* frame) |
259 : m_frame(frame) | 259 : m_frame(frame) |
260 , m_navigateTaskFactory(CancellableTaskFactory::create(this, &NavigationSche
duler::navigateTask)) | 260 , m_navigateTaskFactory(CancellableTaskFactory::create(this, &NavigationSche
duler::navigateTask)) |
261 { | 261 { |
262 } | 262 } |
263 | 263 |
264 NavigationScheduler::~NavigationScheduler() | 264 NavigationScheduler::~NavigationScheduler() |
265 { | 265 { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 schedule(ScheduledLocationChange::create(originDocument, url, replacesCurren
tItem)); | 343 schedule(ScheduledLocationChange::create(originDocument, url, replacesCurren
tItem)); |
344 } | 344 } |
345 | 345 |
346 void NavigationScheduler::schedulePageBlock(Document* originDocument) | 346 void NavigationScheduler::schedulePageBlock(Document* originDocument) |
347 { | 347 { |
348 ASSERT(m_frame->page()); | 348 ASSERT(m_frame->page()); |
349 const KURL& url = m_frame->document()->url(); | 349 const KURL& url = m_frame->document()->url(); |
350 schedule(ScheduledPageBlock::create(originDocument, url)); | 350 schedule(ScheduledPageBlock::create(originDocument, url)); |
351 } | 351 } |
352 | 352 |
353 void NavigationScheduler::scheduleFormSubmission(Document* document, PassRefPtrW
illBeRawPtr<FormSubmission> submission) | 353 void NavigationScheduler::scheduleFormSubmission(Document* document, RawPtr<Form
Submission> submission) |
354 { | 354 { |
355 ASSERT(m_frame->page()); | 355 ASSERT(m_frame->page()); |
356 schedule(ScheduledFormSubmission::create(document, submission, mustReplaceCu
rrentItem(m_frame))); | 356 schedule(ScheduledFormSubmission::create(document, submission, mustReplaceCu
rrentItem(m_frame))); |
357 } | 357 } |
358 | 358 |
359 void NavigationScheduler::scheduleReload() | 359 void NavigationScheduler::scheduleReload() |
360 { | 360 { |
361 if (!shouldScheduleReload()) | 361 if (!shouldScheduleReload()) |
362 return; | 362 return; |
363 if (m_frame->document()->url().isEmpty()) | 363 if (m_frame->document()->url().isEmpty()) |
364 return; | 364 return; |
365 schedule(ScheduledReload::create()); | 365 schedule(ScheduledReload::create()); |
366 } | 366 } |
367 | 367 |
368 void NavigationScheduler::navigateTask() | 368 void NavigationScheduler::navigateTask() |
369 { | 369 { |
370 Platform::current()->currentThread()->scheduler()->removePendingNavigation()
; | 370 Platform::current()->currentThread()->scheduler()->removePendingNavigation()
; |
371 | 371 |
372 if (!m_frame->page()) | 372 if (!m_frame->page()) |
373 return; | 373 return; |
374 if (m_frame->page()->defersLoading()) { | 374 if (m_frame->page()->defersLoading()) { |
375 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); | 375 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
376 return; | 376 return; |
377 } | 377 } |
378 | 378 |
379 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 379 RawPtr<LocalFrame> protect(m_frame.get()); |
380 | 380 |
381 OwnPtrWillBeRawPtr<ScheduledNavigation> redirect(m_redirect.release()); | 381 RawPtr<ScheduledNavigation> redirect(m_redirect.release()); |
382 redirect->fire(m_frame); | 382 redirect->fire(m_frame); |
383 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); | 383 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
384 } | 384 } |
385 | 385 |
386 void NavigationScheduler::schedule(PassOwnPtrWillBeRawPtr<ScheduledNavigation> r
edirect) | 386 void NavigationScheduler::schedule(RawPtr<ScheduledNavigation> redirect) |
387 { | 387 { |
388 ASSERT(m_frame->page()); | 388 ASSERT(m_frame->page()); |
389 | 389 |
390 // In a back/forward navigation, we sometimes restore history state to ifram
es, even though the state was generated | 390 // In a back/forward navigation, we sometimes restore history state to ifram
es, even though the state was generated |
391 // dynamically and JS will try to put something different in the iframe. In
this case, we will load stale things | 391 // dynamically and JS will try to put something different in the iframe. In
this case, we will load stale things |
392 // and/or confuse the JS when it shortly thereafter tries to schedule a loca
tion change. Let the JS have its way. | 392 // and/or confuse the JS when it shortly thereafter tries to schedule a loca
tion change. Let the JS have its way. |
393 // FIXME: This check seems out of place. | 393 // FIXME: This check seems out of place. |
394 if (!m_frame->loader().stateMachine()->committedFirstRealDocumentLoad() && m
_frame->loader().provisionalDocumentLoader()) { | 394 if (!m_frame->loader().stateMachine()->committedFirstRealDocumentLoad() && m
_frame->loader().provisionalDocumentLoader()) { |
395 RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get()); | 395 RawPtr<LocalFrame> protect(m_frame.get()); |
396 m_frame->loader().stopAllLoaders(); | 396 m_frame->loader().stopAllLoaders(); |
397 if (!m_frame->host()) | 397 if (!m_frame->host()) |
398 return; | 398 return; |
399 } | 399 } |
400 | 400 |
401 cancel(); | 401 cancel(); |
402 m_redirect = redirect; | 402 m_redirect = redirect; |
403 startTimer(); | 403 startTimer(); |
404 } | 404 } |
405 | 405 |
(...skipping 26 matching lines...) Expand all Loading... |
432 m_redirect.clear(); | 432 m_redirect.clear(); |
433 } | 433 } |
434 | 434 |
435 DEFINE_TRACE(NavigationScheduler) | 435 DEFINE_TRACE(NavigationScheduler) |
436 { | 436 { |
437 visitor->trace(m_frame); | 437 visitor->trace(m_frame); |
438 visitor->trace(m_redirect); | 438 visitor->trace(m_redirect); |
439 } | 439 } |
440 | 440 |
441 } // namespace blink | 441 } // namespace blink |
OLD | NEW |