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

Side by Side Diff: chrome/renderer/extensions/chrome_private_custom_bindings.cc

Issue 9317013: Add a centralized mechanism for whitelisting access to extension permissions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix a couple tests Created 8 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/chrome_private_custom_bindings.h" 5 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 : ChromeV8Extension( 24 : ChromeV8Extension(
25 "extensions/chrome_private_custom_bindings.js", 25 "extensions/chrome_private_custom_bindings.js",
26 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS, 26 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS,
27 dependency_count, 27 dependency_count,
28 dependencies, 28 dependencies,
29 extension_dispatcher) {} 29 extension_dispatcher) {}
30 30
31 // static 31 // static
32 v8::Handle<v8::Value> ChromePrivateCustomBindings::DecodeJPEG( 32 v8::Handle<v8::Value> ChromePrivateCustomBindings::DecodeJPEG(
33 const v8::Arguments& args) { 33 const v8::Arguments& args) {
34 static const char* kAllowedIds[] = {
35 "haiffjcadagjlijoggckpgfnoeiflnem",
36 "gnedhmakppccajfpfiihfcdlnpgomkcf",
37 "fjcibdnjlbfnbfdjneajpipnlcppleek",
38 "oflbaaikkabfdfkimeclgkackhdkpnip" // Testing extension.
39 };
40 const std::vector<std::string> allowed_ids(
41 kAllowedIds, kAllowedIds + arraysize(kAllowedIds));
42
43 ChromePrivateCustomBindings* v8_extension = 34 ChromePrivateCustomBindings* v8_extension =
44 GetFromArguments<ChromePrivateCustomBindings>(args); 35 GetFromArguments<ChromePrivateCustomBindings>(args);
45 const ::Extension* extension = 36 const ::Extension* extension =
46 v8_extension->GetExtensionForCurrentRenderView(); 37 v8_extension->GetExtensionForCurrentRenderView();
47 if (!extension) 38 if (!extension)
48 return v8::Undefined(); 39 return v8::Undefined();
49 if (allowed_ids.end() == std::find(
50 allowed_ids.begin(), allowed_ids.end(), extension->id())) {
51 return v8::Undefined();
52 }
53 40
54 DCHECK(args.Length() == 1); 41 DCHECK(args.Length() == 1);
55 DCHECK(args[0]->IsArray()); 42 DCHECK(args[0]->IsArray());
56 v8::Local<v8::Object> jpeg_array = args[0]->ToObject(); 43 v8::Local<v8::Object> jpeg_array = args[0]->ToObject();
57 size_t jpeg_length = 44 size_t jpeg_length =
58 jpeg_array->Get(v8::String::New("length"))->Int32Value(); 45 jpeg_array->Get(v8::String::New("length"))->Int32Value();
59 46
60 // Put input JPEG array into string for DecodeImage(). 47 // Put input JPEG array into string for DecodeImage().
61 std::string jpeg_array_string; 48 std::string jpeg_array_string;
62 jpeg_array_string.reserve(jpeg_length); 49 jpeg_array_string.reserve(jpeg_length);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 89
103 v8::Handle<v8::FunctionTemplate> ChromePrivateCustomBindings::GetNativeFunction( 90 v8::Handle<v8::FunctionTemplate> ChromePrivateCustomBindings::GetNativeFunction(
104 v8::Handle<v8::String> name) { 91 v8::Handle<v8::String> name) {
105 if (name->Equals(v8::String::New("DecodeJPEG"))) 92 if (name->Equals(v8::String::New("DecodeJPEG")))
106 return v8::FunctionTemplate::New(DecodeJPEG, v8::External::New(this)); 93 return v8::FunctionTemplate::New(DecodeJPEG, v8::External::New(this));
107 94
108 return ChromeV8Extension::GetNativeFunction(name); 95 return ChromeV8Extension::GetNativeFunction(name);
109 } 96 }
110 97
111 } // namespace extensions 98 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698