Home | History | Annotate | Download | only in webkit
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.webkit;
     18 
     19 import android.annotation.Nullable;
     20 
     21 /**
     22  * The Java representation of the HTML5 PostMessage event. See
     23  * https://html.spec.whatwg.org/multipage/comms.html#the-messageevent-interfaces
     24  * for definition of a MessageEvent in HTML5.
     25  *
     26  */
     27 public class WebMessage {
     28 
     29     private String mData;
     30     private WebMessagePort[] mPorts;
     31 
     32     /**
     33      * Creates a WebMessage.
     34      * @param data  the data of the message.
     35      */
     36     public WebMessage(String data) {
     37         mData = data;
     38     }
     39 
     40     /**
     41      * Creates a WebMessage.
     42      * @param data  the data of the message.
     43      * @param ports  the ports that are sent with the message.
     44      */
     45     public WebMessage(String data, WebMessagePort[] ports) {
     46         mData = data;
     47         mPorts = ports;
     48     }
     49 
     50     /**
     51      * Returns the data of the message.
     52      */
     53     public String getData() {
     54         return mData;
     55     }
     56 
     57     /**
     58      * Returns the ports that are sent with the message, or {@code null} if no port
     59      * is sent.
     60      */
     61     @Nullable
     62     public WebMessagePort[] getPorts() {
     63         return mPorts;
     64     }
     65 }
     66