OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 (1 << INTERNAL_COOKIE_EVENT_MAX); | 95 (1 << INTERNAL_COOKIE_EVENT_MAX); |
96 | 96 |
97 // static | 97 // static |
98 const int PrerenderContents::kNumCookieSendTypes = COOKIE_SEND_TYPE_MAX; | 98 const int PrerenderContents::kNumCookieSendTypes = COOKIE_SEND_TYPE_MAX; |
99 | 99 |
100 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { | 100 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { |
101 public: | 101 public: |
102 virtual PrerenderContents* CreatePrerenderContents( | 102 virtual PrerenderContents* CreatePrerenderContents( |
103 PrerenderManager* prerender_manager, Profile* profile, | 103 PrerenderManager* prerender_manager, Profile* profile, |
104 const GURL& url, const content::Referrer& referrer, | 104 const GURL& url, const content::Referrer& referrer, |
105 Origin origin, uint8 experiment_id) OVERRIDE { | 105 Origin origin, uint8 experiment_id) override { |
106 return new PrerenderContents(prerender_manager, profile, | 106 return new PrerenderContents(prerender_manager, profile, |
107 url, referrer, origin, experiment_id); | 107 url, referrer, origin, experiment_id); |
108 } | 108 } |
109 }; | 109 }; |
110 | 110 |
111 // WebContentsDelegateImpl ----------------------------------------------------- | 111 // WebContentsDelegateImpl ----------------------------------------------------- |
112 | 112 |
113 class PrerenderContents::WebContentsDelegateImpl | 113 class PrerenderContents::WebContentsDelegateImpl |
114 : public content::WebContentsDelegate { | 114 : public content::WebContentsDelegate { |
115 public: | 115 public: |
116 explicit WebContentsDelegateImpl(PrerenderContents* prerender_contents) | 116 explicit WebContentsDelegateImpl(PrerenderContents* prerender_contents) |
117 : prerender_contents_(prerender_contents) { | 117 : prerender_contents_(prerender_contents) { |
118 } | 118 } |
119 | 119 |
120 // content::WebContentsDelegate implementation: | 120 // content::WebContentsDelegate implementation: |
121 virtual WebContents* OpenURLFromTab(WebContents* source, | 121 virtual WebContents* OpenURLFromTab(WebContents* source, |
122 const OpenURLParams& params) OVERRIDE { | 122 const OpenURLParams& params) override { |
123 // |OpenURLFromTab| is typically called when a frame performs a navigation | 123 // |OpenURLFromTab| is typically called when a frame performs a navigation |
124 // that requires the browser to perform the transition instead of WebKit. | 124 // that requires the browser to perform the transition instead of WebKit. |
125 // Examples include prerendering a site that redirects to an app URL, | 125 // Examples include prerendering a site that redirects to an app URL, |
126 // or if --enable-strict-site-isolation is specified and the prerendered | 126 // or if --enable-strict-site-isolation is specified and the prerendered |
127 // frame redirects to a different origin. | 127 // frame redirects to a different origin. |
128 // TODO(cbentzel): Consider supporting this if it is a common case during | 128 // TODO(cbentzel): Consider supporting this if it is a common case during |
129 // prerenders. | 129 // prerenders. |
130 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL); | 130 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL); |
131 return NULL; | 131 return NULL; |
132 } | 132 } |
133 | 133 |
134 virtual void CloseContents(content::WebContents* contents) OVERRIDE { | 134 virtual void CloseContents(content::WebContents* contents) override { |
135 prerender_contents_->Destroy(FINAL_STATUS_CLOSED); | 135 prerender_contents_->Destroy(FINAL_STATUS_CLOSED); |
136 } | 136 } |
137 | 137 |
138 virtual void CanDownload( | 138 virtual void CanDownload( |
139 RenderViewHost* render_view_host, | 139 RenderViewHost* render_view_host, |
140 const GURL& url, | 140 const GURL& url, |
141 const std::string& request_method, | 141 const std::string& request_method, |
142 const base::Callback<void(bool)>& callback) OVERRIDE { | 142 const base::Callback<void(bool)>& callback) override { |
143 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); | 143 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); |
144 // Cancel the download. | 144 // Cancel the download. |
145 callback.Run(false); | 145 callback.Run(false); |
146 } | 146 } |
147 | 147 |
148 virtual bool ShouldCreateWebContents( | 148 virtual bool ShouldCreateWebContents( |
149 WebContents* web_contents, | 149 WebContents* web_contents, |
150 int route_id, | 150 int route_id, |
151 WindowContainerType window_container_type, | 151 WindowContainerType window_container_type, |
152 const base::string16& frame_name, | 152 const base::string16& frame_name, |
153 const GURL& target_url, | 153 const GURL& target_url, |
154 const std::string& partition_id, | 154 const std::string& partition_id, |
155 SessionStorageNamespace* session_storage_namespace) OVERRIDE { | 155 SessionStorageNamespace* session_storage_namespace) override { |
156 // Since we don't want to permit child windows that would have a | 156 // Since we don't want to permit child windows that would have a |
157 // window.opener property, terminate prerendering. | 157 // window.opener property, terminate prerendering. |
158 prerender_contents_->Destroy(FINAL_STATUS_CREATE_NEW_WINDOW); | 158 prerender_contents_->Destroy(FINAL_STATUS_CREATE_NEW_WINDOW); |
159 // Cancel the popup. | 159 // Cancel the popup. |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 virtual bool OnGoToEntryOffset(int offset) OVERRIDE { | 163 virtual bool OnGoToEntryOffset(int offset) override { |
164 // This isn't allowed because the history merge operation | 164 // This isn't allowed because the history merge operation |
165 // does not work if there are renderer issued challenges. | 165 // does not work if there are renderer issued challenges. |
166 // TODO(cbentzel): Cancel in this case? May not need to do | 166 // TODO(cbentzel): Cancel in this case? May not need to do |
167 // since render-issued offset navigations are not guaranteed, | 167 // since render-issued offset navigations are not guaranteed, |
168 // but indicates that the page cares about the history. | 168 // but indicates that the page cares about the history. |
169 return false; | 169 return false; |
170 } | 170 } |
171 | 171 |
172 virtual bool ShouldSuppressDialogs() OVERRIDE { | 172 virtual bool ShouldSuppressDialogs() override { |
173 // We still want to show the user the message when they navigate to this | 173 // We still want to show the user the message when they navigate to this |
174 // page, so cancel this prerender. | 174 // page, so cancel this prerender. |
175 prerender_contents_->Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); | 175 prerender_contents_->Destroy(FINAL_STATUS_JAVASCRIPT_ALERT); |
176 // Always suppress JavaScript messages if they're triggered by a page being | 176 // Always suppress JavaScript messages if they're triggered by a page being |
177 // prerendered. | 177 // prerendered. |
178 return true; | 178 return true; |
179 } | 179 } |
180 | 180 |
181 virtual void RegisterProtocolHandler(WebContents* web_contents, | 181 virtual void RegisterProtocolHandler(WebContents* web_contents, |
182 const std::string& protocol, | 182 const std::string& protocol, |
183 const GURL& url, | 183 const GURL& url, |
184 bool user_gesture) OVERRIDE { | 184 bool user_gesture) override { |
185 // TODO(mmenke): Consider supporting this if it is a common case during | 185 // TODO(mmenke): Consider supporting this if it is a common case during |
186 // prerenders. | 186 // prerenders. |
187 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); | 187 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); |
188 } | 188 } |
189 | 189 |
190 virtual gfx::Size GetSizeForNewRenderView( | 190 virtual gfx::Size GetSizeForNewRenderView( |
191 WebContents* web_contents) const OVERRIDE { | 191 WebContents* web_contents) const override { |
192 // Have to set the size of the RenderView on initialization to be sure it is | 192 // Have to set the size of the RenderView on initialization to be sure it is |
193 // set before the RenderView is hidden on all platforms (esp. Android). | 193 // set before the RenderView is hidden on all platforms (esp. Android). |
194 return prerender_contents_->size_; | 194 return prerender_contents_->size_; |
195 } | 195 } |
196 | 196 |
197 private: | 197 private: |
198 PrerenderContents* prerender_contents_; | 198 PrerenderContents* prerender_contents_; |
199 }; | 199 }; |
200 | 200 |
201 void PrerenderContents::Observer::OnPrerenderStopLoading( | 201 void PrerenderContents::Observer::OnPrerenderStopLoading( |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 void PrerenderContents::AddResourceThrottle( | 886 void PrerenderContents::AddResourceThrottle( |
887 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 887 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
888 resource_throttles_.push_back(throttle); | 888 resource_throttles_.push_back(throttle); |
889 } | 889 } |
890 | 890 |
891 void PrerenderContents::AddNetworkBytes(int64 bytes) { | 891 void PrerenderContents::AddNetworkBytes(int64 bytes) { |
892 network_bytes_ += bytes; | 892 network_bytes_ += bytes; |
893 } | 893 } |
894 | 894 |
895 } // namespace prerender | 895 } // namespace prerender |
OLD | NEW |