OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "extensions/renderer/user_script_set.h" | 5 #include "extensions/renderer/user_script_set.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "content/public/common/url_constants.h" | 8 #include "content/public/common/url_constants.h" |
9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool whitelisted_only) { | 91 bool whitelisted_only) { |
92 bool only_inject_incognito = | 92 bool only_inject_incognito = |
93 ExtensionsRendererClient::Get()->IsIncognitoProcess(); | 93 ExtensionsRendererClient::Get()->IsIncognitoProcess(); |
94 | 94 |
95 // Create the shared memory object (read only). | 95 // Create the shared memory object (read only). |
96 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 96 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
97 if (!shared_memory_.get()) | 97 if (!shared_memory_.get()) |
98 return false; | 98 return false; |
99 | 99 |
100 // First get the size of the memory block. | 100 // First get the size of the memory block. |
101 if (!shared_memory_->Map(sizeof(Pickle::Header))) | 101 if (!shared_memory_->Map(sizeof(base::Pickle::Header))) |
102 return false; | 102 return false; |
103 Pickle::Header* pickle_header = | 103 base::Pickle::Header* pickle_header = |
104 reinterpret_cast<Pickle::Header*>(shared_memory_->memory()); | 104 reinterpret_cast<base::Pickle::Header*>(shared_memory_->memory()); |
105 | 105 |
106 // Now map in the rest of the block. | 106 // Now map in the rest of the block. |
107 int pickle_size = sizeof(Pickle::Header) + pickle_header->payload_size; | 107 int pickle_size = sizeof(base::Pickle::Header) + pickle_header->payload_size; |
108 shared_memory_->Unmap(); | 108 shared_memory_->Unmap(); |
109 if (!shared_memory_->Map(pickle_size)) | 109 if (!shared_memory_->Map(pickle_size)) |
110 return false; | 110 return false; |
111 | 111 |
112 // Unpickle scripts. | 112 // Unpickle scripts. |
113 size_t num_scripts = 0; | 113 size_t num_scripts = 0; |
114 Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()), pickle_size); | 114 base::Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()), |
115 PickleIterator iter(pickle); | 115 pickle_size); |
| 116 base::PickleIterator iter(pickle); |
116 CHECK(iter.ReadSizeT(&num_scripts)); | 117 CHECK(iter.ReadSizeT(&num_scripts)); |
117 | 118 |
118 scripts_.clear(); | 119 scripts_.clear(); |
119 scripts_.reserve(num_scripts); | 120 scripts_.reserve(num_scripts); |
120 for (size_t i = 0; i < num_scripts; ++i) { | 121 for (size_t i = 0; i < num_scripts; ++i) { |
121 scoped_ptr<UserScript> script(new UserScript()); | 122 scoped_ptr<UserScript> script(new UserScript()); |
122 script->Unpickle(pickle, &iter); | 123 script->Unpickle(pickle, &iter); |
123 | 124 |
124 // Note that this is a pointer into shared memory. We don't own it. It gets | 125 // Note that this is a pointer into shared memory. We don't own it. It gets |
125 // cleared up when the last renderer or browser process drops their | 126 // cleared up when the last renderer or browser process drops their |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 injector.Pass(), | 239 injector.Pass(), |
239 web_frame->toWebLocalFrame(), | 240 web_frame->toWebLocalFrame(), |
240 injection_host.Pass(), | 241 injection_host.Pass(), |
241 run_location, | 242 run_location, |
242 tab_id)); | 243 tab_id)); |
243 } | 244 } |
244 return injection.Pass(); | 245 return injection.Pass(); |
245 } | 246 } |
246 | 247 |
247 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |