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 typedef enum RendererForUrl { 21 RENDERER_NOT_SPECIFIED = -1, 22 RENDER_IN_HOST, 23 RENDER_IN_CHROME_FRAME, 24 }; 25 26 static PolicySettings* GetInstance(); 27 28 RendererForUrl default_renderer() const { 29 return default_renderer_; 30 } 31 32 RendererForUrl GetRendererForUrl(const wchar_t* url); 33 34 RendererForUrl GetRendererForContentType(const wchar_t* content_type); 35 36 // Returns the policy-configured Chrome app locale, or an empty string if none 37 // is configured. 38 const std::wstring& ApplicationLocale() const { 39 return application_locale_; 40 } 41 42 // Contains additional parameters that can optionally be configured for the 43 // current user via the policy settings. The program part of this command 44 // line object must not be used when appending to another command line. 45 const CommandLine& AdditionalLaunchParameters() const; 46 47 // Returns true if the Chrome Frame turndown prompt should be suppressed. 48 bool suppress_turndown_prompt() const { 49 return suppress_turndown_prompt_; 50 } 51 52 // Helper functions for reading settings from the registry 53 static void ReadUrlSettings(RendererForUrl* default_renderer, 54 std::vector<std::wstring>* renderer_exclusion_list); 55 static void ReadContentTypeSetting( 56 std::vector<std::wstring>* content_type_list); 57 static void ReadStringSetting(const char* value_name, std::wstring* value); 58 static void ReadBoolSetting(const char* value_name, bool* value); 59 60 protected: 61 PolicySettings() 62 : default_renderer_(RENDERER_NOT_SPECIFIED), 63 additional_launch_parameters_(CommandLine::NO_PROGRAM), 64 suppress_turndown_prompt_(false) { 65 RefreshFromRegistry(); 66 } 67 68 ~PolicySettings() { 69 } 70 71 // Protected for now since the class is not thread safe. 72 void RefreshFromRegistry(); 73 74 protected: 75 RendererForUrl default_renderer_; 76 std::vector<std::wstring> renderer_exclusion_list_; 77 std::vector<std::wstring> content_type_list_; 78 std::wstring application_locale_; 79 CommandLine additional_launch_parameters_; 80 bool suppress_turndown_prompt_; 81 82 private: 83 // This ensures no construction is possible outside of the class itself. 84 friend struct DefaultSingletonTraits<PolicySettings>; 85 DISALLOW_COPY_AND_ASSIGN(PolicySettings); 86 }; 87 88 #endif // CHROME_FRAME_POLICY_SETTINGS_H_ 89