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
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_
6 #define CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/public/renderer/render_process_observer.h"
15 #include "third_party/WebKit/public/platform/WebPrerender.h"
16 #include "third_party/WebKit/public/platform/WebPrerenderingSupport.h"
22 // There is one PrerenderDispatcher per render process. It keeps track of which
23 // prerenders were launched from this renderer, and ensures prerender navigation
24 // is triggered on navigation to those. It implements the prerendering interface
25 // supplied to WebKit.
26 class PrerenderDispatcher
: public content::RenderProcessObserver
,
27 public blink::WebPrerenderingSupport
{
29 PrerenderDispatcher();
30 virtual ~PrerenderDispatcher();
32 bool IsPrerenderURL(const GURL
& url
) const;
35 friend class PrerenderDispatcherTest
;
37 // Message handlers for messages from the browser process.
38 void OnPrerenderStart(int prerender_id
);
39 void OnPrerenderStopLoading(int prerender_id
);
40 void OnPrerenderDomContentLoaded(int prerender_id
);
41 void OnPrerenderAddAlias(const GURL
& alias
);
42 void OnPrerenderRemoveAliases(const std::vector
<GURL
>& aliases
);
43 void OnPrerenderStop(int prerender_id
);
45 // From RenderProcessObserver:
46 bool OnControlMessageReceived(const IPC::Message
& message
) override
;
48 // From WebPrerenderingSupport:
49 virtual void add(const blink::WebPrerender
& prerender
) override
;
50 virtual void cancel(const blink::WebPrerender
& prerender
) override
;
51 virtual void abandon(const blink::WebPrerender
& prerender
) override
;
53 // From WebKit, prerender elements launched by renderers in our process.
54 std::map
<int, blink::WebPrerender
> prerenders_
;
56 // From the browser process, which prerenders are running, indexed by URL.
57 // Updated by the browser processes as aliases are discovered.
58 std::multiset
<GURL
> running_prerender_urls_
;
61 } // namespace prerender
63 #endif // CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_