1// Copyright (c) 2011 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#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_
7#pragma once
8
9#include <map>
10#include <string>
11
12#include "base/basictypes.h"
13#include "base/file_path.h"
14#include "base/memory/ref_counted.h"
15#include "chrome/common/extensions/extension.h"
16#include "chrome/common/extensions/extension_extent.h"
17#include "googleurl/src/gurl.h"
18
19class Extension;
20
21// Contains extension data that needs to be accessed on the IO thread. It can
22// be created/destroyed on any thread, but all other methods must be called on
23// the IO thread.
24//
25// TODO(mpcomplete): consider simplifying this class to return the StaticData
26// object itself, since most methods are simple property accessors.
27class ExtensionInfoMap : public base::RefCountedThreadSafe<ExtensionInfoMap> {
28 public:
29  ExtensionInfoMap();
30  ~ExtensionInfoMap();
31
32  // Callback for when new extensions are loaded.
33  void AddExtension(const Extension* extension);
34
35  // Callback for when an extension is unloaded.
36  void RemoveExtension(const std::string& id,
37                       const UnloadedExtensionInfo::Reason reason);
38
39  // Gets the name for the specified extension.
40  std::string GetNameForExtension(const std::string& id) const;
41
42  // Gets the path to the directory for the specified extension.
43  FilePath GetPathForExtension(const std::string& id) const;
44
45  // Gets the path to the directory for the specified disabled extension.
46  FilePath GetPathForDisabledExtension(const std::string& id) const;
47
48  // Returns true if the specified extension exists and has a non-empty web
49  // extent.
50  bool ExtensionHasWebExtent(const std::string& id) const;
51
52  // Returns true if the specified extension exists and can load in incognito
53  // contexts.
54  bool ExtensionCanLoadInIncognito(const std::string& id) const;
55
56  // Returns an empty string if the extension with |id| doesn't have a default
57  // locale.
58  std::string GetDefaultLocaleForExtension(const std::string& id) const;
59
60  // Gets the effective host permissions for the extension with |id|.
61  ExtensionExtent
62      GetEffectiveHostPermissionsForExtension(const std::string& id) const;
63
64  // Determine whether a URL has access to the specified extension permission.
65  bool CheckURLAccessToExtensionPermission(const GURL& url,
66                                           const char* permission_name) const;
67
68  // Returns true if the specified URL references the icon for an extension.
69  bool URLIsForExtensionIcon(const GURL& url) const;
70
71 private:
72  // Map of extension info by extension id.
73  typedef std::map<std::string, scoped_refptr<const Extension> > Map;
74
75  Map extension_info_;
76  Map disabled_extension_info_;
77};
78
79#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INFO_MAP_H_
80