OLD | NEW |
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( | 374 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( |
375 base::Callback<void(bool ask_user, bool is_allowed)> callback, | 375 base::Callback<void(bool ask_user, bool is_allowed)> callback, |
376 int render_process_id, | 376 int render_process_id, |
377 int render_view_id, | 377 int render_view_id, |
378 bool js_api) { | 378 bool js_api) { |
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
380 const content::RenderViewHost* render_view_host = | 380 const content::RenderViewHost* render_view_host = |
381 content::RenderViewHost::FromID(render_process_id, render_view_id); | 381 content::RenderViewHost::FromID(render_process_id, render_view_id); |
382 | 382 |
383 bool allowed = false; | 383 bool allowed = false; |
384 bool ask_permission = false; | 384 bool check_permission = false; |
385 | 385 |
386 if (!render_view_host) { | 386 if (!render_view_host) { |
387 if (!js_api) { | 387 if (!js_api) { |
388 // If there is no render view, we cannot show the speech bubble, so this | 388 // If there is no render view, we cannot show the speech bubble, so this |
389 // is not allowed. | 389 // is not allowed. |
390 allowed = false; | 390 allowed = false; |
391 ask_permission = false; | 391 check_permission = false; |
392 } else { | 392 } else { |
393 // This happens for extensions. Manifest should be checked for permission. | 393 // This happens for extensions. Manifest should be checked for permission. |
394 allowed = true; | 394 allowed = true; |
395 ask_permission = false; | 395 check_permission = false; |
396 } | 396 } |
397 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 397 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
398 base::Bind(callback, ask_permission, allowed)); | 398 base::Bind(callback, check_permission, allowed)); |
399 return; | 399 return; |
400 } | 400 } |
401 | 401 |
402 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); | 402 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
403 extensions::ViewType view_type = extensions::GetViewType(web_contents); | 403 extensions::ViewType view_type = extensions::GetViewType(web_contents); |
404 | 404 |
405 // TODO(kalman): Also enable speech bubble for extension popups | 405 // TODO(kalman): Also enable speech bubble for extension popups |
406 // (VIEW_TYPE_EXTENSION_POPUP) once popup-like control UI works properly in | 406 // (VIEW_TYPE_EXTENSION_POPUP) once popup-like control UI works properly in |
407 // extensions: http://crbug.com/163851. | 407 // extensions: http://crbug.com/163851. |
408 // Right now the extension popup closes and dismisses immediately on user | 408 // Right now the extension popup closes and dismisses immediately on user |
409 // click. | 409 // click. |
410 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS || | 410 if (view_type == extensions::VIEW_TYPE_TAB_CONTENTS || |
411 view_type == extensions::VIEW_TYPE_APP_SHELL || | 411 view_type == extensions::VIEW_TYPE_APP_SHELL || |
412 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD) { | 412 view_type == extensions::VIEW_TYPE_VIRTUAL_KEYBOARD || |
413 // If it is a tab, we can show the speech input bubble or ask for | 413 // Only allow requests through JavaScript API (|js_api| = true). |
| 414 // Requests originating from html element (|js_api| = false) would want |
| 415 // to show bubble which isn't quite intuitive from a background page. Also |
| 416 // see todo above about issues with rendering such bubbles from extension |
| 417 // popups. |
| 418 (view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
| 419 js_api)) { |
| 420 // If it is a tab, we can show the speech input bubble or check for |
| 421 // permission. For apps, this means manifest would be checked for |
414 // permission. | 422 // permission. |
415 | 423 |
416 allowed = true; | 424 allowed = true; |
417 if (js_api) | 425 if (js_api) |
418 ask_permission = true; | 426 check_permission = true; |
419 } | 427 } |
420 | 428 |
421 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 429 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
422 base::Bind(callback, ask_permission, allowed)); | 430 base::Bind(callback, check_permission, allowed)); |
423 } | 431 } |
424 | 432 |
425 } // namespace speech | 433 } // namespace speech |
OLD | NEW |