Chromium Code Reviews| Index: content/public/common/resource_type_enum_traits.cc |
| diff --git a/content/public/common/resource_type_enum_traits.cc b/content/public/common/resource_type_enum_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cb3fc2cc054ee32330717af18d818f1bbd69969e |
| --- /dev/null |
| +++ b/content/public/common/resource_type_enum_traits.cc |
| @@ -0,0 +1,124 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/public/common/resource_type_enum_traits.h" |
| + |
| +namespace mojo { |
| + |
| +// static |
| +content::mojom::ResourceType |
| +EnumTraits<content::mojom::ResourceType, content::ResourceType>::ToMojom( |
| + content::ResourceType input) { |
| + switch (input) { |
| + case content::RESOURCE_TYPE_MAIN_FRAME: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_MAIN_FRAME; |
|
vakh (use Gerrit instead)
2017/05/31 23:53:09
This is fairly mechanical. Is it possible to use s
yzshen1
2017/06/01 17:45:04
Yeah. It is tedious.
But static_cast won't warn us
|
| + case content::RESOURCE_TYPE_SUB_FRAME: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_SUB_FRAME; |
| + case content::RESOURCE_TYPE_STYLESHEET: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_STYLESHEET; |
| + case content::RESOURCE_TYPE_SCRIPT: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_SCRIPT; |
| + case content::RESOURCE_TYPE_IMAGE: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_IMAGE; |
| + case content::RESOURCE_TYPE_FONT_RESOURCE: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_FONT_RESOURCE; |
| + case content::RESOURCE_TYPE_SUB_RESOURCE: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_SUB_RESOURCE; |
| + case content::RESOURCE_TYPE_OBJECT: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_OBJECT; |
| + case content::RESOURCE_TYPE_MEDIA: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_MEDIA; |
| + case content::RESOURCE_TYPE_WORKER: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_WORKER; |
| + case content::RESOURCE_TYPE_SHARED_WORKER: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_SHARED_WORKER; |
| + case content::RESOURCE_TYPE_PREFETCH: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_PREFETCH; |
| + case content::RESOURCE_TYPE_FAVICON: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_FAVICON; |
| + case content::RESOURCE_TYPE_XHR: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_XHR; |
| + case content::RESOURCE_TYPE_PING: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_PING; |
| + case content::RESOURCE_TYPE_SERVICE_WORKER: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_SERVICE_WORKER; |
| + case content::RESOURCE_TYPE_CSP_REPORT: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_CSP_REPORT; |
| + case content::RESOURCE_TYPE_PLUGIN_RESOURCE: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_PLUGIN_RESOURCE; |
| + case content::RESOURCE_TYPE_LAST_TYPE: |
| + return content::mojom::ResourceType::RESOURCE_TYPE_LAST_TYPE; |
| + } |
| + |
| + NOTREACHED(); |
| + return content::mojom::ResourceType::RESOURCE_TYPE_MAIN_FRAME; |
| +} |
| +// static |
| +bool EnumTraits<content::mojom::ResourceType, content::ResourceType>::FromMojom( |
| + |
| + content::mojom::ResourceType input, |
| + content::ResourceType* output) { |
| + switch (input) { |
| + case content::mojom::ResourceType::RESOURCE_TYPE_MAIN_FRAME: |
|
vakh (use Gerrit instead)
2017/05/31 23:53:09
Same here
yzshen1
2017/06/01 17:45:04
Please see my reply above.
|
| + *output = content::RESOURCE_TYPE_MAIN_FRAME; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_SUB_FRAME: |
| + *output = content::RESOURCE_TYPE_SUB_FRAME; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_STYLESHEET: |
| + *output = content::RESOURCE_TYPE_STYLESHEET; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_SCRIPT: |
| + *output = content::RESOURCE_TYPE_SCRIPT; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_IMAGE: |
| + *output = content::RESOURCE_TYPE_IMAGE; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_FONT_RESOURCE: |
| + *output = content::RESOURCE_TYPE_FONT_RESOURCE; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_SUB_RESOURCE: |
| + *output = content::RESOURCE_TYPE_SUB_RESOURCE; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_OBJECT: |
| + *output = content::RESOURCE_TYPE_OBJECT; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_MEDIA: |
| + *output = content::RESOURCE_TYPE_MEDIA; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_WORKER: |
| + *output = content::RESOURCE_TYPE_WORKER; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_SHARED_WORKER: |
| + *output = content::RESOURCE_TYPE_SHARED_WORKER; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_PREFETCH: |
| + *output = content::RESOURCE_TYPE_PREFETCH; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_FAVICON: |
| + *output = content::RESOURCE_TYPE_FAVICON; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_XHR: |
| + *output = content::RESOURCE_TYPE_XHR; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_PING: |
| + *output = content::RESOURCE_TYPE_PING; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_SERVICE_WORKER: |
| + *output = content::RESOURCE_TYPE_SERVICE_WORKER; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_CSP_REPORT: |
| + *output = content::RESOURCE_TYPE_CSP_REPORT; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_PLUGIN_RESOURCE: |
| + *output = content::RESOURCE_TYPE_PLUGIN_RESOURCE; |
| + return true; |
| + case content::mojom::ResourceType::RESOURCE_TYPE_LAST_TYPE: |
| + *output = content::RESOURCE_TYPE_LAST_TYPE; |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +} // namespace mojo |