Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/devtools/renderer_overrides_handler.h" | 5 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/devtools/devtools_protocol_constants.h" | 19 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 20 #include "content/browser/devtools/devtools_tracing_handler.h" | 20 #include "content/browser/devtools/devtools_tracing_handler.h" |
| 21 #include "content/browser/renderer_host/dip_util.h" | 21 #include "content/browser/renderer_host/dip_util.h" |
| 22 #include "content/browser/renderer_host/render_view_host_delegate.h" | 22 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 23 #include "content/browser/renderer_host/render_view_host_impl.h" | 23 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 24 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 25 #include "content/browser/web_contents/web_contents_impl.h" | |
| 26 #include "content/common/cursors/webcursor.h" | |
| 25 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| 28 #include "content/public/browser/devtools_agent_host.h" | 30 #include "content/public/browser/devtools_agent_host.h" |
| 29 #include "content/public/browser/javascript_dialog_manager.h" | 31 #include "content/public/browser/javascript_dialog_manager.h" |
| 30 #include "content/public/browser/navigation_controller.h" | 32 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
| 32 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 35 #include "content/public/browser/storage_partition.h" | 37 #include "content/public/browser/storage_partition.h" |
| 36 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 38 #include "content/public/common/content_client.h" | 40 #include "content/public/common/content_client.h" |
| 39 #include "content/public/common/page_transition_types.h" | 41 #include "content/public/common/page_transition_types.h" |
| 40 #include "content/public/common/referrer.h" | 42 #include "content/public/common/referrer.h" |
| 41 #include "ipc/ipc_sender.h" | 43 #include "ipc/ipc_sender.h" |
| 42 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 45 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | |
| 43 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 46 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 44 #include "third_party/WebKit/public/web/WebInputEvent.h" | 47 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 45 #include "ui/gfx/codec/jpeg_codec.h" | 48 #include "ui/gfx/codec/jpeg_codec.h" |
| 46 #include "ui/gfx/codec/png_codec.h" | 49 #include "ui/gfx/codec/png_codec.h" |
| 47 #include "ui/gfx/display.h" | 50 #include "ui/gfx/display.h" |
| 48 #include "ui/gfx/screen.h" | 51 #include "ui/gfx/screen.h" |
| 49 #include "ui/gfx/size_conversions.h" | 52 #include "ui/gfx/size_conversions.h" |
| 50 #include "ui/snapshot/snapshot.h" | 53 #include "ui/snapshot/snapshot.h" |
| 51 #include "url/gurl.h" | 54 #include "url/gurl.h" |
| 52 #include "webkit/browser/quota/quota_manager.h" | 55 #include "webkit/browser/quota/quota_manager.h" |
| 53 | 56 |
| 54 using blink::WebGestureEvent; | 57 using blink::WebGestureEvent; |
| 55 using blink::WebInputEvent; | 58 using blink::WebInputEvent; |
| 56 using blink::WebMouseEvent; | 59 using blink::WebMouseEvent; |
| 57 | 60 |
| 58 namespace content { | 61 namespace content { |
| 59 | 62 |
| 60 namespace { | 63 namespace { |
| 61 | 64 |
| 62 static const char kPng[] = "png"; | 65 static const char kPng[] = "png"; |
| 63 static const char kJpeg[] = "jpeg"; | 66 static const char kJpeg[] = "jpeg"; |
| 64 static int kDefaultScreenshotQuality = 80; | 67 static int kDefaultScreenshotQuality = 80; |
| 65 static int kFrameRateThresholdMs = 100; | 68 static int kFrameRateThresholdMs = 100; |
| 66 static int kCaptureRetryLimit = 2; | 69 static int kCaptureRetryLimit = 2; |
| 67 | 70 |
| 68 } // namespace | 71 } // namespace |
| 69 | 72 |
| 70 RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) | 73 RendererOverridesHandler::RendererOverridesHandler() |
| 71 : agent_(agent), | 74 : has_last_compositor_frame_metadata_(false), |
| 72 has_last_compositor_frame_metadata_(false), | |
| 73 capture_retry_count_(0), | 75 capture_retry_count_(0), |
| 76 color_picker_enabled_(false), | |
| 74 weak_factory_(this) { | 77 weak_factory_(this) { |
| 75 RegisterCommandHandler( | 78 RegisterCommandHandler( |
| 76 devtools::DOM::setFileInputFiles::kName, | 79 devtools::DOM::setFileInputFiles::kName, |
| 77 base::Bind( | 80 base::Bind( |
| 78 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, | 81 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, |
| 79 base::Unretained(this))); | 82 base::Unretained(this))); |
| 80 RegisterCommandHandler( | 83 RegisterCommandHandler( |
| 81 devtools::Network::clearBrowserCache::kName, | 84 devtools::Network::clearBrowserCache::kName, |
| 82 base::Bind( | 85 base::Bind( |
| 83 &RendererOverridesHandler::ClearBrowserCache, | 86 &RendererOverridesHandler::ClearBrowserCache, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 devtools::Page::stopScreencast::kName, | 138 devtools::Page::stopScreencast::kName, |
| 136 base::Bind( | 139 base::Bind( |
| 137 &RendererOverridesHandler::PageStopScreencast, | 140 &RendererOverridesHandler::PageStopScreencast, |
| 138 base::Unretained(this))); | 141 base::Unretained(this))); |
| 139 RegisterCommandHandler( | 142 RegisterCommandHandler( |
| 140 devtools::Page::queryUsageAndQuota::kName, | 143 devtools::Page::queryUsageAndQuota::kName, |
| 141 base::Bind( | 144 base::Bind( |
| 142 &RendererOverridesHandler::PageQueryUsageAndQuota, | 145 &RendererOverridesHandler::PageQueryUsageAndQuota, |
| 143 base::Unretained(this))); | 146 base::Unretained(this))); |
| 144 RegisterCommandHandler( | 147 RegisterCommandHandler( |
| 148 devtools::Page::setColorPickerEnabled::kName, | |
| 149 base::Bind( | |
| 150 &RendererOverridesHandler::PageSetColorPickerEnabled, | |
| 151 base::Unretained(this))); | |
| 152 RegisterCommandHandler( | |
| 145 devtools::Input::emulateTouchFromMouseEvent::kName, | 153 devtools::Input::emulateTouchFromMouseEvent::kName, |
| 146 base::Bind( | 154 base::Bind( |
| 147 &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, | 155 &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, |
| 148 base::Unretained(this))); | 156 base::Unretained(this))); |
| 157 mouse_event_callback_ = base::Bind( | |
| 158 &RendererOverridesHandler::HandleMouseEvent, | |
| 159 base::Unretained(this)); | |
| 149 } | 160 } |
| 150 | 161 |
| 151 RendererOverridesHandler::~RendererOverridesHandler() {} | 162 RendererOverridesHandler::~RendererOverridesHandler() {} |
| 152 | 163 |
| 153 void RendererOverridesHandler::OnClientDetached() { | 164 void RendererOverridesHandler::OnClientDetached() { |
| 154 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 165 if (screencast_command_ && host_) |
| 155 if (screencast_command_ && host) | 166 host_->SetTouchEventEmulationEnabled(false, false); |
| 156 host->SetTouchEventEmulationEnabled(false, false); | |
| 157 screencast_command_ = NULL; | 167 screencast_command_ = NULL; |
| 168 SetColorPickerEnabled(false); | |
| 158 } | 169 } |
| 159 | 170 |
| 160 void RendererOverridesHandler::OnSwapCompositorFrame( | 171 void RendererOverridesHandler::OnSwapCompositorFrame( |
| 161 const cc::CompositorFrameMetadata& frame_metadata) { | 172 const cc::CompositorFrameMetadata& frame_metadata) { |
| 162 last_compositor_frame_metadata_ = frame_metadata; | 173 last_compositor_frame_metadata_ = frame_metadata; |
| 163 has_last_compositor_frame_metadata_ = true; | 174 has_last_compositor_frame_metadata_ = true; |
| 164 | 175 |
| 165 if (screencast_command_) | 176 if (screencast_command_) |
| 166 InnerSwapCompositorFrame(); | 177 InnerSwapCompositorFrame(); |
| 178 if (color_picker_enabled_) | |
| 179 UpdateColorPickerFrame(); | |
| 167 } | 180 } |
| 168 | 181 |
| 169 void RendererOverridesHandler::OnVisibilityChanged(bool visible) { | 182 void RendererOverridesHandler::OnVisibilityChanged(bool visible) { |
| 170 if (!screencast_command_) | 183 if (!screencast_command_) |
| 171 return; | 184 return; |
| 172 NotifyScreencastVisibility(visible); | 185 NotifyScreencastVisibility(visible); |
| 173 } | 186 } |
| 174 | 187 |
| 175 void RendererOverridesHandler::OnRenderViewHostChanged() { | 188 void RendererOverridesHandler::SetRenderViewHost( |
| 176 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 189 RenderViewHostImpl* host) { |
| 190 host_ = host; | |
| 177 if (screencast_command_ && host) | 191 if (screencast_command_ && host) |
| 178 host->SetTouchEventEmulationEnabled(true, true); | 192 host->SetTouchEventEmulationEnabled(true, true); |
| 193 if (color_picker_enabled_) | |
| 194 host->AddMouseEventCallback(mouse_event_callback_); | |
| 195 } | |
| 196 | |
| 197 void RendererOverridesHandler::ClearRenderViewHost() { | |
| 198 if (host_) | |
| 199 host_->RemoveMouseEventCallback(mouse_event_callback_); | |
| 200 host_ = NULL; | |
| 179 } | 201 } |
| 180 | 202 |
| 181 bool RendererOverridesHandler::OnSetTouchEventEmulationEnabled() { | 203 bool RendererOverridesHandler::OnSetTouchEventEmulationEnabled() { |
| 182 return screencast_command_.get() != NULL; | 204 return screencast_command_.get() != NULL; |
| 183 } | 205 } |
| 184 | 206 |
| 185 void RendererOverridesHandler::InnerSwapCompositorFrame() { | 207 void RendererOverridesHandler::InnerSwapCompositorFrame() { |
| 186 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() < | 208 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() < |
| 187 kFrameRateThresholdMs) { | 209 kFrameRateThresholdMs) { |
| 188 return; | 210 return; |
| 189 } | 211 } |
| 190 | 212 |
| 191 RenderViewHost* host = GetRenderViewHostImpl(); | 213 if (!host_ || !host_->GetView()) |
| 192 if (!host->GetView()) | |
| 193 return; | 214 return; |
| 194 | 215 |
| 195 last_frame_time_ = base::TimeTicks::Now(); | 216 last_frame_time_ = base::TimeTicks::Now(); |
| 196 | 217 |
| 197 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 218 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 198 host->GetView()); | 219 host_->GetView()); |
| 199 // TODO(vkuzkokov): do not use previous frame metadata. | 220 // TODO(vkuzkokov): do not use previous frame metadata. |
| 200 cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; | 221 cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; |
| 201 | 222 |
| 202 float page_scale = metadata.page_scale_factor; | 223 float page_scale = metadata.page_scale_factor; |
| 203 gfx::SizeF viewport_size_dip = gfx::ScaleSize( | 224 gfx::SizeF viewport_size_dip = gfx::ScaleSize( |
| 204 metadata.scrollable_viewport_size, page_scale); | 225 metadata.scrollable_viewport_size, page_scale); |
| 205 | 226 |
| 206 float total_bar_height_dip = metadata.location_bar_content_translation.y() + | 227 float total_bar_height_dip = metadata.location_bar_content_translation.y() + |
| 207 metadata.overdraw_bottom_height; | 228 metadata.overdraw_bottom_height; |
| 208 gfx::SizeF screen_size_dip(viewport_size_dip.width(), | 229 gfx::SizeF screen_size_dip(viewport_size_dip.width(), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 284 |
| 264 scoped_refptr<DevToolsProtocol::Response> | 285 scoped_refptr<DevToolsProtocol::Response> |
| 265 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( | 286 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| 266 scoped_refptr<DevToolsProtocol::Command> command) { | 287 scoped_refptr<DevToolsProtocol::Command> command) { |
| 267 base::DictionaryValue* params = command->params(); | 288 base::DictionaryValue* params = command->params(); |
| 268 base::ListValue* file_list = NULL; | 289 base::ListValue* file_list = NULL; |
| 269 const char* param = | 290 const char* param = |
| 270 devtools::DOM::setFileInputFiles::kParamFiles; | 291 devtools::DOM::setFileInputFiles::kParamFiles; |
| 271 if (!params || !params->GetList(param, &file_list)) | 292 if (!params || !params->GetList(param, &file_list)) |
| 272 return command->InvalidParamResponse(param); | 293 return command->InvalidParamResponse(param); |
| 273 RenderViewHost* host = GetRenderViewHostImpl(); | 294 if (!host_) |
| 274 if (!host) | |
| 275 return NULL; | 295 return NULL; |
| 276 | 296 |
| 277 for (size_t i = 0; i < file_list->GetSize(); ++i) { | 297 for (size_t i = 0; i < file_list->GetSize(); ++i) { |
| 278 base::FilePath::StringType file; | 298 base::FilePath::StringType file; |
| 279 if (!file_list->GetString(i, &file)) | 299 if (!file_list->GetString(i, &file)) |
| 280 return command->InvalidParamResponse(param); | 300 return command->InvalidParamResponse(param); |
| 281 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | 301 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 282 host->GetProcess()->GetID(), base::FilePath(file)); | 302 host_->GetProcess()->GetID(), base::FilePath(file)); |
| 283 } | 303 } |
| 284 return NULL; | 304 return NULL; |
| 285 } | 305 } |
| 286 | 306 |
| 287 | 307 |
| 288 // Network agent handlers ---------------------------------------------------- | 308 // Network agent handlers ---------------------------------------------------- |
| 289 | 309 |
| 290 scoped_refptr<DevToolsProtocol::Response> | 310 scoped_refptr<DevToolsProtocol::Response> |
| 291 RendererOverridesHandler::ClearBrowserCache( | 311 RendererOverridesHandler::ClearBrowserCache( |
| 292 scoped_refptr<DevToolsProtocol::Command> command) { | 312 scoped_refptr<DevToolsProtocol::Command> command) { |
| 293 GetContentClient()->browser()->ClearCache(GetRenderViewHostImpl()); | 313 GetContentClient()->browser()->ClearCache(host_); |
| 294 return command->SuccessResponse(NULL); | 314 return command->SuccessResponse(NULL); |
| 295 } | 315 } |
| 296 | 316 |
| 297 scoped_refptr<DevToolsProtocol::Response> | 317 scoped_refptr<DevToolsProtocol::Response> |
| 298 RendererOverridesHandler::ClearBrowserCookies( | 318 RendererOverridesHandler::ClearBrowserCookies( |
| 299 scoped_refptr<DevToolsProtocol::Command> command) { | 319 scoped_refptr<DevToolsProtocol::Command> command) { |
| 300 GetContentClient()->browser()->ClearCookies(GetRenderViewHostImpl()); | 320 GetContentClient()->browser()->ClearCookies(host_); |
| 301 return command->SuccessResponse(NULL); | 321 return command->SuccessResponse(NULL); |
| 302 } | 322 } |
| 303 | 323 |
| 304 | 324 |
| 305 // Page agent handlers ------------------------------------------------------- | 325 // Page agent handlers ------------------------------------------------------- |
| 306 | 326 |
| 307 scoped_refptr<DevToolsProtocol::Response> | 327 scoped_refptr<DevToolsProtocol::Response> |
| 308 RendererOverridesHandler::PageDisable( | 328 RendererOverridesHandler::PageDisable( |
| 309 scoped_refptr<DevToolsProtocol::Command> command) { | 329 scoped_refptr<DevToolsProtocol::Command> command) { |
| 310 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 330 if (screencast_command_ && host_) |
| 311 if (screencast_command_ && host) | 331 host_->SetTouchEventEmulationEnabled(false, false); |
| 312 host->SetTouchEventEmulationEnabled(false, false); | |
| 313 screencast_command_ = NULL; | 332 screencast_command_ = NULL; |
| 314 return NULL; | 333 return NULL; |
| 315 } | 334 } |
| 316 | 335 |
| 317 scoped_refptr<DevToolsProtocol::Response> | 336 scoped_refptr<DevToolsProtocol::Response> |
| 318 RendererOverridesHandler::PageHandleJavaScriptDialog( | 337 RendererOverridesHandler::PageHandleJavaScriptDialog( |
| 319 scoped_refptr<DevToolsProtocol::Command> command) { | 338 scoped_refptr<DevToolsProtocol::Command> command) { |
| 320 base::DictionaryValue* params = command->params(); | 339 base::DictionaryValue* params = command->params(); |
| 321 const char* paramAccept = | 340 const char* paramAccept = |
| 322 devtools::Page::handleJavaScriptDialog::kParamAccept; | 341 devtools::Page::handleJavaScriptDialog::kParamAccept; |
| 323 bool accept = false; | 342 bool accept = false; |
| 324 if (!params || !params->GetBoolean(paramAccept, &accept)) | 343 if (!params || !params->GetBoolean(paramAccept, &accept)) |
| 325 return command->InvalidParamResponse(paramAccept); | 344 return command->InvalidParamResponse(paramAccept); |
| 326 base::string16 prompt_override; | 345 base::string16 prompt_override; |
| 327 base::string16* prompt_override_ptr = &prompt_override; | 346 base::string16* prompt_override_ptr = &prompt_override; |
| 328 if (!params || !params->GetString( | 347 if (!params || !params->GetString( |
| 329 devtools::Page::handleJavaScriptDialog::kParamPromptText, | 348 devtools::Page::handleJavaScriptDialog::kParamPromptText, |
| 330 prompt_override_ptr)) { | 349 prompt_override_ptr)) { |
| 331 prompt_override_ptr = NULL; | 350 prompt_override_ptr = NULL; |
| 332 } | 351 } |
| 333 | 352 |
| 334 WebContents* web_contents = agent_->GetWebContents(); | 353 if (!host_) |
| 354 return command->InternalErrorResponse("Could not connect to view"); | |
| 355 | |
| 356 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | |
| 335 if (web_contents) { | 357 if (web_contents) { |
| 336 JavaScriptDialogManager* manager = | 358 JavaScriptDialogManager* manager = |
| 337 web_contents->GetDelegate()->GetJavaScriptDialogManager(); | 359 web_contents->GetDelegate()->GetJavaScriptDialogManager(); |
| 338 if (manager && manager->HandleJavaScriptDialog( | 360 if (manager && manager->HandleJavaScriptDialog( |
| 339 web_contents, accept, prompt_override_ptr)) { | 361 web_contents, accept, prompt_override_ptr)) { |
| 340 return command->SuccessResponse(new base::DictionaryValue()); | 362 return command->SuccessResponse(new base::DictionaryValue()); |
| 341 } | 363 } |
| 342 } | 364 } |
| 343 return command->InternalErrorResponse("No JavaScript dialog to handle"); | 365 return command->InternalErrorResponse("No JavaScript dialog to handle"); |
| 344 } | 366 } |
| 345 | 367 |
| 346 scoped_refptr<DevToolsProtocol::Response> | 368 scoped_refptr<DevToolsProtocol::Response> |
| 347 RendererOverridesHandler::PageNavigate( | 369 RendererOverridesHandler::PageNavigate( |
| 348 scoped_refptr<DevToolsProtocol::Command> command) { | 370 scoped_refptr<DevToolsProtocol::Command> command) { |
| 349 base::DictionaryValue* params = command->params(); | 371 base::DictionaryValue* params = command->params(); |
| 350 std::string url; | 372 std::string url; |
| 351 const char* param = devtools::Page::navigate::kParamUrl; | 373 const char* param = devtools::Page::navigate::kParamUrl; |
| 352 if (!params || !params->GetString(param, &url)) | 374 if (!params || !params->GetString(param, &url)) |
| 353 return command->InvalidParamResponse(param); | 375 return command->InvalidParamResponse(param); |
| 354 | 376 |
| 355 GURL gurl(url); | 377 GURL gurl(url); |
| 356 if (!gurl.is_valid()) | 378 if (!gurl.is_valid()) |
| 357 return command->InternalErrorResponse("Cannot navigate to invalid URL"); | 379 return command->InternalErrorResponse("Cannot navigate to invalid URL"); |
| 358 | 380 |
| 359 WebContents* web_contents = agent_->GetWebContents(); | 381 if (!host_) |
| 382 return command->InternalErrorResponse("Could not connect to view"); | |
| 383 | |
| 384 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | |
| 360 if (web_contents) { | 385 if (web_contents) { |
| 361 web_contents->GetController() | 386 web_contents->GetController() |
| 362 .LoadURL(gurl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 387 .LoadURL(gurl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| 363 // Fall through into the renderer. | 388 // Fall through into the renderer. |
| 364 return NULL; | 389 return NULL; |
| 365 } | 390 } |
| 366 | 391 |
| 367 return command->InternalErrorResponse("No WebContents to navigate"); | 392 return command->InternalErrorResponse("No WebContents to navigate"); |
| 368 } | 393 } |
| 369 | 394 |
| 370 scoped_refptr<DevToolsProtocol::Response> | 395 scoped_refptr<DevToolsProtocol::Response> |
| 371 RendererOverridesHandler::PageReload( | 396 RendererOverridesHandler::PageReload( |
| 372 scoped_refptr<DevToolsProtocol::Command> command) { | 397 scoped_refptr<DevToolsProtocol::Command> command) { |
| 373 WebContents* web_contents = agent_->GetWebContents(); | 398 if (!host_) |
| 399 return command->InternalErrorResponse("Could not connect to view"); | |
| 400 | |
| 401 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | |
| 374 if (web_contents) { | 402 if (web_contents) { |
| 375 // Override only if it is crashed. | 403 // Override only if it is crashed. |
| 376 if (!web_contents->IsCrashed()) | 404 if (!web_contents->IsCrashed()) |
| 377 return NULL; | 405 return NULL; |
| 378 | 406 |
| 379 web_contents->GetController().Reload(false); | 407 web_contents->GetController().Reload(false); |
| 380 return command->SuccessResponse(NULL); | 408 return command->SuccessResponse(NULL); |
| 381 } | 409 } |
| 382 return command->InternalErrorResponse("No WebContents to reload"); | 410 return command->InternalErrorResponse("No WebContents to reload"); |
| 383 } | 411 } |
| 384 | 412 |
| 385 scoped_refptr<DevToolsProtocol::Response> | 413 scoped_refptr<DevToolsProtocol::Response> |
| 386 RendererOverridesHandler::PageGetNavigationHistory( | 414 RendererOverridesHandler::PageGetNavigationHistory( |
| 387 scoped_refptr<DevToolsProtocol::Command> command) { | 415 scoped_refptr<DevToolsProtocol::Command> command) { |
| 388 WebContents* web_contents = agent_->GetWebContents(); | 416 if (!host_) |
| 417 return command->InternalErrorResponse("Could not connect to view"); | |
| 418 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | |
| 389 if (web_contents) { | 419 if (web_contents) { |
| 390 base::DictionaryValue* result = new base::DictionaryValue(); | 420 base::DictionaryValue* result = new base::DictionaryValue(); |
| 391 NavigationController& controller = web_contents->GetController(); | 421 NavigationController& controller = web_contents->GetController(); |
| 392 result->SetInteger( | 422 result->SetInteger( |
| 393 devtools::Page::getNavigationHistory::kResponseCurrentIndex, | 423 devtools::Page::getNavigationHistory::kResponseCurrentIndex, |
| 394 controller.GetCurrentEntryIndex()); | 424 controller.GetCurrentEntryIndex()); |
| 395 base::ListValue* entries = new base::ListValue(); | 425 base::ListValue* entries = new base::ListValue(); |
| 396 for (int i = 0; i != controller.GetEntryCount(); ++i) { | 426 for (int i = 0; i != controller.GetEntryCount(); ++i) { |
| 397 const NavigationEntry* entry = controller.GetEntryAtIndex(i); | 427 const NavigationEntry* entry = controller.GetEntryAtIndex(i); |
| 398 base::DictionaryValue* entry_value = new base::DictionaryValue(); | 428 base::DictionaryValue* entry_value = new base::DictionaryValue(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 418 scoped_refptr<DevToolsProtocol::Response> | 448 scoped_refptr<DevToolsProtocol::Response> |
| 419 RendererOverridesHandler::PageNavigateToHistoryEntry( | 449 RendererOverridesHandler::PageNavigateToHistoryEntry( |
| 420 scoped_refptr<DevToolsProtocol::Command> command) { | 450 scoped_refptr<DevToolsProtocol::Command> command) { |
| 421 base::DictionaryValue* params = command->params(); | 451 base::DictionaryValue* params = command->params(); |
| 422 const char* param = devtools::Page::navigateToHistoryEntry::kParamEntryId; | 452 const char* param = devtools::Page::navigateToHistoryEntry::kParamEntryId; |
| 423 int entry_id = 0; | 453 int entry_id = 0; |
| 424 if (!params || !params->GetInteger(param, &entry_id)) { | 454 if (!params || !params->GetInteger(param, &entry_id)) { |
| 425 return command->InvalidParamResponse(param); | 455 return command->InvalidParamResponse(param); |
| 426 } | 456 } |
| 427 | 457 |
| 428 WebContents* web_contents = agent_->GetWebContents(); | 458 if (!host_) |
| 459 return command->InternalErrorResponse("Could not connect to view"); | |
| 460 | |
| 461 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | |
| 429 if (web_contents) { | 462 if (web_contents) { |
| 430 NavigationController& controller = web_contents->GetController(); | 463 NavigationController& controller = web_contents->GetController(); |
| 431 for (int i = 0; i != controller.GetEntryCount(); ++i) { | 464 for (int i = 0; i != controller.GetEntryCount(); ++i) { |
| 432 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { | 465 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { |
| 433 controller.GoToIndex(i); | 466 controller.GoToIndex(i); |
| 434 return command->SuccessResponse(new base::DictionaryValue()); | 467 return command->SuccessResponse(new base::DictionaryValue()); |
| 435 } | 468 } |
| 436 } | 469 } |
| 437 return command->InvalidParamResponse(param); | 470 return command->InvalidParamResponse(param); |
| 438 } | 471 } |
| 439 return command->InternalErrorResponse("No WebContents to navigate"); | 472 return command->InternalErrorResponse("No WebContents to navigate"); |
| 440 } | 473 } |
| 441 | 474 |
| 442 scoped_refptr<DevToolsProtocol::Response> | 475 scoped_refptr<DevToolsProtocol::Response> |
| 443 RendererOverridesHandler::PageCaptureScreenshot( | 476 RendererOverridesHandler::PageCaptureScreenshot( |
| 444 scoped_refptr<DevToolsProtocol::Command> command) { | 477 scoped_refptr<DevToolsProtocol::Command> command) { |
| 445 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 478 if (!host_ || !host_->GetView()) |
| 446 if (!host->GetView()) | 479 return command->InternalErrorResponse("Could not connect to view"); |
| 447 return command->InternalErrorResponse("Unable to access the view"); | |
| 448 | 480 |
| 449 host->GetSnapshotFromBrowser( | 481 host_->GetSnapshotFromBrowser( |
| 450 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, | 482 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
| 451 weak_factory_.GetWeakPtr(), command)); | 483 weak_factory_.GetWeakPtr(), command)); |
| 452 return command->AsyncResponsePromise(); | 484 return command->AsyncResponsePromise(); |
| 453 } | 485 } |
| 454 | 486 |
| 455 void RendererOverridesHandler::ScreenshotCaptured( | 487 void RendererOverridesHandler::ScreenshotCaptured( |
| 456 scoped_refptr<DevToolsProtocol::Command> command, | 488 scoped_refptr<DevToolsProtocol::Command> command, |
| 457 const unsigned char* png_data, | 489 const unsigned char* png_data, |
| 458 size_t png_size) { | 490 size_t png_size) { |
| 459 if (!png_data || !png_size) { | 491 if (!png_data || !png_size) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 483 #else | 515 #else |
| 484 result->SetBoolean(devtools::kResult, false); | 516 result->SetBoolean(devtools::kResult, false); |
| 485 #endif // defined(OS_ANDROID) | 517 #endif // defined(OS_ANDROID) |
| 486 return command->SuccessResponse(result); | 518 return command->SuccessResponse(result); |
| 487 } | 519 } |
| 488 | 520 |
| 489 scoped_refptr<DevToolsProtocol::Response> | 521 scoped_refptr<DevToolsProtocol::Response> |
| 490 RendererOverridesHandler::PageStartScreencast( | 522 RendererOverridesHandler::PageStartScreencast( |
| 491 scoped_refptr<DevToolsProtocol::Command> command) { | 523 scoped_refptr<DevToolsProtocol::Command> command) { |
| 492 screencast_command_ = command; | 524 screencast_command_ = command; |
| 493 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 525 if (!host_) |
| 494 host->SetTouchEventEmulationEnabled(true, true); | 526 return command->InternalErrorResponse("Could not connect to view"); |
| 495 bool visible = !host->is_hidden(); | 527 host_->SetTouchEventEmulationEnabled(true, true); |
| 528 bool visible = !host_->is_hidden(); | |
| 496 NotifyScreencastVisibility(visible); | 529 NotifyScreencastVisibility(visible); |
| 497 if (visible) { | 530 if (visible) { |
| 498 if (has_last_compositor_frame_metadata_) | 531 if (has_last_compositor_frame_metadata_) |
| 499 InnerSwapCompositorFrame(); | 532 InnerSwapCompositorFrame(); |
| 500 else | 533 else |
| 501 host->Send(new ViewMsg_ForceRedraw(host->GetRoutingID(), 0)); | 534 host_->Send(new ViewMsg_ForceRedraw(host_->GetRoutingID(), 0)); |
| 502 } | 535 } |
| 503 return command->SuccessResponse(NULL); | 536 return command->SuccessResponse(NULL); |
| 504 } | 537 } |
| 505 | 538 |
| 506 scoped_refptr<DevToolsProtocol::Response> | 539 scoped_refptr<DevToolsProtocol::Response> |
| 507 RendererOverridesHandler::PageStopScreencast( | 540 RendererOverridesHandler::PageStopScreencast( |
| 508 scoped_refptr<DevToolsProtocol::Command> command) { | 541 scoped_refptr<DevToolsProtocol::Command> command) { |
| 509 last_frame_time_ = base::TimeTicks(); | 542 last_frame_time_ = base::TimeTicks(); |
| 510 screencast_command_ = NULL; | 543 screencast_command_ = NULL; |
| 511 RenderViewHostImpl* host = GetRenderViewHostImpl(); | 544 if (host_) |
| 512 if (host) | 545 host_->SetTouchEventEmulationEnabled(false, false); |
| 513 host->SetTouchEventEmulationEnabled(false, false); | |
| 514 return command->SuccessResponse(NULL); | 546 return command->SuccessResponse(NULL); |
| 515 } | 547 } |
| 516 | 548 |
| 517 void RendererOverridesHandler::ScreencastFrameCaptured( | 549 void RendererOverridesHandler::ScreencastFrameCaptured( |
| 518 const std::string& format, | 550 const std::string& format, |
| 519 int quality, | 551 int quality, |
| 520 const cc::CompositorFrameMetadata& metadata, | 552 const cc::CompositorFrameMetadata& metadata, |
| 521 bool success, | 553 bool success, |
| 522 const SkBitmap& bitmap) { | 554 const SkBitmap& bitmap) { |
| 523 if (!success) { | 555 if (!success) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 &security_origin)) { | 826 &security_origin)) { |
| 795 return command->InvalidParamResponse( | 827 return command->InvalidParamResponse( |
| 796 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin); | 828 devtools::Page::queryUsageAndQuota::kParamSecurityOrigin); |
| 797 } | 829 } |
| 798 | 830 |
| 799 ResponseCallback callback = base::Bind( | 831 ResponseCallback callback = base::Bind( |
| 800 &RendererOverridesHandler::PageQueryUsageAndQuotaCompleted, | 832 &RendererOverridesHandler::PageQueryUsageAndQuotaCompleted, |
| 801 weak_factory_.GetWeakPtr(), | 833 weak_factory_.GetWeakPtr(), |
| 802 command); | 834 command); |
| 803 | 835 |
| 804 scoped_refptr<quota::QuotaManager> quota_manager = GetRenderViewHostImpl() | 836 if (!host_) |
| 805 ->GetProcess() | 837 return command->InternalErrorResponse("Could not connect to view"); |
| 806 ->GetStoragePartition() | 838 |
| 807 ->GetQuotaManager(); | 839 scoped_refptr<quota::QuotaManager> quota_manager = |
| 840 host_->GetProcess()->GetStoragePartition()->GetQuotaManager(); | |
| 808 | 841 |
| 809 BrowserThread::PostTask( | 842 BrowserThread::PostTask( |
| 810 BrowserThread::IO, FROM_HERE, | 843 BrowserThread::IO, FROM_HERE, |
| 811 base::Bind( | 844 base::Bind( |
| 812 &QueryUsageAndQuotaOnIOThread, | 845 &QueryUsageAndQuotaOnIOThread, |
| 813 quota_manager, | 846 quota_manager, |
| 814 GURL(security_origin), | 847 GURL(security_origin), |
| 815 callback)); | 848 callback)); |
| 816 | 849 |
| 817 return command->AsyncResponsePromise(); | 850 return command->AsyncResponsePromise(); |
| 818 } | 851 } |
| 819 | 852 |
| 820 void RendererOverridesHandler::PageQueryUsageAndQuotaCompleted( | 853 void RendererOverridesHandler::PageQueryUsageAndQuotaCompleted( |
| 821 scoped_refptr<DevToolsProtocol::Command> command, | 854 scoped_refptr<DevToolsProtocol::Command> command, |
| 822 scoped_ptr<base::DictionaryValue> response_data) { | 855 scoped_ptr<base::DictionaryValue> response_data) { |
| 823 SendAsyncResponse(command->SuccessResponse(response_data.release())); | 856 SendAsyncResponse(command->SuccessResponse(response_data.release())); |
| 824 } | 857 } |
| 825 | 858 |
| 826 void RendererOverridesHandler::NotifyScreencastVisibility(bool visible) { | 859 void RendererOverridesHandler::NotifyScreencastVisibility(bool visible) { |
| 827 if (visible) | 860 if (visible) |
| 828 capture_retry_count_ = kCaptureRetryLimit; | 861 capture_retry_count_ = kCaptureRetryLimit; |
| 829 base::DictionaryValue* params = new base::DictionaryValue(); | 862 base::DictionaryValue* params = new base::DictionaryValue(); |
| 830 params->SetBoolean( | 863 params->SetBoolean( |
| 831 devtools::Page::screencastVisibilityChanged::kParamVisible, visible); | 864 devtools::Page::screencastVisibilityChanged::kParamVisible, visible); |
| 832 SendNotification( | 865 SendNotification( |
| 833 devtools::Page::screencastVisibilityChanged::kName, params); | 866 devtools::Page::screencastVisibilityChanged::kName, params); |
| 834 } | 867 } |
| 835 | 868 |
| 869 scoped_refptr<DevToolsProtocol::Response> | |
| 870 RendererOverridesHandler::PageSetColorPickerEnabled( | |
| 871 scoped_refptr<DevToolsProtocol::Command> command) { | |
| 872 base::DictionaryValue* params = command->params(); | |
| 873 bool color_picker_enabled; | |
| 874 if (!params || !params->GetBoolean( | |
| 875 devtools::Page::setColorPickerEnabled::kParamEnabled, | |
| 876 &color_picker_enabled)) { | |
| 877 return command->InvalidParamResponse( | |
| 878 devtools::Page::setColorPickerEnabled::kParamEnabled); | |
| 879 } | |
| 880 | |
| 881 SetColorPickerEnabled(color_picker_enabled); | |
| 882 return command->SuccessResponse(NULL); | |
| 883 } | |
| 884 | |
| 885 void RendererOverridesHandler::SetColorPickerEnabled(bool enabled) { | |
| 886 if (color_picker_enabled_ == enabled) | |
| 887 return; | |
| 888 | |
| 889 color_picker_enabled_ = enabled; | |
| 890 | |
| 891 if (!host_) | |
| 892 return; | |
| 893 | |
| 894 if (enabled) { | |
| 895 host_->AddMouseEventCallback(mouse_event_callback_); | |
| 896 UpdateColorPickerFrame(); | |
| 897 } else { | |
| 898 host_->RemoveMouseEventCallback(mouse_event_callback_); | |
| 899 color_picker_frame_.reset(); | |
| 900 | |
| 901 WebCursor pointer_cursor; | |
| 902 WebCursor::CursorInfo cursor_info; | |
| 903 cursor_info.type = blink::WebCursorInfo::TypePointer; | |
| 904 pointer_cursor.InitFromCursorInfo(cursor_info); | |
| 905 host_->SetCursor(pointer_cursor); | |
| 906 } | |
| 907 } | |
| 908 | |
| 909 void RendererOverridesHandler::UpdateColorPickerFrame() { | |
| 910 if (!host_) | |
| 911 return; | |
| 912 RenderWidgetHostViewBase* view = | |
| 913 static_cast<RenderWidgetHostViewBase*>(host_->GetView()); | |
| 914 if (!view) | |
| 915 return; | |
| 916 | |
| 917 gfx::Size size = view->GetViewBounds().size(); | |
| 918 view->CopyFromCompositingSurface( | |
| 919 gfx::Rect(size), size, | |
| 920 base::Bind(&RendererOverridesHandler::ColorPickerFrameUpdated, | |
| 921 weak_factory_.GetWeakPtr()), | |
| 922 kN32_SkColorType); | |
| 923 } | |
| 924 | |
| 925 void RendererOverridesHandler::ColorPickerFrameUpdated( | |
| 926 bool succeeded, | |
| 927 const SkBitmap& bitmap) { | |
| 928 if (succeeded) | |
| 929 color_picker_frame_ = bitmap; | |
| 930 } | |
| 931 | |
| 932 bool RendererOverridesHandler::HandleMouseEvent( | |
| 933 const blink::WebMouseEvent& event) { | |
| 934 if (color_picker_frame_.drawsNothing()) { | |
| 935 if (event.button == blink::WebMouseEvent::ButtonLeft) | |
| 936 SetColorPickerEnabled(false); | |
|
dgozman
2014/08/16 11:04:18
Why do you disable color picker here, but not belo
pfeldman
2014/08/16 11:17:50
I used to disable it below, now I don't for the UX
| |
| 937 return true; | |
| 938 } | |
| 939 | |
| 940 if (event.button == blink::WebMouseEvent::ButtonLeft) { | |
| 941 color_picker_frame_.lockPixels(); | |
| 942 SkColor color = color_picker_frame_.getColor(event.x, event.y); | |
| 943 color_picker_frame_.unlockPixels(); | |
| 944 base::DictionaryValue* color_dict = new base::DictionaryValue(); | |
| 945 color_dict->SetInteger("r", SkColorGetR(color)); | |
| 946 color_dict->SetInteger("g", SkColorGetG(color)); | |
| 947 color_dict->SetInteger("b", SkColorGetB(color)); | |
| 948 color_dict->SetInteger("a", SkColorGetA(color)); | |
| 949 base::DictionaryValue* response = new base::DictionaryValue(); | |
| 950 response->Set(devtools::Page::colorPicked::kParamColor, color_dict); | |
| 951 SendNotification(devtools::Page::colorPicked::kName, response); | |
| 952 } | |
| 953 | |
| 954 if (!host_) | |
| 955 return true; | |
| 956 | |
| 957 // Due to platform limitations, we are using two different cursors | |
| 958 // depending on the platform. Mac and Win have large cursors with two circles | |
| 959 // for original spot and its magnified projection; Linux gets smaller (64 px) | |
| 960 // magnified projection only with centered hotspot. | |
| 961 // Mac Retina requires cursor to be > 120px in order to render smoothly. | |
| 962 | |
| 963 #if defined(OS_LINUX) | |
| 964 const float kCursorSize = 63; | |
| 965 const float kDiameter = 63; | |
| 966 const float kHotspotOffset = 32; | |
| 967 const float kHotspotRadius = 0; | |
| 968 const float kPixelSize = 9; | |
| 969 #else | |
| 970 const float kCursorSize = 150; | |
| 971 const float kDiameter = 110; | |
| 972 const float kHotspotOffset = 25; | |
| 973 const float kHotspotRadius = 5; | |
| 974 const float kPixelSize = 10; | |
| 975 #endif | |
| 976 | |
| 977 float padding = (kCursorSize - kDiameter) / 2; | |
| 978 | |
| 979 skia::RefPtr<SkCanvas> canvas = | |
| 980 skia::AdoptRef(SkCanvas::NewRasterN32(kCursorSize, kCursorSize)); | |
| 981 | |
| 982 SkPaint paint; | |
| 983 | |
| 984 // Paint original spot. | |
| 985 if (kHotspotRadius) { | |
| 986 paint.setStrokeWidth(2); | |
| 987 paint.setColor(SK_ColorDKGRAY); | |
| 988 paint.setStyle(SkPaint::kStroke_Style); | |
| 989 paint.setAntiAlias(true); | |
| 990 canvas->drawCircle(kHotspotOffset, kHotspotOffset, kHotspotRadius, paint); | |
| 991 canvas->drawLine(kHotspotOffset + kHotspotRadius - 1, | |
| 992 kHotspotOffset + kHotspotRadius - 1, | |
| 993 kCursorSize / 2, kCursorSize / 2, | |
| 994 paint); | |
| 995 } | |
| 996 | |
| 997 // Clip circle for magnified projection. | |
| 998 SkPath clip_path; | |
| 999 clip_path.addOval(SkRect::MakeXYWH(padding, padding, kDiameter, kDiameter)); | |
| 1000 clip_path.close(); | |
| 1001 canvas->clipPath(clip_path, SkRegion::kIntersect_Op, true); | |
| 1002 | |
| 1003 // Project pixels. | |
| 1004 int pixel_count = kDiameter / kPixelSize; | |
| 1005 SkRect src_rect = SkRect::MakeXYWH(event.x - pixel_count / 2, | |
| 1006 event.y - pixel_count / 2, | |
| 1007 pixel_count, pixel_count); | |
| 1008 SkRect dst_rect = SkRect::MakeXYWH(padding, padding, kDiameter, kDiameter); | |
| 1009 canvas->drawBitmapRectToRect(color_picker_frame_, &src_rect, dst_rect); | |
| 1010 | |
| 1011 // Paint outline circle. | |
| 1012 paint.setStrokeWidth(1); | |
| 1013 paint.setAntiAlias(false); | |
| 1014 paint.setColor(SK_ColorGRAY); | |
| 1015 for (int i = 0; i < pixel_count; ++i) { | |
| 1016 canvas->drawLine(padding + i * kPixelSize, padding, | |
| 1017 padding + i * kPixelSize, kCursorSize - padding, paint); | |
| 1018 canvas->drawLine(padding, padding + i * kPixelSize, | |
| 1019 kCursorSize - padding, padding + i * kPixelSize, paint); | |
| 1020 } | |
| 1021 | |
| 1022 // Paint central pixel in red. | |
| 1023 SkRect pixel = SkRect::MakeXYWH((kCursorSize - kPixelSize) / 2, | |
| 1024 (kCursorSize - kPixelSize) / 2, | |
| 1025 kPixelSize, kPixelSize); | |
| 1026 paint.setColor(SK_ColorRED); | |
| 1027 canvas->drawRect(pixel, paint); | |
| 1028 | |
| 1029 // Paint outline. | |
| 1030 paint.setStrokeWidth(2); | |
| 1031 paint.setColor(SK_ColorDKGRAY); | |
| 1032 paint.setAntiAlias(true); | |
| 1033 paint.setStyle(SkPaint::kStroke_Style); | |
| 1034 canvas->drawCircle(kCursorSize / 2, kCursorSize / 2, kDiameter / 2, paint); | |
| 1035 | |
| 1036 SkBitmap result; | |
| 1037 result.allocN32Pixels(kCursorSize, kCursorSize); | |
| 1038 canvas->readPixels(&result, 0, 0); | |
| 1039 | |
| 1040 WebCursor cursor; | |
| 1041 WebCursor::CursorInfo cursor_info; | |
| 1042 cursor_info.type = blink::WebCursorInfo::TypeCustom; | |
| 1043 cursor_info.image_scale_factor = 1; | |
|
dgozman
2014/08/16 11:04:17
You need to set this to 2.0 on Retina for smoothne
pfeldman
2014/08/16 11:17:50
Yep. Will follow up with that.
| |
| 1044 cursor_info.custom_image = result; | |
| 1045 cursor_info.hotspot = | |
| 1046 gfx::Point(kHotspotOffset, kHotspotOffset); | |
| 1047 #if defined(OS_WIN) | |
| 1048 cursor_info.external_handle = 0; | |
| 1049 #endif | |
| 1050 | |
| 1051 cursor.InitFromCursorInfo(cursor_info); | |
| 1052 DCHECK(host_); | |
| 1053 host_->SetCursor(cursor); | |
| 1054 return true; | |
| 1055 } | |
| 1056 | |
| 1057 void RendererOverridesHandler::UpdateColorPickerCursorSmall(int x, int y) { | |
|
dgozman
2014/08/16 11:04:17
This is not called from anywhere. Will it be used?
pfeldman
2014/08/16 11:17:50
Forgot to nuke this one (I used to have two indepe
| |
| 1058 // Linux has 64 pixel cursor limitation (see ui/base/x/x11_util.cc). | |
| 1059 const int kCursorSize = 63; | |
| 1060 const float kPixelSize = 9; | |
| 1061 | |
| 1062 skia::RefPtr<SkCanvas> canvas = | |
| 1063 skia::AdoptRef(SkCanvas::NewRasterN32(kCursorSize, kCursorSize)); | |
| 1064 | |
| 1065 SkPaint paint; | |
| 1066 paint.setStrokeWidth(1); | |
| 1067 paint.setColor(SK_ColorDKGRAY); | |
| 1068 paint.setStyle(SkPaint::kStroke_Style); | |
| 1069 paint.setAntiAlias(true); | |
| 1070 | |
| 1071 SkPath clip_path; | |
| 1072 clip_path.addOval(SkRect::MakeXYWH(0, 0, kCursorSize, kCursorSize)); | |
| 1073 clip_path.close(); | |
| 1074 canvas->clipPath(clip_path, SkRegion::kIntersect_Op, true); | |
| 1075 | |
| 1076 SkRect src_rect = SkRect::MakeXYWH(x - 3, y - 3, 7, 7); | |
| 1077 SkRect dst_rect = SkRect::MakeXYWH(0, 0, kCursorSize, kCursorSize); | |
| 1078 canvas->drawBitmapRectToRect(color_picker_frame_, &src_rect, dst_rect); | |
| 1079 | |
| 1080 paint.setStrokeWidth(1); | |
| 1081 paint.setAntiAlias(false); | |
| 1082 paint.setColor(SK_ColorGRAY); | |
| 1083 for (int i = 0; i < kCursorSize; i += kPixelSize) { | |
| 1084 canvas->drawLine(i, 0, i, kCursorSize, paint); | |
| 1085 canvas->drawLine(0, i, kCursorSize, i, paint); | |
| 1086 } | |
| 1087 | |
| 1088 SkRect pixel = SkRect::MakeXYWH(kCursorSize / 2 - kPixelSize / 2, | |
| 1089 kCursorSize / 2 - kPixelSize / 2, | |
| 1090 kPixelSize, kPixelSize); | |
| 1091 paint.setColor(SK_ColorRED); | |
| 1092 canvas->drawRect(pixel, paint); | |
| 1093 | |
| 1094 paint.setStrokeWidth(2); | |
| 1095 paint.setColor(SK_ColorDKGRAY); | |
| 1096 paint.setAntiAlias(true); | |
| 1097 canvas->drawCircle(kCursorSize / 2, kCursorSize / 2, kCursorSize / 2, paint); | |
| 1098 | |
| 1099 SkBitmap result; | |
| 1100 result.allocN32Pixels(kCursorSize, kCursorSize); | |
| 1101 canvas->readPixels(&result, 0, 0); | |
| 1102 | |
| 1103 WebCursor cursor; | |
| 1104 WebCursor::CursorInfo cursor_info; | |
| 1105 cursor_info.type = blink::WebCursorInfo::TypeCustom; | |
| 1106 cursor_info.image_scale_factor = 1; | |
| 1107 cursor_info.custom_image = result; | |
| 1108 cursor_info.hotspot = | |
| 1109 gfx::Point(kCursorSize / 2, kCursorSize / 2); | |
| 1110 | |
| 1111 cursor.InitFromCursorInfo(cursor_info); | |
| 1112 DCHECK(host_); | |
| 1113 host_->SetCursor(cursor); | |
| 1114 } | |
| 1115 | |
| 836 // Input agent handlers ------------------------------------------------------ | 1116 // Input agent handlers ------------------------------------------------------ |
| 837 | 1117 |
| 838 scoped_refptr<DevToolsProtocol::Response> | 1118 scoped_refptr<DevToolsProtocol::Response> |
| 839 RendererOverridesHandler::InputEmulateTouchFromMouseEvent( | 1119 RendererOverridesHandler::InputEmulateTouchFromMouseEvent( |
| 840 scoped_refptr<DevToolsProtocol::Command> command) { | 1120 scoped_refptr<DevToolsProtocol::Command> command) { |
| 841 if (!screencast_command_) | 1121 if (!screencast_command_) |
| 842 return command->InternalErrorResponse("Screencast should be turned on"); | 1122 return command->InternalErrorResponse("Screencast should be turned on"); |
| 843 | 1123 |
| 844 base::DictionaryValue* params = command->params(); | 1124 base::DictionaryValue* params = command->params(); |
| 845 if (!params) | 1125 if (!params) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 event->button = WebMouseEvent::ButtonMiddle; | 1227 event->button = WebMouseEvent::ButtonMiddle; |
| 948 event->modifiers |= WebInputEvent::MiddleButtonDown; | 1228 event->modifiers |= WebInputEvent::MiddleButtonDown; |
| 949 } else if (button == "right") { | 1229 } else if (button == "right") { |
| 950 event->button = WebMouseEvent::ButtonRight; | 1230 event->button = WebMouseEvent::ButtonRight; |
| 951 event->modifiers |= WebInputEvent::RightButtonDown; | 1231 event->modifiers |= WebInputEvent::RightButtonDown; |
| 952 } else { | 1232 } else { |
| 953 return command->InvalidParamResponse( | 1233 return command->InvalidParamResponse( |
| 954 devtools::Input::emulateTouchFromMouseEvent::kParamButton); | 1234 devtools::Input::emulateTouchFromMouseEvent::kParamButton); |
| 955 } | 1235 } |
| 956 | 1236 |
| 957 RenderViewHost* host = GetRenderViewHostImpl(); | 1237 if (!host_) |
| 1238 return command->InternalErrorResponse("Could not connect to view"); | |
| 1239 | |
| 958 if (event->type == WebInputEvent::MouseWheel) | 1240 if (event->type == WebInputEvent::MouseWheel) |
| 959 host->ForwardWheelEvent(wheel_event); | 1241 host_->ForwardWheelEvent(wheel_event); |
| 960 else | 1242 else |
| 961 host->ForwardMouseEvent(mouse_event); | 1243 host_->ForwardMouseEvent(mouse_event); |
| 962 return command->SuccessResponse(NULL); | 1244 return command->SuccessResponse(NULL); |
| 963 } | 1245 } |
| 964 | 1246 |
| 965 RenderViewHostImpl* RendererOverridesHandler::GetRenderViewHostImpl() { | |
| 966 return static_cast<RenderViewHostImpl*>( | |
| 967 agent_->GetWebContents()->GetRenderViewHost()); | |
| 968 } | |
| 969 | |
| 970 } // namespace content | 1247 } // namespace content |
| OLD | NEW |