OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #import "ios/chrome/browser/voice/voice_search_url_rewriter.h" | 5 #import "ios/chrome/browser/voice/voice_search_url_rewriter.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #import "base/strings/sys_string_conversions.h" | 10 #import "base/strings/sys_string_conversions.h" |
11 #include "components/google/core/browser/google_util.h" | 11 #include "components/google/core/browser/google_util.h" |
12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
14 #include "ios/chrome/browser/voice/speech_input_locale_config.h" | 14 #include "ios/chrome/browser/voice/speech_input_locale_config.h" |
15 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" | 15 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" |
16 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
19 bool VoiceSearchURLRewriter(GURL* url, web::BrowserState* browser_state) { | 23 bool VoiceSearchURLRewriter(GURL* url, web::BrowserState* browser_state) { |
20 if (!google_util::IsGoogleSearchUrl(*url)) | 24 if (!google_util::IsGoogleSearchUrl(*url)) |
21 return false; | 25 return false; |
22 | 26 |
23 ios::ChromeBrowserState* chrome_browser_state = | 27 ios::ChromeBrowserState* chrome_browser_state = |
24 ios::ChromeBrowserState::FromBrowserState(browser_state); | 28 ios::ChromeBrowserState::FromBrowserState(browser_state); |
25 std::string language = | 29 std::string language = |
26 chrome_browser_state->GetPrefs()->GetString(prefs::kVoiceSearchLocale); | 30 chrome_browser_state->GetPrefs()->GetString(prefs::kVoiceSearchLocale); |
27 GURL rewritten_url(*url); | 31 GURL rewritten_url(*url); |
28 // The |hl| parameter will be overriden only if the voice search locale | 32 // The |hl| parameter will be overriden only if the voice search locale |
(...skipping 16 matching lines...) Expand all Loading... |
45 net::AppendOrReplaceQueryParameter(rewritten_url, "hl", language); | 49 net::AppendOrReplaceQueryParameter(rewritten_url, "hl", language); |
46 rewritten_url = | 50 rewritten_url = |
47 net::AppendQueryParameter(rewritten_url, "spknlang", language); | 51 net::AppendQueryParameter(rewritten_url, "spknlang", language); |
48 rewritten_url = net::AppendQueryParameter(rewritten_url, "inm", "vs"); | 52 rewritten_url = net::AppendQueryParameter(rewritten_url, "inm", "vs"); |
49 rewritten_url = net::AppendQueryParameter(rewritten_url, "vse", "1"); | 53 rewritten_url = net::AppendQueryParameter(rewritten_url, "vse", "1"); |
50 *url = rewritten_url; | 54 *url = rewritten_url; |
51 | 55 |
52 // Return false so other URLRewriters can update the url if necessary. | 56 // Return false so other URLRewriters can update the url if necessary. |
53 return false; | 57 return false; |
54 } | 58 } |
OLD | NEW |