OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_PLUGINS_FLASH_TEMPORARY_PERMISSION_TRACKER_H_ |
| 6 #define CHROME_BROWSER_PLUGINS_FLASH_TEMPORARY_PERMISSION_TRACKER_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/synchronization/lock.h" |
| 11 #include "components/keyed_service/core/refcounted_keyed_service.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 namespace content { |
| 17 class WebContents; |
| 18 } // namespace content |
| 19 |
| 20 // This class tracks temporary permission grants to allow flash to run on web |
| 21 // pages. This is used when the enterprise plugins setting is set to ASK. After |
| 22 // permission has been given to use flash, the page is automatically refreshed |
| 23 // so we need to make sure we don't revoke access when the page is first |
| 24 // refreshed. But any subsequent navigations or destroying the render frame |
| 25 // should revoke access. This class is safe to use from any thread. |
| 26 class FlashTemporaryPermissionTracker : public RefcountedKeyedService { |
| 27 public: |
| 28 static scoped_refptr<FlashTemporaryPermissionTracker> Get(Profile* profile); |
| 29 |
| 30 // Returns true if flash is enabled for a given |url|. |
| 31 bool IsFlashEnabled(const GURL& url); |
| 32 |
| 33 // Call if flash was enabled in the main frame of a given |web_contents|. |
| 34 void FlashEnabledForWebContents(content::WebContents* web_contents); |
| 35 |
| 36 private: |
| 37 friend class FlashTemporaryPermissionTrackerFactory; |
| 38 friend class FlashTemporaryPermissionTrackerTest; |
| 39 |
| 40 class GrantObserver; |
| 41 |
| 42 explicit FlashTemporaryPermissionTracker(Profile* profile); |
| 43 ~FlashTemporaryPermissionTracker() override; |
| 44 |
| 45 // Revoke access from the given origin. |
| 46 void RevokeAccess(const GURL& origin); |
| 47 |
| 48 // RefCountedProfileKeyedBase method override. |
| 49 void ShutdownOnUIThread() override; |
| 50 |
| 51 Profile* profile_; |
| 52 |
| 53 // We use GURLs to store the origins because we need to support the file: |
| 54 // scheme comparing equal to itself. |
| 55 // TODO(raymes): Revisit this after we decide what to do with plugins on file: |
| 56 // URLs. |
| 57 std::map<GURL, std::unique_ptr<GrantObserver>> granted_origins_; |
| 58 |
| 59 // Lock to protect |granted_origins_|. This is needed because IsFlashEnabled |
| 60 // may be called from any thread via the ChromePluginServiceFilter. |
| 61 base::Lock granted_origins_lock_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(FlashTemporaryPermissionTracker); |
| 64 }; |
| 65 |
| 66 #endif // CHROME_BROWSER_PLUGINS_FLASH_TEMPORARY_PERMISSION_TRACKER_H_ |
OLD | NEW |