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

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

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