| OLD | NEW |
| (Empty) |
| 1 // GENERATED FILE | |
| 2 // This file generated by DomDistillerJs protoc plugin. | |
| 3 #include "third_party/dom_distiller_js/dom_distiller.pb.h" | |
| 4 | |
| 5 // proto dependencies | |
| 6 | |
| 7 // base dependencies | |
| 8 #include "base/values.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 | |
| 11 #include <string> | |
| 12 | |
| 13 namespace dom_distiller { | |
| 14 namespace proto { | |
| 15 namespace json { | |
| 16 class DistilledContent { | |
| 17 public: | |
| 18 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:DistilledContent* message) { | |
| 19 const base::DictionaryValue* dict; | |
| 20 if (!json->GetAsDictionary(&dict)) goto error; | |
| 21 if (dict->HasKey("1")) { | |
| 22 std::string field_value; | |
| 23 if (!dict->GetString("1", &field_value)) { | |
| 24 goto error; | |
| 25 } | |
| 26 message->set_html(field_value); | |
| 27 } | |
| 28 return true; | |
| 29 | |
| 30 error: | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
DistilledContent& message) { | |
| 35 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 36 if (message.has_html()) { | |
| 37 dict->SetString("1", message.html()); | |
| 38 } | |
| 39 return dict.Pass(); | |
| 40 } | |
| 41 }; | |
| 42 | |
| 43 class PaginationInfo { | |
| 44 public: | |
| 45 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:PaginationInfo* message) { | |
| 46 const base::DictionaryValue* dict; | |
| 47 if (!json->GetAsDictionary(&dict)) goto error; | |
| 48 if (dict->HasKey("1")) { | |
| 49 std::string field_value; | |
| 50 if (!dict->GetString("1", &field_value)) { | |
| 51 goto error; | |
| 52 } | |
| 53 message->set_next_page(field_value); | |
| 54 } | |
| 55 if (dict->HasKey("2")) { | |
| 56 std::string field_value; | |
| 57 if (!dict->GetString("2", &field_value)) { | |
| 58 goto error; | |
| 59 } | |
| 60 message->set_prev_page(field_value); | |
| 61 } | |
| 62 if (dict->HasKey("3")) { | |
| 63 std::string field_value; | |
| 64 if (!dict->GetString("3", &field_value)) { | |
| 65 goto error; | |
| 66 } | |
| 67 message->set_canonical_page(field_value); | |
| 68 } | |
| 69 return true; | |
| 70 | |
| 71 error: | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
PaginationInfo& message) { | |
| 76 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 77 if (message.has_next_page()) { | |
| 78 dict->SetString("1", message.next_page()); | |
| 79 } | |
| 80 if (message.has_prev_page()) { | |
| 81 dict->SetString("2", message.prev_page()); | |
| 82 } | |
| 83 if (message.has_canonical_page()) { | |
| 84 dict->SetString("3", message.canonical_page()); | |
| 85 } | |
| 86 return dict.Pass(); | |
| 87 } | |
| 88 }; | |
| 89 | |
| 90 class MarkupArticle { | |
| 91 public: | |
| 92 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:MarkupArticle* message) { | |
| 93 const base::DictionaryValue* dict; | |
| 94 if (!json->GetAsDictionary(&dict)) goto error; | |
| 95 if (dict->HasKey("1")) { | |
| 96 std::string field_value; | |
| 97 if (!dict->GetString("1", &field_value)) { | |
| 98 goto error; | |
| 99 } | |
| 100 message->set_published_time(field_value); | |
| 101 } | |
| 102 if (dict->HasKey("2")) { | |
| 103 std::string field_value; | |
| 104 if (!dict->GetString("2", &field_value)) { | |
| 105 goto error; | |
| 106 } | |
| 107 message->set_modified_time(field_value); | |
| 108 } | |
| 109 if (dict->HasKey("3")) { | |
| 110 std::string field_value; | |
| 111 if (!dict->GetString("3", &field_value)) { | |
| 112 goto error; | |
| 113 } | |
| 114 message->set_expiration_time(field_value); | |
| 115 } | |
| 116 if (dict->HasKey("4")) { | |
| 117 std::string field_value; | |
| 118 if (!dict->GetString("4", &field_value)) { | |
| 119 goto error; | |
| 120 } | |
| 121 message->set_section(field_value); | |
| 122 } | |
| 123 if (dict->HasKey("5")) { | |
| 124 const base::ListValue* field_list; | |
| 125 if (!dict->GetList("5", &field_list)) { | |
| 126 goto error; | |
| 127 } | |
| 128 for (size_t i = 0; i < field_list->GetSize(); ++i) { | |
| 129 std::string field_value; | |
| 130 if (!field_list->GetString(i, &field_value)) { | |
| 131 goto error; | |
| 132 } | |
| 133 message->add_authors(field_value); | |
| 134 } | |
| 135 } | |
| 136 return true; | |
| 137 | |
| 138 error: | |
| 139 return false; | |
| 140 } | |
| 141 | |
| 142 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
MarkupArticle& message) { | |
| 143 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 144 if (message.has_published_time()) { | |
| 145 dict->SetString("1", message.published_time()); | |
| 146 } | |
| 147 if (message.has_modified_time()) { | |
| 148 dict->SetString("2", message.modified_time()); | |
| 149 } | |
| 150 if (message.has_expiration_time()) { | |
| 151 dict->SetString("3", message.expiration_time()); | |
| 152 } | |
| 153 if (message.has_section()) { | |
| 154 dict->SetString("4", message.section()); | |
| 155 } | |
| 156 { | |
| 157 base::ListValue* field_list = new base::ListValue(); | |
| 158 dict->Set("5", field_list); | |
| 159 for (int i = 0; i < message.authors_size(); ++i) { | |
| 160 field_list->AppendString(message.authors(i)); | |
| 161 } | |
| 162 } | |
| 163 return dict.Pass(); | |
| 164 } | |
| 165 }; | |
| 166 | |
| 167 class MarkupImage { | |
| 168 public: | |
| 169 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:MarkupImage* message) { | |
| 170 const base::DictionaryValue* dict; | |
| 171 if (!json->GetAsDictionary(&dict)) goto error; | |
| 172 if (dict->HasKey("1")) { | |
| 173 std::string field_value; | |
| 174 if (!dict->GetString("1", &field_value)) { | |
| 175 goto error; | |
| 176 } | |
| 177 message->set_url(field_value); | |
| 178 } | |
| 179 if (dict->HasKey("2")) { | |
| 180 std::string field_value; | |
| 181 if (!dict->GetString("2", &field_value)) { | |
| 182 goto error; | |
| 183 } | |
| 184 message->set_secure_url(field_value); | |
| 185 } | |
| 186 if (dict->HasKey("3")) { | |
| 187 std::string field_value; | |
| 188 if (!dict->GetString("3", &field_value)) { | |
| 189 goto error; | |
| 190 } | |
| 191 message->set_type(field_value); | |
| 192 } | |
| 193 if (dict->HasKey("4")) { | |
| 194 std::string field_value; | |
| 195 if (!dict->GetString("4", &field_value)) { | |
| 196 goto error; | |
| 197 } | |
| 198 message->set_caption(field_value); | |
| 199 } | |
| 200 if (dict->HasKey("5")) { | |
| 201 int field_value; | |
| 202 if (!dict->GetInteger("5", &field_value)) { | |
| 203 goto error; | |
| 204 } | |
| 205 message->set_width(field_value); | |
| 206 } | |
| 207 if (dict->HasKey("6")) { | |
| 208 int field_value; | |
| 209 if (!dict->GetInteger("6", &field_value)) { | |
| 210 goto error; | |
| 211 } | |
| 212 message->set_height(field_value); | |
| 213 } | |
| 214 return true; | |
| 215 | |
| 216 error: | |
| 217 return false; | |
| 218 } | |
| 219 | |
| 220 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
MarkupImage& message) { | |
| 221 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 222 if (message.has_url()) { | |
| 223 dict->SetString("1", message.url()); | |
| 224 } | |
| 225 if (message.has_secure_url()) { | |
| 226 dict->SetString("2", message.secure_url()); | |
| 227 } | |
| 228 if (message.has_type()) { | |
| 229 dict->SetString("3", message.type()); | |
| 230 } | |
| 231 if (message.has_caption()) { | |
| 232 dict->SetString("4", message.caption()); | |
| 233 } | |
| 234 if (message.has_width()) { | |
| 235 dict->SetInteger("5", message.width()); | |
| 236 } | |
| 237 if (message.has_height()) { | |
| 238 dict->SetInteger("6", message.height()); | |
| 239 } | |
| 240 return dict.Pass(); | |
| 241 } | |
| 242 }; | |
| 243 | |
| 244 class MarkupInfo { | |
| 245 public: | |
| 246 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:MarkupInfo* message) { | |
| 247 const base::DictionaryValue* dict; | |
| 248 if (!json->GetAsDictionary(&dict)) goto error; | |
| 249 if (dict->HasKey("1")) { | |
| 250 std::string field_value; | |
| 251 if (!dict->GetString("1", &field_value)) { | |
| 252 goto error; | |
| 253 } | |
| 254 message->set_title(field_value); | |
| 255 } | |
| 256 if (dict->HasKey("2")) { | |
| 257 std::string field_value; | |
| 258 if (!dict->GetString("2", &field_value)) { | |
| 259 goto error; | |
| 260 } | |
| 261 message->set_type(field_value); | |
| 262 } | |
| 263 if (dict->HasKey("3")) { | |
| 264 std::string field_value; | |
| 265 if (!dict->GetString("3", &field_value)) { | |
| 266 goto error; | |
| 267 } | |
| 268 message->set_url(field_value); | |
| 269 } | |
| 270 if (dict->HasKey("4")) { | |
| 271 std::string field_value; | |
| 272 if (!dict->GetString("4", &field_value)) { | |
| 273 goto error; | |
| 274 } | |
| 275 message->set_description(field_value); | |
| 276 } | |
| 277 if (dict->HasKey("5")) { | |
| 278 std::string field_value; | |
| 279 if (!dict->GetString("5", &field_value)) { | |
| 280 goto error; | |
| 281 } | |
| 282 message->set_publisher(field_value); | |
| 283 } | |
| 284 if (dict->HasKey("6")) { | |
| 285 std::string field_value; | |
| 286 if (!dict->GetString("6", &field_value)) { | |
| 287 goto error; | |
| 288 } | |
| 289 message->set_copyright(field_value); | |
| 290 } | |
| 291 if (dict->HasKey("7")) { | |
| 292 std::string field_value; | |
| 293 if (!dict->GetString("7", &field_value)) { | |
| 294 goto error; | |
| 295 } | |
| 296 message->set_author(field_value); | |
| 297 } | |
| 298 if (dict->HasKey("8")) { | |
| 299 const base::Value* inner_message_value; | |
| 300 if (!dict->Get("8", &inner_message_value)) { | |
| 301 goto error; | |
| 302 } | |
| 303 if (!dom_distiller::proto::json::MarkupArticle::ReadFromValue(inner_
message_value, message->mutable_article())) { | |
| 304 goto error; | |
| 305 } | |
| 306 } | |
| 307 if (dict->HasKey("9")) { | |
| 308 const base::ListValue* field_list; | |
| 309 if (!dict->GetList("9", &field_list)) { | |
| 310 goto error; | |
| 311 } | |
| 312 for (size_t i = 0; i < field_list->GetSize(); ++i) { | |
| 313 const base::Value* inner_message_value; | |
| 314 if (!field_list->Get(i, &inner_message_value)) { | |
| 315 goto error; | |
| 316 } | |
| 317 if (!dom_distiller::proto::json::MarkupImage::ReadFromValue(inner_
message_value, message->add_images())) { | |
| 318 goto error; | |
| 319 } | |
| 320 } | |
| 321 } | |
| 322 return true; | |
| 323 | |
| 324 error: | |
| 325 return false; | |
| 326 } | |
| 327 | |
| 328 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
MarkupInfo& message) { | |
| 329 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 330 if (message.has_title()) { | |
| 331 dict->SetString("1", message.title()); | |
| 332 } | |
| 333 if (message.has_type()) { | |
| 334 dict->SetString("2", message.type()); | |
| 335 } | |
| 336 if (message.has_url()) { | |
| 337 dict->SetString("3", message.url()); | |
| 338 } | |
| 339 if (message.has_description()) { | |
| 340 dict->SetString("4", message.description()); | |
| 341 } | |
| 342 if (message.has_publisher()) { | |
| 343 dict->SetString("5", message.publisher()); | |
| 344 } | |
| 345 if (message.has_copyright()) { | |
| 346 dict->SetString("6", message.copyright()); | |
| 347 } | |
| 348 if (message.has_author()) { | |
| 349 dict->SetString("7", message.author()); | |
| 350 } | |
| 351 if (message.has_article()) { | |
| 352 scoped_ptr<base::Value> inner_message_value = | |
| 353 dom_distiller::proto::json::MarkupArticle::WriteToValue(message.
article()); | |
| 354 dict->Set("8", inner_message_value.release()); | |
| 355 } | |
| 356 { | |
| 357 base::ListValue* field_list = new base::ListValue(); | |
| 358 dict->Set("9", field_list); | |
| 359 for (int i = 0; i < message.images_size(); ++i) { | |
| 360 scoped_ptr<base::Value> inner_message_value = | |
| 361 dom_distiller::proto::json::MarkupImage::WriteToValue(message.
images(i)); | |
| 362 field_list->Append(inner_message_value.release()); | |
| 363 } | |
| 364 } | |
| 365 return dict.Pass(); | |
| 366 } | |
| 367 }; | |
| 368 | |
| 369 class TimingEntry { | |
| 370 public: | |
| 371 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:TimingEntry* message) { | |
| 372 const base::DictionaryValue* dict; | |
| 373 if (!json->GetAsDictionary(&dict)) goto error; | |
| 374 if (dict->HasKey("1")) { | |
| 375 std::string field_value; | |
| 376 if (!dict->GetString("1", &field_value)) { | |
| 377 goto error; | |
| 378 } | |
| 379 message->set_name(field_value); | |
| 380 } | |
| 381 if (dict->HasKey("2")) { | |
| 382 double field_value; | |
| 383 if (!dict->GetDouble("2", &field_value)) { | |
| 384 goto error; | |
| 385 } | |
| 386 message->set_time(field_value); | |
| 387 } | |
| 388 return true; | |
| 389 | |
| 390 error: | |
| 391 return false; | |
| 392 } | |
| 393 | |
| 394 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
TimingEntry& message) { | |
| 395 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 396 if (message.has_name()) { | |
| 397 dict->SetString("1", message.name()); | |
| 398 } | |
| 399 if (message.has_time()) { | |
| 400 dict->SetDouble("2", message.time()); | |
| 401 } | |
| 402 return dict.Pass(); | |
| 403 } | |
| 404 }; | |
| 405 | |
| 406 class TimingInfo { | |
| 407 public: | |
| 408 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:TimingInfo* message) { | |
| 409 const base::DictionaryValue* dict; | |
| 410 if (!json->GetAsDictionary(&dict)) goto error; | |
| 411 if (dict->HasKey("1")) { | |
| 412 double field_value; | |
| 413 if (!dict->GetDouble("1", &field_value)) { | |
| 414 goto error; | |
| 415 } | |
| 416 message->set_markup_parsing_time(field_value); | |
| 417 } | |
| 418 if (dict->HasKey("2")) { | |
| 419 double field_value; | |
| 420 if (!dict->GetDouble("2", &field_value)) { | |
| 421 goto error; | |
| 422 } | |
| 423 message->set_document_construction_time(field_value); | |
| 424 } | |
| 425 if (dict->HasKey("3")) { | |
| 426 double field_value; | |
| 427 if (!dict->GetDouble("3", &field_value)) { | |
| 428 goto error; | |
| 429 } | |
| 430 message->set_article_processing_time(field_value); | |
| 431 } | |
| 432 if (dict->HasKey("4")) { | |
| 433 double field_value; | |
| 434 if (!dict->GetDouble("4", &field_value)) { | |
| 435 goto error; | |
| 436 } | |
| 437 message->set_formatting_time(field_value); | |
| 438 } | |
| 439 if (dict->HasKey("5")) { | |
| 440 double field_value; | |
| 441 if (!dict->GetDouble("5", &field_value)) { | |
| 442 goto error; | |
| 443 } | |
| 444 message->set_total_time(field_value); | |
| 445 } | |
| 446 if (dict->HasKey("6")) { | |
| 447 const base::ListValue* field_list; | |
| 448 if (!dict->GetList("6", &field_list)) { | |
| 449 goto error; | |
| 450 } | |
| 451 for (size_t i = 0; i < field_list->GetSize(); ++i) { | |
| 452 const base::Value* inner_message_value; | |
| 453 if (!field_list->Get(i, &inner_message_value)) { | |
| 454 goto error; | |
| 455 } | |
| 456 if (!dom_distiller::proto::json::TimingEntry::ReadFromValue(inner_
message_value, message->add_other_times())) { | |
| 457 goto error; | |
| 458 } | |
| 459 } | |
| 460 } | |
| 461 return true; | |
| 462 | |
| 463 error: | |
| 464 return false; | |
| 465 } | |
| 466 | |
| 467 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
TimingInfo& message) { | |
| 468 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 469 if (message.has_markup_parsing_time()) { | |
| 470 dict->SetDouble("1", message.markup_parsing_time()); | |
| 471 } | |
| 472 if (message.has_document_construction_time()) { | |
| 473 dict->SetDouble("2", message.document_construction_time()); | |
| 474 } | |
| 475 if (message.has_article_processing_time()) { | |
| 476 dict->SetDouble("3", message.article_processing_time()); | |
| 477 } | |
| 478 if (message.has_formatting_time()) { | |
| 479 dict->SetDouble("4", message.formatting_time()); | |
| 480 } | |
| 481 if (message.has_total_time()) { | |
| 482 dict->SetDouble("5", message.total_time()); | |
| 483 } | |
| 484 { | |
| 485 base::ListValue* field_list = new base::ListValue(); | |
| 486 dict->Set("6", field_list); | |
| 487 for (int i = 0; i < message.other_times_size(); ++i) { | |
| 488 scoped_ptr<base::Value> inner_message_value = | |
| 489 dom_distiller::proto::json::TimingEntry::WriteToValue(message.
other_times(i)); | |
| 490 field_list->Append(inner_message_value.release()); | |
| 491 } | |
| 492 } | |
| 493 return dict.Pass(); | |
| 494 } | |
| 495 }; | |
| 496 | |
| 497 class DebugInfo { | |
| 498 public: | |
| 499 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:DebugInfo* message) { | |
| 500 const base::DictionaryValue* dict; | |
| 501 if (!json->GetAsDictionary(&dict)) goto error; | |
| 502 if (dict->HasKey("1")) { | |
| 503 std::string field_value; | |
| 504 if (!dict->GetString("1", &field_value)) { | |
| 505 goto error; | |
| 506 } | |
| 507 message->set_log(field_value); | |
| 508 } | |
| 509 return true; | |
| 510 | |
| 511 error: | |
| 512 return false; | |
| 513 } | |
| 514 | |
| 515 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
DebugInfo& message) { | |
| 516 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 517 if (message.has_log()) { | |
| 518 dict->SetString("1", message.log()); | |
| 519 } | |
| 520 return dict.Pass(); | |
| 521 } | |
| 522 }; | |
| 523 | |
| 524 class StatisticsInfo { | |
| 525 public: | |
| 526 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:StatisticsInfo* message) { | |
| 527 const base::DictionaryValue* dict; | |
| 528 if (!json->GetAsDictionary(&dict)) goto error; | |
| 529 if (dict->HasKey("1")) { | |
| 530 int field_value; | |
| 531 if (!dict->GetInteger("1", &field_value)) { | |
| 532 goto error; | |
| 533 } | |
| 534 message->set_word_count(field_value); | |
| 535 } | |
| 536 return true; | |
| 537 | |
| 538 error: | |
| 539 return false; | |
| 540 } | |
| 541 | |
| 542 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
StatisticsInfo& message) { | |
| 543 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 544 if (message.has_word_count()) { | |
| 545 dict->SetInteger("1", message.word_count()); | |
| 546 } | |
| 547 return dict.Pass(); | |
| 548 } | |
| 549 }; | |
| 550 | |
| 551 class DomDistillerResult { | |
| 552 public: | |
| 553 class ContentImage { | |
| 554 public: | |
| 555 static bool ReadFromValue(const base::Value* json, dom_distiller::prot
o::DomDistillerResult::ContentImage* message) { | |
| 556 const base::DictionaryValue* dict; | |
| 557 if (!json->GetAsDictionary(&dict)) goto error; | |
| 558 if (dict->HasKey("1")) { | |
| 559 std::string field_value; | |
| 560 if (!dict->GetString("1", &field_value)) { | |
| 561 goto error; | |
| 562 } | |
| 563 message->set_url(field_value); | |
| 564 } | |
| 565 return true; | |
| 566 | |
| 567 error: | |
| 568 return false; | |
| 569 } | |
| 570 | |
| 571 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto
::DomDistillerResult::ContentImage& message) { | |
| 572 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 573 if (message.has_url()) { | |
| 574 dict->SetString("1", message.url()); | |
| 575 } | |
| 576 return dict.Pass(); | |
| 577 } | |
| 578 }; | |
| 579 | |
| 580 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:DomDistillerResult* message) { | |
| 581 const base::DictionaryValue* dict; | |
| 582 if (!json->GetAsDictionary(&dict)) goto error; | |
| 583 if (dict->HasKey("1")) { | |
| 584 std::string field_value; | |
| 585 if (!dict->GetString("1", &field_value)) { | |
| 586 goto error; | |
| 587 } | |
| 588 message->set_title(field_value); | |
| 589 } | |
| 590 if (dict->HasKey("2")) { | |
| 591 const base::Value* inner_message_value; | |
| 592 if (!dict->Get("2", &inner_message_value)) { | |
| 593 goto error; | |
| 594 } | |
| 595 if (!dom_distiller::proto::json::DistilledContent::ReadFromValue(inn
er_message_value, message->mutable_distilled_content())) { | |
| 596 goto error; | |
| 597 } | |
| 598 } | |
| 599 if (dict->HasKey("3")) { | |
| 600 const base::Value* inner_message_value; | |
| 601 if (!dict->Get("3", &inner_message_value)) { | |
| 602 goto error; | |
| 603 } | |
| 604 if (!dom_distiller::proto::json::PaginationInfo::ReadFromValue(inner
_message_value, message->mutable_pagination_info())) { | |
| 605 goto error; | |
| 606 } | |
| 607 } | |
| 608 if (dict->HasKey("5")) { | |
| 609 const base::Value* inner_message_value; | |
| 610 if (!dict->Get("5", &inner_message_value)) { | |
| 611 goto error; | |
| 612 } | |
| 613 if (!dom_distiller::proto::json::MarkupInfo::ReadFromValue(inner_mes
sage_value, message->mutable_markup_info())) { | |
| 614 goto error; | |
| 615 } | |
| 616 } | |
| 617 if (dict->HasKey("6")) { | |
| 618 const base::Value* inner_message_value; | |
| 619 if (!dict->Get("6", &inner_message_value)) { | |
| 620 goto error; | |
| 621 } | |
| 622 if (!dom_distiller::proto::json::TimingInfo::ReadFromValue(inner_mes
sage_value, message->mutable_timing_info())) { | |
| 623 goto error; | |
| 624 } | |
| 625 } | |
| 626 if (dict->HasKey("7")) { | |
| 627 const base::Value* inner_message_value; | |
| 628 if (!dict->Get("7", &inner_message_value)) { | |
| 629 goto error; | |
| 630 } | |
| 631 if (!dom_distiller::proto::json::DebugInfo::ReadFromValue(inner_mess
age_value, message->mutable_debug_info())) { | |
| 632 goto error; | |
| 633 } | |
| 634 } | |
| 635 if (dict->HasKey("8")) { | |
| 636 const base::Value* inner_message_value; | |
| 637 if (!dict->Get("8", &inner_message_value)) { | |
| 638 goto error; | |
| 639 } | |
| 640 if (!dom_distiller::proto::json::StatisticsInfo::ReadFromValue(inner
_message_value, message->mutable_statistics_info())) { | |
| 641 goto error; | |
| 642 } | |
| 643 } | |
| 644 if (dict->HasKey("9")) { | |
| 645 std::string field_value; | |
| 646 if (!dict->GetString("9", &field_value)) { | |
| 647 goto error; | |
| 648 } | |
| 649 message->set_text_direction(field_value); | |
| 650 } | |
| 651 if (dict->HasKey("10")) { | |
| 652 const base::ListValue* field_list; | |
| 653 if (!dict->GetList("10", &field_list)) { | |
| 654 goto error; | |
| 655 } | |
| 656 for (size_t i = 0; i < field_list->GetSize(); ++i) { | |
| 657 const base::Value* inner_message_value; | |
| 658 if (!field_list->Get(i, &inner_message_value)) { | |
| 659 goto error; | |
| 660 } | |
| 661 if (!dom_distiller::proto::json::DomDistillerResult::ContentImage:
:ReadFromValue(inner_message_value, message->add_content_images())) { | |
| 662 goto error; | |
| 663 } | |
| 664 } | |
| 665 } | |
| 666 return true; | |
| 667 | |
| 668 error: | |
| 669 return false; | |
| 670 } | |
| 671 | |
| 672 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
DomDistillerResult& message) { | |
| 673 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 674 if (message.has_title()) { | |
| 675 dict->SetString("1", message.title()); | |
| 676 } | |
| 677 if (message.has_distilled_content()) { | |
| 678 scoped_ptr<base::Value> inner_message_value = | |
| 679 dom_distiller::proto::json::DistilledContent::WriteToValue(messa
ge.distilled_content()); | |
| 680 dict->Set("2", inner_message_value.release()); | |
| 681 } | |
| 682 if (message.has_pagination_info()) { | |
| 683 scoped_ptr<base::Value> inner_message_value = | |
| 684 dom_distiller::proto::json::PaginationInfo::WriteToValue(message
.pagination_info()); | |
| 685 dict->Set("3", inner_message_value.release()); | |
| 686 } | |
| 687 if (message.has_markup_info()) { | |
| 688 scoped_ptr<base::Value> inner_message_value = | |
| 689 dom_distiller::proto::json::MarkupInfo::WriteToValue(message.mar
kup_info()); | |
| 690 dict->Set("5", inner_message_value.release()); | |
| 691 } | |
| 692 if (message.has_timing_info()) { | |
| 693 scoped_ptr<base::Value> inner_message_value = | |
| 694 dom_distiller::proto::json::TimingInfo::WriteToValue(message.tim
ing_info()); | |
| 695 dict->Set("6", inner_message_value.release()); | |
| 696 } | |
| 697 if (message.has_debug_info()) { | |
| 698 scoped_ptr<base::Value> inner_message_value = | |
| 699 dom_distiller::proto::json::DebugInfo::WriteToValue(message.debu
g_info()); | |
| 700 dict->Set("7", inner_message_value.release()); | |
| 701 } | |
| 702 if (message.has_statistics_info()) { | |
| 703 scoped_ptr<base::Value> inner_message_value = | |
| 704 dom_distiller::proto::json::StatisticsInfo::WriteToValue(message
.statistics_info()); | |
| 705 dict->Set("8", inner_message_value.release()); | |
| 706 } | |
| 707 if (message.has_text_direction()) { | |
| 708 dict->SetString("9", message.text_direction()); | |
| 709 } | |
| 710 { | |
| 711 base::ListValue* field_list = new base::ListValue(); | |
| 712 dict->Set("10", field_list); | |
| 713 for (int i = 0; i < message.content_images_size(); ++i) { | |
| 714 scoped_ptr<base::Value> inner_message_value = | |
| 715 dom_distiller::proto::json::DomDistillerResult::ContentImage::
WriteToValue(message.content_images(i)); | |
| 716 field_list->Append(inner_message_value.release()); | |
| 717 } | |
| 718 } | |
| 719 return dict.Pass(); | |
| 720 } | |
| 721 }; | |
| 722 | |
| 723 class DomDistillerOptions { | |
| 724 public: | |
| 725 static bool ReadFromValue(const base::Value* json, dom_distiller::proto:
:DomDistillerOptions* message) { | |
| 726 const base::DictionaryValue* dict; | |
| 727 if (!json->GetAsDictionary(&dict)) goto error; | |
| 728 if (dict->HasKey("1")) { | |
| 729 bool field_value; | |
| 730 if (!dict->GetBoolean("1", &field_value)) { | |
| 731 goto error; | |
| 732 } | |
| 733 message->set_extract_text_only(field_value); | |
| 734 } | |
| 735 if (dict->HasKey("2")) { | |
| 736 int field_value; | |
| 737 if (!dict->GetInteger("2", &field_value)) { | |
| 738 goto error; | |
| 739 } | |
| 740 message->set_debug_level(field_value); | |
| 741 } | |
| 742 if (dict->HasKey("3")) { | |
| 743 std::string field_value; | |
| 744 if (!dict->GetString("3", &field_value)) { | |
| 745 goto error; | |
| 746 } | |
| 747 message->set_original_url(field_value); | |
| 748 } | |
| 749 return true; | |
| 750 | |
| 751 error: | |
| 752 return false; | |
| 753 } | |
| 754 | |
| 755 static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::
DomDistillerOptions& message) { | |
| 756 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 757 if (message.has_extract_text_only()) { | |
| 758 dict->SetBoolean("1", message.extract_text_only()); | |
| 759 } | |
| 760 if (message.has_debug_level()) { | |
| 761 dict->SetInteger("2", message.debug_level()); | |
| 762 } | |
| 763 if (message.has_original_url()) { | |
| 764 dict->SetString("3", message.original_url()); | |
| 765 } | |
| 766 return dict.Pass(); | |
| 767 } | |
| 768 }; | |
| 769 | |
| 770 } | |
| 771 } | |
| 772 } | |
| OLD | NEW |