Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | #include "WebDataSourceImpl.h" |
| 33 | |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 34 | #include "core/dom/Document.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 35 | #include "public/platform/WebURL.h" |
| 36 | #include "public/platform/WebURLError.h" |
| 37 | #include "public/platform/WebVector.h" |
| 38 | |
| 39 | using namespace WebCore; |
| 40 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 41 | namespace blink { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 42 | |
| 43 | static OwnPtr<WebPluginLoadObserver>& nextPluginLoadObserver() |
| 44 | { |
| 45 | DEFINE_STATIC_LOCAL(OwnPtr<WebPluginLoadObserver>, nextPluginLoadObserver, ()); |
| 46 | return nextPluginLoadObserver; |
| 47 | } |
| 48 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 49 | PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::create(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 50 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 51 | return adoptRef(new WebDataSourceImpl(frame, request, data)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | const WebURLRequest& WebDataSourceImpl::originalRequest() const |
| 55 | { |
| 56 | m_originalRequestWrapper.bind(DocumentLoader::originalRequest()); |
| 57 | return m_originalRequestWrapper; |
| 58 | } |
| 59 | |
| 60 | const WebURLRequest& WebDataSourceImpl::request() const |
| 61 | { |
| 62 | m_requestWrapper.bind(DocumentLoader::request()); |
| 63 | return m_requestWrapper; |
| 64 | } |
| 65 | |
| 66 | const WebURLResponse& WebDataSourceImpl::response() const |
| 67 | { |
| 68 | m_responseWrapper.bind(DocumentLoader::response()); |
| 69 | return m_responseWrapper; |
| 70 | } |
| 71 | |
| 72 | bool WebDataSourceImpl::hasUnreachableURL() const |
| 73 | { |
| 74 | return !DocumentLoader::unreachableURL().isEmpty(); |
| 75 | } |
| 76 | |
| 77 | WebURL WebDataSourceImpl::unreachableURL() const |
| 78 | { |
| 79 | return DocumentLoader::unreachableURL(); |
| 80 | } |
| 81 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 82 | void WebDataSourceImpl::appendRedirect(const WebURL& url) |
| 83 | { |
| 84 | DocumentLoader::appendRedirect(url); |
| 85 | } |
| 86 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 87 | void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const |
| 88 | { |
| 89 | result.assign(m_redirectChain); |
| 90 | } |
| 91 | |
| 92 | bool WebDataSourceImpl::isClientRedirect() const |
| 93 | { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 94 | return DocumentLoader::isClientRedirect(); |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | bool WebDataSourceImpl::replacesCurrentHistoryItem() const |
| 98 | { |
| 99 | return DocumentLoader::replacesCurrentHistoryItem(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 102 | WebNavigationType WebDataSourceImpl::navigationType() const |
| 103 | { |
| 104 | return toWebNavigationType(triggeringAction().type()); |
| 105 | } |
| 106 | |
| 107 | double WebDataSourceImpl::triggeringEventTime() const |
| 108 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 109 | // DOMTimeStamp uses units of milliseconds. |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 110 | return convertDOMTimeStampToSeconds(triggeringAction().eventTimeStamp()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | WebDataSource::ExtraData* WebDataSourceImpl::extraData() const |
| 114 | { |
| 115 | return m_extraData.get(); |
| 116 | } |
| 117 | |
| 118 | void WebDataSourceImpl::setExtraData(ExtraData* extraData) |
| 119 | { |
| 120 | // extraData can't be a PassOwnPtr because setExtraData is a WebKit API function. |
| 121 | m_extraData = adoptPtr(extraData); |
| 122 | } |
| 123 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 124 | void WebDataSourceImpl::setNavigationStartTime(double navigationStart) |
| 125 | { |
| 126 | timing()->setNavigationStart(navigationStart); |
| 127 | } |
| 128 | |
| 129 | WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type) |
| 130 | { |
| 131 | switch (type) { |
| 132 | case NavigationTypeLinkClicked: |
| 133 | return WebNavigationTypeLinkClicked; |
| 134 | case NavigationTypeFormSubmitted: |
| 135 | return WebNavigationTypeFormSubmitted; |
| 136 | case NavigationTypeBackForward: |
| 137 | return WebNavigationTypeBackForward; |
| 138 | case NavigationTypeReload: |
| 139 | return WebNavigationTypeReload; |
| 140 | case NavigationTypeFormResubmitted: |
| 141 | return WebNavigationTypeFormResubmitted; |
| 142 | case NavigationTypeOther: |
| 143 | default: |
| 144 | return WebNavigationTypeOther; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer) |
| 149 | { |
| 150 | nextPluginLoadObserver() = observer; |
| 151 | } |
| 152 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 153 | WebDataSourceImpl::WebDataSourceImpl(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 154 | : DocumentLoader(frame, request, data) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 155 | { |
| 156 | if (!nextPluginLoadObserver()) |
| 157 | return; |
| 158 | // When a new frame is created, it initially gets a data source for an |
| 159 | // empty document. Then it is navigated to the source URL of the |
| 160 | // frame, which results in a second data source being created. We want |
| 161 | // to wait to attach the WebPluginLoadObserver to that data source. |
| 162 | if (request.url().isEmpty()) |
| 163 | return; |
| 164 | |
| 165 | ASSERT(nextPluginLoadObserver()->url() == WebURL(request.url())); |
| 166 | m_pluginLoadObserver = nextPluginLoadObserver().release(); |
| 167 | } |
| 168 | |
| 169 | WebDataSourceImpl::~WebDataSourceImpl() |
| 170 | { |
| 171 | } |
| 172 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 173 | } // namespace blink |