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

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

Issue 24292004: Allow webkitSpeechRecognition work from an app's background page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync + add ctor/dtor for test class. Created 7 years, 2 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
« no previous file with comments | « chrome/browser/apps/speech_recognition_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( 377 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
378 base::Callback<void(bool ask_user, bool is_allowed)> callback, 378 base::Callback<void(bool ask_user, bool is_allowed)> callback,
379 int render_process_id, 379 int render_process_id,
380 int render_view_id, 380 int render_view_id,
381 bool js_api) { 381 bool js_api) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 const content::RenderViewHost* render_view_host = 383 const content::RenderViewHost* render_view_host =
384 content::RenderViewHost::FromID(render_process_id, render_view_id); 384 content::RenderViewHost::FromID(render_process_id, render_view_id);
385 385
386 bool allowed = false; 386 bool allowed = false;
387 bool ask_permission = false; 387 bool check_permission = false;
388 388
389 if (!render_view_host) { 389 if (!render_view_host) {
390 if (!js_api) { 390 if (!js_api) {
391 // If there is no render view, we cannot show the speech bubble, so this 391 // If there is no render view, we cannot show the speech bubble, so this
392 // is not allowed. 392 // is not allowed.
393 allowed = false; 393 allowed = false;
394 ask_permission = false; 394 check_permission = false;
395 } else { 395 } else {
396 // This happens for extensions. Manifest should be checked for permission. 396 // This happens for extensions. Manifest should be checked for permission.
397 allowed = true; 397 allowed = true;
398 ask_permission = false; 398 check_permission = false;
399 } 399 }
400 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 400 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
401 base::Bind(callback, ask_permission, allowed)); 401 base::Bind(callback, check_permission, allowed));
402 return; 402 return;
403 } 403 }
404 404
405 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); 405 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
406 extensions::ViewType view_type = extensions::GetViewType(web_contents); 406 extensions::ViewType view_type = extensions::GetViewType(web_contents);
407 407
408 // TODO(kalman): Also enable speech bubble for extension popups 408 // TODO(kalman): Also enable speech bubble for extension popups
409 // (VIEW_TYPE_EXTENSION_POPUP) once popup-like control UI works properly in 409 // (VIEW_TYPE_EXTENSION_POPUP) once popup-like control UI works properly in
410 // extensions: http://crbug.com/163851. 410 // extensions: http://crbug.com/163851.
411 // Right now the extension popup closes and dismisses immediately on user 411 // Right now the extension popup closes and dismisses immediately on user
412 // click. 412 // click.
413 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS || 413 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS ||
414 view_type == extensions::VIEW_TYPE_APP_SHELL || 414 view_type == extensions::VIEW_TYPE_APP_SHELL ||
415 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD) { 415 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD ||
416 // If it is a tab, we can show the speech input bubble or ask for 416 // Only allow requests through JavaScript API (|js_api| = true).
417 // Requests originating from html element (|js_api| = false) would want
418 // to show bubble which isn't quite intuitive from a background page. Also
419 // see todo above about issues with rendering such bubbles from extension
420 // popups.
421 (view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
422 js_api)) {
423 // If it is a tab, we can show the speech input bubble or check for
424 // permission. For apps, this means manifest would be checked for
417 // permission. 425 // permission.
418 426
419 allowed = true; 427 allowed = true;
420 if (js_api) 428 if (js_api)
421 ask_permission = true; 429 check_permission = true;
422 } 430 }
423 431
424 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 432 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
425 base::Bind(callback, ask_permission, allowed)); 433 base::Bind(callback, check_permission, allowed));
426 } 434 }
427 435
428 } // namespace speech 436 } // namespace speech
OLDNEW
« no previous file with comments | « chrome/browser/apps/speech_recognition_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698