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

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

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: fix ifdef 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
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";
jbroman 2017/06/29 15:24:21 I assume you'll look into what's up with protected
Devlin 2017/06/29 21:00:51 Yep! This just puts it more inline with the end r
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 platform_string = GetPlatformString();
456 bool allowed = false;
457 for (const auto& platform : *platforms) {
jbroman 2017/06/29 15:24:20 super-nit: your choice, but I mildly prefer <algor
Devlin 2017/06/29 21:00:51 Oh, forgot about none_of. I had a version that us
458 if (platform.is_string() && platform.GetString() == platform_string) {
459 allowed = true;
460 break;
461 }
462 }
463
464 if (!allowed)
465 continue;
466 }
467
431 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key()); 468 v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key());
432 std::string ref; 469 std::string ref;
433 if (dict->GetString("$ref", &ref)) { 470 if (dict->GetString("$ref", &ref)) {
434 const base::ListValue* property_values = nullptr; 471 const base::ListValue* property_values = nullptr;
435 CHECK(dict->GetList("value", &property_values)); 472 CHECK(dict->GetList("value", &property_values));
436 auto property_data = base::MakeUnique<CustomPropertyData>( 473 auto property_data = base::MakeUnique<CustomPropertyData>(
437 ref, iter.key(), property_values, create_custom_type_); 474 ref, iter.key(), property_values, create_custom_type_);
438 object_template->SetLazyDataProperty( 475 object_template->SetLazyDataProperty(
439 v8_key, &APIBinding::GetCustomPropertyObject, 476 v8_key, &APIBinding::GetCustomPropertyObject,
440 v8::External::New(isolate, property_data.get())); 477 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( 659 arguments->ThrowTypeError(api_errors::InvocationError(
623 name, signature->GetExpectedSignature(), error)); 660 name, signature->GetExpectedSignature(), error));
624 return; 661 return;
625 } 662 }
626 663
627 request_handler_->StartRequest(context, name, std::move(converted_arguments), 664 request_handler_->StartRequest(context, name, std::move(converted_arguments),
628 callback, custom_callback, thread); 665 callback, custom_callback, thread);
629 } 666 }
630 667
631 } // namespace extensions 668 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698