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

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

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 << " effective extension id: " 87 << " effective extension id: "
88 << (effective_extension_.get() ? effective_extension_->id() : ""); 88 << (effective_extension_.get() ? effective_extension_->id() : "");
89 Invalidate(); 89 Invalidate();
90 } 90 }
91 91
92 void ScriptContext::Invalidate() { 92 void ScriptContext::Invalidate() {
93 if (!is_valid()) 93 if (!is_valid())
94 return; 94 return;
95 if (module_system_) 95 if (module_system_)
96 module_system_->Invalidate(); 96 module_system_->Invalidate();
97 web_frame_ = NULL; 97 web_frame_ = nullptr;
98 v8_context_.reset(); 98 v8_context_.reset();
99 } 99 }
100 100
101 const std::string& ScriptContext::GetExtensionID() const { 101 const std::string& ScriptContext::GetExtensionID() const {
102 return extension_.get() ? extension_->id() : base::EmptyString(); 102 return extension_.get() ? extension_->id() : base::EmptyString();
103 } 103 }
104 104
105 content::RenderView* ScriptContext::GetRenderView() const { 105 content::RenderView* ScriptContext::GetRenderView() const {
106 if (web_frame_ && web_frame_->view()) 106 if (web_frame_ && web_frame_->view())
107 return content::RenderView::FromWebView(web_frame_->view()); 107 return content::RenderView::FromWebView(web_frame_->view());
108 return NULL; 108 return nullptr;
109 } 109 }
110 110
111 content::RenderFrame* ScriptContext::GetRenderFrame() const { 111 content::RenderFrame* ScriptContext::GetRenderFrame() const {
112 if (web_frame_) 112 if (web_frame_)
113 return content::RenderFrame::FromWebFrame(web_frame_); 113 return content::RenderFrame::FromWebFrame(web_frame_);
114 return NULL; 114 return nullptr;
115 } 115 }
116 116
117 v8::Local<v8::Value> ScriptContext::CallFunction( 117 v8::Local<v8::Value> ScriptContext::CallFunction(
118 v8::Handle<v8::Function> function, 118 v8::Handle<v8::Function> function,
119 int argc, 119 int argc,
120 v8::Handle<v8::Value> argv[]) const { 120 v8::Handle<v8::Value> argv[]) const {
121 v8::EscapableHandleScope handle_scope(isolate()); 121 v8::EscapableHandleScope handle_scope(isolate());
122 v8::Context::Scope scope(v8_context()); 122 v8::Context::Scope scope(v8_context());
123 123
124 blink::WebScopedMicrotaskSuppression suppression; 124 blink::WebScopedMicrotaskSuppression suppression;
(...skipping 12 matching lines...) Expand all
137 137
138 Feature::Availability ScriptContext::GetAvailability( 138 Feature::Availability ScriptContext::GetAvailability(
139 const std::string& api_name) { 139 const std::string& api_name) {
140 // Hack: Hosted apps should have the availability of messaging APIs based on 140 // Hack: Hosted apps should have the availability of messaging APIs based on
141 // the URL of the page (which might have access depending on some extension 141 // the URL of the page (which might have access depending on some extension
142 // with externally_connectable), not whether the app has access to messaging 142 // with externally_connectable), not whether the app has access to messaging
143 // (which it won't). 143 // (which it won't).
144 const Extension* extension = extension_.get(); 144 const Extension* extension = extension_.get();
145 if (extension && extension->is_hosted_app() && 145 if (extension && extension->is_hosted_app() &&
146 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) { 146 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
147 extension = NULL; 147 extension = nullptr;
148 } 148 }
149 return ExtensionAPI::GetSharedInstance()->IsAvailable( 149 return ExtensionAPI::GetSharedInstance()->IsAvailable(
150 api_name, extension, context_type_, GetURL()); 150 api_name, extension, context_type_, GetURL());
151 } 151 }
152 152
153 void ScriptContext::DispatchEvent(const char* event_name, 153 void ScriptContext::DispatchEvent(const char* event_name,
154 v8::Handle<v8::Array> args) const { 154 v8::Handle<v8::Array> args) const {
155 v8::HandleScope handle_scope(isolate()); 155 v8::HandleScope handle_scope(isolate());
156 v8::Context::Scope context_scope(v8_context()); 156 v8::Context::Scope context_scope(v8_context());
157 157
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // |document_url| (supposedly the URL of the frame). 209 // |document_url| (supposedly the URL of the frame).
210 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme)) 210 if (!match_about_blank || !document_url.SchemeIs(url::kAboutScheme))
211 return document_url; 211 return document_url;
212 212
213 // Non-sandboxed about:blank and about:srcdoc pages inherit their security 213 // Non-sandboxed about:blank and about:srcdoc pages inherit their security
214 // origin from their parent frame/window. So, traverse the frame/window 214 // origin from their parent frame/window. So, traverse the frame/window
215 // hierarchy to find the closest non-about:-page and return its URL. 215 // hierarchy to find the closest non-about:-page and return its URL.
216 const blink::WebFrame* parent = frame; 216 const blink::WebFrame* parent = frame;
217 do { 217 do {
218 parent = parent->parent() ? parent->parent() : parent->opener(); 218 parent = parent->parent() ? parent->parent() : parent->opener();
219 } while (parent != NULL && !parent->document().isNull() && 219 } while (parent != nullptr && !parent->document().isNull() &&
220 GURL(parent->document().url()).SchemeIs(url::kAboutScheme)); 220 GURL(parent->document().url()).SchemeIs(url::kAboutScheme));
221 221
222 if (parent && !parent->document().isNull()) { 222 if (parent && !parent->document().isNull()) {
223 // Only return the parent URL if the frame can access it. 223 // Only return the parent URL if the frame can access it.
224 const blink::WebDocument& parent_document = parent->document(); 224 const blink::WebDocument& parent_document = parent->document();
225 if (frame->document().securityOrigin().canAccess( 225 if (frame->document().securityOrigin().canAccess(
226 parent_document.securityOrigin())) 226 parent_document.securityOrigin()))
227 return parent_document.url(); 227 return parent_document.url();
228 } 228 }
229 return document_url; 229 return document_url;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 v8::Handle<v8::Value> argv[]) { 266 v8::Handle<v8::Value> argv[]) {
267 return CallFunction(function, argc, argv); 267 return CallFunction(function, argc, argv);
268 } 268 }
269 269
270 gin::ContextHolder* ScriptContext::GetContextHolder() { 270 gin::ContextHolder* ScriptContext::GetContextHolder() {
271 v8::HandleScope handle_scope(isolate()); 271 v8::HandleScope handle_scope(isolate());
272 return gin::PerContextData::From(v8_context())->context_holder(); 272 return gin::PerContextData::From(v8_context())->context_holder();
273 } 273 }
274 274
275 } // namespace extensions 275 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698