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

Side by Side Diff: trunk/src/content/browser/devtools/renderer_overrides_handler.cc

Issue 101113004: Revert 239759 "The comment in base64.h implies that base::Base64..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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
OLDNEW
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
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 base::Base64Encode( 446 bool success = 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 base::DictionaryValue* result = new base::DictionaryValue(); 449 if (success) {
450 result->SetString( 450 base::DictionaryValue* result = new base::DictionaryValue();
451 devtools::Page::captureScreenshot::kResponseData, base64_data); 451 result->SetString(
452 return command->SuccessResponse(result); 452 devtools::Page::captureScreenshot::kResponseData, base64_data);
453 return command->SuccessResponse(result);
454 }
455 return command->InternalErrorResponse("Unable to base64encode screenshot");
453 } 456 }
454 457
455 // Fallback to copying from compositing surface. 458 // Fallback to copying from compositing surface.
456 RenderWidgetHostViewPort* view_port = 459 RenderWidgetHostViewPort* view_port =
457 RenderWidgetHostViewPort::FromRWHV(host->GetView()); 460 RenderWidgetHostViewPort::FromRWHV(host->GetView());
458 461
459 view_port->CopyFromCompositingSurface( 462 view_port->CopyFromCompositingSurface(
460 view_bounds, snapshot_size, 463 view_bounds, snapshot_size,
461 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, 464 base::Bind(&RendererOverridesHandler::ScreenshotCaptured,
462 weak_factory_.GetWeakPtr(), command, format, quality, 465 weak_factory_.GetWeakPtr(), command, format, quality,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 546
544 if (!encoded) { 547 if (!encoded) {
545 if (command) { 548 if (command) {
546 SendAsyncResponse( 549 SendAsyncResponse(
547 command->InternalErrorResponse("Unable to encode screenshot")); 550 command->InternalErrorResponse("Unable to encode screenshot"));
548 } 551 }
549 return; 552 return;
550 } 553 }
551 554
552 std::string base_64_data; 555 std::string base_64_data;
553 base::Base64Encode( 556 if (!base::Base64Encode(base::StringPiece(
554 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), 557 reinterpret_cast<char*>(&data[0]),
555 &base_64_data); 558 data.size()),
559 &base_64_data)) {
560 if (command) {
561 SendAsyncResponse(
562 command->InternalErrorResponse("Unable to base64 encode"));
563 }
564 return;
565 }
556 566
557 base::DictionaryValue* response = new base::DictionaryValue(); 567 base::DictionaryValue* response = new base::DictionaryValue();
558 response->SetString(devtools::Page::screencastFrame::kParamData, 568 response->SetString(devtools::Page::screencastFrame::kParamData,
559 base_64_data); 569 base_64_data);
560 570
561 // Consider metadata empty in case it has no device scale factor. 571 // Consider metadata empty in case it has no device scale factor.
562 if (metadata.device_scale_factor != 0) { 572 if (metadata.device_scale_factor != 0) {
563 base::DictionaryValue* response_metadata = new base::DictionaryValue(); 573 base::DictionaryValue* response_metadata = new base::DictionaryValue();
564 574
565 response_metadata->SetDouble( 575 response_metadata->SetDouble(
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 return NULL; 980 return NULL;
971 } 981 }
972 event.data.pinchUpdate.scale = static_cast<float>(scale); 982 event.data.pinchUpdate.scale = static_cast<float>(scale);
973 } 983 }
974 984
975 host->ForwardGestureEvent(event); 985 host->ForwardGestureEvent(event);
976 return command->SuccessResponse(NULL); 986 return command->SuccessResponse(NULL);
977 } 987 }
978 988
979 } // namespace content 989 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698