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

Side by Side Diff: chrome/renderer/extensions/user_script_slave.h

Issue 7071025: Use WebFrame::setIsolatedWorldSecurityOrigin to allow cross-origin XHRs in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove ExtensionOriginEntry Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_
6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ 6 #define CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
9 #include <set> 10 #include <set>
10 #include <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/shared_memory.h" 15 #include "base/shared_memory.h"
15 #include "base/stl_util-inl.h" 16 #include "base/stl_util-inl.h"
16 #include "base/string_piece.h" 17 #include "base/string_piece.h"
17 #include "chrome/common/extensions/user_script.h" 18 #include "chrome/common/extensions/user_script.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
19 20
21 class Extension;
20 class ExtensionSet; 22 class ExtensionSet;
21 23
22 namespace WebKit { 24 namespace WebKit {
23 class WebFrame; 25 class WebFrame;
24 } 26 }
25 27
26 using WebKit::WebScriptSource; 28 using WebKit::WebScriptSource;
27 29
28 // Manages installed UserScripts for a render process. 30 // Manages installed UserScripts for a render process.
29 class UserScriptSlave { 31 class UserScriptSlave {
30 public: 32 public:
31 UserScriptSlave(const ExtensionSet* extensions); 33 explicit UserScriptSlave(const ExtensionSet* extensions);
32 ~UserScriptSlave(); 34 ~UserScriptSlave();
33 35
34 // Returns the unique set of extension IDs this UserScriptSlave knows about. 36 // Returns the unique set of extension IDs this UserScriptSlave knows about.
35 void GetActiveExtensions(std::set<std::string>* extension_ids); 37 void GetActiveExtensions(std::set<std::string>* extension_ids);
36 38
37 // Update the parsed scripts from shared memory. 39 // Update the parsed scripts from shared memory.
38 bool UpdateScripts(base::SharedMemoryHandle shared_memory); 40 bool UpdateScripts(base::SharedMemoryHandle shared_memory);
39 41
40 // Inject the appropriate scripts into a frame based on its URL. 42 // Inject the appropriate scripts into a frame based on its URL.
41 // TODO(aa): Extract a UserScriptFrame interface out of this to improve 43 // TODO(aa): Extract a UserScriptFrame interface out of this to improve
42 // testability. 44 // testability.
43 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location); 45 void InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location);
44 46
45 static int GetIsolatedWorldId(const std::string& extension_id); 47 static int GetIsolatedWorldId(const std::string& extension_id);
46 48
47 static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources, 49 static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources,
48 const std::string& extension_id); 50 const std::string& extension_id);
49 private: 51 private:
52 void InitializeIsolatedWorld(WebKit::WebFrame* frame,
53 int isolated_world_id,
54 const Extension* extension);
55
50 // Shared memory containing raw script data. 56 // Shared memory containing raw script data.
51 scoped_ptr<base::SharedMemory> shared_memory_; 57 scoped_ptr<base::SharedMemory> shared_memory_;
52 58
53 // Parsed script data. 59 // Parsed script data.
54 std::vector<UserScript*> scripts_; 60 std::vector<UserScript*> scripts_;
55 STLElementDeleter<std::vector<UserScript*> > script_deleter_; 61 STLElementDeleter<std::vector<UserScript*> > script_deleter_;
56 62
57 // Greasemonkey API source that is injected with the scripts. 63 // Greasemonkey API source that is injected with the scripts.
58 base::StringPiece api_js_; 64 base::StringPiece api_js_;
59 65
60 // Extension metadata. 66 // Extension metadata.
61 const ExtensionSet* extensions_; 67 const ExtensionSet* extensions_;
62 68
69 // Map from WebFrame identifier to its origin, used to allow the extension
70 // origin access to the frame (and to disallow once the frame's URL changes)
71 typedef std::map<long long, std::pair<std::string, std::string> >
72 FrameOriginMap;
73 FrameOriginMap frame_origins_;
74
75 // Map from extension ID to host permissions that have been whitelisted for
76 // it. Used to avoid whitelisting an origin more than once.
77 typedef std::multimap<std::string, URLPattern> ExtensionOriginMap;
78 ExtensionOriginMap extension_origins_;
79
63 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave); 80 DISALLOW_COPY_AND_ASSIGN(UserScriptSlave);
64 }; 81 };
65 82
66 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_ 83 #endif // CHROME_RENDERER_EXTENSIONS_USER_SCRIPT_SLAVE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698