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

Side by Side Diff: extensions/shell/browser/shell_nacl_browser_delegate.cc

Issue 437503004: Add NaCl support to app_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (nacl-init) cleanup Created 6 years, 4 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/shell/browser/shell_nacl_browser_delegate.h"
6
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/path_service.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/site_instance.h"
16 #include "content/shell/common/shell_switches.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/info_map.h"
19 #include "extensions/browser/process_manager.h"
20 #include "extensions/common/constants.h"
21 #include "extensions/common/extension.h"
22 #include "extensions/common/url_pattern.h"
23 #include "ppapi/c/private/ppb_nacl_private.h"
24 #include "url/gurl.h"
25
26 using content::BrowserContext;
27 using content::BrowserThread;
28 using content::BrowserPpapiHost;
29
30 namespace extensions {
31 namespace {
32
33 // Handles an extension's NaCl process transitioning in or out of idle state by
34 // relaying the state to the extension's process manager. See Chrome's
35 // NaClBrowserDelegateImpl for another example.
36 void OnKeepaliveOnUIThread(
37 const BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
38 const base::FilePath& profile_data_directory) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40
41 // Only one instance will exist for NaCl embeds, even when more than one
42 // embed of the same plugin exists on the same page.
43 DCHECK(instance_data.size() == 1);
44 if (instance_data.size() < 1)
45 return;
46
47 ProcessManager::OnKeepaliveFromPlugin(instance_data[0].render_process_id,
48 instance_data[0].render_frame_id,
49 instance_data[0].document_url.host());
50 }
51
52 // Calls OnKeepaliveOnUIThread on UI thread.
53 void OnKeepalive(const BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
54 const base::FilePath& profile_data_directory) {
55 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
56 BrowserThread::PostTask(
57 BrowserThread::UI,
58 FROM_HERE,
59 base::Bind(
60 &OnKeepaliveOnUIThread, instance_data, profile_data_directory));
61 }
62
63 } // namespace
64
65 ShellNaClBrowserDelegate::ShellNaClBrowserDelegate(BrowserContext* context)
66 : browser_context_(context) {
67 DCHECK(browser_context_);
68 }
69
70 ShellNaClBrowserDelegate::~ShellNaClBrowserDelegate() {
71 }
72
73 void ShellNaClBrowserDelegate::ShowMissingArchInfobar(int render_process_id,
74 int render_view_id) {
75 // app_shell does not have infobars.
76 LOG(ERROR) << "Missing architecture for pid " << render_process_id;
77 }
78
79 bool ShellNaClBrowserDelegate::DialogsAreSuppressed() {
80 return false;
81 }
82
83 bool ShellNaClBrowserDelegate::GetCacheDirectory(base::FilePath* cache_dir) {
84 // Just use the general cache directory, not a subdirectory like Chrome does.
85 return PathService::Get(base::DIR_CACHE, cache_dir);
86 }
87
88 bool ShellNaClBrowserDelegate::GetPluginDirectory(base::FilePath* plugin_dir) {
89 // On Posix, plugins are in the module directory.
90 return PathService::Get(base::DIR_MODULE, plugin_dir);
91 }
92
93 bool ShellNaClBrowserDelegate::GetPnaclDirectory(base::FilePath* pnacl_dir) {
94 // On Posix, the pnacl directory is inside the plugin directory.
95 base::FilePath plugin_dir;
96 if (!GetPluginDirectory(&plugin_dir))
97 return false;
98 *pnacl_dir = plugin_dir.Append(FILE_PATH_LITERAL("pnacl"));
99 return true;
100 }
101
102 bool ShellNaClBrowserDelegate::GetUserDirectory(base::FilePath* user_dir) {
103 base::FilePath path;
104 // app_shell on real Chrome OS devices will have --data-path set to the user
105 // directory.
106 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
107 if (cmd->HasSwitch(switches::kContentShellDataPath)) {
108 path = cmd->GetSwitchValuePath(switches::kContentShellDataPath);
109 return true;
110 }
111 // Otherwise just use a temporary directory.
112 return PathService::Get(base::DIR_TEMP, user_dir);
113 }
114
115 std::string ShellNaClBrowserDelegate::GetVersionString() const {
116 // Used to trigger update of the validation caches.
117 // TODO(jamescook): Generate a real version number and use it both here and
118 // in our user agent. http://crbug.com/402612
119 return "1.2.3.4";
120 }
121
122 ppapi::host::HostFactory* ShellNaClBrowserDelegate::CreatePpapiHostFactory(
123 content::BrowserPpapiHost* ppapi_host) {
124 return NULL;
125 }
126
127 void ShellNaClBrowserDelegate::SetDebugPatterns(std::string debug_patterns) {
128 // No debugger support. Developers should use Chrome for debugging.
129 }
130
131 bool ShellNaClBrowserDelegate::URLMatchesDebugPatterns(
132 const GURL& manifest_url) {
133 // No debugger support. Developers should use Chrome for debugging.
134 return false;
135 }
136
137 // This function is security sensitive. Be sure to check with a security
138 // person before you modify it.
139 bool ShellNaClBrowserDelegate::MapUrlToLocalFilePath(
teravest 2014/08/12 19:57:12 It'd be nice if this code could be shared with NaC
James Cook 2014/08/12 20:20:45 I'll file a bug for it, leave a TODO, and do it in
140 const GURL& file_url,
141 bool use_blocking_api,
142 const base::FilePath& profile_directory,
143 base::FilePath* file_path) {
144 scoped_refptr<InfoMap> info_map =
145 ExtensionSystem::Get(browser_context_)->info_map();
146 // Check that the URL is recognized by the extension system.
147 const Extension* extension =
148 info_map->extensions().GetExtensionOrAppByURL(file_url);
149 if (!extension)
150 return false;
151
152 // This is a short-cut which avoids calling a blocking file operation
153 // (GetFilePath()), so that this can be called on the IO thread. It only
154 // handles a subset of the urls.
155 if (!use_blocking_api) {
156 if (file_url.SchemeIs(kExtensionScheme)) {
157 std::string path = file_url.path();
158 base::TrimString(path, "/", &path); // Remove first slash
159 *file_path = extension->path().AppendASCII(path);
160 return true;
161 }
162 return false;
163 }
164
165 // Check that the URL references a resource in the extension.
166 // NOTE: app_shell does not support shared modules.
167 ExtensionResource resource = extension->GetResource(file_url.path());
168 if (resource.empty())
169 return false;
170
171 // GetFilePath is a blocking function call.
172 const base::FilePath resource_file_path = resource.GetFilePath();
173 if (resource_file_path.empty())
174 return false;
175
176 *file_path = resource_file_path;
177 return true;
178 }
179
180 content::BrowserPpapiHost::OnKeepaliveCallback
181 ShellNaClBrowserDelegate::GetOnKeepaliveCallback() {
182 return base::Bind(&OnKeepalive);
183 }
184
185 bool ShellNaClBrowserDelegate::IsNonSfiModeAllowed(
186 const base::FilePath& profile_directory,
187 const GURL& manifest_url) {
188 return false;
189 }
190
191 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698