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

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: address comments 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 12 matching lines...) Expand all
23 #include "third_party/WebKit/public/web/WebFrame.h" 23 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" 24 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
25 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 25 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
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 namespace {
34
35 std::string GetContextTypeDescriptionString(Feature::Context context_type) {
36 switch (context_type) {
37 case Feature::UNSPECIFIED_CONTEXT:
38 return "UNSPECIFIED";
39 case Feature::BLESSED_EXTENSION_CONTEXT:
40 return "BLESSED_EXTENSION";
41 case Feature::UNBLESSED_EXTENSION_CONTEXT:
42 return "UNBLESSED_EXTENSION";
43 case Feature::CONTENT_SCRIPT_CONTEXT:
44 return "CONTENT_SCRIPT";
45 case Feature::WEB_PAGE_CONTEXT:
46 return "WEB_PAGE";
47 case Feature::BLESSED_WEB_PAGE_CONTEXT:
48 return "BLESSED_WEB_PAGE";
49 case Feature::WEBUI_CONTEXT:
50 return "WEBUI";
51 }
52 NOTREACHED();
53 return std::string();
54 }
55
56 const std::string& GetIDForExtension(const Extension* extension) {
57 if (extension)
58 return extension->id();
59 return base::EmptyString();
Devlin 2014/09/04 19:15:11 base::EmptyString is expensive. It'd probably be
Marijn Kruisselbrink 2014/09/04 23:41:11 Good point, done.
60 }
61
62 } // namespace
63
33 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, 64 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context,
34 blink::WebFrame* web_frame, 65 blink::WebFrame* web_frame,
35 const Extension* extension, 66 const Extension* extension,
36 Feature::Context context_type) 67 Feature::Context context_type,
68 const Extension* effective_extension,
69 Feature::Context effective_context_type)
37 : v8_context_(v8_context), 70 : v8_context_(v8_context),
38 web_frame_(web_frame), 71 web_frame_(web_frame),
39 extension_(extension), 72 extension_(extension),
40 context_type_(context_type), 73 context_type_(context_type),
74 effective_extension_(effective_extension),
75 effective_context_type_(effective_context_type),
41 safe_builtins_(this), 76 safe_builtins_(this),
42 isolate_(v8_context->GetIsolate()) { 77 isolate_(v8_context->GetIsolate()) {
43 VLOG(1) << "Created context:\n" 78 VLOG(1) << "Created context:\n"
44 << " extension id: " << GetExtensionID() << "\n" 79 << " extension id: " << GetExtensionID() << "\n"
45 << " frame: " << web_frame_ << "\n" 80 << " frame: " << web_frame_ << "\n"
46 << " URL: " << GetURL() << "\n" 81 << " URL: " << GetURL() << "\n"
47 << " context type: " << GetContextTypeDescription(); 82 << " context type: " << GetContextTypeDescription() << "\n"
83 << " effective extension id: "
84 << GetIDForExtension(effective_extension_.get()) << "\n"
85 << " effective context type: "
86 << GetEffectiveContextTypeDescription();
48 gin::PerContextData::From(v8_context)->set_runner(this); 87 gin::PerContextData::From(v8_context)->set_runner(this);
49 } 88 }
50 89
51 ScriptContext::~ScriptContext() { 90 ScriptContext::~ScriptContext() {
52 VLOG(1) << "Destroyed context for extension\n" 91 VLOG(1) << "Destroyed context for extension\n"
53 << " extension id: " << GetExtensionID(); 92 << " extension id: " << GetExtensionID() << "\n"
93 << " effective extension id: "
94 << GetIDForExtension(effective_extension_.get());
54 Invalidate(); 95 Invalidate();
55 } 96 }
56 97
57 void ScriptContext::Invalidate() { 98 void ScriptContext::Invalidate() {
58 if (!is_valid()) 99 if (!is_valid())
59 return; 100 return;
60 if (module_system_) 101 if (module_system_)
61 module_system_->Invalidate(); 102 module_system_->Invalidate();
62 web_frame_ = NULL; 103 web_frame_ = NULL;
63 v8_context_.reset(); 104 v8_context_.reset();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 kEventBindings, "dispatchEvent", arraysize(argv), argv); 167 kEventBindings, "dispatchEvent", arraysize(argv), argv);
127 } 168 }
128 169
129 void ScriptContext::DispatchOnUnloadEvent() { 170 void ScriptContext::DispatchOnUnloadEvent() {
130 v8::HandleScope handle_scope(isolate()); 171 v8::HandleScope handle_scope(isolate());
131 v8::Context::Scope context_scope(v8_context()); 172 v8::Context::Scope context_scope(v8_context());
132 module_system_->CallModuleMethod("unload_event", "dispatch"); 173 module_system_->CallModuleMethod("unload_event", "dispatch");
133 } 174 }
134 175
135 std::string ScriptContext::GetContextTypeDescription() { 176 std::string ScriptContext::GetContextTypeDescription() {
136 switch (context_type_) { 177 return GetContextTypeDescriptionString(context_type_);
137 case Feature::UNSPECIFIED_CONTEXT: 178 }
138 return "UNSPECIFIED"; 179
139 case Feature::BLESSED_EXTENSION_CONTEXT: 180 std::string ScriptContext::GetEffectiveContextTypeDescription() {
140 return "BLESSED_EXTENSION"; 181 return GetContextTypeDescriptionString(effective_context_type_);
141 case Feature::UNBLESSED_EXTENSION_CONTEXT:
142 return "UNBLESSED_EXTENSION";
143 case Feature::CONTENT_SCRIPT_CONTEXT:
144 return "CONTENT_SCRIPT";
145 case Feature::WEB_PAGE_CONTEXT:
146 return "WEB_PAGE";
147 case Feature::BLESSED_WEB_PAGE_CONTEXT:
148 return "BLESSED_WEB_PAGE";
149 case Feature::WEBUI_CONTEXT:
150 return "WEBUI";
151 }
152 NOTREACHED();
153 return std::string();
154 } 182 }
155 183
156 GURL ScriptContext::GetURL() const { 184 GURL ScriptContext::GetURL() const {
157 return web_frame() ? GetDataSourceURLForFrame(web_frame()) : GURL(); 185 return web_frame() ? GetDataSourceURLForFrame(web_frame()) : GURL();
158 } 186 }
159 187
160 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { 188 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) {
161 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 189 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
162 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); 190 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame()));
163 } 191 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 v8::Handle<v8::Value> argv[]) { 272 v8::Handle<v8::Value> argv[]) {
245 return CallFunction(function, argc, argv); 273 return CallFunction(function, argc, argv);
246 } 274 }
247 275
248 gin::ContextHolder* ScriptContext::GetContextHolder() { 276 gin::ContextHolder* ScriptContext::GetContextHolder() {
249 v8::HandleScope handle_scope(isolate()); 277 v8::HandleScope handle_scope(isolate());
250 return gin::PerContextData::From(v8_context())->context_holder(); 278 return gin::PerContextData::From(v8_context())->context_holder();
251 } 279 }
252 280
253 } // namespace extensions 281 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698