| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace extensions { |
| 33 |
| 32 // Helper function to parse greasesmonkey headers | 34 // Helper function to parse greasesmonkey headers |
| 33 static bool GetDeclarationValue(const base::StringPiece& line, | 35 static bool GetDeclarationValue(const base::StringPiece& line, |
| 34 const base::StringPiece& prefix, | 36 const base::StringPiece& prefix, |
| 35 std::string* value) { | 37 std::string* value) { |
| 36 base::StringPiece::size_type index = line.find(prefix); | 38 base::StringPiece::size_type index = line.find(prefix); |
| 37 if (index == base::StringPiece::npos) | 39 if (index == base::StringPiece::npos) |
| 38 return false; | 40 return false; |
| 39 | 41 |
| 40 std::string temp(line.data() + index + prefix.length(), | 42 std::string temp(line.data() + index + prefix.length(), |
| 41 line.length() - index - prefix.length()); | 43 line.length() - index - prefix.length()); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 const content::NotificationSource& source, | 345 const content::NotificationSource& source, |
| 344 const content::NotificationDetails& details) { | 346 const content::NotificationDetails& details) { |
| 345 bool should_start_load = false; | 347 bool should_start_load = false; |
| 346 switch (type) { | 348 switch (type) { |
| 347 case chrome::NOTIFICATION_EXTENSIONS_READY: | 349 case chrome::NOTIFICATION_EXTENSIONS_READY: |
| 348 extensions_service_ready_ = true; | 350 extensions_service_ready_ = true; |
| 349 should_start_load = true; | 351 should_start_load = true; |
| 350 break; | 352 break; |
| 351 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 353 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 352 // Add any content scripts inside the extension. | 354 // Add any content scripts inside the extension. |
| 353 const extensions::Extension* extension = | 355 const Extension* extension = |
| 354 content::Details<const extensions::Extension>(details).ptr(); | 356 content::Details<const Extension>(details).ptr(); |
| 355 extensions_info_[extension->id()] = | 357 extensions_info_[extension->id()] = |
| 356 ExtensionSet::ExtensionPathAndDefaultLocale( | 358 ExtensionSet::ExtensionPathAndDefaultLocale( |
| 357 extension->path(), extension->default_locale()); | 359 extension->path(), extension->default_locale()); |
| 358 bool incognito_enabled = profile_->GetExtensionService()-> | 360 bool incognito_enabled = profile_->GetExtensionService()-> |
| 359 IsIncognitoEnabled(extension->id()); | 361 IsIncognitoEnabled(extension->id()); |
| 360 const UserScriptList& scripts = extension->content_scripts(); | 362 const UserScriptList& scripts = extension->content_scripts(); |
| 361 for (UserScriptList::const_iterator iter = scripts.begin(); | 363 for (UserScriptList::const_iterator iter = scripts.begin(); |
| 362 iter != scripts.end(); ++iter) { | 364 iter != scripts.end(); ++iter) { |
| 363 user_scripts_.push_back(*iter); | 365 user_scripts_.push_back(*iter); |
| 364 user_scripts_.back().set_incognito_enabled(incognito_enabled); | 366 user_scripts_.back().set_incognito_enabled(incognito_enabled); |
| 365 } | 367 } |
| 366 if (extensions_service_ready_) | 368 if (extensions_service_ready_) |
| 367 should_start_load = true; | 369 should_start_load = true; |
| 368 break; | 370 break; |
| 369 } | 371 } |
| 370 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 372 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 371 // Remove any content scripts. | 373 // Remove any content scripts. |
| 372 const extensions::Extension* extension = | 374 const Extension* extension = |
| 373 content::Details<extensions::UnloadedExtensionInfo>( | 375 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 374 details)->extension; | |
| 375 extensions_info_.erase(extension->id()); | 376 extensions_info_.erase(extension->id()); |
| 376 UserScriptList new_user_scripts; | 377 UserScriptList new_user_scripts; |
| 377 for (UserScriptList::iterator iter = user_scripts_.begin(); | 378 for (UserScriptList::iterator iter = user_scripts_.begin(); |
| 378 iter != user_scripts_.end(); ++iter) { | 379 iter != user_scripts_.end(); ++iter) { |
| 379 if (iter->extension_id() != extension->id()) | 380 if (iter->extension_id() != extension->id()) |
| 380 new_user_scripts.push_back(*iter); | 381 new_user_scripts.push_back(*iter); |
| 381 } | 382 } |
| 382 user_scripts_ = new_user_scripts; | 383 user_scripts_ = new_user_scripts; |
| 383 should_start_load = true; | 384 should_start_load = true; |
| 384 | 385 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (!handle) | 432 if (!handle) |
| 432 return; | 433 return; |
| 433 | 434 |
| 434 base::SharedMemoryHandle handle_for_process; | 435 base::SharedMemoryHandle handle_for_process; |
| 435 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 436 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
| 436 return; // This can legitimately fail if the renderer asserts at startup. | 437 return; // This can legitimately fail if the renderer asserts at startup. |
| 437 | 438 |
| 438 if (base::SharedMemory::IsHandleValid(handle_for_process)) | 439 if (base::SharedMemory::IsHandleValid(handle_for_process)) |
| 439 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); | 440 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); |
| 440 } | 441 } |
| 442 |
| 443 } // namespace extensions |
| OLD | NEW |