Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 10 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 class Profile; | |
| 14 namespace content { | 13 namespace content { |
| 14 class BrowserContext; | |
| 15 class WebContents; | 15 class WebContents; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 class Extension; | 19 class Extension; |
| 20 | 20 |
| 21 // Tracks the web connectability of domains to extensions in incognito mode. | 21 // Tracks the web connectability of domains to extensions in incognito mode. |
| 22 // | 22 // |
| 23 // The most important functionality is prompting the user to allow or disallow | 23 // The most important functionality is prompting the user to allow or disallow |
| 24 // connections from incognito tabs to extensions or apps. Even if an extension | 24 // connections from incognito tabs to extensions or apps. Even if an extension |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 43 ~ScopedAlertTracker(); | 43 ~ScopedAlertTracker(); |
| 44 | 44 |
| 45 // Returns the number of times the alert has been shown since | 45 // Returns the number of times the alert has been shown since |
| 46 // GetAndResetAlertCount was last called. | 46 // GetAndResetAlertCount was last called. |
| 47 int GetAndResetAlertCount(); | 47 int GetAndResetAlertCount(); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 int last_checked_invocation_count_; | 50 int last_checked_invocation_count_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Returns the IncognitoConnectability object for |profile|. |profile| must | 53 // Returns the IncognitoConnectability object for |profile|. |profile| must |
|
James Cook
2014/02/21 00:14:44
nit: |profile| -> |context|.
Yoyo Zhou
2014/02/21 17:17:07
Done.
| |
| 54 // be off-the-record. | 54 // be off-the-record. |
| 55 static IncognitoConnectability* Get(Profile* profile); | 55 static IncognitoConnectability* Get(content::BrowserContext* context); |
| 56 | 56 |
| 57 // Returns true if |url| is allowed to connect from this profile, false | 57 // Returns true if |url| is allowed to connect from this profile, false |
| 58 // otherwise. If unknown, this call will block and prompt the user. | 58 // otherwise. If unknown, this call will block and prompt the user. |
| 59 bool Query(const Extension* extension, | 59 bool Query(const Extension* extension, |
| 60 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
| 61 const GURL& url); | 61 const GURL& url); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 friend class ProfileKeyedAPIFactory<IncognitoConnectability>; | 64 friend class ProfileKeyedAPIFactory<IncognitoConnectability>; |
| 65 | 65 |
| 66 explicit IncognitoConnectability(Profile* profile); | 66 explicit IncognitoConnectability(content::BrowserContext* context); |
| 67 virtual ~IncognitoConnectability(); | 67 virtual ~IncognitoConnectability(); |
| 68 | 68 |
| 69 typedef std::map<std::string, std::set<GURL> > ExtensionToOriginsMap; | 69 typedef std::map<std::string, std::set<GURL> > ExtensionToOriginsMap; |
| 70 | 70 |
| 71 // Returns true if the (|extension|, |origin|) pair appears in the map. | 71 // Returns true if the (|extension|, |origin|) pair appears in the map. |
| 72 bool IsInMap(const Extension* extension, | 72 bool IsInMap(const Extension* extension, |
| 73 const GURL& origin, | 73 const GURL& origin, |
| 74 const ExtensionToOriginsMap& map); | 74 const ExtensionToOriginsMap& map); |
| 75 | 75 |
| 76 // ProfileKeyedAPI implementation. | 76 // ProfileKeyedAPI implementation. |
| 77 static ProfileKeyedAPIFactory<IncognitoConnectability>* GetFactoryInstance(); | 77 static ProfileKeyedAPIFactory<IncognitoConnectability>* GetFactoryInstance(); |
| 78 static const char* service_name() { | 78 static const char* service_name() { |
| 79 return "Messaging.IncognitoConnectability"; | 79 return "Messaging.IncognitoConnectability"; |
| 80 } | 80 } |
| 81 static const bool kServiceHasOwnInstanceInIncognito = true; | 81 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 82 static const bool kServiceIsCreatedWithBrowserContext = false; | 82 static const bool kServiceIsCreatedWithBrowserContext = false; |
| 83 | 83 |
| 84 // The origins that have been prompted for and either allowed or disallowed. | 84 // The origins that have been prompted for and either allowed or disallowed. |
| 85 // These are deliberately stored in-memory so that they're reset when the | 85 // These are deliberately stored in-memory so that they're reset when the |
| 86 // profile is destroyed (i.e. when the last incognito window is closed). | 86 // profile is destroyed (i.e. when the last incognito window is closed). |
| 87 ExtensionToOriginsMap allowed_origins_; | 87 ExtensionToOriginsMap allowed_origins_; |
| 88 ExtensionToOriginsMap disallowed_origins_; | 88 ExtensionToOriginsMap disallowed_origins_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 } // namespace extensions | 91 } // namespace extensions |
| 92 | 92 |
| 93 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ | 93 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_INCOGNITO_CONNECTABILITY_H_ |
| OLD | NEW |