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 #include "chrome/browser/extensions/api/messaging/arc_support_host.h" | 5 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
6 | 6 |
7 #include "ash/system/chromeos/devicetype_utils.h" | 7 #include "ash/system/chromeos/devicetype_utils.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/webui/web_ui_util.h" | 15 #include "ui/base/webui/web_ui_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 const char kAction[] = "action"; | 18 const char kAction[] = "action"; |
| 19 const char kCode[] = "code"; |
19 const char kStatus[] = "status"; | 20 const char kStatus[] = "status"; |
20 const char kData[] = "data"; | 21 const char kData[] = "data"; |
21 const char kPage[] = "page"; | 22 const char kPage[] = "page"; |
22 const char kActionSetLocalization[] = "setLocalization"; | 23 const char kActionSetLocalization[] = "setLocalization"; |
23 const char kActionCheckAuthCode[] = "checkAuthCode"; | 24 const char kActionStartLso[] = "startLso"; |
24 const char kActionCancelAuthCode[] = "cancelAuthCode"; | 25 const char kActionCancelAuthCode[] = "cancelAuthCode"; |
| 26 const char kActionSetAuthCode[] = "setAuthCode"; |
25 const char kActionCloseUI[] = "closeUI"; | 27 const char kActionCloseUI[] = "closeUI"; |
26 const char kActionShowPage[] = "showPage"; | 28 const char kActionShowPage[] = "showPage"; |
27 } // namespace | 29 } // namespace |
28 | 30 |
29 // static | 31 // static |
30 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; | 32 const char ArcSupportHost::kHostName[] = "com.google.arc_support"; |
31 | 33 |
32 // static | 34 // static |
33 const char* const ArcSupportHost::kHostOrigin[] = { | 35 const char* const ArcSupportHost::kHostOrigin[] = { |
34 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/" | 36 "chrome-extension://cnbgggchhmkkdmeppjobngjoejnihlei/"}; |
35 }; | |
36 | 37 |
37 // static | 38 // static |
38 scoped_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { | 39 scoped_ptr<extensions::NativeMessageHost> ArcSupportHost::Create() { |
39 return scoped_ptr<NativeMessageHost>(new ArcSupportHost()); | 40 return scoped_ptr<NativeMessageHost>(new ArcSupportHost()); |
40 } | 41 } |
41 | 42 |
42 ArcSupportHost::ArcSupportHost() { | 43 ArcSupportHost::ArcSupportHost() { |
43 arc::ArcAuthService::Get()->AddObserver(this); | 44 arc::ArcAuthService::Get()->AddObserver(this); |
44 } | 45 } |
45 | 46 |
(...skipping 27 matching lines...) Expand all Loading... |
73 localized_strings->SetString( | 74 localized_strings->SetString( |
74 "greetingLegacy", | 75 "greetingLegacy", |
75 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_LEGACY)); | 76 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_LEGACY)); |
76 localized_strings->SetString( | 77 localized_strings->SetString( |
77 "buttonGetStarted", | 78 "buttonGetStarted", |
78 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_GET_STARTED)); | 79 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_GET_STARTED)); |
79 localized_strings->SetString( | 80 localized_strings->SetString( |
80 "buttonRetry", | 81 "buttonRetry", |
81 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_RETRY)); | 82 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_RETRY)); |
82 localized_strings->SetString( | 83 localized_strings->SetString( |
83 "progressLSOLoading", | 84 "progressLsoLoading", |
84 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_LSO)); | 85 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_LSO)); |
85 localized_strings->SetString( | 86 localized_strings->SetString( |
86 "progressAndroidLoading", | 87 "progressAndroidLoading", |
87 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); | 88 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); |
| 89 localized_strings->SetString( |
| 90 "authorizationFailed", |
| 91 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_AUTHORIZATION_FAILED)); |
88 | 92 |
89 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 93 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
90 webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); | 94 webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); |
91 | 95 |
92 base::DictionaryValue request; | 96 base::DictionaryValue request; |
93 std::string request_string; | 97 std::string request_string; |
94 request.SetString(kAction, kActionSetLocalization); | 98 request.SetString(kAction, kActionSetLocalization); |
95 request.Set(kData, std::move(localized_strings)); | 99 request.Set(kData, std::move(localized_strings)); |
96 base::JSONWriter::Write(request, &request_string); | 100 base::JSONWriter::Write(request, &request_string); |
97 client_->PostMessageFromNativeHost(request_string); | 101 client_->PostMessageFromNativeHost(request_string); |
(...skipping 20 matching lines...) Expand all Loading... |
118 response.SetInteger(kPage, static_cast<int>(page)); | 122 response.SetInteger(kPage, static_cast<int>(page)); |
119 response.SetString(kStatus, status); | 123 response.SetString(kStatus, status); |
120 std::string response_string; | 124 std::string response_string; |
121 base::JSONWriter::Write(response, &response_string); | 125 base::JSONWriter::Write(response, &response_string); |
122 client_->PostMessageFromNativeHost(response_string); | 126 client_->PostMessageFromNativeHost(response_string); |
123 } | 127 } |
124 | 128 |
125 void ArcSupportHost::OnMessage(const std::string& request_string) { | 129 void ArcSupportHost::OnMessage(const std::string& request_string) { |
126 scoped_ptr<base::Value> request_value = | 130 scoped_ptr<base::Value> request_value = |
127 base::JSONReader::Read(request_string); | 131 base::JSONReader::Read(request_string); |
128 scoped_ptr<base::DictionaryValue> request( | 132 base::DictionaryValue* request; |
129 static_cast<base::DictionaryValue*>(request_value.release())); | 133 if (!request_value || !request_value->GetAsDictionary(&request)) { |
130 if (!request.get()) { | |
131 NOTREACHED(); | 134 NOTREACHED(); |
132 return; | 135 return; |
133 } | 136 } |
134 | 137 |
135 std::string action; | 138 std::string action; |
136 if (!request->GetString(kAction, &action)) { | 139 if (!request->GetString(kAction, &action)) { |
137 NOTREACHED(); | 140 NOTREACHED(); |
138 return; | 141 return; |
139 } | 142 } |
140 | 143 |
141 if (action == kActionCheckAuthCode) { | 144 if (action == kActionStartLso) { |
142 arc::ArcAuthService::Get()->CheckAuthCode(); | 145 arc::ArcAuthService::Get()->StartLso(); |
| 146 } else if (action == kActionSetAuthCode) { |
| 147 std::string code; |
| 148 if (!request->GetString(kCode, &code)) { |
| 149 NOTREACHED(); |
| 150 return; |
| 151 } |
| 152 arc::ArcAuthService::Get()->SetAuthCodeAndStartArc(code); |
143 } else if (action == kActionCancelAuthCode) { | 153 } else if (action == kActionCancelAuthCode) { |
144 arc::ArcAuthService::Get()->CancelAuthCode(); | 154 arc::ArcAuthService::Get()->CancelAuthCode(); |
145 } else { | 155 } else { |
146 NOTREACHED(); | 156 NOTREACHED(); |
147 } | 157 } |
148 } | 158 } |
149 | 159 |
150 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 160 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
151 const { | 161 const { |
152 return base::ThreadTaskRunnerHandle::Get(); | 162 return base::ThreadTaskRunnerHandle::Get(); |
153 } | 163 } |
OLD | NEW |