summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/api/execute_code_function.cc8
-rw-r--r--extensions/browser/api/execute_code_function.h9
-rw-r--r--extensions/browser/api/web_view/web_view_internal_api.cc14
-rw-r--r--extensions/browser/script_executor.cc29
-rw-r--r--extensions/browser/script_executor.h2
-rw-r--r--extensions/common/extension_messages.cc24
-rw-r--r--extensions/common/extension_messages.h16
-rw-r--r--extensions/common/host_id.h2
-rw-r--r--extensions/renderer/extension_injection_host.cc5
-rw-r--r--extensions/renderer/extension_injection_host.h6
-rw-r--r--extensions/renderer/programmatic_script_injector.cc1
-rw-r--r--extensions/renderer/script_injection_manager.cc18
-rw-r--r--extensions/renderer/web_ui_injection_host.cc1
13 files changed, 104 insertions, 31 deletions
diff --git a/extensions/browser/api/execute_code_function.cc b/extensions/browser/api/execute_code_function.cc
index 21845aa..aebf61f 100644
--- a/extensions/browser/api/execute_code_function.cc
+++ b/extensions/browser/api/execute_code_function.cc
@@ -129,7 +129,7 @@ bool ExecuteCodeFunction::Execute(const std::string& code_string) {
if (!executor)
return false;
- if (!extension())
+ if (!extension() && !IsWebView())
return false;
ScriptExecutor::ScriptType script_type = ScriptExecutor::JAVASCRIPT;
@@ -162,7 +162,7 @@ bool ExecuteCodeFunction::Execute(const std::string& code_string) {
CHECK_NE(UserScript::UNDEFINED, run_at);
executor->ExecuteScript(
- extension()->id(),
+ host_id_,
script_type,
code_string,
frame_scope,
@@ -204,6 +204,10 @@ bool ExecuteCodeFunction::RunAsync() {
if (!details_->file.get())
return false;
+
+ if (!extension())
+ return false;
+
resource_ = extension()->GetResource(*details_->file);
if (resource_.extension_root().empty() || resource_.relative_path().empty()) {
diff --git a/extensions/browser/api/execute_code_function.h b/extensions/browser/api/execute_code_function.h
index 9e1593a..db0f441 100644
--- a/extensions/browser/api/execute_code_function.h
+++ b/extensions/browser/api/execute_code_function.h
@@ -8,6 +8,7 @@
#include "extensions/browser/extension_function.h"
#include "extensions/browser/script_executor.h"
#include "extensions/common/api/extension_types.h"
+#include "extensions/common/host_id.h"
namespace extensions {
@@ -39,6 +40,11 @@ class ExecuteCodeFunction : public AsyncExtensionFunction {
// The injection details.
scoped_ptr<core_api::extension_types::InjectDetails> details_;
+ const HostID& host_id() const { return host_id_; }
+ void set_host_id(HostID host_id) {
+ host_id_ = host_id;
+ }
+
private:
// Called when contents from the file whose path is specified in JSON
// arguments has been loaded.
@@ -65,6 +71,9 @@ class ExecuteCodeFunction : public AsyncExtensionFunction {
// The URL of the file being injected into the page.
GURL file_url_;
+
+ // The ID of the injection host.
+ HostID host_id_;
};
} // namespace extensions
diff --git a/extensions/browser/api/web_view/web_view_internal_api.cc b/extensions/browser/api/web_view/web_view_internal_api.cc
index 4b041e9..dd9842a 100644
--- a/extensions/browser/api/web_view/web_view_internal_api.cc
+++ b/extensions/browser/api/web_view/web_view_internal_api.cc
@@ -102,7 +102,19 @@ bool WebViewInternalExecuteCodeFunction::Init() {
return false;
details_ = details.Pass();
- return true;
+
+ if (extension()) {
+ set_host_id(HostID(HostID::EXTENSIONS, extension()->id()));
+ return true;
+ }
+
+ WebContents* web_contents = GetSenderWebContents();
+ if (web_contents && web_contents->GetWebUI()) {
+ const GURL& url = render_view_host()->GetSiteInstance()->GetSiteURL();
+ set_host_id(HostID(HostID::WEBUI, url.spec()));
+ return true;
+ }
+ return false;
}
bool WebViewInternalExecuteCodeFunction::ShouldInsertCSS() const {
diff --git a/extensions/browser/script_executor.cc b/extensions/browser/script_executor.cc
index ac3e671..bdd831a 100644
--- a/extensions/browser/script_executor.cc
+++ b/extensions/browser/script_executor.cc
@@ -38,7 +38,7 @@ class Handler : public content::WebContentsObserver {
const ScriptExecutor::ExecuteScriptCallback& callback)
: content::WebContentsObserver(web_contents),
script_observers_(AsWeakPtr(script_observers)),
- extension_id_(params.extension_id),
+ host_id_(params.host_id),
request_id_(params.request_id),
callback_(callback) {
content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
@@ -78,9 +78,10 @@ class Handler : public content::WebContentsObserver {
const std::string& error,
const GURL& on_url,
const base::ListValue& script_result) {
- if (script_observers_.get() && error.empty()) {
+ if (script_observers_.get() && error.empty() &&
+ host_id_.type() == HostID::EXTENSIONS) {
ScriptExecutionObserver::ExecutingScriptsMap id_map;
- id_map[extension_id_] = std::set<std::string>();
+ id_map[host_id_.id()] = std::set<std::string>();
FOR_EACH_OBSERVER(ScriptExecutionObserver,
*script_observers_,
OnScriptsExecuted(web_contents(), id_map, on_url));
@@ -91,7 +92,7 @@ class Handler : public content::WebContentsObserver {
}
base::WeakPtr<ObserverList<ScriptExecutionObserver> > script_observers_;
- std::string extension_id_;
+ HostID host_id_;
int request_id_;
ScriptExecutor::ExecuteScriptCallback callback_;
};
@@ -113,7 +114,7 @@ ScriptExecutor::ScriptExecutor(
ScriptExecutor::~ScriptExecutor() {
}
-void ScriptExecutor::ExecuteScript(const std::string& extension_id,
+void ScriptExecutor::ExecuteScript(const HostID& host_id,
ScriptExecutor::ScriptType script_type,
const std::string& code,
ScriptExecutor::FrameScope frame_scope,
@@ -126,16 +127,20 @@ void ScriptExecutor::ExecuteScript(const std::string& extension_id,
bool user_gesture,
ScriptExecutor::ResultType result_type,
const ExecuteScriptCallback& callback) {
- // Don't execute if the extension has been unloaded.
- const Extension* extension =
- ExtensionRegistry::Get(web_contents_->GetBrowserContext())
- ->enabled_extensions().GetByID(extension_id);
- if (!extension)
- return;
+ if (host_id.type() == HostID::EXTENSIONS) {
+ // Don't execute if the extension has been unloaded.
+ const Extension* extension =
+ ExtensionRegistry::Get(web_contents_->GetBrowserContext())
+ ->enabled_extensions().GetByID(host_id.id());
+ if (!extension)
+ return;
+ } else {
+ CHECK(process_type == WEB_VIEW_PROCESS);
+ }
ExtensionMsg_ExecuteCode_Params params;
params.request_id = next_request_id_++;
- params.extension_id = extension_id;
+ params.host_id = host_id;
params.is_javascript = (script_type == JAVASCRIPT);
params.code = code;
params.all_frames = (frame_scope == ALL_FRAMES);
diff --git a/extensions/browser/script_executor.h b/extensions/browser/script_executor.h
index c4ecb00..322e9bb 100644
--- a/extensions/browser/script_executor.h
+++ b/extensions/browser/script_executor.h
@@ -85,7 +85,7 @@ class ScriptExecutor {
// |callback| will always be called even if the IPC'd renderer is destroyed
// before a response is received (in this case the callback will be with a
// failure and appropriate error message).
- void ExecuteScript(const std::string& extension_id,
+ void ExecuteScript(const HostID& host_id,
ScriptType script_type,
const std::string& code,
FrameScope frame_scope,
diff --git a/extensions/common/extension_messages.cc b/extensions/common/extension_messages.cc
index 94a6bd0..41b8023 100644
--- a/extensions/common/extension_messages.cc
+++ b/extensions/common/extension_messages.cc
@@ -249,6 +249,30 @@ void ParamTraits<ManifestPermissionSet>::Log(
LogParam(p.map(), l);
}
+void ParamTraits<HostID>::Write(
+ Message* m, const param_type& p) {
+ WriteParam(m, p.type());
+ WriteParam(m, p.id());
+}
+
+bool ParamTraits<HostID>::Read(
+ const Message* m, PickleIterator* iter, param_type* r) {
+ HostID::HostType type;
+ std::string id;
+ if (!ReadParam(m, iter, &type))
+ return false;
+ if (!ReadParam(m, iter, &id))
+ return false;
+ *r = HostID(type, id);
+ return true;
+}
+
+void ParamTraits<HostID>::Log(
+ const param_type& p, std::string* l) {
+ LogParam(p.type(), l);
+ LogParam(p.id(), l);
+}
+
void ParamTraits<ExtensionMsg_PermissionSetStruct>::Write(Message* m,
const param_type& p) {
WriteParam(m, p.apis);
diff --git a/extensions/common/extension_messages.h b/extensions/common/extension_messages.h
index aee505c..232167c 100644
--- a/extensions/common/extension_messages.h
+++ b/extensions/common/extension_messages.h
@@ -16,6 +16,7 @@
#include "extensions/common/draggable_region.h"
#include "extensions/common/extension.h"
#include "extensions/common/extensions_client.h"
+#include "extensions/common/host_id.h"
#include "extensions/common/permissions/media_galleries_permission_data.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/socket_permission_data.h"
@@ -38,6 +39,8 @@ IPC_ENUM_TRAITS_MAX_VALUE(content::SocketPermissionRequest::OperationType,
IPC_ENUM_TRAITS_MAX_VALUE(extensions::UserScript::InjectionType,
extensions::UserScript::INJECTION_TYPE_LAST)
+IPC_ENUM_TRAITS_MAX_VALUE(HostID::HostType, HostID::HOST_TYPE_LAST)
+
// Parameters structure for ExtensionHostMsg_AddAPIActionToActivityLog and
// ExtensionHostMsg_AddEventToActivityLog.
IPC_STRUCT_BEGIN(ExtensionHostMsg_APIActionOrEvent_Params)
@@ -106,9 +109,8 @@ IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params)
// The extension API request id, for responding.
IPC_STRUCT_MEMBER(int, request_id)
- // The ID of the requesting extension. To know which isolated world to
- // execute the code inside of.
- IPC_STRUCT_MEMBER(std::string, extension_id)
+ // The ID of the requesting injection host.
+ IPC_STRUCT_MEMBER(HostID, host_id)
// Whether the code is JavaScript or CSS.
IPC_STRUCT_MEMBER(bool, is_javascript)
@@ -338,6 +340,14 @@ struct ParamTraits<extensions::ManifestPermissionSet> {
};
template <>
+struct ParamTraits<HostID> {
+ typedef HostID param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template <>
struct ParamTraits<ExtensionMsg_PermissionSetStruct> {
typedef ExtensionMsg_PermissionSetStruct param_type;
static void Write(Message* m, const param_type& p);
diff --git a/extensions/common/host_id.h b/extensions/common/host_id.h
index d977a44..176ea49 100644
--- a/extensions/common/host_id.h
+++ b/extensions/common/host_id.h
@@ -10,7 +10,7 @@
// IDs of hosts who own user scripts.
// A HostID is immutable after creation.
struct HostID {
- enum HostType { EXTENSIONS, WEBUI };
+ enum HostType { EXTENSIONS, WEBUI, HOST_TYPE_LAST = WEBUI };
HostID();
HostID(HostType type, const std::string& id);
diff --git a/extensions/renderer/extension_injection_host.cc b/extensions/renderer/extension_injection_host.cc
index 7a27a08..a97a702 100644
--- a/extensions/renderer/extension_injection_host.cc
+++ b/extensions/renderer/extension_injection_host.cc
@@ -18,8 +18,9 @@ ExtensionInjectionHost::~ExtensionInjectionHost() {
}
// static
-scoped_ptr<const ExtensionInjectionHost> ExtensionInjectionHost::Create(
- const std::string& extension_id, const ExtensionSet* extensions) {
+scoped_ptr<const InjectionHost> ExtensionInjectionHost::Create(
+ const std::string& extension_id,
+ const ExtensionSet* extensions) {
const Extension* extension = extensions->GetByID(extension_id);
if (!extension)
return scoped_ptr<const ExtensionInjectionHost>();
diff --git a/extensions/renderer/extension_injection_host.h b/extensions/renderer/extension_injection_host.h
index bdf6f41..1b77cac 100644
--- a/extensions/renderer/extension_injection_host.h
+++ b/extensions/renderer/extension_injection_host.h
@@ -12,6 +12,8 @@
namespace extensions {
class ExtensionSet;
+class ExtensionSet;
+
// A wrapper class that holds an extension and implements the InjectionHost
// interface.
class ExtensionInjectionHost : public InjectionHost {
@@ -21,8 +23,8 @@ class ExtensionInjectionHost : public InjectionHost {
// Create an ExtensionInjectionHost object. If the extension is gone, returns
// a null scoped ptr.
- static scoped_ptr<const ExtensionInjectionHost> Create(
- const std::string& extension_id, const ExtensionSet* extensions);
+ static scoped_ptr<const InjectionHost> Create(const std::string& extension_id,
+ const ExtensionSet* extensions);
private:
// InjectionHost:
diff --git a/extensions/renderer/programmatic_script_injector.cc b/extensions/renderer/programmatic_script_injector.cc
index 19259df..6e28bef 100644
--- a/extensions/renderer/programmatic_script_injector.cc
+++ b/extensions/renderer/programmatic_script_injector.cc
@@ -82,6 +82,7 @@ PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
? PermissionsData::ACCESS_ALLOWED
: PermissionsData::ACCESS_DENIED;
}
+ DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS);
return injection_host->CanExecuteOnFrame(
effective_document_url, top_url, tab_id, true /* is_declarative */);
diff --git a/extensions/renderer/script_injection_manager.cc b/extensions/renderer/script_injection_manager.cc
index 5481a8e..c550cfd 100644
--- a/extensions/renderer/script_injection_manager.cc
+++ b/extensions/renderer/script_injection_manager.cc
@@ -19,6 +19,7 @@
#include "extensions/renderer/programmatic_script_injector.h"
#include "extensions/renderer/script_injection.h"
#include "extensions/renderer/scripts_run_info.h"
+#include "extensions/renderer/web_ui_injection_host.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
@@ -406,17 +407,22 @@ void ScriptInjectionManager::HandleExecuteCode(
return;
}
- scoped_ptr<const ExtensionInjectionHost> extension_injection_host =
- ExtensionInjectionHost::Create(params.extension_id, extensions_);
-
- if (!extension_injection_host)
- return;
+ scoped_ptr<const InjectionHost> injection_host;
+ if (params.host_id.type() == HostID::EXTENSIONS) {
+ injection_host = ExtensionInjectionHost::Create(params.host_id.id(),
+ extensions_);
+ if (!injection_host)
+ return;
+ } else if (params.host_id.type() == HostID::WEBUI) {
+ injection_host.reset(
+ new WebUIInjectionHost(params.host_id));
+ }
scoped_ptr<ScriptInjection> injection(new ScriptInjection(
scoped_ptr<ScriptInjector>(
new ProgrammaticScriptInjector(params, main_frame)),
main_frame,
- extension_injection_host.Pass(),
+ injection_host.Pass(),
static_cast<UserScript::RunLocation>(params.run_at),
ExtensionHelper::Get(render_view)->tab_id()));
diff --git a/extensions/renderer/web_ui_injection_host.cc b/extensions/renderer/web_ui_injection_host.cc
index 334358a..5c6e117 100644
--- a/extensions/renderer/web_ui_injection_host.cc
+++ b/extensions/renderer/web_ui_injection_host.cc
@@ -12,7 +12,6 @@ WebUIInjectionHost::WebUIInjectionHost(const HostID& host_id)
WebUIInjectionHost::~WebUIInjectionHost() {
}
-
std::string WebUIInjectionHost::GetContentSecurityPolicy() const {
return std::string();
}