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

Unified 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: Disabled Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/voice/voice_search_url_rewriter.h ('k') | ios/chrome/test/data/voice/test_sound.m4a » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/voice/voice_search_url_rewriter.mm
diff --git a/ios/chrome/browser/voice/voice_search_url_rewriter.mm b/ios/chrome/browser/voice/voice_search_url_rewriter.mm
new file mode 100644
index 0000000000000000000000000000000000000000..73d891ee1314c06235666690f5b146d6ed7ce465
--- /dev/null
+++ b/ios/chrome/browser/voice/voice_search_url_rewriter.mm
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/voice/voice_search_url_rewriter.h"
+
+#import <Foundation/Foundation.h>
+
+#import "base/mac/scoped_nsobject.h"
+#import "base/strings/sys_string_conversions.h"
+#include "components/google/core/browser/google_util.h"
+#include "components/prefs/pref_service.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/chrome/browser/pref_names.h"
+#include "ios/chrome/browser/voice/speech_input_locale_config.h"
+#include "net/base/url_util.h"
+#include "url/gurl.h"
+
+bool VoiceSearchURLRewriter(GURL* url, web::BrowserState* browser_state) {
+ if (!google_util::IsGoogleSearchUrl(*url))
+ return false;
+
+ ios::ChromeBrowserState* chrome_browser_state =
+ ios::ChromeBrowserState::FromBrowserState(browser_state);
+ std::string language =
+ chrome_browser_state->GetPrefs()->GetString(prefs::kVoiceSearchLocale);
+ GURL rewritten_url(*url);
+ // The |hl| parameter will be overriden only if the voice search locale
+ // is not empty. If it is empty (indicating that voice search locale
+ // uses device language), the |hl| will keep the original value.
+ // If there is no |hl| in the query the |spknlang| will use the application
+ // locale as a fallback (instead of using the same locale for both |hl|
+ // and |spknlang|).
+ if (language.empty()) {
+ voice::SpeechInputLocaleConfig* locale_config =
+ voice::SpeechInputLocaleConfig::GetInstance();
+ if (locale_config)
+ language = locale_config->GetDefaultLocale().code;
+ if (!language.length()) {
+ NOTREACHED();
+ language = "en-US";
+ }
+ }
+ rewritten_url =
+ net::AppendOrReplaceQueryParameter(rewritten_url, "hl", language);
+ rewritten_url =
+ net::AppendQueryParameter(rewritten_url, "spknlang", language);
+ rewritten_url = net::AppendQueryParameter(rewritten_url, "inm", "vs");
+ rewritten_url = net::AppendQueryParameter(rewritten_url, "vse", "1");
+ *url = rewritten_url;
+
+ // Return false so other URLRewriters can update the url if necessary.
+ return false;
+}
« no previous file with comments | « ios/chrome/browser/voice/voice_search_url_rewriter.h ('k') | ios/chrome/test/data/voice/test_sound.m4a » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698