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

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

Powered by Google App Engine
This is Rietveld 408576698