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

Side by Side Diff: ios/chrome/browser/voice/voice_search_url_rewriter.mm

Issue 2449593002: [ios] Adds support for parsing Text-to-Speech search results. (Closed)
Patch Set: Fix AVFoundation dependency. Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/voice/voice_search_url_rewriter.h"
6
7 #import <Foundation/Foundation.h>
8
9 #import "base/mac/scoped_nsobject.h"
10 #import "base/strings/sys_string_conversions.h"
11 #include "components/google/core/browser/google_util.h"
12 #include "components/prefs/pref_service.h"
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
14 #include "ios/chrome/browser/pref_names.h"
15 #include "ios/chrome/browser/voice/speech_input_locale_config.h"
16 #include "net/base/url_util.h"
17 #include "url/gurl.h"
18
19 bool VoiceSearchURLRewriter(GURL* url, web::BrowserState* browser_state) {
20 if (!google_util::IsGoogleSearchUrl(*url))
21 return false;
22
23 ios::ChromeBrowserState* chrome_browser_state =
24 ios::ChromeBrowserState::FromBrowserState(browser_state);
25 std::string language =
26 chrome_browser_state->GetPrefs()->GetString(prefs::kVoiceSearchLocale);
27 GURL rewritten_url(*url);
28 // The |hl| parameter will be overriden only if the voice search locale
29 // is not empty. If it is empty (indicating that voice search locale
30 // uses device language), the |hl| will keep the original value.
31 // If there is no |hl| in the query the |spknlang| will use the application
32 // locale as a fallback (instead of using the same locale for both |hl|
33 // and |spknlang|).
34 if (language.empty()) {
35 voice::SpeechInputLocaleConfig* locale_config =
36 voice::SpeechInputLocaleConfig::GetInstance();
37 if (locale_config)
38 language = locale_config->GetDefaultLocale().code;
39 if (!language.length()) {
40 NOTREACHED();
41 language = "en-US";
42 }
43 }
44 rewritten_url =
45 net::AppendOrReplaceQueryParameter(rewritten_url, "hl", language);
46 rewritten_url =
47 net::AppendQueryParameter(rewritten_url, "spknlang", language);
48 rewritten_url = net::AppendQueryParameter(rewritten_url, "inm", "vs");
49 rewritten_url = net::AppendQueryParameter(rewritten_url, "vse", "1");
50 *url = rewritten_url;
51
52 // Return false so other URLRewriters can update the url if necessary.
53 return false;
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698