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" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 gfx::ScaleSize(view_bounds.size(), scale)); | 436 gfx::ScaleSize(view_bounds.size(), scale)); |
437 | 437 |
438 // Grab screen pixels if available for current platform. | 438 // Grab screen pixels if available for current platform. |
439 // TODO(pfeldman): support format, scale and quality in ui::GrabViewSnapshot. | 439 // TODO(pfeldman): support format, scale and quality in ui::GrabViewSnapshot. |
440 std::vector<unsigned char> png; | 440 std::vector<unsigned char> png; |
441 bool is_unscaled_png = scale == 1 && format == kPng; | 441 bool is_unscaled_png = scale == 1 && format == kPng; |
442 if (is_unscaled_png && ui::GrabViewSnapshot(host->GetView()->GetNativeView(), | 442 if (is_unscaled_png && ui::GrabViewSnapshot(host->GetView()->GetNativeView(), |
443 &png, | 443 &png, |
444 gfx::Rect(snapshot_size))) { | 444 gfx::Rect(snapshot_size))) { |
445 std::string base64_data; | 445 std::string base64_data; |
446 bool success = base::Base64Encode( | 446 base::Base64Encode( |
447 base::StringPiece(reinterpret_cast<char*>(&*png.begin()), png.size()), | 447 base::StringPiece(reinterpret_cast<char*>(&*png.begin()), png.size()), |
448 &base64_data); | 448 &base64_data); |
449 if (success) { | 449 base::DictionaryValue* result = new base::DictionaryValue(); |
450 base::DictionaryValue* result = new base::DictionaryValue(); | 450 result->SetString( |
451 result->SetString( | 451 devtools::Page::kData, base64_data); |
452 devtools::Page::kData, base64_data); | 452 return command->SuccessResponse(result); |
453 return command->SuccessResponse(result); | |
454 } | |
455 return command->InternalErrorResponse("Unable to base64encode screenshot"); | |
456 } | 453 } |
457 | 454 |
458 // Fallback to copying from compositing surface. | 455 // Fallback to copying from compositing surface. |
459 RenderWidgetHostViewPort* view_port = | 456 RenderWidgetHostViewPort* view_port = |
460 RenderWidgetHostViewPort::FromRWHV(host->GetView()); | 457 RenderWidgetHostViewPort::FromRWHV(host->GetView()); |
461 | 458 |
462 view_port->CopyFromCompositingSurface( | 459 view_port->CopyFromCompositingSurface( |
463 view_bounds, snapshot_size, | 460 view_bounds, snapshot_size, |
464 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, | 461 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
465 weak_factory_.GetWeakPtr(), command, format, quality, | 462 weak_factory_.GetWeakPtr(), command, format, quality, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 543 |
547 if (!encoded) { | 544 if (!encoded) { |
548 if (command) { | 545 if (command) { |
549 SendAsyncResponse( | 546 SendAsyncResponse( |
550 command->InternalErrorResponse("Unable to encode screenshot")); | 547 command->InternalErrorResponse("Unable to encode screenshot")); |
551 } | 548 } |
552 return; | 549 return; |
553 } | 550 } |
554 | 551 |
555 std::string base_64_data; | 552 std::string base_64_data; |
556 if (!base::Base64Encode(base::StringPiece( | 553 base::Base64Encode( |
557 reinterpret_cast<char*>(&data[0]), | 554 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), |
558 data.size()), | 555 &base_64_data); |
559 &base_64_data)) { | |
560 if (command) { | |
561 SendAsyncResponse( | |
562 command->InternalErrorResponse("Unable to base64 encode")); | |
563 } | |
564 return; | |
565 } | |
566 | 556 |
567 base::DictionaryValue* response = new base::DictionaryValue(); | 557 base::DictionaryValue* response = new base::DictionaryValue(); |
568 response->SetString(devtools::Page::kData, base_64_data); | 558 response->SetString(devtools::Page::kData, base_64_data); |
569 | 559 |
570 // Consider metadata empty in case it has no device scale factor. | 560 // Consider metadata empty in case it has no device scale factor. |
571 if (metadata.device_scale_factor != 0) { | 561 if (metadata.device_scale_factor != 0) { |
572 base::DictionaryValue* response_metadata = new base::DictionaryValue(); | 562 base::DictionaryValue* response_metadata = new base::DictionaryValue(); |
573 | 563 |
574 response_metadata->SetDouble(devtools::Page::kParamDeviceScaleFactor, | 564 response_metadata->SetDouble(devtools::Page::kParamDeviceScaleFactor, |
575 metadata.device_scale_factor); | 565 metadata.device_scale_factor); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 return NULL; | 937 return NULL; |
948 } | 938 } |
949 event.data.pinchUpdate.scale = static_cast<float>(scale); | 939 event.data.pinchUpdate.scale = static_cast<float>(scale); |
950 } | 940 } |
951 | 941 |
952 host->ForwardGestureEvent(event); | 942 host->ForwardGestureEvent(event); |
953 return command->SuccessResponse(NULL); | 943 return command->SuccessResponse(NULL); |
954 } | 944 } |
955 | 945 |
956 } // namespace content | 946 } // namespace content |
OLD | NEW |