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

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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 // TODO(aa): Do we want to do something smarter for the scripts that have 377 // TODO(aa): Do we want to do something smarter for the scripts that have
378 // already been injected? 378 // already been injected?
379 379
380 break; 380 break;
381 } 381 }
382 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 382 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
383 RenderProcessHost* process = 383 RenderProcessHost* process =
384 content::Source<RenderProcessHost>(source).ptr(); 384 content::Source<RenderProcessHost>(source).ptr();
385 Profile* profile = Profile::FromBrowserContext( 385 Profile* profile = Profile::FromBrowserContext(
386 process->browser_context()); 386 process->GetBrowserContext());
387 if (!profile_->IsSameProfile(profile)) 387 if (!profile_->IsSameProfile(profile))
388 return; 388 return;
389 if (ScriptsReady()) 389 if (ScriptsReady())
390 SendUpdate(process, GetSharedMemory()); 390 SendUpdate(process, GetSharedMemory());
391 break; 391 break;
392 } 392 }
393 default: 393 default:
394 DCHECK(false); 394 DCHECK(false);
395 } 395 }
396 396
397 if (should_start_load) { 397 if (should_start_load) {
398 if (script_reloader_) { 398 if (script_reloader_) {
399 pending_load_ = true; 399 pending_load_ = true;
400 } else { 400 } else {
401 StartLoad(); 401 StartLoad();
402 } 402 }
403 } 403 }
404 } 404 }
405 405
406 void UserScriptMaster::StartLoad() { 406 void UserScriptMaster::StartLoad() {
407 if (!script_reloader_) 407 if (!script_reloader_)
408 script_reloader_ = new ScriptReloader(this); 408 script_reloader_ = new ScriptReloader(this);
409 409
410 script_reloader_->StartLoad(user_scripts_, extensions_info_); 410 script_reloader_->StartLoad(user_scripts_, extensions_info_);
411 } 411 }
412 412
413 void UserScriptMaster::SendUpdate(RenderProcessHost* process, 413 void UserScriptMaster::SendUpdate(RenderProcessHost* process,
414 base::SharedMemory* shared_memory) { 414 base::SharedMemory* shared_memory) {
415 Profile* profile = Profile::FromBrowserContext(process->browser_context()); 415 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
416 // Make sure we only send user scripts to processes in our profile. 416 // Make sure we only send user scripts to processes in our profile.
417 if (!profile_->IsSameProfile(profile)) 417 if (!profile_->IsSameProfile(profile))
418 return; 418 return;
419 419
420 // If the process is being started asynchronously, early return. We'll end up 420 // 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. 421 // calling InitUserScripts when it's created which will call this again.
422 base::ProcessHandle handle = process->GetHandle(); 422 base::ProcessHandle handle = process->GetHandle();
423 if (!handle) 423 if (!handle)
424 return; 424 return;
425 425
426 base::SharedMemoryHandle handle_for_process; 426 base::SharedMemoryHandle handle_for_process;
427 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 427 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
428 return; // This can legitimately fail if the renderer asserts at startup. 428 return; // This can legitimately fail if the renderer asserts at startup.
429 429
430 if (base::SharedMemory::IsHandleValid(handle_for_process)) 430 if (base::SharedMemory::IsHandleValid(handle_for_process))
431 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); 431 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
432 } 432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698