Upstream version 7.35.139.0
[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 boolean 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             return true;
35         }
36
37         @Override
38         public void onDestroyContentVideoView() {
39             mAwContentsClient.onHideCustomView();
40         }
41
42         @Override
43         public View getVideoLoadingProgressView() {
44             return mAwContentsClient.getVideoLoadingProgressView();
45         }
46     }
47
48     private AwContentsClient mAwContentsClient;
49     private AwSettings mAwSettings;
50
51     public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awSettings) {
52         mAwContentsClient = awContentsClient;
53         mAwSettings = awSettings;
54     }
55
56     @Override
57     public void onBackgroundColorChanged(int color) {
58         mAwContentsClient.onBackgroundColorChanged(color);
59     }
60
61     @Override
62     public void onStartContentIntent(Context context, String contentUrl) {
63         //  Callback when detecting a click on a content link.
64         mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
65     }
66
67     @Override
68     public void onUpdateTitle(String title) {
69         mAwContentsClient.onReceivedTitle(title);
70     }
71
72     @Override
73     public boolean shouldOverrideKeyEvent(KeyEvent event) {
74         return mAwContentsClient.shouldOverrideKeyEvent(event);
75     }
76
77     @Override
78     public final ContentVideoViewClient getContentVideoViewClient() {
79         return new AwContentVideoViewClient();
80     }
81
82     @Override
83     public boolean shouldBlockMediaRequest(String url) {
84         return mAwSettings != null ?
85                 mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
86     }
87 }