- add sources.
[platform/framework/web/crosswalk.git] / src / content / public / renderer / render_thread.h
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 CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/shared_memory.h"
11 #include "content/common/content_export.h"
12 #include "ipc/ipc_channel_proxy.h"
13 #include "ipc/ipc_sender.h"
14
15 #if defined(OS_WIN)
16 #include <windows.h>
17 #endif
18
19 class GURL;
20
21 namespace base {
22 class MessageLoop;
23 class MessageLoopProxy;
24 }
25
26 namespace IPC {
27 class SyncChannel;
28 class SyncMessageFilter;
29 }
30
31 namespace v8 {
32 class Extension;
33 }
34
35 namespace content {
36
37 class RenderProcessObserver;
38 class ResourceDispatcherDelegate;
39
40 class CONTENT_EXPORT RenderThread : public IPC::Sender {
41  public:
42   // Returns the one render thread for this process.  Note that this can only
43   // be accessed when running on the render thread itself.
44   static RenderThread* Get();
45
46   RenderThread();
47   virtual ~RenderThread();
48
49   virtual base::MessageLoop* GetMessageLoop() = 0;
50   virtual IPC::SyncChannel* GetChannel() = 0;
51   virtual std::string GetLocale() = 0;
52   virtual IPC::SyncMessageFilter* GetSyncMessageFilter() = 0;
53   virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() = 0;
54
55   // Called to add or remove a listener for a particular message routing ID.
56   // These methods normally get delegated to a MessageRouter.
57   virtual void AddRoute(int32 routing_id, IPC::Listener* listener) = 0;
58   virtual void RemoveRoute(int32 routing_id) = 0;
59   virtual int GenerateRoutingID() = 0;
60
61   // These map to IPC::ChannelProxy methods.
62   virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
63   virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) = 0;
64
65   // Add/remove observers for the process.
66   virtual void AddObserver(RenderProcessObserver* observer) = 0;
67   virtual void RemoveObserver(RenderProcessObserver* observer) = 0;
68
69   // Set the ResourceDispatcher delegate object for this process.
70   virtual void SetResourceDispatcherDelegate(
71       ResourceDispatcherDelegate* delegate) = 0;
72
73   // Called by a RenderWidget when it is hidden or restored.
74   virtual void WidgetHidden() = 0;
75   virtual void WidgetRestored() = 0;
76
77   // We initialize WebKit as late as possible. Call this to force
78   // initialization.
79   virtual void EnsureWebKitInitialized() = 0;
80
81   // Helper function to send over a string to be recorded by user metrics
82   virtual void RecordUserMetrics(const std::string& action) = 0;
83
84   // Asks the host to create a block of shared memory for the renderer.
85   // The shared memory allocated by the host is returned back.
86   virtual scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer(
87       size_t buffer_size) = 0;
88
89   // Registers the given V8 extension with WebKit.
90   virtual void RegisterExtension(v8::Extension* extension) = 0;
91
92   // Schedule a call to IdleHandler with the given initial delay.
93   virtual void ScheduleIdleHandler(int64 initial_delay_ms) = 0;
94
95   // A task we invoke periodically to assist with idle cleanup.
96   virtual void IdleHandler() = 0;
97
98   // Get/Set the delay for how often the idle handler is called.
99   virtual int64 GetIdleNotificationDelayInMs() const = 0;
100   virtual void SetIdleNotificationDelayInMs(
101       int64 idle_notification_delay_in_ms) = 0;
102
103   // Suspend/resume the webkit timer for this renderer.
104   virtual void ToggleWebKitSharedTimer(bool suspend) = 0;
105
106   virtual void UpdateHistograms(int sequence_number) = 0;
107
108   // Post task to all worker threads. Returns number of workers.
109   virtual int PostTaskToAllWebWorkers(const base::Closure& closure) = 0;
110
111   // Resolve the proxy servers to use for a given url. On success true is
112   // returned and |proxy_list| is set to a PAC string containing a list of
113   // proxy servers.
114   virtual bool ResolveProxy(const GURL& url, std::string* proxy_list) = 0;
115
116 #if defined(OS_WIN)
117   // Request that the given font be loaded by the browser so it's cached by the
118   // OS. Please see ChildProcessHost::PreCacheFont for details.
119   virtual void PreCacheFont(const LOGFONT& log_font) = 0;
120
121   // Release cached font.
122   virtual void ReleaseCachedFonts() = 0;
123 #endif
124 };
125
126 }  // namespace content
127
128 #endif  // CONTENT_PUBLIC_RENDERER_RENDER_THREAD_H_