Home | History | Annotate | Download | only in webkit
      1 /*
      2  * Copyright (C) 2009 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 /**
     20  * This class is simply a container for the methods used to configure WebKit's
     21  * mock Geolocation service for use in LayoutTests.
     22  * @hide
     23  */
     24 public final class MockGeolocation {
     25 
     26     // Global instance of a MockGeolocation
     27     private static MockGeolocation sMockGeolocation;
     28 
     29     /**
     30      * Set the position for the mock Geolocation service.
     31      */
     32     public void setPosition(double latitude, double longitude, double accuracy) {
     33         // This should only ever be called on the WebKit thread.
     34         nativeSetPosition(latitude, longitude, accuracy);
     35     }
     36 
     37     /**
     38      * Set the error for the mock Geolocation service.
     39      */
     40     public void setError(int code, String message) {
     41         // This should only ever be called on the WebKit thread.
     42         nativeSetError(code, message);
     43     }
     44 
     45     /**
     46      * Get the global instance of MockGeolocation.
     47      * @return The global MockGeolocation instance.
     48      */
     49     public static MockGeolocation getInstance() {
     50       if (sMockGeolocation == null) {
     51           sMockGeolocation = new MockGeolocation();
     52       }
     53       return sMockGeolocation;
     54     }
     55 
     56     // Native functions
     57     private static native void nativeSetPosition(double latitude, double longitude, double accuracy);
     58     private static native void nativeSetError(int code, String message);
     59 }
     60