Commit e25a1787 authored by apiccion@chromium.org's avatar apiccion@chromium.org

Changes to enable HTML5 autoplay for voice search.

* Added VoiceSearchTabHelper web contents observer to toggle on html 5
  media autoiplay for google search urls.

BUG=323264

Review URL: https://codereview.chromium.org/114183006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243399 0039d316-1c4b-4281-b951-d872f2087c98
parent 51d1bbee
......@@ -105,6 +105,7 @@ public abstract class TabBase implements NavigationClient {
// Content layer Observers and Delegates
private ContentViewClient mContentViewClient;
private WebContentsObserverAndroid mWebContentsObserver;
private VoiceSearchTabHelper mVoiceSearchTabHelper;
private TabBaseChromeWebContentsDelegateAndroid mWebContentsDelegate;
/**
......@@ -650,6 +651,7 @@ public abstract class TabBase implements NavigationClient {
mContentViewCore = mContentView.getContentViewCore();
mWebContentsDelegate = createWebContentsDelegate();
mWebContentsObserver = new TabBaseWebContentsObserverAndroid(mContentViewCore);
mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore);
if (mContentViewClient != null) mContentViewCore.setContentViewClient(mContentViewClient);
......@@ -765,6 +767,7 @@ public abstract class TabBase implements NavigationClient {
mContentViewCore = null;
mWebContentsDelegate = null;
mWebContentsObserver = null;
mVoiceSearchTabHelper = null;
assert mNativeTabAndroid != 0;
nativeDestroyWebContents(mNativeTabAndroid, deleteNativeWebContents);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.WebContents;
import org.chromium.content.browser.WebContentsObserverAndroid;
/**
* Tab helper to toggle media autoplay for voice URL searches.
*/
public class VoiceSearchTabHelper extends WebContentsObserverAndroid {
private WebContents mWebContents;
/**
* Create an instance of VoiceSearchTabHelper.
*
* @param contentViewCore ContentViewCore to update media autoplay status.
*/
public VoiceSearchTabHelper(ContentViewCore contentViewCore) {
super(contentViewCore);
mWebContents = contentViewCore.getWebContents();
}
@Override
public void navigationEntryCommitted() {
nativeUpdateAutoplayStatus(mWebContents);
}
private native void nativeUpdateAutoplayStatus(WebContents webContents);
}
......@@ -28,6 +28,7 @@
#include "chrome/browser/android/uma_bridge.h"
#include "chrome/browser/android/uma_utils.h"
#include "chrome/browser/android/url_utilities.h"
#include "chrome/browser/android/voice_search_tab_helper.h"
#include "chrome/browser/autofill/android/personal_data_manager_android.h"
#include "chrome/browser/history/android/sqlite_cursor.h"
#include "chrome/browser/invalidation/invalidation_controller_android.h"
......@@ -138,6 +139,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{ "TtsPlatformImpl", TtsPlatformImplAndroid::Register },
{ "UmaBridge", RegisterUmaBridge },
{ "UrlUtilities", RegisterUrlUtilities },
{ "VoiceSearchTabHelper", RegisterVoiceSearchTabHelper },
{ "WebsiteSettingsPopupAndroid",
WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid },
#if defined(ENABLE_PRINTING) && !defined(ENABLE_FULL_PRINTING)
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/voice_search_tab_helper.h"
#include "chrome/browser/google/google_util.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "jni/VoiceSearchTabHelper_jni.h"
#include "webkit/common/webpreferences.h"
using content::WebContents;
// Register native methods
bool RegisterVoiceSearchTabHelper(JNIEnv* env) {
return RegisterNativesImpl(env);
}
static void UpdateAutoplayStatus(JNIEnv* env,
jobject obj,
jobject j_web_contents) {
WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents);
content::RenderViewHost* host = web_contents->GetRenderViewHost();
WebPreferences prefs = host->GetWebkitPreferences();
// In the case where media autoplay has been enabled by default (e.g. in
// performance media tests) do not update it based on navigation changes.
//
// Note that GetWekitPreferences() is 'stateless'. It returns the default
// webkit preferences configuration from command line switches.
if (!prefs.user_gesture_required_for_media_playback)
return;
prefs.user_gesture_required_for_media_playback =
!google_util::IsGoogleSearchUrl(web_contents->GetLastCommittedURL());
host->UpdateWebkitPreferences(prefs);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_VOICE_SEARCH_TAB_HELPER_H_
#define CHROME_BROWSER_ANDROID_VOICE_SEARCH_TAB_HELPER_H_
#include "base/android/jni_android.h"
bool RegisterVoiceSearchTabHelper(JNIEnv* env);
#endif // CHROME_BROWSER_ANDROID_VOICE_SEARCH_TAB_HELPER_H_
......@@ -155,6 +155,8 @@
'browser/android/uma_utils.h',
'browser/android/url_utilities.cc',
'browser/android/url_utilities.h',
'browser/android/voice_search_tab_helper.cc',
'browser/android/voice_search_tab_helper.h',
'browser/android/webapps/single_tab_mode_tab_helper.cc',
'browser/android/webapps/single_tab_mode_tab_helper.h',
'browser/app_controller_mac.h',
......@@ -3580,6 +3582,7 @@
'android/java/src/org/chromium/chrome/browser/UmaBridge.java',
'android/java/src/org/chromium/chrome/browser/UmaUtils.java',
'android/java/src/org/chromium/chrome/browser/UrlUtilities.java',
'android/java/src/org/chromium/chrome/browser/VoiceSearchTabHelper.java',
'android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java',
'android/java/src/org/chromium/chrome/browser/infobar/AutoLoginDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBarDelegate.java',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment