| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
| 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 14 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/session_tab_helper.h" |
| 18 #include "content/public/browser/invalidate_type.h" | 19 #include "content/public/browser/invalidate_type.h" |
| 20 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 20 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_messages.h" |
| 23 | 26 |
| 24 namespace extensions { | 27 namespace extensions { |
| 25 | 28 |
| 26 namespace keys = declarative_content_constants; | 29 namespace keys = declarative_content_constants; |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 // Error messages. | 32 // Error messages. |
| 30 const char kInvalidInstanceTypeError[] = | 33 const char kInvalidInstanceTypeError[] = |
| 31 "An action has an invalid instanceType: %s"; | 34 "An action has an invalid instanceType: %s"; |
| 32 const char kNoPageAction[] = | 35 const char kNoPageAction[] = |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 298 } |
| 296 } | 299 } |
| 297 | 300 |
| 298 ContentAction::Type RequestContentScript::GetType() const { | 301 ContentAction::Type RequestContentScript::GetType() const { |
| 299 return ACTION_REQUEST_CONTENT_SCRIPT; | 302 return ACTION_REQUEST_CONTENT_SCRIPT; |
| 300 } | 303 } |
| 301 | 304 |
| 302 void RequestContentScript::Apply(const std::string& extension_id, | 305 void RequestContentScript::Apply(const std::string& extension_id, |
| 303 const base::Time& extension_install_time, | 306 const base::Time& extension_install_time, |
| 304 ApplyInfo* apply_info) const { | 307 ApplyInfo* apply_info) const { |
| 305 InstructRenderProcessToInject(apply_info->tab, extension_id); | 308 InstructRenderProcessToInject(apply_info->tab, extension_id); |
| 306 } | 309 } |
| 307 | 310 |
| 308 void RequestContentScript::Reapply(const std::string& extension_id, | 311 void RequestContentScript::Reapply(const std::string& extension_id, |
| 309 const base::Time& extension_install_time, | 312 const base::Time& extension_install_time, |
| 310 ApplyInfo* apply_info) const { | 313 ApplyInfo* apply_info) const { |
| 311 InstructRenderProcessToInject(apply_info->tab, extension_id); | 314 InstructRenderProcessToInject(apply_info->tab, extension_id); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void RequestContentScript::Revert(const std::string& extension_id, | 317 void RequestContentScript::Revert(const std::string& extension_id, |
| 315 const base::Time& extension_install_time, | 318 const base::Time& extension_install_time, |
| 316 ApplyInfo* apply_info) const {} | 319 ApplyInfo* apply_info) const {} |
| 317 | 320 |
| 318 void RequestContentScript::InstructRenderProcessToInject( | 321 void RequestContentScript::InstructRenderProcessToInject( |
| 319 content::WebContents* contents, | 322 content::WebContents* contents, |
| 320 const std::string& extension_id) const { | 323 const std::string& extension_id) const { |
| 321 // TODO(markdittmer): Send ExtensionMsg to renderer. | 324 content::RenderViewHost* render_view_host = contents->GetRenderViewHost(); |
| 325 render_view_host->Send(new ExtensionMsg_ExecuteDeclarativeScript( |
| 326 render_view_host->GetRoutingID(), |
| 327 SessionTabHelper::IdForTab(contents), |
| 328 extension_id, |
| 329 script_.id(), |
| 330 contents->GetLastCommittedURL())); |
| 322 } | 331 } |
| 323 | 332 |
| 324 // | 333 // |
| 325 // ContentAction | 334 // ContentAction |
| 326 // | 335 // |
| 327 | 336 |
| 328 ContentAction::ContentAction() {} | 337 ContentAction::ContentAction() {} |
| 329 | 338 |
| 330 ContentAction::~ContentAction() {} | 339 ContentAction::~ContentAction() {} |
| 331 | 340 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 358 bool* bad_message, | 367 bool* bad_message, |
| 359 const base::DictionaryValue** action_dict, | 368 const base::DictionaryValue** action_dict, |
| 360 std::string* instance_type) { | 369 std::string* instance_type) { |
| 361 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); | 370 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); |
| 362 INPUT_FORMAT_VALIDATE( | 371 INPUT_FORMAT_VALIDATE( |
| 363 (*action_dict)->GetString(keys::kInstanceType, instance_type)); | 372 (*action_dict)->GetString(keys::kInstanceType, instance_type)); |
| 364 return true; | 373 return true; |
| 365 } | 374 } |
| 366 | 375 |
| 367 } // namespace extensions | 376 } // namespace extensions |
| OLD | NEW |