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

Side by Side Diff: extensions/shell/browser/shell_speech_recognition_manager_delegate.cc

Issue 636863003: Make SpeechRecognition per RenderFrame instead of per RenderView. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/shell/browser/shell_speech_recognition_manager_delegate.h" 5 #include "extensions/shell/browser/shell_speech_recognition_manager_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/speech_recognition_manager.h" 11 #include "content/public/browser/speech_recognition_manager.h"
11 #include "content/public/browser/speech_recognition_session_context.h" 12 #include "content/public/browser/speech_recognition_session_context.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "extensions/browser/view_type_utils.h" 14 #include "extensions/browser/view_type_utils.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 using content::SpeechRecognitionManager; 17 using content::SpeechRecognitionManager;
17 using content::WebContents; 18 using content::WebContents;
18 19
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); 79 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
79 80
80 // Make sure that initiators (extensions/web pages) properly set the 81 // Make sure that initiators (extensions/web pages) properly set the
81 // |render_process_id| field, which is needed later to retrieve the profile. 82 // |render_process_id| field, which is needed later to retrieve the profile.
82 DCHECK_NE(context.render_process_id, 0); 83 DCHECK_NE(context.render_process_id, 0);
83 84
84 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
85 base::Bind(&CheckRenderViewType, 86 base::Bind(&CheckRenderViewType,
86 callback, 87 callback,
87 context.render_process_id, 88 context.render_process_id,
88 context.render_view_id)); 89 context.render_frame_id));
89 } 90 }
90 91
91 content::SpeechRecognitionEventListener* 92 content::SpeechRecognitionEventListener*
92 ShellSpeechRecognitionManagerDelegate::GetEventListener() { 93 ShellSpeechRecognitionManagerDelegate::GetEventListener() {
93 return this; 94 return this;
94 } 95 }
95 96
96 bool ShellSpeechRecognitionManagerDelegate::FilterProfanities( 97 bool ShellSpeechRecognitionManagerDelegate::FilterProfanities(
97 int render_process_id) { 98 int render_process_id) {
98 // TODO(zork): Determine where this preference should come from. 99 // TODO(zork): Determine where this preference should come from.
99 return true; 100 return true;
100 } 101 }
101 102
102 // static 103 // static
103 void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType( 104 void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType(
104 base::Callback<void(bool ask_user, bool is_allowed)> callback, 105 base::Callback<void(bool ask_user, bool is_allowed)> callback,
105 int render_process_id, 106 int render_process_id,
106 int render_view_id) { 107 int render_frame_id) {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
108 const content::RenderViewHost* render_view_host = 109
109 content::RenderViewHost::FromID(render_process_id, render_view_id); 110 content::RenderFrameHost* render_frame_host =
111 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
110 bool allowed = false; 112 bool allowed = false;
111 bool check_permission = false; 113 bool check_permission = false;
112 114
115 const content::RenderViewHost* render_view_host =
Charlie Reis 2014/12/09 00:52:33 We don't need |render_view_host| if we use WebCont
mlamouri (slow - plz ping) 2015/01/19 11:20:23 Right ;)
116 render_frame_host ? render_frame_host->GetRenderViewHost() : nullptr;
117
113 if (render_view_host) { 118 if (render_view_host) {
114 WebContents* web_contents = 119 WebContents* web_contents =
115 WebContents::FromRenderViewHost(render_view_host); 120 WebContents::FromRenderViewHost(render_view_host);
116 extensions::ViewType view_type = extensions::GetViewType(web_contents); 121 extensions::ViewType view_type = extensions::GetViewType(web_contents);
117 122
118 if (view_type == extensions::VIEW_TYPE_APP_WINDOW || 123 if (view_type == extensions::VIEW_TYPE_APP_WINDOW ||
119 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { 124 view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
120 allowed = true; 125 allowed = true;
121 check_permission = true; 126 check_permission = true;
122 } else { 127 } else {
123 LOG(WARNING) << "Speech recognition only supported in Apps."; 128 LOG(WARNING) << "Speech recognition only supported in Apps.";
124 } 129 }
125 } 130 }
126 131
127 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 132 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
128 base::Bind(callback, check_permission, allowed)); 133 base::Bind(callback, check_permission, allowed));
129 } 134 }
130 135
131 } // namespace speech 136 } // namespace speech
132 } // namespace extensions 137 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698