Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: Source/core/html/HTMLFrameJavaScriptURLOpener.cpp

Issue 221673003: Defer iframe JavaScript URL evaluation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "core/html/HTMLFrameJavaScriptURLOpener.h"
28
29 #include "core/dom/Document.h"
30 #include "core/dom/Microtask.h"
31 #include "core/frame/LocalFrame.h"
32 #include "core/html/HTMLFrameElementBase.h"
33
34 namespace WebCore {
35
36 HTMLFrameJavaScriptURLOpener::Request::Request(PassRefPtr<HTMLFrameElementBase> element)
37 : m_element(element)
38 , m_document(&m_element->document())
39 , m_lastURL(m_element->url())
40 {
41 m_document->didAddPendingResource();
42 }
43
44 HTMLFrameJavaScriptURLOpener::Request::~Request()
45 {
46 m_document->didRemovePendingResource();
47 }
48
49 void HTMLFrameJavaScriptURLOpener::Request::setNameAndOpenURL()
50 {
51 if (!m_element->inDocument())
52 return;
53 if (m_element->url() != m_lastURL)
54 return;
55 m_element->setNameAndOpenURL();
abarth-chromium 2014/04/02 01:02:19 This function eventually calls isURLAllowed(), whi
56 }
57
58 HTMLFrameJavaScriptURLOpener& HTMLFrameJavaScriptURLOpener::instance()
59 {
60 DEFINE_STATIC_LOCAL(HTMLFrameJavaScriptURLOpener, s_instance, ());
61 return s_instance;
62 }
63
64 HTMLFrameJavaScriptURLOpener::HTMLFrameJavaScriptURLOpener()
65 : m_enqueued(false)
66 {
67 }
68
69 HTMLFrameJavaScriptURLOpener::~HTMLFrameJavaScriptURLOpener()
70 {
71 }
72
73 void HTMLFrameJavaScriptURLOpener::microtaskCallback()
74 {
75 instance().processPendingRequests();
76 }
77
78 void HTMLFrameJavaScriptURLOpener::request(PassRefPtr<HTMLFrameElementBase> elem ent)
79 {
80 m_requests.append(adoptRef(new Request(element)));
81 if (m_enqueued)
82 return;
83
84 m_enqueued = true;
85 Microtask::enqueueMicrotask(&HTMLFrameJavaScriptURLOpener::microtaskCallback );
86 }
87
88 void HTMLFrameJavaScriptURLOpener::processPendingRequests()
89 {
90 ASSERT(m_enqueued);
91 m_enqueued = false;
92
93 while (!m_requests.isEmpty()) {
94 Vector<RefPtr<Request> > requests;
95 m_requests.swap(requests);
96 for (size_t i = 0; i < requests.size(); ++i)
97 requests[i]->setNameAndOpenURL();
98 }
99 }
100
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698