Home | History | Annotate | Download | only in dom_distiller_js
      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 dom_distiller::proto::DistilledContent ReadFromValue(const base::Value* json) {
     19           dom_distiller::proto::DistilledContent message;
     20           const base::DictionaryValue* dict;
     21           if (!json->GetAsDictionary(&dict)) goto error;
     22           if (dict->HasKey("1")) {
     23             std::string field_value;
     24             if (!dict->GetString("1", &field_value)) {
     25               goto error;
     26             }
     27             message.set_html(field_value);
     28           }
     29           return message;
     30 
     31         error:
     32           return dom_distiller::proto::DistilledContent();
     33         }
     34 
     35         static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::DistilledContent& message) {
     36           scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
     37           if (message.has_html()) {
     38             dict->SetString("1", message.html());
     39           }
     40           return dict.PassAs<base::Value>();
     41         }
     42       };
     43 
     44       class PaginationInfo {
     45        public:
     46         static dom_distiller::proto::PaginationInfo ReadFromValue(const base::Value* json) {
     47           dom_distiller::proto::PaginationInfo message;
     48           const base::DictionaryValue* dict;
     49           if (!json->GetAsDictionary(&dict)) goto error;
     50           if (dict->HasKey("1")) {
     51             std::string field_value;
     52             if (!dict->GetString("1", &field_value)) {
     53               goto error;
     54             }
     55             message.set_next_page(field_value);
     56           }
     57           if (dict->HasKey("2")) {
     58             std::string field_value;
     59             if (!dict->GetString("2", &field_value)) {
     60               goto error;
     61             }
     62             message.set_prev_page(field_value);
     63           }
     64           if (dict->HasKey("3")) {
     65             std::string field_value;
     66             if (!dict->GetString("3", &field_value)) {
     67               goto error;
     68             }
     69             message.set_canonical_page(field_value);
     70           }
     71           return message;
     72 
     73         error:
     74           return dom_distiller::proto::PaginationInfo();
     75         }
     76 
     77         static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::PaginationInfo& message) {
     78           scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
     79           if (message.has_next_page()) {
     80             dict->SetString("1", message.next_page());
     81           }
     82           if (message.has_prev_page()) {
     83             dict->SetString("2", message.prev_page());
     84           }
     85           if (message.has_canonical_page()) {
     86             dict->SetString("3", message.canonical_page());
     87           }
     88           return dict.PassAs<base::Value>();
     89         }
     90       };
     91 
     92       class DomDistillerResult {
     93        public:
     94         static dom_distiller::proto::DomDistillerResult ReadFromValue(const base::Value* json) {
     95           dom_distiller::proto::DomDistillerResult message;
     96           const base::DictionaryValue* dict;
     97           if (!json->GetAsDictionary(&dict)) goto error;
     98           if (dict->HasKey("1")) {
     99             std::string field_value;
    100             if (!dict->GetString("1", &field_value)) {
    101               goto error;
    102             }
    103             message.set_title(field_value);
    104           }
    105           if (dict->HasKey("2")) {
    106             const base::Value* inner_message_value;
    107             if (!dict->Get("2", &inner_message_value)) {
    108               goto error;
    109             }
    110             *message.mutable_distilled_content() =
    111                 dom_distiller::proto::json::DistilledContent::ReadFromValue(inner_message_value);
    112           }
    113           if (dict->HasKey("3")) {
    114             const base::Value* inner_message_value;
    115             if (!dict->Get("3", &inner_message_value)) {
    116               goto error;
    117             }
    118             *message.mutable_pagination_info() =
    119                 dom_distiller::proto::json::PaginationInfo::ReadFromValue(inner_message_value);
    120           }
    121           if (dict->HasKey("4")) {
    122             const base::ListValue* field_list;
    123             if (!dict->GetList("4", &field_list)) {
    124               goto error;
    125             }
    126             for (size_t i = 0; i < field_list->GetSize(); ++i) {
    127               std::string field_value;
    128               if (!field_list->GetString(i, &field_value)) {
    129                 goto error;
    130               }
    131               message.add_image_urls(field_value);
    132             }
    133           }
    134           return message;
    135 
    136         error:
    137           return dom_distiller::proto::DomDistillerResult();
    138         }
    139 
    140         static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::DomDistillerResult& message) {
    141           scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
    142           if (message.has_title()) {
    143             dict->SetString("1", message.title());
    144           }
    145           if (message.has_distilled_content()) {
    146             scoped_ptr<base::Value> inner_message_value =
    147                 dom_distiller::proto::json::DistilledContent::WriteToValue(message.distilled_content());
    148             dict->Set("2", inner_message_value.release());
    149           }
    150           if (message.has_pagination_info()) {
    151             scoped_ptr<base::Value> inner_message_value =
    152                 dom_distiller::proto::json::PaginationInfo::WriteToValue(message.pagination_info());
    153             dict->Set("3", inner_message_value.release());
    154           }
    155           base::ListValue* field_list = new base::ListValue();
    156           dict->Set("4", field_list);
    157           for (int i = 0; i < message.image_urls_size(); ++i) {
    158             field_list->AppendString(message.image_urls(i));
    159           }
    160           return dict.PassAs<base::Value>();
    161         }
    162       };
    163 
    164       class DomDistillerOptions {
    165        public:
    166         static dom_distiller::proto::DomDistillerOptions ReadFromValue(const base::Value* json) {
    167           dom_distiller::proto::DomDistillerOptions message;
    168           const base::DictionaryValue* dict;
    169           if (!json->GetAsDictionary(&dict)) goto error;
    170           if (dict->HasKey("1")) {
    171             bool field_value;
    172             if (!dict->GetBoolean("1", &field_value)) {
    173               goto error;
    174             }
    175             message.set_extract_text_only(field_value);
    176           }
    177           if (dict->HasKey("2")) {
    178             int field_value;
    179             if (!dict->GetInteger("2", &field_value)) {
    180               goto error;
    181             }
    182             message.set_debug_level(field_value);
    183           }
    184           return message;
    185 
    186         error:
    187           return dom_distiller::proto::DomDistillerOptions();
    188         }
    189 
    190         static scoped_ptr<base::Value> WriteToValue(const dom_distiller::proto::DomDistillerOptions& message) {
    191           scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
    192           if (message.has_extract_text_only()) {
    193             dict->SetBoolean("1", message.extract_text_only());
    194           }
    195           if (message.has_debug_level()) {
    196             dict->SetInteger("2", message.debug_level());
    197           }
    198           return dict.PassAs<base::Value>();
    199         }
    200       };
    201 
    202     }
    203   }
    204 }
    205