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

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

Issue 21543: Add developer tools message handling to renderer (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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/render_view.h ('k') | chrome/renderer/renderer.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/gfx/png_encoder.h" 12 #include "base/gfx/png_encoder.h"
13 #include "base/gfx/native_widget_types.h" 13 #include "base/gfx/native_widget_types.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/gfx/favicon_size.h" 18 #include "chrome/common/gfx/favicon_size.h"
19 #include "chrome/common/gfx/color_utils.h" 19 #include "chrome/common/gfx/color_utils.h"
20 #include "chrome/common/jstemplate_builder.h" 20 #include "chrome/common/jstemplate_builder.h"
21 #include "chrome/common/l10n_util.h" 21 #include "chrome/common/l10n_util.h"
22 #include "chrome/common/page_zoom.h" 22 #include "chrome/common/page_zoom.h"
23 #include "chrome/common/render_messages.h" 23 #include "chrome/common/render_messages.h"
24 #include "chrome/common/resource_bundle.h" 24 #include "chrome/common/resource_bundle.h"
25 #include "chrome/common/thumbnail_score.h" 25 #include "chrome/common/thumbnail_score.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/renderer/about_handler.h" 27 #include "chrome/renderer/about_handler.h"
28 #include "chrome/renderer/debug_message_handler.h" 28 #include "chrome/renderer/debug_message_handler.h"
29 #include "chrome/renderer/dev_tools_agent.h"
30 #include "chrome/renderer/dev_tools_client.h"
29 #include "chrome/renderer/localized_error.h" 31 #include "chrome/renderer/localized_error.h"
30 #include "chrome/renderer/media/audio_renderer_impl.h" 32 #include "chrome/renderer/media/audio_renderer_impl.h"
31 #include "chrome/renderer/render_process.h" 33 #include "chrome/renderer/render_process.h"
32 #include "chrome/renderer/user_script_slave.h" 34 #include "chrome/renderer/user_script_slave.h"
33 #include "chrome/renderer/visitedlink_slave.h" 35 #include "chrome/renderer/visitedlink_slave.h"
34 #include "chrome/renderer/webmediaplayer_delegate_impl.h" 36 #include "chrome/renderer/webmediaplayer_delegate_impl.h"
35 #include "chrome/renderer/webplugin_delegate_proxy.h" 37 #include "chrome/renderer/webplugin_delegate_proxy.h"
36 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
37 #include "grit/renderer_resources.h" 39 #include "grit/renderer_resources.h"
38 #include "net/base/escape.h" 40 #include "net/base/escape.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 target_url_status_(TARGET_NONE), 164 target_url_status_(TARGET_NONE),
163 is_loading_(false), 165 is_loading_(false),
164 navigation_gesture_(NavigationGestureUnknown), 166 navigation_gesture_(NavigationGestureUnknown),
165 page_id_(-1), 167 page_id_(-1),
166 last_page_id_sent_to_browser_(-1), 168 last_page_id_sent_to_browser_(-1),
167 last_indexed_page_id_(-1), 169 last_indexed_page_id_(-1),
168 opened_by_user_gesture_(true), 170 opened_by_user_gesture_(true),
169 method_factory_(this), 171 method_factory_(this),
170 first_default_plugin_(NULL), 172 first_default_plugin_(NULL),
171 printed_document_width_(0), 173 printed_document_width_(0),
174 dev_tools_agent_(NULL),
175 dev_tools_client_(NULL),
172 history_back_list_count_(0), 176 history_back_list_count_(0),
173 history_forward_list_count_(0), 177 history_forward_list_count_(0),
174 disable_popup_blocking_(false), 178 disable_popup_blocking_(false),
175 has_unload_listener_(false), 179 has_unload_listener_(false),
176 decrement_shared_popup_at_destruction_(false), 180 decrement_shared_popup_at_destruction_(false),
177 waiting_for_create_window_ack_(false), 181 waiting_for_create_window_ack_(false),
178 form_field_autofill_request_id_(0), 182 form_field_autofill_request_id_(0),
179 popup_notification_visible_(false), 183 popup_notification_visible_(false),
180 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) { 184 delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) {
181 resource_dispatcher_ = new ResourceDispatcher(this); 185 resource_dispatcher_ = new ResourceDispatcher(this);
182 #ifdef CHROME_PERSONALIZATION 186 #ifdef CHROME_PERSONALIZATION
183 personalization_ = Personalization::CreateRendererPersonalization(); 187 personalization_ = Personalization::CreateRendererPersonalization();
184 #endif 188 #endif
185 } 189 }
186 190
187 RenderView::~RenderView() { 191 RenderView::~RenderView() {
188 if (decrement_shared_popup_at_destruction_) 192 if (decrement_shared_popup_at_destruction_)
189 shared_popup_counter_->data--; 193 shared_popup_counter_->data--;
190 194
191 resource_dispatcher_->ClearMessageSender(); 195 resource_dispatcher_->ClearMessageSender();
192 // Clear any back-pointers that might still be held by plugins. 196 // Clear any back-pointers that might still be held by plugins.
193 PluginDelegateList::iterator it = plugin_delegates_.begin(); 197 PluginDelegateList::iterator it = plugin_delegates_.begin();
194 while (it != plugin_delegates_.end()) { 198 while (it != plugin_delegates_.end()) {
195 (*it)->DropRenderView(); 199 (*it)->DropRenderView();
196 it = plugin_delegates_.erase(it); 200 it = plugin_delegates_.erase(it);
197 } 201 }
198 202
199 render_thread_->RemoveFilter(debug_message_handler_); 203 render_thread_->RemoveFilter(debug_message_handler_);
204 render_thread_->RemoveFilter(dev_tools_agent_);
200 205
201 #ifdef CHROME_PERSONALIZATION 206 #ifdef CHROME_PERSONALIZATION
202 Personalization::CleanupRendererPersonalization(personalization_); 207 Personalization::CleanupRendererPersonalization(personalization_);
203 personalization_ = NULL; 208 personalization_ = NULL;
204 #endif 209 #endif
205 } 210 }
206 211
207 /*static*/ 212 /*static*/
208 RenderView* RenderView::Create( 213 RenderView* RenderView::Create(
209 RenderThreadBase* render_thread, 214 RenderThreadBase* render_thread,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 modal_dialog_event_.reset(modal_dialog_event); 312 modal_dialog_event_.reset(modal_dialog_event);
308 313
309 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 314 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
310 enable_dom_automation_ = 315 enable_dom_automation_ =
311 command_line.HasSwitch(switches::kDomAutomationController); 316 command_line.HasSwitch(switches::kDomAutomationController);
312 disable_popup_blocking_ = 317 disable_popup_blocking_ =
313 command_line.HasSwitch(switches::kDisablePopupBlocking); 318 command_line.HasSwitch(switches::kDisablePopupBlocking);
314 319
315 debug_message_handler_ = new DebugMessageHandler(this); 320 debug_message_handler_ = new DebugMessageHandler(this);
316 render_thread_->AddFilter(debug_message_handler_); 321 render_thread_->AddFilter(debug_message_handler_);
322
323 dev_tools_agent_ = new DevToolsAgent(this, MessageLoop::current());
324 render_thread_->AddFilter(dev_tools_agent_);
317 } 325 }
318 326
319 void RenderView::OnMessageReceived(const IPC::Message& message) { 327 void RenderView::OnMessageReceived(const IPC::Message& message) {
320 // If the current RenderView instance represents a popup, then we 328 // If the current RenderView instance represents a popup, then we
321 // need to wait for ViewMsg_CreatingNew_ACK to be sent by the browser. 329 // need to wait for ViewMsg_CreatingNew_ACK to be sent by the browser.
322 // As part of this ack we also receive the browser window handle, which 330 // As part of this ack we also receive the browser window handle, which
323 // parents any plugins instantiated in this RenderView instance. 331 // parents any plugins instantiated in this RenderView instance.
324 // Plugins can be instantiated only when we receive the parent window 332 // Plugins can be instantiated only when we receive the parent window
325 // handle as they are child windows. 333 // handle as they are child windows.
326 if (waiting_for_create_window_ack_ && 334 if (waiting_for_create_window_ack_ &&
327 resource_dispatcher_->IsResourceMessage(message)) { 335 resource_dispatcher_->IsResourceMessage(message)) {
328 queued_resource_messages_.push(new IPC::Message(message)); 336 queued_resource_messages_.push(new IPC::Message(message));
329 return; 337 return;
330 } 338 }
331 339
332 // Let the resource dispatcher intercept resource messages first. 340 // Let the resource dispatcher intercept resource messages first.
333 if (resource_dispatcher_->OnMessageReceived(message)) 341 if (resource_dispatcher_->OnMessageReceived(message))
334 return; 342 return;
335 343
344 // If this is developer tools renderer intercept tools messages first.
345 if (dev_tools_client_.get() && dev_tools_client_->OnMessageReceived(message))
346 return;
347
336 IPC_BEGIN_MESSAGE_MAP(RenderView, message) 348 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
337 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) 349 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
338 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) 350 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
339 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) 351 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
340 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) 352 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
341 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) 353 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
342 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText) 354 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
343 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 355 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
344 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) 356 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
345 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) 357 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
346 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) 358 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
347 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) 359 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
348 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) 360 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
349 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) 361 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
350 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) 362 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
351 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) 363 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
352 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) 364 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
353 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) 365 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
354 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) 366 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
355 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 367 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
356 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 368 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
357 IPC_MESSAGE_HANDLER(ViewMsg_InspectElement, OnInspectElement) 369 IPC_MESSAGE_HANDLER(ViewMsg_InspectElement, OnInspectElement)
358 IPC_MESSAGE_HANDLER(ViewMsg_ShowJavaScriptConsole, OnShowJavaScriptConsole) 370 IPC_MESSAGE_HANDLER(ViewMsg_ShowJavaScriptConsole, OnShowJavaScriptConsole)
371 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
359 IPC_MESSAGE_HANDLER(ViewMsg_DownloadImage, OnDownloadImage) 372 IPC_MESSAGE_HANDLER(ViewMsg_DownloadImage, OnDownloadImage)
360 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) 373 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
361 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) 374 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
362 IPC_MESSAGE_HANDLER(ViewMsg_DebugAttach, OnDebugAttach) 375 IPC_MESSAGE_HANDLER(ViewMsg_DebugAttach, OnDebugAttach)
363 IPC_MESSAGE_HANDLER(ViewMsg_DebugDetach, OnDebugDetach) 376 IPC_MESSAGE_HANDLER(ViewMsg_DebugDetach, OnDebugDetach)
364 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) 377 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
365 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest) 378 IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest)
366 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill) 379 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
367 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) 380 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
368 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) 381 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 } 910 }
898 911
899 void RenderView::OnInspectElement(int x, int y) { 912 void RenderView::OnInspectElement(int x, int y) {
900 webview()->InspectElement(x, y); 913 webview()->InspectElement(x, y);
901 } 914 }
902 915
903 void RenderView::OnShowJavaScriptConsole() { 916 void RenderView::OnShowJavaScriptConsole() {
904 webview()->ShowJavaScriptConsole(); 917 webview()->ShowJavaScriptConsole();
905 } 918 }
906 919
920 void RenderView::OnSetupDevToolsClient() {
921 DCHECK(!dev_tools_client_.get());
922 dev_tools_client_.reset(new DevToolsClient(this));
923 }
924
907 void RenderView::OnStopFinding(bool clear_selection) { 925 void RenderView::OnStopFinding(bool clear_selection) {
908 WebView* view = webview(); 926 WebView* view = webview();
909 if (!view) 927 if (!view)
910 return; 928 return;
911 929
912 if (clear_selection) 930 if (clear_selection)
913 view->GetFocusedFrame()->ClearSelection(); 931 view->GetFocusedFrame()->ClearSelection();
914 932
915 WebFrame* frame = view->GetMainFrame(); 933 WebFrame* frame = view->GetMainFrame();
916 while (frame) { 934 while (frame) {
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); 2983 DCHECK(audio_renderers_.Lookup(stream_id) != NULL);
2966 Send(new ViewHostMsg_SetAudioVolume(routing_id_, stream_id, left, right)); 2984 Send(new ViewHostMsg_SetAudioVolume(routing_id_, stream_id, left, right));
2967 } 2985 }
2968 2986
2969 void RenderView::OnResize(const gfx::Size& new_size, 2987 void RenderView::OnResize(const gfx::Size& new_size,
2970 const gfx::Rect& resizer_rect) { 2988 const gfx::Rect& resizer_rect) {
2971 if (webview()) 2989 if (webview())
2972 webview()->HideAutofillPopup(); 2990 webview()->HideAutofillPopup();
2973 RenderWidget::OnResize(new_size, resizer_rect); 2991 RenderWidget::OnResize(new_size, resizer_rect);
2974 } 2992 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/renderer.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698