Update To 11.40.268.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 import android.widget.FrameLayout;
13
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 implements ContentVideoViewClient {
21     private final AwContentsClient mAwContentsClient;
22     private final AwSettings mAwSettings;
23     private final AwContents mAwContents;
24     private final Context mContext;
25     private FrameLayout mCustomView;
26
27     public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awSettings,
28             AwContents awContents, Context context) {
29         mAwContentsClient = awContentsClient;
30         mAwSettings = awSettings;
31         mAwContents = awContents;
32         mContext = context;
33     }
34
35     @Override
36     public void onBackgroundColorChanged(int color) {
37         mAwContentsClient.onBackgroundColorChanged(color);
38     }
39
40     @Override
41     public void onStartContentIntent(Context context, String contentUrl) {
42         //  Callback when detecting a click on a content link.
43         mAwContentsClient.shouldOverrideUrlLoading(contentUrl);
44     }
45
46     @Override
47     public void onUpdateTitle(String title) {
48         mAwContentsClient.onReceivedTitle(title);
49     }
50
51     @Override
52     public boolean shouldOverrideKeyEvent(KeyEvent event) {
53         return mAwContentsClient.shouldOverrideKeyEvent(event);
54     }
55
56     @Override
57     public final ContentVideoViewClient getContentVideoViewClient() {
58         return this;
59     }
60
61     @Override
62     public boolean shouldBlockMediaRequest(String url) {
63         return mAwSettings != null
64                 ? mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
65     }
66
67     @Override
68     public void enterFullscreenVideo(View videoView) {
69         if (mCustomView == null) {
70             // enterFullscreenVideo will only be called after enterFullscreen, but
71             // in this case exitFullscreen has been invoked in between them.
72             // TODO(igsolla): Fix http://crbug/425926 and replace with assert.
73             return;
74         }
75         mCustomView.addView(videoView, 0);
76     }
77
78     @Override
79     public void exitFullscreenVideo() {
80         // Intentional no-op
81     }
82
83     @Override
84     public View getVideoLoadingProgressView() {
85         return mAwContentsClient.getVideoLoadingProgressView();
86     }
87
88     /**
89      * Called to show the web contents in fullscreen mode.
90      *
91      * <p>If entering fullscreen on a video element the web contents will contain just
92      * the html5 video controls. {@link #enterFullscreenVideo(View)} will be called later
93      * once the ContentVideoView, which contains the hardware accelerated fullscreen video,
94      * is ready to be shown.
95      */
96     public void enterFullscreen() {
97         if (mAwContents.isFullScreen()) {
98             return;
99         }
100         View fullscreenView = mAwContents.enterFullScreen();
101         if (fullscreenView == null) {
102             return;
103         }
104         WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCallback() {
105             @Override
106             public void onCustomViewHidden() {
107                 mAwContents.requestExitFullscreen();
108             }
109         };
110         mCustomView = new FrameLayout(mContext);
111         mCustomView.addView(fullscreenView);
112         mAwContentsClient.onShowCustomView(mCustomView, cb);
113     }
114
115     /**
116      * Called to show the web contents in embedded mode.
117      */
118     public void exitFullscreen() {
119         if (mCustomView != null) {
120             mAwContents.exitFullScreen();
121             mAwContentsClient.onHideCustomView();
122             mCustomView = null;
123         }
124     }
125 }