Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: extensions/renderer/bindings/api_binding.cc

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: jbroman's Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/renderer/bindings/api_binding_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 12 matching lines...) Expand all
23 #include "extensions/renderer/bindings/declarative_event.h" 23 #include "extensions/renderer/bindings/declarative_event.h"
24 #include "gin/arguments.h" 24 #include "gin/arguments.h"
25 #include "gin/handle.h" 25 #include "gin/handle.h"
26 #include "gin/per_context_data.h" 26 #include "gin/per_context_data.h"
27 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 27 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
28 28
29 namespace extensions { 29 namespace extensions {
30 30
31 namespace { 31 namespace {
32 32
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
33 // Returns the name of the enum value for use in JavaScript; JS enum entries use 48 // Returns the name of the enum value for use in JavaScript; JS enum entries use
34 // SCREAMING_STYLE. 49 // SCREAMING_STYLE.
35 std::string GetJSEnumEntryName(const std::string& original) { 50 std::string GetJSEnumEntryName(const std::string& original) {
36 // The webstorePrivate API has an empty enum value for a result. 51 // The webstorePrivate API has an empty enum value for a result.
37 // TODO(devlin): Work with the webstore team to see if we can move them off 52 // TODO(devlin): Work with the webstore team to see if we can move them off
38 // this - they also already have a "success" result that they can use. 53 // this - they also already have a "success" result that they can use.
39 // See crbug.com/709120. 54 // See crbug.com/709120.
40 if (original.empty()) 55 if (original.empty())
41 return original; 56 return original;
42 57
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 const base::DictionaryValue* dict = nullptr; 436 const base::DictionaryValue* dict = nullptr;
422 CHECK(iter.value().GetAsDictionary(&dict)); 437 CHECK(iter.value().GetAsDictionary(&dict));
423 bool optional = false; 438 bool optional = false;
424 if (dict->GetBoolean("optional", &optional)) { 439 if (dict->GetBoolean("optional", &optional)) {
425 // TODO(devlin): What does optional even mean here? It's only used, it 440 // TODO(devlin): What does optional even mean here? It's only used, it
426 // seems, for lastError and inIncognitoContext, which are both handled 441 // seems, for lastError and inIncognitoContext, which are both handled
427 // with custom bindings. Investigate, and remove. 442 // with custom bindings. Investigate, and remove.
428 continue; 443 continue;
429 } 444 }
430 445
446 const base::ListValue* platforms = nullptr;
447 // 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
449 // API specification itself. Additionally, they aren't equivalent
450 // 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
452 // this check here. If this becomes more common, we should really find a
453 // way of moving these checks to the features files.
454 if (dict->GetList("platforms", &platforms)) {
455 std::string this_platform = GetPlatformString();
456 auto is_this_platform = [&this_platform](const base::Value& platform) {
457 return platform.is_string() && platform.GetString() == this_platform;
458 };
459 if (std::none_of(platforms->begin(), platforms->end(), is_this_platform))
460 continue;
461 }
462
431 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key()); 463 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key());
432 std::string ref; 464 std::string ref;
433 if (dict->GetString("$ref", &ref)) { 465 if (dict->GetString("$ref", &ref)) {
434 const base::ListValue* property_values = nullptr; 466 const base::ListValue* property_values = nullptr;
435 CHECK(dict->GetList("value", &property_values)); 467 CHECK(dict->GetList("value", &property_values));
436 auto property_data = base::MakeUnique<CustomPropertyData>( 468 auto property_data = base::MakeUnique<CustomPropertyData>(
437 ref, iter.key(), property_values, create_custom_type_); 469 ref, iter.key(), property_values, create_custom_type_);
438 object_template->SetLazyDataProperty( 470 object_template->SetLazyDataProperty(
439 v8_key, &APIBinding::GetCustomPropertyObject, 471 v8_key, &APIBinding::GetCustomPropertyObject,
440 v8::External::New(isolate, property_data.get())); 472 v8::External::New(isolate, property_data.get()));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 arguments->ThrowTypeError(api_errors::InvocationError( 654 arguments->ThrowTypeError(api_errors::InvocationError(
623 name, signature->GetExpectedSignature(), error)); 655 name, signature->GetExpectedSignature(), error));
624 return; 656 return;
625 } 657 }
626 658
627 request_handler_->StartRequest(context, name, std::move(converted_arguments), 659 request_handler_->StartRequest(context, name, std::move(converted_arguments),
628 callback, custom_callback, thread); 660 callback, custom_callback, thread);
629 } 661 }
630 662
631 } // namespace extensions 663 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/bindings/api_binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698