Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ui/ash/launcher/launcher_app_tab_helper.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | |
| 21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_set.h" | |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 const extensions::Extension* GetExtensionForTab(Profile* profile, | 27 const extensions::Extension* GetExtensionForTab(Profile* profile, |
| 26 content::WebContents* tab) { | 28 content::WebContents* tab) { |
| 27 ExtensionService* extension_service = profile->GetExtensionService(); | 29 if (!ExtensionSystem::Get(profile)->extension_service()->extensions_enabled()) |
|
sky
2014/04/04 21:21:13
We seem to have all sorts of code that NULL checks
Devlin
2014/04/04 21:24:14
ExtensionService can be null (in unittests, more t
| |
| 28 if (!extension_service || !extension_service->extensions_enabled()) | |
| 29 return NULL; | 30 return NULL; |
| 30 | 31 |
| 31 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 32 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
| 32 DCHECK(browser); | 33 DCHECK(browser); |
| 33 | 34 |
| 35 extensions::ExtensionRegistry* registry = | |
| 36 extensions::ExtensionRegistry::Get(profile); | |
| 37 | |
| 34 // Use the Browser's app name to determine the extension for app windows and | 38 // Use the Browser's app name to determine the extension for app windows and |
| 35 // use the tab's url for app tabs. | 39 // use the tab's url for app tabs. |
| 36 if (browser->is_app()) { | 40 if (browser->is_app()) { |
| 37 return extension_service->GetInstalledExtension( | 41 return registry->GetInstalledExtensionById( |
| 38 web_app::GetExtensionIdFromApplicationName(browser->app_name())); | 42 web_app::GetExtensionIdFromApplicationName(browser->app_name()), |
| 43 extensions::ExtensionRegistry::EVERYTHING); | |
| 39 } | 44 } |
| 40 | 45 |
| 41 const GURL url = tab->GetURL(); | 46 const GURL url = tab->GetURL(); |
| 42 if (extension_service->IsInstalledApp(url)) | 47 const extensions::ExtensionSet& extensions = registry->enabled_extensions(); |
| 43 return extension_service->GetInstalledApp(url); | 48 const Extension* extension = extensions.GetAppByURL(url); |
| 49 if (extension) | |
| 50 return extension; | |
| 44 | 51 |
| 45 // Bookmark app windows should match their launch url extension despite | 52 // Bookmark app windows should match their launch url extension despite |
| 46 // their web extents. | 53 // their web extents. |
| 47 if (CommandLine::ForCurrentProcess()->HasSwitch( | 54 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 48 switches::kEnableStreamlinedHostedApps)) { | 55 switches::kEnableStreamlinedHostedApps)) { |
| 49 const extensions::ExtensionSet& extensions = | |
| 50 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 51 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); | 56 for (extensions::ExtensionSet::const_iterator it = extensions.begin(); |
| 52 it != extensions.end(); ++it) { | 57 it != extensions.end(); ++it) { |
| 53 if (it->get()->from_bookmark() && | 58 if (it->get()->from_bookmark() && |
| 54 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { | 59 extensions::AppLaunchInfo::GetLaunchWebURL(it->get()) == url) { |
| 55 return it->get(); | 60 return it->get(); |
| 56 } | 61 } |
| 57 } | 62 } |
| 58 } | 63 } |
| 59 return NULL; | 64 return NULL; |
| 60 } | 65 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 return extension ? extension->id() : std::string(); | 102 return extension ? extension->id() : std::string(); |
| 98 } | 103 } |
| 99 | 104 |
| 100 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { | 105 bool LauncherAppTabHelper::IsValidIDForCurrentUser(const std::string& id) { |
| 101 return GetExtensionByID(profile_, id) != NULL; | 106 return GetExtensionByID(profile_, id) != NULL; |
| 102 } | 107 } |
| 103 | 108 |
| 104 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { | 109 void LauncherAppTabHelper::SetCurrentUser(Profile* profile) { |
| 105 profile_ = profile; | 110 profile_ = profile; |
| 106 } | 111 } |
| OLD | NEW |