15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/android/voice_search_tab_helper.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/command_line.h" 86d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/google/core/browser/google_util.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_view_host.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/web_contents.h" 116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/common/content_switches.h" 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/common/web_preferences.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "jni/VoiceSearchTabHelper_jni.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using content::WebContents; 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Register native methods 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool RegisterVoiceSearchTabHelper(JNIEnv* env) { 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return RegisterNativesImpl(env); 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static void UpdateAutoplayStatus(JNIEnv* env, 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) jobject obj, 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) jobject j_web_contents) { 256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // In the case where media autoplay has been disabled by default (e.g. in 266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // performance media tests) do not update it based on navigation changes. 276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (command_line.HasSwitch( 296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) switches::kDisableGestureRequirementForMediaPlayback)) 306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return; 316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents); 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RenderViewHost* host = web_contents->GetRenderViewHost(); 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::WebPreferences prefs = host->GetWebkitPreferences(); 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool gesture_required = 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !google_util::IsGoogleSearchUrl(web_contents->GetLastCommittedURL()); 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (gesture_required != prefs.user_gesture_required_for_media_playback) { 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // TODO(chrishtr): this is wrong. user_gesture_required_for_media_playback 416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // will be reset the next time a preference changes. 426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) prefs.user_gesture_required_for_media_playback = 436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) !google_util::IsGoogleSearchUrl(web_contents->GetLastCommittedURL()); 446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) host->UpdateWebkitPreferences(prefs); 456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 47