OLD | NEW |
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 #include "chrome/browser/extensions/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/version.h" | 18 #include "base/version.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_file_util.h" | 23 #include "chrome/common/extensions/extension_file_util.h" |
24 #include "chrome/common/extensions/extension_message_bundle.h" | 24 #include "chrome/common/extensions/extension_message_bundle.h" |
25 #include "chrome/common/extensions/extension_resource.h" | 25 #include "chrome/common/extensions/extension_resource.h" |
26 #include "chrome/common/extensions/extension_set.h" | 26 #include "chrome/common/extensions/extension_set.h" |
27 #include "content/browser/renderer_host/render_process_host.h" | 27 #include "content/browser/renderer_host/render_process_host.h" |
28 #include "content/common/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
29 | 29 |
30 // Helper function to parse greasesmonkey headers | 30 // Helper function to parse greasesmonkey headers |
31 static bool GetDeclarationValue(const base::StringPiece& line, | 31 static bool GetDeclarationValue(const base::StringPiece& line, |
32 const base::StringPiece& prefix, | 32 const base::StringPiece& prefix, |
33 std::string* value) { | 33 std::string* value) { |
34 base::StringPiece::size_type index = line.find(prefix); | 34 base::StringPiece::size_type index = line.find(prefix); |
35 if (index == base::StringPiece::npos) | 35 if (index == base::StringPiece::npos) |
36 return false; | 36 return false; |
37 | 37 |
38 std::string temp(line.data() + index + prefix.length(), | 38 std::string temp(line.data() + index + prefix.length(), |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 : extensions_service_ready_(false), | 288 : extensions_service_ready_(false), |
289 pending_load_(false), | 289 pending_load_(false), |
290 profile_(profile) { | 290 profile_(profile) { |
291 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 291 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
292 content::Source<Profile>(profile_)); | 292 content::Source<Profile>(profile_)); |
293 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 293 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
294 content::Source<Profile>(profile_)); | 294 content::Source<Profile>(profile_)); |
295 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 295 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
296 content::Source<Profile>(profile_)); | 296 content::Source<Profile>(profile_)); |
297 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 297 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
298 NotificationService::AllBrowserContextsAndSources()); | 298 content::NotificationService::AllBrowserContextsAndSources()); |
299 } | 299 } |
300 | 300 |
301 UserScriptMaster::~UserScriptMaster() { | 301 UserScriptMaster::~UserScriptMaster() { |
302 if (script_reloader_) | 302 if (script_reloader_) |
303 script_reloader_->DisownMaster(); | 303 script_reloader_->DisownMaster(); |
304 } | 304 } |
305 | 305 |
306 void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) { | 306 void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) { |
307 // Ensure handle is deleted or released. | 307 // Ensure handle is deleted or released. |
308 scoped_ptr<base::SharedMemory> handle_deleter(handle); | 308 scoped_ptr<base::SharedMemory> handle_deleter(handle); |
309 | 309 |
310 if (pending_load_) { | 310 if (pending_load_) { |
311 // While we were loading, there were further changes. Don't bother | 311 // While we were loading, there were further changes. Don't bother |
312 // notifying about these scripts and instead just immediately reload. | 312 // notifying about these scripts and instead just immediately reload. |
313 pending_load_ = false; | 313 pending_load_ = false; |
314 StartLoad(); | 314 StartLoad(); |
315 } else { | 315 } else { |
316 // We're no longer loading. | 316 // We're no longer loading. |
317 script_reloader_ = NULL; | 317 script_reloader_ = NULL; |
318 // We've got scripts ready to go. | 318 // We've got scripts ready to go. |
319 shared_memory_.swap(handle_deleter); | 319 shared_memory_.swap(handle_deleter); |
320 | 320 |
321 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 321 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
322 !i.IsAtEnd(); i.Advance()) { | 322 !i.IsAtEnd(); i.Advance()) { |
323 SendUpdate(i.GetCurrentValue(), handle); | 323 SendUpdate(i.GetCurrentValue(), handle); |
324 } | 324 } |
325 | 325 |
326 NotificationService::current()->Notify( | 326 content::NotificationService::current()->Notify( |
327 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 327 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
328 content::Source<Profile>(profile_), | 328 content::Source<Profile>(profile_), |
329 content::Details<base::SharedMemory>(handle)); | 329 content::Details<base::SharedMemory>(handle)); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 void UserScriptMaster::Observe(int type, | 333 void UserScriptMaster::Observe(int type, |
334 const content::NotificationSource& source, | 334 const content::NotificationSource& source, |
335 const content::NotificationDetails& details) { | 335 const content::NotificationDetails& details) { |
336 bool should_start_load = false; | 336 bool should_start_load = false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 if (!handle) | 421 if (!handle) |
422 return; | 422 return; |
423 | 423 |
424 base::SharedMemoryHandle handle_for_process; | 424 base::SharedMemoryHandle handle_for_process; |
425 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 425 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
426 return; // This can legitimately fail if the renderer asserts at startup. | 426 return; // This can legitimately fail if the renderer asserts at startup. |
427 | 427 |
428 if (base::SharedMemory::IsHandleValid(handle_for_process)) | 428 if (base::SharedMemory::IsHandleValid(handle_for_process)) |
429 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); | 429 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); |
430 } | 430 } |
OLD | NEW |