| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "extensions/browser/api/capture_web_contents_function.h" | 5 #include "extensions/browser/api/capture_web_contents_function.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool CaptureWebContentsFunction::RunAsync() { | 28 bool CaptureWebContentsFunction::RunAsync() { |
| 29 EXTENSION_FUNCTION_VALIDATE(args_); | 29 EXTENSION_FUNCTION_VALIDATE(args_); |
| 30 | 30 |
| 31 context_id_ = extension_misc::kCurrentWindowId; | 31 context_id_ = extension_misc::kCurrentWindowId; |
| 32 args_->GetInteger(0, &context_id_); | 32 args_->GetInteger(0, &context_id_); |
| 33 | 33 |
| 34 scoped_ptr<ImageDetails> image_details; | 34 scoped_ptr<ImageDetails> image_details; |
| 35 if (args_->GetSize() > 1) { | 35 if (args_->GetSize() > 1) { |
| 36 base::Value* spec = NULL; | 36 base::Value* spec = nullptr; |
| 37 EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &spec) && spec); | 37 EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &spec) && spec); |
| 38 image_details = ImageDetails::FromValue(*spec); | 38 image_details = ImageDetails::FromValue(*spec); |
| 39 } | 39 } |
| 40 | 40 |
| 41 if (!IsScreenshotEnabled()) | 41 if (!IsScreenshotEnabled()) |
| 42 return false; | 42 return false; |
| 43 | 43 |
| 44 WebContents* contents = GetWebContentsForID(context_id_); | 44 WebContents* contents = GetWebContentsForID(context_id_); |
| 45 if (!contents) | 45 if (!contents) |
| 46 return false; | 46 return false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 122 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
| 123 | 123 |
| 124 base::Base64Encode(stream_as_string, &base64_result); | 124 base::Base64Encode(stream_as_string, &base64_result); |
| 125 base64_result.insert( | 125 base64_result.insert( |
| 126 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); | 126 0, base::StringPrintf("data:%s;base64,", mime_type.c_str())); |
| 127 SetResult(new base::StringValue(base64_result)); | 127 SetResult(new base::StringValue(base64_result)); |
| 128 SendResponse(true); | 128 SendResponse(true); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace extensions | 131 } // namespace extensions |
| OLD | NEW |