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

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 206613005: Extract RuntimeEventRouter from extensions Runtime API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove from android whitelist (runtime-api) Created 6 years, 9 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/runtime/runtime_api.h" 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/updater/extension_updater.h" 15 #include "chrome/browser/extensions/updater/extension_updater.h"
17 #include "chrome/browser/omaha_query_params/omaha_query_params.h" 16 #include "chrome/browser/omaha_query_params/omaha_query_params.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_navigator.h" 20 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/extensions/api/runtime.h" 22 #include "chrome/common/extensions/api/runtime.h"
24 #include "content/public/browser/child_process_security_policy.h" 23 #include "content/public/browser/child_process_security_policy.h"
25 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
27 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
28 #include "extensions/browser/event_router.h" 27 #include "extensions/browser/api/runtime/runtime_event_router.h"
29 #include "extensions/browser/extension_host.h" 28 #include "extensions/browser/extension_host.h"
30 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
32 #include "extensions/browser/extensions_browser_client.h" 31 #include "extensions/browser/extensions_browser_client.h"
33 #include "extensions/browser/lazy_background_task_queue.h" 32 #include "extensions/browser/lazy_background_task_queue.h"
34 #include "extensions/browser/process_manager.h" 33 #include "extensions/browser/process_manager.h"
35 #include "extensions/common/error_utils.h" 34 #include "extensions/common/error_utils.h"
36 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
37 #include "extensions/common/manifest_handlers/background_info.h" 36 #include "extensions/common/manifest_handlers/background_info.h"
38 #include "url/gurl.h" 37 #include "url/gurl.h"
(...skipping 10 matching lines...) Expand all
49 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo; 48 namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo;
50 49
51 namespace extensions { 50 namespace extensions {
52 51
53 namespace runtime = api::runtime; 52 namespace runtime = api::runtime;
54 53
55 namespace { 54 namespace {
56 55
57 const char kNoBackgroundPageError[] = "You do not have a background page."; 56 const char kNoBackgroundPageError[] = "You do not have a background page.";
58 const char kPageLoadError[] = "Background page failed to load."; 57 const char kPageLoadError[] = "Background page failed to load.";
59 const char kInstallReason[] = "reason";
60 const char kInstallReasonChromeUpdate[] = "chrome_update";
61 const char kInstallReasonUpdate[] = "update";
62 const char kInstallReasonInstall[] = "install";
63 const char kInstallPreviousVersion[] = "previousVersion";
64 const char kInvalidUrlError[] = "Invalid URL."; 58 const char kInvalidUrlError[] = "Invalid URL.";
65 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; 59 const char kUpdatesDisabledError[] = "Autoupdate is not enabled.";
66 const char kUpdateFound[] = "update_available"; 60 const char kUpdateFound[] = "update_available";
67 const char kUpdateNotFound[] = "no_update"; 61 const char kUpdateNotFound[] = "no_update";
68 const char kUpdateThrottled[] = "throttled"; 62 const char kUpdateThrottled[] = "throttled";
69 63
70 // A preference key storing the url loaded when an extension is uninstalled. 64 // A preference key storing the url loaded when an extension is uninstalled.
71 const char kUninstallUrl[] = "uninstall_url"; 65 const char kUninstallUrl[] = "uninstall_url";
72 66
73 // The name of the directory to be returned by getPackageDirectoryEntry. This 67 // The name of the directory to be returned by getPackageDirectoryEntry. This
74 // particular value does not matter to user code, but is chosen for consistency 68 // particular value does not matter to user code, but is chosen for consistency
75 // with the equivalent Pepper API. 69 // with the equivalent Pepper API.
76 const char kPackageDirectoryPath[] = "crxfs"; 70 const char kPackageDirectoryPath[] = "crxfs";
77 71
78 void DispatchOnStartupEventImpl(BrowserContext* browser_context,
79 const std::string& extension_id,
80 bool first_call,
81 ExtensionHost* host) {
82 // A NULL host from the LazyBackgroundTaskQueue means the page failed to
83 // load. Give up.
84 if (!host && !first_call)
85 return;
86
87 // Don't send onStartup events to incognito browser contexts.
88 if (browser_context->IsOffTheRecord())
89 return;
90
91 if (ExtensionsBrowserClient::Get()->IsShuttingDown() ||
92 !ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
93 return;
94 ExtensionSystem* system = ExtensionSystem::Get(browser_context);
95 if (!system)
96 return;
97
98 // If this is a persistent background page, we want to wait for it to load
99 // (it might not be ready, since this is startup). But only enqueue once.
100 // If it fails to load the first time, don't bother trying again.
101 const Extension* extension =
102 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
103 extension_id);
104 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) &&
105 first_call &&
106 system->lazy_background_task_queue()->
107 ShouldEnqueueTask(browser_context, extension)) {
108 system->lazy_background_task_queue()->AddPendingTask(
109 browser_context, extension_id,
110 base::Bind(&DispatchOnStartupEventImpl,
111 browser_context, extension_id, false));
112 return;
113 }
114
115 scoped_ptr<base::ListValue> event_args(new base::ListValue());
116 scoped_ptr<Event> event(new Event(runtime::OnStartup::kEventName,
117 event_args.Pass()));
118 system->event_router()->DispatchEventToExtension(extension_id, event.Pass());
119 }
120
121 void SetUninstallURL(ExtensionPrefs* prefs, 72 void SetUninstallURL(ExtensionPrefs* prefs,
122 const std::string& extension_id, 73 const std::string& extension_id,
123 const std::string& url_string) { 74 const std::string& url_string) {
124 prefs->UpdateExtensionPref(extension_id, 75 prefs->UpdateExtensionPref(extension_id,
125 kUninstallUrl, 76 kUninstallUrl,
126 new base::StringValue(url_string)); 77 new base::StringValue(url_string));
127 } 78 }
128 79
129 #if defined(ENABLE_EXTENSIONS) 80 #if defined(ENABLE_EXTENSIONS)
130 std::string GetUninstallURL(ExtensionPrefs* prefs, 81 std::string GetUninstallURL(ExtensionPrefs* prefs,
131 const std::string& extension_id) { 82 const std::string& extension_id) {
132 std::string url_string; 83 std::string url_string;
133 prefs->ReadPrefAsString(extension_id, kUninstallUrl, &url_string); 84 prefs->ReadPrefAsString(extension_id, kUninstallUrl, &url_string);
134 return url_string; 85 return url_string;
135 } 86 }
136 #endif // defined(ENABLE_EXTENSIONS) 87 #endif // defined(ENABLE_EXTENSIONS)
137 88
138 } // namespace 89 } // namespace
139 90
140 /////////////////////////////////////////////////////////////////////////////// 91 ///////////////////////////////////////////////////////////////////////////////
141 92
142 static base::LazyInstance<BrowserContextKeyedAPIFactory<RuntimeAPI> > 93 static base::LazyInstance<BrowserContextKeyedAPIFactory<RuntimeAPI> >
143 g_factory = LAZY_INSTANCE_INITIALIZER; 94 g_factory = LAZY_INSTANCE_INITIALIZER;
144 95
145 // static 96 // static
146 BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() { 97 BrowserContextKeyedAPIFactory<RuntimeAPI>* RuntimeAPI::GetFactoryInstance() {
147 return g_factory.Pointer(); 98 return g_factory.Pointer();
148 } 99 }
149 100
150 RuntimeAPI::RuntimeAPI(content::BrowserContext* context) 101 RuntimeAPI::RuntimeAPI(BrowserContext* context)
151 : browser_context_(context), 102 : browser_context_(context),
152 dispatch_chrome_updated_event_(false), 103 dispatch_chrome_updated_event_(false),
153 registered_for_updates_(false) { 104 registered_for_updates_(false) {
154 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 105 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
155 content::Source<BrowserContext>(context)); 106 content::Source<BrowserContext>(context));
156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 107 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
157 content::Source<BrowserContext>(context)); 108 content::Source<BrowserContext>(context));
158 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 109 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
159 content::Source<BrowserContext>(context)); 110 content::Source<BrowserContext>(context));
160 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 111 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 true)); 180 true));
230 } 181 }
231 182
232 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { 183 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
233 // Ephemeral apps are not considered to be installed and do not receive 184 // Ephemeral apps are not considered to be installed and do not receive
234 // the onInstalled() event. 185 // the onInstalled() event.
235 if (extension->is_ephemeral()) 186 if (extension->is_ephemeral())
236 return; 187 return;
237 188
238 // Get the previous version to check if this is an upgrade. 189 // Get the previous version to check if this is an upgrade.
239 ExtensionService* service = ExtensionSystem::Get( 190 const Extension* old =
240 browser_context_)->extension_service(); 191 ExtensionRegistry::Get(browser_context_)
241 const Extension* old = service->GetExtensionById(extension->id(), true); 192 ->GetExtensionById(extension->id(), ExtensionRegistry::EVERYTHING);
242 Version old_version; 193 Version old_version;
243 if (old) 194 if (old)
244 old_version = *old->version(); 195 old_version = *old->version();
245 196
246 // Dispatch the onInstalled event. 197 // Dispatch the onInstalled event.
247 base::MessageLoop::current()->PostTask( 198 base::MessageLoop::current()->PostTask(
248 FROM_HERE, 199 FROM_HERE,
249 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, 200 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent,
250 browser_context_, 201 browser_context_,
251 extension->id(), 202 extension->id(),
252 old_version, 203 old_version,
253 false)); 204 false));
254 205
255 } 206 }
256 207
257 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) { 208 void RuntimeAPI::OnExtensionUninstalled(const Extension* extension) {
258 // Ephemeral apps are not considered to be installed, so the uninstall URL 209 // Ephemeral apps are not considered to be installed, so the uninstall URL
259 // is not invoked when they are removed. 210 // is not invoked when they are removed.
260 if (extension->is_ephemeral()) 211 if (extension->is_ephemeral())
261 return; 212 return;
262 213
263 Profile* profile = Profile::FromBrowserContext(browser_context_); 214 Profile* profile = Profile::FromBrowserContext(browser_context_);
264 RuntimeEventRouter::OnExtensionUninstalled(profile, extension->id()); 215 ShowUninstallURL(profile, extension->id());
265 }
266
267 void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) {
268 Profile* profile = Profile::FromBrowserContext(browser_context_);
269 RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
270 profile, extension->id(), extension->manifest()->value());
271 }
272
273 void RuntimeAPI::OnChromeUpdateAvailable() {
274 Profile* profile = Profile::FromBrowserContext(browser_context_);
275 RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(profile);
276 }
277
278 ///////////////////////////////////////////////////////////////////////////////
279
280 // static
281 void RuntimeEventRouter::DispatchOnStartupEvent(
282 content::BrowserContext* context, const std::string& extension_id) {
283 DispatchOnStartupEventImpl(context, extension_id, true, NULL);
284 } 216 }
285 217
286 // static 218 // static
287 void RuntimeEventRouter::DispatchOnInstalledEvent( 219 void RuntimeAPI::ShowUninstallURL(Profile* profile,
288 content::BrowserContext* context, 220 const std::string& extension_id) {
289 const std::string& extension_id,
290 const Version& old_version,
291 bool chrome_updated) {
292 if (!ExtensionsBrowserClient::Get()->IsValidContext(context))
293 return;
294 ExtensionSystem* system = ExtensionSystem::Get(context);
295 if (!system)
296 return;
297
298 scoped_ptr<base::ListValue> event_args(new base::ListValue());
299 base::DictionaryValue* info = new base::DictionaryValue();
300 event_args->Append(info);
301 if (old_version.IsValid()) {
302 info->SetString(kInstallReason, kInstallReasonUpdate);
303 info->SetString(kInstallPreviousVersion, old_version.GetString());
304 } else if (chrome_updated) {
305 info->SetString(kInstallReason, kInstallReasonChromeUpdate);
306 } else {
307 info->SetString(kInstallReason, kInstallReasonInstall);
308 }
309 DCHECK(system->event_router());
310 scoped_ptr<Event> event(new Event(runtime::OnInstalled::kEventName,
311 event_args.Pass()));
312 system->event_router()->DispatchEventWithLazyListener(extension_id,
313 event.Pass());
314 }
315
316 // static
317 void RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
318 Profile* profile,
319 const std::string& extension_id,
320 const base::DictionaryValue* manifest) {
321 ExtensionSystem* system = ExtensionSystem::Get(profile);
322 if (!system)
323 return;
324
325 scoped_ptr<base::ListValue> args(new base::ListValue);
326 args->Append(manifest->DeepCopy());
327 DCHECK(system->event_router());
328 scoped_ptr<Event> event(new Event(runtime::OnUpdateAvailable::kEventName,
329 args.Pass()));
330 system->event_router()->DispatchEventToExtension(extension_id, event.Pass());
331 }
332
333 // static
334 void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(
335 Profile* profile) {
336 ExtensionSystem* system = ExtensionSystem::Get(profile);
337 if (!system)
338 return;
339
340 scoped_ptr<base::ListValue> args(new base::ListValue);
341 DCHECK(system->event_router());
342 scoped_ptr<Event> event(new Event(
343 runtime::OnBrowserUpdateAvailable::kEventName, args.Pass()));
344 system->event_router()->BroadcastEvent(event.Pass());
345 }
346
347 // static
348 void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
349 Profile* profile,
350 const std::string& app_id,
351 api::runtime::OnRestartRequired::Reason reason) {
352 ExtensionSystem* system = ExtensionSystem::Get(profile);
353 if (!system)
354 return;
355
356 scoped_ptr<Event> event(
357 new Event(runtime::OnRestartRequired::kEventName,
358 api::runtime::OnRestartRequired::Create(reason)));
359
360 DCHECK(system->event_router());
361 system->event_router()->DispatchEventToExtension(app_id, event.Pass());
362 }
363
364 // static
365 void RuntimeEventRouter::OnExtensionUninstalled(
366 Profile* profile,
367 const std::string& extension_id) {
368 #if defined(ENABLE_EXTENSIONS) 221 #if defined(ENABLE_EXTENSIONS)
369 GURL uninstall_url(GetUninstallURL(ExtensionPrefs::Get(profile), 222 GURL uninstall_url(GetUninstallURL(ExtensionPrefs::Get(profile),
370 extension_id)); 223 extension_id));
371 224
372 if (uninstall_url.is_empty()) 225 if (uninstall_url.is_empty())
373 return; 226 return;
374 227
375 Browser* browser = chrome::FindLastActiveWithProfile(profile, 228 Browser* browser = chrome::FindLastActiveWithProfile(profile,
376 chrome::GetActiveDesktop()); 229 chrome::GetActiveDesktop());
377 if (!browser) 230 if (!browser)
378 browser = new Browser(Browser::CreateParams(profile, 231 browser = new Browser(Browser::CreateParams(profile,
379 chrome::GetActiveDesktop())); 232 chrome::GetActiveDesktop()));
380 233
381 chrome::NavigateParams params(browser, uninstall_url, 234 chrome::NavigateParams params(browser, uninstall_url,
382 content::PAGE_TRANSITION_CLIENT_REDIRECT); 235 content::PAGE_TRANSITION_CLIENT_REDIRECT);
383 params.disposition = NEW_FOREGROUND_TAB; 236 params.disposition = NEW_FOREGROUND_TAB;
384 params.user_gesture = false; 237 params.user_gesture = false;
385 chrome::Navigate(&params); 238 chrome::Navigate(&params);
386 #endif // defined(ENABLE_EXTENSIONS) 239 #endif // defined(ENABLE_EXTENSIONS)
387 } 240 }
388 241
242 void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) {
243 RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
244 browser_context_, extension->id(), extension->manifest()->value());
245 }
246
247 void RuntimeAPI::OnChromeUpdateAvailable() {
248 RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(browser_context_);
249 }
250
251 ///////////////////////////////////////////////////////////////////////////////
252
389 bool RuntimeGetBackgroundPageFunction::RunImpl() { 253 bool RuntimeGetBackgroundPageFunction::RunImpl() {
390 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); 254 ExtensionSystem* system = ExtensionSystem::Get(GetProfile());
391 ExtensionHost* host = system->process_manager()-> 255 ExtensionHost* host = system->process_manager()->
392 GetBackgroundHostForExtension(extension_id()); 256 GetBackgroundHostForExtension(extension_id());
393 if (system->lazy_background_task_queue()->ShouldEnqueueTask(GetProfile(), 257 if (system->lazy_background_task_queue()->ShouldEnqueueTask(GetProfile(),
394 GetExtension())) { 258 GetExtension())) {
395 system->lazy_background_task_queue()->AddPendingTask( 259 system->lazy_background_task_queue()->AddPendingTask(
396 GetProfile(), 260 GetProfile(),
397 extension_id(), 261 extension_id(),
398 base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this)); 262 base::Bind(&RuntimeGetBackgroundPageFunction::OnPageLoaded, this));
399 } else if (host) { 263 } else if (host) {
400 OnPageLoaded(host); 264 OnPageLoaded(host);
401 } else { 265 } else {
402 error_ = kNoBackgroundPageError; 266 error_ = kNoBackgroundPageError;
403 return false; 267 return false;
404 } 268 }
405 269
406 return true; 270 return true;
407 } 271 }
408 272
409 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { 273 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) {
410 if (host) { 274 if (host) {
411 SendResponse(true); 275 SendResponse(true);
412 } else { 276 } else {
413 error_ = kPageLoadError; 277 error_ = kPageLoadError;
414 SendResponse(false); 278 SendResponse(false);
415 } 279 }
416 } 280 }
417 281
282 //////////////////////////////////////////////////////////////////////////////
283
418 bool RuntimeSetUninstallURLFunction::RunImpl() { 284 bool RuntimeSetUninstallURLFunction::RunImpl() {
419 std::string url_string; 285 std::string url_string;
420 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); 286 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string));
421 287
422 GURL url(url_string); 288 GURL url(url_string);
423 if (!url.is_valid()) { 289 if (!url.is_valid()) {
424 error_ = ErrorUtils::FormatErrorMessage(kInvalidUrlError, url_string); 290 error_ = ErrorUtils::FormatErrorMessage(kInvalidUrlError, url_string);
425 return false; 291 return false;
426 } 292 }
427 293
428 SetUninstallURL( 294 SetUninstallURL(
429 ExtensionPrefs::Get(GetProfile()), extension_id(), url_string); 295 ExtensionPrefs::Get(GetProfile()), extension_id(), url_string);
430 return true; 296 return true;
431 } 297 }
432 298
299 //////////////////////////////////////////////////////////////////////////////
300
433 bool RuntimeReloadFunction::RunImpl() { 301 bool RuntimeReloadFunction::RunImpl() {
434 // We can't call ReloadExtension directly, since when this method finishes 302 // We can't call ReloadExtension directly, since when this method finishes
435 // it tries to decrease the reference count for the extension, which fails 303 // it tries to decrease the reference count for the extension, which fails
436 // if the extension has already been reloaded; so instead we post a task. 304 // if the extension has already been reloaded; so instead we post a task.
437 base::MessageLoop::current()->PostTask( 305 base::MessageLoop::current()->PostTask(
438 FROM_HERE, 306 FROM_HERE,
439 base::Bind(&ExtensionService::ReloadExtension, 307 base::Bind(&ExtensionService::ReloadExtension,
440 GetProfile()->GetExtensionService()->AsWeakPtr(), 308 GetProfile()->GetExtensionService()->AsWeakPtr(),
441 extension_id())); 309 extension_id()));
442 return true; 310 return true;
443 } 311 }
444 312
313 //////////////////////////////////////////////////////////////////////////////
314
445 RuntimeRequestUpdateCheckFunction::RuntimeRequestUpdateCheckFunction() { 315 RuntimeRequestUpdateCheckFunction::RuntimeRequestUpdateCheckFunction() {
446 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, 316 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND,
447 content::NotificationService::AllSources()); 317 content::NotificationService::AllSources());
448 } 318 }
449 319
450 bool RuntimeRequestUpdateCheckFunction::RunImpl() { 320 bool RuntimeRequestUpdateCheckFunction::RunImpl() {
451 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); 321 ExtensionSystem* system = ExtensionSystem::Get(GetProfile());
452 ExtensionService* service = system->extension_service(); 322 ExtensionService* service = system->extension_service();
453 ExtensionUpdater* updater = service->updater(); 323 ExtensionUpdater* updater = service->updater();
454 if (!updater) { 324 if (!updater) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const std::string& version) { 377 const std::string& version) {
508 did_reply_ = true; 378 did_reply_ = true;
509 results_.reset(new base::ListValue); 379 results_.reset(new base::ListValue);
510 results_->AppendString(kUpdateFound); 380 results_->AppendString(kUpdateFound);
511 base::DictionaryValue* details = new base::DictionaryValue; 381 base::DictionaryValue* details = new base::DictionaryValue;
512 results_->Append(details); 382 results_->Append(details);
513 details->SetString("version", version); 383 details->SetString("version", version);
514 SendResponse(true); 384 SendResponse(true);
515 } 385 }
516 386
387 //////////////////////////////////////////////////////////////////////////////
388
517 bool RuntimeRestartFunction::RunImpl() { 389 bool RuntimeRestartFunction::RunImpl() {
518 #if defined(OS_CHROMEOS) 390 #if defined(OS_CHROMEOS)
519 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) { 391 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) {
520 chromeos::DBusThreadManager::Get() 392 chromeos::DBusThreadManager::Get()
521 ->GetPowerManagerClient() 393 ->GetPowerManagerClient()
522 ->RequestRestart(); 394 ->RequestRestart();
523 return true; 395 return true;
524 } 396 }
525 #endif 397 #endif
526 SetError("Function available only for ChromeOS kiosk mode."); 398 SetError("Function available only for ChromeOS kiosk mode.");
527 return false; 399 return false;
528 } 400 }
529 401
402 //////////////////////////////////////////////////////////////////////////////
403
530 bool RuntimeGetPlatformInfoFunction::RunImpl() { 404 bool RuntimeGetPlatformInfoFunction::RunImpl() {
531 GetPlatformInfo::Results::PlatformInfo info; 405 GetPlatformInfo::Results::PlatformInfo info;
532 406
533 const char* os = chrome::OmahaQueryParams::GetOS(); 407 const char* os = chrome::OmahaQueryParams::GetOS();
534 if (strcmp(os, "mac") == 0) { 408 if (strcmp(os, "mac") == 0) {
535 info.os = GetPlatformInfo::Results::PlatformInfo::OS_MAC_; 409 info.os = GetPlatformInfo::Results::PlatformInfo::OS_MAC_;
536 } else if (strcmp(os, "win") == 0) { 410 } else if (strcmp(os, "win") == 0) {
537 info.os = GetPlatformInfo::Results::PlatformInfo::OS_WIN_; 411 info.os = GetPlatformInfo::Results::PlatformInfo::OS_WIN_;
538 } else if (strcmp(os, "android") == 0) { 412 } else if (strcmp(os, "android") == 0) {
539 info.os = GetPlatformInfo::Results::PlatformInfo::OS_ANDROID_; 413 info.os = GetPlatformInfo::Results::PlatformInfo::OS_ANDROID_;
(...skipping 29 matching lines...) Expand all
569 info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64; 443 info.nacl_arch = GetPlatformInfo::Results::PlatformInfo::NACL_ARCH_X86_64;
570 } else { 444 } else {
571 NOTREACHED(); 445 NOTREACHED();
572 return false; 446 return false;
573 } 447 }
574 448
575 results_ = GetPlatformInfo::Results::Create(info); 449 results_ = GetPlatformInfo::Results::Create(info);
576 return true; 450 return true;
577 } 451 }
578 452
453 //////////////////////////////////////////////////////////////////////////////
454
579 bool RuntimeGetPackageDirectoryEntryFunction::RunImpl() { 455 bool RuntimeGetPackageDirectoryEntryFunction::RunImpl() {
580 fileapi::IsolatedContext* isolated_context = 456 fileapi::IsolatedContext* isolated_context =
581 fileapi::IsolatedContext::GetInstance(); 457 fileapi::IsolatedContext::GetInstance();
582 DCHECK(isolated_context); 458 DCHECK(isolated_context);
583 459
584 std::string relative_path = kPackageDirectoryPath; 460 std::string relative_path = kPackageDirectoryPath;
585 base::FilePath path = extension_->path(); 461 base::FilePath path = extension_->path();
586 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( 462 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
587 fileapi::kFileSystemTypeNativeLocal, path, &relative_path); 463 fileapi::kFileSystemTypeNativeLocal, path, &relative_path);
588 464
589 int renderer_id = render_view_host_->GetProcess()->GetID(); 465 int renderer_id = render_view_host_->GetProcess()->GetID();
590 content::ChildProcessSecurityPolicy* policy = 466 content::ChildProcessSecurityPolicy* policy =
591 content::ChildProcessSecurityPolicy::GetInstance(); 467 content::ChildProcessSecurityPolicy::GetInstance();
592 policy->GrantReadFileSystem(renderer_id, filesystem_id); 468 policy->GrantReadFileSystem(renderer_id, filesystem_id);
593 base::DictionaryValue* dict = new base::DictionaryValue(); 469 base::DictionaryValue* dict = new base::DictionaryValue();
594 SetResult(dict); 470 SetResult(dict);
595 dict->SetString("fileSystemId", filesystem_id); 471 dict->SetString("fileSystemId", filesystem_id);
596 dict->SetString("baseName", relative_path); 472 dict->SetString("baseName", relative_path);
597 return true; 473 return true;
598 } 474 }
599 475
600 } // namespace extensions 476 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/runtime/runtime_api.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698