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#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_PEPPER_FLASH_CONTENT_SETTINGS_UTILS_H_
6#define CHROME_BROWSER_UI_WEBUI_OPTIONS_PEPPER_FLASH_CONTENT_SETTINGS_UTILS_H_
7
8#include <vector>
9
10#include "components/content_settings/core/common/content_settings.h"
11#include "components/content_settings/core/common/content_settings_pattern.h"
12#include "ppapi/c/private/ppp_flash_browser_operations.h"
13#include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h"
14
15namespace options {
16
17struct MediaException {
18  MediaException(const ContentSettingsPattern& in_pattern,
19                 ContentSetting in_audio_setting,
20                 ContentSetting in_video_setting);
21  ~MediaException();
22
23  bool operator==(const MediaException& other) const;
24
25  ContentSettingsPattern pattern;
26  ContentSetting audio_setting;
27  ContentSetting video_setting;
28};
29
30typedef std::vector<MediaException> MediaExceptions;
31
32class PepperFlashContentSettingsUtils {
33 public:
34  static ContentSetting FlashPermissionToContentSetting(
35      PP_Flash_BrowserOperations_Permission permission);
36
37  static void FlashSiteSettingsToMediaExceptions(
38      const ppapi::FlashSiteSettings& site_settings,
39      MediaExceptions* media_exceptions);
40
41  // Sorts |media_exceptions| in ascending order by comparing the |pattern|
42  // field of the elements.
43  static void SortMediaExceptions(MediaExceptions* media_exceptions);
44
45  // Checks whether |exceptions_1| and |exceptions_2| describe the same set of
46  // exceptions. |exceptions_1| and |exceptions_2| should be sorted by
47  // SortMediaExceptions() before passing into this method.
48  //
49  // When an element of |exceptions_1| has a pattern that doesn't match any
50  // element of |exceptions_2|, it would be compared with |default_setting_2|,
51  // and visa versa.
52  //
53  // |ignore_audio_setting| and |ignore_video_setting| specify whether to skip
54  // comparison of the |audio_setting| and |video_setting| field of
55  // MediaException, respectively.
56  static bool AreMediaExceptionsEqual(ContentSetting default_setting_1,
57                                      const MediaExceptions& exceptions_1,
58                                      ContentSetting default_setting_2,
59                                      const MediaExceptions& exceptions_2,
60                                      bool ignore_audio_setting,
61                                      bool ignore_video_setting);
62};
63
64}  // namespace options
65
66#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_PEPPER_FLASH_CONTENT_SETTINGS_UTILS_H_
67