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

Side by Side Diff: chrome/renderer/prefetch_helper.cc

Issue 334483004: Enable resource prefetch from the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 6 years, 6 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
« no previous file with comments | « chrome/renderer/prefetch_helper.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/prefetch_helper.h"
6
7 #include "chrome/common/prefetch_messages.h"
8 #include "content/public/renderer/render_frame.h"
9 #include "third_party/WebKit/public/web/WebFrame.h"
10 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
11
12 namespace prefetch {
13
14 PrefetchHelper::PrefetchHelper(content::RenderFrame* render_frame)
15 : content::RenderFrameObserver(render_frame) {
16 }
17
18 PrefetchHelper::~PrefetchHelper() {
19 STLDeleteElements(&loader_set_);
20 }
21
22 bool PrefetchHelper::OnMessageReceived(
23 const IPC::Message& message) {
24 bool handled = true;
25 IPC_BEGIN_MESSAGE_MAP(PrefetchHelper, message)
26 IPC_MESSAGE_HANDLER(PrefetchMsg_Prefetch, OnPrefetch)
27 IPC_MESSAGE_UNHANDLED(handled = false)
28 IPC_END_MESSAGE_MAP()
29
30 return handled;
31 }
32
33 void PrefetchHelper::OnPrefetch(const GURL& url) {
34 blink::WebFrame* frame = render_frame()->GetWebFrame();
35 blink::WebURLRequest request(url);
36 request.setTargetType(blink::WebURLRequest::TargetIsPrefetch);
37 request.setPriority(blink::WebURLRequest::PriorityVeryLow);
38 blink::WebURLLoaderOptions options;
39 options.allowCredentials = true;
40 options.crossOriginRequestPolicy =
41 blink::WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
42 blink::WebURLLoader* loader = frame->createAssociatedURLLoader(options);
43 loader->loadAsynchronously(request, this);
44 loader_set_.insert(loader);
45 }
46
47 void PrefetchHelper::didFinishLoading(blink::WebURLLoader* loader,
48 double finishTime,
49 int64_t totalEncodedDataLength) {
50 loader_set_.erase(loader);
51 }
52
53 void PrefetchHelper::didFail(blink::WebURLLoader* loader,
54 const blink::WebURLError& error) {
55 loader_set_.erase(loader);
56 }
57
58 } // namespace prefetch
OLDNEW
« no previous file with comments | « chrome/renderer/prefetch_helper.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698