OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/translate/translate_service_ios.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "components/translate/core/browser/translate_download_manager.h" | |
9 #include "components/translate/core/browser/translate_manager.h" | |
10 #include "ios/chrome/browser/application_context.h" | |
11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | |
12 #include "url/gurl.h" | |
13 | |
14 namespace { | |
15 // The singleton instance of TranslateServiceIOS. | |
16 TranslateServiceIOS* g_translate_service = nullptr; | |
17 } | |
18 | |
19 TranslateServiceIOS::TranslateServiceIOS() | |
20 : resource_request_allowed_notifier_( | |
21 GetApplicationContext()->GetLocalState(), | |
22 nullptr) { | |
23 resource_request_allowed_notifier_.Init(this); | |
24 } | |
25 | |
26 TranslateServiceIOS::~TranslateServiceIOS() { | |
27 } | |
28 | |
29 // static | |
30 void TranslateServiceIOS::Initialize() { | |
31 if (g_translate_service) | |
32 return; | |
33 | |
34 g_translate_service = new TranslateServiceIOS; | |
35 // Initialize the allowed state for resource requests. | |
36 g_translate_service->OnResourceRequestsAllowed(); | |
37 translate::TranslateDownloadManager* download_manager = | |
38 translate::TranslateDownloadManager::GetInstance(); | |
39 download_manager->set_request_context( | |
40 GetApplicationContext()->GetSystemURLRequestContext()); | |
41 download_manager->set_application_locale( | |
42 GetApplicationContext()->GetApplicationLocale()); | |
43 } | |
44 | |
45 // static | |
46 void TranslateServiceIOS::Shutdown() { | |
47 translate::TranslateDownloadManager* download_manager = | |
48 translate::TranslateDownloadManager::GetInstance(); | |
49 download_manager->Shutdown(); | |
50 } | |
51 | |
52 void TranslateServiceIOS::OnResourceRequestsAllowed() { | |
53 translate::TranslateLanguageList* language_list = | |
54 translate::TranslateDownloadManager::GetInstance()->language_list(); | |
55 if (!language_list) { | |
56 NOTREACHED(); | |
57 return; | |
58 } | |
59 | |
60 language_list->SetResourceRequestsAllowed( | |
61 resource_request_allowed_notifier_.ResourceRequestsAllowed()); | |
62 } | |
63 | |
64 // static | |
65 bool TranslateServiceIOS::IsTranslatableURL(const GURL& url) { | |
66 // A URL is translatable unless it is one of the following: | |
67 // - empty (can happen for popups created with window.open("")) | |
68 // - an internal URL (chrome:// and others) | |
sdefresne
2015/01/08 09:22:33
nit: the comment does not agree with the code (the
| |
69 return !url.is_empty() && | |
70 !url.SchemeIs(ios::GetChromeBrowserProvider()->GetChromeUIScheme()); | |
71 } | |
OLD | NEW |