| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_ | |
| 6 #define CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_ | |
| 7 | |
| 8 #include "base/clipboard.h" | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/gfx/rect.h" | |
| 11 #include "base/gfx/native_widget_types.h" | |
| 12 #include "base/ref_counted.h" | |
| 13 #include "build/build_config.h" | |
| 14 #include "chrome/browser/net/resolve_proxy_msg_helper.h" | |
| 15 #include "chrome/common/ipc_channel_proxy.h" | |
| 16 #include "chrome/common/notification_observer.h" | |
| 17 #include "webkit/glue/cache_manager.h" | |
| 18 | |
| 19 #if defined(OS_WIN) | |
| 20 #include <windows.h> | |
| 21 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | |
| 22 #else | |
| 23 // TODO(port): port ResourceDispatcherHost. | |
| 24 #include "chrome/common/temp_scaffolding_stubs.h" | |
| 25 #endif | |
| 26 | |
| 27 class ClipboardService; | |
| 28 class Profile; | |
| 29 class RenderWidgetHelper; | |
| 30 class SpellChecker; | |
| 31 struct WebPluginInfo; | |
| 32 | |
| 33 namespace printing { | |
| 34 class PrinterQuery; | |
| 35 class PrintJobManager; | |
| 36 } | |
| 37 | |
| 38 namespace webkit_glue { | |
| 39 struct ScreenInfo; | |
| 40 } | |
| 41 | |
| 42 // This class filters out incoming IPC messages for network requests and | |
| 43 // processes them on the IPC thread. As a result, network requests are not | |
| 44 // delayed by costly UI processing that may be occuring on the main thread of | |
| 45 // the browser. It also means that any hangs in starting a network request | |
| 46 // will not interfere with browser UI. | |
| 47 | |
| 48 class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, | |
| 49 public ResourceDispatcherHost::Receiver, | |
| 50 public NotificationObserver, | |
| 51 public ResolveProxyMsgHelper::Delegate { | |
| 52 public: | |
| 53 // Create the filter. | |
| 54 // Note: because the lifecycle of the ResourceMessageFilter is not | |
| 55 // tied to the lifecycle of the object which created it, the | |
| 56 // ResourceMessageFilter is 'given' ownership of the spellchecker | |
| 57 // object and must clean it up on exit. | |
| 58 ResourceMessageFilter(ResourceDispatcherHost* resource_dispatcher_host, | |
| 59 PluginService* plugin_service, | |
| 60 printing::PrintJobManager* print_job_manager, | |
| 61 int render_process_host_id, | |
| 62 Profile* profile, | |
| 63 RenderWidgetHelper* render_widget_helper, | |
| 64 SpellChecker* spellchecker); | |
| 65 virtual ~ResourceMessageFilter(); | |
| 66 | |
| 67 // IPC::ChannelProxy::MessageFilter methods: | |
| 68 virtual void OnFilterAdded(IPC::Channel* channel); | |
| 69 virtual void OnChannelConnected(int32 peer_pid); | |
| 70 virtual void OnChannelClosing(); | |
| 71 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 72 | |
| 73 // ResourceDispatcherHost::Receiver methods: | |
| 74 virtual bool Send(IPC::Message* message); | |
| 75 | |
| 76 // Access to the spell checker. | |
| 77 SpellChecker* spellchecker() { return spellchecker_.get(); } | |
| 78 | |
| 79 int render_process_host_id() const { return render_process_host_id_;} | |
| 80 | |
| 81 base::ProcessHandle renderer_handle() const { return render_handle_;} | |
| 82 | |
| 83 // NotificationObserver implementation. | |
| 84 virtual void Observe(NotificationType type, | |
| 85 const NotificationSource& source, | |
| 86 const NotificationDetails& details); | |
| 87 | |
| 88 private: | |
| 89 void OnMsgCreateWindow(int opener_id, bool user_gesture, int* route_id, | |
| 90 ModalDialogEvent* modal_dialog_event); | |
| 91 void OnMsgCreateWidget(int opener_id, bool activatable, int* route_id); | |
| 92 void OnRequestResource(const IPC::Message& msg, int request_id, | |
| 93 const ViewHostMsg_Resource_Request& request); | |
| 94 void OnCancelRequest(int request_id); | |
| 95 void OnClosePageACK(int new_render_process_host_id, int new_request_id); | |
| 96 void OnDataReceivedACK(int request_id); | |
| 97 void OnUploadProgressACK(int request_id); | |
| 98 void OnSyncLoad(int request_id, | |
| 99 const ViewHostMsg_Resource_Request& request, | |
| 100 IPC::Message* result_message); | |
| 101 void OnSetCookie(const GURL& url, const GURL& policy_url, | |
| 102 const std::string& cookie); | |
| 103 void OnGetCookies(const GURL& url, const GURL& policy_url, | |
| 104 std::string* cookies); | |
| 105 void OnGetDataDir(std::wstring* data_dir); | |
| 106 void OnPluginMessage(const FilePath& plugin_path, | |
| 107 const std::vector<uint8>& message); | |
| 108 void OnPluginSyncMessage(const FilePath& plugin_path, | |
| 109 const std::vector<uint8>& message, | |
| 110 std::vector<uint8> *retval); | |
| 111 void OnPluginFileDialog(const IPC::Message& msg, | |
| 112 bool multiple_files, | |
| 113 const std::wstring& title, | |
| 114 const std::wstring& filter, | |
| 115 uint32 user_data); | |
| 116 | |
| 117 #if defined(OS_WIN) | |
| 118 // Cache fonts for the renderer. See ResourceMessageFilter::OnLoadFont | |
| 119 // implementation for more details | |
| 120 void OnLoadFont(LOGFONT font); | |
| 121 #endif | |
| 122 | |
| 123 void OnGetScreenInfo(gfx::NativeViewId window, | |
| 124 webkit_glue::ScreenInfo* results); | |
| 125 void OnGetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins); | |
| 126 void OnGetPluginPath(const GURL& url, | |
| 127 const std::string& mime_type, | |
| 128 const std::string& clsid, | |
| 129 FilePath* filename, | |
| 130 std::string* actual_mime_type); | |
| 131 void OnOpenChannelToPlugin(const GURL& url, | |
| 132 const std::string& mime_type, | |
| 133 const std::string& clsid, | |
| 134 const std::wstring& locale, | |
| 135 IPC::Message* reply_msg); | |
| 136 void OnDownloadUrl(const IPC::Message& message, | |
| 137 const GURL& url, | |
| 138 const GURL& referrer); | |
| 139 void OnSpellCheck(const std::wstring& word, | |
| 140 IPC::Message* reply_msg); | |
| 141 void OnDnsPrefetch(const std::vector<std::string>& hostnames); | |
| 142 void OnReceiveContextMenuMsg(const IPC::Message& msg); | |
| 143 // Clipboard messages | |
| 144 void OnClipboardWriteObjects(const Clipboard::ObjectMap& objects); | |
| 145 void OnClipboardIsFormatAvailable(unsigned int format, bool* result); | |
| 146 void OnClipboardReadText(std::wstring* result); | |
| 147 void OnClipboardReadAsciiText(std::string* result); | |
| 148 void OnClipboardReadHTML(std::wstring* markup, GURL* src_url); | |
| 149 #if defined(OS_WIN) | |
| 150 void OnGetWindowRect(gfx::NativeViewId window, gfx::Rect *rect); | |
| 151 void OnGetRootWindowRect(gfx::NativeViewId window, gfx::Rect *rect); | |
| 152 void OnGetRootWindowResizerRect(gfx::NativeViewId window, gfx::Rect *rect); | |
| 153 #endif | |
| 154 void OnGetMimeTypeFromExtension(const std::wstring& ext, | |
| 155 std::string* mime_type); | |
| 156 void OnGetMimeTypeFromFile(const std::wstring& file_path, | |
| 157 std::string* mime_type); | |
| 158 void OnGetPreferredExtensionForMimeType(const std::string& mime_type, | |
| 159 std::wstring* ext); | |
| 160 void OnGetCPBrowsingContext(uint32* context); | |
| 161 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, | |
| 162 base::SharedMemoryHandle* browser_handle); | |
| 163 void OnResourceTypeStats(const CacheManager::ResourceTypeStats& stats); | |
| 164 | |
| 165 void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); | |
| 166 | |
| 167 // ResolveProxyMsgHelper::Delegate implementation: | |
| 168 virtual void OnResolveProxyCompleted(IPC::Message* reply_msg, | |
| 169 int result, | |
| 170 const std::string& proxy_list); | |
| 171 | |
| 172 // A javascript code requested to print the current page. This is done in two | |
| 173 // steps and this is the first step. Get the print setting right here | |
| 174 // synchronously. It will hang the I/O completely. | |
| 175 void OnGetDefaultPrintSettings(IPC::Message* reply_msg); | |
| 176 void OnGetDefaultPrintSettingsReply( | |
| 177 scoped_refptr<printing::PrinterQuery> printer_query, | |
| 178 IPC::Message* reply_msg); | |
| 179 #if defined(OS_WIN) | |
| 180 // A javascript code requested to print the current page. The renderer host | |
| 181 // have to show to the user the print dialog and returns the selected print | |
| 182 // settings. | |
| 183 void OnScriptedPrint(gfx::NativeViewId host_window, | |
| 184 int cookie, | |
| 185 int expected_pages_count, | |
| 186 IPC::Message* reply_msg); | |
| 187 void OnScriptedPrintReply( | |
| 188 scoped_refptr<printing::PrinterQuery> printer_query, | |
| 189 IPC::Message* reply_msg); | |
| 190 #endif | |
| 191 | |
| 192 // We have our own clipboard service because we want to access the clipboard | |
| 193 // on the IO thread instead of forwarding (possibly synchronous) messages to | |
| 194 // the UI thread. | |
| 195 // This instance of the clipboard service should be accessed only on the IO | |
| 196 // thread. | |
| 197 static ClipboardService* GetClipboardService(); | |
| 198 | |
| 199 // The channel associated with the renderer connection. This pointer is not | |
| 200 // owned by this class. | |
| 201 IPC::Channel* channel_; | |
| 202 | |
| 203 // Cached resource request dispatcher host and plugin service, guaranteed to | |
| 204 // be non-null if Init succeeds. We do not own the objects, they are managed | |
| 205 // by the BrowserProcess, which has a wider scope than we do. | |
| 206 ResourceDispatcherHost* resource_dispatcher_host_; | |
| 207 PluginService* plugin_service_; | |
| 208 printing::PrintJobManager* print_job_manager_; | |
| 209 | |
| 210 // ID for the RenderProcessHost that corresponds to this channel. This is | |
| 211 // used by the ResourceDispatcherHost to look up the TabContents that | |
| 212 // originated URLRequest. Since the RenderProcessHost can be destroyed | |
| 213 // before this object, we only hold an ID for lookup. | |
| 214 int render_process_host_id_; | |
| 215 | |
| 216 // Our spellchecker object. | |
| 217 scoped_refptr<SpellChecker> spellchecker_; | |
| 218 | |
| 219 // Helper class for handling PluginProcessHost_ResolveProxy messages (manages | |
| 220 // the requests to the proxy service). | |
| 221 ResolveProxyMsgHelper resolve_proxy_msg_helper_; | |
| 222 | |
| 223 // Process handle of the renderer process. | |
| 224 base::ProcessHandle render_handle_; | |
| 225 | |
| 226 // Contextual information to be used for requests created here. | |
| 227 scoped_refptr<URLRequestContext> request_context_; | |
| 228 | |
| 229 // A pointer to the profile associated with this filter. | |
| 230 // | |
| 231 // DANGER! Do not dereference this pointer! This class lives on the I/O thread | |
| 232 // and the profile may only be used on the UI thread. It is used only for | |
| 233 // determining which notifications to watch for. | |
| 234 // | |
| 235 // This is void* to prevent people from accidentally dereferencing it. | |
| 236 // When registering for observers, cast to Profile*. | |
| 237 void* profile_; | |
| 238 | |
| 239 scoped_refptr<RenderWidgetHelper> render_widget_helper_; | |
| 240 | |
| 241 DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter); | |
| 242 }; | |
| 243 | |
| 244 #endif // CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_ | |
| OLD | NEW |