1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/*
2ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block * Copyright (C) 2010 Google Inc. All rights reserved.
38f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Redistribution and use in source and binary forms, with or without
5635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * modification, are permitted provided that the following conditions are
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * met:
78f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
8635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions of source code must retain the above copyright
9635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * notice, this list of conditions and the following disclaimer.
10635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions in binary form must reproduce the above
11635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * copyright notice, this list of conditions and the following disclaimer
12635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * in the documentation and/or other materials provided with the
13635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * distribution.
14635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Neither the name of Google Inc. nor the names of its
15635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * contributors may be used to endorse or promote products derived from
16635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * this software without specific prior written permission.
178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
18635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */
30635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
31ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block#include "config.h"
326b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner#include "PerformanceNavigation.h"
33635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
34ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block#if ENABLE(WEB_TIMING)
35635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
36e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "DocumentLoader.h"
37ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block#include "Frame.h"
38e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "FrameLoaderTypes.h"
39635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
40ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Blocknamespace WebCore {
418f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
426b70adc33054f8aee8c54d0f460458a9df11b8a5Russell BrennerPerformanceNavigation::PerformanceNavigation(Frame* frame)
43ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    : m_frame(frame)
44ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
45ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
46ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
476b70adc33054f8aee8c54d0f460458a9df11b8a5Russell BrennerFrame* PerformanceNavigation::frame() const
48ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
49ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    return m_frame;
50ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
51ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
526b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brennervoid PerformanceNavigation::disconnectFrame()
53ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
54ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    m_frame = 0;
55ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
56ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
576b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brennerunsigned short PerformanceNavigation::type() const
58ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
59ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    if (!m_frame)
60f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        return TYPE_NAVIGATE;
61ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
62e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    DocumentLoader* documentLoader = m_frame->loader()->documentLoader();
63e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    if (!documentLoader)
64f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        return TYPE_NAVIGATE;
65e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
66e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    WebCore::NavigationType navigationType = documentLoader->triggeringAction().type();
67e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    switch (navigationType) {
68e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    case NavigationTypeReload:
69f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        return TYPE_RELOAD;
70e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    case NavigationTypeBackForward:
71f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        return TYPE_BACK_FORWARD;
72e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    default:
73f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch        return TYPE_NAVIGATE;
74e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    }
75ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
76ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
776b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brennerunsigned short PerformanceNavigation::redirectCount() const
78ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
79ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    if (!m_frame)
80ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block        return 0;
81ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
82967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    DocumentLoader* loader = m_frame->loader()->documentLoader();
83967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch    if (!loader)
84967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch        return 0;
85967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch
86cad810f21b803229eb11403f9209855525a25d57Steve Block    DocumentLoadTiming* timing = loader->timing();
87cad810f21b803229eb11403f9209855525a25d57Steve Block    if (timing->hasCrossOriginRedirect)
88cad810f21b803229eb11403f9209855525a25d57Steve Block        return 0;
89cad810f21b803229eb11403f9209855525a25d57Steve Block
90cad810f21b803229eb11403f9209855525a25d57Steve Block    return timing->redirectCount;
91ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
92ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
93ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block} // namespace WebCore
94ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
95ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block#endif // ENABLE(WEB_TIMING)
96