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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_action.cc

Issue 2227193002: Make UserScript non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove browser/renderer specific file impl as it is not helping much Created 4 years, 4 months 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
OLDNEW
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/macros.h" 10 #include "base/macros.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 const ScriptData& script_data) { 324 const ScriptData& script_data) {
325 HostID host_id(HostID::EXTENSIONS, extension->id()); 325 HostID host_id(HostID::EXTENSIONS, extension->id());
326 InitScript(host_id, extension, script_data); 326 InitScript(host_id, extension, script_data);
327 327
328 master_ = master; 328 master_ = master;
329 AddScript(); 329 AddScript();
330 } 330 }
331 331
332 RequestContentScript::~RequestContentScript() { 332 RequestContentScript::~RequestContentScript() {
333 DCHECK(master_); 333 DCHECK(master_);
334 master_->RemoveScript(script_); 334 master_->RemoveScript(UserScriptIDPair(script_.id(), script_.host_id()));
335 } 335 }
336 336
337 void RequestContentScript::InitScript(const HostID& host_id, 337 void RequestContentScript::InitScript(const HostID& host_id,
338 const Extension* extension, 338 const Extension* extension,
339 const ScriptData& script_data) { 339 const ScriptData& script_data) {
340 script_.set_id(UserScript::GenerateUserScriptID()); 340 script_.set_id(UserScript::GenerateUserScriptID());
341 script_.set_host_id(host_id); 341 script_.set_host_id(host_id);
342 script_.set_run_location(UserScript::BROWSER_DRIVEN); 342 script_.set_run_location(UserScript::BROWSER_DRIVEN);
343 script_.set_match_all_frames(script_data.all_frames); 343 script_.set_match_all_frames(script_data.all_frames);
344 script_.set_match_about_blank(script_data.match_about_blank); 344 script_.set_match_about_blank(script_data.match_about_blank);
345 for (std::vector<std::string>::const_iterator it = 345 for (std::vector<std::string>::const_iterator it =
346 script_data.css_file_names.begin(); 346 script_data.css_file_names.begin();
347 it != script_data.css_file_names.end(); ++it) { 347 it != script_data.css_file_names.end(); ++it) {
348 GURL url = extension->GetResourceURL(*it); 348 GURL url = extension->GetResourceURL(*it);
349 ExtensionResource resource = extension->GetResource(*it); 349 ExtensionResource resource = extension->GetResource(*it);
350 script_.css_scripts().push_back(UserScript::File( 350 script_.css_scripts().push_back(base::WrapUnique(new UserScript::File(
Devlin 2016/08/17 16:39:30 nitty nit: I think we came to a semi-consensus to
lazyboy 2016/08/17 18:55:52 Done.
351 resource.extension_root(), resource.relative_path(), url)); 351 resource.extension_root(), resource.relative_path(), url)));
352 } 352 }
353 for (std::vector<std::string>::const_iterator it = 353 for (std::vector<std::string>::const_iterator it =
354 script_data.js_file_names.begin(); 354 script_data.js_file_names.begin();
355 it != script_data.js_file_names.end(); ++it) { 355 it != script_data.js_file_names.end(); ++it) {
356 GURL url = extension->GetResourceURL(*it); 356 GURL url = extension->GetResourceURL(*it);
357 ExtensionResource resource = extension->GetResource(*it); 357 ExtensionResource resource = extension->GetResource(*it);
358 script_.js_scripts().push_back(UserScript::File( 358 script_.js_scripts().push_back(base::WrapUnique(new UserScript::File(
359 resource.extension_root(), resource.relative_path(), url)); 359 resource.extension_root(), resource.relative_path(), url)));
360 } 360 }
361 } 361 }
362 362
363 void RequestContentScript::AddScript() {
364 DCHECK(master_);
365 master_->AddScript(UserScript::CopyFrom(script_));
366 }
367
363 void RequestContentScript::Apply(const ApplyInfo& apply_info) const { 368 void RequestContentScript::Apply(const ApplyInfo& apply_info) const {
364 InstructRenderProcessToInject(apply_info.tab, apply_info.extension); 369 InstructRenderProcessToInject(apply_info.tab, apply_info.extension);
365 } 370 }
366 371
367 void RequestContentScript::Reapply(const ApplyInfo& apply_info) const { 372 void RequestContentScript::Reapply(const ApplyInfo& apply_info) const {
368 InstructRenderProcessToInject(apply_info.tab, apply_info.extension); 373 InstructRenderProcessToInject(apply_info.tab, apply_info.extension);
369 } 374 }
370 375
371 void RequestContentScript::Revert(const ApplyInfo& apply_info) const {} 376 void RequestContentScript::Revert(const ApplyInfo& apply_info) const {}
372 377
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return (*factory_method_iter->second)( 442 return (*factory_method_iter->second)(
438 browser_context, extension, action_dict, error); 443 browser_context, extension, action_dict, error);
439 444
440 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); 445 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str());
441 return std::unique_ptr<ContentAction>(); 446 return std::unique_ptr<ContentAction>();
442 } 447 }
443 448
444 ContentAction::ContentAction() {} 449 ContentAction::ContentAction() {}
445 450
446 } // namespace extensions 451 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698