Convert StringPiece to std::string_view in //pdf
Bug: 40506050 Change-Id: I6774a26d242aa72e920da8bf505a226c518f412b Signed-off-by: Md Hasibul Hasan <hasibulhasan873@gmail.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5385507 Commit-Queue: K. Moon <kmoon@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Cr-Commit-Position: refs/heads/main@{#1279497}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cd4376dc73
commit
fe1715d42a
@ -11,6 +11,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "base/check_op.h"
|
||||
@ -194,7 +195,7 @@ void URLLoaderWrapperImpl::ParseHeaders(const std::string& response_headers) {
|
||||
net::HttpUtil::HeadersIterator it(response_headers.begin(),
|
||||
response_headers.end(), "\n");
|
||||
while (it.GetNext()) {
|
||||
base::StringPiece name = it.name_piece();
|
||||
std::string_view name = it.name_piece();
|
||||
if (base::EqualsCaseInsensitiveASCII(name, "content-length")) {
|
||||
content_length_ = atoi(it.values().c_str());
|
||||
} else if (base::EqualsCaseInsensitiveASCII(name, "accept-ranges")) {
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
#include "pdf/paint_manager.h"
|
||||
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "cc/test/pixel_comparator.h"
|
||||
#include "cc/test/pixel_test_utils.h"
|
||||
#include "pdf/paint_ready_rect.h"
|
||||
@ -33,7 +33,7 @@ namespace {
|
||||
using ::testing::_;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
base::FilePath GetTestDataFilePath(base::StringPiece filename) {
|
||||
base::FilePath GetTestDataFilePath(std::string_view filename) {
|
||||
return base::FilePath(FILE_PATH_LITERAL("paint_manager"))
|
||||
.AppendASCII(filename);
|
||||
}
|
||||
@ -130,7 +130,7 @@ class PaintManagerTest : public testing::Test {
|
||||
|
||||
void TestScroll(const gfx::Vector2d& scroll_amount,
|
||||
const gfx::Rect& expected_paint_rect,
|
||||
base::StringPiece expected_png) {
|
||||
std::string_view expected_png) {
|
||||
// Paint non-uniform initial image.
|
||||
gfx::Size plugin_size = paint_manager_.GetEffectiveSize();
|
||||
ASSERT_GE(plugin_size.width(), 4);
|
||||
|
@ -7,9 +7,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/time/time.h"
|
||||
|
||||
@ -21,7 +21,7 @@ class DateDeserializer final {
|
||||
public:
|
||||
// `parsing` must outlive `this` because `base::StringPiece` has reference
|
||||
// semantics.
|
||||
explicit DateDeserializer(base::StringPiece parsing)
|
||||
explicit DateDeserializer(std::string_view parsing)
|
||||
: deserializing_(parsing) {}
|
||||
~DateDeserializer() = default;
|
||||
|
||||
@ -65,7 +65,7 @@ class DateDeserializer final {
|
||||
void unstop() { stopped_ = false; }
|
||||
|
||||
private:
|
||||
base::StringPiece deserializing_;
|
||||
std::string_view deserializing_;
|
||||
bool stopped_ = false;
|
||||
};
|
||||
|
||||
@ -100,7 +100,7 @@ base::TimeDelta ParseOffset(DateDeserializer& deserializer) {
|
||||
|
||||
} // namespace
|
||||
|
||||
base::Time ParsePdfDate(base::StringPiece date) {
|
||||
base::Time ParsePdfDate(std::string_view date) {
|
||||
// The prefix "D:" is required according to the spec, but don't require it as
|
||||
// earlier versions of the spec weren't strict about it.
|
||||
if (date.substr(0, 2) == "D:")
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef PDF_PDF_UTILS_DATES_H_
|
||||
#define PDF_PDF_UTILS_DATES_H_
|
||||
|
||||
#include "base/strings/string_piece.h"
|
||||
#include <string_view>
|
||||
|
||||
namespace base {
|
||||
class Time;
|
||||
@ -16,7 +16,7 @@ namespace chrome_pdf {
|
||||
// Parses a string in the PDF date format (see section 7.9.4 "Dates" of the ISO
|
||||
// 32000-1:2008 spec). If `date` cannot be parsed, returns a "null" time (one
|
||||
// for which `base::Time::is_null()` returns `true`).
|
||||
base::Time ParsePdfDate(base::StringPiece date);
|
||||
base::Time ParsePdfDate(std::string_view date);
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
#include "pdf/pdf_utils/dates.h"
|
||||
|
||||
#include "base/strings/string_piece.h"
|
||||
#include <string_view>
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -12,7 +13,7 @@ namespace chrome_pdf {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsInvalidPdfDate(base::StringPiece input) {
|
||||
bool IsInvalidPdfDate(std::string_view input) {
|
||||
return ParsePdfDate(input).is_null();
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@ -33,7 +34,6 @@
|
||||
#include "base/strings/escape.h"
|
||||
#include "base/strings/strcat.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
@ -131,14 +131,14 @@ constexpr base::TimeDelta kAccessibilityPageDelay = base::Milliseconds(100);
|
||||
|
||||
constexpr base::TimeDelta kFindResultCooldown = base::Milliseconds(100);
|
||||
|
||||
constexpr base::StringPiece kChromeExtensionHost =
|
||||
constexpr std::string_view kChromeExtensionHost =
|
||||
"chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/";
|
||||
|
||||
// Print Preview base URL.
|
||||
constexpr base::StringPiece kChromePrintHost = "chrome://print/";
|
||||
constexpr std::string_view kChromePrintHost = "chrome://print/";
|
||||
|
||||
// Untrusted Print Preview base URL.
|
||||
constexpr base::StringPiece kChromeUntrustedPrintHost =
|
||||
constexpr std::string_view kChromeUntrustedPrintHost =
|
||||
"chrome-untrusted://print/";
|
||||
|
||||
// Same value as `printing::COMPLETE_PREVIEW_DOCUMENT_INDEX`.
|
||||
@ -219,14 +219,14 @@ base::Value::Dict DictFromRect(const gfx::Rect& rect) {
|
||||
return dict;
|
||||
}
|
||||
|
||||
bool IsPrintPreviewUrl(base::StringPiece url) {
|
||||
bool IsPrintPreviewUrl(std::string_view url) {
|
||||
return base::StartsWith(url, kChromeUntrustedPrintHost);
|
||||
}
|
||||
|
||||
int ExtractPrintPreviewPageIndex(base::StringPiece src_url) {
|
||||
int ExtractPrintPreviewPageIndex(std::string_view src_url) {
|
||||
// Sample `src_url` format: chrome-untrusted://print/id/page_index/print.pdf
|
||||
// The page_index is zero-based, but can be negative with special meanings.
|
||||
std::vector<base::StringPiece> url_substr =
|
||||
std::vector<std::string_view> url_substr =
|
||||
base::SplitStringPiece(src_url.substr(kChromeUntrustedPrintHost.size()),
|
||||
"/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
||||
if (url_substr.size() != 3)
|
||||
@ -249,7 +249,7 @@ bool IsPreviewingPDF(int print_preview_page_count) {
|
||||
// If the "type" value of `message` is "foo", then the `reply_type` must be
|
||||
// "fooReply". The `message` from the embedder must have a "messageId" value
|
||||
// that will be copied to the reply message.
|
||||
base::Value::Dict PrepareReplyMessage(base::StringPiece reply_type,
|
||||
base::Value::Dict PrepareReplyMessage(std::string_view reply_type,
|
||||
const base::Value::Dict& message) {
|
||||
DCHECK_EQ(reply_type, *message.FindString("type") + "Reply");
|
||||
|
||||
@ -964,8 +964,7 @@ std::string PdfViewWebPlugin::GetURL() {
|
||||
return url_;
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::LoadUrl(base::StringPiece url,
|
||||
LoadUrlCallback callback) {
|
||||
void PdfViewWebPlugin::LoadUrl(std::string_view url, LoadUrlCallback callback) {
|
||||
UrlRequest request;
|
||||
request.url = std::string(url);
|
||||
request.method = "GET";
|
||||
@ -1302,7 +1301,7 @@ void PdfViewWebPlugin::OnMessage(const base::Value::Dict& message) {
|
||||
using MessageHandler = void (PdfViewWebPlugin::*)(const base::Value::Dict&);
|
||||
|
||||
static constexpr auto kMessageHandlers =
|
||||
base::MakeFixedFlatMap<base::StringPiece, MessageHandler>({
|
||||
base::MakeFixedFlatMap<std::string_view, MessageHandler>({
|
||||
{"displayAnnotations",
|
||||
&PdfViewWebPlugin::HandleDisplayAnnotationsMessage},
|
||||
{"getNamedDestination",
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
@ -17,7 +18,6 @@
|
||||
#include "base/i18n/rtl.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/values.h"
|
||||
#include "cc/paint/paint_image.h"
|
||||
#include "mojo/public/cpp/bindings/associated_remote.h"
|
||||
@ -466,7 +466,7 @@ class PdfViewWebPlugin final : public PDFEngine::Client,
|
||||
void UpdateScroll(const gfx::PointF& scroll_position);
|
||||
|
||||
// Loads `url`, invoking `callback` on receiving the initial response.
|
||||
void LoadUrl(base::StringPiece url, LoadUrlCallback callback);
|
||||
void LoadUrl(std::string_view url, LoadUrlCallback callback);
|
||||
|
||||
// Handles `Open()` result for `form_loader_`.
|
||||
void DidFormOpen(int32_t result);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@ -17,7 +18,6 @@
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "base/test/bind.h"
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
@ -151,7 +151,7 @@ MATCHER_P(IsExpectedImeKeyEvent, expected_text, "") {
|
||||
event.unmodified_text == expected_text;
|
||||
}
|
||||
|
||||
base::Value::Dict ParseMessage(base::StringPiece json) {
|
||||
base::Value::Dict ParseMessage(std::string_view json) {
|
||||
return std::move(base::test::ParseJson(json).GetDict());
|
||||
}
|
||||
|
||||
@ -348,14 +348,14 @@ class PdfViewWebPluginWithoutInitializeTest
|
||||
void operator()(PdfViewWebPlugin* ptr) { ptr->Destroy(); }
|
||||
};
|
||||
|
||||
static void AddToPluginParams(base::StringPiece name,
|
||||
base::StringPiece value,
|
||||
static void AddToPluginParams(std::string_view name,
|
||||
std::string_view value,
|
||||
blink::WebPluginParams& params) {
|
||||
params.attribute_names.push_back(blink::WebString::FromUTF8(name));
|
||||
params.attribute_values.push_back(blink::WebString::FromUTF8(value));
|
||||
}
|
||||
|
||||
void SetUpPlugin(base::StringPiece document_url,
|
||||
void SetUpPlugin(std::string_view document_url,
|
||||
const blink::WebPluginParams& params) {
|
||||
auto client = std::make_unique<NiceMock<FakePdfViewWebPluginClient>>();
|
||||
client_ptr_ = client.get();
|
||||
@ -1452,7 +1452,7 @@ class PdfViewWebPluginImeTest : public PdfViewWebPluginTest {
|
||||
std::u16string expected_text16 = expected_text.Utf16();
|
||||
if (expected_text16.size()) {
|
||||
for (const auto& c : expected_text16) {
|
||||
base::StringPiece16 expected_key(&c, 1);
|
||||
std::u16string_view expected_key(&c, 1);
|
||||
EXPECT_CALL(*engine_ptr_,
|
||||
HandleInputEvent(IsExpectedImeKeyEvent(expected_key)))
|
||||
.WillOnce(Return(true));
|
||||
@ -1468,7 +1468,7 @@ class PdfViewWebPluginImeTest : public PdfViewWebPluginTest {
|
||||
std::u16string expected_text16 = text.Utf16();
|
||||
if (expected_text16.size()) {
|
||||
for (const auto& c : expected_text16) {
|
||||
base::StringPiece16 event(&c, 1);
|
||||
std::u16string_view event(&c, 1);
|
||||
EXPECT_CALL(*engine_ptr_,
|
||||
HandleInputEvent(IsExpectedImeKeyEvent(event)))
|
||||
.WillOnce(Return(true));
|
||||
@ -2084,8 +2084,7 @@ TEST_F(PdfViewWebPluginSaveTest, EditedInEditMode) {
|
||||
class PdfViewWebPluginSubmitFormTest
|
||||
: public PdfViewWebPluginWithoutInitializeTest {
|
||||
protected:
|
||||
void SubmitForm(const std::string& url,
|
||||
base::StringPiece form_data = "data") {
|
||||
void SubmitForm(const std::string& url, std::string_view form_data = "data") {
|
||||
EXPECT_TRUE(plugin_->InitializeForTesting());
|
||||
|
||||
EXPECT_CALL(*client_ptr_, CreateAssociatedURLLoader).WillOnce([this]() {
|
||||
@ -2111,7 +2110,7 @@ class PdfViewWebPluginSubmitFormTest
|
||||
|
||||
EXPECT_CALL(*client_ptr_, CreateAssociatedURLLoader).Times(0);
|
||||
|
||||
constexpr base::StringPiece kFormData = "form data";
|
||||
constexpr std::string_view kFormData = "form data";
|
||||
plugin_->SubmitForm(url, kFormData.data(), kFormData.size());
|
||||
}
|
||||
|
||||
@ -2129,7 +2128,7 @@ TEST_F(PdfViewWebPluginSubmitFormTest, RequestMethod) {
|
||||
TEST_F(PdfViewWebPluginSubmitFormTest, RequestBody) {
|
||||
SetUpPluginWithUrl("https://www.example.com/path/to/the.pdf");
|
||||
|
||||
constexpr base::StringPiece kFormData = "form data";
|
||||
constexpr std::string_view kFormData = "form data";
|
||||
SubmitForm(/*url=*/"", kFormData);
|
||||
|
||||
blink::WebHTTPBody::Element element;
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_exports.h"
|
||||
@ -47,7 +47,7 @@ std::string GenerateRendererSpecificFileName(const std::string& file_name,
|
||||
use_skia_renderer ? "_skia" : "");
|
||||
}
|
||||
|
||||
base::FilePath GetReferenceFilePath(base::StringPiece test_filename) {
|
||||
base::FilePath GetReferenceFilePath(std::string_view test_filename) {
|
||||
return base::FilePath(FILE_PATH_LITERAL("pdfium_print"))
|
||||
.AppendASCII(test_filename);
|
||||
}
|
||||
@ -79,7 +79,7 @@ void CheckPdfDimensions(const std::vector<uint8_t>& pdf_data,
|
||||
void CheckPdfRendering(const std::vector<uint8_t>& pdf_data,
|
||||
int page_number,
|
||||
const gfx::SizeF& size_in_points,
|
||||
base::StringPiece expected_png_filename) {
|
||||
std::string_view expected_png_filename) {
|
||||
int width_in_pixels =
|
||||
printing::ConvertUnit(size_in_points.width(), printing::kPointsPerInch,
|
||||
printing::kDefaultPdfDpi);
|
||||
|
Reference in New Issue
Block a user