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  * Used to configure the mock Geolocation client for the LayoutTests.
     21  * @hide
     22  */
     23 public final class MockGeolocation {
     24     private WebViewCore mWebViewCore;
     25 
     26     public MockGeolocation(WebViewCore webViewCore) {
     27         mWebViewCore = webViewCore;
     28     }
     29 
     30     /**
     31      * Sets use of the mock Geolocation client. Also resets that client.
     32      */
     33     public void setUseMock() {
     34         nativeSetUseMock(mWebViewCore);
     35     }
     36 
     37     /**
     38      * Set the position for the mock Geolocation service.
     39      */
     40     public void setPosition(double latitude, double longitude, double accuracy) {
     41         // This should only ever be called on the WebKit thread.
     42         nativeSetPosition(mWebViewCore, latitude, longitude, accuracy);
     43     }
     44 
     45     /**
     46      * Set the error for the mock Geolocation service.
     47      */
     48     public void setError(int code, String message) {
     49         // This should only ever be called on the WebKit thread.
     50         nativeSetError(mWebViewCore, code, message);
     51     }
     52 
     53     public void setPermission(boolean allow) {
     54         // This should only ever be called on the WebKit thread.
     55         nativeSetPermission(mWebViewCore, allow);
     56     }
     57 
     58     // Native functions
     59     private static native void nativeSetUseMock(WebViewCore webViewCore);
     60     private static native void nativeSetPosition(WebViewCore webViewCore, double latitude,
     61             double longitude, double accuracy);
     62     private static native void nativeSetError(WebViewCore webViewCore, int code, String message);
     63     private static native void nativeSetPermission(WebViewCore webViewCore, boolean allow);
     64 }
     65