Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/browser/extensions/user_script_master.h

Issue 266963003: Beginning of support for extension content verification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged latest trunk Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "extensions/browser/extension_registry_observer.h" 17 #include "extensions/browser/extension_registry_observer.h"
18 #include "extensions/common/extension_messages.h" 18 #include "extensions/common/extension_messages.h"
19 #include "extensions/common/extension_set.h" 19 #include "extensions/common/extension_set.h"
20 #include "extensions/common/user_script.h" 20 #include "extensions/common/user_script.h"
21 21
22 namespace content { 22 namespace content {
23 class RenderProcessHost; 23 class RenderProcessHost;
24 } 24 }
25 25
26 class Profile; 26 class Profile;
27 27
28 namespace extensions { 28 namespace extensions {
29 29
30 class ContentVerifier;
30 class ExtensionRegistry; 31 class ExtensionRegistry;
31 32
32 typedef std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale> 33 typedef std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale>
33 ExtensionsInfo; 34 ExtensionsInfo;
34 35
35 // Manages a segment of shared memory that contains the user scripts the user 36 // Manages a segment of shared memory that contains the user scripts the user
36 // has installed. Lives on the UI thread. 37 // has installed. Lives on the UI thread.
37 class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, 38 class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
38 public content::NotificationObserver, 39 public content::NotificationObserver,
39 public ExtensionRegistryObserver { 40 public ExtensionRegistryObserver {
40 public: 41 public:
41 explicit UserScriptMaster(Profile* profile); 42 explicit UserScriptMaster(Profile* profile);
42 43
43 // Kicks off a process on the file thread to reload scripts from disk 44 // Kicks off a process on the file thread to reload scripts from disk
44 // into a new chunk of shared memory and notify renderers. 45 // into a new chunk of shared memory and notify renderers.
45 virtual void StartLoad(); 46 virtual void StartLoad();
46 47
47 // Gets the segment of shared memory for the scripts. 48 // Gets the segment of shared memory for the scripts.
48 base::SharedMemory* GetSharedMemory() const { 49 base::SharedMemory* GetSharedMemory() const {
49 return shared_memory_.get(); 50 return shared_memory_.get();
50 } 51 }
51 52
52 // Called by the script reloader when new scripts have been loaded. 53 // Called by the script reloader when new scripts have been loaded.
53 void NewScriptsAvailable(base::SharedMemory* handle); 54 void NewScriptsAvailable(base::SharedMemory* handle);
54 55
55 // Return true if we have any scripts ready. 56 // Return true if we have any scripts ready.
56 bool ScriptsReady() const { return shared_memory_.get() != NULL; } 57 bool ScriptsReady() const { return shared_memory_.get() != NULL; }
57 58
59 // Returns the content verifier for our browser context.
60 ContentVerifier* content_verifier();
61
58 protected: 62 protected:
59 friend class base::RefCountedThreadSafe<UserScriptMaster>; 63 friend class base::RefCountedThreadSafe<UserScriptMaster>;
60 64
61 virtual ~UserScriptMaster(); 65 virtual ~UserScriptMaster();
62 66
63 public: 67 public:
64 // We reload user scripts on the file thread to prevent blocking the UI. 68 // We reload user scripts on the file thread to prevent blocking the UI.
65 // ScriptReloader lives on the file thread and does the reload 69 // ScriptReloader lives on the file thread and does the reload
66 // work, and then sends a message back to its master with a new SharedMemory*. 70 // work, and then sends a message back to its master with a new SharedMemory*.
67 // ScriptReloader is the worker that manages running the script load 71 // ScriptReloader is the worker that manages running the script load
68 // on the file thread. It must be created on, and its public API must only be 72 // on the file thread. It must be created on, and its public API must only be
69 // called from, the master's thread. 73 // called from, the master's thread.
70 class ScriptReloader 74 class ScriptReloader
71 : public base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader> { 75 : public base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader> {
72 public: 76 public:
73 // Parses the includes out of |script| and returns them in |includes|. 77 // Parses the includes out of |script| and returns them in |includes|.
74 static bool ParseMetadataHeader(const base::StringPiece& script_text, 78 static bool ParseMetadataHeader(const base::StringPiece& script_text,
75 UserScript* script); 79 UserScript* script);
76 80
77 explicit ScriptReloader(UserScriptMaster* master); 81 explicit ScriptReloader(UserScriptMaster* master);
78 82
79 // Start loading of scripts. 83 // Start loading of scripts.
80 // Will always send a message to the master upon completion. 84 // Will always send a message to the master upon completion.
81 void StartLoad(const UserScriptList& external_scripts, 85 void StartLoad(const UserScriptList& external_scripts,
82 const ExtensionsInfo& extension_info_); 86 const ExtensionsInfo& extensions_info);
83 87
84 // The master is going away; don't call it back. 88 // The master is going away; don't call it back.
85 void DisownMaster() { 89 void DisownMaster() {
86 master_ = NULL; 90 master_ = NULL;
87 } 91 }
88 92
89 private: 93 private:
90 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, SkipBOMAtTheBeginning); 94 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, SkipBOMAtTheBeginning);
91 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, LeaveBOMNotAtTheBeginning); 95 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, LeaveBOMNotAtTheBeginning);
92 friend class base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader>; 96 friend class base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader>;
(...skipping 26 matching lines...) Expand all
119 // May be NULL if DisownMaster() is called. 123 // May be NULL if DisownMaster() is called.
120 UserScriptMaster* master_; 124 UserScriptMaster* master_;
121 125
122 // Maps extension info needed for localization to an extension ID. 126 // Maps extension info needed for localization to an extension ID.
123 ExtensionsInfo extensions_info_; 127 ExtensionsInfo extensions_info_;
124 128
125 // The message loop to call our master back on. 129 // The message loop to call our master back on.
126 // Expected to always outlive us. 130 // Expected to always outlive us.
127 content::BrowserThread::ID master_thread_id_; 131 content::BrowserThread::ID master_thread_id_;
128 132
133 scoped_refptr<ContentVerifier> verifier_;
134
129 DISALLOW_COPY_AND_ASSIGN(ScriptReloader); 135 DISALLOW_COPY_AND_ASSIGN(ScriptReloader);
130 }; 136 };
131 137
132 private: 138 private:
133 // content::NotificationObserver implementation. 139 // content::NotificationObserver implementation.
134 virtual void Observe(int type, 140 virtual void Observe(int type,
135 const content::NotificationSource& source, 141 const content::NotificationSource& source,
136 const content::NotificationDetails& details) OVERRIDE; 142 const content::NotificationDetails& details) OVERRIDE;
137 143
138 // ExtensionRegistryObserver implementation. 144 // ExtensionRegistryObserver implementation.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Listen to extension load, unloaded notifications. 183 // Listen to extension load, unloaded notifications.
178 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 184 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
179 extension_registry_observer_; 185 extension_registry_observer_;
180 186
181 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); 187 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster);
182 }; 188 };
183 189
184 } // namespace extensions 190 } // namespace extensions
185 191
186 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ 192 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/test_extension_system.cc ('k') | chrome/browser/extensions/user_script_master.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698