| 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/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 &script_data->match_about_blank)); | 343 &script_data->match_about_blank)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 return true; | 346 return true; |
| 347 } | 347 } |
| 348 | 348 |
| 349 RequestContentScript::RequestContentScript( | 349 RequestContentScript::RequestContentScript( |
| 350 content::BrowserContext* browser_context, | 350 content::BrowserContext* browser_context, |
| 351 const Extension* extension, | 351 const Extension* extension, |
| 352 const ScriptData& script_data) { | 352 const ScriptData& script_data) { |
| 353 InitScript(extension, script_data); | |
| 354 | |
| 355 master_ = ExtensionSystem::Get(browser_context) | 353 master_ = ExtensionSystem::Get(browser_context) |
| 356 ->declarative_user_script_manager() | 354 ->declarative_user_script_manager() |
| 357 ->GetDeclarativeUserScriptMasterByID(extension->id()); | 355 ->GetDeclarativeUserScriptMasterByID(extension->id()); |
| 356 InitScript(extension, script_data); |
| 358 AddScript(); | 357 AddScript(); |
| 359 } | 358 } |
| 360 | 359 |
| 361 RequestContentScript::RequestContentScript( | 360 RequestContentScript::RequestContentScript( |
| 362 DeclarativeUserScriptMaster* master, | 361 DeclarativeUserScriptMaster* master, |
| 363 const Extension* extension, | 362 const Extension* extension, |
| 364 const ScriptData& script_data) { | 363 const ScriptData& script_data) { |
| 364 master_ = master; |
| 365 InitScript(extension, script_data); | 365 InitScript(extension, script_data); |
| 366 | |
| 367 master_ = master; | |
| 368 AddScript(); | 366 AddScript(); |
| 369 } | 367 } |
| 370 | 368 |
| 371 RequestContentScript::~RequestContentScript() { | 369 RequestContentScript::~RequestContentScript() { |
| 372 DCHECK(master_); | 370 DCHECK(master_); |
| 373 master_->RemoveScript(script_); | 371 master_->RemoveScript(script_); |
| 374 } | 372 } |
| 375 | 373 |
| 376 void RequestContentScript::InitScript(const Extension* extension, | 374 void RequestContentScript::InitScript(const Extension* extension, |
| 377 const ScriptData& script_data) { | 375 const ScriptData& script_data) { |
| 378 script_.set_id(UserScript::GenerateUserScriptID()); | 376 script_.set_id(UserScript::GenerateUserScriptID()); |
| 379 script_.set_extension_id(extension->id()); | 377 script_.set_consumer_id(master_->consumer_id()); |
| 380 script_.set_run_location(UserScript::BROWSER_DRIVEN); | 378 script_.set_run_location(UserScript::BROWSER_DRIVEN); |
| 381 script_.set_match_all_frames(script_data.all_frames); | 379 script_.set_match_all_frames(script_data.all_frames); |
| 382 script_.set_match_about_blank(script_data.match_about_blank); | 380 script_.set_match_about_blank(script_data.match_about_blank); |
| 383 for (std::vector<std::string>::const_iterator it = | 381 for (std::vector<std::string>::const_iterator it = |
| 384 script_data.css_file_names.begin(); | 382 script_data.css_file_names.begin(); |
| 385 it != script_data.css_file_names.end(); ++it) { | 383 it != script_data.css_file_names.end(); ++it) { |
| 386 GURL url = extension->GetResourceURL(*it); | 384 GURL url = extension->GetResourceURL(*it); |
| 387 ExtensionResource resource = extension->GetResource(*it); | 385 ExtensionResource resource = extension->GetResource(*it); |
| 388 script_.css_scripts().push_back(UserScript::File( | 386 script_.css_scripts().push_back(UserScript::File( |
| 389 resource.extension_root(), resource.relative_path(), url)); | 387 resource.extension_root(), resource.relative_path(), url)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 bool* bad_message, | 494 bool* bad_message, |
| 497 const base::DictionaryValue** action_dict, | 495 const base::DictionaryValue** action_dict, |
| 498 std::string* instance_type) { | 496 std::string* instance_type) { |
| 499 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); | 497 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); |
| 500 INPUT_FORMAT_VALIDATE( | 498 INPUT_FORMAT_VALIDATE( |
| 501 (*action_dict)->GetString(keys::kInstanceType, instance_type)); | 499 (*action_dict)->GetString(keys::kInstanceType, instance_type)); |
| 502 return true; | 500 return true; |
| 503 } | 501 } |
| 504 | 502 |
| 505 } // namespace extensions | 503 } // namespace extensions |
| OLD | NEW |