Shaka Player Embedded
dom_parser.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/dom/dom_parser.h"
16 
17 #include "src/js/dom/document.h"
19 #include "src/js/js_error.h"
20 #include "src/util/utils.h"
21 
22 namespace shaka {
23 namespace js {
24 namespace dom {
25 
27 // \cond Doxygen_Skip
28 DOMParser::~DOMParser() {}
29 // \endcond Doxygen_Skip
30 
32  const std::string& source, const std::string& type) const {
33  const std::string type_lower = util::ToAsciiLower(type);
34  if (type_lower == "text/xml" || type_lower == "application/xml") {
35  RefPtr<Document> ret = new Document();
36  XMLDocumentParser parser(ret);
37  return parser.Parse(source);
38  }
39 
40  return JsError::TypeError("Unsupported parse type " + type);
41 }
42 
43 
45  AddMemberFunction("parseFromString", &DOMParser::ParseFromString);
46 }
47 
48 } // namespace dom
49 } // namespace js
50 } // namespace shaka
std::string ToAsciiLower(const std::string &source)
Definition: utils.cc:76
ExceptionOr< RefPtr< Document > > ParseFromString(const std::string &source, const std::string &type) const
Definition: dom_parser.cc:31
const char * source
Definition: media_utils.cc:30
ExceptionCode type
ExceptionOr< RefPtr< Document > > Parse(const std::string &source)
static JsError TypeError(const std::string &message)
Definition: js_error.cc:81