1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/runtime/browser/ui/taskbar_util.h"
8 #include "base/command_line.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/public/common/content_switches.h"
13 #include "crypto/sha2.h"
17 #include <shobjidl.h> // NOLINT(build/include_order)
22 const size_t kIdSize = 16;
24 // Converts a normal hexadecimal string into the alphabet.
25 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a
26 // completely numeric host, since some software interprets that as an IP
28 void ConvertHexadecimalToIDAlphabet(std::string* id) {
29 for (size_t i = 0; i < id->size(); ++i) {
31 if (base::HexStringToInt(base::StringPiece(id->begin() + i,
41 // Generates an ID from arbitrary input. The same input string will
42 // always generate the same output ID.
43 void GenerateId(const std::string& input, std::string* output) {
46 crypto::SHA256HashString(input, hash, sizeof(hash));
47 *output = base::StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
48 ConvertHexadecimalToIDAlphabet(output);
51 void SetTaskbarGroupIdForProcess() {
52 CommandLine* command_line = CommandLine::ForCurrentProcess();
53 const CommandLine::StringVector& args = command_line->GetArgs();
59 if (url.is_valid() && url.has_scheme()) {
61 GenerateId(url.spec(), &appid);
62 ::SetCurrentProcessExplicitAppUserModelID(base::ASCIIToWide(appid).c_str());