Skip to content

Commit

Permalink
Added caitp's changed for bug 853879.
Browse files Browse the repository at this point in the history
Changed qualifiedName to no longer be a pointer. It was being used
incorrectly and it being a pointer is uneccessary.
  • Loading branch information
RickEyre committed Mar 27, 2013
1 parent 83200c7 commit 2e70003
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 545 deletions.
22 changes: 11 additions & 11 deletions content/html/content/src/WebVTTLoadListener.cpp
Expand Up @@ -307,29 +307,29 @@ WebVTTLoadListener::ConvertNodeToCueTextContent(const webvtt_node *aWebVttNode)
nodeInfo = mElement->NodeInfo();
NS_NewHTMLElement(getter_AddRefs(cueTextContent), nodeInfo, mozilla::dom::NOT_FROM_PARSER);

nsAString *qualifiedName = nullptr;
nsAutoString qualifiedName;
switch (aWebVttNode->kind) {
case WEBVTT_CLASS:
*qualifiedName = NS_LITERAL_STRING("span");
qualifiedName = NS_LITERAL_STRING("span");
break;
case WEBVTT_ITALIC:
*qualifiedName = NS_LITERAL_STRING("i");
qualifiedName = NS_LITERAL_STRING("i");
break;
case WEBVTT_BOLD:
*qualifiedName = NS_LITERAL_STRING("b");
qualifiedName = NS_LITERAL_STRING("b");
break;
case WEBVTT_UNDERLINE:
*qualifiedName = NS_LITERAL_STRING("u");
qualifiedName = NS_LITERAL_STRING("u");
break;
case WEBVTT_RUBY:
*qualifiedName = NS_LITERAL_STRING("ruby");
qualifiedName = NS_LITERAL_STRING("ruby");
break;
case WEBVTT_RUBY_TEXT:
*qualifiedName = NS_LITERAL_STRING("rt");
qualifiedName = NS_LITERAL_STRING("rt");
break;
case WEBVTT_VOICE:
{
*qualifiedName = NS_LITERAL_STRING("span");
qualifiedName = NS_LITERAL_STRING("span");

nsCOMPtr<nsGenericHTMLElement> htmlElement =
do_QueryInterface(cueTextContent);
Expand All @@ -350,9 +350,9 @@ WebVTTLoadListener::ConvertNodeToCueTextContent(const webvtt_node *aWebVttNode)

// TODO:: Need to concatenate all applicable classes separated by spaces and
// set them to the htmlElements class attribute

htmlElement->SetAttributeNS(NS_LITERAL_STRING("html"), *qualifiedName,
NS_LITERAL_STRING(""));
htmlElement->SetAttributeNS(NS_LITERAL_STRING("html"), qualifiedName,
EmptyString());

for (int i = 0; i < aWebVttNode->data.internal_data->length; i++) {
nsCOMPtr<nsIDOMNode> resultNode, childNode;
Expand Down
50 changes: 25 additions & 25 deletions media/webvtt/LICENSE
@@ -1,25 +1,25 @@
Copyright (c) 2013 Mozilla Foundation and Contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (c) 2013 Mozilla Foundation and Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2 changes: 1 addition & 1 deletion media/webvtt/README_MOZILLA
@@ -1,5 +1,5 @@
These files are from the WebVTT library, and are extracted from rev
7446b988db7a7f1202f6f2ff4fd5a5eb59758e35 of the git repository at
f587652d6eccfbf41bedb8c4648458bcce25516d of the git repository at
https://github.com/mozilla/webvtt.

The following CPPFLAGS are used in order to build and link in Mozilla
Expand Down
1 change: 0 additions & 1 deletion media/webvtt/cue.c
Expand Up @@ -84,7 +84,6 @@ webvtt_release_cue( webvtt_cue **pcue )
*pcue = 0;
if( webvtt_deref( &cue->refs ) == 0 ) {
webvtt_release_string( &cue->id );
webvtt_release_string( &cue->body );
webvtt_release_node( &cue->node_head );
webvtt_free( cue );
}
Expand Down
118 changes: 60 additions & 58 deletions media/webvtt/cuetext.c
Expand Up @@ -29,6 +29,7 @@
#include <string.h>
#include "parser_internal.h"
#include "cuetext_internal.h"
#include "node_internal.h"
#include "cue_internal.h"
#include "string_internal.h"

Expand Down Expand Up @@ -175,19 +176,15 @@ webvtt_delete_token( webvtt_cuetext_token **token )
* Note that time stamp tokens do not need to free any internal data because
* they do not allocate anything.
*/
switch( t->token_type ) {
case START_TOKEN:
data = t->start_token_data;
webvtt_release_stringlist( &data.css_classes );
webvtt_release_string( &data.annotations );
webvtt_release_string( &t->tag_name );
break;
case END_TOKEN:
webvtt_release_string( &t->tag_name );
break;
case TEXT_TOKEN:
webvtt_release_string( &t->text );
break;
if( t->token_type == START_TOKEN ) {
data = t->start_token_data;
webvtt_release_stringlist( &data.css_classes );
webvtt_release_string( &data.annotations );
webvtt_release_string( &t->tag_name );
} else if( t->token_type == END_TOKEN ) {
webvtt_release_string( &t->tag_name );
} else if( t->token_type == TEXT_TOKEN ) {
webvtt_release_string( &t->text );
}
webvtt_free( t );
*token = 0;
Expand All @@ -196,7 +193,7 @@ webvtt_delete_token( webvtt_cuetext_token **token )
WEBVTT_INTERN int
tag_accepts_annotation( webvtt_string *tag_name )
{
return webvtt_string_is_equal( tag_name, "v", 1 );
return webvtt_string_is_equal( tag_name, ( webvtt_byte * )"v", 1 );
}

WEBVTT_INTERN webvtt_status
Expand Down Expand Up @@ -224,9 +221,9 @@ webvtt_node_kind_from_tag_name( webvtt_string *tag_name, webvtt_node_kind *kind
*kind = WEBVTT_VOICE;
break;
}
} else if( webvtt_string_is_equal( tag_name, "ruby", 4 ) ) {
} else if( webvtt_string_is_equal( tag_name, ( webvtt_byte * )"ruby", 4 ) ) {
*kind = WEBVTT_RUBY;
} else if( webvtt_string_is_equal( tag_name, "rt", 2 ) ) {
} else if( webvtt_string_is_equal( tag_name, ( webvtt_byte * )"rt", 2 ) ) {
*kind = WEBVTT_RUBY_TEXT;
} else {
return WEBVTT_INVALID_TAG_NAME;
Expand Down Expand Up @@ -356,17 +353,17 @@ webvtt_escape_state( webvtt_byte **position, webvtt_token_state *token_state,
* the interpretation to result and change the state to DATA.
*/
else if( **position == UTF8_SEMI_COLON ) {
if( webvtt_string_is_equal( &buffer, "&amp", 4 ) ) {
if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&amp", 4 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '&' ) );
} else if( webvtt_string_is_equal( &buffer, "&lt", 3 ) ) {
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&lt", 3 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '<' ) );
} else if( webvtt_string_is_equal( &buffer, "&gt", 3 ) ) {
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&gt", 3 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '>' ) );
} else if( webvtt_string_is_equal( &buffer, "&rlm", 4 ) ) {
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&rlm", 4 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, rlm_replace, RLM_REPLACE_LENGTH ) );
} else if( webvtt_string_is_equal( &buffer, "&lrm", 4 ) ) {
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&lrm", 4 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, lrm_replace, LRM_REPLACE_LENGTH ) );
} else if( webvtt_string_is_equal( &buffer, "&nbsp", 5 ) ) {
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&nbsp", 5 ) ) {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, nbsp_replace, NBSP_REPLACE_LENGTH ) );
} else {
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append_string( result, &buffer ) );
Expand Down Expand Up @@ -661,6 +658,16 @@ webvtt_parse_cuetext( webvtt_parser self, webvtt_cue *cue, webvtt_string *payloa
webvtt_cuetext_token *token;
webvtt_node_kind kind;

/**
* TODO: Use these parameters! 'finished' isn't really important
* here, but 'self' certainly is as it lets us report syntax errors.
*
* However, for the time being we can trick the compiler into not
* warning us about unused variables by doing this.
*/
( void )self;
( void )finished;

if( !cue ) {
return WEBVTT_INVALID_PARAM;
}
Expand All @@ -686,71 +693,66 @@ webvtt_parse_cuetext( webvtt_parser self, webvtt_cue *cue, webvtt_string *payloa
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-parsing-rules
*/
while( *position != UTF8_NULL_BYTE ) {

webvtt_status status = WEBVTT_SUCCESS;
webvtt_delete_token( &token );

/* Step 7. */
switch( webvtt_cuetext_tokenizer( &position, &token ) ) {
case( WEBVTT_UNFINISHED ):
/* Error here. */
break;
/* Step 8. */
case( WEBVTT_SUCCESS ):

if( WEBVTT_FAILED( status = webvtt_cuetext_tokenizer( &position,
&token ) ) ) {
/* Error here. */
} else {
/* Succeeded... Process token */
if( token->token_type == END_TOKEN ) {
/**
* If we've found an end token which has a valid end token tag name and
* a tag name that is equal to the current node then set current to the
* parent of current.
*/
if( token->token_type == END_TOKEN ) {
if( current_node->kind == WEBVTT_HEAD_NODE ) {
/**
* We have encountered an end token but we are at the top of the list
* and thus have not encountered any start tokens yet, throw away the
* token.
*/
if( current_node->kind == WEBVTT_HEAD_NODE ) {
continue;
}
continue;
}

if( webvtt_node_kind_from_tag_name( &token->tag_name, &kind ) == WEBVTT_INVALID_TAG_NAME ) {
/**
* We have encountered an end token but it is not in a format that is
* supported, throw away the token.
*/
if( webvtt_node_kind_from_tag_name( &token->tag_name, &kind ) == WEBVTT_INVALID_TAG_NAME ) {
continue;
}
continue;
}

if( current_node->kind == kind ) {
/**
* We have encountered an end token and it matches the start token of
* the node that we are currently on. Move back up the list of nodes
* and continue parsing.
*/
if( current_node->kind == kind ) {
current_node = current_node->parent;
}
current_node = current_node->parent;
}
} else {
/**
* Attempt to create a valid node from the token.
* If successful then attach the node to the current nodes list and
* also set current to the newly created node if it is an internal
* node type.
*/
if( webvtt_create_node_from_token( token, &temp_node, current_node ) != WEBVTT_SUCCESS ) {
/* Do something here? */
} else {
webvtt_attach_node( current_node, temp_node );

/**
* Attempt to create a valid node from the token.
* If successful then attach the node to the current nodes list and
* also set current to the newly created node if it is an internal
* node type.
*/
if( webvtt_create_node_from_token( token, &temp_node, current_node ) != WEBVTT_SUCCESS ) {
/* Do something here? */
if( WEBVTT_IS_VALID_INTERNAL_NODE( temp_node->kind ) ) {
current_node = temp_node;
}
else {
webvtt_attach_node( current_node, temp_node );

if( WEBVTT_IS_VALID_INTERNAL_NODE( temp_node->kind ) ) {
current_node = temp_node;
}

/* Release the node as attach internal node increases the count. */
webvtt_release_node( &temp_node );
}
/* Release the node as attach internal node increases the count. */
webvtt_release_node( &temp_node );
}
break;
}
}
webvtt_skipwhite( &position );
}
Expand Down
19 changes: 14 additions & 5 deletions media/webvtt/include/webvtt/node.h
Expand Up @@ -71,11 +71,20 @@ webvtt_node_kind_t {
WEBVTT_EMPTY_NODE = 258
} webvtt_node_kind;

#define WEBVTT_IS_LEAF(Kind) ( ((Kind) & WEBVTT_NODE_LEAF) != 0 )
#define WEBVTT_NODE_INDEX(Kind) ( (Kind) & ~WEBVTT_NODE_LEAF )
#define WEBVTT_IS_VALID_LEAF_NODE(Kind) ( WEBVTT_IS_LEAF(Kind) && (WEBVTT_NODE_INDEX(Kind) >= WEBVTT_NODE_LEAF_START && WEBVTT_NODE_INDEX(Kind) <= WEBVTT_NODE_LEAF_END ) )
#define WEBVTT_IS_VALID_INTERNAL_NODE(Kind) ( (!WEBVTT_IS_LEAF(Kind)) && (WEBVTT_NODE_INDEX(Kind) >= WEBVTT_NODE_INTERNAL_START && WEBVTT_NODE_INDEX(Kind) <= WEBVTT_NODE_INTERNAL_END) )
#define WEBVTT_IS_VALID_NODE_KIND(Kind) ( WEBVTT_IS_VALID_INTERNAL_NODE(Kind) || WEBVTT_IS_VALID_LEAF_NODE(Kind) )
#define WEBVTT_IS_LEAF( Kind ) ( ( ( Kind ) & WEBVTT_NODE_LEAF) != 0 )
#define WEBVTT_NODE_INDEX( Kind ) ( ( Kind ) & ~WEBVTT_NODE_LEAF )

#define WEBVTT_IS_VALID_LEAF_NODE( Kind ) \
( WEBVTT_IS_LEAF( Kind ) && \
( WEBVTT_NODE_INDEX( Kind ) >= WEBVTT_NODE_LEAF_START && \
WEBVTT_NODE_INDEX( Kind ) <= WEBVTT_NODE_LEAF_END ) )

#define WEBVTT_IS_VALID_INTERNAL_NODE( Kind ) \
( ( !WEBVTT_IS_LEAF( Kind ) ) && \
( WEBVTT_NODE_INDEX( Kind ) <= WEBVTT_NODE_INTERNAL_END ) )

#define WEBVTT_IS_VALID_NODE_KIND( Kind ) \
( WEBVTT_IS_VALID_INTERNAL_NODE( Kind ) || WEBVTT_IS_VALID_LEAF_NODE( Kind ) )

struct webvtt_internal_node_data_t;

Expand Down
7 changes: 4 additions & 3 deletions media/webvtt/include/webvtt/string.h
Expand Up @@ -126,14 +126,14 @@ WEBVTT_EXPORT const webvtt_byte *webvtt_string_text( const webvtt_string *str );
*
* return the length of a strings text
*/
WEBVTT_EXPORT const webvtt_uint32 webvtt_string_length( const webvtt_string *str );
WEBVTT_EXPORT webvtt_uint32 webvtt_string_length( const webvtt_string *str );

/**
* webvtt_string_capacity
*
* return the current capacity of a string
*/
WEBVTT_EXPORT const webvtt_uint32 webvtt_string_capacity( const webvtt_string *str );
WEBVTT_EXPORT webvtt_uint32 webvtt_string_capacity( const webvtt_string *str );

/**
* webvtt_string_getline
Expand All @@ -158,7 +158,8 @@ WEBVTT_EXPORT webvtt_status webvtt_string_putc( webvtt_string *str, webvtt_byte
* compare a string's text to a byte array
*
*/
WEBVTT_EXPORT webvtt_bool webvtt_string_is_equal( webvtt_string *str, webvtt_byte *to_compare, webvtt_uint len );
WEBVTT_EXPORT webvtt_bool webvtt_string_is_equal( const webvtt_string *str,
const webvtt_byte *to_compare, webvtt_uint len );

/**
* webvtt_string_append
Expand Down
13 changes: 11 additions & 2 deletions media/webvtt/lexer.c
Expand Up @@ -156,7 +156,6 @@ webvtt_lex_word( webvtt_parser self, webvtt_string *str, const webvtt_byte *buff
{
webvtt_status status = WEBVTT_SUCCESS;
webvtt_uint pos = *ppos;
int d = 0;
if( !str ) {
return WEBVTT_INVALID_PARAM;
}
Expand Down Expand Up @@ -272,7 +271,17 @@ webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, web
OVERFLOW(INTEGER)
SET_STATE(L_DIGIT0)
}
U_COLON { SET_STATE(L_TIMESTAMP1) }
/* Don't return a TIMESTAMP if we start with a dash */
U_COLON {
if( self->token[0] == UTF8_HYPHEN_MINUS )
{
RETURN(INTEGER)
}
else
{
SET_STATE(L_TIMESTAMP1)
}
}
U_PERCENT { RETURN(PERCENTAGE) }
DEFAULT { BACKUP AND RETURN(INTEGER) }
END_STATE_EX
Expand Down

0 comments on commit 2e70003

Please sign in to comment.