web_contents_preferences.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
  5. #define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
  6. #include <vector>
  7. #include "base/values.h"
  8. #include "content/public/browser/web_contents_user_data.h"
  9. namespace base {
  10. class CommandLine;
  11. }
  12. namespace content {
  13. struct WebPreferences;
  14. }
  15. namespace mate {
  16. class Dictionary;
  17. }
  18. namespace atom {
  19. // Stores and applies the preferences of WebContents.
  20. class WebContentsPreferences
  21. : public content::WebContentsUserData<WebContentsPreferences> {
  22. public:
  23. // Get WebContents according to process ID.
  24. // FIXME(zcbenz): This method does not belong here.
  25. static content::WebContents* GetWebContentsFromProcessID(int process_id);
  26. // Append command paramters according to |web_contents|'s preferences.
  27. static void AppendExtraCommandLineSwitches(
  28. content::WebContents* web_contents, base::CommandLine* command_line);
  29. static bool IsSandboxed(content::WebContents* web_contents);
  30. // Modify the WebPreferences according to |web_contents|'s preferences.
  31. static void OverrideWebkitPrefs(
  32. content::WebContents* web_contents, content::WebPreferences* prefs);
  33. WebContentsPreferences(content::WebContents* web_contents,
  34. const mate::Dictionary& web_preferences);
  35. ~WebContentsPreferences() override;
  36. // $.extend(|web_preferences_|, |new_web_preferences|).
  37. void Merge(const base::DictionaryValue& new_web_preferences);
  38. // Returns the web preferences.
  39. base::DictionaryValue* web_preferences() { return &web_preferences_; }
  40. private:
  41. friend class content::WebContentsUserData<WebContentsPreferences>;
  42. static std::vector<WebContentsPreferences*> instances_;
  43. content::WebContents* web_contents_;
  44. base::DictionaryValue web_preferences_;
  45. DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
  46. };
  47. } // namespace atom
  48. #endif // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_