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

Side by Side Diff: apps/launcher.cc

Issue 217533006: Introduce apps API target in //apps and move app.runtime API into it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dependencies (app-runtime-move) Created 6 years, 8 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 | « apps/common/api/dummy.idl ('k') | apps/shell/browser/shell_extension_system.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "apps/launcher.h" 5 #include "apps/launcher.h"
6 6
7 #include "apps/apps_client.h" 7 #include "apps/apps_client.h"
8 #include "apps/browser/api/app_runtime/app_runtime_api.h"
9 #include "apps/browser/file_handler_util.h"
10 #include "apps/common/api/app_runtime.h"
8 #include "base/command_line.h" 11 #include "base/command_line.h"
9 #include "base/file_util.h" 12 #include "base/file_util.h"
10 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
11 #include "base/logging.h" 14 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
13 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 18 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
17 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 19 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/extensions/api/app_runtime.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/event_router.h" 24 #include "extensions/browser/event_router.h"
24 #include "extensions/browser/extension_host.h" 25 #include "extensions/browser/extension_host.h"
25 #include "extensions/browser/extension_prefs.h" 26 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/extension_system.h" 27 #include "extensions/browser/extension_system.h"
27 #include "extensions/browser/lazy_background_task_queue.h" 28 #include "extensions/browser/lazy_background_task_queue.h"
28 #include "extensions/browser/process_manager.h" 29 #include "extensions/browser/process_manager.h"
29 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
30 #include "extensions/common/extension_messages.h" 31 #include "extensions/common/extension_messages.h"
31 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 32 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
32 #include "net/base/mime_util.h" 33 #include "net/base/mime_util.h"
33 #include "net/base/net_util.h" 34 #include "net/base/net_util.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/drive/file_errors.h" 38 #include "chrome/browser/chromeos/drive/file_errors.h"
38 #include "chrome/browser/chromeos/drive/file_system_interface.h" 39 #include "chrome/browser/chromeos/drive/file_system_interface.h"
39 #include "chrome/browser/chromeos/drive/file_system_util.h" 40 #include "chrome/browser/chromeos/drive/file_system_util.h"
40 #include "chrome/browser/chromeos/login/user_manager.h" 41 #include "chrome/browser/chromeos/login/user_manager.h"
41 #endif 42 #endif
42 43
43 #if defined(OS_WIN) 44 #if defined(OS_WIN)
44 #include "win8/util/win8_util.h" 45 #include "win8/util/win8_util.h"
45 #endif 46 #endif
46 47
47 namespace app_runtime = extensions::api::app_runtime; 48 namespace app_runtime = apps::api::app_runtime;
48 49
50 using apps::file_handler_util::GrantedFileEntry;
49 using content::BrowserThread; 51 using content::BrowserThread;
50 using extensions::app_file_handler_util::CheckWritableFiles; 52 using extensions::app_file_handler_util::CheckWritableFiles;
51 using extensions::app_file_handler_util::FileHandlerForId; 53 using extensions::app_file_handler_util::FileHandlerForId;
52 using extensions::app_file_handler_util::FileHandlerCanHandleFile; 54 using extensions::app_file_handler_util::FileHandlerCanHandleFile;
53 using extensions::app_file_handler_util::FirstFileHandlerForFile; 55 using extensions::app_file_handler_util::FirstFileHandlerForFile;
54 using extensions::app_file_handler_util::CreateFileEntry; 56 using extensions::app_file_handler_util::CreateFileEntry;
55 using extensions::app_file_handler_util::GrantedFileEntry;
56 using extensions::app_file_handler_util::HasFileSystemWritePermission; 57 using extensions::app_file_handler_util::HasFileSystemWritePermission;
57 using extensions::EventRouter; 58 using extensions::EventRouter;
58 using extensions::Extension; 59 using extensions::Extension;
59 using extensions::ExtensionHost; 60 using extensions::ExtensionHost;
60 using extensions::ExtensionSystem; 61 using extensions::ExtensionSystem;
61 62
62 namespace apps { 63 namespace apps {
63 64
64 namespace { 65 namespace {
65 66
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 98 }
98 *path = absolute_path; 99 *path = absolute_path;
99 return true; 100 return true;
100 } 101 }
101 102
102 // Helper method to launch the platform app |extension| with no data. This 103 // Helper method to launch the platform app |extension| with no data. This
103 // should be called in the fallback case, where it has been impossible to 104 // should be called in the fallback case, where it has been impossible to
104 // load or obtain file launch data. 105 // load or obtain file launch data.
105 void LaunchPlatformAppWithNoData(Profile* profile, const Extension* extension) { 106 void LaunchPlatformAppWithNoData(Profile* profile, const Extension* extension) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension); 108 AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
108 } 109 }
109 110
110 // Class to handle launching of platform apps to open a specific path. 111 // Class to handle launching of platform apps to open a specific path.
111 // An instance of this class is created for each launch. The lifetime of these 112 // An instance of this class is created for each launch. The lifetime of these
112 // instances is managed by reference counted pointers. As long as an instance 113 // instances is managed by reference counted pointers. As long as an instance
113 // has outstanding tasks on a message queue it will be retained; once all 114 // has outstanding tasks on a message queue it will be retained; once all
114 // outstanding tasks are completed it will be deleted. 115 // outstanding tasks are completed it will be deleted.
115 class PlatformAppPathLauncher 116 class PlatformAppPathLauncher
116 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { 117 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> {
117 public: 118 public:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 LOG(ERROR) << "Could not load app page for " << extension_->id(); 286 LOG(ERROR) << "Could not load app page for " << extension_->id();
286 return; 287 return;
287 } 288 }
288 289
289 GrantedFileEntry file_entry = 290 GrantedFileEntry file_entry =
290 CreateFileEntry(profile_, 291 CreateFileEntry(profile_,
291 extension_, 292 extension_,
292 host->render_process_host()->GetID(), 293 host->render_process_host()->GetID(),
293 file_path_, 294 file_path_,
294 false); 295 false);
295 extensions::AppEventRouter::DispatchOnLaunchedEventWithFileEntry( 296 AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
296 profile_, extension_, handler_id_, mime_type, file_entry); 297 profile_, extension_, handler_id_, mime_type, file_entry);
297 } 298 }
298 299
299 // The profile the app should be run in. 300 // The profile the app should be run in.
300 Profile* profile_; 301 Profile* profile_;
301 // The extension providing the app. 302 // The extension providing the app.
302 const Extension* extension_; 303 const Extension* extension_;
303 // The path to be passed through to the app. 304 // The path to be passed through to the app.
304 const base::FilePath file_path_; 305 const base::FilePath file_path_;
305 // The ID of the file handler used to launch the app. 306 // The ID of the file handler used to launch the app.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // In restart we are just making sure launch doesn't slip through. 378 // In restart we are just making sure launch doesn't slip through.
378 if (win8::IsSingleWindowMetroMode()) 379 if (win8::IsSingleWindowMetroMode())
379 return; 380 return;
380 #endif 381 #endif
381 EventRouter* event_router = EventRouter::Get(profile); 382 EventRouter* event_router = EventRouter::Get(profile);
382 bool listening_to_restart = event_router-> 383 bool listening_to_restart = event_router->
383 ExtensionHasEventListener(extension->id(), 384 ExtensionHasEventListener(extension->id(),
384 app_runtime::OnRestarted::kEventName); 385 app_runtime::OnRestarted::kEventName);
385 386
386 if (listening_to_restart) { 387 if (listening_to_restart) {
387 extensions::AppEventRouter::DispatchOnRestartedEvent(profile, extension); 388 AppEventRouter::DispatchOnRestartedEvent(profile, extension);
388 return; 389 return;
389 } 390 }
390 391
391 extensions::ExtensionPrefs* extension_prefs = 392 extensions::ExtensionPrefs* extension_prefs =
392 extensions::ExtensionPrefs::Get(profile); 393 extensions::ExtensionPrefs::Get(profile);
393 bool had_windows = extension_prefs->IsActive(extension->id()); 394 bool had_windows = extension_prefs->IsActive(extension->id());
394 extension_prefs->SetIsActive(extension->id(), false); 395 extension_prefs->SetIsActive(extension->id(), false);
395 bool listening_to_launch = event_router-> 396 bool listening_to_launch = event_router->
396 ExtensionHasEventListener(extension->id(), 397 ExtensionHasEventListener(extension->id(),
397 app_runtime::OnLaunched::kEventName); 398 app_runtime::OnLaunched::kEventName);
398 399
399 if (listening_to_launch && had_windows) 400 if (listening_to_launch && had_windows)
400 LaunchPlatformAppWithNoData(profile, extension); 401 LaunchPlatformAppWithNoData(profile, extension);
401 } 402 }
402 403
403 void LaunchPlatformAppWithUrl(Profile* profile, 404 void LaunchPlatformAppWithUrl(Profile* profile,
404 const Extension* extension, 405 const Extension* extension,
405 const std::string& handler_id, 406 const std::string& handler_id,
406 const GURL& url, 407 const GURL& url,
407 const GURL& referrer_url) { 408 const GURL& referrer_url) {
408 extensions::AppEventRouter::DispatchOnLaunchedEventWithUrl( 409 AppEventRouter::DispatchOnLaunchedEventWithUrl(
409 profile, extension, handler_id, url, referrer_url); 410 profile, extension, handler_id, url, referrer_url);
410 } 411 }
411 412
412 } // namespace apps 413 } // namespace apps
OLDNEW
« no previous file with comments | « apps/common/api/dummy.idl ('k') | apps/shell/browser/shell_extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698