6ed4911ffaf2dae142ec0c2946e315b850d401c3
[platform/framework/web/crosswalk.git] / src / android_webview / java / src / org / chromium / android_webview / AwContentViewClient.java
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.android_webview;
6
7 import android.content.Context;
8 import android.view.KeyEvent;
9 import android.view.View;
10 import android.webkit.URLUtil;
11 import android.webkit.WebChromeClient;
12
13 import org.chromium.content.browser.ContentVideoView;
14 import org.chromium.content.browser.ContentVideoViewClient;
15 import org.chromium.content.browser.ContentViewClient;
16
17 /**
18  * ContentViewClient implementation for WebView
19  */
20 public class AwContentViewClient extends ContentViewClient {
21
22     private class AwContentVideoViewClient implements ContentVideoViewClient {
23         @Override
24         public void onShowCustomView(View view) {
25             WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() {
26                 @Override
27                 public void onCustomViewHidden() {
28                     ContentVideoView contentVideoView = ContentVideoView.getContentVideoView();
29                     if (contentVideoView != null)
30                         contentVideoView.exitFullscreen(false);
31                 }
32             };
33             mAwContentsClient.onShowCustomView(view, cb);
34         }
35
36         @Override
37         public void onDestroyContentVideoView() {
38             mAwContentsClient.onHideCustomView();
39         }
40
41         @Override
42         public View getVideoLoadingProgressView() {
43             return mAwContentsClient.getVideoLoadingProgressView();
44         }
45     }
46
47     private AwContentsClient mAwContentsClient;
48     private AwSettings mAwSettings;
49
50     public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awSettings) {
51         mAwContentsClient = awContentsClient;
52         mAwSettings = awSettings;
53     }
54
55     @Override
56     public void onBackgroundColorChanged(int color) {
57         mAwContentsClient.onBackgroundColorChanged(color);
58     }
59
60     @Override
61     public void onStartContentIntent(Context context, String contentUrl) {
62         //  Callback when detecting a click on a content link.
63         mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
64     }
65
66     @Override
67     public void onUpdateTitle(String title) {
68         mAwContentsClient.onReceivedTitle(title);
69     }
70
71     @Override
72     public boolean shouldOverrideKeyEvent(KeyEvent event) {
73         return mAwContentsClient.shouldOverrideKeyEvent(event);
74     }
75
76     @Override
77     public final ContentVideoViewClient getContentVideoViewClient() {
78         return new AwContentVideoViewClient();
79     }
80
81     @Override
82     public boolean shouldBlockMediaRequest(String url) {
83         return mAwSettings != null ?
84                 mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
85     }
86 }