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

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

Issue 86913002: Make base::Base64Encode() return void (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: One more chromeos-specific fix. 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
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 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::captureScreenshot::kResponseData, base64_data);
452 devtools::Page::captureScreenshot::kResponseData, 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
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::screencastFrame::kParamData, 558 response->SetString(devtools::Page::screencastFrame::kParamData,
569 base_64_data); 559 base_64_data);
570 560
571 // Consider metadata empty in case it has no device scale factor. 561 // Consider metadata empty in case it has no device scale factor.
572 if (metadata.device_scale_factor != 0) { 562 if (metadata.device_scale_factor != 0) {
573 base::DictionaryValue* response_metadata = new base::DictionaryValue(); 563 base::DictionaryValue* response_metadata = new base::DictionaryValue();
574 564
575 response_metadata->SetDouble( 565 response_metadata->SetDouble(
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 return NULL; 970 return NULL;
981 } 971 }
982 event.data.pinchUpdate.scale = static_cast<float>(scale); 972 event.data.pinchUpdate.scale = static_cast<float>(scale);
983 } 973 }
984 974
985 host->ForwardGestureEvent(event); 975 host->ForwardGestureEvent(event);
986 return command->SuccessResponse(NULL); 976 return command->SuccessResponse(NULL);
987 } 977 }
988 978
989 } // namespace content 979 } // namespace content
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/resource_cache.cc ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698