Codebase list mozc / 18fa27d
Added std:: prefix to Windows build and a few files BUG=#392 TEST=unittest REF_BUG=71969651 REF_CL=182312682 REF_TIME=2018-01-18T13:37:36+09:00 REF_TIME_RAW=1516250256 +0900 Hiroyuki Komatsu 6 years ago
151 changed file(s) with 1100 addition(s) and 1067 deletion(s). Raw diff Collapse all Expand all
7070 }
7171
7272 void MockJNIEnv::ClearArrayMap() {
73 for (map<jbyteArray, pair<jsize, jbyte*> >::iterator iter =
73 for (std::map<jbyteArray, pair<jsize, jbyte*> >::iterator iter =
7474 byte_array_map_.begin();
7575 iter != byte_array_map_.end(); ++iter) {
7676 delete iter->first;
133133 << "_data_wordtype[] = {\n";
134134 output_stream_format_flags_ = output_stream_->flags();
135135 // Set the output format in the form of "0x000012340000ABCD".
136 output_stream_->setf(ios_base::hex, ios_base::basefield);
137 output_stream_->setf(ios_base::uppercase);
138 output_stream_->setf(ios_base::right);
136 output_stream_->setf(std::ios_base::hex, std::ios_base::basefield);
137 output_stream_->setf(std::ios_base::uppercase);
138 output_stream_->setf(std::ios_base::right);
139139 output_stream_format_fill_ = output_stream_->fill('0');
140140 // Put the prefix "0x" by ourselves, otherwise it becomes "0X".
141 output_stream_->unsetf(ios_base::showbase);
141 output_stream_->unsetf(std::ios_base::showbase);
142142 word_buffer_ = 0;
143143 #else
144144 *output_stream_ << "const char k" << var_name_base_ << "_data[] =\n";
238238 char * const buf = reinterpret_cast<char *>(&word_buffer_);
239239 const size_t kWordSize = sizeof word_buffer_;
240240 while (begin < end) {
241 size_t output_length = min(static_cast<size_t>(end - begin),
242 kWordSize - output_count_ % kWordSize);
241 size_t output_length = std::min(static_cast<size_t>(end - begin),
242 kWordSize - output_count_ % kWordSize);
243243 for (size_t i = 0; i < output_length; ++i) {
244244 buf[output_count_ % kWordSize + i] = *begin++;
245245 }
275275
276276 #ifdef MOZC_CODEGEN_BYTEARRAY_STREAM_USES_WORD_ARRAY
277277 void WriteWordBuffer() {
278 *output_stream_ << "0x" << setw(2 * sizeof word_buffer_) << word_buffer_;
278 *output_stream_ << "0x" << std::setw(2 * sizeof word_buffer_)
279 << word_buffer_;
279280 word_buffer_ = 0;
280281 }
281282 #endif
286287 std::basic_ostream<char> *output_stream_;
287288 codegenstream::StreamOwner own_output_stream_;
288289 #ifdef MOZC_CODEGEN_BYTEARRAY_STREAM_USES_WORD_ARRAY
289 ios_base::fmtflags output_stream_format_flags_;
290 std::ios_base::fmtflags output_stream_format_flags_;
290291 char output_stream_format_fill_;
291292 #endif
292293
318319 // A call to |OpenVarDef| must precede any output to the instance.
319320 void OpenVarDef(const string &var_name_base) {
320321 if (!streambuf_.OpenVarDef(var_name_base)) {
321 this->setstate(ios_base::failbit);
322 this->setstate(std::ios_base::failbit);
322323 }
323324 }
324325
327328 // unless |OpenVarDef| is called with a different variable name.
328329 void CloseVarDef() {
329330 if (!streambuf_.CloseVarDef()) {
330 this->setstate(ios_base::failbit);
331 this->setstate(std::ios_base::failbit);
331332 }
332333 }
333334
141141
142142 // Returns the pipe name of the GoogleCrashHandler.exe or
143143 // GoogleCrashHandler64.exe running as a system user.
144 wstring GetCrashHandlerPipeName() {
145 wstring pipe_name = kGoogleCrashHandlerPipePrefix;
144 std::wstring GetCrashHandlerPipeName() {
145 std::wstring pipe_name = kGoogleCrashHandlerPipePrefix;
146146 pipe_name.append(kSystemPrincipalSid);
147147 pipe_name.append(kGoogleCrashHandlerPipePostfix);
148148 return pipe_name;
268268 FileUtil::CreateDirectory(acrashdump_directory);
269269 }
270270
271 wstring crashdump_directory;
271 std::wstring crashdump_directory;
272272 Util::UTF8ToWide(acrashdump_directory, &crashdump_directory);
273273
274274 google_breakpad::ExceptionHandler::FilterCallback filter_callback =
5050 }
5151
5252 InputFileStream::InputFileStream(const char* filename,
53 ios_base::openmode mode)
53 std::ios_base::openmode mode)
5454 : std::istream(nullptr) {
5555 init(&string_buffer_);
5656 InputFileStream::open(filename, mode);
5757 }
5858
59 void InputFileStream::open(const char* filename, ios_base::openmode mode) {
59 void InputFileStream::open(const char* filename, std::ios_base::openmode mode) {
6060 string buffer;
6161 const bool ret = PepperFileUtil::ReadBinaryFile(filename, &buffer);
6262 if (ret) {
6363 string_buffer_.sputn(buffer.c_str(), buffer.length());
6464 } else {
65 setstate(ios_base::failbit);
65 setstate(std::ios_base::failbit);
6666 }
6767 }
6868
7575 }
7676
7777 OutputFileStream::OutputFileStream(const char* filename,
78 ios_base::openmode mode)
78 std::ios_base::openmode mode)
7979 : ostream(),
8080 write_done_(false) {
8181 init(&string_buffer_);
8686 close();
8787 }
8888
89 void OutputFileStream::open(const char* filename, ios_base::openmode mode) {
89 void OutputFileStream::open(const char* filename,
90 std::ios_base::openmode mode) {
9091 filename_ = filename;
9192 }
9293
107108 namespace {
108109
109110 #ifdef OS_WIN
110 wstring ToPlatformString(const char* filename) {
111 std::wstring ToPlatformString(const char* filename) {
111112 // Since Windows uses UTF-16 for internationalized file names, we should
112113 // convert the encoding of the given |filename| from UTF-8 to UTF-16.
113114 // NOTE: To avoid circular dependency, |Util::UTF8ToWide| shouldn't be used
126127 InputFileStream::InputFileStream() {}
127128
128129 InputFileStream::InputFileStream(const char* filename,
129 ios_base::openmode mode) {
130 std::ios_base::openmode mode) {
130131 InputFileStream::open(filename, mode);
131132 }
132133
133 void InputFileStream::open(const char* filename, ios_base::openmode mode) {
134 void InputFileStream::open(const char* filename, std::ios_base::openmode mode) {
134135 std::ifstream::open(ToPlatformString(filename), mode);
135136 }
136137
137138 OutputFileStream::OutputFileStream() {}
138139
139140 OutputFileStream::OutputFileStream(const char* filename,
140 ios_base::openmode mode) {
141 std::ios_base::openmode mode) {
141142 OutputFileStream::open(filename, mode);
142143 }
143144
144 void OutputFileStream::open(const char* filename, ios_base::openmode mode) {
145 void OutputFileStream::open(const char* filename,
146 std::ios_base::openmode mode) {
145147 std::ofstream::open(ToPlatformString(filename), mode);
146148 }
147149 #endif // MOZC_USE_PEPPER_FILE_IO
4848 public:
4949 InputFileStream();
5050 explicit InputFileStream(const char* filename,
51 ios_base::openmode mode = ios_base::in);
51 std::ios_base::openmode mode = std::ios_base::in);
5252 // Opens the file and reads the all data to string_buffer_.
53 void open(const char* filename, ios_base::openmode mode = ios_base::in);
53 void open(const char* filename, ios_base::openmode mode = std::ios_base::in);
5454 // Do nothing.
5555 // Note: Error handling after close() is not correctly implemented.
5656 // TODO(horo) Implement error handling correctly.
7474 public:
7575 OutputFileStream();
7676 explicit OutputFileStream(const char* filename,
77 ios_base::openmode mode = ios_base::in);
77 std::ios_base::openmode mode = std::ios_base::in);
7878 ~OutputFileStream();
7979 // Sets filename_.
80 void open(const char* filename, ios_base::openmode mode = ios_base::in);
80 void open(const char* filename, ios_base::openmode mode = std::ios_base::in);
8181 // Write the data to the file using Pepper FileIO.
8282 // Note: Error handling after close() is not correctly implemented.
8383 // TODO(horo) Implement error handling correctly.
106106 public:
107107 InputFileStream();
108108 explicit InputFileStream(const char* filename,
109 ios_base::openmode mode = ios_base::in);
109 std::ios_base::openmode mode = std::ios_base::in);
110110
111111 // Opens the specified file.
112112 // This function is a wrapper function for the ifstream::open() function
113113 // to change the encoding of the specified file name from UTF-8 to its native
114114 // one before calling the ifstream::open() function.
115 void open(const char* filename, ios_base::openmode mode = ios_base::in);
115 void open(const char* filename,
116 std::ios_base::openmode mode = std::ios_base::in);
116117
117118 // Helper functions to load the entire content of a file into string.
118119 void ReadToString(string *s);
126127 public:
127128 OutputFileStream();
128129 explicit OutputFileStream(const char* filename,
129 ios_base::openmode mode = ios_base::out);
130 std::ios_base::openmode mode = std::ios_base::out);
130131
131132 // Opens the specified file.
132133 // This function is a wrapper function for the ofstream::open() function
133134 // to change the encoding of the specified file name from UTF-8 to its native
134135 // one before calling the ofstream::open() function.
135 void open(const char* filename, ios_base::openmode mode = ios_base::out);
136 void open(const char* filename,
137 std::ios_base::openmode mode = std::ios_base::out);
136138
137139 private:
138140 virtual void UnusedKeyMethod(); // go/definekeymethod
8686 if (!FileUtil::FileExists(filename)) {
8787 return;
8888 }
89 wstring wide_filename;
89 std::wstring wide_filename;
9090 Util::UTF8ToWide(filename, &wide_filename);
9191 const DWORD kDropAttributes =
9292 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY;
101101
102102 bool FileUtil::CreateDirectory(const string &path) {
103103 #if defined(OS_WIN)
104 wstring wide;
104 std::wstring wide;
105105 return (Util::UTF8ToWide(path, &wide) > 0 &&
106106 ::CreateDirectoryW(wide.c_str(), nullptr) != 0);
107107 #elif defined(OS_NACL) // OS_WIN
113113
114114 bool FileUtil::RemoveDirectory(const string &dirname) {
115115 #ifdef OS_WIN
116 wstring wide;
116 std::wstring wide;
117117 return (Util::UTF8ToWide(dirname, &wide) > 0 &&
118118 ::RemoveDirectoryW(wide.c_str()) != 0);
119119 #elif defined(OS_NACL) // OS_WIN
126126 bool FileUtil::Unlink(const string &filename) {
127127 #ifdef OS_WIN
128128 StripWritePreventingAttributesIfExists(filename);
129 wstring wide;
129 std::wstring wide;
130130 return (Util::UTF8ToWide(filename, &wide) > 0 &&
131131 ::DeleteFileW(wide.c_str()) != 0);
132132 #elif defined(MOZC_USE_PEPPER_FILE_IO)
138138
139139 bool FileUtil::FileExists(const string &filename) {
140140 #ifdef OS_WIN
141 wstring wide;
141 std::wstring wide;
142142 return (Util::UTF8ToWide(filename, &wide) > 0 &&
143143 ::GetFileAttributesW(wide.c_str()) != -1);
144144 #elif defined(MOZC_USE_PEPPER_FILE_IO)
151151
152152 bool FileUtil::DirectoryExists(const string &dirname) {
153153 #ifdef OS_WIN
154 wstring wide;
154 std::wstring wide;
155155 if (Util::UTF8ToWide(dirname, &wide) <= 0) {
156156 return false;
157157 }
170170 #ifdef OS_WIN
171171 namespace {
172172
173 bool TransactionalMoveFile(const wstring &from, const wstring &to) {
173 bool TransactionalMoveFile(const std::wstring &from, const std::wstring &to) {
174174 const DWORD kTimeout = 5000; // 5 sec.
175175 ScopedHandle handle(::CreateTransaction(
176176 nullptr, 0, 0, 0, 0, kTimeout, nullptr));
228228 return false;
229229 }
230230
231 wstring wfilename;
231 std::wstring wfilename;
232232 Util::UTF8ToWide(filename, &wfilename);
233233
234234 const DWORD original_attributes = ::GetFileAttributesW(wfilename.c_str());
249249 }
250250
251251 #ifdef OS_WIN
252 wstring wto;
252 std::wstring wto;
253253 Util::UTF8ToWide(to, &wto);
254254 StripWritePreventingAttributesIfExists(to);
255255 #endif // OS_WIN
270270 ofs.close();
271271
272272 #ifdef OS_WIN
273 wstring wfrom;
273 std::wstring wfrom;
274274 Util::UTF8ToWide(from, &wfrom);
275275 ::SetFileAttributesW(wto.c_str(), ::GetFileAttributesW(wfrom.c_str()));
276276 #endif // OS_WIN
301301
302302 bool FileUtil::AtomicRename(const string &from, const string &to) {
303303 #ifdef OS_WIN
304 wstring fromw, tow;
304 std::wstring fromw, tow;
305305 Util::UTF8ToWide(from, &fromw);
306306 Util::UTF8ToWide(to, &tow);
307307
384384 bool FileUtil::GetModificationTime(const string &filename,
385385 FileTimeStamp *modified_at) {
386386 #if defined (OS_WIN)
387 wstring wide;
387 std::wstring wide;
388388 if (!Util::UTF8ToWide(filename, &wide)) {
389389 return false;
390390 }
133133 FILE_ATTRIBUTE_TEMPORARY,
134134 };
135135
136 wstring wfilepath;
136 std::wstring wfilepath;
137137 Util::UTF8ToWide(filepath, &wfilepath);
138138 for (size_t i = 0; i < arraysize(kTestAttributeList); ++i) {
139139 SCOPED_TRACE(Util::StringPrintf("AttributeTest %zd", i));
156156
157157 EXPECT_FALSE(FileUtil::HideFile(filename));
158158
159 wstring wfilename;
159 std::wstring wfilename;
160160 Util::UTF8ToWide(filename.c_str(), &wfilename);
161161
162162 CreateTestFile(filename, "test data");
266266 CreateTestFile(from, test_label);
267267
268268 const TestData &kData = kTestDataList[i];
269 wstring wfrom, wto;
269 std::wstring wfrom, wto;
270270 Util::UTF8ToWide(from.c_str(), &wfrom);
271271 Util::UTF8ToWide(to.c_str(), &wto);
272272 EXPECT_NE(FALSE,
355355 CreateTestFile(from, test_label);
356356
357357 const TestData &kData = kTestDataList[i];
358 wstring wfrom, wto;
358 std::wstring wfrom, wto;
359359 Util::UTF8ToWide(from.c_str(), &wfrom);
360360 Util::UTF8ToWide(to.c_str(), &wto);
361361 EXPECT_NE(FALSE,
6767 // return iter->first;
6868 // }
6969 // };
70 // vector<pair<int, double> > data;
70 // std::vector<pair<int, double> > data;
7171 // :
7272 // // To find the first element whose first is 5.
7373 // typedef IteratorAdapter<vector<pair<int, double> >, FirstAdapter>
7474 // FirstIterator;
75 // vector<pair<int, double> >::const_iterator iter =
75 // std::vector<pair<int, double> >::const_iterator iter =
7676 // find(FirstIterator(data.begin()), FirstIterator(data.end()), 5).base();
7777 //
7878 // Below, two utilities are provided, AdapterBase class and MakeIteratorAdapter
8585 // return iter->first;
8686 // }
8787 // };
88 // vector<pair<int, double> > data;
89 // vector<pair<int, double> >::const_iterator iter =
88 // std::vector<pair<int, double> > data;
89 // std::vector<pair<int, double> >::const_iterator iter =
9090 // find(MakeIteratorAdapter(data.begin(), FirstAdapter()),
9191 // MakeIteratorAdapter(data.end(), FirstAdapter()), 5).base();
9292 //
8080 return false;
8181 }
8282
83 wstring filename_wide;
83 std::wstring filename_wide;
8484 if (Util::UTF8ToWide(filename, &filename_wide) <= 0) {
8585 return false;
8686 }
7676 return;
7777 }
7878 #ifdef OS_WIN
79 wstring wfilename;
79 std::wstring wfilename;
8080 Util::UTF8ToWide(filename_, &wfilename);
8181 if (!::SetFileAttributesW(wfilename.c_str(), FILE_ATTRIBUTE_NORMAL)) {
8282 LOG(ERROR) << "Cannot make writable: " << filename_;
769769
770770 bool PepperFileSystem::SyncMmapToFile() {
771771 scoped_lock lock(&mutex_);
772 for (set<MmapSyncInterface*>::iterator it = mmap_set_.begin();
772 for (std::set<MmapSyncInterface*>::iterator it = mmap_set_.begin();
773773 it != mmap_set_.end(); ++it) {
774774 (*it)->SyncToFile();
775775 }
9090 }
9191
9292 #ifdef OS_WIN
93 wstring wurl;
93 std::wstring wurl;
9494 Util::UTF8ToWide(url, &wurl);
9595 return WinUtil::ShellExecuteInSystemDir(L"open", wurl.c_str(), nullptr);
9696 #endif
111111 bool Process::SpawnProcess(const string &path,
112112 const string& arg, size_t *pid) {
113113 #ifdef OS_WIN
114 wstring wpath;
114 std::wstring wpath;
115115 Util::UTF8ToWide(path, &wpath);
116116 wpath = L"\"" + wpath + L"\"";
117117 if (!arg.empty()) {
118 wstring warg;
118 std::wstring warg;
119119 Util::UTF8ToWide(arg, &warg);
120120 wpath += L" ";
121121 wpath += warg;
9393 return false;
9494 }
9595
96 wstring wfilename;
96 std::wstring wfilename;
9797 Util::UTF8ToWide(filename_, &wfilename);
9898 const DWORD kAttribute =
9999 FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM |
160160
161161 private:
162162 Mutex mutex_;
163 map<string, string> lock_map_;
163 std::map<string, string> lock_map_;
164164 DISALLOW_COPY_AND_ASSIGN(NamedLockManager);
165165 };
166166
218218 // See http://b/2301066 for details.
219219 const string user_dir = SystemUtil::GetUserProfileDirectory();
220220
221 wstring dir;
221 std::wstring dir;
222222 Util::UTF8ToWide(user_dir, &dir);
223223 ScopedHandle dir_handle(::CreateFile(dir.c_str(),
224224 READ_CONTROL | WRITE_DAC,
150150 if (FAILED(result)) {
151151 return result;
152152 }
153 wstring path = config;
154 const wstring::size_type local_pos = path.find(L"\\Packages\\");
155 if (local_pos == wstring::npos) {
153 std::wstring path = config;
154 const std::wstring::size_type local_pos = path.find(L"\\Packages\\");
155 if (local_pos == std::wstring::npos) {
156156 return E_FAIL;
157157 }
158158 path.erase(local_pos);
183183 return E_UNEXPECTED;
184184 }
185185
186 wstring wpath = task_mem_buffer;
186 std::wstring wpath = task_mem_buffer;
187187 ::CoTaskMemFree(task_mem_buffer);
188188
189189 string path;
5252
5353 HKEY created_key;
5454 bool reg_create_key_ex_called;
55 wstring created_key_path;
55 std::wstring created_key_path;
5656 bool reg_set_value_ex_called;
57 wstring written_value_name;
58 wstring written_value;
57 std::wstring written_value_name;
58 std::wstring written_value;
5959 DWORD written_type;
6060 bool reg_close_key_called;
6161 };
6262
6363 static void SetUpTestCase() {
64 vector<WinAPITestHelper::HookRequest> requests;
64 std::vector<WinAPITestHelper::HookRequest> requests;
6565 requests.push_back(
6666 DEFINE_HOOK("advapi32.dll", RegCreateKeyExW, HookRegCreateKeyExW));
6767 requests.push_back(
110110 call_result_->reg_set_value_ex_called = true;
111111 call_result_->written_value_name = value_name;
112112 call_result_->written_value =
113 wstring(reinterpret_cast<const wchar_t*>(data));
113 std::wstring(reinterpret_cast<const wchar_t*>(data));
114114 call_result_->written_type = type;
115115 return ERROR_SUCCESS;
116116 }
802802 return num_chars;
803803 }
804804
805 int Util::UTF8ToWide(StringPiece input, wstring *output) {
805 int Util::UTF8ToWide(StringPiece input, std::wstring *output) {
806806 const size_t output_length = WideCharsLen(input);
807807 if (output_length == 0) {
808808 return 0;
836836 return result;
837837 }
838838
839 int Util::WideToUTF8(const wstring &input, string *output) {
839 int Util::WideToUTF8(const std::wstring &input, string *output) {
840840 return WideToUTF8(input.c_str(), output);
841841 }
842842 #endif // OS_WIN
228228 static size_t WideCharsLen(StringPiece src);
229229 // Converts the encoding of the specified string from UTF-8 to UTF-16, and
230230 // vice versa.
231 static int UTF8ToWide(StringPiece input, wstring *output);
231 static int UTF8ToWide(StringPiece input, std::wstring *output);
232232 static int WideToUTF8(const wchar_t *input, string *output);
233 static int WideToUTF8(const wstring &input, string *output);
233 static int WideToUTF8(const std::wstring &input, string *output);
234234 #endif // OS_WIN
235235
236236 // Extracts a substring range, where both start and length are in terms of
16471647
16481648 TEST(UtilTest, UTF8ToWide) {
16491649 const string input_utf8 = "abc";
1650 wstring output_wide;
1650 std::wstring output_wide;
16511651 Util::UTF8ToWide(input_utf8, &output_wide);
16521652
16531653 string output_utf8;
16631663 string output_utf8;
16641664 Util::WideToUTF8(input_wide, &output_utf8);
16651665
1666 wstring output_wide;
1666 std::wstring output_wide;
16671667 Util::UTF8ToWide(output_utf8, &output_wide);
16681668
16691669 EXPECT_EQ("\360\240\256\237", output_utf8);
4848 }
4949
5050 #ifdef OS_WIN
51 wstring Version::GetMozcVersionW() {
52 wstring version;
51 std::wstring Version::GetMozcVersionW() {
52 std::wstring version;
5353 Util::UTF8ToWide(version::kMozcVersion, &version);
5454 return version;
5555 }
4040 static string GetMozcVersion();
4141
4242 #ifdef OS_WIN
43 // Get current mozc version (former called MOZC_VERSION) by wstring
44 static wstring GetMozcVersionW();
43 // Get current mozc version (former called MOZC_VERSION) by std::wstring
44 static std::wstring GetMozcVersionW();
4545 #endif
4646
4747 static int GetMozcVersionMajor();
9898 class HookTargetInfo {
9999 public:
100100 explicit HookTargetInfo(
101 const vector<WinAPITestHelper::HookRequest> &requests) {
101 const std::vector<WinAPITestHelper::HookRequest> &requests) {
102102 for (size_t i = 0; i < requests.size(); ++i) {
103103 const auto &request = requests[i];
104104 HMODULE module_handle = nullptr;
147147 }
148148
149149 private:
150 map<string, map<FunctionPointer, FunctionPointer>> info_;
150 std::map<string, std::map<FunctionPointer, FunctionPointer>> info_;
151151 };
152152
153153 class PortableExecutableImage {
285285
286286 class WinAPITestHelper::RestoreInfo {
287287 public:
288 vector<ThunkRewriter> rewrites;
288 std::vector<ThunkRewriter> rewrites;
289289 };
290290
291291 WinAPITestHelper::HookRequest::HookRequest(
299299 // static
300300 WinAPITestHelper::RestoreInfoHandle WinAPITestHelper::DoHook(
301301 HMODULE target_module,
302 const vector<WinAPITestHelper::HookRequest> &requests) {
302 const std::vector<WinAPITestHelper::HookRequest> &requests) {
303303 const HookTargetInfo target_info(requests);
304304
305305 // Following code skips some data validations as this code is only used in
5050 // recovery from such cases are not trivial.
5151 //
5252 // Example:
53 // vector<WinAPITestHelper::HookRequest> requests;
53 // std::vector<WinAPITestHelper::HookRequest> requests;
5454 // requests.push_back(
5555 // DEFINE_HOOK("kernel32.dll", GetVersion, GetVersionHook));
5656 // requests.push_back(
100100 // Since this code is designed to be used in unit test, this method
101101 // causes critical failure and stops execution when something fails.
102102 static RestoreInfoHandle DoHook(HMODULE target_module,
103 const vector<HookRequest> &requests);
103 const std::vector<HookRequest> &requests);
104104
105105 // Restores the API hooks. |backup_info| cannot be used after this method
106106 // is called.
4040 }
4141
4242 TEST(WinAPITestHelperTest, BasicTest) {
43 vector<WinAPITestHelper::HookRequest> requests;
43 std::vector<WinAPITestHelper::HookRequest> requests;
4444 requests.push_back(DEFINE_HOOK("kernel32.dll", GetVersion, GetVersionHook));
4545
4646 auto restore_info = WinAPITestHelper::DoHook(
177177 DISALLOW_COPY_AND_ASSIGN(ScopedLocalFreeInvoker);
178178 };
179179
180 bool GetUserSid(wstring *token_user_sid, wstring *token_primary_group_sid) {
180 bool GetUserSid(std::wstring *token_user_sid,
181 std::wstring *token_primary_group_sid) {
181182 DCHECK(token_user_sid);
182183 DCHECK(token_primary_group_sid);
183184 token_user_sid->clear();
219220 return true;
220221 }
221222
222 wstring Allow(const wstring &access_right, const wstring &account_sid) {
223 return (wstring(L"(") + SDDL_ACCESS_ALLOWED + L";;" +
223 std::wstring Allow(const std::wstring &access_right,
224 const std::wstring &account_sid) {
225 return (std::wstring(L"(") + SDDL_ACCESS_ALLOWED + L";;" +
224226 access_right + L";;;" + account_sid + L")");
225227 }
226228
227 wstring Deny(const wstring &access_right, const wstring &account_sid) {
228 return (wstring(L"(") + SDDL_ACCESS_DENIED + L";;" +
229 std::wstring Deny(const std::wstring &access_right,
230 const std::wstring &account_sid) {
231 return (std::wstring(L"(") + SDDL_ACCESS_DENIED + L";;" +
229232 access_right + L";;;" + account_sid + L")");
230233 }
231234
232 wstring MandatoryLevel(const wstring &mandatory_label,
233 const wstring &integrity_levels) {
234 return (wstring(L"(") + SDDL_MANDATORY_LABEL + L";;" +
235 std::wstring MandatoryLevel(const std::wstring &mandatory_label,
236 const std::wstring &integrity_levels) {
237 return (std::wstring(L"(") + SDDL_MANDATORY_LABEL + L";;" +
235238 mandatory_label + L";;;" + integrity_levels + L")");
236239 }
237240
257260
258261 } // namespace
259262
260 wstring WinSandbox::GetSDDL(ObjectSecurityType shareble_object_type,
261 const wstring &token_user_sid,
262 const wstring &token_primary_group_sid,
263 std::wstring WinSandbox::GetSDDL(ObjectSecurityType shareble_object_type,
264 const std::wstring &token_user_sid,
265 const std::wstring &token_primary_group_sid,
263266 bool is_windows_8_or_later) {
264267 // See http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/e92502b1-0b9f-4e02-9d72-e4e47e924a8f/
265268 // for how to acess named objects from an AppContainer.
266269
267 wstring dacl;
268 wstring sacl;
270 std::wstring dacl;
271 std::wstring sacl;
269272 switch (shareble_object_type) {
270273 case WinSandbox::kSharablePipe:
271274 // Strip implicit owner rights
402405 break;
403406 }
404407
405 wstring sddl;
408 std::wstring sddl;
406409 // Owner SID
407410 sddl += ((SDDL_OWNER SDDL_DELIMINATOR) + token_user_sid);
408411 // Primary Group SID
436439 return reinterpret_cast<SID*>(const_cast<BYTE*>(sid_));
437440 }
438441
439 wstring Sid::GetName() const {
442 std::wstring Sid::GetName() const {
440443 wchar_t *ptr = nullptr;
441444 Sid temp_sid(GetPSID());
442445 ConvertSidToStringSidW(temp_sid.GetPSID(), &ptr);
443 wstring name = ptr;
446 std::wstring name = ptr;
444447 ::LocalFree(ptr);
445448 return name;
446449 }
447450
448 wstring Sid::GetAccountName() const {
451 std::wstring Sid::GetAccountName() const {
449452 wchar_t *ptr = nullptr;
450453 DWORD name_size = 0;
451454 DWORD domain_name_size = 0;
461464 unique_ptr<wchar_t[]> name_buffer(new wchar_t[name_size]);
462465 ::LookupAccountSid(nullptr, temp_sid.GetPSID(), name_buffer.get(),
463466 &name_size, nullptr, &domain_name_size, &name_use);
464 return wstring(L"/") + name_buffer.get();
467 return std::wstring(L"/") + name_buffer.get();
465468 }
466469 unique_ptr<wchar_t[]> name_buffer(new wchar_t[name_size]);
467470 unique_ptr<wchar_t[]> domain_name_buffer(new wchar_t[domain_name_size]);
468471 ::LookupAccountSid(nullptr, temp_sid.GetPSID(), name_buffer.get(), &name_size,
469472 domain_name_buffer.get(), &domain_name_size, &name_use);
470 const wstring domain_name = wstring(domain_name_buffer.get());
471 const wstring user_name = wstring(name_buffer.get());
473 const std::wstring domain_name = std::wstring(domain_name_buffer.get());
474 const std::wstring user_name = std::wstring(name_buffer.get());
472475 return domain_name + L"/" + user_name;
473476 }
474477
476479 bool WinSandbox::MakeSecurityAttributes(
477480 ObjectSecurityType shareble_object_type,
478481 SECURITY_ATTRIBUTES *security_attributes) {
479 wstring token_user_sid;
480 wstring token_primary_group_sid;
482 std::wstring token_user_sid;
483 std::wstring token_primary_group_sid;
481484 if (!GetUserSid(&token_user_sid, &token_primary_group_sid)) {
482485 return false;
483486 }
484487
485 const wstring &sddl = GetSDDL(
488 const std::wstring &sddl = GetSDDL(
486489 shareble_object_type, token_user_sid, token_primary_group_sid,
487490 SystemUtil::IsWindows8OrLater());
488491
810813 const string &arg,
811814 const SecurityInfo &info,
812815 DWORD *pid) {
813 wstring wpath;
816 std::wstring wpath;
814817 Util::UTF8ToWide(path, &wpath);
815818 wpath = L"\"" + wpath + L"\"";
816819 if (!arg.empty()) {
817 wstring warg;
820 std::wstring warg;
818821 Util::UTF8ToWide(arg, &warg);
819822 wpath += L" ";
820823 wpath += warg;
923926 };
924927
925928 // Returns all the 'TokenGroups' information of the specified |token_handle|.
926 vector<SidAndAttributes> GetAllTokenGroups(HANDLE token_handle) {
927 vector<SidAndAttributes> result;
929 std::vector<SidAndAttributes> GetAllTokenGroups(HANDLE token_handle) {
930 std::vector<SidAndAttributes> result;
928931 ScopedTokenInfo<TokenGroups, TOKEN_GROUPS> all_token_groups(token_handle);
929932 if (all_token_groups.get() == nullptr) {
930933 return result;
937940 return result;
938941 }
939942
940 vector<SidAndAttributes> FilterByHavingAttribute(
941 const vector<SidAndAttributes> &source, DWORD attribute) {
942 vector<SidAndAttributes> result;
943 std::vector<SidAndAttributes> FilterByHavingAttribute(
944 const std::vector<SidAndAttributes> &source, DWORD attribute) {
945 std::vector<SidAndAttributes> result;
943946 for (size_t i = 0; i < source.size(); ++i) {
944947 if (source[i].HasAttribute(attribute)) {
945948 result.push_back(source[i]);
948951 return result;
949952 }
950953
951 vector<SidAndAttributes> FilterByNotHavingAttribute(
952 const vector<SidAndAttributes> &source, DWORD attribute) {
953 vector<SidAndAttributes> result;
954 std::vector<SidAndAttributes> FilterByNotHavingAttribute(
955 const std::vector<SidAndAttributes> &source, DWORD attribute) {
956 std::vector<SidAndAttributes> result;
954957 for (size_t i = 0; i < source.size(); ++i) {
955958 if (!source[i].HasAttribute(attribute)) {
956959 result.push_back(source[i]);
960963 }
961964
962965 template <size_t NumExceptions>
963 vector<Sid> FilterSidExceptFor(
964 const vector<SidAndAttributes> &source_sids,
966 std::vector<Sid> FilterSidExceptFor(
967 const std::vector<SidAndAttributes> &source_sids,
965968 const WELL_KNOWN_SID_TYPE (&exception_sids)[NumExceptions]) {
966 vector<Sid> result;
969 std::vector<Sid> result;
967970 // find logon_sid.
968971 for (size_t i = 0; i < source_sids.size(); ++i) {
969972 bool in_the_exception_list = false;
985988 }
986989
987990 template <size_t NumExceptions>
988 vector<LUID> FilterPrivilegesExceptFor(
989 const vector<LUID_AND_ATTRIBUTES> &source_privileges,
991 std::vector<LUID> FilterPrivilegesExceptFor(
992 const std::vector<LUID_AND_ATTRIBUTES> &source_privileges,
990993 const wchar_t *(&exception_privileges)[NumExceptions]) {
991 vector<LUID> result;
994 std::vector<LUID> result;
992995 for (size_t i = 0; i < source_privileges.size(); ++i) {
993996 bool in_the_exception_list = false;
994997 for (size_t j = 0; j < NumExceptions; ++j) {
10191022 return Optional<SidAndAttributes>(SidAndAttributes(sid, attributes));
10201023 }
10211024
1022 vector<LUID_AND_ATTRIBUTES> GetPrivileges(HANDLE token) {
1023 vector<LUID_AND_ATTRIBUTES> result;
1025 std::vector<LUID_AND_ATTRIBUTES> GetPrivileges(HANDLE token) {
1026 std::vector<LUID_AND_ATTRIBUTES> result;
10241027 ScopedTokenInfo<TokenPrivileges, TOKEN_PRIVILEGES> token_privileges(token);
10251028 if (token_privileges.get() == nullptr) {
10261029 return result;
10361039 bool CreateRestrictedTokenImpl(HANDLE effective_token,
10371040 WinSandbox::TokenLevel security_level,
10381041 ScopedHandle *restricted_token) {
1039 const vector<Sid> sids_to_disable =
1042 const std::vector<Sid> sids_to_disable =
10401043 WinSandbox::GetSidsToDisable(effective_token, security_level);
1041 const vector<LUID> privileges_to_disable =
1044 const std::vector<LUID> privileges_to_disable =
10421045 WinSandbox::GetPrivilegesToDisable(effective_token, security_level);
1043 const vector<Sid> sids_to_restrict =
1046 const std::vector<Sid> sids_to_restrict =
10441047 WinSandbox::GetSidsToRestrict(effective_token, security_level);
10451048
10461049 if ((sids_to_disable.size() == 0) &&
10611064 }
10621065
10631066 unique_ptr<SID_AND_ATTRIBUTES[]> sids_to_disable_array;
1064 vector<Sid> sids_to_disable_array_buffer = sids_to_disable;
1067 std::vector<Sid> sids_to_disable_array_buffer = sids_to_disable;
10651068 {
10661069 const size_t size = sids_to_disable.size();
10671070 if (size > 0) {
10871090 }
10881091
10891092 unique_ptr<SID_AND_ATTRIBUTES[]> sids_to_restrict_array;
1090 vector<Sid> sids_to_restrict_array_buffer = sids_to_restrict;
1093 std::vector<Sid> sids_to_restrict_array_buffer = sids_to_restrict;
10911094 {
10921095 const size_t size = sids_to_restrict.size();
10931096 if (size > 0) {
12021205
12031206 } // namespace
12041207
1205 vector<Sid> WinSandbox::GetSidsToDisable(HANDLE effective_token,
1208 std::vector<Sid> WinSandbox::GetSidsToDisable(HANDLE effective_token,
12061209 TokenLevel security_level) {
1207 const vector<SidAndAttributes> all_token_groups =
1210 const std::vector<SidAndAttributes> all_token_groups =
12081211 GetAllTokenGroups(effective_token);
12091212 const Optional<SidAndAttributes> current_user_sid =
12101213 GetUserSid(effective_token);
1211 const vector<SidAndAttributes> normal_tokens =
1214 const std::vector<SidAndAttributes> normal_tokens =
12121215 FilterByNotHavingAttribute(
12131216 FilterByNotHavingAttribute(all_token_groups, SE_GROUP_LOGON_ID),
12141217 SE_GROUP_INTEGRITY);
12151218
1216 vector<Sid> sids_to_disable;
1219 std::vector<Sid> sids_to_disable;
12171220 switch (security_level) {
12181221 case USER_UNPROTECTED:
12191222 case USER_RESTRICTED_SAME_ACCESS:
12551258 return sids_to_disable;
12561259 }
12571260
1258 vector<LUID> WinSandbox::GetPrivilegesToDisable(HANDLE effective_token,
1261 std::vector<LUID> WinSandbox::GetPrivilegesToDisable(HANDLE effective_token,
12591262 TokenLevel security_level ) {
1260 const vector<LUID_AND_ATTRIBUTES> all_privileges =
1263 const std::vector<LUID_AND_ATTRIBUTES> all_privileges =
12611264 GetPrivileges(effective_token);
12621265
1263 vector<LUID> privileges_to_disable;
1266 std::vector<LUID> privileges_to_disable;
12641267 switch (security_level) {
12651268 case USER_UNPROTECTED:
12661269 case USER_RESTRICTED_SAME_ACCESS:
12891292 return privileges_to_disable;
12901293 }
12911294
1292 vector<Sid> WinSandbox::GetSidsToRestrict(HANDLE effective_token,
1295 std::vector<Sid> WinSandbox::GetSidsToRestrict(HANDLE effective_token,
12931296 TokenLevel security_level) {
1294 const vector<SidAndAttributes> all_token_groups =
1297 const std::vector<SidAndAttributes> all_token_groups =
12951298 GetAllTokenGroups(effective_token);
12961299 const Optional<SidAndAttributes> current_user_sid =
12971300 GetUserSid(effective_token);
1298 const vector<SidAndAttributes> token_logon_session =
1301 const std::vector<SidAndAttributes> token_logon_session =
12991302 FilterByHavingAttribute(all_token_groups, SE_GROUP_LOGON_ID);
13001303
1301 vector<Sid> sids_to_restrict;
1304 std::vector<Sid> sids_to_restrict;
13021305 switch (security_level) {
13031306 case USER_UNPROTECTED:
13041307 sids_to_restrict.clear();
13071310 if (current_user_sid.has_value()) {
13081311 sids_to_restrict.push_back(current_user_sid.value().sid());
13091312 }
1310 const vector<SidAndAttributes> tokens =
1313 const std::vector<SidAndAttributes> tokens =
13111314 FilterByNotHavingAttribute(all_token_groups, SE_GROUP_INTEGRITY);
13121315 for (size_t i = 0; i < tokens.size(); ++i) {
13131316 sids_to_restrict.push_back(tokens[i].sid());
14301433 }
14311434
14321435 bool WinSandbox::EnsureAllApplicationPackagesPermisssion(
1433 const wstring &file_name) {
1436 const std::wstring &file_name) {
14341437 // Get "All Application Packages" group SID.
14351438 const ATL::CSid all_application_packages(
14361439 Sid(WinBuiltinAnyPackageSid).GetPSID());
4848 explicit Sid(WELL_KNOWN_SID_TYPE type);
4949 const SID *GetPSID() const;
5050 SID *GetPSID();
51 wstring GetName() const;
52 wstring GetAccountName() const;
51 std::wstring GetName() const;
52 std::wstring GetAccountName() const;
5353
5454 private:
5555 BYTE sid_[SECURITY_MAX_SID_SIZE];
160160 // |security_level|. These methods emulates CreateRestrictedToken
161161 // method in the Chromium sandbox library.
162162 // http://src.chromium.org/viewvc/chrome/trunk/src/sandbox/src/restricted_token_utils.cc?view=markup
163 static vector<Sid> GetSidsToDisable(HANDLE effective_token,
163 static std::vector<Sid> GetSidsToDisable(HANDLE effective_token,
164164 TokenLevel security_level);
165 static vector<LUID> GetPrivilegesToDisable(HANDLE effective_token,
165 static std::vector<LUID> GetPrivilegesToDisable(HANDLE effective_token,
166166 TokenLevel security_level);
167 static vector<Sid> GetSidsToRestrict(HANDLE effective_token,
167 static std::vector<Sid> GetSidsToRestrict(HANDLE effective_token,
168168 TokenLevel security_level);
169169
170170 // Returns true if a restricted token handle is successfully assigned into
191191 // - FILE_EXECUTE
192192 // - READ_CONTROL
193193 // - SYNCHRONIZE
194 static bool EnsureAllApplicationPackagesPermisssion(const wstring &file_name);
194 static bool EnsureAllApplicationPackagesPermisssion(
195 const std::wstring &file_name);
195196
196197 protected:
197198 // Returns SDDL for given |shareble_object_type|.
198199 // This method is placed here for unit testing.
199 static wstring GetSDDL(ObjectSecurityType shareble_object_type,
200 const wstring &token_user_sid,
201 const wstring &token_primary_group_sid,
200 static std::wstring GetSDDL(ObjectSecurityType shareble_object_type,
201 const std::wstring &token_user_sid,
202 const std::wstring &token_primary_group_sid,
202203 bool is_windows_8_or_later);
203204
204205 private:
4444 DISALLOW_IMPLICIT_CONSTRUCTORS(TestableWinSandbox);
4545 };
4646
47 void VerifySidContained(const vector<Sid> sids,
47 void VerifySidContained(const std::vector<Sid> sids,
4848 WELL_KNOWN_SID_TYPE expected_well_known_sid) {
4949 Sid expected_sid(expected_well_known_sid);
5050 for (size_t i = 0; i < sids.size(); ++i) {
6363 &process_token_ret);
6464 ScopedHandle process_token(process_token_ret);
6565
66 const vector<Sid> lockdown = WinSandbox::GetSidsToDisable(
66 const std::vector<Sid> lockdown = WinSandbox::GetSidsToDisable(
6767 process_token.get(), WinSandbox::USER_LOCKDOWN);
68 const vector<Sid> restricted = WinSandbox::GetSidsToDisable(
68 const std::vector<Sid> restricted = WinSandbox::GetSidsToDisable(
6969 process_token.get(), WinSandbox::USER_RESTRICTED);
70 const vector<Sid> limited = WinSandbox::GetSidsToDisable(
70 const std::vector<Sid> limited = WinSandbox::GetSidsToDisable(
7171 process_token.get(), WinSandbox::USER_LIMITED);
72 const vector<Sid> interactive = WinSandbox::GetSidsToDisable(
72 const std::vector<Sid> interactive = WinSandbox::GetSidsToDisable(
7373 process_token.get(), WinSandbox::USER_INTERACTIVE);
74 const vector<Sid> non_admin = WinSandbox::GetSidsToDisable(
74 const std::vector<Sid> non_admin = WinSandbox::GetSidsToDisable(
7575 process_token.get(), WinSandbox::USER_NON_ADMIN);
76 const vector<Sid> restricted_same_access = WinSandbox::GetSidsToDisable(
76 const std::vector<Sid> restricted_same_access = WinSandbox::GetSidsToDisable(
7777 process_token.get(), WinSandbox::USER_RESTRICTED_SAME_ACCESS);
78 const vector<Sid> unprotect = WinSandbox::GetSidsToDisable(
78 const std::vector<Sid> unprotect = WinSandbox::GetSidsToDisable(
7979 process_token.get(), WinSandbox::USER_UNPROTECTED);
8080
8181 EXPECT_TRUE(restricted.size() == lockdown.size());
9696 &process_token_ret);
9797 ScopedHandle process_token(process_token_ret);
9898
99 const vector<LUID> lockdown = WinSandbox::GetPrivilegesToDisable(
99 const std::vector<LUID> lockdown = WinSandbox::GetPrivilegesToDisable(
100100 process_token.get(), WinSandbox::USER_LOCKDOWN);
101 const vector<LUID> restricted = WinSandbox::GetPrivilegesToDisable(
101 const std::vector<LUID> restricted = WinSandbox::GetPrivilegesToDisable(
102102 process_token.get(), WinSandbox::USER_RESTRICTED);
103 const vector<LUID> limited = WinSandbox::GetPrivilegesToDisable(
103 const std::vector<LUID> limited = WinSandbox::GetPrivilegesToDisable(
104104 process_token.get(), WinSandbox::USER_LIMITED);
105 const vector<LUID> interactive = WinSandbox::GetPrivilegesToDisable(
105 const std::vector<LUID> interactive = WinSandbox::GetPrivilegesToDisable(
106106 process_token.get(), WinSandbox::USER_INTERACTIVE);
107 const vector<LUID> non_admin = WinSandbox::GetPrivilegesToDisable(
107 const std::vector<LUID> non_admin = WinSandbox::GetPrivilegesToDisable(
108108 process_token.get(), WinSandbox::USER_NON_ADMIN);
109 const vector<LUID> restricted_same_access =
109 const std::vector<LUID> restricted_same_access =
110110 WinSandbox::GetPrivilegesToDisable(
111111 process_token.get(), WinSandbox::USER_RESTRICTED_SAME_ACCESS);
112 const vector<LUID> unprotect = WinSandbox::GetPrivilegesToDisable(
112 const std::vector<LUID> unprotect = WinSandbox::GetPrivilegesToDisable(
113113 process_token.get(), WinSandbox::USER_UNPROTECTED);
114114
115115 EXPECT_EQ(0, restricted_same_access.size());
122122 &process_token_ret);
123123 ScopedHandle process_token(process_token_ret);
124124
125 const vector<Sid> lockdown = WinSandbox::GetSidsToRestrict(
125 const std::vector<Sid> lockdown = WinSandbox::GetSidsToRestrict(
126126 process_token.get(), WinSandbox::USER_LOCKDOWN);
127 const vector<Sid> restricted = WinSandbox::GetSidsToRestrict(
127 const std::vector<Sid> restricted = WinSandbox::GetSidsToRestrict(
128128 process_token.get(), WinSandbox::USER_RESTRICTED);
129 const vector<Sid> limited = WinSandbox::GetSidsToRestrict(
129 const std::vector<Sid> limited = WinSandbox::GetSidsToRestrict(
130130 process_token.get(), WinSandbox::USER_LIMITED);
131 const vector<Sid> interactive = WinSandbox::GetSidsToRestrict(
131 const std::vector<Sid> interactive = WinSandbox::GetSidsToRestrict(
132132 process_token.get(), WinSandbox::USER_INTERACTIVE);
133 const vector<Sid> non_admin = WinSandbox::GetSidsToRestrict(
133 const std::vector<Sid> non_admin = WinSandbox::GetSidsToRestrict(
134134 process_token.get(), WinSandbox::USER_NON_ADMIN);
135 const vector<Sid> restricted_same_access = WinSandbox::GetSidsToRestrict(
135 const std::vector<Sid> restricted_same_access = WinSandbox::GetSidsToRestrict(
136136 process_token.get(), WinSandbox::USER_RESTRICTED_SAME_ACCESS);
137 const vector<Sid> unprotect = WinSandbox::GetSidsToRestrict(
137 const std::vector<Sid> unprotect = WinSandbox::GetSidsToRestrict(
138138 process_token.get(), WinSandbox::USER_UNPROTECTED);
139139
140140 EXPECT_EQ(1, lockdown.size());
148148 const wchar_t kDummyUserSID[] = L"S-8";
149149 const wchar_t kDummyGroupSID[] = L"S-9";
150150
151 wstring GetSDDLForVista(WinSandbox::ObjectSecurityType type) {
151 std::wstring GetSDDLForVista(WinSandbox::ObjectSecurityType type) {
152152 return TestableWinSandbox::GetSDDL(
153153 type, kDummyUserSID, kDummyGroupSID, false);
154154 }
155155
156 wstring GetSDDLForWin8(WinSandbox::ObjectSecurityType type) {
156 std::wstring GetSDDLForWin8(WinSandbox::ObjectSecurityType type) {
157157 return TestableWinSandbox::GetSDDL(
158158 type, kDummyUserSID, kDummyGroupSID, true);
159159 }
8585
8686 } // namespace
8787
88 HMODULE WinUtil::LoadSystemLibrary(const wstring &base_filename) {
89 wstring fullpath = SystemUtil::GetSystemDir();
88 HMODULE WinUtil::LoadSystemLibrary(const std::wstring &base_filename) {
89 std::wstring fullpath = SystemUtil::GetSystemDir();
9090 fullpath += L"\\";
9191 fullpath += base_filename;
9292
102102 return module;
103103 }
104104
105 HMODULE WinUtil::LoadMozcLibrary(const wstring &base_filename) {
106 wstring fullpath;
105 HMODULE WinUtil::LoadMozcLibrary(const std::wstring &base_filename) {
106 std::wstring fullpath;
107107 Util::UTF8ToWide(SystemUtil::GetServerDirectory(), &fullpath);
108108 fullpath += L"\\";
109109 fullpath += base_filename;
120120 return module;
121121 }
122122
123 HMODULE WinUtil::GetSystemModuleHandle(const wstring &base_filename) {
124 wstring fullpath = SystemUtil::GetSystemDir();
123 HMODULE WinUtil::GetSystemModuleHandle(const std::wstring &base_filename) {
124 std::wstring fullpath = SystemUtil::GetSystemDir();
125125 fullpath += L"\\";
126126 fullpath += base_filename;
127127
137137 }
138138
139139 HMODULE WinUtil::GetSystemModuleHandleAndIncrementRefCount(
140 const wstring &base_filename) {
141 wstring fullpath = SystemUtil::GetSystemDir();
140 const std::wstring &base_filename) {
141 std::wstring fullpath = SystemUtil::GetSystemDir();
142142 fullpath += L"\\";
143143 fullpath += base_filename;
144144
181181 }
182182
183183 bool WinUtil::SystemEqualString(
184 const wstring &lhs, const wstring &rhs, bool ignore_case) {
184 const std::wstring &lhs, const std::wstring &rhs, bool ignore_case) {
185185 // We assume a string instance never contains NUL character in principle.
186186 // So we will raise an error to notify the unexpected situation in debug
187187 // builds. In production, however, we will admit such an instance and
188188 // silently trim it at the first NUL character.
189 const wstring::size_type lhs_null_pos = lhs.find_first_of(L'\0');
190 const wstring::size_type rhs_null_pos = rhs.find_first_of(L'\0');
189 const std::wstring::size_type lhs_null_pos = lhs.find_first_of(L'\0');
190 const std::wstring::size_type rhs_null_pos = rhs.find_first_of(L'\0');
191191 DCHECK_EQ(lhs.npos, lhs_null_pos)
192192 << "|lhs| should not contain NUL character.";
193193 DCHECK_EQ(rhs.npos, rhs_null_pos)
194194 << "|rhs| should not contain NUL character.";
195 const wstring &lhs_null_trimmed = lhs.substr(0, lhs_null_pos);
196 const wstring &rhs_null_trimmed = rhs.substr(0, rhs_null_pos);
195 const std::wstring &lhs_null_trimmed = lhs.substr(0, lhs_null_pos);
196 const std::wstring &rhs_null_trimmed = rhs.substr(0, rhs_null_pos);
197197
198198 const int compare_result = ::CompareStringOrdinal(
199199 lhs_null_trimmed.data(), lhs_null_trimmed.size(),
417417 }
418418
419419 bool WinUtil::GetFileSystemInfoFromPath(
420 const wstring &path, BY_HANDLE_FILE_INFORMATION *info) {
420 const std::wstring &path, BY_HANDLE_FILE_INFORMATION *info) {
421421 // no read access is required.
422422 ScopedHandle handle(::CreateFileW(
423423 path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
432432 return !!::GetFileInformationByHandle(handle.get(), info);
433433 }
434434
435 bool WinUtil::AreEqualFileSystemObject(const wstring &left_path,
436 const wstring &right_path) {
435 bool WinUtil::AreEqualFileSystemObject(const std::wstring &left_path,
436 const std::wstring &right_path) {
437437 BY_HANDLE_FILE_INFORMATION left_info = {};
438438 if (!GetFileSystemInfoFromPath(left_path, &left_info)) {
439439 return false;
446446 (left_info.nFileIndexHigh == right_info.nFileIndexHigh);
447447 }
448448
449 bool WinUtil::GetNtPath(const wstring &dos_path, wstring *nt_path) {
449 bool WinUtil::GetNtPath(const std::wstring &dos_path, std::wstring *nt_path) {
450450 if (nt_path == nullptr) {
451451 return false;
452452 }
483483 return true;
484484 }
485485
486 bool WinUtil::GetProcessInitialNtPath(DWORD pid, wstring *nt_path) {
486 bool WinUtil::GetProcessInitialNtPath(DWORD pid, std::wstring *nt_path) {
487487 if (nt_path == nullptr) {
488488 return false;
489489 }
4646 // If the function succeeds, the return value is a handle to the module.
4747 // You should call FreeLibrary with the handle.
4848 // If the function fails, the return value is NULL.
49 static HMODULE LoadSystemLibrary(const wstring &base_filename);
49 static HMODULE LoadSystemLibrary(const std::wstring &base_filename);
5050
5151 // Load a DLL which has the specified base-name and is located in the
5252 // Mozc server directory.
5353 // If the function succeeds, the return value is a handle to the module.
5454 // You should call FreeLibrary with the handle.
5555 // If the function fails, the return value is NULL.
56 static HMODULE LoadMozcLibrary(const wstring &base_filename);
56 static HMODULE LoadMozcLibrary(const std::wstring &base_filename);
5757
5858 // If a DLL which has the specified base-name and located in the system
5959 // directory is loaded in the caller process, retrieve its module handle.
6161 // without incrementing its reference count so that you should not call
6262 // FreeLibrary with the handle.
6363 // If the function fails, the return value is NULL.
64 static HMODULE GetSystemModuleHandle(const wstring &base_filename);
64 static HMODULE GetSystemModuleHandle(const std::wstring &base_filename);
6565
6666 // A variant ot GetSystemModuleHandle except that this method increments
6767 // reference count of the target DLL.
6868 static HMODULE GetSystemModuleHandleAndIncrementRefCount(
69 const wstring &base_filename);
69 const std::wstring &base_filename);
7070
7171 // Retrieve whether the calling thread hold loader lock or not.
7272 // Return true if the state is retrieved successfully.
8686 // Although this function ignores the rest part of given string when NUL
8787 // character is found, you should not pass such a string in principle.
8888 static bool SystemEqualString(
89 const wstring &lhs, const wstring &rhs, bool ignore_case);
89 const std::wstring &lhs, const std::wstring &rhs, bool ignore_case);
9090
9191 // Returns true if succeeds to determine whether the current process has
9292 // a process token which seems to be one for service process. Otherwise,
123123
124124 // Returns true if |info| is filled with a valid file information that
125125 // describes |path|. |path| can be a directory or a file.
126 static bool GetFileSystemInfoFromPath(const wstring &path,
126 static bool GetFileSystemInfoFromPath(const std::wstring &path,
127127 BY_HANDLE_FILE_INFORMATION *info);
128128
129129 // Returns true if |left_path| and |right_path| are the same file system
130130 // object. This method takes hard-link into consideration.
131131 // Returns false if either |left_path| or |right_path| does not exist even
132132 // when |left_path| == |right_path|.
133 static bool AreEqualFileSystemObject(const wstring &left_path,
134 const wstring &right_path);
133 static bool AreEqualFileSystemObject(const std::wstring &left_path,
134 const std::wstring &right_path);
135135
136136 // Returns true if the file or directory specified by |dos_path| exists and
137137 // its NT path is retrieved as |nt_path|. This function can work only on
138138 // Vista and later.
139 static bool GetNtPath(const wstring &dos_path, wstring *nt_path);
139 static bool GetNtPath(const std::wstring &dos_path, std::wstring *nt_path);
140140
141141 // Returns true if the process specified by |pid| exists and its *initial*
142142 // NT path is retrieved as |nt_path|. Note that even when the process path is
143143 // renamed after the process is launched, the *initial* path is retrieved.
144144 // This is important when MSI changes paths of executables.
145 static bool GetProcessInitialNtPath(DWORD pid, wstring *nt_path);
145 static bool GetProcessInitialNtPath(DWORD pid, std::wstring *nt_path);
146146
147147 // Returns true if input settings is shared among applications on Windows 8.
148148 // Returns false otherwise.
3737
3838 namespace {
3939
40 bool LooksLikeNtPath(const wstring &nt_path) {
40 bool LooksLikeNtPath(const std::wstring &nt_path) {
4141 const wchar_t kPrefix[] = L"\\Device\\";
4242
43 return nt_path.find(kPrefix) != wstring::npos;
43 return nt_path.find(kPrefix) != std::wstring::npos;
4444 }
4545
4646 } // namespace
156156 TEST(WinUtilTest, SystemEqualStringTestForNUL) {
157157 {
158158 const wchar_t kTestBuffer[] = L"abc";
159 const wstring test_string1(kTestBuffer);
160 const wstring test_string2(kTestBuffer,
159 const std::wstring test_string1(kTestBuffer);
160 const std::wstring test_string2(kTestBuffer,
161161 kTestBuffer + arraysize(kTestBuffer));
162162
163163 EXPECT_EQ(3, test_string1.size());
169169 }
170170 {
171171 const wchar_t kTestBuffer[] = L"abc\0def";
172 const wstring test_string1(kTestBuffer);
173 const wstring test_string2(kTestBuffer,
172 const std::wstring test_string1(kTestBuffer);
173 const std::wstring test_string2(kTestBuffer,
174174 kTestBuffer + arraysize(kTestBuffer));
175175
176176 EXPECT_EQ(3, test_string1.size());
184184 #endif // DEBUG
185185
186186 TEST(WinUtilTest, AreEqualFileSystemObjectTest) {
187 const wstring system_dir = SystemUtil::GetSystemDir();
188 const wstring notepad = system_dir + L"\\notepad.exe";
189 const wstring notepad_with_prefix = L"\\\\?\\" + notepad;
187 const std::wstring system_dir = SystemUtil::GetSystemDir();
188 const std::wstring notepad = system_dir + L"\\notepad.exe";
189 const std::wstring notepad_with_prefix = L"\\\\?\\" + notepad;
190190 const wchar_t kThisFileNeverExists[] = L"/this/file/never/exists";
191191
192192 EXPECT_TRUE(WinUtil::AreEqualFileSystemObject(system_dir, system_dir))
203203 }
204204
205205 TEST(WinUtilTest, GetNtPath) {
206 const wstring system_dir = SystemUtil::GetSystemDir();
207 const wstring notepad = system_dir + L"\\notepad.exe";
206 const std::wstring system_dir = SystemUtil::GetSystemDir();
207 const std::wstring notepad = system_dir + L"\\notepad.exe";
208208 const wchar_t kThisFileNeverExists[] = L"/this/file/never/exists";
209209
210 wstring nt_system_dir;
210 std::wstring nt_system_dir;
211211 EXPECT_TRUE(WinUtil::GetNtPath(system_dir, &nt_system_dir))
212212 << "Can work against a directory.";
213213 EXPECT_TRUE(LooksLikeNtPath(nt_system_dir));
215215 EXPECT_FALSE(WinUtil::GetNtPath(system_dir, nullptr))
216216 << "Must fail against a NULL argument.";
217217
218 wstring nt_notepad;
218 std::wstring nt_notepad;
219219 EXPECT_TRUE(WinUtil::GetNtPath(notepad, &nt_notepad))
220220 << "Can work against a file.";
221221 EXPECT_TRUE(LooksLikeNtPath(nt_notepad));
222222
223223 EXPECT_TRUE(nt_system_dir != nt_notepad);
224224
225 wstring nt_not_exists = L"foo";
225 std::wstring nt_not_exists = L"foo";
226226 EXPECT_FALSE(WinUtil::GetNtPath(kThisFileNeverExists, &nt_not_exists))
227227 << "Must fail against non-exist file.";
228228 EXPECT_TRUE(nt_not_exists.empty())
230230 }
231231
232232 TEST(WinUtilTest, GetProcessInitialNtPath) {
233 wstring nt_path;
233 std::wstring nt_path;
234234 EXPECT_TRUE(WinUtil::GetProcessInitialNtPath(::GetCurrentProcessId(),
235235 &nt_path));
236236 EXPECT_TRUE(LooksLikeNtPath(nt_path));
403403 void GetPosList(Json::Value *response) {
404404 (*response)["event"]["posList"] = Json::Value(Json::arrayValue);
405405 Json::Value *pos_list = &(*response)["event"]["posList"];
406 vector<string> tmp_pos_vec;
406 std::vector<string> tmp_pos_vec;
407407 user_pos_->GetPOSList(&tmp_pos_vec);
408408 for (int i = 0; i < tmp_pos_vec.size(); ++i) {
409409 (*pos_list)[i] = Json::Value(Json::objectValue);
864864 if (mode == "administration_dialog") {
865865 #ifdef OS_WIN
866866 const string &path = mozc::SystemUtil::GetToolPath();
867 wstring wpath;
867 std::wstring wpath;
868868 Util::UTF8ToWide(path, &wpath);
869869 wpath = L"\"" + wpath + L"\"";
870870 // Run administration dialog with UAC.
283283
284284 #ifdef OS_WIN
285285 // Reset the file attributes since it may contain FILE_ATTRIBUTE_READONLY.
286 wstring wdest_path;
286 std::wstring wdest_path;
287287 Util::UTF8ToWide(dest_path, &wdest_path);
288288 ::SetFileAttributesW(wdest_path.c_str(), FILE_ATTRIBUTE_NORMAL);
289289 #endif // OS_WIN
7474 HKEY dummy = NULL;
7575 HKEY &result = (result_key != NULL ? *result_key : dummy);
7676 if (HKEY_CURRENT_USER == key) {
77 if (wstring(kOmahaUsageKey) == sub_key) {
77 if (std::wstring(kOmahaUsageKey) == sub_key) {
7878 result = kHKCU_ClientState;
7979 return true;
8080 }
8181 } else if (HKEY_LOCAL_MACHINE == key) {
82 if (wstring(kOmahaUsageKey) == sub_key) {
82 if (std::wstring(kOmahaUsageKey) == sub_key) {
8383 result = kHKLM_ClientState;
8484 return true;
85 } else if (wstring(kOmahaUsageKeyForEveryone) == sub_key) {
85 } else if (std::wstring(kOmahaUsageKeyForEveryone) == sub_key) {
8686 result = kHKLM_ClientStateMedium;
8787 return true;
8888 }
137137 };
138138 typedef PropertySelector<Id> Property;
139139 RegistryEmulator() {
140 vector<WinAPITestHelper::HookRequest> requests;
140 std::vector<WinAPITestHelper::HookRequest> requests;
141141 requests.push_back(
142142 DEFINE_HOOK("advapi32.dll", RegCreateKeyExW, TestRegCreateKeyExW));
143143 requests.push_back(
228228 static LSTATUS WINAPI TestRegSetValueExW(
229229 HKEY key, LPCWSTR value_name, DWORD reserved, DWORD type,
230230 const BYTE *data, DWORD num_data) {
231 if (type != REG_DWORD || wstring(kSendStatsName) != value_name) {
231 if (type != REG_DWORD || std::wstring(kSendStatsName) != value_name) {
232232 // Do nothing for other cases.
233233 return ERROR_SUCCESS;
234234 }
251251 static LSTATUS WINAPI TestRegQueryValueExW(
252252 HKEY key, LPCWSTR value_name, LPDWORD reserved, LPDWORD type,
253253 LPBYTE data, LPDWORD num_data) {
254 if (wstring(kSendStatsName) != value_name) {
254 if (std::wstring(kSendStatsName) != value_name) {
255255 return ERROR_SUCCESS;
256256 }
257257 if (!HasUsagestatsValue(key)) {
262262 return ERROR_SUCCESS;
263263 }
264264 static LSTATUS WINAPI TestRegDeleteValueW(HKEY key, LPCWSTR value_name) {
265 if (wstring(kSendStatsName) != value_name) {
265 if (std::wstring(kSendStatsName) != value_name) {
266266 return ERROR_SUCCESS;
267267 }
268268 if (!HasUsagestatsValue(key)) {
2929
3030 MAJOR=2
3131 MINOR=23
32 BUILD=2792
32 BUILD=2793
3333 REVISION=102
3434 # This version represents the version of Mozc IME engine (converter, predictor,
3535 # etc.). This version info is included both in the Mozc server and in the Mozc
6363 return false;
6464 }
6565
66 unique_ptr<wchar_t[]> wide(new wchar_t[wide_length + 1]);
66 std::unique_ptr<wchar_t[]> wide(new wchar_t[wide_length + 1]);
6767 if (MultiByteToWideChar(CP_932, MB_ERR_INVALID_CHARS, input.data(),
6868 input.size(), wide.get(),
6969 wide_length + 1) != wide_length) {
241241 }
242242
243243 private:
244 vector<IMEWRD> buf_;
244 std::vector<IMEWRD> buf_;
245245 ScopedIFEDictionary dic_;
246246 map<int, string> pos_map_;
247247 HRESULT result_;
4747 #include "gui/base/win_util.h"
4848 #include "ipc/window_info.pb.h"
4949
50 #ifdef OS_WIN
51 using std::unique_ptr;
52 #endif // OS_WIN
53
5450 namespace mozc {
5551 namespace gui {
5652 namespace {
5753 bool ReadWindowInfo(const string &lock_name,
5854 ipc::WindowInfo *window_info) {
5955 #ifdef OS_WIN
60 wstring wfilename;
56 std::wstring wfilename;
6157 mozc::Util::UTF8ToWide(lock_name, &wfilename);
6258 {
6359 mozc::ScopedHandle handle(
8278 return false;
8379 }
8480
85 unique_ptr<char[]> buf(new char[size]);
81 std::unique_ptr<char[]> buf(new char[size]);
8682
8783 DWORD read_size = 0;
8884 if (!::ReadFile(handle.get(), buf.get(),
6868 }
6969
7070 {
71 wstring mozc_tool_path_wide;
71 std::wstring mozc_tool_path_wide;
7272 Util::UTF8ToWide(SystemUtil::GetToolPath(), &mozc_tool_path_wide);
7373 hr = link->SetPath(mozc_tool_path_wide.c_str());
7474 if (FAILED(hr)) {
7878 }
7979
8080 {
81 wstring argument_wide;
81 std::wstring argument_wide;
8282 Util::UTF8ToWide(argument, &argument_wide);
8383 hr = link->SetArguments(argument_wide.c_str());
8484 if (FAILED(hr)) {
9494 }
9595
9696 {
97 wstring item_title_wide;
97 std::wstring item_title_wide;
9898 Util::UTF8ToWide(item_title, &item_title_wide);
9999 PROPVARIANT prop_variant;
100100 hr = ::InitPropVariantFromString(item_title_wide.c_str(), &prop_variant);
252252 LOG(ERROR) << "Could not find the exsisting window.";
253253 }
254254 const CWindow window(info.found_window_handle);
255 wstring window_title_wide;
255 std::wstring window_title_wide;
256256 {
257257 CString buf;
258258 window.GetWindowTextW(buf);
310310 // can return |true|
311311 if (ERROR_SUCCESS == result &&
312312 num_chars < arraysize(data) &&
313 wstring(data) == kIMEHotKeyEntryData) {
313 std::wstring(data) == kIMEHotKeyEntryData) {
314314 return true;
315315 }
316316
4343 WindowsSelectionHandler::~WindowsSelectionHandler() {}
4444
4545 void WindowsSelectionHandler::Select(const QString &str) {
46 vector<INPUT> inputs;
46 std::vector<INPUT> inputs;
4747 for (int i = 0; i < str.size(); ++i) {
4848 INPUT input = { 0 };
4949 KEYBDINPUT kb = { 0 };
6363 using mozc::user_dictionary::UserDictionaryCommandStatus;
6464 using mozc::user_dictionary::UserDictionarySession;
6565 using mozc::user_dictionary::UserDictionaryStorage;
66 #ifdef OS_WIN
67 using std::unique_ptr;
68 #endif // OS_WIN
6966
7067 namespace {
7168 const int kSessionTimeout = 100000;
7471
7572 QString GetEnv(const char *envname) {
7673 #if defined(OS_WIN)
77 wstring wenvname;
74 std::wstring wenvname;
7875 mozc::Util::UTF8ToWide(envname, &wenvname);
7976 const DWORD buffer_size =
8077 ::GetEnvironmentVariable(wenvname.c_str(), NULL, 0);
8178 if (buffer_size == 0) {
8279 return "";
8380 }
84 unique_ptr<wchar_t[]> buffer(new wchar_t[buffer_size]);
81 std::unique_ptr<wchar_t[]> buffer(new wchar_t[buffer_size]);
8582 const DWORD num_copied =
8683 ::GetEnvironmentVariable(wenvname.c_str(), buffer.get(), buffer_size);
8784 if (num_copied > 0) {
103103 server_thread_main.SetJoinable(true);
104104 server_thread_main.Start("IpcMain");
105105
106 vector<mozc::MultiConnections> cons(FLAGS_num_threads);
106 std::vector<mozc::MultiConnections> cons(FLAGS_num_threads);
107107 for (size_t i = 0; i < cons.size(); ++i) {
108108 cons[i].SetJoinable(true);
109109 cons[i].Start("MultiConnections");
7070 #include "ipc/ipc.h"
7171 #include "ipc/ipc.pb.h"
7272
73 #ifdef OS_WIN
74 using std::unique_ptr;
75 #endif // OS_WIn
76
7773 namespace mozc {
7874 namespace {
7975
333329
334330 #ifdef OS_WIN
335331 {
336 wstring expected_server_ntpath;
337 const map<string, wstring>::const_iterator it =
332 std::wstring expected_server_ntpath;
333 const std::map<string, std::wstring>::const_iterator it =
338334 expected_server_ntpath_cache_.find(server_path);
339335 if (it != expected_server_ntpath_cache_.end()) {
340336 expected_server_ntpath = it->second;
341337 } else {
342 wstring wide_server_path;
338 std::wstring wide_server_path;
343339 Util::UTF8ToWide(server_path, &wide_server_path);
344340 if (WinUtil::GetNtPath(wide_server_path, &expected_server_ntpath)) {
345341 // Caches the relationship from |server_path| to
353349 return false;
354350 }
355351
356 wstring actual_server_ntpath;
352 std::wstring actual_server_ntpath;
357353 if (!WinUtil::GetProcessInitialNtPath(pid, &actual_server_ntpath)) {
358354 return false;
359355 }
464460 // Special code for Windows,
465461 // we want to pass FILE_SHRED_DELETE flag for CreateFile.
466462 #ifdef OS_WIN
467 wstring wfilename;
463 std::wstring wfilename;
468464 Util::UTF8ToWide(filename, &wfilename);
469465
470466 {
493489 return false;
494490 }
495491
496 unique_ptr<char[]> buf(new char[size]);
492 std::unique_ptr<char[]> buf(new char[size]);
497493
498494 DWORD read_size = 0;
499495 if (!::ReadFile(handle.get(), buf.get(),
133133 uint32 server_pid_; // cache for pid of server_path
134134 time_t last_modified_;
135135 #ifdef OS_WIN
136 map<string, wstring> expected_server_ntpath_cache_;
136 std::map<string, std::wstring> expected_server_ntpath_cache_;
137137 #endif // OS_WIN
138138 };
139139
101101 #ifdef OS_WIN
102102 NamedEventListener::NamedEventListener(const char *name)
103103 : is_owner_(false), handle_(NULL) {
104 wstring event_path;
104 std::wstring event_path;
105105 Util::UTF8ToWide(NamedEventUtil::GetEventPath(name), &event_path);
106106
107107 handle_ = ::OpenEventW(EVENT_ALL_ACCESS, false,
219219
220220 NamedEventNotifier::NamedEventNotifier(const char *name)
221221 : handle_(NULL) {
222 wstring event_path;
222 std::wstring event_path;
223223 Util::UTF8ToWide(NamedEventUtil::GetEventPath(name), &event_path);
224224 handle_ = ::OpenEventW(EVENT_MODIFY_STATE, false,
225225 event_path.c_str());
5454 mozc::TestProcessWatchDog dog;
5555
5656 string line;
57 vector<string> fields;
57 std::vector<string> fields;
5858
5959 while (getline(cin, line)) {
6060 fields.clear();
6060 size_t GetNumberOfProcessors() {
6161 // thread-safety is not required.
6262 static size_t num = CPUStats().GetNumberOfProcessors();
63 return max(num, static_cast<size_t>(1));
63 return std::max(num, static_cast<size_t>(1));
6464 }
6565
6666 // Least significant bit of OVERLAPPED::hEvent can be used for special
106106 mutex_name += ".";
107107 mutex_name += ipc_channel_name;
108108 mutex_name += ".ipc";
109 wstring wmutex_name;
109 std::wstring wmutex_name;
110110 Util::UTF8ToWide(mutex_name, &wmutex_name);
111111
112112 LPSECURITY_ATTRIBUTES security_attributes_ptr = nullptr;
483483 }
484484
485485 // Create a named pipe.
486 wstring wserver_address;
486 std::wstring wserver_address;
487487 Util::UTF8ToWide(server_address, &wserver_address);
488488 HANDLE handle = ::CreateNamedPipe(wserver_address.c_str(),
489489 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
715715 if (!manager->LoadPathName() || !manager->GetPathName(&server_address)) {
716716 continue;
717717 }
718 wstring wserver_address;
718 std::wstring wserver_address;
719719 Util::UTF8ToWide(server_address, &wserver_address);
720720
721721 if (GetNumberOfProcessors() == 1) {
234234 uc.dwUrlPathLength = sizeof(UrlPath);
235235 uc.dwExtraInfoLength = sizeof(ExtraInfo);
236236
237 wstring wurl;
237 std::wstring wurl;
238238 Util::UTF8ToWide(url, &wurl);
239239
240240 if (!::InternetCrackUrlW(wurl.c_str(), 0, 0, &uc)) {
264264 return false;
265265 }
266266
267 wstring uri = UrlPath;
267 std::wstring uri = UrlPath;
268268 if (uc.dwExtraInfoLength != 0) {
269269 uri += uc.lpszExtraInfo;
270270 }
295295
296296 for (size_t i = 0; i < option.headers.size(); ++i) {
297297 const string header = option.headers[i] + "\r\n";
298 wstring wheader;
298 std::wstring wheader;
299299 Util::UTF8ToWide(header, &wheader);
300300 if (!::HttpAddRequestHeadersW(handle.get(), wheader.c_str(), -1,
301301 HTTP_ADDREQ_FLAG_ADD |
172172 // than 10. Thus, this linear order algorithm is fast enough.
173173 // Theoretically, we can construct a trie of strings in |subsequent_chars_|
174174 // to get more performance but it's overkill here.
175 // TODO(noriyukit): vector<string> would be better than set<string>. To
176 // this end, we need to fix Comopser as well.
175 // TODO(noriyukit): std::vector<string> would be better than set<string>.
176 // To this end, we need to fix Comopser as well.
177177 const StringPiece rest = ClippedSubstr(key, original_key_len_);
178178 for (const string &chr : *subsequent_chars_) {
179179 if (Util::StartsWith(rest, chr)) {
158158
159159 // Retrieves the display string from the specified candidate for the specified
160160 // column and returns it.
161 wstring GetDisplayStringByColumn(
161 std::wstring GetDisplayStringByColumn(
162162 const commands::Candidates::Candidate &candidate,
163163 COLUMN_TYPE column_type) {
164 wstring display_string;
164 std::wstring display_string;
165165
166166 switch (column_type) {
167167 case COLUMN_SHORTCUT:
179179 if (candidate.has_annotation()) {
180180 const commands::Annotation &annotation = candidate.annotation();
181181 if (annotation.has_prefix()) {
182 wstring annotation_prefix;
182 std::wstring annotation_prefix;
183183 mozc::Util::UTF8ToWide(annotation.prefix(), &annotation_prefix);
184184 display_string = annotation_prefix + display_string;
185185 }
186186 if (annotation.has_suffix()) {
187 wstring annotation_suffix;
187 std::wstring annotation_suffix;
188188 mozc::Util::UTF8ToWide(annotation.suffix(), &annotation_suffix);
189189 display_string += annotation_suffix;
190190 }
475475
476476 // Calculate the size to display a label string.
477477 if (candidates_->footer().has_label()) {
478 wstring footer_label;
478 std::wstring footer_label;
479479 mozc::Util::UTF8ToWide(candidates_->footer().label(),
480480 &footer_label);
481481 const Size label_string_size = text_renderer_->MeasureString(
482482 TextRenderer::FONTSET_FOOTER_LABEL,
483483 L" " + footer_label + L" ");
484484 footer_size.width += label_string_size.width;
485 footer_size.height = max(footer_size.height, label_string_size.height);
485 footer_size.height = std::max(footer_size.height,
486 label_string_size.height);
486487 } else if (candidates_->footer().has_sub_label()) {
487488 // Currently the sub label will not be shown unless (main) label is
488489 // absent.
489490 // TODO(yukawa): Refactor the layout system for the footer.
490 wstring footer_sub_label;
491 std::wstring footer_sub_label;
491492 mozc::Util::UTF8ToWide(candidates_->footer().sub_label(),
492493 &footer_sub_label);
493494 const Size label_string_size = text_renderer_->MeasureString(
494495 TextRenderer::FONTSET_FOOTER_SUBLABEL,
495496 L" " + footer_sub_label + L" ");
496497 footer_size.width += label_string_size.width;
497 footer_size.height = max(footer_size.height, label_string_size.height);
498 footer_size.height = std::max(footer_size.height,
499 label_string_size.height);
498500 }
499501
500502 // Calculate the size to display a index string.
501503 if (candidates_->footer().index_visible()) {
502 wstring index_guide_string;
504 std::wstring index_guide_string;
503505 mozc::Util::UTF8ToWide(GetIndexGuideString(*candidates_),
504506 &index_guide_string);
505507 const Size index_guide_size = text_renderer_->MeasureString(
506508 TextRenderer::FONTSET_FOOTER_INDEX, index_guide_string);
507509 footer_size.width += index_guide_size.width;
508 footer_size.height = max(footer_size.height, index_guide_size.height);
510 footer_size.height = std::max(footer_size.height,
511 index_guide_size.height);
509512 }
510513
511514 // Calculate the size to display a Footer logo.
512515 if (!footer_logo_.IsNull()) {
513516 if (candidates_->footer().logo_visible()) {
514517 footer_size.width += footer_logo_display_size_.width;
515 footer_size.height = max(footer_size.height,
516 footer_logo_display_size_.height);
518 footer_size.height = std::max(footer_size.height,
519 footer_logo_display_size_.height);
517520 } else if (footer_size.height > 0) {
518521 // Ensure the footer height is greater than the Footer logo height
519522 // even if the Footer logo is absent. This hack prevents the footer
520523 // from changing its height too frequently.
521 footer_size.height = max(footer_size.height,
522 footer_logo_display_size_.height);
524 footer_size.height = std::max(footer_size.height,
525 footer_logo_display_size_.height);
523526 }
524527 }
525528
527530 // one page.
528531 if (candidates_->candidate_size() < candidates_->size()) {
529532 // We use FONTSET_CANDIDATE for calculating the minimum width.
530 wstring minimum_width_as_wstring;
533 std::wstring minimum_width_as_wstring;
531534 mozc::Util::UTF8ToWide(
532535 kMinimumCandidateAndDescriptionWidthAsString,
533536 &minimum_width_as_wstring);
557560 for (size_t i = 0; i < candidates_->candidate_size(); ++i) {
558561 const commands::Candidates::Candidate &candidate =
559562 candidates_->candidate(i);
560 const wstring shortcut =
563 const std::wstring shortcut =
561564 GetDisplayStringByColumn(candidate, COLUMN_SHORTCUT);
562 const wstring description =
565 const std::wstring description =
563566 GetDisplayStringByColumn(candidate, COLUMN_DESCRIPTION);
564 const wstring candidate_string =
567 const std::wstring candidate_string =
565568 GetDisplayStringByColumn(candidate, COLUMN_CANDIDATE);
566569
567570 if (!shortcut.empty()) {
568 wstring text;
571 std::wstring text;
569572 text.push_back(L' '); // put a space for padding
570573 text.append(shortcut);
571574 text.push_back(L' '); // put a space for padding
575578 }
576579
577580 if (!candidate_string.empty()) {
578 wstring text;
581 std::wstring text;
579582 text.append(candidate_string);
580583
581584 const Size rendering_size = text_renderer_->MeasureString(
584587 }
585588
586589 if (!description.empty()) {
587 wstring text;
590 std::wstring text;
588591 text.append(description);
589592 text.push_back(L' '); // put a space for padding
590593 const Size rendering_size = text_renderer_->MeasureString(
658661 const COLUMN_TYPE column_type = kColumnTypes[type_index];
659662 const TextRenderer::FONT_TYPE font_type = kFontTypes[type_index];
660663
661 vector<TextRenderingInfo> display_list;
664 std::vector<TextRenderingInfo> display_list;
662665 for (size_t i = 0; i < candidates_->candidate_size(); ++i) {
663666 const commands::Candidates::Candidate &candidate =
664667 candidates_->candidate(i);
665 const wstring display_string =
668 const std::wstring display_string =
666669 GetDisplayStringByColumn(candidate, column_type);
667670 const Rect text_rect =
668671 table_layout_->GetCellRect(i, column_type);
787790
788791 int right_used = 0;
789792 if (candidates_->footer().index_visible()) {
790 wstring index_guide_string;
793 std::wstring index_guide_string;
791794 mozc::Util::UTF8ToWide(GetIndexGuideString(*candidates_),
792795 &index_guide_string);
793796 const Size index_guide_size = text_renderer_->MeasureString(
806809 footer_content_rect.Top(),
807810 footer_content_rect.Width() - left_used - right_used,
808811 footer_content_rect.Height());
809 wstring footer_label;
812 std::wstring footer_label;
810813 mozc::Util::UTF8ToWide(candidates_->footer().label(), &footer_label);
811814 text_renderer_->RenderText(dc,
812815 L" " + footer_label + L" ",
813816 label_rect,
814817 TextRenderer::FONTSET_FOOTER_LABEL);
815818 } else if (candidates_->footer().has_sub_label()) {
816 wstring footer_sub_label;
819 std::wstring footer_sub_label;
817820 mozc::Util::UTF8ToWide(candidates_->footer().sub_label(),
818821 &footer_sub_label);
819822 const Rect label_rect(left_used,
820823 footer_content_rect.Top(),
821824 footer_content_rect.Width() - left_used - right_used,
822825 footer_content_rect.Height());
823 const wstring text = L" " + footer_sub_label + L" ";
826 const std::wstring text = L" " + footer_sub_label + L" ";
824827 text_renderer_->RenderText(dc,
825828 text,
826829 label_rect,
196196 Destroy();
197197 }
198198
199 virtual void UpdateLayout(const vector<CompositionWindowLayout> &layouts) {
199 virtual void UpdateLayout(
200 const std::vector<CompositionWindowLayout> &layouts) {
200201 // Create windows if needed.
201202 if (line_windows_.size() < layouts.size()) {
202203 const size_t num_windows = layouts.size() - line_windows_.size();
253254 }
254255
255256 private:
256 vector<CompositionLineWindow *> line_windows_;
257 std::vector<CompositionLineWindow *> line_windows_;
257258 DISALLOW_COPY_AND_ASSIGN(CompositionWindowListImpl);
258259 };
259260 } // namespace
5151 virtual void Destroy() = 0;
5252 virtual void Hide() = 0;
5353 virtual void UpdateLayout(
54 const vector<CompositionWindowLayout> &layouts) = 0;
54 const std::vector<CompositionWindowLayout> &layouts) = 0;
5555
5656 static CompositionWindowList *CreateInstance();
5757
5959 const uint32 kMaxBitmapHeight = 16384;
6060
6161 bool ConvertMain() {
62 wstring wide_src;
62 std::wstring wide_src;
6363 mozc::Util::UTF8ToWide(FLAGS_src, &wide_src);
6464 std::unique_ptr<Gdiplus::Bitmap> image(
6565 Gdiplus::Bitmap::FromFile(wide_src.c_str()));
230230 SetTimer(kTimerEventFading, kFadingOutInterval);
231231 break;
232232 case kTimerEventFading:
233 alpha_ = max(static_cast<int>(alpha_) - kFadingOutAlphaDelta, 0);
233 alpha_ = std::max(static_cast<int>(alpha_) - kFadingOutAlphaDelta, 0);
234234 if (alpha_ == 0) {
235235 KillTimer(kTimerEventFading);
236236 }
320320 CPoint top_left_;
321321 BYTE alpha_;
322322 double dpi_scaling_;
323 vector<Sprite> sprites_;
323 std::vector<Sprite> sprites_;
324324
325325 DISALLOW_COPY_AND_ASSIGN(WindowImpl);
326326 };
170170 infostyle.caption_background_color().g(),
171171 infostyle.caption_background_color().b()));
172172
173 wstring caption_str;
173 std::wstring caption_str;
174174 const Rect caption_rect(
175175 infostyle.window_border() + infostyle.caption_padding()
176176 + caption_style.left_padding(),
221221 infostyle.row_rect_padding() * 2;
222222 const Information &info = usages.information(row);
223223
224 wstring title_str;
224 std::wstring title_str;
225225 mozc::Util::UTF8ToWide(info.title(), &title_str);
226226 const Size title_size = text_renderer_->MeasureStringMultiLine(
227227 TextRenderer::FONTSET_INFOLIST_TITLE, title_str, title_width);
228228
229 wstring desc_str;
229 std::wstring desc_str;
230230 mozc::Util::UTF8ToWide(info.description(), &desc_str);
231231 const Size desc_size = text_renderer_->MeasureStringMultiLine(
232232 TextRenderer::FONTSET_INFOLIST_DESCRIPTION, desc_str, desc_width);
221221 }
222222 }
223223
224 virtual Size MeasureString(FONT_TYPE font_type, const wstring &str) const {
224 virtual Size MeasureString(FONT_TYPE font_type,
225 const std::wstring &str) const {
225226 const auto previous_font = mem_dc_.SelectFont(render_info_[font_type].font);
226227 CRect rect;
227228 mem_dc_.DrawTextW(str.c_str(), str.length(), &rect,
231232 }
232233
233234 virtual Size MeasureStringMultiLine(
234 FONT_TYPE font_type, const wstring &str, const int width) const {
235 FONT_TYPE font_type, const std::wstring &str, const int width) const {
235236 const auto previous_font = mem_dc_.SelectFont(render_info_[font_type].font);
236237 CRect rect(0, 0, width, 0);
237238 mem_dc_.DrawTextW(str.c_str(), str.length(), &rect,
241242 }
242243
243244 virtual void RenderText(CDCHandle dc,
244 const wstring &text,
245 const std::wstring &text,
245246 const Rect &rect,
246247 FONT_TYPE font_type) const {
247 vector<TextRenderingInfo> infolist;
248 std::vector<TextRenderingInfo> infolist;
248249 infolist.push_back(TextRenderingInfo(text, rect));
249250 RenderTextList(dc, infolist, font_type);
250251 }
251252
252 virtual void RenderTextList(CDCHandle dc,
253 const vector<TextRenderingInfo> &display_list,
254 FONT_TYPE font_type) const {
253 virtual void RenderTextList(
254 CDCHandle dc,
255 const std::vector<TextRenderingInfo> &display_list,
256 FONT_TYPE font_type) const {
255257 const auto &render_info = render_info_[font_type];
256258 const auto old_font = dc.SelectFont(render_info.font);
257259 const auto previous_color = dc.SetTextColor(render_info.color);
272274 DWORD style;
273275 CFont font;
274276 };
275 unique_ptr<RenderInfo[]> render_info_;
277 std::unique_ptr<RenderInfo[]> render_info_;
276278 mutable CDC mem_dc_;
277279
278280 DISALLOW_COPY_AND_ASSIGN(GdiTextRenderer);
349351 }
350352
351353 // Retrieves the bounding box for a given string.
352 virtual Size MeasureString(FONT_TYPE font_type, const wstring &str) const {
354 virtual Size MeasureString(FONT_TYPE font_type,
355 const std::wstring &str) const {
353356 return MeasureStringImpl(font_type, str, 0, false);
354357 }
355358
356 virtual Size MeasureStringMultiLine(FONT_TYPE font_type, const wstring &str,
359 virtual Size MeasureStringMultiLine(FONT_TYPE font_type,
360 const std::wstring &str,
357361 const int width) const {
358362 return MeasureStringImpl(font_type, str, width, true);
359363 }
360364
361 virtual void RenderText(CDCHandle dc, const wstring &text,
365 virtual void RenderText(CDCHandle dc, const std::wstring &text,
362366 const Rect &rect, FONT_TYPE font_type) const {
363 vector<TextRenderingInfo> infolist;
367 std::vector<TextRenderingInfo> infolist;
364368 infolist.push_back(TextRenderingInfo(text, rect));
365369 RenderTextList(dc, infolist, font_type);
366370 }
367371
368 virtual void RenderTextList(CDCHandle dc,
369 const vector<TextRenderingInfo> &display_list,
370 FONT_TYPE font_type) const {
372 virtual void RenderTextList(
373 CDCHandle dc,
374 const std::vector<TextRenderingInfo> &display_list,
375 FONT_TYPE font_type) const {
371376 const size_t kMaxTrial = 3;
372377 size_t trial = 0;
373378 while (true) {
390395 }
391396
392397 HRESULT RenderTextListImpl(CDCHandle dc,
393 const vector<TextRenderingInfo> &display_list,
398 const std::vector<TextRenderingInfo> &display_list,
394399 FONT_TYPE font_type) const {
395400 CRect total_rect;
396401 for (const auto &item : display_list) {
397402 const auto &item_rect = ToCRect(item.rect);
398 total_rect.right = max(total_rect.right, item_rect.right);
399 total_rect.bottom = max(total_rect.bottom, item_rect.bottom);
403 total_rect.right = std::max(total_rect.right, item_rect.right);
404 total_rect.bottom = std::max(total_rect.bottom, item_rect.bottom);
400405 }
401406 HRESULT hr = S_OK;
402407 hr = dc_render_target_->BindDC(dc, &total_rect);
434439 return dc_render_target_->EndDraw();
435440 }
436441
437 Size MeasureStringImpl(FONT_TYPE font_type, const wstring &str,
442 Size MeasureStringImpl(FONT_TYPE font_type, const std::wstring &str,
438443 const int width, bool use_width) const {
439444 HRESULT hr = S_OK;
440445 const FLOAT kLayoutLimit = 100000.0f;
489494 return nullptr;
490495 }
491496 length += 1; // for NUL.
492 unique_ptr<wchar_t[]> family_name(new wchar_t[length]);
497 std::unique_ptr<wchar_t[]> family_name(new wchar_t[length]);
493498 hr = localized_family_names->GetString(0, family_name.get(), length);
494499 if (FAILED(hr)) {
495500 return nullptr;
549554 CComPtr<IDWriteFactory> dwrite_factory_;
550555 mutable CComPtr<ID2D1DCRenderTarget> dc_render_target_;
551556 CComPtr<IDWriteGdiInterop> dwrite_interop_;
552 vector<RenderInfo> render_info_;
557 std::vector<RenderInfo> render_info_;
553558
554559 DISALLOW_COPY_AND_ASSIGN(DirectWriteTextRenderer);
555560 };
4848
4949 // text-rect pair for batch text rendering.
5050 struct TextRenderingInfo {
51 wstring text;
51 std::wstring text;
5252 Rect rect;
53 TextRenderingInfo(const wstring &str, const Rect &r) :
53 TextRenderingInfo(const std::wstring &str, const Rect &r) :
5454 text(str), rect(r) {
5555 }
5656 };
8282 virtual void OnThemeChanged() = 0;
8383
8484 // Retrieves the bounding box for a given string.
85 virtual Size MeasureString(FONT_TYPE font_type, const wstring &str) const = 0;
85 virtual Size MeasureString(FONT_TYPE font_type,
86 const std::wstring &str) const = 0;
8687 virtual Size MeasureStringMultiLine(FONT_TYPE font_type,
87 const wstring &str,
88 const std::wstring &str,
8889 const int width) const = 0;
8990 // Renders the given |text|.
9091 virtual void RenderText(WTL::CDCHandle dc,
91 const wstring &text,
92 const std::wstring &text,
9293 const Rect &rect,
9394 FONT_TYPE font_type) const = 0;
94 virtual void RenderTextList(WTL::CDCHandle dc,
95 const vector<TextRenderingInfo> &display_list,
96 FONT_TYPE font_type) const = 0;
95 virtual void RenderTextList(
96 WTL::CDCHandle dc,
97 const std::vector<TextRenderingInfo> &display_list,
98 FONT_TYPE font_type) const = 0;
9799 };
98100
99101 } // namespace win32
102102 log_font->lfQuality = win_log_font.quality();
103103 log_font->lfPitchAndFamily = win_log_font.pitch_and_family();
104104
105 wstring face_name;
105 std::wstring face_name;
106106 mozc::Util::UTF8ToWide(win_log_font.face_name(), &face_name);
107107
108108 // Although the result of mozc::Util::UTF8ToWide never contains any null
8282 win_log_font.set_pitch_and_family(FF_SCRIPT);
8383
8484 LOGFONT log_font = { };
85 wstring too_long_face_name(L' ', arraysize(log_font.lfFaceName));
85 std::wstring too_long_face_name(L' ', arraysize(log_font.lfFaceName));
8686 string face_name;
8787 mozc::Util::WideToUTF8(too_long_face_name, &face_name);
8888 win_log_font.set_face_name(face_name);
224224 // Returns PixelType as a quick determination. If kUnknown is returned, you
225225 // need to investigate the pixel type more precisely.
226226 PixelType GetPixelTypeInternalFast(int x, int y) const {
227 const double frame = max(corner_radius_, frame_thickness_);
227 const double frame = std::max(corner_radius_, frame_thickness_);
228228 if ((left_ + frame) < x &&
229229 (x + 1) < (left_ + width_ - frame) &&
230230 (top_ + frame) < y &&
374374
375375 // Core logic to render 1-bit text glyphs for sub-pixel rendering. Caller takes
376376 // the ownerships of the returned pointers.
377 vector<TextLabel::BinarySubdivisionalPixel *> Get1bitGlyph(
377 std::vector<TextLabel::BinarySubdivisionalPixel *> Get1bitGlyph(
378378 double left,
379379 double top,
380380 double width,
388388 const int pix_width = bounding_rect.Width();
389389 const int pix_height = bounding_rect.Height();
390390
391 vector<TextLabel::BinarySubdivisionalPixel *> pixels;
391 std::vector<TextLabel::BinarySubdivisionalPixel *> pixels;
392392 pixels.resize(pix_width * pix_height, nullptr);
393393 if (text.empty()) {
394394 return pixels;
426426 dc.CreateCompatibleDC(nullptr);
427427 CBitmapHandle old_bitmap = dc.SelectBitmap(dib);
428428
429 wstring wide_fontname;
429 std::wstring wide_fontname;
430430 Util::UTF8ToWide(fontname, &wide_fontname);
431431 CLogFont logfont;
432432 logfont.lfWeight = FW_NORMAL;
451451 CRect rect(lefttop, size);
452452 dc.SetBkMode(TRANSPARENT);
453453 dc.SetTextColor(RGB(255, 255, 255));
454 wstring wide_text;
454 std::wstring wide_text;
455455 Util::UTF8ToWide(text, &wide_text);
456456 dc.DrawTextW(wide_text.c_str(), wide_text.size(), &rect,
457457 DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CENTER);
573573 HBITMAP BalloonImage::CreateInternal(const BalloonImageInfo &info,
574574 POINT *tail_offset,
575575 SIZE *size,
576 vector<ARGBColor> *arbg_buffer) {
576 std::vector<ARGBColor> *arbg_buffer) {
577577 // Base point. You can set arbitrary position.
578578 const double kLeft = 10.0;
579579 const double kTop = 10.0;
580580
581581 const Balloon balloon(
582 kLeft, kTop, max(info.rect_width, 0.0), max(info.rect_height, 0.0),
583 max(info.frame_thickness, 0.0), max(info.corner_radius, 0.0),
584 max(info.tail_height, 0.0), max(info.tail_width, 0.0),
582 kLeft, kTop,
583 std::max(info.rect_width, 0.0), std::max(info.rect_height, 0.0),
584 std::max(info.frame_thickness, 0.0), std::max(info.corner_radius, 0.0),
585 std::max(info.tail_height, 0.0), std::max(info.tail_width, 0.0),
585586 info.frame_color, info.inside_color, info.tail_direction);
586587
587588 const TextLabel label(kLeft + info.frame_thickness,
616617 GaussianBlur blur(info.blur_sigma);
617618
618619 const int begin_x =
619 rect.Left() - max(blur.cutoff_length() - info.blur_offset_x, 0);
620 rect.Left() - std::max(blur.cutoff_length() - info.blur_offset_x, 0);
620621 const int begin_y =
621 rect.Top() - max(blur.cutoff_length() - info.blur_offset_y, 0);
622 rect.Top() - std::max(blur.cutoff_length() - info.blur_offset_y, 0);
622623 const int end_x =
623 rect.Right() + max(blur.cutoff_length() + info.blur_offset_x, 0);
624 rect.Right() + std::max(blur.cutoff_length() + info.blur_offset_x, 0);
624625 const int end_y =
625 rect.Bottom() + max(blur.cutoff_length() + info.blur_offset_y, 0);
626 rect.Bottom() + std::max(blur.cutoff_length() + info.blur_offset_y, 0);
626627
627628 const int bmp_width = end_x - begin_x;
628629 const int bmp_height = end_y - begin_y;
680681 const int offset_y_;
681682 };
682683
683 const double normalized_blur_alpha = min(max(info.blur_alpha, 0.0), 1.0);
684 const double normalized_blur_alpha =
685 std::min(std::max(info.blur_alpha, 0.0), 1.0);
684686 Accessor accessor(frame_buffer, -info.blur_offset_x, -info.blur_offset_y);
685687 for (int y = begin_y; y < begin_y + bmp_height; ++y) {
686688 for (int x = begin_x; x < begin_x + bmp_width; ++x) {
156156 const BalloonImageInfo &info,
157157 POINT *tail_offset,
158158 SIZE *size,
159 vector<ARGBColor> *arbg_buffer);
159 std::vector<ARGBColor> *arbg_buffer);
160160
161161 private:
162162 DISALLOW_IMPLICIT_CONSTRUCTORS(BalloonImage);
245245 static size_t GetIndex(const Fraction2D &offset);
246246
247247 // A bit vector that indicates each sub-pixel is filled or not.
248 bitset<kTotalPixels> filled_;
248 std::bitset<kTotalPixels> filled_;
249249 std::unique_ptr<ColorType[]> colors_;
250250 ColorType single_color_;
251251
284284 MatrixElement();
285285 MatrixElement(int x, int y, double c);
286286 };
287 typedef vector<MatrixElement> Matrix;
287 typedef std::vector<MatrixElement> Matrix;
288288
289289 size_t GetMatrixLength() const;
290290
324324 // output the result to SubdivisionalPixel storage.
325325 class TextLabel {
326326 public:
327 typedef bitset<SubdivisionalPixel::kDivision * SubdivisionalPixel::kDivision>
327 typedef
328 std::bitset<SubdivisionalPixel::kDivision * SubdivisionalPixel::kDivision>
328329 BinarySubdivisionalPixel;
329330
330331 TextLabel(double left,
345346 const Rect &bounding_rect() const;
346347
347348 private:
348 const vector<BinarySubdivisionalPixel *> pixels_;
349 const std::vector<BinarySubdivisionalPixel *> pixels_;
349350 const Rect bounding_rect_;
350351 const RGBColor text_color_;
351352
106106
107107 static void BalloonImageTest::SaveTestImage(
108108 const TestableBalloonImage::BalloonImageInfo &info,
109 const wstring filename) {
109 const std::wstring filename) {
110110 CPoint tail_offset;
111111 CSize size;
112 vector<ARGBColor> buffer;
112 std::vector<ARGBColor> buffer;
113113 CBitmap dib = TestableBalloonImage::CreateInternal(
114114 info, &tail_offset, &size, &buffer);
115115
190190 }
191191
192192 private:
193 static bool GetEncoderClsid(const wstring format, CLSID *clsid) {
193 static bool GetEncoderClsid(const std::wstring format, CLSID *clsid) {
194194 UINT num_codecs = 0;
195195 UINT codecs_buffer_size = 0;
196196 Gdiplus::GetImageEncodersSize(&num_codecs, &codecs_buffer_size);
198198 return false;
199199 }
200200
201 unique_ptr<uint8[]> codesc_buffer(new uint8[codecs_buffer_size]);
201 std::unique_ptr<uint8[]> codesc_buffer(new uint8[codecs_buffer_size]);
202202 Gdiplus::ImageCodecInfo *codecs =
203203 reinterpret_cast<Gdiplus::ImageCodecInfo *>(codesc_buffer.get());
204204
304304
305305 CPoint actual_tail_offset;
306306 CSize actual_size;
307 vector<ARGBColor> actual_buffer;
307 std::vector<ARGBColor> actual_buffer;
308308 CBitmap dib = TestableBalloonImage::CreateInternal(
309309 info, &actual_tail_offset, &actual_size, &actual_buffer);
310310
311311 EXPECT_EQ(tail["output"]["tail_offset_x"].asInt(), actual_tail_offset.x);
312312 EXPECT_EQ(tail["output"]["tail_offset_y"].asInt(), actual_tail_offset.y);
313313
314 wstring wide_path;
314 std::wstring wide_path;
315315 Util::UTF8ToWide(expected_image_path, &wide_path);
316316
317317 Gdiplus::Bitmap bitmap(wide_path.c_str());
431431 return true;
432432 }
433433
434 wstring ComposePreeditText(const commands::Preedit &preedit,
434 std::wstring ComposePreeditText(const commands::Preedit &preedit,
435435 string *preedit_utf8,
436 vector<int> *segment_indices,
437 vector<CharacterRange> *segment_ranges) {
436 std::vector<int> *segment_indices,
437 std::vector<CharacterRange> *segment_ranges) {
438438 if (preedit_utf8 != NULL) {
439439 preedit_utf8->clear();
440440 }
444444 if (segment_ranges != NULL) {
445445 segment_ranges->clear();
446446 }
447 wstring value;
447 std::wstring value;
448448 int total_characters = 0;
449449 for (size_t segment_index = 0; segment_index < preedit.segment_size();
450450 ++segment_index) {
451451 const commands::Preedit::Segment &segment = preedit.segment(segment_index);
452 wstring segment_value;
452 std::wstring segment_value;
453453 mozc::Util::UTF8ToWide(segment.value(), &segment_value);
454454 value.append(segment_value);
455455 if (preedit_utf8 != NULL) {
474474
475475 bool CalcLayoutWithTextWrappingInternal(
476476 CDCHandle dc,
477 const wstring &str,
477 const std::wstring &str,
478478 const int maximum_line_length,
479479 const int initial_offset,
480 vector<LineLayout> *line_layouts) {
480 std::vector<LineLayout> *line_layouts) {
481481 DCHECK(line_layouts != NULL);
482482 if (initial_offset < 0 || maximum_line_length <= 0 ||
483483 maximum_line_length < initial_offset) {
557557 } else {
558558 CSize line_size;
559559 int allowable_chars_for_confirmation = 0;
560 unique_ptr<int[]> size_buffer(new int[allowable_chars]);
560 std::unique_ptr<int[]> size_buffer(new int[allowable_chars]);
561561 result = dc.GetTextExtentExPoint(
562562 layout.text.c_str(),
563563 layout.text.size(),
741741 }
742742
743743 // This method is not const to implement Win32WindowInterface.
744 virtual bool GetWindowClassName(HWND window_handle, wstring *class_name) {
744 virtual bool GetWindowClassName(HWND window_handle,
745 std::wstring *class_name) {
745746 if (class_name == NULL) {
746747 return false;
747748 }
783784 };
784785
785786 struct WindowInfo {
786 wstring class_name;
787 std::wstring class_name;
787788 CRect window_rect;
788789 CPoint client_area_offset;
789790 CSize client_area_size;
884885
885886 // This method wraps API call of GetAncestor/GA_ROOT.
886887 virtual HWND GetRootWindow(HWND window_handle) {
887 const map<HWND, HWND>::const_iterator it = root_map_.find(window_handle);
888 const std::map<HWND, HWND>::const_iterator it =
889 root_map_.find(window_handle);
888890 if (it == root_map_.end()) {
889891 return window_handle;
890892 }
892894 }
893895
894896 // This method is not const to implement Win32WindowInterface.
895 virtual bool GetWindowClassName(HWND window_handle, wstring *class_name) {
897 virtual bool GetWindowClassName(HWND window_handle,
898 std::wstring *class_name) {
896899 if (class_name == NULL) {
897900 return false;
898901 }
934937 }
935938
936939 virtual HWND RegisterWindow(
937 const wstring &class_name, const RECT &window_rect,
940 const std::wstring &class_name, const RECT &window_rect,
938941 const POINT &client_area_offset, const SIZE &client_area_size,
939942 double scale_factor) {
940943 const HWND hwnd = GetNextWindowHandle();
968971 return &(window_map_.find(hwnd)->second);
969972 }
970973
971 map<HWND, WindowInfo> window_map_;
972 map<HWND, HWND> root_map_;
974 std::map<HWND, WindowInfo> window_map_;
975 std::map<HWND, HWND> root_map_;
973976
974977 DISALLOW_COPY_AND_ASSIGN(WindowPositionEmulatorImpl);
975978 };
16651668
16661669 bool LayoutManager::CalcLayoutWithTextWrapping(
16671670 const LOGFONTW &font,
1668 const wstring &text,
1671 const std::wstring &text,
16691672 int maximum_line_length,
16701673 int initial_offset,
1671 vector<LineLayout> *line_layouts) {
1674 std::vector<LineLayout> *line_layouts) {
16721675 if (line_layouts == NULL) {
16731676 return false;
16741677 }
17611764 // more easily.
17621765 bool LayoutManager::LayoutCompositionWindow(
17631766 const commands::RendererCommand &command,
1764 vector<CompositionWindowLayout> *composition_window_layouts,
1767 std::vector<CompositionWindowLayout> *composition_window_layouts,
17651768 CandidateWindowLayout *candidate_layout) const {
17661769 if (composition_window_layouts != NULL) {
17671770 composition_window_layouts->clear();
19291932 }
19301933
19311934 string preedit_utf8;
1932 vector<int> segment_indices;
1933 vector<CharacterRange> segment_lengths;
1934 const wstring composition_text = ComposePreeditText(
1935 std::vector<int> segment_indices;
1936 std::vector<CharacterRange> segment_lengths;
1937 const std::wstring composition_text = ComposePreeditText(
19351938 preedit, &preedit_utf8, &segment_indices, &segment_lengths);
19361939 DCHECK_EQ(composition_text.size(), segment_indices.size());
19371940 DCHECK_EQ(preedit.segment_size(), segment_lengths.size());
1938 vector<mozc::renderer::win32::LineLayout> layouts;
1941 std::vector<mozc::renderer::win32::LineLayout> layouts;
19391942 bool result = false;
19401943 {
19411944 const int offset = is_vertical
21332136 continue;
21342137 }
21352138 const int segment_begin =
2136 max(segment_lengths[segment_index].begin, total_characters) -
2139 std::max(segment_lengths[segment_index].begin, total_characters) -
21372140 total_characters;
21382141 const int segment_end =
2139 min(segment_lengths[segment_index].begin +
2142 std::min(segment_lengths[segment_index].begin +
21402143 segment_lengths[segment_index].length,
21412144 next_total_characters) - total_characters;
21422145 if (segment_begin >= segment_end) {
22002203 // Initialize the |exclusion_area| with invalid data. These values will
22012204 // be updated to be valid at the first turn of the next for-loop.
22022205 // For example, |exclusion_area.left| will be updated as follows.
2203 // exclusion_area.left = min(exclusion_area.left,
2204 // numeric_limits<int>::max());
2205 CRect exclusion_area(numeric_limits<int>::max(),
2206 numeric_limits<int>::max(),
2207 numeric_limits<int>::min(),
2208 numeric_limits<int>::min());
2206 // exclusion_area.left = std::min(exclusion_area.left,
2207 // std::numeric_limits<int>::max());
2208 CRect exclusion_area(std::numeric_limits<int>::max(),
2209 std::numeric_limits<int>::max(),
2210 std::numeric_limits<int>::min(),
2211 std::numeric_limits<int>::min());
22092212
22102213 for (size_t i = 0; i < composition_window_layouts->size(); ++i) {
22112214 const CompositionWindowLayout &layout = composition_window_layouts->at(i);
22132216 text_area_in_screen_coord.OffsetRect(
22142217 layout.window_position_in_screen_coordinate.left,
22152218 layout.window_position_in_screen_coordinate.top);
2216 exclusion_area.left = min(exclusion_area.left,
2217 text_area_in_screen_coord.left);
2218 exclusion_area.top = min(exclusion_area.top,
2219 text_area_in_screen_coord.top);
2220 exclusion_area.right = max(exclusion_area.right,
2221 text_area_in_screen_coord.right);
2222 exclusion_area.bottom = max(exclusion_area.bottom,
2223 text_area_in_screen_coord.bottom);
2219 exclusion_area.left = std::min(exclusion_area.left,
2220 text_area_in_screen_coord.left);
2221 exclusion_area.top = std::min(exclusion_area.top,
2222 text_area_in_screen_coord.top);
2223 exclusion_area.right = std::max(exclusion_area.right,
2224 text_area_in_screen_coord.right);
2225 exclusion_area.bottom = std::max(exclusion_area.bottom,
2226 text_area_in_screen_coord.bottom);
22242227 }
22252228
22262229 CPoint cursor_pos;
25372540 return COMPATIBILITY_MODE_NONE;
25382541 }
25392542
2540 wstring class_name;
2543 std::wstring class_name;
25412544 if (!window_position_->GetWindowClassName(target_window, &class_name)) {
25422545 return COMPATIBILITY_MODE_NONE;
25432546 }
6262 };
6363
6464 struct LineLayout {
65 wstring text;
65 std::wstring text;
6666 int line_length;
6767 int line_width;
6868 int line_start_offset;
69 vector<CharacterRange> character_positions;
69 std::vector<CharacterRange> character_positions;
7070 LineLayout();
7171 };
7272
8383 RECT caret_rect;
8484 POINT base_position;
8585 LOGFONT log_font;
86 wstring text;
87 vector<SegmentMarkerLayout> marker_layouts;
86 std::wstring text;
87 std::vector<SegmentMarkerLayout> marker_layouts;
8888 CompositionWindowLayout();
8989 };
9090
215215 virtual HWND GetRootWindow(HWND window_handle) = 0;
216216
217217 // This method wraps API call of GetClassName.
218 virtual bool GetWindowClassName(HWND window_handle, wstring *class_name) = 0;
218 virtual bool GetWindowClassName(HWND window_handle,
219 std::wstring *class_name) = 0;
219220 };
220221
221222 // This class implements WindowPositionInterface and emulates APIs
229230 // WindowPositionInterface with this dummy handle. You need not to release
230231 // the returned handle.
231232 virtual HWND RegisterWindow(
232 const wstring &class_name, const RECT &window_rect,
233 const std::wstring &class_name, const RECT &window_rect,
233234 const POINT &client_area_offset, const SIZE &client_area_size,
234235 double scale_factor) = 0;
235236
292293 // displayed.
293294 bool LayoutCompositionWindow(
294295 const commands::RendererCommand &command,
295 vector<CompositionWindowLayout> *composition_window_layouts,
296 std::vector<CompositionWindowLayout> *composition_window_layouts,
296297 CandidateWindowLayout* candidate_layout) const;
297298
298299 // Returns compatibility bits for given target application.
418419 // LineLayout: Layout information for each split line.
419420 static bool CalcLayoutWithTextWrapping(
420421 const LOGFONTW &font,
421 const wstring &text,
422 const std::wstring &text,
422423 int maximum_line_length,
423424 int initial_offset,
424 vector<LineLayout> *line_layouts);
425 std::vector<LineLayout> *line_layouts);
425426
426427 std::unique_ptr<SystemPreferenceInterface> system_preference_;
427428 std::unique_ptr<WindowPositionInterface> window_position_;
143143 } while (false)
144144
145145 WindowPositionEmulator *CreateWindowEmulator(
146 const wstring &class_name, const RECT &window_rect,
146 const std::wstring &class_name, const RECT &window_rect,
147147 const POINT &client_area_offset, const SIZE &client_area_size,
148148 double scale_factor, HWND *hwnd) {
149149 WindowPositionEmulator *emulator = WindowPositionEmulator::Create();
164164 }
165165
166166 WindowPositionEmulator *CreateWindowEmulatorWithClassName(
167 const wstring &class_name, HWND *hwnd) {
167 const std::wstring &class_name, HWND *hwnd) {
168168 const CPoint kClientOffset(8, 42);
169169 const CSize kClientSize(2000, 1000);
170170 const CRect kWindowRect(500, 500, 2516, 1550);
284284 }
285285
286286 static CLogFont GetFont(bool is_proportional, bool is_vertical) {
287 wstring font_face;
287 std::wstring font_face;
288288 Util::UTF8ToWide((is_proportional ? GetPropotionalFontFaceForTest()
289289 : GetMonospacedFontFaceForTest()),
290290 &font_face);
320320 return SystemPreferenceFactory::CreateMock(font);
321321 }
322322
323 static wstring GetTestMessageWithCompositeGlyph(int num_repeat) {
324 wstring message;
323 static std::wstring GetTestMessageWithCompositeGlyph(int num_repeat) {
324 std::wstring message;
325325 for (size_t i = 0; i < num_repeat; ++i) {
326326 // "ぱ"
327327 message += L'\u3071';
330330 return message;
331331 }
332332
333 static wstring GetTestMessageForMonospaced() {
334 wstring w_path;
333 static std::wstring GetTestMessageForMonospaced() {
334 std::wstring w_path;
335335 const char kMessage[] = "熊本県阿蘇郡南阿蘇村大字中松南阿蘇水の生まれる里白水高原駅";
336 wstring w_message;
336 std::wstring w_message;
337337 Util::UTF8ToWide(kMessage, &w_message);
338338 return w_message;
339339 }
340340
341 static wstring GetTestMessageForProportional() {
342 wstring w_path;
341 static std::wstring GetTestMessageForProportional() {
342 std::wstring w_path;
343343 const char kMessage[] =
344344 "This open-source project originates from Google 日本語入力.";
345 wstring w_message;
345 std::wstring w_message;
346346 Util::UTF8ToWide(kMessage, &w_message);
347347 return w_message;
348348 }
10221022 EXPECT_TRUE(emulator->ClientToScreen(hwnd, &point));
10231023 EXPECT_EQ(kWindowRect.TopLeft() + kClientOffset, point);
10241024
1025 wstring class_name;
1025 std::wstring class_name;
10261026 EXPECT_TRUE(emulator->GetWindowClassName(hwnd, &class_name));
10271027 EXPECT_EQ(kWindowClassName, class_name);
10281028 }
10531053 EXPECT_TRUE(emulator->ClientToScreen(hwnd, &point));
10541054 EXPECT_EQ(kWindowRect.TopLeft() + kClientOffset, point);
10551055
1056 wstring class_name;
1056 std::wstring class_name;
10571057 EXPECT_TRUE(emulator->GetWindowClassName(hwnd, &class_name));
10581058 EXPECT_EQ(kWindowClassName, class_name);
10591059 }
10621062 TEST_F(Win32RendererUtilTest, HorizontalProportional) {
10631063 const CLogFont &logfont = GetFont(true, false);
10641064
1065 vector<mozc::renderer::win32::LineLayout> line_layouts;
1065 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
10661066 bool result = true;
10671067
1068 const wstring &message = GetTestMessageForProportional();
1068 const std::wstring &message = GetTestMessageForProportional();
10691069
10701070 // Check if the |initial_offset| works as expected.
10711071 result = LayoutManager::CalcLayoutWithTextWrapping(
11201120 TEST_F(Win32RendererUtilTest, VerticalProportional) {
11211121 const CLogFont &logfont = GetFont(true, true);
11221122
1123 vector<mozc::renderer::win32::LineLayout> line_layouts;
1123 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
11241124 bool result = true;
11251125
1126 const wstring &message = GetTestMessageForProportional();
1126 const std::wstring &message = GetTestMessageForProportional();
11271127
11281128 // Check if the |initial_offset| works as expected.
11291129 result = LayoutManager::CalcLayoutWithTextWrapping(
11781178 TEST_F(Win32RendererUtilTest, HorizontalMonospaced) {
11791179 const CLogFont &logfont = GetFont(false, false);
11801180
1181 vector<mozc::renderer::win32::LineLayout> line_layouts;
1181 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
11821182 bool result = true;
11831183
1184 const wstring &message = GetTestMessageForMonospaced();
1184 const std::wstring &message = GetTestMessageForMonospaced();
11851185
11861186 // Check if the |initial_offset| works as expected.
11871187 result = LayoutManager::CalcLayoutWithTextWrapping(
12361236 TEST_F(Win32RendererUtilTest, VerticalMonospaced) {
12371237 const CLogFont &logfont = GetFont(false, true);
12381238
1239 vector<mozc::renderer::win32::LineLayout> line_layouts;
1239 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
12401240 bool result = true;
12411241
1242 const wstring &message = GetTestMessageForMonospaced();
1242 const std::wstring &message = GetTestMessageForMonospaced();
12431243
12441244 // Check if the |initial_offset| works as expected.
12451245 result = LayoutManager::CalcLayoutWithTextWrapping(
12941294 TEST_F(Win32RendererUtilTest, HorizontalProportionalCompositeGlyph) {
12951295 const CLogFont &logfont = GetFont(true, false);
12961296
1297 vector<mozc::renderer::win32::LineLayout> line_layouts;
1297 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
12981298 bool result = true;
12991299
1300 const wstring &message = GetTestMessageWithCompositeGlyph(1);
1300 const std::wstring &message = GetTestMessageWithCompositeGlyph(1);
13011301
13021302 result = LayoutManager::CalcLayoutWithTextWrapping(
13031303 logfont, message, 200, 100, &line_layouts);
13141314 TEST_F(Win32RendererUtilTest, VerticalProportionalCompositeGlyph) {
13151315 const CLogFont &logfont = GetFont(true, true);
13161316
1317 vector<mozc::renderer::win32::LineLayout> line_layouts;
1317 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
13181318 bool result = true;
13191319
1320 const wstring &message = GetTestMessageWithCompositeGlyph(1);
1320 const std::wstring &message = GetTestMessageWithCompositeGlyph(1);
13211321 result = LayoutManager::CalcLayoutWithTextWrapping(
13221322 logfont, message, 200, 100, &line_layouts);
13231323 EXPECT_TRUE(result);
13331333 TEST_F(Win32RendererUtilTest, HorizontalMonospacedCompositeGlyph) {
13341334 const CLogFont &logfont = GetFont(false, false);
13351335
1336 vector<mozc::renderer::win32::LineLayout> line_layouts;
1336 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
13371337 bool result = true;
13381338
1339 const wstring &message = GetTestMessageWithCompositeGlyph(1);
1339 const std::wstring &message = GetTestMessageWithCompositeGlyph(1);
13401340
13411341 result = LayoutManager::CalcLayoutWithTextWrapping(
13421342 logfont, message, 200, 100, &line_layouts);
13531353 TEST_F(Win32RendererUtilTest, VerticalMonospacedCompositeGlyph) {
13541354 const CLogFont &logfont = GetFont(false, true);
13551355
1356 vector<mozc::renderer::win32::LineLayout> line_layouts;
1356 std::vector<mozc::renderer::win32::LineLayout> line_layouts;
13571357 bool result = true;
13581358
1359 const wstring &message = GetTestMessageWithCompositeGlyph(1);
1359 const std::wstring &message = GetTestMessageWithCompositeGlyph(1);
13601360
13611361 result = LayoutManager::CalcLayoutWithTextWrapping(
13621362 logfont, message, 200, 100, &line_layouts);
13791379 HWND hwnd = nullptr;
13801380 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
13811381 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
1382 vector<CompositionWindowLayout> layouts;
1382 std::vector<CompositionWindowLayout> layouts;
13831383 CandidateWindowLayout candidate_layout;
13841384
13851385 CLogFont logfont;
14061406 0, 0, 0, 0, 0, 0, logfont, layout);
14071407 {
14081408 const char kMsg[] = "これは";
1409 wstring msg;
1409 std::wstring msg;
14101410 mozc::Util::UTF8ToWide(kMsg, &msg);
14111411 EXPECT_EQ(msg, layout.text);
14121412 }
14241424 0, 0, 646, 0, 647, 49, logfont, layout);
14251425 {
14261426 const char kMsg[] = "、Google日本語入力のTestです";
1427 wstring msg;
1427 std::wstring msg;
14281428 mozc::Util::UTF8ToWide(kMsg, &msg);
14291429 EXPECT_EQ(msg, layout.text);
14301430 }
15001500 HWND hwnd = nullptr;
15011501 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
15021502 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
1503 vector<CompositionWindowLayout> layouts;
1503 std::vector<CompositionWindowLayout> layouts;
15041504 CandidateWindowLayout candidate_layout;
15051505 CLogFont logfont;
15061506
15261526 0, 0, 0, 0, 0, 0, logfont, layout);
15271527 {
15281528 const char kMsg[] = "これは、Go";
1529 wstring msg;
1529 std::wstring msg;
15301530 mozc::Util::UTF8ToWide(kMsg, &msg);
15311531 EXPECT_EQ(msg, layout.text);
15321532 }
15501550 0, 0, 540, 0, 541, 49, logfont, layout);
15511551 {
15521552 const char kMsg[] = "ogle日本語入力のTestです";
1553 wstring msg;
1553 std::wstring msg;
15541554 mozc::Util::UTF8ToWide(kMsg, &msg);
15551555 EXPECT_EQ(msg, layout.text);
15561556 }
16241624 HWND hwnd = nullptr;
16251625 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
16261626 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
1627 vector<CompositionWindowLayout> layouts;
1627 std::vector<CompositionWindowLayout> layouts;
16281628 CandidateWindowLayout candidate_layout;
16291629 CLogFont logfont;
16301630
16521652 51, 0, 0, 0, 0, 0, logfont, layout);
16531653 {
16541654 const char kMsg[] = "これは";
1655 wstring msg;
1655 std::wstring msg;
16561656 mozc::Util::UTF8ToWide(kMsg, &msg);
16571657 EXPECT_EQ(msg, layout.text);
16581658 }
16701670 51, 0, 0, 0, 0, 0, logfont, layout);
16711671 {
16721672 const char kMsg[] = "、Google日本語入";
1673 wstring msg;
1673 std::wstring msg;
16741674 mozc::Util::UTF8ToWide(kMsg, &msg);
16751675 EXPECT_EQ(msg, layout.text);
16761676 }
16941694 51, 0, 0, 270, 51, 271, logfont, layout);
16951695 {
16961696 const char kMsg[] = "力のTestです";
1697 wstring msg;
1697 std::wstring msg;
16981698 mozc::Util::UTF8ToWide(kMsg, &msg);
16991699 EXPECT_EQ(msg, layout.text);
17001700 }
17651765 HWND hwnd = nullptr;
17661766 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
17671767 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
1768 vector<CompositionWindowLayout> layouts;
1768 std::vector<CompositionWindowLayout> layouts;
17691769 CandidateWindowLayout candidate_layout;
17701770 CLogFont logfont;
17711771
17931793 51, 0, 0, 0, 0, 0, logfont, layout);
17941794 {
17951795 const char kMsg[] = "これは、Goo";
1796 wstring msg;
1796 std::wstring msg;
17971797 mozc::Util::UTF8ToWide(kMsg, &msg);
17981798 EXPECT_EQ(msg, layout.text);
17991799 }
18171817 51, 0, 0, 0, 0, 0, logfont, layout);
18181818 {
18191819 const char kMsg[] = "gle日本語入力のTe";
1820 wstring msg;
1820 std::wstring msg;
18211821 mozc::Util::UTF8ToWide(kMsg, &msg);
18221822 EXPECT_EQ(msg, layout.text);
18231823 }
18411841 51, 0, 0, 127, 51, 128, logfont, layout);
18421842 {
18431843 const char kMsg[] = "stです";
1844 wstring msg;
1844 std::wstring msg;
18451845 mozc::Util::UTF8ToWide(kMsg, &msg);
18461846 EXPECT_EQ(msg, layout.text);
18471847 }
19091909 HWND hwnd = nullptr;
19101910 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
19111911 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
1912 vector<CompositionWindowLayout> layouts;
1912 std::vector<CompositionWindowLayout> layouts;
19131913 CandidateWindowLayout candidate_layout;
19141914 CLogFont logfont;
19151915
19351935 0, 0, 0, 0, 0, 0, logfont, layout);
19361936 {
19371937 const char kMsg[] = "これは";
1938 wstring msg;
1938 std::wstring msg;
19391939 mozc::Util::UTF8ToWide(kMsg, &msg);
19401940 EXPECT_EQ(msg, layout.text);
19411941 }
19531953 0, 0, 646, 0, 647, 54, logfont, layout);
19541954 {
19551955 const char kMsg[] = "、Google日本語入力のTestです";
1956 wstring msg;
1956 std::wstring msg;
19571957 mozc::Util::UTF8ToWide(kMsg, &msg);
19581958 EXPECT_EQ(msg, layout.text);
19591959 }
20302030 HWND hwnd = nullptr;
20312031 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
20322032 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2033 vector<CompositionWindowLayout> layouts;
2033 std::vector<CompositionWindowLayout> layouts;
20342034 CandidateWindowLayout candidate_layout;
20352035 CLogFont logfont;
20362036
20562056 0, 0, 0, 0, 0, 0, logfont, layout);
20572057 {
20582058 const char kMsg[] = "これは、Go";
2059 wstring msg;
2059 std::wstring msg;
20602060 mozc::Util::UTF8ToWide(kMsg, &msg);
20612061 EXPECT_EQ(msg, layout.text);
20622062 }
20802080 0, 0, 539, 0, 540, 54, logfont, layout);
20812081 {
20822082 const char kMsg[] = "ogle日本語入力のTestです";
2083 wstring msg;
2083 std::wstring msg;
20842084 mozc::Util::UTF8ToWide(kMsg, &msg);
20852085 EXPECT_EQ(msg, layout.text);
20862086 }
21542154 HWND hwnd = nullptr;
21552155 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
21562156 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2157 vector<CompositionWindowLayout> layouts;
2157 std::vector<CompositionWindowLayout> layouts;
21582158 CandidateWindowLayout candidate_layout;
21592159 CLogFont logfont;
21602160
21822182 56, 0, 0, 0, 0, 0, logfont, layout);
21832183 {
21842184 const char kMsg[] = "これは";
2185 wstring msg;
2185 std::wstring msg;
21862186 mozc::Util::UTF8ToWide(kMsg, &msg);
21872187 EXPECT_EQ(msg, layout.text);
21882188 }
22002200 56, 0, 0, 0, 0, 0, logfont, layout);
22012201 {
22022202 const char kMsg[] = "、Google日本語入";
2203 wstring msg;
2203 std::wstring msg;
22042204 mozc::Util::UTF8ToWide(kMsg, &msg);
22052205 EXPECT_EQ(msg, layout.text);
22062206 }
22242224 56, 0, 0, 269, 56, 270, logfont, layout);
22252225 {
22262226 const char kMsg[] = "力のTestです";
2227 wstring msg;
2227 std::wstring msg;
22282228 mozc::Util::UTF8ToWide(kMsg, &msg);
22292229 EXPECT_EQ(msg, layout.text);
22302230 }
22952295 HWND hwnd = nullptr;
22962296 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
22972297 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2298 vector<CompositionWindowLayout> layouts;
2298 std::vector<CompositionWindowLayout> layouts;
22992299 CandidateWindowLayout candidate_layout;
23002300 CLogFont logfont;
23012301
23232323 56, 0, 0, 0, 0, 0, logfont, layout);
23242324 {
23252325 const char kMsg[] = "これは、Go";
2326 wstring msg;
2326 std::wstring msg;
23272327 mozc::Util::UTF8ToWide(kMsg, &msg);
23282328 EXPECT_EQ(msg, layout.text);
23292329 }
23472347 56, 0, 0, 0, 0, 0, logfont, layout);
23482348 {
23492349 const char kMsg[] = "ogle日本語入力のT";
2350 wstring msg;
2350 std::wstring msg;
23512351 mozc::Util::UTF8ToWide(kMsg, &msg);
23522352 EXPECT_EQ(msg, layout.text);
23532353 }
23712371 56, 0, 0, 151, 56, 152, logfont, layout);
23722372 {
23732373 const char kMsg[] = "estです";
2374 wstring msg;
2374 std::wstring msg;
23752375 mozc::Util::UTF8ToWide(kMsg, &msg);
23762376 EXPECT_EQ(msg, layout.text);
23772377 }
24392439 HWND hwnd = nullptr;
24402440 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
24412441 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2442 vector<CompositionWindowLayout> layouts;
2442 std::vector<CompositionWindowLayout> layouts;
24432443 CandidateWindowLayout candidate_layout;
24442444 CLogFont logfont;
24452445
24652465 0, 0, 781, 0, 782, 49, logfont, layout);
24662466 {
24672467 const char kMsg[] = "これは、Google日本語入力のTestです";
2468 wstring msg;
2468 std::wstring msg;
24692469 mozc::Util::UTF8ToWide(kMsg, &msg);
24702470 EXPECT_EQ(msg, layout.text);
24712471 }
24982498 HWND hwnd = nullptr;
24992499 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
25002500 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2501 vector<CompositionWindowLayout> layouts;
2501 std::vector<CompositionWindowLayout> layouts;
25022502 CandidateWindowLayout candidate_layout;
25032503 CLogFont logfont;
25042504
25242524 0, 0, 781, 0, 782, 54, logfont, layout);
25252525 {
25262526 const char kMsg[] = "これは、Google日本語入力のTestです";
2527 wstring msg;
2527 std::wstring msg;
25282528 mozc::Util::UTF8ToWide(kMsg, &msg);
25292529 EXPECT_EQ(msg, layout.text);
25302530 }
25572557 HWND hwnd = nullptr;
25582558 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
25592559 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2560 vector<CompositionWindowLayout> layouts;
2560 std::vector<CompositionWindowLayout> layouts;
25612561 CandidateWindowLayout candidate_layout;
25622562 CLogFont logfont;
25632563
25852585 51, 0, 0, 0, 0, 0, logfont, layout);
25862586 {
25872587 const char kMsg[] = "これは、Google日";
2588 wstring msg;
2588 std::wstring msg;
25892589 mozc::Util::UTF8ToWide(kMsg, &msg);
25902590 EXPECT_EQ(msg, layout.text);
25912591 }
26122612 51, 0, 0, 0, 0, 0, logfont, layout);
26132613 {
26142614 const char kMsg[] = "本語入力のTestで";
2615 wstring msg;
2615 std::wstring msg;
26162616 mozc::Util::UTF8ToWide(kMsg, &msg);
26172617 EXPECT_EQ(msg, layout.text);
26182618 }
26332633 51, 0, 0, 45, 51, 46, logfont, layout);
26342634 {
26352635 const char kMsg[] = "す";
2636 wstring msg;
2636 std::wstring msg;
26372637 mozc::Util::UTF8ToWide(kMsg, &msg);
26382638 EXPECT_EQ(msg, layout.text);
26392639 }
26542654 HWND hwnd = nullptr;
26552655 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
26562656 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2657 vector<CompositionWindowLayout> layouts;
2657 std::vector<CompositionWindowLayout> layouts;
26582658 CandidateWindowLayout candidate_layout;
26592659 CLogFont logfont;
26602660
26822682 56, 0, 0, 0, 0, 0, logfont, layout);
26832683 {
26842684 const char kMsg[] = "これは、Google日";
2685 wstring msg;
2685 std::wstring msg;
26862686 mozc::Util::UTF8ToWide(kMsg, &msg);
26872687 EXPECT_EQ(msg, layout.text);
26882688 }
27092709 56, 0, 0, 0, 0, 0, logfont, layout);
27102710 {
27112711 const char kMsg[] = "本語入力のTestで";
2712 wstring msg;
2712 std::wstring msg;
27132713 mozc::Util::UTF8ToWide(kMsg, &msg);
27142714 EXPECT_EQ(msg, layout.text);
27152715 }
27302730 56, 0, 0, 45, 56, 46, logfont, layout);
27312731 {
27322732 const char kMsg[] = "す";
2733 wstring msg;
2733 std::wstring msg;
27342734 mozc::Util::UTF8ToWide(kMsg, &msg);
27352735 EXPECT_EQ(msg, layout.text);
27362736 }
27492749 HWND hwnd = nullptr;
27502750 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
27512751 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2752 vector<CompositionWindowLayout> layouts;
2752 std::vector<CompositionWindowLayout> layouts;
27532753
27542754 RendererCommand command;
27552755 CandidateWindowLayout candidate_layout;
27802780 HWND hwnd = nullptr;
27812781 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
27822782 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2783 vector<CompositionWindowLayout> layouts;
2783 std::vector<CompositionWindowLayout> layouts;
27842784
27852785 RendererCommand command;
27862786 CandidateWindowLayout candidate_layout;
28132813 HWND hwnd = nullptr;
28142814 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
28152815 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2816 vector<CompositionWindowLayout> layouts;
2816 std::vector<CompositionWindowLayout> layouts;
28172817
28182818 RendererCommand command;
28192819 CandidateWindowLayout candidate_layout;
28452845 HWND hwnd = nullptr;
28462846 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
28472847 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2848 vector<CompositionWindowLayout> layouts;
2848 std::vector<CompositionWindowLayout> layouts;
28492849
28502850 RendererCommand command;
28512851 CandidateWindowLayout candidate_layout;
28772877 HWND hwnd = nullptr;
28782878 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
28792879 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2880 vector<CompositionWindowLayout> layouts;
2880 std::vector<CompositionWindowLayout> layouts;
28812881
28822882 RendererCommand command;
28832883 CandidateWindowLayout candidate_layout;
29162916 HWND hwnd = nullptr;
29172917 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
29182918 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2919 vector<CompositionWindowLayout> layouts;
2919 std::vector<CompositionWindowLayout> layouts;
29202920
29212921 RendererCommand command;
29222922 CandidateWindowLayout candidate_layout;
29492949 HWND hwnd = nullptr;
29502950 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
29512951 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2952 vector<CompositionWindowLayout> layouts;
2952 std::vector<CompositionWindowLayout> layouts;
29532953
29542954 RendererCommand command;
29552955 CandidateWindowLayout candidate_layout;
29842984 HWND hwnd = nullptr;
29852985 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
29862986 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
2987 vector<CompositionWindowLayout> layouts;
2987 std::vector<CompositionWindowLayout> layouts;
29882988
29892989 RendererCommand command;
29902990 CandidateWindowLayout candidate_layout;
30183018 HWND hwnd = nullptr;
30193019 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
30203020 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3021 vector<CompositionWindowLayout> layouts;
3021 std::vector<CompositionWindowLayout> layouts;
30223022
30233023 RendererCommand command;
30243024 CandidateWindowLayout candidate_layout;
30523052 HWND hwnd = nullptr;
30533053 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
30543054 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3055 vector<CompositionWindowLayout> layouts;
3055 std::vector<CompositionWindowLayout> layouts;
30563056
30573057 RendererCommand command;
30583058 CandidateWindowLayout candidate_layout;
30963096 HWND hwnd = nullptr;
30973097 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
30983098 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3099 vector<CompositionWindowLayout> layouts;
3099 std::vector<CompositionWindowLayout> layouts;
31003100 CandidateWindowLayout candidate_layout;
31013101 CLogFont logfont;
31023102
31313131 HWND hwnd = nullptr;
31323132 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
31333133 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3134 vector<CompositionWindowLayout> layouts;
3134 std::vector<CompositionWindowLayout> layouts;
31353135 CandidateWindowLayout candidate_layout;
31363136 CLogFont logfont;
31373137
31633163 HWND hwnd = nullptr;
31643164 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
31653165 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3166 vector<CompositionWindowLayout> layouts;
3166 std::vector<CompositionWindowLayout> layouts;
31673167
31683168 RendererCommand command;
31693169 CandidateWindowLayout candidate_layout;
32023202 HWND hwnd = nullptr;
32033203 LayoutManager layout_mgr(CreateDefaultGUIFontEmulator(),
32043204 CreateWindowEmulatorWithDPIScaling(1.0, &hwnd));
3205 vector<CompositionWindowLayout> layouts;
3205 std::vector<CompositionWindowLayout> layouts;
32063206 CandidateWindowLayout candidate_layout;
32073207
32083208 CLogFont logfont;
32323232 0, 0, 0, 0, 0, 0, logfont, layout);
32333233 {
32343234 const char kMsg[] = "これは";
3235 wstring msg;
3235 std::wstring msg;
32363236 mozc::Util::UTF8ToWide(kMsg, &msg);
32373237 EXPECT_EQ(msg, layout.text);
32383238 }
32503250 0, 0, 646, 0, 647, 49, logfont, layout);
32513251 {
32523252 const char kMsg[] = "、Google日本語入力のTestです";
3253 wstring msg;
3253 std::wstring msg;
32543254 mozc::Util::UTF8ToWide(kMsg, &msg);
32553255 EXPECT_EQ(msg, layout.text);
32563256 }
33553355 command.mutable_application_info(), false, 0, 0, 0, 0, hwnd);
33563356
33573357 CandidateWindowLayout candidate_layout;
3358 vector<CompositionWindowLayout> layouts;
3358 std::vector<CompositionWindowLayout> layouts;
33593359 bool result = false;
33603360
33613361 layouts.clear();
33783378 0, 0, 0, 0, 0, 0, default_font, layout);
33793379 {
33803380 const char kMsg[] = "これは、Google日本語入力のTest";
3381 wstring msg;
3381 std::wstring msg;
33823382 mozc::Util::UTF8ToWide(kMsg, &msg);
33833383 EXPECT_EQ(msg, layout.text);
33843384 }
34083408 0, 0, 30, 0, 31, 18, default_font, layout);
34093409 {
34103410 const char kMsg[] = "です";
3411 wstring msg;
3411 std::wstring msg;
34123412 mozc::Util::UTF8ToWide(kMsg, &msg);
34133413 EXPECT_EQ(msg, layout.text);
34143414 }
34703470 false, 34, 0, 36, 14, hwnd);
34713471
34723472 CandidateWindowLayout candidate_layout;
3473 vector<CompositionWindowLayout> layouts;
3473 std::vector<CompositionWindowLayout> layouts;
34743474 bool result = false;
34753475
34763476 layouts.clear();
34933493 259, 0, 260, 18, default_font, layout);
34943494 {
34953495 const char kMsg[] = "これは、Google日本語入力のTestです";
3496 wstring msg;
3496 std::wstring msg;
34973497 mozc::Util::UTF8ToWide(kMsg, &msg);
34983498 EXPECT_EQ(msg, layout.text);
34993499 }
35853585 true, 2, 1, 3, 19, child_window);
35863586
35873587 CandidateWindowLayout candidate_layout;
3588 vector<CompositionWindowLayout> layouts;
3588 std::vector<CompositionWindowLayout> layouts;
35893589 bool result = false;
35903590
35913591 layouts.clear();
36083608 0, 0, 0, 0, default_font, layout);
36093609 {
36103610 const char kMsg[] = "これは、Google";
3611 wstring msg;
3611 std::wstring msg;
36123612 mozc::Util::UTF8ToWide(kMsg, &msg);
36133613 EXPECT_EQ(msg, layout.text);
36143614 }
36323632 0, 0, 0, 0, default_font, layout);
36333633 {
36343634 const char kMsg[] = "日本語入力のTes";
3635 wstring msg;
3635 std::wstring msg;
36363636 mozc::Util::UTF8ToWide(kMsg, &msg);
36373637 EXPECT_EQ(msg, layout.text);
36383638 }
36533653 35, 0, 36, 18, default_font, layout);
36543654 {
36553655 const char kMsg[] = "tです";
3656 wstring msg;
3656 std::wstring msg;
36573657 mozc::Util::UTF8ToWide(kMsg, &msg);
36583658 EXPECT_EQ(msg, layout.text);
36593659 }
36863686 EXPECT_TRUE(mozc::win32::FontUtil::ToLOGFONT(
36873687 command.application_info().composition_font(), &logfont));
36883688
3689 vector<CompositionWindowLayout> layouts;
3689 std::vector<CompositionWindowLayout> layouts;
36903690 CandidateWindowLayout candidate_layout;
36913691 EXPECT_TRUE(layout_mgr.LayoutCompositionWindow(
36923692 command, &layouts, &candidate_layout));
37013701 layout);
37023702 {
37033703 const char kMsg[] = "𠮟咤𠮟咤𠮟咤𠮟咤";
3704 wstring msg;
3704 std::wstring msg;
37053705 mozc::Util::UTF8ToWide(kMsg, &msg);
37063706 EXPECT_EQ(msg, layout.text);
37073707 }
37443744 command.application_info().composition_font(), &logfont));
37453745 logfont.lfOrientation = 2700;
37463746
3747 vector<CompositionWindowLayout> layouts;
3747 std::vector<CompositionWindowLayout> layouts;
37483748 CandidateWindowLayout candidate_layout;
37493749 EXPECT_TRUE(layout_mgr.LayoutCompositionWindow(
37503750 command, &layouts, &candidate_layout));
37593759 0, 360, 51, 361, logfont, layout);
37603760 {
37613761 const char kMsg[] = "𠮟咤𠮟咤𠮟咤𠮟咤";
3762 wstring msg;
3762 std::wstring msg;
37633763 mozc::Util::UTF8ToWide(kMsg, &msg);
37643764 EXPECT_EQ(msg, layout.text);
37653765 }
147147
148148 bool Win32Server::AsyncExecCommand(string *proto_message) {
149149 // Take the ownership of |proto_message|.
150 unique_ptr<string> proto_message_owner(proto_message);
150 std::unique_ptr<string> proto_message_owner(proto_message);
151151 scoped_lock l(&mutex_);
152152 if (message_ == *proto_message_owner.get()) {
153153 // This is exactly the same to the previous message. Theoretically it is
169169 ApplicationInfo::ShowCompositionWindow);
170170
171171 CandidateWindowLayout candidate_layout;
172 vector<CompositionWindowLayout> layouts;
172 std::vector<CompositionWindowLayout> layouts;
173173 if (show_composition) {
174174 if (!layout_manager_->LayoutCompositionWindow(
175175 command, &layouts, &candidate_layout)) {
365365 // If SHOW_INFOLIST_IMMEDIATELY flag is set, we should show the InfoList
366366 // without delay. See the comment of SHOW_INFOLIST_IMMEDIATELY in
367367 // win32_renderer_util.h or b/5824433 for details.
368 uint32 maximum_delay = numeric_limits<int32>::max();
368 uint32 maximum_delay = std::numeric_limits<int32>::max();
369369 if ((mode & SHOW_INFOLIST_IMMEDIATELY) == SHOW_INFOLIST_IMMEDIATELY) {
370370 maximum_delay = 0;
371371 }
372372
373 const uint32 hide_window_delay = min(maximum_delay, kHideWindowDelay);
373 const uint32 hide_window_delay = std::min(maximum_delay, kHideWindowDelay);
374374 if (candidates.has_focused_index() && candidates.candidate_size() > 0) {
375375 const int focused_row =
376376 candidates.focused_index() - candidates.candidate(0).index();
377377 if (candidates.candidate_size() >= focused_row &&
378378 candidates.candidate(focused_row).has_information_id()) {
379379 const uint32 raw_delay =
380 max(static_cast<uint32>(0),
380 std::max(static_cast<uint32>(0),
381381 command.output().candidates().usages().delay());
382 const uint32 delay = min(maximum_delay, raw_delay);
382 const uint32 delay = std::min(maximum_delay, raw_delay);
383383 infolist_window_->DelayShow(delay);
384384 } else {
385385 infolist_window_->DelayHide(hide_window_delay);
661661 const size_t j_max = std::min(next_seg->candidates_size(), kCandidateSize);
662662
663663 // Cache the results for the next segment
664 std::vector<int> next_seg_ok(j_max); // Avoiding vector<bool>
664 std::vector<int> next_seg_ok(j_max); // Avoiding std::vector<bool>
665665 std::vector<std::vector<string> > normalized_string(j_max);
666666
667667 // Reuse |nexts| in the loop as this method is performance critical.
7777 };
7878
7979 // This function serializes a given message (any type of protobuf message)
80 // as a wstring encoded by base64.
80 // as a std::wstring encoded by base64.
8181 // Returns true if succeeds.
8282 bool SerializeToBase64WString(const ::google::protobuf::Message &message,
83 wstring *dest) {
83 std::wstring *dest) {
8484 if (dest == NULL) {
8585 return false;
8686 }
111111 }
112112
113113 // This function deserializes a message (any type of protobuf message)
114 // from the given wstring. This wstring should be generated by
114 // from the given std::wstring. This wstring should be generated by
115115 // SerializeToBase64WString.
116116 // Returns true if succeeds
117 bool DeserializeFromBase64WString(const wstring &src,
117 bool DeserializeFromBase64WString(const std::wstring &src,
118118 ::google::protobuf::Message *message) {
119119 if (message == NULL) {
120120 return false;
200200 }
201201
202202 bool StartServiceInternal(const ScopedSCHandle &service_handle,
203 const vector<wstring> &arguments) {
203 const std::vector<wstring> &arguments) {
204204 if (arguments.size() <= 0) {
205205 if (!::StartService(service_handle.get(), 0, NULL)) {
206206 LOG(ERROR) << "StartService failed: " << ::GetLastError();
260260 SERVICE_REQUIRED_PRIVILEGES_INFO privileges_info = {};
261261 // |SERVICE_REQUIRED_PRIVILEGES_INFO::pmszRequiredPrivileges| needs to be
262262 // terminated with two L'\0's.
263 wstring required_privileges(SE_INC_BASE_PRIORITY_NAME);
263 std::wstring required_privileges(SE_INC_BASE_PRIORITY_NAME);
264264 required_privileges.push_back(L'\0');
265265 required_privileges.push_back(L'\0');
266266 // |SERVICE_REQUIRED_PRIVILEGES_INFO::pmszRequiredPrivileges| needs to be
327327 // load type is not DISABLED.
328328 if (state.running() && !now_running &&
329329 (state.load_type() != cache_service::Win32ServiceState::DISABLED)) {
330 vector<wstring> arguments(state.arguments_size());
330 std::vector<wstring> arguments(state.arguments_size());
331331 arguments.resize(state.arguments_size());
332332 for (size_t i = 0; i < state.arguments_size(); ++i) {
333333 if (Util::UTF8ToWide(state.arguments(i), &arguments[i]) <= 0) {
432432 return kMozcCacheServiceName;
433433 }
434434
435 wstring CacheServiceManager::GetUnquotedServicePath() {
435 std::wstring CacheServiceManager::GetUnquotedServicePath() {
436436 const string lock_service_path =
437437 FileUtil::JoinPath(SystemUtil::GetServerDirectory(),
438438 kMozcCacheServiceExeName);
439 wstring wlock_service_path;
439 std::wstring wlock_service_path;
440440 if (Util::UTF8ToWide(lock_service_path, &wlock_service_path) <= 0) {
441441 return L"";
442442 }
443443 return wlock_service_path;
444444 }
445445
446 wstring CacheServiceManager::GetQuotedServicePath() {
446 std::wstring CacheServiceManager::GetQuotedServicePath() {
447447 return L"\"" + GetUnquotedServicePath() + L"\"";
448448 }
449449
512512 ::Sleep(200); // wait for 0.2sec
513513 }
514514
515 return StartServiceInternal(service_handle, vector<wstring>());
515 return StartServiceInternal(service_handle, std::vector<wstring>());
516516 }
517517
518518 bool CacheServiceManager::HasEnoughMemory() {
520520 kMinimumRequiredMemorySizeForInstall;
521521 }
522522
523 bool CacheServiceManager::BackupStateAsString(wstring *result) {
523 bool CacheServiceManager::BackupStateAsString(std::wstring *result) {
524524 if (result == NULL) {
525525 return false;
526526 }
573573 return true;
574574 }
575575
576 bool CacheServiceManager::RestoreStateFromString(const wstring &serialized) {
576 bool CacheServiceManager::RestoreStateFromString(
577 const std::wstring &serialized) {
577578 cache_service::Win32ServiceState state;
578579 if (!DeserializeFromBase64WString(serialized, &state)) {
579580 return false;
5050 static const wchar_t *GetServiceName();
5151
5252 // Return the unquoted path to the cache service exe file.
53 static wstring GetUnquotedServicePath();
53 static std::wstring GetUnquotedServicePath();
5454
5555 // Return the quoted path to the cache service exe file.
56 static wstring GetQuotedServicePath();
56 static std::wstring GetQuotedServicePath();
5757
5858 // Enable the autostart of the cache service.
5959 // Fails if the cache service is not installed.
7878 static bool HasEnoughMemory();
7979
8080 // Return true if the current status of the serivice is successfully
81 // serialized into the specified wstring instance.
81 // serialized into the specified std::wstring instance.
8282 // You can assume that the serialized data consists of ASCII printable
8383 // characters.
8484 // If the cache service is not installed, default settings is returned
8686 static bool BackupStateAsString(wstring *buffer);
8787
8888 // Return true if the previous status of the service is successfully
89 // restored from the specified wstring instance.
89 // restored from the specified std::wstring instance.
9090 // This function may start the service if needed.
91 static bool RestoreStateFromString(const wstring &buffer);
91 static bool RestoreStateFromString(const std::wstring &buffer);
9292
9393 // Return true if:
9494 // - The cache service is not installed.
6363 LogMessageImpl(_T(__FILE__), __LINE__, message, ::GetLastError())
6464 #endif
6565
66 wstring GetMappedFileNameByAddress(LPVOID address) {
66 std::wstring GetMappedFileNameByAddress(LPVOID address) {
6767 wchar_t path[MAX_PATH];
6868 const int length = ::GetMappedFileName(::GetCurrentProcess(), address,
6969 path, arraysize(path));
7171 LOG_WIN32_ERROR(L"GetMappedFileName failed.");
7272 return L"";
7373 }
74 return wstring(path, length);
74 return std::wstring(path, length);
7575 }
7676
7777 // This function scans each section of a given mapped image section and
9191 // MEMORY_BASIC_INFORMATION::Type should be MEM_IMAGE.
9292
9393 // Store the source filename.
94 const wstring &filename = ::GetMappedFileNameByAddress(address);
94 const std::wstring &filename = ::GetMappedFileNameByAddress(address);
9595 if (filename.empty()) {
9696 return false;
9797 }
179179 // See http://b/2470180 for the whole story.
180180 bool VerifyPrivilegeRestrictionIfNeeded(DWORD dwArgc, LPTSTR *lpszArgv) {
181181 bool verify_privilege = false;
182 const wstring test_mode = L"--verify_privilege_restriction";
182 const std::wstring test_mode = L"--verify_privilege_restriction";
183183 for (size_t i = 0; i < dwArgc; ++i) {
184184 if (test_mode == lpszArgv[i]) {
185185 verify_privilege = true;
193193 const string temp_path =
194194 mozc::FileUtil::JoinPath(mozc::SystemUtil::GetServerDirectory(),
195195 "delete_me.txt");
196 wstring wtemp_path;
196 std::wstring wtemp_path;
197197 mozc::Util::UTF8ToWide(temp_path, &wtemp_path);
198198 const HANDLE temp_file = ::CreateFileW(
199199 wtemp_path.c_str(),
272272 STOP_SERVICE_AND_EXIT_FUNCTION();
273273 }
274274
275 wstring server_path;
275 std::wstring server_path;
276276 mozc::Util::UTF8ToWide(mozc::SystemUtil::GetServerPath(), &server_path);
277277
278278 mozc::ScopedHandle file_handle(::CreateFile(server_path.c_str(),
4040
4141 string line;
4242 while (getline(cin, line)) {
43 vector<string> fields;
43 std::vector<string> fields;
4444 mozc::Util::SplitStringUsing(line, "\t ", &fields);
4545 if (fields[0] == "i") {
4646 cache.Insert(fields[1], fields[2]);
5656 LOG(INFO) << "value_size=" << s.value_size();
5757
5858 string line;
59 vector<string> fields;
59 std::vector<string> fields;
6060 while (getline(cin, line)) {
6161 fields.clear();
6262 mozc::Util::SplitStringUsing(line, "\t ", &fields);
3030 // example:
3131 //
3232 // UploadUtil uploader;
33 // vector<pair<string, string> > params;
33 // std::vector<pair<string, string> > params;
3434 // params.push_back(make_pair("hl", "ja"));
3535 // params.push_back(make_pair("v", "0.0.0.0"));
3636 // uploader.SetHeader("Daily", 100, params);
4646 using ::ATL::CComQIPtr;
4747 using ::ATL::CComVariant;
4848
49 string UTF16ToUTF8(const wstring &str) {
49 string UTF16ToUTF8(const std::wstring &str) {
5050 string utf8;
5151 Util::WideToUTF8(str, &utf8);
5252 return utf8;
5656 if (bstr == nullptr) {
5757 return "";
5858 }
59 return UTF16ToUTF8(wstring(bstr, ::SysStringLen(bstr)));
59 return UTF16ToUTF8(std::wstring(bstr, ::SysStringLen(bstr)));
6060 }
6161
6262 string RoleToString(const CComVariant &role) {
262262 return info;
263263 }
264264
265 vector<AccessibleObject> AccessibleObject::GetChildren() const {
266 vector<AccessibleObject> result;
265 std::vector<AccessibleObject> AccessibleObject::GetChildren() const {
266 std::vector<AccessibleObject> result;
267267 if (!container_) {
268268 result;
269269 }
275275 return result;
276276 }
277277
278 vector<CComVariant> buffer;
278 std::vector<CComVariant> buffer;
279279 buffer.resize(num_children);
280280
281281 LONG num_fetched = 0;
5151 AccessibleObject(ATL::CComPtr<IAccessible> container, int32 child_id);
5252
5353 AccessibleObjectInfo GetInfo() const;
54 vector<AccessibleObject> GetChildren() const;
54 std::vector<AccessibleObject> GetChildren() const;
5555 AccessibleObject GetParent() const;
5656 AccessibleObject GetFocus() const;
5757 bool GetWindowHandle(HWND *window_handle) const;
6060 BrowserInfo::BrowserType g_browser_type_ = BrowserInfo::kBrowserTypeUnknown;
6161 bool g_browser_type_initialized_ = false;
6262
63 wstring GetProcessModuleName() {
63 std::wstring GetProcessModuleName() {
6464 if (g_exe_module_name_len_ == 0) {
6565 return L"";
6666 }
67 return wstring(g_exe_module_name_, g_exe_module_name_len_);
67 return std::wstring(g_exe_module_name_, g_exe_module_name_len_);
6868 }
6969
7070 } // namespace
8484 const auto &direct_mode_keys =
8585 KeyInfoUtil::ExtractSortedDirectModeKeys(config);
8686 const size_t size_to_be_copied =
87 min(direct_mode_keys.size(), kMaxDirectModeKeys);
87 std::min(direct_mode_keys.size(), kMaxDirectModeKeys);
8888 snapshot.num_direct_mode_keys = size_to_be_copied;
8989 for (size_t i = 0; i < size_to_be_copied; ++i) {
9090 snapshot.direct_mode_keys[i] = direct_mode_keys[i];
4747 bool use_kana_input;
4848 bool use_keyboard_to_change_preedit_method;
4949 bool use_mode_indicator;
50 vector<KeyInformation> direct_mode_keys;
50 std::vector<KeyInformation> direct_mode_keys;
5151 Info();
5252 };
5353
6464 void VKBackBasedDeleter::BeginDeletion(int deletion_count,
6565 const mozc::commands::Output &output,
6666 const InputState &ime_state) {
67 vector<INPUT> inputs;
67 std::vector<INPUT> inputs;
6868
6969 wait_queue_->clear();
7070 *pending_ime_state_ = InputState();
7676 unicode_buffer_num_elements, flags);
7777 }
7878
79 virtual UINT SendInput(const vector<INPUT> &inputs) {
79 virtual UINT SendInput(const std::vector<INPUT> &inputs) {
8080 last_send_input_data_ = inputs;
8181 return inputs.size();
8282 }
9797 async_key_state_ = async_key_state;
9898 }
9999
100 const vector<INPUT> &last_send_input_data() const {
100 const std::vector<INPUT> &last_send_input_data() const {
101101 return last_send_input_data_;
102102 }
103103
108108 private:
109109 KeyboardStatus key_state_;
110110 KeyboardStatus async_key_state_;
111 vector<INPUT> last_send_input_data_;
111 std::vector<INPUT> last_send_input_data_;
112112 DISALLOW_COPY_AND_ASSIGN(KeyboardMock);
113113 };
114114
179179 // Expect three pairs of VK_BACK [down/up] for deleting proceeding characters
180180 // and one pair of VK_BACK [down/up] as a sentinel key event where pending
181181 // output and ime state wiil be applied.
182 const vector<INPUT> inputs = keyboard_mock->last_send_input_data();
182 const std::vector<INPUT> inputs = keyboard_mock->last_send_input_data();
183183 EXPECT_EQ(8, inputs.size());
184184 EXPECT_EQ(VK_BACK, inputs[0].ki.wVk);
185185 EXPECT_EQ(VK_BACK, inputs[1].ki.wVk);
5757 DWORD g_tls_index = TLS_OUT_OF_INDEXES;
5858 HMODULE g_module_handle = nullptr;
5959
60 string UTF16ToUTF8(const wstring &str) {
60 string UTF16ToUTF8(const std::wstring &str) {
6161 string utf8;
6262 Util::WideToUTF8(str, &utf8);
6363 return utf8;
7676 copied_len_without_null + 1 > buffer_len) {
7777 return "";
7878 }
79 return UTF16ToUTF8(wstring(buffer.get(), copied_len_without_null));
79 return UTF16ToUTF8(std::wstring(buffer.get(), copied_len_without_null));
8080 }
8181
8282 string GetWindowClassNameAsUTF8(HWND window_handle) {
8888 copied_len_without_null + 1 > kBufferLen) {
8989 return "";
9090 }
91 return UTF16ToUTF8(wstring(buffer.get(), copied_len_without_null));
91 return UTF16ToUTF8(std::wstring(buffer.get(), copied_len_without_null));
9292 }
9393
9494 DWORD GetProcessIdFromWindow(HWND window_handle) {
101101
102102 void FillWindowInfo(
103103 HWND window_handle,
104 vector<FocusHierarchyObserver::WindowInfo> *window_hierarchy) {
104 std::vector<FocusHierarchyObserver::WindowInfo> *window_hierarchy) {
105105 if (window_handle == nullptr) {
106106 // error
107107 window_hierarchy->clear();
138138 void FillAccessibleInfo(
139139 AccessibleObject accessible,
140140 HWND focused_window_handle,
141 vector<AccessibleObjectInfo> *hierarchy) {
141 std::vector<AccessibleObjectInfo> *hierarchy) {
142142 if (!accessible.IsValid()) {
143143 return;
144144 }
167167
168168 class ThreadLocalInfo {
169169 public:
170 vector<AccessibleObjectInfo> ui_hierarchy() const {
170 std::vector<AccessibleObjectInfo> ui_hierarchy() const {
171171 return ui_hierarchy_;
172172 }
173 vector<FocusHierarchyObserver::WindowInfo> window_hierarchy() const {
173 std::vector<FocusHierarchyObserver::WindowInfo> window_hierarchy() const {
174174 return window_hierarchy_;
175175 }
176176 string root_window_name() const {
325325
326326 int ref_count_;
327327 HWINEVENTHOOK hook_handle_;
328 vector<AccessibleObjectInfo> ui_hierarchy_;
329 vector<FocusHierarchyObserver::WindowInfo> window_hierarchy_;
328 std::vector<AccessibleObjectInfo> ui_hierarchy_;
329 std::vector<FocusHierarchyObserver::WindowInfo> window_hierarchy_;
330330 string root_window_name_;
331331 };
332332
367367 virtual bool IsAbailable() const {
368368 return ThreadLocalInfo::Self() != nullptr;
369369 }
370 virtual vector<AccessibleObjectInfo> GetUIHierarchy() const {
370 virtual std::vector<AccessibleObjectInfo> GetUIHierarchy() const {
371371 auto *self = ThreadLocalInfo::Self();
372372 if (self == nullptr) {
373 return vector<AccessibleObjectInfo>();
373 return std::vector<AccessibleObjectInfo>();
374374 }
375375 return self->ui_hierarchy();
376376 }
377 virtual vector<WindowInfo> GetWindowHierarchy() const {
377 virtual std::vector<WindowInfo> GetWindowHierarchy() const {
378378 auto *self = ThreadLocalInfo::Self();
379379 if (self == nullptr) {
380 return vector<FocusHierarchyObserver::WindowInfo>();
380 return std::vector<FocusHierarchyObserver::WindowInfo>();
381381 }
382382 return self->window_hierarchy();
383383 }
407407 virtual bool IsAbailable() const {
408408 return false;
409409 }
410 virtual vector<AccessibleObjectInfo> GetUIHierarchy() const {
411 return vector<AccessibleObjectInfo>();
412 }
413 virtual vector<WindowInfo> GetWindowHierarchy() const {
414 return vector<WindowInfo>();
410 virtual std::vector<AccessibleObjectInfo> GetUIHierarchy() const {
411 return std::vector<AccessibleObjectInfo>();
412 }
413 virtual std::vector<WindowInfo> GetWindowHierarchy() const {
414 return std::vector<WindowInfo>();
415415 }
416416 virtual string GetRootWindowName() const {
417417 return "";
5454
5555 virtual void SyncFocusHierarchy() = 0;
5656 virtual bool IsAbailable() const = 0;
57 virtual vector<AccessibleObjectInfo> GetUIHierarchy() const = 0;
58 virtual vector<WindowInfo> GetWindowHierarchy() const = 0;
57 virtual std::vector<AccessibleObjectInfo> GetUIHierarchy() const = 0;
58 virtual std::vector<WindowInfo> GetWindowHierarchy() const = 0;
5959 virtual string GetRootWindowName() const = 0;
6060
6161 static FocusHierarchyObserver *Create();
7373 }
7474 } // namespace
7575
76 bool ReconvertString::Compose(const wstring &preceding_text,
77 const wstring &preceding_composition,
78 const wstring &target,
79 const wstring &following_composition,
80 const wstring &following_text,
76 bool ReconvertString::Compose(const std::wstring &preceding_text,
77 const std::wstring &preceding_composition,
78 const std::wstring &target,
79 const std::wstring &following_composition,
80 const std::wstring &following_text,
8181 RECONVERTSTRING *reconvert_string) {
8282 if (reconvert_string == nullptr) {
8383 return false;
206206 }
207207
208208 bool ReconvertString::Decompose(const RECONVERTSTRING *reconvert_string,
209 wstring *preceding_text,
210 wstring *preceding_composition,
211 wstring *target,
212 wstring *following_composition,
213 wstring *following_text) {
209 std::wstring *preceding_text,
210 std::wstring *preceding_composition,
211 std::wstring *target,
212 std::wstring *following_composition,
213 std::wstring *following_text) {
214214 if (reconvert_string == nullptr) {
215215 return false;
216216 }
346346
347347 bool ReconvertString::EnsureCompositionIsNotEmpty(
348348 RECONVERTSTRING *reconvert_string) {
349 wstring preceding_text;
350 wstring preceding_composition;
351 wstring target;
352 wstring following_composition;
353 wstring following_text;
349 std::wstring preceding_text;
350 std::wstring preceding_composition;
351 std::wstring target;
352 std::wstring following_composition;
353 std::wstring following_text;
354354 if (!ReconvertString::Decompose(
355355 reconvert_string, &preceding_text, &preceding_composition,
356356 &target, &following_composition, &following_text)) {
6060 // Returns true if given substrings are copied into |reconvert_string|.
6161 // The caller is responsible for allocating enough memory for
6262 // |reconvert_string|.
63 static bool Compose(const wstring &preceding_text,
64 const wstring &preceding_composition,
65 const wstring &target,
66 const wstring &following_composition,
67 const wstring &following_text,
63 static bool Compose(const std::wstring &preceding_text,
64 const std::wstring &preceding_composition,
65 const std::wstring &target,
66 const std::wstring &following_composition,
67 const std::wstring &following_text,
6868 RECONVERTSTRING *reconvert_string);
6969
7070 // Returns true if substrings are copied from |reconvert_string|.
7171 static bool Decompose(const RECONVERTSTRING *reconvert_string,
72 wstring *preceding_text,
73 wstring *preceding_composition,
74 wstring *target,
75 wstring *following_composition,
76 wstring *following_text);
72 std::wstring *preceding_text,
73 std::wstring *preceding_composition,
74 std::wstring *target,
75 std::wstring *following_composition,
76 std::wstring *following_text);
7777
7878 // Returns true if the given |reconvert_string| is valid.
7979 static bool Validate(const RECONVERTSTRING *reconvert_string);
3737 namespace {
3838 struct FixedReconvertString : public RECONVERTSTRING {
3939 BYTE buffer[4096];
40 void Initialize(const wstring &entire_string,
40 void Initialize(const std::wstring &entire_string,
4141 size_t padding_bytes) {
4242 dwSize = sizeof(FixedReconvertString);
4343 dwVersion = 0;
163163 expected_following_text, \
164164 actual_reconvert_string) \
165165 do { \
166 wstring actual_precedeing_text; \
167 wstring actual_preceding_composition; \
168 wstring actual_target; \
169 wstring actual_following_composition; \
170 wstring actual_following_text; \
166 std::wstring actual_precedeing_text; \
167 std::wstring actual_preceding_composition; \
168 std::wstring actual_target; \
169 std::wstring actual_following_composition; \
170 std::wstring actual_following_text; \
171171 EXPECT_TRUE(ReconvertString::Decompose( \
172172 &(actual_reconvert_string), \
173173 &actual_precedeing_text, \
186186
187187 #define EXPECT_DECOMPOSE_FAIL(actual_reconvert_string) \
188188 do { \
189 wstring actual_precedeing_text; \
190 wstring actual_preceding_composition; \
191 wstring actual_target; \
192 wstring actual_following_composition; \
193 wstring actual_following_text; \
189 std::wstring actual_precedeing_text; \
190 std::wstring actual_preceding_composition; \
191 std::wstring actual_target; \
192 std::wstring actual_following_composition; \
193 std::wstring actual_following_text; \
194194 EXPECT_FALSE(ReconvertString::Decompose( \
195195 &(actual_reconvert_string), \
196196 &actual_precedeing_text, \
588588 FixedReconvertString reconvert_string;
589589 reconvert_string.Initialize(L"", 10);
590590
591 wstring following_text;
591 std::wstring following_text;
592592 following_text += L'\0';
593593 // "つづく"
594594 following_text += L"\u3064\u3065\u304F";
6565 const wchar_t kPreloadKeyName[] = L"Keyboard Layout\\Preload";
6666 const wchar_t kPreloadTopValueName[] = L"1";
6767
68 typedef map<unsigned int, DWORD> PreloadValueMap;
68 typedef std::map<unsigned int, DWORD> PreloadValueMap;
6969
7070 // Converts an unsigned integer to a wide string.
71 wstring utow(unsigned int i) {
72 wstringstream ss;
71 std::wstring utow(unsigned int i) {
72 std::wstringstream ss;
7373 ss << i;
7474 return ss.str();
7575 }
7676
77 wstring GetSystemRegKeyName(const KeyboardLayoutID &klid) {
78 return wstring(kRegKeyboardLayouts) + L"\\" + klid.ToString();
77 std::wstring GetSystemRegKeyName(const KeyboardLayoutID &klid) {
78 return std::wstring(kRegKeyboardLayouts) + L"\\" + klid.ToString();
7979 }
8080
8181 // Set the layout display name with the Registry String Redirection format
8585 // http://blogs.msdn.com/michkap/archive/2007/01/05/1387397.aspx
8686 // http://blogs.msdn.com/michkap/archive/2007/08/25/4564548.aspx
8787 // http://msdn.microsoft.com/en-us/library/dd374120.aspx
88 HRESULT SetLayoutDisplayName(const KeyboardLayoutID &klid,
89 const wstring &layout_display_name_resource_path,
90 int layout_display_name_resource_id) {
88 HRESULT SetLayoutDisplayName(
89 const KeyboardLayoutID &klid,
90 const std::wstring &layout_display_name_resource_path,
91 int layout_display_name_resource_id) {
9192 if (!klid.has_id()) {
9293 return E_FAIL;
9394 }
9495
95 const wstring &key_name = GetSystemRegKeyName(klid);
96 const std::wstring &key_name = GetSystemRegKeyName(klid);
9697
9798 CRegKey keybord_layout_key;
9899 LRESULT result = keybord_layout_key.Open(
129130 // folder as a system folder, so it will refuse to install our IME. The
130131 // solution here is to combine the 64-bit System32 folder and our filename
131132 // to make ImmInstallIME happy.
132 wstring GetFullPathForSystem(const string& basename) {
133 std::wstring GetFullPathForSystem(const string& basename) {
133134 string system_dir;
134135 if (Util::WideToUTF8(SystemUtil::GetSystemDir(), &system_dir) <= 0) {
135136 return L"";
137138
138139 const string fullpath = FileUtil::JoinPath(system_dir, basename);
139140
140 wstring wfullpath;
141 std::wstring wfullpath;
141142 if (Util::UTF8ToWide(fullpath, &wfullpath) <= 0) {
142143 return L"";
143144 }
178179 }
179180
180181 const int ivalue_name = _wtoi(value_name);
181 const wstring wvalue(reinterpret_cast<wchar_t*>(value),
182 const std::wstring wvalue(reinterpret_cast<wchar_t*>(value),
182183 (value_length / sizeof(wchar_t)) - 1);
183184 KeyboardLayoutID klid(wvalue);
184185 if (!klid.has_id()) {
203204 return index;
204205 }
205206
206 wstring ToWideString(const string &str) {
207 wstring wide;
207 std::wstring ToWideString(const string &str) {
208 std::wstring wide;
208209 if (Util::UTF8ToWide(str, &wide) <= 0) {
209210 return L"";
210211 }
240241 }
241242 } // namespace
242243
243 HRESULT ImmRegistrar::Register(const wstring &ime_filename,
244 const wstring &layout_name,
245 const wstring &layout_display_name_resource_path,
246 int layout_display_name_resource_id,
247 HKL* hkl) {
244 HRESULT ImmRegistrar::Register(
245 const std::wstring &ime_filename,
246 const std::wstring &layout_name,
247 const std::wstring &layout_display_name_resource_path,
248 int layout_display_name_resource_id,
249 HKL* hkl) {
248250 HKL dummy_hkl = nullptr;
249251 if (hkl == nullptr) {
250252 hkl = &dummy_hkl;
265267
266268 IMEPROW dummy_ime_property = { 0 };
267269
268 const wstring &fullpath(
269 wstring(SystemUtil::GetSystemDir()) + L"\\" + ime_filename);
270 const std::wstring &fullpath(
271 std::wstring(SystemUtil::GetSystemDir()) + L"\\" + ime_filename);
270272
271273 // The path name of IME has hard limit. (http://b/2072809)
272274 if (fullpath.size() + 1 > arraysize(dummy_ime_property.szName)) {
316318 }
317319
318320 // Uninstall module by deleting a registry key under kRegKeyboardLayouts.
319 HRESULT ImmRegistrar::Unregister(const wstring &ime_filename) {
321 HRESULT ImmRegistrar::Unregister(const std::wstring &ime_filename) {
320322 const KeyboardLayoutID &klid = GetKLIDFromFileName(ime_filename);
321323 if (!klid.has_id()) {
322324 // already unregistered?
356358 return S_OK;
357359 }
358360
359 bool ImmRegistrar::IsIME(HKL hkl, const wstring &ime_filename) {
361 bool ImmRegistrar::IsIME(HKL hkl, const std::wstring &ime_filename) {
360362 if (hkl == nullptr) {
361363 return false;
362364 }
371373 return WinUtil::SystemEqualString(buf, ime_filename, true);
372374 }
373375
374 wstring ImmRegistrar::GetFileNameForIME() {
376 std::wstring ImmRegistrar::GetFileNameForIME() {
375377 return ToWideString(mozc::kIMEFile);
376378 }
377379
380382 }
381383
382384 KeyboardLayoutID ImmRegistrar::GetKLIDFromFileName(
383 const wstring &ime_filename) {
385 const std::wstring &ime_filename) {
384386 if (ime_filename.empty()) {
385387 return KeyboardLayoutID();
386388 }
410412
411413 // Note that |value_name_length| does not contain NUL character.
412414 const KeyboardLayoutID klid(
413 wstring(value_name, value_name + value_name_length));
415 std::wstring(value_name, value_name + value_name_length));
414416
415417 if (!klid.has_id()) {
416418 continue;
434436
435437 const ULONG filename_length = (filename_length_including_null - 1);
436438 // Note that |filename_length| does not contain NUL character.
437 const wstring target_basename(
439 const std::wstring target_basename(
438440 filename_buffer, filename_buffer + filename_length);
439441
440442 // TODO(yukawa): Support short filename. See b/2977730
445447 return KeyboardLayoutID();
446448 }
447449
448 wstring ImmRegistrar::GetFullPathForIME() {
450 std::wstring ImmRegistrar::GetFullPathForIME() {
449451 return GetFullPathForSystem(mozc::kIMEFile);
450452 }
451453
452 wstring ImmRegistrar::GetLayoutName() {
453 wstring layout_name;
454 std::wstring ImmRegistrar::GetLayoutName() {
455 std::wstring layout_name;
454456 // We use English name here as culture-invariant layout name.
455457 if (Util::UTF8ToWide(kProductNameInEnglish, &layout_name) <= 0) {
456458 return L"";
501503 for (PreloadValueMap::iterator i = preload_values.begin();
502504 i != preload_values.end();
503505 ++i) {
504 const wstring& value_name = utow((*i).first);
506 const std::wstring& value_name = utow((*i).first);
505507 const KeyboardLayoutID target_klid((*i).second);
506508 result = preload_key.DeleteValue(value_name.c_str());
507509 if ((*i).first == preload_index) {
508510 continue;
509511 }
510 const wstring& new_value_name = utow((*i).first - 1);
512 const std::wstring& new_value_name = utow((*i).first - 1);
511513 preload_key.SetStringValue(new_value_name.c_str(),
512514 target_klid.ToString().c_str());
513515 }
4545 public:
4646 // Installs module to the system as an IME.
4747 // Returns registered HKL to hkl.
48 static HRESULT Register(const wstring &ime_filename,
49 const wstring &layout_name,
50 const wstring &layout_display_name_resource_path,
48 static HRESULT Register(const std::wstring &ime_filename,
49 const std::wstring &layout_name,
50 const std::wstring &layout_display_name_resource_path,
5151 int layout_display_name_resource_id,
5252 HKL *hkl);
5353
5454 // Uninstalls module from the system.
55 static HRESULT Unregister(const wstring &ime_filename);
55 static HRESULT Unregister(const std::wstring &ime_filename);
5656
5757 // Returns true if given |hkl| is an IME which consists of |ime_filename|.
58 static bool IsIME(HKL hkl, const wstring &ime_filename);
58 static bool IsIME(HKL hkl, const std::wstring &ime_filename);
5959
6060 // Returns a file name of the IME file.
61 static wstring GetFileNameForIME();
61 static std::wstring GetFileNameForIME();
6262
6363 // Returns a full path to the IME file.
6464 // Returns an empty string if it fails to compose a fullpath.
65 static wstring GetFullPathForIME();
65 static std::wstring GetFullPathForIME();
6666
6767 // Returns a KILD for the IME file.
6868 static KeyboardLayoutID GetKLIDForIME();
6969
7070 // Returns a layout name of the IME file.
7171 // Returns an empty string if it fails to compose a layout name.
72 static wstring GetLayoutName();
72 static std::wstring GetLayoutName();
7373
7474 // Returns a resource ID of a layout display name.
7575 static int GetLayoutDisplayNameResourceId();
7676
7777 // Returns a KILD for the given ime file specified by |ime_file|
78 static KeyboardLayoutID GetKLIDFromFileName(const wstring &ime_file);
78 static KeyboardLayoutID GetKLIDFromFileName(const std::wstring &ime_file);
7979
8080 // Add key to the preload if not exist.
8181 // Returns S_OK if operation completes successfully.
115115 return E_OUTOFMEMORY;
116116 }
117117
118 const wstring &profile = wstring(L"0x0411:") + clsid + profile_id;
118 const std::wstring &profile = std::wstring(L"0x0411:") + clsid + profile_id;
119119 if (!::InstallLayoutOrTip(profile.c_str(), 0)) {
120120 DLOG(ERROR) << "InstallLayoutOrTip failed";
121121 return false;
167167 return false;
168168 }
169169
170 const wstring id(profile.szId);
170 const std::wstring id(profile.szId);
171171 // A valid |profile.szId| should consists of language ID (LANGID) and
172172 // keyboard layout ID (KILD) as follows.
173173 // <LangID 1>:<KLID 1>
212212 return false;
213213 }
214214
215 const wstring &profile_list = L"0x0411:0x" + mozc_klid.ToString();
215 const std::wstring &profile_list = L"0x0411:0x" + mozc_klid.ToString();
216216 if (!::SetDefaultLayoutOrTip(profile_list.c_str(), 0)) {
217217 DLOG(ERROR) << "SetDefaultLayoutOrTip failed";
218218 return false;
254254 // Wait for "MSCTF.AsmCacheReady.<desktop name><session #>" event signal to
255255 // work around b/5765783.
256256 bool ImeUtil::WaitForAsmCacheReady(uint32 timeout_msec) {
257 wstring event_name;
257 std::wstring event_name;
258258 if (Util::UTF8ToWide(SystemUtil::GetMSCTFAsmCacheReadyEventName(),
259259 &event_name) == 0) {
260260 LOG(ERROR) << "Failed to compose event name.";
5959 bool prefer_kana_input;
6060 bool use_mode_indicator;
6161 bool use_romaji_key_to_toggle_input_style;
62 vector<KeyInformation> direct_mode_keys;
62 std::vector<KeyInformation> direct_mode_keys;
6363 InputBehavior();
6464 };
6565
198198 }
199199
200200 // [Overrides]
201 virtual UINT SendInput(const vector<INPUT> &inputs) {
201 virtual UINT SendInput(const std::vector<INPUT> &inputs) {
202202 if (inputs.size() < 1) {
203203 return 0;
204204 }
131131 __in UINT wFlags) = 0;
132132
133133 // Injection point for SendInput API.
134 virtual UINT SendInput(const vector<INPUT> &inputs) = 0;
134 virtual UINT SendInput(const std::vector<INPUT> &inputs) = 0;
135135
136136 static Win32KeyboardInterface *CreateDefault();
137137 };
6262 : id_(kDefaultKLID),
6363 has_id_(false) {}
6464
65 KeyboardLayoutID::KeyboardLayoutID(const wstring &text)
65 KeyboardLayoutID::KeyboardLayoutID(const std::wstring &text)
6666 : id_(kDefaultKLID),
6767 has_id_(false) {
6868 Parse(text);
7272 : id_(id),
7373 has_id_(true) {}
7474
75 bool KeyboardLayoutID::Parse(const wstring &text) {
75 bool KeyboardLayoutID::Parse(const std::wstring &text) {
7676 clear_id();
7777
7878 if (text.size() != kTextLength) {
8585 }
8686
8787 DWORD id = 0;
88 wstringstream ss;
88 std::wstringstream ss;
8989 ss << text;
90 ss >> hex >> id;
90 ss >> std::hex >> id;
9191 set_id(id);
9292 return true;
9393 }
9494
95 wstring KeyboardLayoutID::ToString() const {
95 std::wstring KeyboardLayoutID::ToString() const {
9696 CHECK(has_id()) << "ID is not set.";
9797 wchar_t buffer[KL_NAMELENGTH];
9898 const HRESULT result =
5454
5555 // Initializes an instance with a KLID in text form.
5656 // |id_| remains 'cleared' if |text| is an invalid text form.
57 explicit KeyboardLayoutID(const wstring &text);
57 explicit KeyboardLayoutID(const std::wstring &text);
5858
5959 // Initializes an instance with a KLID in integer form.
6060 explicit KeyboardLayoutID(DWORD id);
6161
6262 // Returns true unless |text| does not have an invalid text form.
6363 // When this method returns false, it behaves as if |clear_id()| was called.
64 bool Parse(const wstring &text);
64 bool Parse(const std::wstring &text);
6565
6666 // Returns KLID in text form.
6767 // You cannot call this method when |has_id()| returns false.
68 wstring ToString() const;
68 std::wstring ToString() const;
6969
7070 // Returns KLID in integer form.
7171 // You cannot call this method when |has_id()| returns false.
4646 KeyboardLayoutID klid(0);
4747 EXPECT_TRUE(klid.has_id());
4848 EXPECT_EQ(0x00000000, klid.id());
49 EXPECT_EQ(wstring(L"00000000"), klid.ToString());
49 EXPECT_EQ(std::wstring(L"00000000"), klid.ToString());
5050 }
5151
5252 // constructor for the text form.
5454 KeyboardLayoutID klid(L"00000000");
5555 EXPECT_TRUE(klid.has_id());
5656 EXPECT_EQ(0x00000000, klid.id());
57 EXPECT_EQ(wstring(L"00000000"), klid.ToString());
57 EXPECT_EQ(std::wstring(L"00000000"), klid.ToString());
5858 }
5959
6060 {
6969 klid.set_id(1);
7070 EXPECT_TRUE(klid.has_id());
7171 EXPECT_EQ(0x00000001, klid.id());
72 EXPECT_EQ(wstring(L"00000001"), klid.ToString());
72 EXPECT_EQ(std::wstring(L"00000001"), klid.ToString());
7373
7474 // Can copy the instance.
7575 KeyboardLayoutID another_klid(L"00000002");
7676 klid = another_klid;
7777 EXPECT_TRUE(klid.has_id());
7878 EXPECT_EQ(0x00000002, klid.id());
79 EXPECT_EQ(wstring(L"00000002"), klid.ToString());
79 EXPECT_EQ(std::wstring(L"00000002"), klid.ToString());
8080 }
8181 }
8282
8686 EXPECT_TRUE(klid.Parse(L"E0220411"));
8787 EXPECT_TRUE(klid.has_id());
8888 EXPECT_EQ(0xE0220411, klid.id());
89 EXPECT_EQ(wstring(L"E0220411"), klid.ToString());
89 EXPECT_EQ(std::wstring(L"E0220411"), klid.ToString());
9090
9191 EXPECT_TRUE(klid.Parse(L"e0220411"));
9292 EXPECT_EQ(0xE0220411, klid.id());
9393 EXPECT_TRUE(klid.has_id());
94 EXPECT_EQ(wstring(L"E0220411"), klid.ToString()); // should be capitalised
94 // This should be capitalised
95 EXPECT_EQ(std::wstring(L"E0220411"), klid.ToString());
9596
9697 // Do not reject any KLID unless it has an invalid text form.
9798 // The caller is responsible for checking the existence of this KLID in the
99100 EXPECT_TRUE(klid.Parse(L"00000000"));
100101 EXPECT_TRUE(klid.has_id());
101102 EXPECT_EQ(0x00000000, klid.id());
102 EXPECT_EQ(wstring(L"00000000"), klid.ToString());
103 EXPECT_EQ(std::wstring(L"00000000"), klid.ToString());
103104
104105 // Invalid text form. Should be rejected.
105106 EXPECT_FALSE(klid.Parse(L"123"));
124125 klid.set_id(0xE0220411);
125126 EXPECT_TRUE(klid.has_id());
126127 EXPECT_EQ(0xE0220411, klid.id());
127 EXPECT_EQ(wstring(L"E0220411"), klid.ToString());
128 EXPECT_EQ(std::wstring(L"E0220411"), klid.ToString());
128129
129130 klid.set_id(0x00000123);
130131 EXPECT_TRUE(klid.has_id());
131132 EXPECT_EQ(0x00000123, klid.id());
132 EXPECT_EQ(wstring(L"00000123"), klid.ToString());
133 EXPECT_EQ(std::wstring(L"00000123"), klid.ToString());
133134
134135 // Do not reject any KLID because the integer form never be invalid as
135136 // opposed to text form.
138139 klid.set_id(0xFFFFFFFF);
139140 EXPECT_TRUE(klid.has_id());
140141 EXPECT_EQ(0xFFFFFFFF, klid.id());
141 EXPECT_EQ(wstring(L"FFFFFFFF"), klid.ToString());
142 EXPECT_EQ(std::wstring(L"FFFFFFFF"), klid.ToString());
142143 }
143144 } // namespace win32
144145 } // namespace mozc
325325 };
326326
327327 void ClearModifyerKeyIfNeeded(
328 const KeyEvent *key, set<KeyEvent::ModifierKey> *modifiers) {
328 const KeyEvent *key, std::set<KeyEvent::ModifierKey> *modifiers) {
329329 if (key == nullptr) {
330330 return;
331331 }
393393 const KeyboardStatus &keyboard_status,
394394 Win32KeyboardInterface *keyboard,
395395 commands::KeyEvent *key,
396 set<KeyEvent::ModifierKey> *modifer_keys) {
396 std::set<KeyEvent::ModifierKey> *modifer_keys) {
397397 if (key == nullptr) {
398398 return false;
399399 }
955955 // Since Mozc protocol requires tricky conditions for modifiers, using set
956956 // container makes the the main part of key event conversion simple rather
957957 // than using vector-like container.
958 set<KeyEvent::ModifierKey> modifiers;
958 std::set<KeyEvent::ModifierKey> modifiers;
959959 const bool result = ConvertToKeyEventMain(
960960 virtual_key,
961961 scan_code,
972972 }
973973
974974 // Updates |modifier_keys| field based on the returned set of modifier keys.
975 for (set<KeyEvent::ModifierKey>::const_iterator i = modifiers.begin();
975 for (std::set<KeyEvent::ModifierKey>::const_iterator i = modifiers.begin();
976976 i != modifiers.end(); ++i) {
977977 key->add_modifier_keys(*i);
978978 }
165165 bool start_server_called_;
166166 uint32 server_protocol_version_;
167167 string response_;
168 map<int, int> error_map_;
168 std::map<int, int> error_map_;
169169 };
170170
171171 class KeyboardMock : public Win32KeyboardInterface {
201201 return JapaneseKeyboardLayoutEmulator::ToUnicode(
202202 wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff, wFlags);
203203 }
204 virtual UINT SendInput(const vector<INPUT> &input) {
204 virtual UINT SendInput(const std::vector<INPUT> &input) {
205205 // Not implemented.
206206 return 0;
207207 }
266266 mozc::config::ConfigHandler::SetConfig(default_config_);
267267 }
268268
269 vector<KeyInformation> GetDefaultDirectModeKeys() const {
269 std::vector<KeyInformation> GetDefaultDirectModeKeys() const {
270270 return KeyInfoUtil::ExtractSortedDirectModeKeys(default_config_);
271271 }
272272
273 vector<KeyInformation> GetDirectModeKeysCtrlJToEnableIME() const {
273 std::vector<KeyInformation> GetDirectModeKeysCtrlJToEnableIME() const {
274274 config::Config config;
275275 config.CopyFrom(default_config_);
276276
284284 return KeyInfoUtil::ExtractSortedDirectModeKeys(config);
285285 }
286286
287 vector<KeyInformation> GetDirectModeKeysCtrlBackslashToEnableIME() const {
287 std::vector<KeyInformation>
288 GetDirectModeKeysCtrlBackslashToEnableIME() const {
288289 config::Config config;
289290 config.CopyFrom(default_config_);
290291
7777
7878 bool MigrationUtil::IsFullTIPAvailable() {
7979 const LANGID kLANGJaJP = MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN);
80 vector<LayoutProfileInfo> profile_list;
80 std::vector<LayoutProfileInfo> profile_list;
8181 if (!UninstallHelper::GetInstalledProfilesByLanguage(kLANGJaJP,
8282 &profile_list)) {
8383 return false;
161161 continue;
162162 }
163163
164 const wstring id(profile.szId);
164 const std::wstring id(profile.szId);
165165 // A valid |profile.szId| should consists of language ID (LANGID) and
166166 // keyboard layout ID (KILD) as follows.
167167 // <LangID 1>:<KLID 1>
194194 return false;
195195 }
196196
197 const wstring &profile = wstring(L"0x0411:") + clsid + profile_id;
197 const std::wstring &profile =
198 std::wstring(L"0x0411:") + clsid + profile_id;
198199 if (!::SetDefaultLayoutOrTip(profile.c_str(), 0)) {
199200 DLOG(ERROR) << "SetDefaultLayoutOrTip failed";
200201 return false;
6363 } // namespace
6464
6565 // Writes a REG_SZ channel name into "ap" in Mozc's client state key.
66 bool OmahaUtil::WriteChannel(const wstring &value) {
66 bool OmahaUtil::WriteChannel(const std::wstring &value) {
6767 CRegKey key;
6868 LONG result = OpenClientStateKey(&key, KEY_READ | KEY_WRITE);
6969 if (ERROR_SUCCESS != result) {
7777 }
7878
7979 // Reads a REG_SZ channel name from "ap" in Mozc's client state key.
80 wstring OmahaUtil::ReadChannel() {
80 std::wstring OmahaUtil::ReadChannel() {
8181 CRegKey key;
8282 LONG result = OpenClientStateKey(&key, KEY_READ);
8383 if (ERROR_SUCCESS != result) {
8989 if (ERROR_SUCCESS != result) {
9090 return L"";
9191 }
92 return wstring(buf);
92 return std::wstring(buf);
9393 }
9494
9595 bool OmahaUtil::ClearOmahaError() {
109109 return true;
110110 }
111111
112 bool OmahaUtil::WriteOmahaError(const wstring &ui_message,
113 const wstring &header) {
112 bool OmahaUtil::WriteOmahaError(const std::wstring &ui_message,
113 const std::wstring &header) {
114114 CRegKey key;
115115 LONG result = OpenClientStateKey(&key, KEY_READ | KEY_WRITE);
116116 if (ERROR_SUCCESS != result) {
122122 }
123123
124124 // Leaves Mozc version in addition to UI message for customer support.
125 const wstring &message = header.length() > 0 ? header + L"\r\n" + ui_message
126 : ui_message;
125 const std::wstring &message =
126 header.length() > 0 ? header + L"\r\n" + ui_message : ui_message;
127127
128128 // This message will be displayed by Omaha meta installer in the error
129129 // dialog.
4747 public:
4848 // Writes the channel name specified by |value| for Omaha.
4949 // Returns true if the operation completed successfully.
50 static bool WriteChannel(const wstring &value);
50 static bool WriteChannel(const std::wstring &value);
5151
5252 // Reads the channel name for Omaha.
5353 // Returns an empty string if there is no entry or fails to retrieve the
5454 // channel name.
55 static wstring ReadChannel();
55 static std::wstring ReadChannel();
5656
5757 // Clears the registry entry to specify error message for Omaha.
5858 // Returns true if the operation completed successfully.
6060
6161 // Writes the registry entry for Omaha to show some error messages.
6262 // Returns true if the operation completed successfully.
63 static bool WriteOmahaError(const wstring &ui_message, const wstring &header);
63 static bool WriteOmahaError(const std::wstring &ui_message,
64 const std::wstring &header);
6465
6566 // Clears the registry entry for the channel name.
6667 // Returns true if the operation completed successfully.
6262 const HKEY KRegKey_NotFound = INT2HKEY(100);
6363 #undef INT2HKEY
6464
65 bool IsEqualInLowercase(const wstring &lhs, const wstring &rhs) {
65 bool IsEqualInLowercase(const std::wstring &lhs, const std::wstring &rhs) {
6666 return WinUtil::SystemEqualString(lhs, rhs, true);
6767 }
6868
115115 has_##field_name##_ = true; \
116116 return &##field_name##_; \
117117 }
118 DEFINE_FIELD(wstring, ap_value)
118 DEFINE_FIELD(std::wstring, ap_value)
119119 DEFINE_FIELD(DWORD, installer_result)
120 DEFINE_FIELD(wstring, installer_result_ui_string)
120 DEFINE_FIELD(std::wstring, installer_result_ui_string)
121121 #undef DEFINE_FIELD
122122
123123 private:
124124 bool omaha_client_state_key_exists_;
125125 bool has_ap_value_;
126 wstring ap_value_;
126 std::wstring ap_value_;
127127 bool has_installer_result_;
128128 DWORD installer_result_;
129129 bool has_installer_result_ui_string_;
130 wstring installer_result_ui_string_;
130 std::wstring installer_result_ui_string_;
131131 };
132132
133133 typedef PropertySelector<Id> Property;
134134
135135 RegistryEmulator() {
136 vector<WinAPITestHelper::HookRequest> requests;
136 std::vector<WinAPITestHelper::HookRequest> requests;
137137 requests.push_back(
138138 DEFINE_HOOK("advapi32.dll", RegCreateKeyExW, TestRegCreateKeyExW));
139139 requests.push_back(
216216
217217 static LSTATUS UpdateString(const wchar_t *value_name,
218218 const wchar_t *src, DWORD num_data) {
219 wstring *target = nullptr;
219 std::wstring *target = nullptr;
220220 if (IsEqualInLowercase(value_name, kRegEntryNameForChannel)) {
221221 target = property()->mutable_ap_value();
222222 } else if (IsEqualInLowercase(
234234 const size_t null_char_index = total_size_in_tchar - 1;
235235 EXPECT_EQ(L'\0', src[null_char_index]);
236236 const size_t total_length_without_null = total_size_in_tchar - 1;
237 const wstring value(src, src + total_length_without_null);
237 const std::wstring value(src, src + total_length_without_null);
238238 target->assign(value);
239239 } else {
240240 target->assign(L"");
308308
309309 static LSTATUS QueryString(const wchar_t *value_name, DWORD *type,
310310 wchar_t *dest, DWORD *num_data) {
311 wstring value;
311 std::wstring value;
312312 if (IsEqualInLowercase(value_name, kRegEntryNameForChannel)) {
313313 if (!property()->has_ap_value()) {
314314 return ERROR_FILE_NOT_FOUND;
4242 const size_t kMaxReadingChars = 512;
4343
4444 void UTF8ToSJIS(StringPiece input, string *output) {
45 wstring utf16;
45 std::wstring utf16;
4646 Util::UTF8ToWide(input, &utf16);
4747 if (utf16.empty()) {
4848 output->clear();
7373
7474 } // namespace
7575
76 wstring StringUtil::KeyToReading(StringPiece key) {
76 std::wstring StringUtil::KeyToReading(StringPiece key) {
7777 string katakana;
7878 Util::HiraganaToKatakana(key, &katakana);
7979
119119 if (output_length_without_null != actual_output_length_without_null) {
120120 return L"";
121121 }
122 return wstring(wide_output.get(), actual_output_length_without_null);
122 return std::wstring(wide_output.get(), actual_output_length_without_null);
123123 }
124124
125125 string StringUtil::KeyToReadingA(StringPiece key) {
128128 return ret;
129129 }
130130
131 wstring StringUtil::ComposePreeditText(const commands::Preedit &preedit) {
132 wstring value;
131 std::wstring StringUtil::ComposePreeditText(const commands::Preedit &preedit) {
132 std::wstring value;
133133 for (int i = 0; i < preedit.segment_size(); ++i) {
134 wstring segment_value;
134 std::wstring segment_value;
135135 mozc::Util::UTF8ToWide(preedit.segment(i).value(), &segment_value);
136136 value.append(segment_value);
137137 }
4949 // http://msdn.microsoft.com/en-us/library/ms629017(VS.85).aspx
5050 // This function only supports conversion of Japanese characters (characters
5151 // covered by code page 932).
52 static wstring KeyToReading(StringPiece key);
52 static std::wstring KeyToReading(StringPiece key);
5353
5454 // Returns a UTF8 string converted from the result of KeyToReading.
5555 // This function is mainly for unittest.
5656 static string KeyToReadingA(StringPiece key);
5757
5858 // Joins all segment strings in |preedit| and returns it.
59 static wstring ComposePreeditText(const mozc::commands::Preedit &preedit);
59 static std::wstring ComposePreeditText(
60 const mozc::commands::Preedit &preedit);
6061 };
6162
6263 } // namespace win32
128128 logfont.lfCharSet = DEFAULT_CHARSET;
129129 logfont.lfHeight = bitmap_height;
130130 logfont.lfQuality = NONANTIALIASED_QUALITY;
131 wstring wide_fontname;
131 std::wstring wide_fontname;
132132 Util::UTF8ToWide(fontname, &wide_fontname);
133133 const errno_t error = wcscpy_s(logfont.lfFaceName, wide_fontname.c_str());
134134 if (error != 0) {
146146 dc.SetBkMode(OPAQUE);
147147 dc.SetBkColor(kBackgroundColor);
148148 dc.SetTextColor(kForegroundColor);
149 wstring wide_text;
149 std::wstring wide_text;
150150 Util::UTF8ToWide(text, &wide_text);
151151 CRect rect(0, 0, bitmap_width, bitmap_height);
152152 dc.FillSolidRect(rect, kBackgroundColor);
216216 // 4-byte alignment. Here we need to do alignment conversion.
217217 const size_t mask_buffer_stride = (bitmap_width + 0x0f) / 16 * 2;
218218 const size_t mask_buffer_size = mask_buffer_stride * bitmap_width;
219 unique_ptr<uint8[]> mask_buffer(new uint8[mask_buffer_size]);
219 std::unique_ptr<uint8[]> mask_buffer(new uint8[mask_buffer_size]);
220220 for (size_t y = 0; y < bitmap_height; ++y) {
221221 for (size_t x = 0; x < bitmap_width; ++x) {
222222 const uint8 *src_line_start =
115115 return HRESULT_FROM_WIN32(result);
116116 }
117117
118 wstring description;
118 std::wstring description;
119119 mozc::Util::UTF8ToWide(mozc::kProductNameInEnglish, &description);
120120
121121 result = key.SetStringValue(nullptr, description.c_str(), REG_SZ);
192192 if (result == S_OK) {
193193 // We use English name here as culture-invariant description.
194194 // Localized name is specified later by SetLanguageProfileDisplayName.
195 wstring description;
195 std::wstring description;
196196 mozc::Util::UTF8ToWide(mozc::kProductNameInEnglish, &description);
197197
198198 result = profiles->AddLanguageProfile(TsfProfile::GetTextServiceGuid(),
5858
5959 namespace {
6060
61 typedef map<int, DWORD> PreloadOrderToKLIDMap;
61 typedef std::map<int, DWORD> PreloadOrderToKLIDMap;
6262
6363 // Windows NT 6.0, 6.1 and 6.2
6464 const CLSID CLSID_IMJPTIP = {
8484 const uint32 kWaitForAsmCacheReadyEventTimeout = 10000; // 10 sec.
8585
8686 // Converts an unsigned integer to a wide string.
87 wstring utow(unsigned int i) {
88 wstringstream ss;
87 std::wstring utow(unsigned int i) {
88 std::wstringstream ss;
8989 ss << i;
9090 return ss.str();
9191 }
9292
93 wstring GetIMEFileNameFromKeyboardLayout(
93 std::wstring GetIMEFileNameFromKeyboardLayout(
9494 const CRegKey &key, const KeyboardLayoutID &klid) {
9595 CRegKey subkey;
9696 LONG result = subkey.Open(key, klid.ToString().c_str(), KEY_READ);
109109 }
110110
111111 const ULONG filename_length = (filename_length_including_null - 1);
112 const wstring filename(filename_buffer);
112 const std::wstring filename(filename_buffer);
113113
114114 // Note that |filename_length| does not contain NUL character.
115115 DCHECK_EQ(filename_length, filename.size());
116116 return filename;
117117 }
118118
119 bool GenerateKeyboardLayoutList(vector<KeyboardLayoutInfo> *keyboard_layouts) {
119 bool GenerateKeyboardLayoutList(
120 std::vector<KeyboardLayoutInfo> *keyboard_layouts) {
120121 if (keyboard_layouts == nullptr) {
121122 return false;
122123 }
145146
146147 // Note that |value_name_length| does not contain NUL character.
147148 const KeyboardLayoutID klid(
148 wstring(value_name, value_name + value_name_length));
149 std::wstring(value_name, value_name + value_name_length));
149150
150151 if (!klid.has_id()) {
151152 continue;
159160 return true;
160161 }
161162
162 bool GenerateKeyboardLayoutMap(map<DWORD, wstring> *keyboard_layouts) {
163 bool GenerateKeyboardLayoutMap(
164 std::map<DWORD, std::wstring> *keyboard_layouts) {
163165 if (keyboard_layouts == nullptr) {
164166 return false;
165167 }
166 vector<KeyboardLayoutInfo> keyboard_layout_list;
168 std::vector<KeyboardLayoutInfo> keyboard_layout_list;
167169 if (!GenerateKeyboardLayoutList(&keyboard_layout_list)) {
168170 return false;
169171 }
176178 return true;
177179 }
178180
179 wstring GetIMEFileName(HKL hkl) {
181 std::wstring GetIMEFileName(HKL hkl) {
180182 const UINT num_chars_without_null = ::ImmGetIMEFileName(hkl, nullptr, 0);
181183 const size_t num_chars_with_null = num_chars_without_null + 1;
182184 unique_ptr<wchar_t[]> buffer(new wchar_t[num_chars_with_null]);
184186 ::ImmGetIMEFileName(hkl, buffer.get(), num_chars_with_null);
185187
186188 // |num_copied| does not include terminating null character.
187 return wstring(buffer.get(), buffer.get() + num_copied);
189 return std::wstring(buffer.get(), buffer.get() + num_copied);
188190 }
189191
190192 bool GetInstalledProfilesByLanguageForTSF(
191193 LANGID langid,
192 vector<LayoutProfileInfo> *installed_profiles) {
194 std::vector<LayoutProfileInfo> *installed_profiles) {
193195 ScopedCOMInitializer com_initializer;
194196 if (FAILED(com_initializer.error_code())) {
195197 return false;
243245
244246 bool GetInstalledProfilesByLanguageForIMM32(
245247 LANGID langid,
246 vector<LayoutProfileInfo> *installed_profiles) {
247 vector<KeyboardLayoutInfo> keyboard_layouts;
248 std::vector<LayoutProfileInfo> *installed_profiles) {
249 std::vector<KeyboardLayoutInfo> keyboard_layouts;
248250 if (!GenerateKeyboardLayoutList(&keyboard_layouts)) {
249251 DLOG(ERROR) << "GenerateKeyboardLayoutList failed.";
250252 return false;
302304 }
303305
304306 const int ivalue_name = _wtoi(value_name);
305 const wstring wvalue(reinterpret_cast<wchar_t*>(value),
307 const std::wstring wvalue(reinterpret_cast<wchar_t*>(value),
306308 (value_length / sizeof(wchar_t)) - 1);
307309 KeyboardLayoutID klid(wvalue);
308310 if (!klid.has_id()) {
313315 return true;
314316 }
315317
316 wstring GUIDToString(const GUID &guid) {
318 std::wstring GUIDToString(const GUID &guid) {
317319 wchar_t buffer[256];
318320 const int character_length_with_null =
319321 ::StringFromGUID2(guid, buffer, arraysize(buffer));
323325
324326 const size_t character_length_without_null =
325327 character_length_with_null - 1;
326 return wstring(buffer, buffer + character_length_without_null);
327 }
328
329 wstring LANGIDToString(LANGID langid) {
328 return std::wstring(buffer, buffer + character_length_without_null);
329 }
330
331 std::wstring LANGIDToString(LANGID langid) {
330332 wchar_t buffer[5];
331333 HRESULT hr = ::StringCchPrintf(buffer, arraysize(buffer), L"%04x", langid);
332334 if (FAILED(hr)) {
457459 return true;
458460 }
459461
460 bool GetActiveKeyboardLayouts(vector<HKL> *keyboard_layouts) {
462 bool GetActiveKeyboardLayouts(std::vector<HKL> *keyboard_layouts) {
461463 if (keyboard_layouts == nullptr) {
462464 return false;
463465 }
554556 // function unloads any active IME if it is included in |ime_filenames|.
555557 // If |exclude| is false, this function unloads any active IME unless it is
556558 // included in |ime_filenames|.
557 void UnloadActivatedKeyboardMain(const vector<wstring> &ime_filenames,
559 void UnloadActivatedKeyboardMain(const std::vector<std::wstring> &ime_filenames,
558560 bool exclude) {
559 vector<HKL> loaded_layouts;
561 std::vector<HKL> loaded_layouts;
560562 if (!GetActiveKeyboardLayouts(&loaded_layouts)) {
561563 return;
562564 }
563565 for (size_t i = 0; i < loaded_layouts.size(); ++i) {
564566 const HKL hkl = loaded_layouts[i];
565 const wstring ime_filename = GetIMEFileName(hkl);
567 const std::wstring ime_filename = GetIMEFileName(hkl);
566568 if (ime_filename.empty()) {
567569 continue;
568570 }
580582 }
581583
582584 void UnloadProfilesForVista(
583 const vector<LayoutProfileInfo> &profiles_to_be_removed) {
584 vector <wstring> ime_filenames;
585 const std::vector<LayoutProfileInfo> &profiles_to_be_removed) {
586 std::vector<std::wstring> ime_filenames;
585587 for (size_t i = 0; i < profiles_to_be_removed.size(); ++i) {
586588 ime_filenames.push_back(profiles_to_be_removed[i].ime_filename);
587589 }
626628 return true;
627629 }
628630
629 bool IsEqualPreload(const PreloadOrderToKLIDMap &current_preload_map,
630 const vector<KeyboardLayoutInfo> &new_preload_layouts) {
631 bool IsEqualPreload(
632 const PreloadOrderToKLIDMap &current_preload_map,
633 const std::vector<KeyboardLayoutInfo> &new_preload_layouts) {
631634 if (current_preload_map.size() != new_preload_layouts.size()) {
632635 return false;
633636 }
649652
650653 // Currently only keyboard layouts which have IME filename are supported.
651654 bool RemoveHotKeyForIME(
652 const vector<KeyboardLayoutInfo> &layouts_to_be_removed) {
655 const std::vector<KeyboardLayoutInfo> &layouts_to_be_removed) {
653656 bool succeeded = true;
654657 for (DWORD id = IME_HOTKEY_DSWITCH_FIRST; id <= IME_HOTKEY_DSWITCH_LAST;
655658 ++id) {
663666 if (hkl == nullptr) {
664667 continue;
665668 }
666 const wstring ime_name = GetIMEFileName(hkl);
669 const std::wstring ime_name = GetIMEFileName(hkl);
667670 for (size_t i = 0; i < layouts_to_be_removed.size(); ++i) {
668671 const KeyboardLayoutInfo &layout = layouts_to_be_removed[i];
669672 if (layout.ime_filename.empty()) {
686689
687690 // Currently this function is Mozc-specific.
688691 // TODO(yukawa): Generalize this function for any IME.
689 void RemoveHotKeyForVista(const vector<LayoutProfileInfo> &installed_profiles) {
690 vector<KeyboardLayoutInfo> hotkey_remove_targets;
692 void RemoveHotKeyForVista(
693 const std::vector<LayoutProfileInfo> &installed_profiles) {
694 std::vector<KeyboardLayoutInfo> hotkey_remove_targets;
691695 for (size_t i = 0; i < installed_profiles.size(); ++i) {
692696 const LayoutProfileInfo &profile = installed_profiles[i];
693697 if (!profile.is_tip && WinUtil::SystemEqualString(
723727 // Currently this function is Mozc-specific.
724728 // TODO(yukawa): Generalize this function for any IME and/or TIP.
725729 bool UninstallHelper::GetNewEnabledProfileForVista(
726 const vector<LayoutProfileInfo> &current_profiles,
727 const vector<LayoutProfileInfo> &installed_profiles,
730 const std::vector<LayoutProfileInfo> &current_profiles,
731 const std::vector<LayoutProfileInfo> &installed_profiles,
728732 LayoutProfileInfo *current_default,
729733 LayoutProfileInfo *new_default,
730 vector<LayoutProfileInfo> *removed_profiles) {
734 std::vector<LayoutProfileInfo> *removed_profiles) {
731735 if (current_default == nullptr) {
732736 return false;
733737 }
795799
796800 bool UninstallHelper::GetInstalledProfilesByLanguage(
797801 LANGID langid,
798 vector<LayoutProfileInfo> *installed_profiles) {
802 std::vector<LayoutProfileInfo> *installed_profiles) {
799803 if (installed_profiles == nullptr) {
800804 return false;
801805 }
817821 }
818822
819823 bool UninstallHelper::GetCurrentProfilesForVista(
820 vector<LayoutProfileInfo> *current_profiles) {
824 std::vector<LayoutProfileInfo> *current_profiles) {
821825 if (current_profiles == nullptr) {
822826 return false;
823827 }
824828 current_profiles->clear();
825829
826 map<DWORD, wstring> keyboard_layouts;
830 std::map<DWORD, std::wstring> keyboard_layouts;
827831 if (!GenerateKeyboardLayoutMap(&keyboard_layouts)) {
828832 return false;
829833 }
856860 }
857861
858862 if ((src.dwProfileType & LOTP_KEYBOARDLAYOUT) == LOTP_KEYBOARDLAYOUT) {
859 const wstring id(src.szId);
863 const std::wstring id(src.szId);
860864 // A valid |profile.szId| should consists of language ID (LANGID) and
861865 // keyboard layout ID (KILD) as follows.
862866 // <LangID 1>:<KLID 1>
886890 }
887891
888892 bool UninstallHelper::RemoveProfilesForVista(
889 const vector<LayoutProfileInfo> &profiles_to_be_removed) {
893 const std::vector<LayoutProfileInfo> &profiles_to_be_removed) {
890894 if (profiles_to_be_removed.size() == 0) {
891895 // Nothing to do.
892896 return true;
893897 }
894898
895 const wstring &profile_string = ComposeProfileStringForVista(
899 const std::wstring &profile_string = ComposeProfileStringForVista(
896900 profiles_to_be_removed);
897901
898902 const BOOL result = ::InstallLayoutOrTipUserReg(
901905 return result != FALSE;
902906 }
903907
904 wstring UninstallHelper::ComposeProfileStringForVista(
905 const vector<LayoutProfileInfo> &profiles) {
906 wstringstream ss;
908 std::wstring UninstallHelper::ComposeProfileStringForVista(
909 const std::vector<LayoutProfileInfo> &profiles) {
910 std::wstringstream ss;
907911 for (size_t i = 0; i < profiles.size(); ++i) {
908912 const LayoutProfileInfo &info = profiles[i];
909913 if (i != 0) {
910914 ss << L";";
911915 }
912916
913 const wstring &langid_string = LANGIDToString(info.langid);
917 const std::wstring &langid_string = LANGIDToString(info.langid);
914918 if (langid_string.empty()) {
915919 continue;
916920 }
917921
918922 if (info.is_tip) {
919 const wstring &clsid_string = GUIDToString(info.clsid);
920 const wstring &guid_string = GUIDToString(info.profile_guid);
923 const std::wstring &clsid_string = GUIDToString(info.clsid);
924 const std::wstring &guid_string = GUIDToString(info.profile_guid);
921925 if (clsid_string.empty() || guid_string.empty()) {
922926 continue;
923927 }
945949 DLOG(ERROR) << "EnableAndBroadcastNewLayout failed.";
946950 }
947951
948 vector<LayoutProfileInfo> profile_list;
952 std::vector<LayoutProfileInfo> profile_list;
949953 profile_list.push_back(new_default);
950 const wstring profile_string = ComposeProfileStringForVista(profile_list);
954 const std::wstring profile_string =
955 ComposeProfileStringForVista(profile_list);
951956 if (profile_string.empty()) {
952957 return false;
953958 }
968973 }
969974
970975 bool UninstallHelper::RestoreUserIMEEnvironmentForVista(bool broadcast_change) {
971 vector<LayoutProfileInfo> installed_profiles;
976 std::vector<LayoutProfileInfo> installed_profiles;
972977 if (!GetInstalledProfilesByLanguage(kLANGJaJP, &installed_profiles)) {
973978 return false;
974979 }
975980
976981 RemoveHotKeyForVista(installed_profiles);
977982
978 vector<LayoutProfileInfo> current_profiles;
983 std::vector<LayoutProfileInfo> current_profiles;
979984 if (!GetCurrentProfilesForVista(&current_profiles)) {
980985 return false;
981986 }
982987 LayoutProfileInfo current_default;
983988 LayoutProfileInfo new_default;
984 vector<LayoutProfileInfo> removed_profiles;
989 std::vector<LayoutProfileInfo> removed_profiles;
985990 if (!GetNewEnabledProfileForVista(current_profiles, installed_profiles,
986991 &current_default, &new_default,
987992 &removed_profiles)) {
4444 struct KeyboardLayoutInfo {
4545 KeyboardLayoutInfo();
4646 DWORD klid;
47 wstring ime_filename;
47 std::wstring ime_filename;
4848 };
4949
5050 struct LayoutProfileInfo {
5353 CLSID clsid;
5454 GUID profile_guid;
5555 DWORD klid;
56 wstring ime_filename;
56 std::wstring ime_filename;
5757 bool is_default;
5858 bool is_tip;
5959 bool is_enabled;
8787 // retrieved in successful.
8888 static bool GetInstalledProfilesByLanguage(
8989 LANGID langid,
90 vector<LayoutProfileInfo> *installed_profiles);
90 std::vector<LayoutProfileInfo> *installed_profiles);
9191
9292 private:
9393 // This function is the main part of RestoreUserIMEEnvironmentMain for
9797 // Returns true if both new enabled profiles and new default profile are
9898 // successfully determined.
9999 static bool GetNewEnabledProfileForVista(
100 const vector<LayoutProfileInfo> &current_profiles,
101 const vector<LayoutProfileInfo> &installed_profiles,
100 const std::vector<LayoutProfileInfo> &current_profiles,
101 const std::vector<LayoutProfileInfo> &installed_profiles,
102102 LayoutProfileInfo *current_default,
103103 LayoutProfileInfo *new_default,
104 vector<LayoutProfileInfo> *removed_profiles);
104 std::vector<LayoutProfileInfo> *removed_profiles);
105105
106106 // Returns true if the list of keyboard layout and TIP for the current user
107107 // is retrieved in successful.
108108 static bool GetCurrentProfilesForVista(
109 vector<LayoutProfileInfo> *current_profiles);
109 std::vector<LayoutProfileInfo> *current_profiles);
110110
111111 // Returns true if the list of keyboard layout and TIP for the current user
112112 // is updated with the specified list as |profiles_to_be_removed|.
113113 static bool RemoveProfilesForVista(
114 const vector<LayoutProfileInfo> &profiles_to_be_removed);
114 const std::vector<LayoutProfileInfo> &profiles_to_be_removed);
115115
116116 // Returns true if |profile| is set as the new default IME or TIP.
117117 static bool SetDefaultForVista(
121121 // Returns a string in which the list of profile information specified in
122122 // |profiles| is encoded. See input_dll.h for the format.
123123 // Returns an empty string if fails.
124 static wstring ComposeProfileStringForVista(
125 const vector<LayoutProfileInfo> &profiles);
124 static std::wstring ComposeProfileStringForVista(
125 const std::vector<LayoutProfileInfo> &profiles);
126126
127127 FRIEND_TEST(UninstallHelperTest, BasicCaseForVista);
128128 FRIEND_TEST(UninstallHelperTest, BasicCaseForWin8);
5151
5252 const DWORD kJapaneseKLID = 0xE0200411;
5353
54 wstring ToWideString(const string &str) {
55 wstring wide;
54 std::wstring ToWideString(const string &str) {
55 std::wstring wide;
5656 if (mozc::Util::UTF8ToWide(str, &wide) <= 0) {
5757 return L"";
5858 }
6666 // 2. Set Google Japanese Input as the default IME.
6767 // 3. Uninstall Google Japanese Input.
6868 // -> MS-IME should be the default IME.
69 vector<LayoutProfileInfo> current_profiles;
69 std::vector<LayoutProfileInfo> current_profiles;
7070 {
7171 // Full IMM32 version of Google Japanese Input.
7272 LayoutProfileInfo info;
9494 current_profiles.push_back(info);
9595 }
9696
97 vector<LayoutProfileInfo> installed_profiles;
97 std::vector<LayoutProfileInfo> installed_profiles;
9898 installed_profiles = current_profiles;
9999
100100 LayoutProfileInfo current_default;
101101 LayoutProfileInfo new_default;
102 vector<LayoutProfileInfo> removed_profiles;
102 std::vector<LayoutProfileInfo> removed_profiles;
103103
104104 EXPECT_TRUE(UninstallHelper::GetNewEnabledProfileForVista(
105105 current_profiles,
120120 // 2. Set Google Japanese Input (IMM32) as the default IME.
121121 // 3. Uninstall Google Japanese Input.
122122 // -> MS-IME should be the default IME.
123 vector<LayoutProfileInfo> current_profiles;
123 std::vector<LayoutProfileInfo> current_profiles;
124124 {
125125 // Full IMM32 version of Google Japanese Input.
126126 LayoutProfileInfo info;
161161 current_profiles.push_back(info);
162162 }
163163
164 vector<LayoutProfileInfo> installed_profiles;
164 std::vector<LayoutProfileInfo> installed_profiles;
165165 installed_profiles = current_profiles;
166166
167167 LayoutProfileInfo current_default;
168168 LayoutProfileInfo new_default;
169 vector<LayoutProfileInfo> removed_profiles;
169 std::vector<LayoutProfileInfo> removed_profiles;
170170
171171 EXPECT_TRUE(UninstallHelper::GetNewEnabledProfileForVista(
172172 current_profiles,
187187 // only their availability is checked.
188188 // TODO(yukawa): Use API hook to inject mock result.
189189 TEST(UninstallHelperTest, LoadKeyboardProfilesTest) {
190 vector<LayoutProfileInfo> installed_profiles;
190 std::vector<LayoutProfileInfo> installed_profiles;
191191 EXPECT_TRUE(UninstallHelper::GetInstalledProfilesByLanguage(
192192 kLANGJaJP, &installed_profiles));
193193
194 vector<LayoutProfileInfo> current_profiles;
194 std::vector<LayoutProfileInfo> current_profiles;
195195 EXPECT_TRUE(UninstallHelper::GetCurrentProfilesForVista(
196196 &current_profiles));
197197 }
198198
199199 TEST(UninstallHelperTest, ComposeProfileStringForVistaTest) {
200 vector<LayoutProfileInfo> profiles;
200 std::vector<LayoutProfileInfo> profiles;
201201 {
202202 LayoutProfileInfo info;
203203 info.langid = kLANGJaJP;
213213 info.is_tip = true;
214214 profiles.push_back(info);
215215 }
216 const wstring &profile_string =
216 const std::wstring &profile_string =
217217 UninstallHelper::ComposeProfileStringForVista(profiles);
218218 EXPECT_EQ(L"0411:E0220411;0411:{03B5835F-F03C-411B-9CE2-AA23E1171E36}"
219219 L"{A76C93D9-5523-4E90-AAFA-4DB112F9AC76}",
4949 using ATL::CStringW;
5050 using std::unique_ptr;
5151
52 wstring SafeGetWindowText(HWND window_handle) {
52 std::wstring SafeGetWindowText(HWND window_handle) {
5353 if (!::IsWindow(window_handle)) {
54 return wstring();
54 return std::wstring();
5555 }
5656
5757 const int text_len_without_null = GetWindowTextLength(window_handle);
5858 if (text_len_without_null <= 0) {
59 return wstring();
59 return std::wstring();
6060 }
6161
6262 const size_t buffer_len = text_len_without_null + 1;
6666 window_handle, buffer.get(), buffer_len);
6767
6868 if (copied_len_without_null <= 0) {
69 return wstring();
69 return std::wstring();
7070 }
7171
72 return wstring(buffer.get(), copied_len_without_null);
72 return std::wstring(buffer.get(), copied_len_without_null);
7373 }
7474
7575 } // namespace
7676
77 wstring WindowUtil::GetWindowClassName(HWND window_handle) {
77 std::wstring WindowUtil::GetWindowClassName(HWND window_handle) {
7878 // Maximum length of WindowClass is assumed to be 256.
7979 // http://msdn.microsoft.com/en-us/library/ms633576.aspx
8080 wchar_t buffer[256 + 1] = {};
8383 if (num_copied_without_null + 1 >= arraysize(buffer)) {
8484 return L"";
8585 }
86 return wstring(buffer, num_copied_without_null);
86 return std::wstring(buffer, num_copied_without_null);
8787 }
8888
8989 // static
4141 public:
4242 // Returns the window class name of |window_handle|.
4343 // Returns an empty string when fails to retrieve the class name.
44 static wstring GetWindowClassName(HWND window_handle);
44 static std::wstring GetWindowClassName(HWND window_handle);
4545
4646 // Returns true if the target window specified by |window_handle| can be
4747 // successfully configured to receive an incoming message from lower
4141 } // namespace
4242
4343 int RunRegisterIME(int argc, char *argv[]) {
44 const wstring ime_path = ImmRegistrar::GetFullPathForIME();
44 const std::wstring ime_path = ImmRegistrar::GetFullPathForIME();
4545 if (ime_path.empty()) {
4646 return kErrorLevelGeneralError;
4747 }
48 const wstring ime_filename = ImmRegistrar::GetFileNameForIME();
48 const std::wstring ime_filename = ImmRegistrar::GetFileNameForIME();
4949
50 const wstring layout_name = ImmRegistrar::GetLayoutName();
50 const std::wstring layout_name = ImmRegistrar::GetLayoutName();
5151 if (layout_name.empty()) {
5252 return kErrorLevelGeneralError;
5353 }
6767 int RunUnregisterIME(int argc, char *argv[]) {
6868 UninstallHelper::RestoreUserIMEEnvironmentMain();
6969
70 const wstring ime_filename = ImmRegistrar::GetFileNameForIME();
70 const std::wstring ime_filename = ImmRegistrar::GetFileNameForIME();
7171 if (ime_filename.empty()) {
7272 return kErrorLevelGeneralError;
7373 }
8383
8484 HMODULE g_module = nullptr;
8585
86 wstring GetMozcComponentPath(const string &filename) {
86 std::wstring GetMozcComponentPath(const string &filename) {
8787 const string path = mozc::SystemUtil::GetServerDirectory() + "\\" + filename;
88 wstring wpath;
88 std::wstring wpath;
8989 mozc::Util::UTF8ToWide(path, &wpath);
9090 return wpath;
9191 }
9393 // Retrieves the value for an installer property.
9494 // Returns an empty string if a property corresponding to |name| is not found or
9595 // error occurs.
96 wstring GetProperty(MSIHANDLE msi, const wstring &name) {
96 std::wstring GetProperty(MSIHANDLE msi, const std::wstring &name) {
9797 DWORD num_buf = 0;
9898 // Obtains the size of the property's string, without null termination.
9999 // Note: |MsiGetProperty()| requires non-null writable buffer.
111111 return L"";
112112 }
113113
114 return wstring(buf.get());
115 }
116
117 bool SetProperty(MSIHANDLE msi, const wstring &name, const wstring &value) {
114 return std::wstring(buf.get());
115 }
116
117 bool SetProperty(
118 MSIHANDLE msi, const std::wstring &name, const std::wstring &value) {
118119 if (MsiSetProperty(msi, name.c_str(), value.c_str()) != ERROR_SUCCESS) {
119120 return false;
120121 }
141142 }
142143 #endif
143144
144 wstring FormatMessageByResourceId(int resourceID, ...) {
145 std::wstring FormatMessageByResourceId(int resourceID, ...) {
145146 wchar_t format_message[4096];
146147 {
147148 const int length = ::LoadString(g_module, resourceID, format_message,
169170 return buffer;
170171 }
171172
172 wstring GetVersionHeader() {
173 std::wstring GetVersionHeader() {
173174 return FormatMessageByResourceId(IDS_FORMAT_VERSION_INFO,
174175 mozc::Version::GetMozcVersionW().c_str());
175176 }
194195 mozc::Version::GetMozcVersionW().c_str(), function, line);
195196 ::OutputDebugStringW(log);
196197 #endif
197 const wstring &message =
198 const std::wstring &message =
198199 FormatMessageByResourceId(IDS_FORMAT_FUNCTION_AND_LINE,
199200 function, line);
200201 return OmahaUtil::WriteOmahaError(message, GetVersionHeader());
366367 DEBUG_BREAK_FOR_DEBUGGER();
367368 // store the CHANNEL value specified in the command line argument for
368369 // WriteApValue.
369 const wstring channel = GetProperty(msi_handle, L"CHANNEL");
370 const std::wstring channel = GetProperty(msi_handle, L"CHANNEL");
370371 if (!channel.empty()) {
371372 if (!SetProperty(msi_handle, L"WriteApValue", channel)) {
372373 LOG_ERROR_FOR_OMAHA();
375376 }
376377
377378 // store the original ap value for WriteApValueRollback.
378 const wstring ap_value = OmahaUtil::ReadChannel();
379 const std::wstring ap_value = OmahaUtil::ReadChannel();
379380 if (!SetProperty(msi_handle, L"WriteApValueRollback", ap_value.c_str())) {
380381 LOG_ERROR_FOR_OMAHA();
381382 return ERROR_INSTALL_FAILURE;
382383 }
383384
384385 // store the current settings of the cache service.
385 wstring backup;
386 std::wstring backup;
386387 if (!mozc::CacheServiceManager::BackupStateAsString(&backup)) {
387388 LOG_ERROR_FOR_OMAHA();
388389 return ERROR_INSTALL_FAILURE;
404405 // "RestoreServiceState" and "RestoreServiceStateRollback"
405406 UINT __stdcall RestoreServiceState(MSIHANDLE msi_handle) {
406407 DEBUG_BREAK_FOR_DEBUGGER();
407 const wstring &backup = GetProperty(msi_handle, L"CustomActionData");
408 const std::wstring &backup = GetProperty(msi_handle, L"CustomActionData");
408409 if (!mozc::CacheServiceManager::RestoreStateFromString(backup)) {
409410 return ERROR_INSTALL_FAILURE;
410411 }
424425
425426 UINT __stdcall WriteApValue(MSIHANDLE msi_handle) {
426427 DEBUG_BREAK_FOR_DEBUGGER();
427 const wstring channel = GetProperty(msi_handle, L"CustomActionData");
428 const std::wstring channel = GetProperty(msi_handle, L"CustomActionData");
428429 if (channel.empty()) {
429430 // OK. Does not change ap value when CustomActionData is not found.
430431 return ERROR_SUCCESS;
440441
441442 UINT __stdcall WriteApValueRollback(MSIHANDLE msi_handle) {
442443 DEBUG_BREAK_FOR_DEBUGGER();
443 const wstring ap_value = GetProperty(msi_handle, L"CustomActionData");
444 const std::wstring ap_value = GetProperty(msi_handle, L"CustomActionData");
444445 if (ap_value.empty()) {
445446 // The ap value did not originally exist so attempt to delete the value.
446447 if (!OmahaUtil::ClearChannel()) {
461462 UINT __stdcall InstallIME(MSIHANDLE msi_handle) {
462463 DEBUG_BREAK_FOR_DEBUGGER();
463464
464 const wstring ime_path =
465 const std::wstring ime_path =
465466 mozc::win32::ImmRegistrar::GetFullPathForIME();
466467 if (ime_path.empty()) {
467468 LOG_ERROR_FOR_OMAHA();
468469 return ERROR_INSTALL_FAILURE;
469470 }
470 const wstring ime_filename =
471 const std::wstring ime_filename =
471472 mozc::win32::ImmRegistrar::GetFileNameForIME();
472473
473 const wstring layout_name = mozc::win32::ImmRegistrar::GetLayoutName();
474 const std::wstring layout_name = mozc::win32::ImmRegistrar::GetLayoutName();
474475 if (layout_name.empty()) {
475476 LOG_ERROR_FOR_OMAHA();
476477 return ERROR_INSTALL_FAILURE;
497498
498499 UINT __stdcall UninstallIME(MSIHANDLE msi_handle) {
499500 DEBUG_BREAK_FOR_DEBUGGER();
500 const wstring ime_filename =
501 const std::wstring ime_filename =
501502 mozc::win32::ImmRegistrar::GetFileNameForIME();
502503 if (ime_filename.empty()) {
503504 return ERROR_INSTALL_FAILURE;
517518 mozc::ScopedCOMInitializer com_initializer;
518519
519520 #if defined(_M_X64)
520 const wstring &path = GetMozcComponentPath(mozc::kMozcTIP64);
521 const std::wstring &path = GetMozcComponentPath(mozc::kMozcTIP64);
521522 #elif defined(_M_IX86)
522 const wstring &path = GetMozcComponentPath(mozc::kMozcTIP32);
523 const std::wstring &path = GetMozcComponentPath(mozc::kMozcTIP32);
523524 #else
524525 #error "Unsupported CPU architecture"
525526 #endif // _M_X64, _M_IX86, and others
255255 }
256256 info->offsets.push_back(offset);
257257
258 wstring value;
258 std::wstring value;
259259 if (mozc::Util::UTF8ToWide(candidate_list.candidates(i).value(), &value) ==
260260 0) {
261261 value.clear();
364364
365365 HIMCC CandidateInfoUtil::Update(HIMCC current_handle,
366366 const mozc::commands::Output &output,
367 vector<UIMessage> *messages) {
367 std::vector<UIMessage> *messages) {
368368 CandidateInfo info;
369369 Convert(output, &info);
370370
5858 DWORD count;
5959 DWORD selection;
6060 bool show_candidate;
61 vector<DWORD> offsets;
62 vector<wchar_t> text_buffer;
61 std::vector<DWORD> offsets;
62 std::vector<wchar_t> text_buffer;
6363 };
6464
6565 class CandidateInfoUtil {
8383 // of the returned handle either way.
8484 static HIMCC Update(HIMCC current_handle,
8585 const mozc::commands::Output &output,
86 vector<UIMessage> *messages);
86 std::vector<UIMessage> *messages);
8787
8888 private:
8989 static bool Convert(const mozc::commands::Output &output,
134134 reinterpret_cast<const BYTE *>(header_) +
135135 header_->dwOffset[candidate_list_no]);
136136 }
137 const wstring GetCandidateString(int candidate_list_no,
137 const std::wstring GetCandidateString(int candidate_list_no,
138138 int candidate_index) const {
139139 const CANDIDATELIST *list = GetList(candidate_list_no);
140140 DCHECK_GE(candidate_index, 0);
455455 }
456456 }
457457
458 string ToUTF8(const wstring &wstr) {
458 string ToUTF8(const std::wstring &wstr) {
459459 string result;
460460 Util::WideToUTF8(wstr, &result);
461461 return result;
8181 }
8282
8383 bool CompositionString::Update(
84 const mozc::commands::Output &output, vector<UIMessage> *messages) {
84 const mozc::commands::Output &output, std::vector<UIMessage> *messages) {
8585 CompositionString prev_composition;
8686 ::CopyMemory(&prev_composition, this, sizeof(CompositionString));
8787
135135
136136 HRESULT result = S_OK;
137137
138 wstring result_string;
138 std::wstring result_string;
139139 mozc::Util::UTF8ToWide(output.result().value(), &result_string);
140140 result = ::StringCchCopyN(result_,
141141 arraysize(result_),
159159 if (output.result().has_key()) {
160160 // Reading string should be stored as half-width katakana like
161161 // other major IMEs. See b/1793283 for details.
162 const wstring &reading_string =
162 const std::wstring &reading_string =
163163 StringUtil::KeyToReading(output.result().key());
164164 result = ::StringCchCopyN(result_reading_,
165165 arraysize(result_reading_),
193193
194194 const mozc::commands::Preedit &preedit = output.preedit();
195195
196 vector<BYTE> reading_attributes;
197 vector<DWORD> reading_clauses;
196 std::vector<BYTE> reading_attributes;
197 std::vector<DWORD> reading_clauses;
198198 reading_clauses.push_back(0);
199199
200 vector<BYTE> composition_attributes;
201 vector<DWORD> composition_clauses;
200 std::vector<BYTE> composition_attributes;
201 std::vector<DWORD> composition_clauses;
202202 composition_clauses.push_back(0);
203203
204 wstring reading_string;
205 wstring composition_string;
204 std::wstring reading_string;
205 std::wstring composition_string;
206206
207207 // As filed in b/2962397, we should use ATTR_CONVERTED as default
208208 // attribute when the preedit state is 'Convert' ("変換") or 'Prediction'
220220 if (segment.has_key()) {
221221 // Reading string should be stored as half-width katakana like
222222 // other major IMEs. See b/1793283 for details.
223 const wstring &segment_reading =
223 const std::wstring &segment_reading =
224224 StringUtil::KeyToReading(segment.key());
225225 reading_string.append(segment_reading);
226226 for (size_t i = 0; i < segment_reading.size(); ++i) {
239239 reading_clauses.push_back(reading_string.size());
240240 DCHECK(segment.has_value());
241241 {
242 wstring segment_composition;
242 std::wstring segment_composition;
243243 mozc::Util::UTF8ToWide(segment.value(), &segment_composition);
244244 composition_string.append(segment_composition);
245245 preedit_utf8.append(segment.value());
5252 public:
5353 bool Initialize();
5454 bool Update(const mozc::commands::Output &output,
55 vector<UIMessage> *messages);
55 std::vector<UIMessage> *messages);
5656
5757 // Returns |focused_character_index_|, which represents the index of wide
5858 // character where suggest/predict/candidate window is aligned.
6565 const BYTE *addr = reinterpret_cast<const BYTE*>(&composition);
6666 const wchar_t *string_start =
6767 reinterpret_cast<const wchar_t *>(addr + offset);
68 const wstring wstr(string_start, string_start + length);
68 const std::wstring wstr(string_start, string_start + length);
6969 string str;
7070 Util::WideToUTF8(wstr.c_str(), &str);
7171 return str;
486486 segment->set_value("が");
487487 segment->set_value_length(1);
488488
489 vector<UIMessage> messages;
489 std::vector<UIMessage> messages;
490490 EXPECT_TRUE(compstr.Update(output, &messages));
491491 EXPECT_EQ(2, messages.size());
492492
540540 output.mutable_status()->set_activated(true);
541541 output.mutable_status()->set_mode(mozc::commands::HIRAGANA);
542542
543 vector<UIMessage> messages;
543 std::vector<UIMessage> messages;
544544 EXPECT_TRUE(compstr.Update(output, &messages));
545545 EXPECT_EQ(2, messages.size());
546546
587587 result->set_value("が");
588588 result->set_type(mozc::commands::Result::STRING);
589589
590 vector<UIMessage> messages;
590 std::vector<UIMessage> messages;
591591 EXPECT_TRUE(compstr.Update(output, &messages));
592592 EXPECT_EQ(2, messages.size());
593593
642642 output.mutable_status()->set_activated(true);
643643 output.mutable_status()->set_mode(mozc::commands::HIRAGANA);
644644
645 vector<UIMessage> messages;
645 std::vector<UIMessage> messages;
646646 EXPECT_TRUE(compstr.Update(output, &messages));
647647 EXPECT_EQ(3, messages.size());
648648
707707 segment->set_value("が");
708708 segment->set_value_length(1);
709709
710 vector<UIMessage> messages;
710 std::vector<UIMessage> messages;
711711 EXPECT_TRUE(compstr.Update(output, &messages));
712712 EXPECT_EQ(1, messages.size());
713713
751751 CompositionString compstr;
752752 EXPECT_TRUE(compstr.Initialize());
753753
754 vector<UIMessage> messages;
754 std::vector<UIMessage> messages;
755755 EXPECT_TRUE(compstr.Update(output, &messages));
756756 EXPECT_EQ(2, messages.size());
757757
805805 CompositionString compstr;
806806 EXPECT_TRUE(compstr.Initialize());
807807
808 vector<UIMessage> messages;
808 std::vector<UIMessage> messages;
809809 EXPECT_TRUE(compstr.Update(output, &messages));
810810 EXPECT_EQ(2, messages.size());
811811
871871 // conversion.
872872 FillOutputForConversion(&output, 0, false);
873873 {
874 vector<UIMessage> messages;
874 std::vector<UIMessage> messages;
875875 EXPECT_TRUE(compstr.Update(output, &messages));
876876 EXPECT_EQ(2, messages.size());
877877
930930 // Second conversion
931931 FillOutputForConversion(&output, 1, true);
932932 {
933 vector<UIMessage> messages;
933 std::vector<UIMessage> messages;
934934 EXPECT_TRUE(compstr.Update(output, &messages));
935935 EXPECT_EQ(1, messages.size());
936936
10231023 status->set_mode(commands::HIRAGANA);
10241024 }
10251025
1026 vector<UIMessage> messages;
1026 std::vector<UIMessage> messages;
10271027 EXPECT_TRUE(compstr.Update(output, &messages));
10281028
10291029 // Here, |focused_character_index_| != Preedit::highlighted_position()
125125
126126 bool UpdateCompositionString(HIMC himc,
127127 const commands::Output &output,
128 vector<UIMessage> *messages) {
128 std::vector<UIMessage> *messages) {
129129 ScopedHIMC<InputContext> context(himc);
130130
131131 // When the string is inserted from Tablet Input Panel, MSCTF shrinks the
150150 MessageQueue *message_queue) {
151151 ScopedHIMC<InputContext> context(himc);
152152 ScopedHIMCC<PrivateContext> private_context(context->hPrivate);
153 vector<UIMessage> messages;
153 std::vector<UIMessage> messages;
154154
155155 if (!UpdateCompositionString(himc, output, &messages)) {
156156 return false;
183183 return false;
184184 }
185185
186 wstring preceding_composition;
187 wstring target_text;
188 wstring following_composition;
186 std::wstring preceding_composition;
187 std::wstring target_text;
188 std::wstring following_composition;
189189 if (!ReconvertString::Decompose(
190190 reconvert_string, nullptr, &preceding_composition,
191191 &target_text, &following_composition, nullptr)) {
193193 return false;
194194 }
195195
196 const wstring total_composition =
196 const std::wstring total_composition =
197197 preceding_composition + target_text + following_composition;
198198
199199 // Like other Japanese IMEs (MS-IME, ATOK), Mozc does not support
200200 // reconversion when the composition string contains any embedded object
201201 // because it is too complicated to restore the original state when the
202202 // reconversion is canceled. See b/3406434 for details.
203 if (total_composition.find(kObjectReplacementCharacter) != wstring::npos) {
203 if (total_composition.find(kObjectReplacementCharacter) !=
204 std::wstring::npos) {
204205 return false;
205206 }
206207
214215 }
215216
216217 bool QueryDocumentFeed(HIMC himc,
217 wstring *preceding_text,
218 wstring *following_text) {
218 std::wstring *preceding_text,
219 std::wstring *following_text) {
219220 LRESULT result = ::ImmRequestMessageW(himc, IMR_DOCUMENTFEED, 0);
220221 if (result == 0) {
221222 // IMR_DOCUMENTFEED is not supported.
255256 }
256257 context->clear_preceding_text();
257258 context->clear_following_text();
258 wstring preceding_text;
259 wstring following_text;
259 std::wstring preceding_text;
260 std::wstring following_text;
260261 if (!QueryDocumentFeed(himc, &preceding_text, &following_text)) {
261262 return;
262263 }
453454 }
454455
455456 void ImeCore::SortIMEMessages(
456 const vector<UIMessage> &composition_messages,
457 const vector<UIMessage> &candidate_messages,
457 const std::vector<UIMessage> &composition_messages,
458 const std::vector<UIMessage> &candidate_messages,
458459 bool previous_open_status,
459460 DWORD previous_conversion_mode,
460461 bool next_open_status,
461462 DWORD next_conversion_mode,
462 vector<UIMessage> *sorted_messages) {
463 std::vector<UIMessage> *sorted_messages) {
463464 DCHECK(sorted_messages);
464465 sorted_messages->clear();
465466
480481 }
481482
482483 // Notify IMN_CLOSECANDIDATE.
483 vector<UIMessage> other_candidate_messages;
484 std::vector<UIMessage> other_candidate_messages;
484485 for (vector<UIMessage>::const_iterator it = candidate_messages.begin();
485486 it != candidate_messages.end(); ++it) {
486487 const bool is_close_candidate = ((it->message() == WM_IME_NOTIFY) &&
494495
495496 // Notify all composition UI messages except for WM_IME_ENDCOMPOSITION.
496497 // Typically WM_IME_STARTCOMPOSITION / WM_IME_COMPOSITION will be handled.
497 vector<UIMessage> end_composition_messages;
498 std::vector<UIMessage> end_composition_messages;
498499 for (vector<UIMessage>::const_iterator it = composition_messages.begin();
499500 it != composition_messages.end(); ++it) {
500501 if (it->message() == WM_IME_ENDCOMPOSITION) {
626627 context->fOpen = next_state.open ? TRUE : FALSE;
627628 context->fdwConversion = next_state.logical_conversion_mode;
628629
629 vector<UIMessage> composition_messages;
630 std::vector<UIMessage> composition_messages;
630631 if (!UpdateCompositionString(himc, output, &composition_messages)) {
631632 return false;
632633 }
633634
634 vector<UIMessage> candidate_messages;
635 std::vector<UIMessage> candidate_messages;
635636 context->hCandInfo =
636637 mozc::win32::CandidateInfoUtil::Update(context->hCandInfo,
637638 output, &candidate_messages);
643644 // In order to minimize the risk of application compatibility problem,
644645 // we might want to send these messages in the the same order to MS-IME.
645646 // See b/3488848 for details.
646 vector<UIMessage> sorted_messages;
647 std::vector<UIMessage> sorted_messages;
647648 SortIMEMessages(composition_messages,
648649 candidate_messages,
649650 previous_open,
211211 // - [WM_IME_ENDCOMPOSITION]
212212 // - [IMN_SETOPENSTATUS for IME-Off]
213213 static void SortIMEMessages(
214 const vector<UIMessage> &composition_messages,
215 const vector<UIMessage> &candidate_messages,
214 const std::vector<UIMessage> &composition_messages,
215 const std::vector<UIMessage> &candidate_messages,
216216 bool previous_open_status,
217217 DWORD previous_conversion_mode,
218218 bool next_open_status,
219219 DWORD next_conversion_mode,
220 vector<UIMessage> *sorted_messages);
220 std::vector<UIMessage> *sorted_messages);
221221
222222 // Internal use only.
223223 // This method implements main part of UpdateContext. Note that this method
127127 bool start_server_called_;
128128 uint32 server_protocol_version_;
129129 string response_;
130 map<int, int> error_map_;
130 std::map<int, int> error_map_;
131131 };
132132
133133 class MockClient : public client::Client {
380380 TEST(ImeCoreTest, TemporalConversionModeMessageOrderTest) {
381381 // "Hankaku/Zenkaku"
382382 {
383 vector<UIMessage> composition_messages;
384 vector<UIMessage> candidate_messages;
385
386 vector<UIMessage> sorted_messages;
383 std::vector<UIMessage> composition_messages;
384 std::vector<UIMessage> candidate_messages;
385
386 std::vector<UIMessage> sorted_messages;
387387 ImeCore::SortIMEMessages(composition_messages,
388388 candidate_messages,
389389 false,
399399
400400 // "(Shift +)G"
401401 {
402 vector<UIMessage> composition_messages;
402 std::vector<UIMessage> composition_messages;
403403 composition_messages.push_back(kMsgStartComposition);
404404 composition_messages.push_back(kMsgCompositionUpdate);
405405
406 vector<UIMessage> candidate_messages;
407
408 vector<UIMessage> sorted_messages;
406 std::vector<UIMessage> candidate_messages;
407
408 std::vector<UIMessage> sorted_messages;
409409 ImeCore::SortIMEMessages(composition_messages,
410410 candidate_messages,
411411 true,
424424
425425 // "Hankaku/Zenkaku"
426426 {
427 vector<UIMessage> composition_messages;
427 std::vector<UIMessage> composition_messages;
428428 composition_messages.push_back(kMsgCompositionResult);
429429 composition_messages.push_back(kMsgEndComposition);
430 vector<UIMessage> candidate_messages;
431
432 vector<UIMessage> sorted_messages;
430 std::vector<UIMessage> candidate_messages;
431
432 std::vector<UIMessage> sorted_messages;
433433 ImeCore::SortIMEMessages(composition_messages,
434434 candidate_messages,
435435 true,
452452 TEST(ImeCoreTest, CompositionMessageOrderTest) {
453453 // "Hankaku/Zenkaku"
454454 {
455 vector<UIMessage> composition_messages;
456 vector<UIMessage> candidate_messages;
457
458 vector<UIMessage> sorted_messages;
455 std::vector<UIMessage> composition_messages;
456 std::vector<UIMessage> candidate_messages;
457
458 std::vector<UIMessage> sorted_messages;
459459 ImeCore::SortIMEMessages(composition_messages,
460460 candidate_messages,
461461 false,
471471
472472 // "(Shift +)G"
473473 {
474 vector<UIMessage> composition_messages;
474 std::vector<UIMessage> composition_messages;
475475 composition_messages.push_back(kMsgStartComposition);
476476 composition_messages.push_back(kMsgCompositionUpdate);
477477
478 vector<UIMessage> candidate_messages;
479
480 vector<UIMessage> sorted_messages;
478 std::vector<UIMessage> candidate_messages;
479
480 std::vector<UIMessage> sorted_messages;
481481 ImeCore::SortIMEMessages(composition_messages,
482482 candidate_messages,
483483 true,
496496
497497 // "o"
498498 {
499 vector<UIMessage> composition_messages;
499 std::vector<UIMessage> composition_messages;
500500 composition_messages.push_back(kMsgCompositionUpdate);
501501
502 vector<UIMessage> candidate_messages;
503
504 vector<UIMessage> sorted_messages;
502 std::vector<UIMessage> candidate_messages;
503
504 std::vector<UIMessage> sorted_messages;
505505 ImeCore::SortIMEMessages(composition_messages,
506506 candidate_messages,
507507 true,
518518
519519 // "Enter"
520520 {
521 vector<UIMessage> composition_messages;
521 std::vector<UIMessage> composition_messages;
522522 composition_messages.push_back(kMsgCompositionResult);
523523 composition_messages.push_back(kMsgEndComposition);
524524
525 vector<UIMessage> candidate_messages;
526
527 vector<UIMessage> sorted_messages;
525 std::vector<UIMessage> candidate_messages;
526
527 std::vector<UIMessage> sorted_messages;
528528 ImeCore::SortIMEMessages(composition_messages,
529529 candidate_messages,
530530 true,
543543
544544 // "Hankaku/Zenkaku"
545545 {
546 vector<UIMessage> composition_messages;
547 vector<UIMessage> candidate_messages;
548
549 vector<UIMessage> sorted_messages;
546 std::vector<UIMessage> composition_messages;
547 std::vector<UIMessage> candidate_messages;
548
549 std::vector<UIMessage> sorted_messages;
550550 ImeCore::SortIMEMessages(composition_messages,
551551 candidate_messages,
552552 true,
566566 TEST(ImeCoreTest, CandidateMessageOrderTest) {
567567 // "Hankaku/Zenkaku"
568568 {
569 vector<UIMessage> composition_messages;
570 vector<UIMessage> candidate_messages;
571
572 vector<UIMessage> sorted_messages;
569 std::vector<UIMessage> composition_messages;
570 std::vector<UIMessage> candidate_messages;
571
572 std::vector<UIMessage> sorted_messages;
573573 ImeCore::SortIMEMessages(composition_messages,
574574 candidate_messages,
575575 false,
585585
586586 // "a"
587587 {
588 vector<UIMessage> composition_messages;
588 std::vector<UIMessage> composition_messages;
589589 composition_messages.push_back(kMsgStartComposition);
590590 composition_messages.push_back(kMsgCompositionUpdate);
591591
592 vector<UIMessage> candidate_messages;
593
594 vector<UIMessage> sorted_messages;
592 std::vector<UIMessage> candidate_messages;
593
594 std::vector<UIMessage> sorted_messages;
595595 ImeCore::SortIMEMessages(composition_messages,
596596 candidate_messages,
597597 true,
609609
610610 // "Space"
611611 {
612 vector<UIMessage> composition_messages;
612 std::vector<UIMessage> composition_messages;
613613 composition_messages.push_back(kMsgCompositionUpdate);
614614
615 vector<UIMessage> candidate_messages;
616
617 vector<UIMessage> sorted_messages;
615 std::vector<UIMessage> candidate_messages;
616
617 std::vector<UIMessage> sorted_messages;
618618 ImeCore::SortIMEMessages(composition_messages,
619619 candidate_messages,
620620 true,
631631
632632 // "Space"
633633 {
634 vector<UIMessage> composition_messages;
634 std::vector<UIMessage> composition_messages;
635635 composition_messages.push_back(kMsgCompositionUpdate);
636636
637 vector<UIMessage> candidate_messages;
637 std::vector<UIMessage> candidate_messages;
638638 candidate_messages.push_back(kMsgOpenCandidate);
639639
640 vector<UIMessage> sorted_messages;
640 std::vector<UIMessage> sorted_messages;
641641 ImeCore::SortIMEMessages(composition_messages,
642642 candidate_messages,
643643 true,
655655
656656 // "Space"
657657 {
658 vector<UIMessage> composition_messages;
658 std::vector<UIMessage> composition_messages;
659659 composition_messages.push_back(kMsgCompositionUpdate);
660660
661 vector<UIMessage> candidate_messages;
661 std::vector<UIMessage> candidate_messages;
662662 candidate_messages.push_back(kMsgChangeCandidate);
663663
664 vector<UIMessage> sorted_messages;
664 std::vector<UIMessage> sorted_messages;
665665 ImeCore::SortIMEMessages(composition_messages,
666666 candidate_messages,
667667 true,
679679
680680 // "i"
681681 {
682 vector<UIMessage> composition_messages;
682 std::vector<UIMessage> composition_messages;
683683 composition_messages.push_back(kMsgCompositionResultAndUpdate);
684684
685 vector<UIMessage> candidate_messages;
685 std::vector<UIMessage> candidate_messages;
686686 candidate_messages.push_back(kMsgCloseCandidate);
687687
688 vector<UIMessage> sorted_messages;
688 std::vector<UIMessage> sorted_messages;
689689 ImeCore::SortIMEMessages(composition_messages,
690690 candidate_messages,
691691 true,
122122 const size_t kMaxCharsForRegisterWord = 64;
123123
124124 // If given string is too long, returns an empty string instead.
125 wstring GetStringIfWithinLimit(const wchar_t *src, size_t size_limit) {
125 std::wstring GetStringIfWithinLimit(const wchar_t *src, size_t size_limit) {
126126 if (src == nullptr) {
127 return wstring();
127 return std::wstring();
128128 }
129129 for (size_t i = 0; i < size_limit; ++i) {
130130 if (src[i] == L'\0') {
131 return wstring(src, i);
132 }
133 }
134 return wstring();
131 return std::wstring(src, i);
132 }
133 }
134 return std::wstring();
135135 }
136136
137137 void SetEnveronmentVariablesForWordRegisterDialog(
138 const wstring &word_value, const wstring &word_reading) {
139 wstring word_value_env_name;
140 wstring word_reading_env_name;
138 const std::wstring &word_value, const std::wstring &word_reading) {
139 std::wstring word_value_env_name;
140 std::wstring word_reading_env_name;
141141 mozc::Util::UTF8ToWide(
142142 mozc::kWordRegisterEnvironmentName, &word_value_env_name);
143143 mozc::Util::UTF8ToWide(
410410 // According to the document, the buffer is guaranteed to be greater
411411 // than or equal to 64 characters in Windows NT.
412412 // http://msdn.microsoft.com/en-us/library/dd318166.aspx
413 wstring name;
413 std::wstring name;
414414 mozc::Util::UTF8ToWide(mozc::kProductNameInEnglish, &name);
415415 wchar_t *dest = static_cast<wchar_t *>(data);
416416 const HRESULT result = ::StringCchCopyN(
10461046 // Generate NotifyUpdateUI message if not exists.
10471047 {
10481048 bool has_ui_message = false;
1049 const vector<TRANSMSG> &messages = message_queue.messages();
1049 const std::vector<TRANSMSG> &messages = message_queue.messages();
10501050 for (size_t i = 0; i < messages.size(); ++i) {
10511051 const TRANSMSG &msg = messages[i];
10521052 if (msg.message == WM_IME_NOTIFY &&
10931093
10941094 // Retrieves word registration data.
10951095 const REGISTERWORD *reg_word = static_cast<REGISTERWORD *>(data);
1096 const wstring word = GetStringIfWithinLimit(reg_word->lpWord,
1096 const std::wstring word = GetStringIfWithinLimit(reg_word->lpWord,
10971097 kMaxCharsForRegisterWord);
1098 const wstring reading = GetStringIfWithinLimit(reg_word->lpReading,
1098 const std::wstring reading = GetStringIfWithinLimit(reg_word->lpReading,
10991099 kMaxCharsForRegisterWord);
11001100
11011101 SetEnveronmentVariablesForWordRegisterDialog(word, reading);
8585 size_t size() const;
8686 ImeLangBarMenuData* data(size_t i);
8787 private:
88 vector<ImeLangBarMenuData> data_;
88 std::vector<ImeLangBarMenuData> data_;
8989 };
9090
9191 MIDL_INTERFACE(IIDSTR_IMozcLangBarMenu)
160160 return true;
161161 }
162162
163 const vector<TRANSMSG> &MessageQueue::messages() const {
163 const std::vector<TRANSMSG> &MessageQueue::messages() const {
164164 return messages_;
165165 }
166166
5858 // Send the messages to context if not attached to a message list.
5959 bool Send();
6060
61 const vector<TRANSMSG> &messages() const;
61 const std::vector<TRANSMSG> &messages() const;
6262
6363 private:
6464 HIMC himc_;
6565 LPTRANSMSGLIST transmsg_;
66 vector<TRANSMSG> messages_;
66 std::vector<TRANSMSG> messages_;
6767 int transmsg_count_;
6868
6969 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
201201 const bool show_suggest_window =
202202 ui_visibility_tracker.IsSuggestWindowVisible();
203203
204 vector<wstring> candidate_list;
204 std::vector<wstring> candidate_list;
205205 DWORD focused_index = 0;
206206 if (!context.IsEmpty() && context.GetOpenStatus()) {
207207 // Copy the last output.
5252
5353 class CandidateStringImpl : public ITfCandidateString {
5454 public:
55 CandidateStringImpl(ULONG index, const wstring &value)
55 CandidateStringImpl(ULONG index, const std::wstring &value)
5656 : index_(index),
5757 value_(value) {
5858 }
111111
112112 TipRefCount ref_count_;
113113 const ULONG index_;
114 const wstring value_;
114 const std::wstring value_;
115115
116116 DISALLOW_COPY_AND_ASSIGN(CandidateStringImpl);
117117 };
118118
119119 class EnumTfCandidatesImpl : public IEnumTfCandidates {
120120 public:
121 explicit EnumTfCandidatesImpl(const vector<wstring> &candidates)
121 explicit EnumTfCandidatesImpl(const std::vector<wstring> &candidates)
122122 : candidates_(candidates),
123123 current_(0) {
124124 }
209209
210210 TipRefCount ref_count_;
211211
212 vector<wstring> candidates_;
212 std::vector<wstring> candidates_;
213213 size_t current_;
214214
215215 DISALLOW_COPY_AND_ASSIGN(EnumTfCandidatesImpl);
217217
218218 class CandidateListImpl : public ITfCandidateList {
219219 public:
220 CandidateListImpl(const vector<wstring> &candidates,
220 CandidateListImpl(const std::vector<wstring> &candidates,
221221 TipCandidateListCallback *callback)
222222 : candidates_(candidates),
223223 callback_(callback) {
305305 }
306306
307307 TipRefCount ref_count_;
308 vector<wstring> candidates_;
308 std::vector<wstring> candidates_;
309309 unique_ptr<TipCandidateListCallback> callback_;
310310
311311 DISALLOW_COPY_AND_ASSIGN(CandidateListImpl);
317317 }
318318
319319 // static
320 ITfCandidateList *TipCandidateList::New(const vector<wstring> &candidates,
320 ITfCandidateList *TipCandidateList::New(const std::vector<wstring> &candidates,
321321 TipCandidateListCallback *callback) {
322322 return new CandidateListImpl(candidates, callback);
323323 }
4949 class TipCandidateListCallback {
5050 public:
5151 virtual ~TipCandidateListCallback();
52 virtual void OnFinalize(size_t index, const wstring &candidate) = 0;
52 virtual void OnFinalize(size_t index, const std::wstring &candidate) = 0;
5353 };
5454
5555 class TipCandidateList {
5959 // is called with CAND_FINALIZED. TipCandidateList will take the
6060 // ownership of |callback|. |callback| can be nullptr.
6161 // Caller must maintain the reference count of the returned object.
62 static ITfCandidateList *New(const vector<wstring> &candidates,
62 static ITfCandidateList *New(const std::vector<wstring> &candidates,
6363 TipCandidateListCallback *callback);
6464 static const IID& GetIID();
6565
7272 candidate_.clear();
7373 }
7474
75 void OnFinalize(size_t index, const wstring &candidate) {
75 void OnFinalize(size_t index, const std::wstring &candidate) {
7676 on_finalize_called_ = true;
7777 index_ = index;
7878 candidate_ = candidate;
8686 return index_;
8787 }
8888
89 const wstring &candidate() const {
89 const std::wstring &candidate() const {
9090 return candidate_;
9191 }
9292
9393 private:
9494 bool on_finalize_called_;
9595 size_t index_;
96 wstring candidate_;
96 std::wstring candidate_;
9797 DISALLOW_COPY_AND_ASSIGN(MockCallbackResult);
9898 };
9999
106106
107107 private:
108108 // TipCandidateListCallback overrides:
109 virtual void OnFinalize(size_t index, const wstring &candidate) {
109 virtual void OnFinalize(size_t index, const std::wstring &candidate) {
110110 result_->OnFinalize(index, candidate);
111111 }
112112
114114 DISALLOW_COPY_AND_ASSIGN(MockCallback);
115115 };
116116
117 wstring ToWStr(const CComBSTR &bstr) {
118 return wstring(static_cast<const wchar_t *>(bstr), bstr.Length());
117 std::wstring ToWStr(const CComBSTR &bstr) {
118 return std::wstring(static_cast<const wchar_t *>(bstr), bstr.Length());
119119 }
120120
121121 AssertionResult ExpectCandidateString(ULONG expected_index,
122 const wstring &expected_text,
122 const std::wstring &expected_text,
123123 CComPtr<ITfCandidateString> candiate) {
124124 if (candiate == nullptr) {
125125 return AssertionFailure() << "|actual| should be non-null";
144144 return AssertionFailure() << "ITfCandidateString::GetString failed."
145145 << " hr = " << hr;
146146 }
147 const wstring wstr(ToWStr(str));
147 const std::wstring wstr(ToWStr(str));
148148 if (expected_text != wstr) {
149149 return AssertionFailure() << "expected: " << expected_text
150150 << ", actual: " << wstr;
159159 TEST(TipCandidateListTest, EmptyCandiate) {
160160 MockCallbackResult result;
161161
162 vector<wstring> empty;
162 std::vector<wstring> empty;
163163 CComPtr<ITfCandidateList> candidate_list(
164164 TipCandidateList::New(empty, new MockCallback(&result)));
165165 ASSERT_NE(nullptr, candidate_list);
193193 TEST(TipCandidateListTest, NonEmptyCandiates) {
194194 MockCallbackResult result;
195195
196 vector<wstring> source;
196 std::vector<wstring> source;
197197 for (wchar_t c = L'A'; c < L'Z'; ++c) {
198 source.push_back(wstring(c, 1));
198 source.push_back(std::wstring(c, 1));
199199 }
200200 CComPtr<ITfCandidateList> candidate_list(
201201 TipCandidateList::New(source, new MockCallback(&result)));
8686
8787 TipDisplayAttribute::TipDisplayAttribute(const GUID &guid,
8888 const TF_DISPLAYATTRIBUTE &attribute,
89 const wstring &description)
89 const std::wstring &description)
9090 : guid_(guid),
9191 description_(description) {
9292 ::CopyMemory(&original_attribute_, &attribute, sizeof(original_attribute_));
6464 protected:
6565 TipDisplayAttribute(const GUID &guid,
6666 const TF_DISPLAYATTRIBUTE &attribute,
67 const wstring &description);
67 const std::wstring &description);
6868
6969 private:
7070 TipRefCount ref_count_;
7171 GUID guid_;
7272 TF_DISPLAYATTRIBUTE original_attribute_;
73 wstring description_;
73 std::wstring description_;
7474 TF_DISPLAYATTRIBUTE attribute_;
7575
7676 DISALLOW_COPY_AND_ASSIGN(TipDisplayAttribute);
4848 public:
4949 TestableTipDisplayAttribute(const GUID &guid,
5050 const TF_DISPLAYATTRIBUTE &attribute,
51 const wstring &description)
51 const std::wstring &description)
5252 : TipDisplayAttribute(guid, attribute, description) {
5353 }
5454 };
203203 // This function is called back by the TSF thread manager when an edit
204204 // request is granted.
205205 virtual STDMETHODIMP DoEditSession(TfEditCookie read_cookie) {
206 vector<InputScope> input_scopes;
206 std::vector<InputScope> input_scopes;
207207 CComPtr<ITfRange> selection_range;
208208 TfActiveSelEnd active_sel_end = TF_AE_NONE;
209209 if (SUCCEEDED(TipRangeUtil::GetDefaultSelection(
726726 return S_OK;
727727 }
728728
729 const wstring &text() const {
729 const std::wstring &text() const {
730730 return text_;
731731 }
732732
734734 TipRefCount ref_count_;
735735 CComPtr<TipTextService> text_service_;
736736 CComPtr<ITfRange> range_;
737 wstring text_;
737 std::wstring text_;
738738
739739 DISALLOW_COPY_AND_ASSIGN(SyncGetTextEditSessionImpl);
740740 };
745745 class AsyncSetTextEditSessionImpl : public ITfEditSession {
746746 public:
747747 AsyncSetTextEditSessionImpl(TipTextService *text_service,
748 const wstring &text,
748 const std::wstring &text,
749749 ITfRange *range)
750750 : text_service_(text_service),
751751 text_(text),
781781 private:
782782 TipRefCount ref_count_;
783783 CComPtr<TipTextService> text_service_;
784 const wstring text_;
784 const std::wstring text_;
785785 CComPtr<ITfRange> range_;
786786
787787 DISALLOW_COPY_AND_ASSIGN(AsyncSetTextEditSessionImpl);
10201020 // Stop reconversion when any embedded object is found because we cannot
10211021 // easily restore it. See b/3406434
10221022 if (info.selected_text.find(static_cast<wchar_t>(TS_CHAR_EMBEDDED)) !=
1023 wstring::npos) {
1023 std::wstring::npos) {
10241024 // embedded object is found.
10251025 return false;
10261026 }
10931093
10941094 bool TipEditSession::GetTextSync(TipTextService *text_service,
10951095 ITfRange *range,
1096 wstring *text) {
1096 std::wstring *text) {
10971097 CComPtr<ITfContext> context;
10981098 if (FAILED(range->GetContext(&context))) {
10991099 return false;
11161116
11171117 // static
11181118 bool TipEditSession::SetTextAsync(TipTextService *text_service,
1119 const wstring &text,
1119 const std::wstring &text,
11201120 ITfRange *range) {
11211121 CComPtr<ITfContext> context;
11221122 if (FAILED(range->GetContext(&context))) {
108108 // Begins a sync edit session to retrieve the text from |range|.
109109 static bool GetTextSync(TipTextService *text_service,
110110 ITfRange *range,
111 wstring *text);
111 std::wstring *text);
112112
113113 // Begins an async edit session to set |text| to |range|.
114114 static bool SetTextAsync(TipTextService *text_service,
115 const wstring &text,
115 const std::wstring &text,
116116 ITfRange *range);
117117
118118 private:
8686 return result;
8787 }
8888
89 const wstring &canonical_reading_string =
89 const std::wstring &canonical_reading_string =
9090 StringUtil::KeyToReading(reading_string_utf8);
9191 CComVariant reading(CComBSTR(canonical_reading_string.c_str()));
9292 result = reading_property->SetValue(write_cookie, range, &reading);
177177 return nullptr;
178178 }
179179
180 wstring result_text;
180 std::wstring result_text;
181181 Util::UTF8ToWide(output.result().value(), &result_text);
182182
183 wstring composition_text;
183 std::wstring composition_text;
184184 TipRangeUtil::GetText(composition_range, write_cookie, &composition_text);
185185
186186 // Make sure that |composition_text| begins with |result_text| so that
249249 return result;
250250 }
251251 if (is_empty != TRUE) {
252 wstring str;
252 std::wstring str;
253253 TipRangeUtil::GetText(composition_range, write_cookie, &str);
254254 result = composition_range->SetText(write_cookie, 0, L"", 0);
255255 if (FAILED(result)) {
297297 }
298298
299299 const Preedit &preedit = output.preedit();
300 const wstring &preedit_text = StringUtil::ComposePreeditText(preedit);
300 const std::wstring &preedit_text = StringUtil::ComposePreeditText(preedit);
301301 result = composition_range->SetText(
302302 write_cookie, 0, preedit_text.c_str(), preedit_text.size());
303303 if (FAILED(result)) {
359359 var.lVal = attribute;
360360 result = display_attribute->SetValue(write_cookie, segment_range, &var);
361361 if (segment.has_key()) {
362 const wstring &reading_string = StringUtil::KeyToReading(segment.key());
362 const std::wstring &reading_string =
363 StringUtil::KeyToReading(segment.key());
363364 CComVariant reading(CComBSTR(reading_string.c_str()));
364365 result = reading_property->SetValue(
365366 write_cookie, segment_range, &reading);
520521 if (FAILED(result)) {
521522 return result;
522523 }
523 vector<InputScope> input_scopes;
524 std::vector<InputScope> input_scopes;
524525 result = TipRangeUtil::GetInputScopes(
525526 selection_range, write_cookie, &input_scopes);
526527 TipInputModeManager *input_mode_manager =
6161
6262 TipInputModeManagerImpl::StatePair TipInputModeManagerImpl::GetOverriddenState(
6363 const StatePair &base_state,
64 const vector<InputScope> &input_scopes) {
64 const std::vector<InputScope> &input_scopes) {
6565 if (input_scopes.empty()) {
6666 return base_state;
6767 }
68 vector<ConversionMode> states;
68 std::vector<ConversionMode> states;
6969 for (size_t i = 0; i < input_scopes.size(); ++i) {
7070 const InputScope input_scope = input_scopes[i];
7171 switch (input_scope) {
132132 StatePair mozc_state;
133133 StatePair tsf_state;
134134 IndicatorVisibilityTracker indicator_visibility_tracker;
135 vector<InputScope> input_scope;
135 std::vector<InputScope> input_scope;
136136 };
137137
138138 // For Mode Indicator.
233233 TipInputModeManager::Action TipInputModeManager::OnSetFocus(
234234 bool system_open_close_mode,
235235 DWORD system_conversion_mode,
236 const vector<InputScope> &input_scopes) {
236 const std::vector<InputScope> &input_scopes) {
237237 const StatePair prev_effective = state_->mozc_state;
238238
239239 state_->indicator_visibility_tracker.OnMoveFocusedWindow();
240240
241 vector<InputScope> new_input_scopes = input_scopes;
241 std::vector<InputScope> new_input_scopes = input_scopes;
242242 Dedup(&new_input_scopes);
243243
244244 state_->tsf_state.open_close = system_open_close_mode;
307307
308308 TipInputModeManager::Action
309309 TipInputModeManager::OnChangeInputScope(
310 const vector<InputScope> &input_scopes) {
310 const std::vector<InputScope> &input_scopes) {
311311 const StatePair prev_effective = state_->mozc_state;
312312
313 vector<InputScope> new_input_scopes = input_scopes;
313 std::vector<InputScope> new_input_scopes = input_scopes;
314314 Dedup(&new_input_scopes);
315315 if (new_input_scopes == state_->input_scope) {
316316 // The same input scope is specified. Use the previous mode.
6363 };
6464
6565 protected:
66 static StatePair GetOverriddenState(const StatePair &base_state,
67 const vector<InputScope> &input_scopes);
66 static StatePair GetOverriddenState(
67 const StatePair &base_state,
68 const std::vector<InputScope> &input_scopes);
6869 };
6970
7071 // In TSF, IME open/close mode and conversion mode are managed per thread not
114115 DWORD mozc_visible_mode);
115116 Action OnSetFocus(bool system_open_close_mode,
116117 DWORD system_conversion_mode,
117 const vector<InputScope> &input_scopes);
118 const std::vector<InputScope> &input_scopes);
118119 Action OnChangeOpenClose(bool new_open_close_mode);
119120 Action OnChangeConversionMode(DWORD new_conversion_mode);
120 Action OnChangeInputScope(const vector<InputScope> &input_scopes);
121 Action OnChangeInputScope(const std::vector<InputScope> &input_scopes);
121122
122123 // Returns IME open/close state that is visible from Mozc session.
123124 bool GetEffectiveOpenClose() const;
6161 TEST(TipInputModeManagerImplTest, GetOverriddenState) {
6262 // Check if input scopes for turning off IME temporarily.
6363 {
64 vector<InputScope> input_scope_off;
64 std::vector<InputScope> input_scope_off;
6565 input_scope_off.push_back(IS_NUMBER);
6666 input_scope_off.push_back(IS_EMAIL_SMTPEMAILADDRESS);
6767 {
8484
8585 // Check if input scopes for turning on IME temporarily.
8686 {
87 vector<InputScope> input_scope_full_hiragana;
87 std::vector<InputScope> input_scope_full_hiragana;
8888 input_scope_full_hiragana.push_back(IS_HIRAGANA);
8989 {
9090 const StatePair state =
116116 // If there are multiple input scopes and they are not aggregatable, use the
117117 // original state as is.
118118 {
119 vector<InputScope> input_scope_invalid;
119 std::vector<InputScope> input_scope_invalid;
120120 input_scope_invalid.push_back(IS_HIRAGANA);
121121 input_scope_invalid.push_back(IS_KATAKANA_FULLWIDTH);
122122 {
155155 input_mode_manager.OnInitialize(false, kNativeHiragana);
156156
157157 // SetFocus (Off + Hiragana)
158 vector<InputScope> input_scope_empty;
158 std::vector<InputScope> input_scope_empty;
159159 auto action = input_mode_manager.OnSetFocus(
160160 false, kNativeHiragana, input_scope_empty);
161161 EXPECT_EQ(TipInputModeManager::kDoNothing, action);
192192 input_mode_manager.OnInitialize(false, kNativeHiragana);
193193
194194 // SetFocus (Off + Hiragana)
195 vector<InputScope> input_scope_empty;
195 std::vector<InputScope> input_scope_empty;
196196 auto action = input_mode_manager.OnSetFocus(
197197 false, kNativeHiragana, input_scope_empty);
198198 EXPECT_EQ(TipInputModeManager::kDoNothing, action);
227227 input_mode_manager.OnInitialize(false, kNativeHiragana);
228228
229229 // SetFocus (Off + Hiragana)
230 vector<InputScope> input_scope_empty;
230 std::vector<InputScope> input_scope_empty;
231231 auto action = input_mode_manager.OnSetFocus(
232232 false, kNativeHiragana, input_scope_empty);
233233 EXPECT_EQ(TipInputModeManager::kDoNothing, action);
236236 EXPECT_EQ(TipInputModeManager::kHiragana,
237237 input_mode_manager.GetEffectiveConversionMode());
238238
239 vector<InputScope> input_scope_full_katakana;
239 std::vector<InputScope> input_scope_full_katakana;
240240 input_scope_full_katakana.push_back(IS_KATAKANA_FULLWIDTH);
241241
242242 // InputScope: IS_KATAKANA_FULLWIDTH
253253
254254 // InputScope: IS_EMAIL_SMTPEMAILADDRESS
255255 // This should change the mode and make indicator visible.
256 vector<InputScope> input_scope_email;
256 std::vector<InputScope> input_scope_email;
257257 input_scope_email.push_back(IS_EMAIL_SMTPEMAILADDRESS);
258258 action = input_mode_manager.OnChangeInputScope(input_scope_email);
259259 EXPECT_EQ(TipInputModeManager::kUpdateUI, action);
269269
270270 // InputScope: IS_NUMBER
271271 // This should not change the mode and keep indicator invisible.
272 vector<InputScope> input_scope_number;
272 std::vector<InputScope> input_scope_number;
273273 input_scope_number.push_back(IS_NUMBER);
274274 action = input_mode_manager.OnChangeInputScope(input_scope_number);
275275 EXPECT_EQ(TipInputModeManager::kDoNothing, action);
551551 return E_NOINTERFACE;
552552 }
553553
554 void TipLangBarButton::SetDescription(const wstring &description) {
554 void TipLangBarButton::SetDescription(const std::wstring &description) {
555555 ::StringCchCopy(item_info_.szDescription,
556556 arraysize(item_info_.szDescription),
557557 description.c_str());
9595 TipLangBarMenuData* data(size_t i);
9696
9797 private:
98 vector<TipLangBarMenuData> data_;
98 std::vector<TipLangBarMenuData> data_;
9999 };
100100
101101 MIDL_INTERFACE(IIDSTR_IMozcLangBarItem)
171171
172172 // Update the item description. The caller is also responsible for calling
173173 // OnUpdate method to notify the change to the system.
174 void SetDescription(const wstring &description);
174 void SetDescription(const std::wstring &description);
175175
176176 // Returns the i-th data in the language bar menu.
177177 // Returns NULL if i is out of bounds.
291291 // Represents the index of the selected menu item.
292292 UINT menu_selected_;
293293 bool disabled_;
294 wstring description_for_enabled_;
294 std::wstring description_for_enabled_;
295295 TipLangBarMenuData menu_data_for_disabled_;
296296 };
297297
126126 return E_INVALIDARG;
127127 }
128128 *candidate_list = nullptr;
129 wstring query;
129 std::wstring query;
130130 if (!TipEditSession::GetTextSync(text_service_, range, &query)) {
131131 return E_FAIL;
132132 }
5858
5959 private:
6060 // The TipQueryProvider interface methods.
61 virtual bool Query(const wstring &query,
61 virtual bool Query(const std::wstring &query,
6262 QueryType type,
63 vector<wstring> *result) {
63 std::vector<wstring> *result) {
6464 if (type == kReconversion) {
6565 return ReconvertQuery(query, result);
6666 }
6767 return SimpleQuery(query, result);
6868 }
6969
70 bool SimpleQuery(const wstring &query,
71 vector<wstring> *result) {
70 bool SimpleQuery(const std::wstring &query,
71 std::vector<wstring> *result) {
7272 {
7373 KeyEvent key_event;
7474 string utf8_query;
8888 const auto &candidates = output.all_candidate_words();
8989 for (size_t i = 0; i < candidates.candidates_size(); ++i) {
9090 const auto &utf8 = candidates.candidates(i).value();
91 wstring wide;
91 std::wstring wide;
9292 Util::UTF8ToWide(utf8, &wide);
9393 result->push_back(wide);
9494 }
102102 return true;
103103 }
104104
105 bool ReconvertQuery(const wstring &query,
106 vector<wstring> *result) {
105 bool ReconvertQuery(const std::wstring &query,
106 std::vector<wstring> *result) {
107107 {
108108 string utf8_query;
109109 Util::WideToUTF8(query, &utf8_query);
118118 const auto &candidates = output.all_candidate_words();
119119 for (size_t i = 0; i < candidates.candidates_size(); ++i) {
120120 const auto &utf8 = candidates.candidates(i).value();
121 wstring wide;
121 std::wstring wide;
122122 Util::UTF8ToWide(utf8, &wide);
123123 result->push_back(wide);
124124 }
5151 kDefault,
5252 kReconversion,
5353 };
54 virtual bool Query(const wstring &query,
54 virtual bool Query(const std::wstring &query,
5555 QueryType type,
56 vector<wstring> *result) = 0;
56 std::vector<wstring> *result) = 0;
5757 };
5858
5959 } // namespace tsf
9595 }
9696
9797 HRESULT TipRangeUtil::GetText(
98 ITfRange *range, TfEditCookie edit_cookie, wstring *text) {
98 ITfRange *range, TfEditCookie edit_cookie, std::wstring *text) {
9999 if (range == nullptr) {
100100 return E_INVALIDARG;
101101 }
154154
155155 HRESULT TipRangeUtil::GetInputScopes(ITfRange *range,
156156 TfEditCookie read_cookie,
157 vector<InputScope> *input_scopes) {
157 std::vector<InputScope> *input_scopes) {
158158 if (input_scopes == nullptr) {
159159 return E_FAIL;
160160 }
6060 // Retrieves the text from |range| into |text|.
6161 // Returns the general result code.
6262 static HRESULT GetText(
63 ITfRange *range, TfEditCookie edit_cookie, wstring *text);
63 ITfRange *range, TfEditCookie edit_cookie, std::wstring *text);
6464
6565 // Retrieves the input scopes from |range| into |input_scopes|.
6666 // Returns the general result code.
6767 static HRESULT GetInputScopes(ITfRange *range,
6868 TfEditCookie read_cookie,
69 vector<InputScope> *input_scopes);
69 std::vector<InputScope> *input_scopes);
7070
7171 // Checks whether or not |range_test| becomes a subset of |range_cover|.
7272 static bool IsRangeCovered(TfEditCookie edit_cookie,
7373
7474 private:
7575 // TipCandidateListCallback overrides:
76 virtual void OnFinalize(size_t index, const wstring &candidate) {
76 virtual void OnFinalize(size_t index, const std::wstring &candidate) {
7777 TipEditSession::SetTextAsync(text_service_, candidate, range_);
7878 }
7979
169169 }
170170
171171 if (info.selected_text.find(static_cast<wchar_t>(TS_CHAR_EMBEDDED)) !=
172 wstring::npos) {
172 std::wstring::npos) {
173173 // embedded object is found.
174174 *convertable = FALSE;
175175 *new_range = nullptr;
195195 if (!provider) {
196196 return E_FAIL;
197197 }
198 wstring query;
198 std::wstring query;
199199 if (!TipEditSession::GetTextSync(text_service_, range, &query)) {
200200 return E_FAIL;
201201 }
277277 &halt_cond))) {
278278 return E_FAIL;
279279 }
280 wstring total_string;
280 std::wstring total_string;
281281 if (FAILED(TipRangeUtil::GetText(
282282 preceeding_range, edit_cookie, &total_string))) {
283283 return E_FAIL;
353353 return false;
354354 }
355355
356 wstring preceding_text;
357 wstring preceding_composition;
358 wstring target;
359 wstring following_composition;
360 wstring following_text;
356 std::wstring preceding_text;
357 std::wstring preceding_composition;
358 std::wstring target;
359 std::wstring following_composition;
360 std::wstring following_text;
361361 if (!ReconvertString::Decompose(
362362 reconvert_string, &preceding_text, &preceding_composition, &target,
363363 &following_composition, &following_text)) {
513513 }
514514
515515 bool TipSurroundingTextUtil::MeasureCharactersBackward(
516 const wstring &text,
516 const std::wstring &text,
517517 size_t characters_in_ucs4,
518518 size_t *characters_in_utf16) {
519519 if (characters_in_utf16 == nullptr) {
5050 struct TipSurroundingTextInfo {
5151 TipSurroundingTextInfo();
5252
53 wstring preceding_text;
54 wstring selected_text;
55 wstring following_text;
53 std::wstring preceding_text;
54 std::wstring selected_text;
55 std::wstring following_text;
5656 bool has_preceding_text;
5757 bool has_selected_text;
5858 bool has_following_text;
108108 // Returns true if |text| has more than |characters_in_ucs4| characters.
109109 // When succeeds, the last |*characters_in_utf16| characters in |text|
110110 // can be measured as |characters_in_ucs4| in the unit of UCS4.
111 static bool MeasureCharactersBackward(const wstring &text,
111 static bool MeasureCharactersBackward(const std::wstring &text,
112112 size_t characters_in_ucs4,
113113 size_t *characters_in_utf16);
114114 };
3939 TEST(TipSurroundingTextUtilTest, MeasureCharactersBackward) {
4040 {
4141 const char kSource[] = "abcde";
42 wstring source;
42 std::wstring source;
4343 Util::UTF8ToWide(kSource, &source);
4444 size_t characters_in_utf16 = 0;
4545 EXPECT_TRUE(TipSurroundingTextUtil::MeasureCharactersBackward(
5959 }
6060 {
6161 const char kSource[] = "𠮟咤";
62 wstring source;
62 std::wstring source;
6363 Util::UTF8ToWide(kSource, &source);
6464 size_t characters_in_utf16 = 0;
6565 EXPECT_TRUE(TipSurroundingTextUtil::MeasureCharactersBackward(
338338 if (visible_index >= list.candidates_size()) {
339339 return E_FAIL;
340340 }
341 wstring wide_text;
341 std::wstring wide_text;
342342 Util::UTF8ToWide(list.candidates(visible_index).value(), &wide_text);
343343 *text = CComBSTR(wide_text.size(), wide_text.data()).Detach();
344344 return S_OK;
122122 void CalcLayout(const Candidates &candidates,
123123 const TextRenderer &text_renderer,
124124 TableLayout *table_layout,
125 vector<wstring> *candidate_strings) {
125 std::vector<wstring> *candidate_strings) {
126126 table_layout->Initialize(candidates.candidate_size(), NUMBER_OF_COLUMNS);
127127
128128 table_layout->SetWindowBorder(kWindowBorder);
142142 table_layout->EnsureCellSize(COLUMN_GAP1, gap1_size);
143143
144144 for (size_t i = 0; i < candidates.candidate_size(); ++i) {
145 wstring candidate_string;
145 std::wstring candidate_string;
146146 const Candidate &candidate = candidates.candidate(i);
147147 if (candidate.has_value()) {
148148 mozc::Util::UTF8ToWide(candidate.value(), &candidate_string);
150150 if (candidate.has_annotation()) {
151151 const commands::Annotation &annotation = candidate.annotation();
152152 if (annotation.has_prefix()) {
153 wstring annotation_prefix;
153 std::wstring annotation_prefix;
154154 mozc::Util::UTF8ToWide(annotation.prefix(), &annotation_prefix);
155155 candidate_string = annotation_prefix + candidate_string;
156156 }
157157 if (annotation.has_suffix()) {
158 wstring annotation_suffix;
158 std::wstring annotation_suffix;
159159 mozc::Util::UTF8ToWide(annotation.suffix(), &annotation_suffix);
160160 candidate_string += annotation_suffix;
161161 }
179179 CBitmapHandle RenderImpl(const Candidates &candidates,
180180 const TableLayout &table_layout,
181181 const TextRenderer &text_renderer,
182 const vector<wstring> &candidate_strings) {
182 const std::vector<wstring> &candidate_strings) {
183183 const int width = table_layout.GetTotalSize().width;
184184 const int height = table_layout.GetTotalSize().height;
185185
217217 const TextRenderer::FONT_TYPE font_type =
218218 TextRenderer::FONTSET_CANDIDATE;
219219
220 vector<TextRenderingInfo> display_list;
220 std::vector<TextRenderingInfo> display_list;
221221 for (size_t i = 0; i < candidate_strings.size(); ++i) {
222 const wstring &candidate_string = candidate_strings[i];
222 const std::wstring &candidate_string = candidate_strings[i];
223223 const Rect &text_rect =
224224 table_layout.GetCellRect(i, column_type);
225225 display_list.push_back(TextRenderingInfo(candidate_string, text_rect));
273273 const renderer::win32::TextRenderer *text_renderer,
274274 renderer::TableLayout *table_layout,
275275 SIZE *size, int *left_align_offset) {
276 vector<wstring> candidate_strings;
276 std::vector<wstring> candidate_strings;
277277 CalcLayout(candidates, *text_renderer, table_layout, &candidate_strings);
278278
279279 const Size &total_size = table_layout->GetTotalSize();