OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/renderer/bindings/api_binding.h" | 5 #include "extensions/renderer/bindings/api_binding.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "extensions/renderer/bindings/api_binding_hooks.h" | 15 #include "extensions/renderer/bindings/api_binding_hooks.h" |
16 #include "extensions/renderer/bindings/api_binding_types.h" | 16 #include "extensions/renderer/bindings/api_binding_types.h" |
| 17 #include "extensions/renderer/bindings/api_binding_util.h" |
17 #include "extensions/renderer/bindings/api_event_handler.h" | 18 #include "extensions/renderer/bindings/api_event_handler.h" |
18 #include "extensions/renderer/bindings/api_invocation_errors.h" | 19 #include "extensions/renderer/bindings/api_invocation_errors.h" |
19 #include "extensions/renderer/bindings/api_request_handler.h" | 20 #include "extensions/renderer/bindings/api_request_handler.h" |
20 #include "extensions/renderer/bindings/api_signature.h" | 21 #include "extensions/renderer/bindings/api_signature.h" |
21 #include "extensions/renderer/bindings/api_type_reference_map.h" | 22 #include "extensions/renderer/bindings/api_type_reference_map.h" |
22 #include "extensions/renderer/bindings/binding_access_checker.h" | 23 #include "extensions/renderer/bindings/binding_access_checker.h" |
23 #include "extensions/renderer/bindings/declarative_event.h" | 24 #include "extensions/renderer/bindings/declarative_event.h" |
24 #include "gin/arguments.h" | 25 #include "gin/arguments.h" |
25 #include "gin/handle.h" | 26 #include "gin/handle.h" |
26 #include "gin/per_context_data.h" | 27 #include "gin/per_context_data.h" |
27 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 28 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 std::string GetPlatformString() { | |
34 #if defined(OS_CHROMEOS) | |
35 return "chromeos"; | |
36 #elif defined(OS_LINUX) | |
37 return "linux"; | |
38 #elif defined(OS_MACOSX) | |
39 return "mac"; | |
40 #elif defined(OS_WIN) | |
41 return "win"; | |
42 #else | |
43 NOTREACHED(); | |
44 return std::string(); | |
45 #endif | |
46 } | |
47 | |
48 // Returns the name of the enum value for use in JavaScript; JS enum entries use | 34 // Returns the name of the enum value for use in JavaScript; JS enum entries use |
49 // SCREAMING_STYLE. | 35 // SCREAMING_STYLE. |
50 std::string GetJSEnumEntryName(const std::string& original) { | 36 std::string GetJSEnumEntryName(const std::string& original) { |
51 // The webstorePrivate API has an empty enum value for a result. | 37 // The webstorePrivate API has an empty enum value for a result. |
52 // TODO(devlin): Work with the webstore team to see if we can move them off | 38 // TODO(devlin): Work with the webstore team to see if we can move them off |
53 // this - they also already have a "success" result that they can use. | 39 // this - they also already have a "success" result that they can use. |
54 // See crbug.com/709120. | 40 // See crbug.com/709120. |
55 if (original.empty()) | 41 if (original.empty()) |
56 return original; | 42 return original; |
57 | 43 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 431 |
446 const base::ListValue* platforms = nullptr; | 432 const base::ListValue* platforms = nullptr; |
447 // TODO(devlin): This isn't great. It's bad to have availability primarily | 433 // TODO(devlin): This isn't great. It's bad to have availability primarily |
448 // defined in the features files, and then partially defined within the | 434 // defined in the features files, and then partially defined within the |
449 // API specification itself. Additionally, they aren't equivalent | 435 // API specification itself. Additionally, they aren't equivalent |
450 // definitions. But given the rarity of property restrictions, and the fact | 436 // definitions. But given the rarity of property restrictions, and the fact |
451 // that they are all limited by platform, it makes more sense to isolate | 437 // that they are all limited by platform, it makes more sense to isolate |
452 // this check here. If this becomes more common, we should really find a | 438 // this check here. If this becomes more common, we should really find a |
453 // way of moving these checks to the features files. | 439 // way of moving these checks to the features files. |
454 if (dict->GetList("platforms", &platforms)) { | 440 if (dict->GetList("platforms", &platforms)) { |
455 std::string this_platform = GetPlatformString(); | 441 std::string this_platform = binding::GetPlatformString(); |
456 auto is_this_platform = [&this_platform](const base::Value& platform) { | 442 auto is_this_platform = [&this_platform](const base::Value& platform) { |
457 return platform.is_string() && platform.GetString() == this_platform; | 443 return platform.is_string() && platform.GetString() == this_platform; |
458 }; | 444 }; |
459 if (std::none_of(platforms->begin(), platforms->end(), is_this_platform)) | 445 if (std::none_of(platforms->begin(), platforms->end(), is_this_platform)) |
460 continue; | 446 continue; |
461 } | 447 } |
462 | 448 |
463 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key()); | 449 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key()); |
464 std::string ref; | 450 std::string ref; |
465 if (dict->GetString("$ref", &ref)) { | 451 if (dict->GetString("$ref", &ref)) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 arguments->ThrowTypeError(api_errors::InvocationError( | 640 arguments->ThrowTypeError(api_errors::InvocationError( |
655 name, signature->GetExpectedSignature(), error)); | 641 name, signature->GetExpectedSignature(), error)); |
656 return; | 642 return; |
657 } | 643 } |
658 | 644 |
659 request_handler_->StartRequest(context, name, std::move(converted_arguments), | 645 request_handler_->StartRequest(context, name, std::move(converted_arguments), |
660 callback, custom_callback, thread); | 646 callback, custom_callback, thread); |
661 } | 647 } |
662 | 648 |
663 } // namespace extensions | 649 } // namespace extensions |
OLD | NEW |