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

Side by Side Diff: extensions/renderer/script_context.cc

Issue 498513002: Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix extensions test compile Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "third_party/WebKit/public/web/WebView.h" 26 #include "third_party/WebKit/public/web/WebView.h"
27 #include "v8/include/v8.h" 27 #include "v8/include/v8.h"
28 28
29 using content::V8ValueConverter; 29 using content::V8ValueConverter;
30 30
31 namespace extensions { 31 namespace extensions {
32 32
33 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, 33 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context,
34 blink::WebFrame* web_frame, 34 blink::WebFrame* web_frame,
35 const Extension* extension, 35 const Extension* extension,
36 Feature::Context context_type) 36 Feature::Context context_type,
37 const Extension* effective_extension,
38 Feature::Context effective_context_type)
37 : v8_context_(v8_context), 39 : v8_context_(v8_context),
38 web_frame_(web_frame), 40 web_frame_(web_frame),
39 extension_(extension), 41 extension_(extension),
40 context_type_(context_type), 42 context_type_(context_type),
43 effective_extension_(effective_extension),
44 effective_context_type_(effective_context_type),
41 safe_builtins_(this), 45 safe_builtins_(this),
42 isolate_(v8_context->GetIsolate()) { 46 isolate_(v8_context->GetIsolate()) {
43 VLOG(1) << "Created context:\n" 47 VLOG(1) << "Created context:\n"
44 << " extension id: " << GetExtensionID() << "\n" 48 << " extension id: " << GetExtensionID() << "\n"
45 << " frame: " << web_frame_ << "\n" 49 << " frame: " << web_frame_ << "\n"
46 << " URL: " << GetURL() << "\n" 50 << " URL: " << GetURL() << "\n"
47 << " context type: " << GetContextTypeDescription(); 51 << " context type: " << GetContextTypeDescription() << "\n"
52 << " effective extension id: " << GetEffectiveExtensionID() << "\n"
53 << " effective context type: "
54 << GetEffectiveContextTypeDescription();
48 gin::PerContextData::From(v8_context)->set_runner(this); 55 gin::PerContextData::From(v8_context)->set_runner(this);
49 } 56 }
50 57
51 ScriptContext::~ScriptContext() { 58 ScriptContext::~ScriptContext() {
52 VLOG(1) << "Destroyed context for extension\n" 59 VLOG(1) << "Destroyed context for extension\n"
53 << " extension id: " << GetExtensionID(); 60 << " extension id: " << GetExtensionID() << "\n"
61 << " effective extension id: " << GetEffectiveExtensionID();
54 Invalidate(); 62 Invalidate();
55 } 63 }
56 64
57 void ScriptContext::Invalidate() { 65 void ScriptContext::Invalidate() {
58 if (!is_valid()) 66 if (!is_valid())
59 return; 67 return;
60 if (module_system_) 68 if (module_system_)
61 module_system_->Invalidate(); 69 module_system_->Invalidate();
62 web_frame_ = NULL; 70 web_frame_ = NULL;
63 v8_context_.reset(); 71 v8_context_.reset();
64 } 72 }
65 73
66 const std::string& ScriptContext::GetExtensionID() const { 74 const std::string& ScriptContext::GetExtensionID() const {
67 return extension_.get() ? extension_->id() : base::EmptyString(); 75 return extension_.get() ? extension_->id() : base::EmptyString();
68 } 76 }
69 77
78 const std::string& ScriptContext::GetEffectiveExtensionID() const {
79 return effective_extension_.get() ? effective_extension_->id()
80 : base::EmptyString();
81 }
82
70 content::RenderView* ScriptContext::GetRenderView() const { 83 content::RenderView* ScriptContext::GetRenderView() const {
71 if (web_frame_ && web_frame_->view()) 84 if (web_frame_ && web_frame_->view())
72 return content::RenderView::FromWebView(web_frame_->view()); 85 return content::RenderView::FromWebView(web_frame_->view());
73 return NULL; 86 return NULL;
74 } 87 }
75 88
76 content::RenderFrame* ScriptContext::GetRenderFrame() const { 89 content::RenderFrame* ScriptContext::GetRenderFrame() const {
77 if (web_frame_) 90 if (web_frame_)
78 return content::RenderFrame::FromWebFrame(web_frame_); 91 return content::RenderFrame::FromWebFrame(web_frame_);
79 return NULL; 92 return NULL;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 module_system_->CallModuleMethod( 138 module_system_->CallModuleMethod(
126 kEventBindings, "dispatchEvent", arraysize(argv), argv); 139 kEventBindings, "dispatchEvent", arraysize(argv), argv);
127 } 140 }
128 141
129 void ScriptContext::DispatchOnUnloadEvent() { 142 void ScriptContext::DispatchOnUnloadEvent() {
130 v8::HandleScope handle_scope(isolate()); 143 v8::HandleScope handle_scope(isolate());
131 v8::Context::Scope context_scope(v8_context()); 144 v8::Context::Scope context_scope(v8_context());
132 module_system_->CallModuleMethod("unload_event", "dispatch"); 145 module_system_->CallModuleMethod("unload_event", "dispatch");
133 } 146 }
134 147
135 std::string ScriptContext::GetContextTypeDescription() { 148 // static
136 switch (context_type_) { 149 std::string ScriptContext::GetContextTypeDescription(
Devlin 2014/09/03 22:09:16 Unless this is used elsewhere, I'd probably move i
Marijn Kruisselbrink 2014/09/03 23:54:07 Done.
150 Feature::Context context_type) {
151 switch (context_type) {
137 case Feature::UNSPECIFIED_CONTEXT: 152 case Feature::UNSPECIFIED_CONTEXT:
138 return "UNSPECIFIED"; 153 return "UNSPECIFIED";
139 case Feature::BLESSED_EXTENSION_CONTEXT: 154 case Feature::BLESSED_EXTENSION_CONTEXT:
140 return "BLESSED_EXTENSION"; 155 return "BLESSED_EXTENSION";
141 case Feature::UNBLESSED_EXTENSION_CONTEXT: 156 case Feature::UNBLESSED_EXTENSION_CONTEXT:
142 return "UNBLESSED_EXTENSION"; 157 return "UNBLESSED_EXTENSION";
143 case Feature::CONTENT_SCRIPT_CONTEXT: 158 case Feature::CONTENT_SCRIPT_CONTEXT:
144 return "CONTENT_SCRIPT"; 159 return "CONTENT_SCRIPT";
145 case Feature::WEB_PAGE_CONTEXT: 160 case Feature::WEB_PAGE_CONTEXT:
146 return "WEB_PAGE"; 161 return "WEB_PAGE";
147 case Feature::BLESSED_WEB_PAGE_CONTEXT: 162 case Feature::BLESSED_WEB_PAGE_CONTEXT:
148 return "BLESSED_WEB_PAGE"; 163 return "BLESSED_WEB_PAGE";
149 case Feature::WEBUI_CONTEXT: 164 case Feature::WEBUI_CONTEXT:
150 return "WEBUI"; 165 return "WEBUI";
151 } 166 }
152 NOTREACHED(); 167 NOTREACHED();
153 return std::string(); 168 return std::string();
154 } 169 }
155 170
171 std::string ScriptContext::GetContextTypeDescription() {
172 return GetContextTypeDescription(context_type_);
173 }
174
175 std::string ScriptContext::GetEffectiveContextTypeDescription() {
176 return GetContextTypeDescription(effective_context_type_);
177 }
178
156 GURL ScriptContext::GetURL() const { 179 GURL ScriptContext::GetURL() const {
157 return web_frame() ? GetDataSourceURLForFrame(web_frame()) : GURL(); 180 return web_frame() ? GetDataSourceURLForFrame(web_frame()) : GURL();
158 } 181 }
159 182
160 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { 183 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) {
161 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 184 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
162 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); 185 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame()));
163 } 186 }
164 187
165 // static 188 // static
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 v8::Handle<v8::Value> argv[]) { 267 v8::Handle<v8::Value> argv[]) {
245 return CallFunction(function, argc, argv); 268 return CallFunction(function, argc, argv);
246 } 269 }
247 270
248 gin::ContextHolder* ScriptContext::GetContextHolder() { 271 gin::ContextHolder* ScriptContext::GetContextHolder() {
249 v8::HandleScope handle_scope(isolate()); 272 v8::HandleScope handle_scope(isolate());
250 return gin::PerContextData::From(v8_context())->context_holder(); 273 return gin::PerContextData::From(v8_context())->context_holder();
251 } 274 }
252 275
253 } // namespace extensions 276 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698