Home | History | Annotate | Download | only in launcher
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
      6 
      7 #include "chrome/browser/extensions/extension_service.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/common/extensions/extension.h"
     10 #include "content/public/browser/web_contents.h"
     11 
     12 namespace {
     13 
     14 const extensions::Extension* GetExtensionForTab(Profile* profile,
     15                                                 content::WebContents* tab) {
     16   ExtensionService* extension_service = profile->GetExtensionService();
     17   if (!extension_service)
     18     return NULL;
     19   return extension_service->GetInstalledApp(tab->GetURL());
     20 }
     21 
     22 const extensions::Extension* GetExtensionByID(Profile* profile,
     23                                               const std::string& id) {
     24   ExtensionService* service = profile->GetExtensionService();
     25   if (!service)
     26     return NULL;
     27   return service->GetInstalledExtension(id);
     28 }
     29 
     30 }  // namespace
     31 
     32 LauncherAppTabHelper::LauncherAppTabHelper(Profile* profile)
     33     : profile_(profile) {
     34 }
     35 
     36 LauncherAppTabHelper::~LauncherAppTabHelper() {
     37 }
     38 
     39 std::string LauncherAppTabHelper::GetAppID(content::WebContents* tab) {
     40   const extensions::Extension* extension = GetExtensionForTab(profile_, tab);
     41   return extension ? extension->id() : std::string();
     42 }
     43 
     44 bool LauncherAppTabHelper::IsValidID(const std::string& id) {
     45   return GetExtensionByID(profile_, id) != NULL;
     46 }
     47