Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vCard/JSON extraction #19443

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eb2c7e0
Merge pull request #11 from servo/master
niravjain Nov 13, 2017
015ef37
Merge pull request #12 from servo/master
CJ8664 Nov 22, 2017
43aeb7c
Added microdata module
niravjain Nov 24, 2017
f306835
Code to send msg from servo to servoshell (EmbedderMsg)
CJ8664 Nov 25, 2017
0530512
Merge branch 'master' of https://github.com/CJ8664/servo
CJ8664 Nov 25, 2017
f939632
naming convention
CJ8664 Nov 25, 2017
3d68d2a
trying serde_json crate
CJ8664 Nov 25, 2017
a4ed961
Uploading erroneous code
CJ8664 Nov 25, 2017
4628943
Uploading erroneous code
CJ8664 Nov 25, 2017
cbfc666
Merge remote-tracking branch 'refs/remotes/origin/serde_try' into ser…
CJ8664 Nov 25, 2017
146dd58
Merge pull request #13 from CJ8664/serde_try
CJ8664 Nov 25, 2017
9284187
serde json working for Hashmap
CJ8664 Nov 25, 2017
dd4dc70
Updated the servo-shell communication
CJ8664 Nov 29, 2017
43650c2
vCard working
CJ8664 Nov 29, 2017
19408a0
Adding adr to vCard
niravjain Nov 30, 2017
79d140d
Adding adr to vCard
niravjain Nov 30, 2017
aab6900
Merged vcard and json logic
CJ8664 Nov 30, 2017
35468f8
Fixed tidy errors
niravjain Nov 30, 2017
8cafd64
Updated code to pass the type of microdata as a parameter
CJ8664 Dec 1, 2017
87d1efa
Merge branch 'vcard' of https://github.com/CJ8664/servo into vcard
CJ8664 Dec 1, 2017
c580c3f
Added code to notify user via change in title
CJ8664 Dec 1, 2017
3cd9731
Created dummy test cases
CJ8664 Dec 1, 2017
d0cb12e
Removed JSON code and replaced with a stub
CJ8664 Dec 1, 2017
0ae2d08
Merge pull request #14 from CJ8664/vcard
CJ8664 Dec 1, 2017
7131823
Merge pull request #15 from servo/master
CJ8664 Dec 1, 2017
a3e5b9f
Updated manifest
CJ8664 Dec 1, 2017
0e5023d
Partially updated the code based on reviews
CJ8664 Dec 2, 2017
37f70c6
Fixed lint issues
CJ8664 Dec 2, 2017
543de1c
Fixed lint issues
CJ8664 Dec 2, 2017
a781bba
Merge fix
CJ8664 Dec 12, 2017
04a043d
Merge branch 'servo-master'
CJ8664 Dec 12, 2017
c740aab
Rebuild cargo
CJ8664 Dec 12, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Merged vcard and json logic

  • Loading branch information
CJ8664 committed Nov 30, 2017
commit aab6900f959f33e991885976f1db21a3ec2d1466
@@ -82,6 +82,7 @@ script_plugins = {path = "../script_plugins"}
script_traits = {path = "../script_traits"}
selectors = { path = "../selectors" }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
servo_allocator = {path = "../allocator"}
servo_arc = {path = "../servo_arc"}
@@ -1710,9 +1710,15 @@ impl Document {
// TODO: completely loaded.

// Step 13.

This comment has been minimized.

Copy link
@jdm

jdm Dec 1, 2017

Member

The comments here refer to actual step numbers defined in the HTML specification. We should not add ones for steps that do not exist :)

This comment has been minimized.

Copy link
@CJ8664

CJ8664 Dec 2, 2017

Author

The previous comments were already present, we just added step 13 for microdata as discussed our logic starts after page completes loading.

This comment has been minimized.

Copy link
@jdm

jdm Dec 2, 2017

Member

Right, but the comments including steps refer to the steps in https://html.spec.whatwg.org/multipage/#the-end . There is no step there about microdata; that's something we're adding that is not part of the specification.

let result = Microdata::parse(self);
let event = ScriptMsg::SendMicrodata(result);
self.send_to_constellation(event);
let htmlelement = self.get_html_element();
let result = Microdata::parse(self, htmlelement.unwrap().upcast::<Node>()); //Chirag
if !result.get("vcard").unwrap().is_empty() {
let event = ScriptMsg::SendMicrodata(result.get("vcard").unwrap().to_string());
self.send_to_constellation(event);
} else {
let event = ScriptMsg::SendMicrodata(result.get("json").unwrap().to_string());
self.send_to_constellation(event);
}
}

// https://html.spec.whatwg.org/multipage/#pending-parsing-blocking-script
@@ -923,6 +923,10 @@ impl Element {
&self.local_name
}

pub fn tag_name(&self) -> DOMString{
self.TagName()

This comment has been minimized.

Copy link
@jdm

jdm Dec 1, 2017

Member

You should be able to import ElementMethods and invoke TagName() directly from the caller.

This comment has been minimized.

Copy link
@vjhebbar

vjhebbar Dec 2, 2017

Contributor

This public method was added to test something, this will be removed.

}

pub fn parsed_name(&self, mut name: DOMString) -> LocalName {
if self.html_element_in_html_document() {
name.make_ascii_lowercase();
@@ -85,6 +85,8 @@ extern crate script_layout_interface;
extern crate script_traits;
extern crate selectors;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate servo_allocator;
extern crate servo_arc;
@@ -6,18 +6,39 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentBinding::Document
use dom::bindings::codegen::Bindings::ElementBinding::ElementBinding::ElementMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::root::DomRoot;
use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::element::Element;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::text::Text;
use std::borrow::Cow;
use std::collections::HashMap;
use serde_json;

pub struct Microdata {}

This comment has been minimized.

Copy link
@jdm

jdm Dec 1, 2017

Member

Rather than an empty structure with static methods, we should use plain old functions in this file instead. Code in other modules can use microdata::parse instead.

#[derive(Serialize,Clone)]
#[serde(untagged)]
enum Data {
StrValue(String),
VecValue(Vec<Data>),
DataValue(Box<Data>),
HashValue(HashMap<String,Data>)
}

impl Microdata {
//[Pref="dom.microdata.testing.enabled"]
pub fn parse(doc: &Document) -> String {
pub fn parse(doc: &Document, node : &Node) -> HashMap<String, String> {
//let dup_doc = Cow::Borrowed(doc);
let serialized_vcard = Self::parse_vcard(doc);
let serialized_json = Self::parse_json(node);
let mut serialized_data : HashMap<String, String> = HashMap::new();
serialized_data.insert("vcard".to_string(), serialized_vcard);
serialized_data.insert("json".to_string(), serialized_json);
return serialized_data;
}

pub fn parse_vcard(doc: &Document) -> String {

let ele = doc.upcast::<Node>();
let mut start_vcard = false;
@@ -131,4 +152,69 @@ impl Microdata {
println!("{}", result);
return result;
}

pub fn parse_json(node: &Node) -> String {
let json_data : Data = Self::traverse(node).unwrap();
let json = serde_json::to_string(&json_data);
//println!("printing json from microdata {:?}", json);
return json.ok().unwrap();
}

fn get_attr_value(element: &Element, property: &str)-> Option<String> {
println!("{:?}",property);
// let mut atoms = match property {
// "itemprop" => element.get_tokenlist_attribute(&local_name!("itemprop"), ),
// "itemtype" => element.get_tokenlist_attribute(&local_name!("itemtype"), ),
// _ => {},
// };
// if !atoms.is_empty() {
// let temp_key = atoms.remove(0);
// return Some(String::from(temp_key.trim()).to_owned());
// }
// else {
// return None;
// }
Some(String::from("itemprop"))
}

fn traverse( node: &Node)-> Option<Data> {
if !node.is::<Element>(){
if let Some(ref text) = node.downcast::<Text>(){
let mut content = String::new();
content.push_str(&text.upcast::<CharacterData>().data());
return Some(Data::StrValue(String::from(content)));
}
None
}
else {
let element = node.downcast::<Element>().unwrap();
let mut head_str = String::from("");
let mut parent_vec:Vec<Data> = Vec::new();
let item_type = Self::get_attr_value(element,"itemtype").unwrap();
// if element.has_attribute(&local_name!("itemscope")) && element.has_attribute(&local_name!("itemtype")) && !element.has_attribute(&local_name!("itemprop")) {
// head_str = String::from("items");
// let mut propMap:HashMap<String,Data> = HashMap::new();
// //Data::HashValue(propMap)
// let item_type = Self::get_attr_value(element,"item_type").unwrap();

// }
// else if element.has_attribute(&local_name!("itemprop")) && element.has_attribute(&local_name!("item_type")) {

// head_str = Self::get_attr_value(element,"itemprop").unwrap();
// let item_type = Self::get_attr_value(element,"item_type").unwrap();

// }
// else {
// return None;
// }
let mut inner_map:HashMap<String,Data> = HashMap::new();
for child in node.children(){
if let Some(childData) = Self::traverse(child.upcast::<Node>()){
parent_vec.push(childData);
}
}
inner_map.insert(head_str,Data::VecValue(parent_vec));
Some(Data::HashValue(inner_map))
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.