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. 4 5 #ifndef CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_ 6 #define CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_ 7 8 #include <map> 9 #include <set> 10 #include <vector> 11 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" 17 18 class GURL; 19 20 namespace prerender { 21 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 { 28 public: 29 PrerenderDispatcher(); 30 virtual ~PrerenderDispatcher(); 31 32 bool IsPrerenderURL(const GURL& url) const; 33 34 private: 35 friend class PrerenderDispatcherTest; 36 37 // Message handlers for messages from the browser process. 38 void OnPrerenderStart(int prerender_id); 39 void OnPrerenderStopLoading(int prerender_id); 40 void OnPrerenderAddAlias(const GURL& alias); 41 void OnPrerenderRemoveAliases(const std::vector<GURL>& aliases); 42 void OnPrerenderStop(int prerender_id); 43 44 // From RenderProcessObserver: 45 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; 46 47 // From WebPrerenderingSupport: 48 virtual void add(const blink::WebPrerender& prerender) OVERRIDE; 49 virtual void cancel(const blink::WebPrerender& prerender) OVERRIDE; 50 virtual void abandon(const blink::WebPrerender& prerender) OVERRIDE; 51 52 // From WebKit, prerender elements launched by renderers in our process. 53 std::map<int, blink::WebPrerender> prerenders_; 54 55 // From the browser process, which prerenders are running, indexed by URL. 56 // Updated by the browser processes as aliases are discovered. 57 std::multiset<GURL> running_prerender_urls_; 58 }; 59 60 } // namespace prerender 61 62 #endif // CHROME_RENDERER_PRERENDER_PRERENDER_DISPATCHER_H_ 63