OLD | NEW |
---|---|
(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 "athena/content/public/app_content_control_delegate.h" | |
6 | |
7 #include "content/public/browser/render_view_host.h" | |
8 #include "content/public/browser/site_instance.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 #include "extensions/browser/api/app_runtime/app_runtime_api.h" | |
11 #include "extensions/browser/extension_registry.h" | |
12 #include "extensions/common/constants.h" | |
13 | |
14 namespace athena { | |
15 | |
16 class AppContentControlDelegateImpl : public AppContentControlDelegate { | |
17 public: | |
18 AppContentControlDelegateImpl() {} | |
19 virtual ~AppContentControlDelegateImpl() {} | |
20 | |
oshima
2014/08/19 21:22:25
// AppContentControlDelegate:
and private:
Mr4D (OOO till 08-26)
2014/08/20 14:34:40
Comment yes, private no. See above.
| |
21 virtual bool UnloadApplication( | |
22 const std::string& app_id, | |
23 content::BrowserContext* browser_context) OVERRIDE; | |
24 virtual bool RestartApplication( | |
25 const std::string& app_id, | |
26 content::BrowserContext* browser_context) OVERRIDE; | |
27 virtual std::string GetApplicationID( | |
28 content::WebContents* web_contents) OVERRIDE; | |
29 | |
30 private: | |
31 DISALLOW_COPY_AND_ASSIGN(AppContentControlDelegateImpl); | |
32 }; | |
33 | |
34 bool AppContentControlDelegateImpl::UnloadApplication( | |
35 const std::string& app_id, | |
36 content::BrowserContext* browser_context) { | |
37 // TODO(skuhne): Use the extension system to unload | |
38 // (|ExtensionService::TerminateExtension|) once it becomes available in | |
39 // Athena. | |
40 return false; | |
41 } | |
42 | |
43 bool AppContentControlDelegateImpl::RestartApplication( | |
44 const std::string& app_id, | |
45 content::BrowserContext* browser_context) { | |
46 // TODO(skuhne): As soon as the ExtensionSystem can be used, we should use the | |
47 // proper commands here for restarting. | |
48 const extensions::Extension* extension = | |
49 extensions::ExtensionRegistry::Get(browser_context)->GetExtensionById( | |
50 app_id, extensions::ExtensionRegistry::EVERYTHING); | |
51 DCHECK(extension); | |
52 extensions::AppRuntimeEventRouter::DispatchOnLaunchedEvent(browser_context, | |
53 extension); | |
54 return true; | |
55 } | |
56 | |
57 // Get the extension Id from a given |web_contents|. | |
58 std::string AppContentControlDelegateImpl::GetApplicationID( | |
59 content::WebContents* web_contents) { | |
60 content::RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | |
61 // This works for both apps and extensions because the site has been | |
62 // normalized to the extension URL for hosted apps. | |
63 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); | |
64 if (!site_instance) | |
65 return std::string(); | |
66 | |
67 const GURL& site_url = site_instance->GetSiteURL(); | |
68 | |
69 if (!site_url.SchemeIs(extensions::kExtensionScheme)) | |
70 return std::string(); | |
71 | |
72 return site_url.host(); | |
73 } | |
74 | |
75 // static | |
76 AppContentControlDelegate* | |
77 AppContentControlDelegate::CreateAppContentControlDelegate() { | |
78 return new AppContentControlDelegateImpl; | |
79 } | |
80 | |
81 } // namespace athena | |
OLD | NEW |