OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/pickle.h" | 13 #include "base/pickle.h" |
14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/thread.h" | 16 #include "base/thread.h" |
17 #include "base/version.h" | 17 #include "base/version.h" |
18 #include "chrome/browser/extensions/extensions_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
25 | 25 |
26 | 26 |
27 // Helper function to parse greasesmonkey headers | 27 // Helper function to parse greasesmonkey headers |
28 static bool GetDeclarationValue(const base::StringPiece& line, | 28 static bool GetDeclarationValue(const base::StringPiece& line, |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 const NotificationSource& source, | 332 const NotificationSource& source, |
333 const NotificationDetails& details) { | 333 const NotificationDetails& details) { |
334 switch (type.value) { | 334 switch (type.value) { |
335 case NotificationType::EXTENSIONS_READY: | 335 case NotificationType::EXTENSIONS_READY: |
336 extensions_service_ready_ = true; | 336 extensions_service_ready_ = true; |
337 StartScan(); | 337 StartScan(); |
338 break; | 338 break; |
339 case NotificationType::EXTENSION_LOADED: { | 339 case NotificationType::EXTENSION_LOADED: { |
340 // Add any content scripts inside the extension. | 340 // Add any content scripts inside the extension. |
341 const Extension* extension = Details<const Extension>(details).ptr(); | 341 const Extension* extension = Details<const Extension>(details).ptr(); |
342 bool incognito_enabled = profile_->GetExtensionsService()-> | 342 bool incognito_enabled = profile_->GetExtensionService()-> |
343 IsIncognitoEnabled(extension); | 343 IsIncognitoEnabled(extension); |
344 bool allow_file_access = profile_->GetExtensionsService()-> | 344 bool allow_file_access = profile_->GetExtensionService()-> |
345 AllowFileAccess(extension); | 345 AllowFileAccess(extension); |
346 const UserScriptList& scripts = extension->content_scripts(); | 346 const UserScriptList& scripts = extension->content_scripts(); |
347 for (UserScriptList::const_iterator iter = scripts.begin(); | 347 for (UserScriptList::const_iterator iter = scripts.begin(); |
348 iter != scripts.end(); ++iter) { | 348 iter != scripts.end(); ++iter) { |
349 lone_scripts_.push_back(*iter); | 349 lone_scripts_.push_back(*iter); |
350 lone_scripts_.back().set_incognito_enabled(incognito_enabled); | 350 lone_scripts_.back().set_incognito_enabled(incognito_enabled); |
351 lone_scripts_.back().set_allow_file_access(allow_file_access); | 351 lone_scripts_.back().set_allow_file_access(allow_file_access); |
352 } | 352 } |
353 if (extensions_service_ready_) | 353 if (extensions_service_ready_) |
354 StartScan(); | 354 StartScan(); |
(...skipping 12 matching lines...) Expand all Loading... |
367 StartScan(); | 367 StartScan(); |
368 | 368 |
369 // TODO(aa): Do we want to do something smarter for the scripts that have | 369 // TODO(aa): Do we want to do something smarter for the scripts that have |
370 // already been injected? | 370 // already been injected? |
371 | 371 |
372 break; | 372 break; |
373 } | 373 } |
374 case NotificationType::EXTENSION_USER_SCRIPTS_UPDATED: { | 374 case NotificationType::EXTENSION_USER_SCRIPTS_UPDATED: { |
375 const Extension* extension = Details<const Extension>(details).ptr(); | 375 const Extension* extension = Details<const Extension>(details).ptr(); |
376 UserScriptList new_lone_scripts; | 376 UserScriptList new_lone_scripts; |
377 bool incognito_enabled = profile_->GetExtensionsService()-> | 377 bool incognito_enabled = profile_->GetExtensionService()-> |
378 IsIncognitoEnabled(extension); | 378 IsIncognitoEnabled(extension); |
379 bool allow_file_access = profile_->GetExtensionsService()-> | 379 bool allow_file_access = profile_->GetExtensionService()-> |
380 AllowFileAccess(extension); | 380 AllowFileAccess(extension); |
381 for (UserScriptList::iterator iter = lone_scripts_.begin(); | 381 for (UserScriptList::iterator iter = lone_scripts_.begin(); |
382 iter != lone_scripts_.end(); ++iter) { | 382 iter != lone_scripts_.end(); ++iter) { |
383 if (iter->extension_id() == extension->id()) { | 383 if (iter->extension_id() == extension->id()) { |
384 iter->set_incognito_enabled(incognito_enabled); | 384 iter->set_incognito_enabled(incognito_enabled); |
385 iter->set_allow_file_access(allow_file_access); | 385 iter->set_allow_file_access(allow_file_access); |
386 } | 386 } |
387 } | 387 } |
388 StartScan(); | 388 StartScan(); |
389 break; | 389 break; |
390 } | 390 } |
391 | 391 |
392 default: | 392 default: |
393 DCHECK(false); | 393 DCHECK(false); |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 void UserScriptMaster::StartScan() { | 397 void UserScriptMaster::StartScan() { |
398 if (!script_reloader_) | 398 if (!script_reloader_) |
399 script_reloader_ = new ScriptReloader(this); | 399 script_reloader_ = new ScriptReloader(this); |
400 | 400 |
401 script_reloader_->StartScan(user_script_dir_, lone_scripts_); | 401 script_reloader_->StartScan(user_script_dir_, lone_scripts_); |
402 } | 402 } |
OLD | NEW |