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/browser/user_script_loader.h" | 5 #include "extensions/browser/user_script_loader.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 // though it removes the possibility that freeing the shared memory block | 437 // though it removes the possibility that freeing the shared memory block |
438 // would open up enough FDs for long enough for a retry to succeed. | 438 // would open up enough FDs for long enough for a retry to succeed. |
439 | 439 |
440 // Pretend the extension change didn't happen. | 440 // Pretend the extension change didn't happen. |
441 return; | 441 return; |
442 } | 442 } |
443 | 443 |
444 // We've got scripts ready to go. | 444 // We've got scripts ready to go. |
445 shared_memory_.reset(shared_memory.release()); | 445 shared_memory_.reset(shared_memory.release()); |
446 | 446 |
447 for (content::RenderProcessHost::iterator i( | 447 // If user scripts are comming from a <webview>, will only notify the |
Nico
2015/03/05 00:40:11
nit: "coming"
| |
448 content::RenderProcessHost::AllHostsIterator()); | 448 // RenderProcessHost of that <webview>; otherwise will notify all of the |
449 !i.IsAtEnd(); | 449 // RenderProcessHosts. |
450 i.Advance()) { | 450 if (user_scripts && !user_scripts->empty() && |
451 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); | 451 (*user_scripts)[0].consumer_instance_type() == |
452 UserScript::ConsumerInstanceType::WEBVIEW) { | |
453 DCHECK_EQ(1u, user_scripts->size()); | |
454 int render_process_id = (*user_scripts)[0].routing_info().render_process_id; | |
455 content::RenderProcessHost* host = | |
456 content::RenderProcessHost::FromID(render_process_id); | |
457 if (host) | |
458 SendUpdate(host, shared_memory_.get(), changed_hosts_); | |
459 } else { | |
460 for (content::RenderProcessHost::iterator i( | |
461 content::RenderProcessHost::AllHostsIterator()); | |
462 !i.IsAtEnd(); i.Advance()) { | |
463 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); | |
464 } | |
452 } | 465 } |
453 changed_hosts_.clear(); | 466 changed_hosts_.clear(); |
454 | 467 |
455 content::NotificationService::current()->Notify( | 468 content::NotificationService::current()->Notify( |
456 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, | 469 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, |
457 content::Source<BrowserContext>(browser_context_), | 470 content::Source<BrowserContext>(browser_context_), |
458 content::Details<base::SharedMemory>(shared_memory_.get())); | 471 content::Details<base::SharedMemory>(shared_memory_.get())); |
459 } | 472 } |
460 | 473 |
461 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process, | 474 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process, |
(...skipping 24 matching lines...) Expand all Loading... | |
486 for (const HostID& id : changed_hosts) | 499 for (const HostID& id : changed_hosts) |
487 changed_ids_set.insert(id.id()); | 500 changed_ids_set.insert(id.id()); |
488 | 501 |
489 if (base::SharedMemory::IsHandleValid(handle_for_process)) { | 502 if (base::SharedMemory::IsHandleValid(handle_for_process)) { |
490 process->Send(new ExtensionMsg_UpdateUserScripts( | 503 process->Send(new ExtensionMsg_UpdateUserScripts( |
491 handle_for_process, host_id().id(), changed_ids_set)); | 504 handle_for_process, host_id().id(), changed_ids_set)); |
492 } | 505 } |
493 } | 506 } |
494 | 507 |
495 } // namespace extensions | 508 } // namespace extensions |
OLD | NEW |