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

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

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 #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"
28 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/render_process_host.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 // Helper function to parse greasesmonkey headers 32 // Helper function to parse greasesmonkey headers
33 static bool GetDeclarationValue(const base::StringPiece& line, 33 static bool GetDeclarationValue(const base::StringPiece& line,
34 const base::StringPiece& prefix, 34 const base::StringPiece& prefix,
35 std::string* value) { 35 std::string* value) {
36 base::StringPiece::size_type index = line.find(prefix); 36 base::StringPiece::size_type index = line.find(prefix);
37 if (index == base::StringPiece::npos) 37 if (index == base::StringPiece::npos)
38 return false; 38 return false;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // While we were loading, there were further changes. Don't bother 313 // While we were loading, there were further changes. Don't bother
314 // notifying about these scripts and instead just immediately reload. 314 // notifying about these scripts and instead just immediately reload.
315 pending_load_ = false; 315 pending_load_ = false;
316 StartLoad(); 316 StartLoad();
317 } else { 317 } else {
318 // We're no longer loading. 318 // We're no longer loading.
319 script_reloader_ = NULL; 319 script_reloader_ = NULL;
320 // We've got scripts ready to go. 320 // We've got scripts ready to go.
321 shared_memory_.swap(handle_deleter); 321 shared_memory_.swap(handle_deleter);
322 322
323 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 323 for (content::RenderProcessHost::iterator i(
324 content::RenderProcessHost::AllHostsIterator());
324 !i.IsAtEnd(); i.Advance()) { 325 !i.IsAtEnd(); i.Advance()) {
325 SendUpdate(i.GetCurrentValue(), handle); 326 SendUpdate(i.GetCurrentValue(), handle);
326 } 327 }
327 328
328 content::NotificationService::current()->Notify( 329 content::NotificationService::current()->Notify(
329 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, 330 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED,
330 content::Source<Profile>(profile_), 331 content::Source<Profile>(profile_),
331 content::Details<base::SharedMemory>(handle)); 332 content::Details<base::SharedMemory>(handle));
332 } 333 }
333 } 334 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 374 }
374 user_scripts_ = new_user_scripts; 375 user_scripts_ = new_user_scripts;
375 should_start_load = true; 376 should_start_load = true;
376 377
377 // TODO(aa): Do we want to do something smarter for the scripts that have 378 // TODO(aa): Do we want to do something smarter for the scripts that have
378 // already been injected? 379 // already been injected?
379 380
380 break; 381 break;
381 } 382 }
382 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 383 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
383 RenderProcessHost* process = 384 content::RenderProcessHost* process =
384 content::Source<RenderProcessHost>(source).ptr(); 385 content::Source<content::RenderProcessHost>(source).ptr();
385 Profile* profile = Profile::FromBrowserContext( 386 Profile* profile = Profile::FromBrowserContext(
386 process->browser_context()); 387 process->GetBrowserContext());
387 if (!profile_->IsSameProfile(profile)) 388 if (!profile_->IsSameProfile(profile))
388 return; 389 return;
389 if (ScriptsReady()) 390 if (ScriptsReady())
390 SendUpdate(process, GetSharedMemory()); 391 SendUpdate(process, GetSharedMemory());
391 break; 392 break;
392 } 393 }
393 default: 394 default:
394 DCHECK(false); 395 DCHECK(false);
395 } 396 }
396 397
397 if (should_start_load) { 398 if (should_start_load) {
398 if (script_reloader_) { 399 if (script_reloader_) {
399 pending_load_ = true; 400 pending_load_ = true;
400 } else { 401 } else {
401 StartLoad(); 402 StartLoad();
402 } 403 }
403 } 404 }
404 } 405 }
405 406
406 void UserScriptMaster::StartLoad() { 407 void UserScriptMaster::StartLoad() {
407 if (!script_reloader_) 408 if (!script_reloader_)
408 script_reloader_ = new ScriptReloader(this); 409 script_reloader_ = new ScriptReloader(this);
409 410
410 script_reloader_->StartLoad(user_scripts_, extensions_info_); 411 script_reloader_->StartLoad(user_scripts_, extensions_info_);
411 } 412 }
412 413
413 void UserScriptMaster::SendUpdate(RenderProcessHost* process, 414 void UserScriptMaster::SendUpdate(content::RenderProcessHost* process,
414 base::SharedMemory* shared_memory) { 415 base::SharedMemory* shared_memory) {
415 Profile* profile = Profile::FromBrowserContext(process->browser_context()); 416 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
416 // Make sure we only send user scripts to processes in our profile. 417 // Make sure we only send user scripts to processes in our profile.
417 if (!profile_->IsSameProfile(profile)) 418 if (!profile_->IsSameProfile(profile))
418 return; 419 return;
419 420
420 // If the process is being started asynchronously, early return. We'll end up 421 // If the process is being started asynchronously, early return. We'll end up
421 // calling InitUserScripts when it's created which will call this again. 422 // calling InitUserScripts when it's created which will call this again.
422 base::ProcessHandle handle = process->GetHandle(); 423 base::ProcessHandle handle = process->GetHandle();
423 if (!handle) 424 if (!handle)
424 return; 425 return;
425 426
426 base::SharedMemoryHandle handle_for_process; 427 base::SharedMemoryHandle handle_for_process;
427 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 428 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
428 return; // This can legitimately fail if the renderer asserts at startup. 429 return; // This can legitimately fail if the renderer asserts at startup.
429 430
430 if (base::SharedMemory::IsHandleValid(handle_for_process)) 431 if (base::SharedMemory::IsHandleValid(handle_for_process))
431 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); 432 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
432 } 433 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/user_script_master.h ('k') | chrome/browser/external_tab_container_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698