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

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
« no previous file with comments | « extensions/shell/browser/shell_nacl_browser_delegate.h ('k') | extensions/shell/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/site_instance.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 = browser_context_->GetPath();
104 if (!path.empty()) {
105 *user_dir = path;
106 return true;
107 }
108 return false;
109 }
110
111 std::string ShellNaClBrowserDelegate::GetVersionString() const {
112 // Used to trigger update of the validation caches.
113 // TODO(jamescook): Generate a real version number and use it both here and
114 // in our user agent. http://crbug.com/402612
115 return "1.2.3.4";
116 }
117
118 ppapi::host::HostFactory* ShellNaClBrowserDelegate::CreatePpapiHostFactory(
119 content::BrowserPpapiHost* ppapi_host) {
120 return NULL;
121 }
122
123 void ShellNaClBrowserDelegate::SetDebugPatterns(std::string debug_patterns) {
124 // No debugger support. Developers should use Chrome for debugging.
125 }
126
127 bool ShellNaClBrowserDelegate::URLMatchesDebugPatterns(
128 const GURL& manifest_url) {
129 // No debugger support. Developers should use Chrome for debugging.
130 return false;
131 }
132
133 // This function is security sensitive. Be sure to check with a security
134 // person before you modify it.
135 // TODO(jamescook): Refactor this code into the extensions module so it can
136 // be shared with Chrome's NaClBrowserDelegateImpl. http://crbug.com/403017
137 bool ShellNaClBrowserDelegate::MapUrlToLocalFilePath(
138 const GURL& file_url,
139 bool use_blocking_api,
140 const base::FilePath& profile_directory,
141 base::FilePath* file_path) {
142 scoped_refptr<InfoMap> info_map =
143 ExtensionSystem::Get(browser_context_)->info_map();
144 // Check that the URL is recognized by the extension system.
145 const Extension* extension =
146 info_map->extensions().GetExtensionOrAppByURL(file_url);
147 if (!extension)
148 return false;
149
150 // This is a short-cut which avoids calling a blocking file operation
151 // (GetFilePath()), so that this can be called on the IO thread. It only
152 // handles a subset of the urls.
153 if (!use_blocking_api) {
154 if (file_url.SchemeIs(kExtensionScheme)) {
155 std::string path = file_url.path();
156 base::TrimString(path, "/", &path); // Remove first slash
157 *file_path = extension->path().AppendASCII(path);
158 return true;
159 }
160 return false;
161 }
162
163 // Check that the URL references a resource in the extension.
164 // NOTE: app_shell does not support shared modules.
165 ExtensionResource resource = extension->GetResource(file_url.path());
166 if (resource.empty())
167 return false;
168
169 // GetFilePath is a blocking function call.
170 const base::FilePath resource_file_path = resource.GetFilePath();
171 if (resource_file_path.empty())
172 return false;
173
174 *file_path = resource_file_path;
175 return true;
176 }
177
178 content::BrowserPpapiHost::OnKeepaliveCallback
179 ShellNaClBrowserDelegate::GetOnKeepaliveCallback() {
180 return base::Bind(&OnKeepalive);
181 }
182
183 bool ShellNaClBrowserDelegate::IsNonSfiModeAllowed(
184 const base::FilePath& profile_directory,
185 const GURL& manifest_url) {
186 return false;
187 }
188
189 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/shell/browser/shell_nacl_browser_delegate.h ('k') | extensions/shell/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698