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

Side by Side Diff: chrome/browser/extensions/api/terminal/terminal_private_api.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: . 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/browser/extensions/api/terminal/terminal_private_api.h" 5 #include "chrome/browser/extensions/api/terminal/terminal_private_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/process_proxy/process_proxy_registry.h" 10 #include "chrome/browser/chromeos/process_proxy/process_proxy_registry.h"
11 #include "chrome/browser/chromeos/system/runtime_environment.h" 11 #include "chrome/browser/chromeos/system/runtime_environment.h"
12 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h" 12 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
13 #include "chrome/browser/extensions/extension_event_names.h" 13 #include "chrome/browser/extensions/extension_event_names.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 14 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char kCroshName[] = "crosh"; 21 const char kCroshName[] = "crosh";
22 const char kCroshCommand[] = "/usr/bin/crosh"; 22 const char kCroshCommand[] = "/usr/bin/crosh";
23 // We make stubbed crosh just echo back input. 23 // We make stubbed crosh just echo back input.
24 const char kStubbedCroshCommand[] = "cat"; 24 const char kStubbedCroshCommand[] = "cat";
25 25
26 const char kPermissionError[] =
27 "Extension does not have the permission to use this API";
28
29 const char* GetCroshPath() { 26 const char* GetCroshPath() {
30 if (chromeos::system::runtime_environment::IsRunningOnChromeOS()) 27 if (chromeos::system::runtime_environment::IsRunningOnChromeOS())
31 return kCroshCommand; 28 return kCroshCommand;
32 else 29 else
33 return kStubbedCroshCommand; 30 return kStubbedCroshCommand;
34 } 31 }
35 32
36 const char* GetProcessCommandForName(const std::string& name) { 33 const char* GetProcessCommandForName(const std::string& name) {
37 if (name == kCroshName) { 34 if (name == kCroshName) {
38 return GetCroshPath(); 35 return GetCroshPath();
39 } else { 36 } else {
40 return NULL; 37 return NULL;
41 } 38 }
42 } 39 }
43 40
44 void NotifyProcessOutput(Profile* profile, 41 void NotifyProcessOutput(Profile* profile,
45 const std::string& extension_id, 42 const std::string& extension_id,
46 pid_t pid, 43 pid_t pid,
47 const std::string& output_type, 44 const std::string& output_type,
48 const std::string& output) { 45 const std::string& output) {
49 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { 46 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
50 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 47 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
51 base::Bind(&NotifyProcessOutput, profile, extension_id, 48 base::Bind(&NotifyProcessOutput, profile, extension_id,
52 pid, output_type, output)); 49 pid, output_type, output));
53 return; 50 return;
54 } 51 }
55 52
56 CHECK(TerminalExtensionHelper::AllowAccessToExtension(profile, extension_id));
57
58 base::ListValue args; 53 base::ListValue args;
59 args.Append(new base::FundamentalValue(pid)); 54 args.Append(new base::FundamentalValue(pid));
60 args.Append(new base::StringValue(output_type)); 55 args.Append(new base::StringValue(output_type));
61 args.Append(new base::StringValue(output)); 56 args.Append(new base::StringValue(output));
62 57
63 std::string args_json; 58 std::string args_json;
64 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 59 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
65 60
66 if (profile && profile->GetExtensionEventRouter()) { 61 if (profile && profile->GetExtensionEventRouter()) {
67 profile->GetExtensionEventRouter()->DispatchEventToExtension( 62 profile->GetExtensionEventRouter()->DispatchEventToExtension(
68 extension_id, extension_event_names::kOnTerminalProcessOutput, 63 extension_id, extension_event_names::kOnTerminalProcessOutput,
69 args_json, NULL, GURL()); 64 args_json, NULL, GURL());
70 } 65 }
71 } 66 }
72 67
73 } // namespace 68 } // namespace
74 69
75 TerminalPrivateFunction::TerminalPrivateFunction() { 70 TerminalPrivateFunction::TerminalPrivateFunction() {
76 } 71 }
77 72
78 TerminalPrivateFunction::~TerminalPrivateFunction() { 73 TerminalPrivateFunction::~TerminalPrivateFunction() {
79 } 74 }
80 75
81 bool TerminalPrivateFunction::RunImpl() { 76 bool TerminalPrivateFunction::RunImpl() {
82 if (!TerminalExtensionHelper::AllowAccessToExtension(profile_,
83 extension_id())) {
84 error_ = kPermissionError;
85 return false;
86 }
87
88 return RunTerminalFunction(); 77 return RunTerminalFunction();
89 } 78 }
90 79
91 OpenTerminalProcessFunction::OpenTerminalProcessFunction() : command_(NULL) { 80 OpenTerminalProcessFunction::OpenTerminalProcessFunction() : command_(NULL) {
92 } 81 }
93 82
94 OpenTerminalProcessFunction::~OpenTerminalProcessFunction() { 83 OpenTerminalProcessFunction::~OpenTerminalProcessFunction() {
95 } 84 }
96 85
97 bool OpenTerminalProcessFunction::RunTerminalFunction() { 86 bool OpenTerminalProcessFunction::RunTerminalFunction() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 172
184 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 173 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
185 base::Bind(&CloseTerminalProcessFunction::RespondOnUIThread, this, 174 base::Bind(&CloseTerminalProcessFunction::RespondOnUIThread, this,
186 success)); 175 success));
187 } 176 }
188 177
189 void CloseTerminalProcessFunction::RespondOnUIThread(bool success) { 178 void CloseTerminalProcessFunction::RespondOnUIThread(bool success) {
190 result_.reset(new base::FundamentalValue(success)); 179 result_.reset(new base::FundamentalValue(success));
191 SendResponse(true); 180 SendResponse(true);
192 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698