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

Side by Side Diff: chrome/browser/extensions/api/terminal/terminal_private_api.cc

Issue 9297008: [HTerm-Crosh] Add key shortcut for opening Crosh on ChromeOS Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 | Annotate | Revision Log
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/extension_event_names.h" 13 #include "chrome/browser/extensions/extension_event_names.h"
13 #include "chrome/browser/extensions/extension_event_router.h" 14 #include "chrome/browser/extensions/extension_event_router.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 18
18 namespace { 19 namespace {
19 20
20 const char kCroshName[] = "crosh"; 21 const char kCroshName[] = "crosh";
21 const char kCroshCommand[] = "/usr/bin/crosh"; 22 const char kCroshCommand[] = "/usr/bin/crosh";
22 // We make stubbed crosh just echo back input. 23 // We make stubbed crosh just echo back input.
23 const char kStubbedCroshCommand[] = "cat"; 24 const char kStubbedCroshCommand[] = "cat";
24 25
25 const char kPermissionError[] = 26 const char kPermissionError[] =
26 "Extension does not have the permission to use this API"; 27 "Extension does not have the permission to use this API";
27 28
28 const char* kAllowedExtensionIds[] ={
29 "okddffdblfhhnmhodogpojmfkjmhinfp", // test SSH/Crosh Client
30 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App
31 };
32
33 // Allow component and whitelisted extensions.
34 bool AllowAccessToExtension(Profile* profile, const std::string& extension_id) {
35 ExtensionService* service = profile->GetExtensionService();
36 const Extension* extension = service->GetExtensionById(extension_id, false);
37
38 if (!extension)
39 return false;
40
41 if (extension->location() == Extension::COMPONENT)
42 return true;
43
44 for (size_t i = 0; i < arraysize(kAllowedExtensionIds); i++) {
45 if (extension->id() == kAllowedExtensionIds[i])
46 return true;
47 }
48 return false;
49 }
50
51 const char* GetCroshPath() { 29 const char* GetCroshPath() {
52 if (chromeos::system::runtime_environment::IsRunningOnChromeOS()) 30 if (chromeos::system::runtime_environment::IsRunningOnChromeOS())
53 return kCroshCommand; 31 return kCroshCommand;
54 else 32 else
55 return kStubbedCroshCommand; 33 return kStubbedCroshCommand;
56 } 34 }
57 35
58 const char* GetProcessCommandForName(const std::string& name) { 36 const char* GetProcessCommandForName(const std::string& name) {
59 if (name == kCroshName) { 37 if (name == kCroshName) {
60 return GetCroshPath(); 38 return GetCroshPath();
61 } else { 39 } else {
62 return NULL; 40 return NULL;
63 } 41 }
64 } 42 }
65 43
66 void NotifyProcessOutput(Profile* profile, 44 void NotifyProcessOutput(Profile* profile,
67 const std::string& extension_id, 45 const std::string& extension_id,
68 pid_t pid, 46 pid_t pid,
69 const std::string& output_type, 47 const std::string& output_type,
70 const std::string& output) { 48 const std::string& output) {
71 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { 49 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
72 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 50 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
73 base::Bind(&NotifyProcessOutput, profile, extension_id, 51 base::Bind(&NotifyProcessOutput, profile, extension_id,
74 pid, output_type, output)); 52 pid, output_type, output));
75 return; 53 return;
76 } 54 }
77 55
78 CHECK(AllowAccessToExtension(profile, extension_id)); 56 CHECK(TerminalExtensionHelper::AllowAccessToExtension(profile, extension_id));
79 57
80 base::ListValue args; 58 base::ListValue args;
81 args.Append(new base::FundamentalValue(pid)); 59 args.Append(new base::FundamentalValue(pid));
82 args.Append(new base::StringValue(output_type)); 60 args.Append(new base::StringValue(output_type));
83 args.Append(new base::StringValue(output)); 61 args.Append(new base::StringValue(output));
84 62
85 std::string args_json; 63 std::string args_json;
86 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 64 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
87 65
88 if (profile && profile->GetExtensionEventRouter()) { 66 if (profile && profile->GetExtensionEventRouter()) {
89 profile->GetExtensionEventRouter()->DispatchEventToExtension( 67 profile->GetExtensionEventRouter()->DispatchEventToExtension(
90 extension_id, extension_event_names::kOnTerminalProcessOutput, 68 extension_id, extension_event_names::kOnTerminalProcessOutput,
91 args_json, NULL, GURL()); 69 args_json, NULL, GURL());
92 } 70 }
93 } 71 }
94 72
95 } // namespace 73 } // namespace
96 74
97 TerminalPrivateFunction::TerminalPrivateFunction() { 75 TerminalPrivateFunction::TerminalPrivateFunction() {
98 } 76 }
99 77
100 TerminalPrivateFunction::~TerminalPrivateFunction() { 78 TerminalPrivateFunction::~TerminalPrivateFunction() {
101 } 79 }
102 80
103 bool TerminalPrivateFunction::RunImpl() { 81 bool TerminalPrivateFunction::RunImpl() {
104 if (!AllowAccessToExtension(profile_, extension_id())) { 82 if (!TerminalExtensionHelper::AllowAccessToExtension(profile_,
83 extension_id())) {
105 error_ = kPermissionError; 84 error_ = kPermissionError;
106 return false; 85 return false;
107 } 86 }
108 87
109 return RunTerminalFunction(); 88 return RunTerminalFunction();
110 } 89 }
111 90
112 OpenTerminalProcessFunction::OpenTerminalProcessFunction() : command_(NULL) { 91 OpenTerminalProcessFunction::OpenTerminalProcessFunction() : command_(NULL) {
113 } 92 }
114 93
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 183
205 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 184 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
206 base::Bind(&CloseTerminalProcessFunction::RespondOnUIThread, this, 185 base::Bind(&CloseTerminalProcessFunction::RespondOnUIThread, this,
207 success)); 186 success));
208 } 187 }
209 188
210 void CloseTerminalProcessFunction::RespondOnUIThread(bool success) { 189 void CloseTerminalProcessFunction::RespondOnUIThread(bool success) {
211 result_.reset(new base::FundamentalValue(success)); 190 result_.reset(new base::FundamentalValue(success));
212 SendResponse(true); 191 SendResponse(true);
213 } 192 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/terminal/terminal_extension_helper.cc ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698