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