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/extensions/api/messaging/arc_support_host.h" |
Sergey Ulanov
2016/03/31 17:24:23
Does this code need to be in this directory? Can i
khmel
2016/03/31 18:02:31
I would say this is hardly achievable. Based on pr
Sergey Ulanov
2016/03/31 18:47:54
I think c/b/chromeos/arc/ would be a better place
khmel
2016/03/31 19:33:33
Done.
| |
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"; |
Sergey Ulanov
2016/03/31 17:24:23
nit: Suggest calling these startLso and kActionSta
khmel
2016/03/31 18:02:31
Thanks for sharing this, this makes sense. Noted f
| |
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/" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_GET_STARTED)); | 80 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_GET_STARTED)); |
79 localized_strings->SetString( | 81 localized_strings->SetString( |
80 "buttonRetry", | 82 "buttonRetry", |
81 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_RETRY)); | 83 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_BUTTON_RETRY)); |
82 localized_strings->SetString( | 84 localized_strings->SetString( |
83 "progressLSOLoading", | 85 "progressLSOLoading", |
84 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_LSO)); | 86 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_LSO)); |
85 localized_strings->SetString( | 87 localized_strings->SetString( |
86 "progressAndroidLoading", | 88 "progressAndroidLoading", |
87 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); | 89 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_PROGRESS_ANDROID)); |
90 localized_strings->SetString( | |
91 "authorizationFailed", | |
92 l10n_util::GetStringUTF16(IDS_ARC_OPT_IN_DIALOG_AUTHORIZATION_FAILED)); | |
88 | 93 |
89 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 94 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
90 webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); | 95 webui::SetLoadTimeDataDefaults(app_locale, localized_strings.get()); |
91 | 96 |
92 base::DictionaryValue request; | 97 base::DictionaryValue request; |
93 std::string request_string; | 98 std::string request_string; |
94 request.SetString(kAction, kActionSetLocalization); | 99 request.SetString(kAction, kActionSetLocalization); |
95 request.Set(kData, std::move(localized_strings)); | 100 request.Set(kData, std::move(localized_strings)); |
96 base::JSONWriter::Write(request, &request_string); | 101 base::JSONWriter::Write(request, &request_string); |
97 client_->PostMessageFromNativeHost(request_string); | 102 client_->PostMessageFromNativeHost(request_string); |
(...skipping 21 matching lines...) Expand all Loading... | |
119 response.SetString(kStatus, status); | 124 response.SetString(kStatus, status); |
120 std::string response_string; | 125 std::string response_string; |
121 base::JSONWriter::Write(response, &response_string); | 126 base::JSONWriter::Write(response, &response_string); |
122 client_->PostMessageFromNativeHost(response_string); | 127 client_->PostMessageFromNativeHost(response_string); |
123 } | 128 } |
124 | 129 |
125 void ArcSupportHost::OnMessage(const std::string& request_string) { | 130 void ArcSupportHost::OnMessage(const std::string& request_string) { |
126 scoped_ptr<base::Value> request_value = | 131 scoped_ptr<base::Value> request_value = |
127 base::JSONReader::Read(request_string); | 132 base::JSONReader::Read(request_string); |
128 scoped_ptr<base::DictionaryValue> request( | 133 scoped_ptr<base::DictionaryValue> request( |
129 static_cast<base::DictionaryValue*>(request_value.release())); | 134 static_cast<base::DictionaryValue*>(request_value.release())); |
Sergey Ulanov
2016/03/31 17:24:23
You should to use Value::GetAsDictionary() to conv
khmel
2016/03/31 18:02:31
On 2016/03/31 17:24:23, Sergey Ulanov wrote:
> You
| |
130 if (!request.get()) { | 135 if (!request.get()) { |
131 NOTREACHED(); | 136 NOTREACHED(); |
132 return; | 137 return; |
133 } | 138 } |
134 | 139 |
135 std::string action; | 140 std::string action; |
136 if (!request->GetString(kAction, &action)) { | 141 if (!request->GetString(kAction, &action)) { |
137 NOTREACHED(); | 142 NOTREACHED(); |
Sergey Ulanov
2016/03/31 17:24:24
I think you want to log this error, but it shouldn
khmel
2016/03/31 18:02:31
This is our built_in extension. Seems NOTREACHED
| |
138 return; | 143 return; |
139 } | 144 } |
140 | 145 |
141 if (action == kActionCheckAuthCode) { | 146 if (action == kActionStartLSO) { |
142 arc::ArcAuthService::Get()->CheckAuthCode(); | 147 arc::ArcAuthService::Get()->StartLSO(); |
Sergey Ulanov
2016/03/31 17:24:23
nit: StartLso()
khmel
2016/03/31 18:02:31
Done.
| |
148 } else if (action == kActionSetAuthCode) { | |
149 std::string code; | |
150 if (!request->GetString(kCode, &code)) { | |
151 NOTREACHED(); | |
152 return; | |
153 } | |
154 arc::ArcAuthService::Get()->SetAuthCodeAndStartArc(code); | |
143 } else if (action == kActionCancelAuthCode) { | 155 } else if (action == kActionCancelAuthCode) { |
144 arc::ArcAuthService::Get()->CancelAuthCode(); | 156 arc::ArcAuthService::Get()->CancelAuthCode(); |
145 } else { | 157 } else { |
146 NOTREACHED(); | 158 NOTREACHED(); |
147 } | 159 } |
148 } | 160 } |
149 | 161 |
150 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() | 162 scoped_refptr<base::SingleThreadTaskRunner> ArcSupportHost::task_runner() |
151 const { | 163 const { |
152 return base::ThreadTaskRunnerHandle::Get(); | 164 return base::ThreadTaskRunnerHandle::Get(); |
153 } | 165 } |
OLD | NEW |