Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc

Issue 260903010: Start removing support for the experimental x-webkit-speech API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't touch histograms.xml Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 render_process_id = context.embedder_render_process_id; 366 render_process_id = context.embedder_render_process_id;
367 render_view_id = context.embedder_render_view_id; 367 render_view_id = context.embedder_render_view_id;
368 } 368 }
369 369
370 // Check that the render view type is appropriate, and whether or not we 370 // Check that the render view type is appropriate, and whether or not we
371 // need to request permission from the user. 371 // need to request permission from the user.
372 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 372 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
373 base::Bind(&CheckRenderViewType, 373 base::Bind(&CheckRenderViewType,
374 callback, 374 callback,
375 render_process_id, 375 render_process_id,
376 render_view_id, 376 render_view_id));
377 !context.requested_by_page_element));
378 } 377 }
379 378
380 content::SpeechRecognitionEventListener* 379 content::SpeechRecognitionEventListener*
381 ChromeSpeechRecognitionManagerDelegate::GetEventListener() { 380 ChromeSpeechRecognitionManagerDelegate::GetEventListener() {
382 return this; 381 return this;
383 } 382 }
384 383
385 bool ChromeSpeechRecognitionManagerDelegate::FilterProfanities( 384 bool ChromeSpeechRecognitionManagerDelegate::FilterProfanities(
386 int render_process_id) { 385 int render_process_id) {
387 content::RenderProcessHost* rph = 386 content::RenderProcessHost* rph =
388 content::RenderProcessHost::FromID(render_process_id); 387 content::RenderProcessHost::FromID(render_process_id);
389 if (!rph) // Guard against race conditions on RPH lifetime. 388 if (!rph) // Guard against race conditions on RPH lifetime.
390 return true; 389 return true;
391 390
392 return Profile::FromBrowserContext(rph->GetBrowserContext())->GetPrefs()-> 391 return Profile::FromBrowserContext(rph->GetBrowserContext())->GetPrefs()->
393 GetBoolean(prefs::kSpeechRecognitionFilterProfanities); 392 GetBoolean(prefs::kSpeechRecognitionFilterProfanities);
394 } 393 }
395 394
396 // static. 395 // static.
397 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( 396 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
398 base::Callback<void(bool ask_user, bool is_allowed)> callback, 397 base::Callback<void(bool ask_user, bool is_allowed)> callback,
399 int render_process_id, 398 int render_process_id,
400 int render_view_id, 399 int render_view_id) {
401 bool js_api) {
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
403 const content::RenderViewHost* render_view_host = 401 const content::RenderViewHost* render_view_host =
404 content::RenderViewHost::FromID(render_process_id, render_view_id); 402 content::RenderViewHost::FromID(render_process_id, render_view_id);
405 403
406 bool allowed = false; 404 bool allowed = false;
407 bool check_permission = false; 405 bool check_permission = false;
408 406
409 if (!render_view_host) { 407 if (!render_view_host) {
410 if (!js_api) { 408 // This happens for extensions. Manifest should be checked for permission.
411 // If there is no render view, we cannot show the speech bubble, so this 409 allowed = true;
412 // is not allowed. 410 check_permission = false;
413 allowed = false;
414 check_permission = false;
415 } else {
416 // This happens for extensions. Manifest should be checked for permission.
417 allowed = true;
418 check_permission = false;
419 }
420 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 411 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
421 base::Bind(callback, check_permission, allowed)); 412 base::Bind(callback, check_permission, allowed));
422 return; 413 return;
423 } 414 }
424 415
425 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); 416 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
426 417
427 // chrome://app-list/ uses speech recognition. 418 // chrome://app-list/ uses speech recognition.
428 if (web_contents->GetCommittedWebUI() && 419 if (web_contents->GetCommittedWebUI() &&
429 web_contents->GetLastCommittedURL().spec() == 420 web_contents->GetLastCommittedURL().spec() ==
430 chrome::kChromeUIAppListStartPageURL) { 421 chrome::kChromeUIAppListStartPageURL) {
431 allowed = true; 422 allowed = true;
432 check_permission = false; 423 check_permission = false;
433 } 424 }
434 425
435 extensions::ViewType view_type = extensions::GetViewType(web_contents); 426 extensions::ViewType view_type = extensions::GetViewType(web_contents);
436 427
437 // TODO(kalman): Also enable speech bubble for extension popups
438 // (VIEW_TYPE_EXTENSION_POPUP) once popup-like control UI works properly in
439 // extensions: http://crbug.com/163851.
440 // Right now the extension popup closes and dismisses immediately on user
441 // click.
442 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS || 428 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS ||
443 view_type == extensions::VIEW_TYPE_APP_WINDOW || 429 view_type == extensions::VIEW_TYPE_APP_WINDOW ||
444 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD || 430 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD ||
445 // Only allow requests through JavaScript API (|js_api| = true). 431 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
446 // Requests originating from html element (|js_api| = false) would want 432 // If it is a tab, we can check for permission. For apps, this means
447 // to show bubble which isn't quite intuitive from a background page. Also 433 // manifest would be checked for permission.
448 // see todo above about issues with rendering such bubbles from extension
449 // popups.
450 (view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
451 js_api)) {
452 // If it is a tab, we can show the speech input bubble or check for
453 // permission. For apps, this means manifest would be checked for
454 // permission.
455
456 allowed = true; 434 allowed = true;
457 if (js_api) 435 check_permission = true;
458 check_permission = true;
459 } 436 }
460 437
461 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 438 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
462 base::Bind(callback, check_permission, allowed)); 439 base::Bind(callback, check_permission, allowed));
463 } 440 }
464 441
465 } // namespace speech 442 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698