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

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

Issue 12589005: Implement web speech synthesis. (Closed) Base URL: http://git.chromium.org/chromium/src.git@webtts
Patch Set: Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
tommi (sloooow) - chröme 2013/03/07 13:04:46 I think that a decision was made to not change the
hans 2013/03/09 14:19:52 something is weird here.. it seems this is a new f
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/spellchecker/spellcheck_message_filter.h" 5 #include "chrome/browser/speech/tts_message_filter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/spellchecker/spellcheck_factory.h" 9 #include "chrome/common/spellcheck_messages.h" /////////////
tommi (sloooow) - chröme 2013/03/07 13:04:46 remove ///////?
11 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
12 #include "chrome/browser/spellchecker/spellcheck_service.h"
13 #include "chrome/browser/spellchecker/spelling_service_client.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/common/spellcheck_messages.h"
16 #include "content/public/browser/render_process_host.h" 10 #include "content/public/browser/render_process_host.h"
17 #include "net/url_request/url_fetcher.h"
18 11
19 using content::BrowserThread; 12 using content::BrowserThread;
20 13
21 SpellCheckMessageFilter::SpellCheckMessageFilter(int render_process_id) 14 TtsMessageFilter::TtsMessageFilter(int render_process_id)
22 : render_process_id_(render_process_id), 15 : render_process_id_(render_process_id)
23 client_(new SpellingServiceClient)
24 #if !defined(OS_MACOSX) 16 #if !defined(OS_MACOSX)
25 , 17 ,
26 route_id_(0), 18 route_id_(0),
27 identifier_(0) 19 identifier_(0)
28 #endif 20 #endif
29 { 21 {
30 } 22 }
31 23
32 void SpellCheckMessageFilter::OverrideThreadForMessage( 24 void TtsMessageFilter::OverrideThreadForMessage(
33 const IPC::Message& message, BrowserThread::ID* thread) { 25 const IPC::Message& message, BrowserThread::ID* thread) {
34 if (message.type() == SpellCheckHostMsg_RequestDictionary::ID || 26 if (message.type() == SpellCheckHostMsg_RequestDictionary::ID ||
hans 2013/03/09 14:19:52 what's up with all the SpellCheck stuff here? am I
dmazzoni 2013/03/19 17:30:22 Sorry, my mistake - I switched implementation stra
35 message.type() == SpellCheckHostMsg_NotifyChecked::ID) 27 message.type() == SpellCheckHostMsg_NotifyChecked::ID)
36 *thread = BrowserThread::UI; 28 *thread = BrowserThread::UI;
37 #if !defined(OS_MACOSX) 29 #if !defined(OS_MACOSX)
38 if (message.type() == SpellCheckHostMsg_CallSpellingService::ID) 30 if (message.type() == SpellCheckHostMsg_CallSpellingService::ID)
39 *thread = BrowserThread::UI; 31 *thread = BrowserThread::UI;
40 #endif 32 #endif
41 } 33 }
42 34
43 bool SpellCheckMessageFilter::OnMessageReceived(const IPC::Message& message, 35 bool TtsMessageFilter::OnMessageReceived(const IPC::Message& message,
44 bool* message_was_ok) { 36 bool* message_was_ok) {
45 bool handled = true; 37 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP_EX(SpellCheckMessageFilter, message, *message_was_ok) 38 IPC_BEGIN_MESSAGE_MAP_EX(TtsMessageFilter, message, *message_was_ok)
47 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestDictionary, 39 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestDictionary,
hans 2013/03/09 14:19:52 again with the spellcheck.. i'm not sure i underst
48 OnSpellCheckerRequestDictionary) 40 OnSpellCheckerRequestDictionary)
49 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_NotifyChecked, 41 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_NotifyChecked,
50 OnNotifyChecked) 42 OnNotifyChecked)
51 #if !defined(OS_MACOSX) 43 #if !defined(OS_MACOSX)
52 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, 44 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService,
53 OnCallSpellingService) 45 OnCallSpellingService)
54 #endif 46 #endif
55 IPC_MESSAGE_UNHANDLED(handled = false) 47 IPC_MESSAGE_UNHANDLED(handled = false)
56 IPC_END_MESSAGE_MAP() 48 IPC_END_MESSAGE_MAP()
57 return handled; 49 return handled;
58 } 50 }
59 51
60 SpellCheckMessageFilter::~SpellCheckMessageFilter() {} 52 TtsMessageFilter::~TtsMessageFilter() {}
61 53
62 void SpellCheckMessageFilter::OnSpellCheckerRequestDictionary() { 54 void TtsMessageFilter::OnSpellCheckerRequestDictionary() {
63 content::RenderProcessHost* host = 55 content::RenderProcessHost* host =
64 content::RenderProcessHost::FromID(render_process_id_); 56 content::RenderProcessHost::FromID(render_process_id_);
65 if (!host) 57 if (!host)
66 return; // Teardown. 58 return; // Teardown.
67 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 59 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
68 // The renderer has requested that we initialize its spellchecker. This should 60 // The renderer has requested that we initialize its spellchecker. This should
69 // generally only be called once per session, as after the first call, all 61 // generally only be called once per session, as after the first call, all
70 // future renderers will be passed the initialization information on startup 62 // future renderers will be passed the initialization information on startup
71 // (or when the dictionary changes in some way). 63 // (or when the dictionary changes in some way).
72 SpellcheckService* spellcheck_service = 64 SpellcheckService* spellcheck_service =
73 SpellcheckServiceFactory::GetForProfile(profile); 65 SpellcheckServiceFactory::GetForProfile(profile);
74 66
75 DCHECK(spellcheck_service); 67 DCHECK(spellcheck_service);
76 // The spellchecker initialization already started and finished; just send 68 // The spellchecker initialization already started and finished; just send
77 // it to the renderer. 69 // it to the renderer.
78 spellcheck_service->InitForRenderer(host); 70 spellcheck_service->InitForRenderer(host);
79 71
80 // TODO(rlp): Ensure that we do not initialize the hunspell dictionary more 72 // TODO(rlp): Ensure that we do not initialize the hunspell dictionary more
81 // than once if we get requests from different renderers. 73 // than once if we get requests from different renderers.
82 } 74 }
83 75
84 void SpellCheckMessageFilter::OnNotifyChecked(const string16& word, 76 void TtsMessageFilter::OnNotifyChecked(const string16& word,
85 bool misspelled) { 77 bool misspelled) {
86 content::RenderProcessHost* host = 78 content::RenderProcessHost* host =
87 content::RenderProcessHost::FromID(render_process_id_); 79 content::RenderProcessHost::FromID(render_process_id_);
88 if (!host) 80 if (!host)
89 return; // Teardown. 81 return; // Teardown.
90 // Delegates to SpellCheckHost which tracks the stats of our spellchecker. 82 // Delegates to SpellCheckHost which tracks the stats of our spellchecker.
91 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 83 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
92 SpellcheckService* spellcheck_service = 84 SpellcheckService* spellcheck_service =
93 SpellcheckServiceFactory::GetForProfile(profile); 85 SpellcheckServiceFactory::GetForProfile(profile);
94 DCHECK(spellcheck_service); 86 DCHECK(spellcheck_service);
95 if (spellcheck_service->GetMetrics()) 87 if (spellcheck_service->GetMetrics())
96 spellcheck_service->GetMetrics()->RecordCheckedWordStats(word, misspelled); 88 spellcheck_service->GetMetrics()->RecordCheckedWordStats(word, misspelled);
97 } 89 }
98 90
99 #if !defined(OS_MACOSX) 91 #if !defined(OS_MACOSX)
100 void SpellCheckMessageFilter::OnCallSpellingService( 92 void TtsMessageFilter::OnCallSpellingService(
101 int route_id, 93 int route_id,
102 int identifier, 94 int identifier,
103 int document_tag, 95 int document_tag,
104 const string16& text) { 96 const string16& text) {
105 DCHECK(!text.empty()); 97 DCHECK(!text.empty());
106 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 98 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
99 if (!CallSpellingService(route_id, identifier, document_tag, text)) {
100 std::vector<SpellCheckResult> results;
101 Send(new SpellCheckMsg_RespondSpellingService(route_id,
102 identifier,
103 document_tag,
104 false,
105 text,
106 results));
107 return;
108 }
107 route_id_ = route_id; 109 route_id_ = route_id;
108 identifier_ = identifier; 110 identifier_ = identifier;
109 CallSpellingService(document_tag, text);
110 } 111 }
111 112
112 void SpellCheckMessageFilter::OnTextCheckComplete( 113 void TtsMessageFilter::OnTextCheckComplete(
113 int tag, 114 int tag,
114 bool success, 115 bool success,
115 const string16& text, 116 const string16& text,
116 const std::vector<SpellCheckResult>& results) { 117 const std::vector<SpellCheckResult>& results) {
117 Send(new SpellCheckMsg_RespondSpellingService(route_id_, 118 Send(new SpellCheckMsg_RespondSpellingService(route_id_,
118 identifier_, 119 identifier_,
119 tag, 120 tag,
120 success, 121 success,
121 text, 122 text,
122 results)); 123 results));
124 client_.reset();
123 } 125 }
124 126
125 // CallSpellingService always executes the callback OnTextCheckComplete. 127 bool TtsMessageFilter::CallSpellingService(
126 // (Which, in turn, sends a SpellCheckMsg_RespondSpellingService) 128 int route_id,
127 void SpellCheckMessageFilter::CallSpellingService(int document_tag, 129 int identifier,
128 const string16& text) { 130 int document_tag,
129 Profile* profile = NULL; 131 const string16& text) {
130 content::RenderProcessHost* host = 132 content::RenderProcessHost* host =
131 content::RenderProcessHost::FromID(render_process_id_); 133 content::RenderProcessHost::FromID(render_process_id_);
132 if (host) 134 if (!host)
133 profile = Profile::FromBrowserContext(host->GetBrowserContext()); 135 return false;
134 136 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
tommi (sloooow) - chröme 2013/03/07 13:04:46 I seem to recall FromBrowserContext return NULL in
135 client_->RequestTextCheck( 137 if (!profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService))
138 return false;
139 client_.reset(new SpellingServiceClient);
140 return client_->RequestTextCheck(
136 profile, SpellingServiceClient::SPELLCHECK, text, 141 profile, SpellingServiceClient::SPELLCHECK, text,
137 base::Bind(&SpellCheckMessageFilter::OnTextCheckComplete, 142 base::Bind(&TtsMessageFilter::OnTextCheckComplete,
138 base::Unretained(this), document_tag)); 143 base::Unretained(this), document_tag));
139 } 144 }
140 #endif 145 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698