Home | History | Annotate | Download | only in chrome_frame
      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_FRAME_POLICY_SETTINGS_H_
      6 #define CHROME_FRAME_POLICY_SETTINGS_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/command_line.h"
     13 #include "base/memory/singleton.h"
     14 
     15 // A simple class that reads and caches policy settings for Chrome Frame.
     16 // TODO(tommi): Support refreshing when new settings are pushed.
     17 // TODO(tommi): Use Chrome's classes for this (and the notification service).
     18 class PolicySettings {
     19  public:
     20   enum RendererForUrl {
     21     RENDERER_NOT_SPECIFIED = -1,
     22     RENDER_IN_HOST,
     23     RENDER_IN_CHROME_FRAME,
     24   };
     25 
     26   enum SkipMetadataCheck {
     27     SKIP_METADATA_CHECK_NOT_SPECIFIED = -1,
     28     SKIP_METADATA_CHECK_NO,
     29     SKIP_METADATA_CHECK_YES,
     30   };
     31 
     32   static PolicySettings* GetInstance();
     33 
     34   RendererForUrl default_renderer() const {
     35     return default_renderer_;
     36   }
     37 
     38   SkipMetadataCheck skip_metadata_check() const {
     39     return skip_metadata_check_;
     40   }
     41 
     42   RendererForUrl GetRendererForUrl(const wchar_t* url);
     43 
     44   RendererForUrl GetRendererForContentType(const wchar_t* content_type);
     45 
     46   // Returns the policy-configured Chrome app locale, or an empty string if none
     47   // is configured.
     48   const std::wstring& ApplicationLocale() const {
     49     return application_locale_;
     50   }
     51 
     52   // Contains additional parameters that can optionally be configured for the
     53   // current user via the policy settings.  The program part of this command
     54   // line object must not be used when appending to another command line.
     55   const CommandLine& AdditionalLaunchParameters() const;
     56 
     57   // Returns true if the Chrome Frame turndown prompt should be suppressed.
     58   bool suppress_turndown_prompt() const {
     59     return suppress_turndown_prompt_;
     60   }
     61 
     62   // Helper functions for reading settings from the registry
     63   static void ReadUrlSettings(RendererForUrl* default_renderer,
     64       std::vector<std::wstring>* renderer_exclusion_list);
     65   static void ReadMetadataCheckSettings(SkipMetadataCheck* skip_metadata_check);
     66   static void ReadContentTypeSetting(
     67       std::vector<std::wstring>* content_type_list);
     68   static void ReadStringSetting(const char* value_name, std::wstring* value);
     69   static void ReadBoolSetting(const char* value_name, bool* value);
     70 
     71  protected:
     72   PolicySettings()
     73       : default_renderer_(RENDERER_NOT_SPECIFIED),
     74         skip_metadata_check_(SKIP_METADATA_CHECK_NOT_SPECIFIED),
     75         additional_launch_parameters_(CommandLine::NO_PROGRAM),
     76         suppress_turndown_prompt_(false) {
     77     RefreshFromRegistry();
     78   }
     79 
     80   ~PolicySettings() {
     81   }
     82 
     83   // Protected for now since the class is not thread safe.
     84   void RefreshFromRegistry();
     85 
     86  protected:
     87   RendererForUrl default_renderer_;
     88   SkipMetadataCheck skip_metadata_check_;
     89   std::vector<std::wstring> renderer_exclusion_list_;
     90   std::vector<std::wstring> content_type_list_;
     91   std::wstring application_locale_;
     92   CommandLine additional_launch_parameters_;
     93   bool suppress_turndown_prompt_;
     94 
     95  private:
     96   // This ensures no construction is possible outside of the class itself.
     97   friend struct DefaultSingletonTraits<PolicySettings>;
     98   DISALLOW_COPY_AND_ASSIGN(PolicySettings);
     99 };
    100 
    101 #endif  // CHROME_FRAME_POLICY_SETTINGS_H_
    102