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

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 6932038: avoid dereferencing NULL extension in ExtensionHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reflect comments Created 9 years, 7 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 }; 119 };
120 120
121 //////////////// 121 ////////////////
122 // ExtensionHost 122 // ExtensionHost
123 123
124 ExtensionHost::ExtensionHost(const Extension* extension, 124 ExtensionHost::ExtensionHost(const Extension* extension,
125 SiteInstance* site_instance, 125 SiteInstance* site_instance,
126 const GURL& url, 126 const GURL& url,
127 ViewType::Type host_type) 127 ViewType::Type host_type)
128 : extension_(extension), 128 : extension_(extension),
129 extension_id_(extension->id()),
129 profile_(site_instance->browsing_instance()->profile()), 130 profile_(site_instance->browsing_instance()->profile()),
130 did_stop_loading_(false), 131 did_stop_loading_(false),
131 document_element_available_(false), 132 document_element_available_(false),
132 url_(url), 133 url_(url),
133 extension_host_type_(host_type), 134 extension_host_type_(host_type),
134 associated_tab_contents_(NULL), 135 associated_tab_contents_(NULL),
135 suppress_javascript_messages_(false) { 136 suppress_javascript_messages_(false) {
136 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, 137 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
137 NULL); 138 NULL);
138 render_view_host_->set_is_extension_process(true); 139 render_view_host_->set_is_extension_process(true);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 228 }
228 229
229 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { 230 gfx::NativeView ExtensionHost::GetNativeViewOfHost() {
230 return view() ? view()->native_view() : NULL; 231 return view() ? view()->native_view() : NULL;
231 } 232 }
232 233
233 void ExtensionHost::NavigateToURL(const GURL& url) { 234 void ExtensionHost::NavigateToURL(const GURL& url) {
234 // Prevent explicit navigation to another extension id's pages. 235 // Prevent explicit navigation to another extension id's pages.
235 // This method is only called by some APIs, so we still need to protect 236 // This method is only called by some APIs, so we still need to protect
236 // DidNavigate below (location = ""). 237 // DidNavigate below (location = "").
237 if (url.SchemeIs(chrome::kExtensionScheme) && 238 if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != extension_id()) {
238 url.host() != extension_->id()) {
239 // TODO(erikkay) communicate this back to the caller? 239 // TODO(erikkay) communicate this back to the caller?
240 return; 240 return;
241 } 241 }
242 242
243 url_ = url; 243 url_ = url;
244 244
245 if (!is_background_page() && 245 if (!is_background_page() &&
246 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { 246 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) {
247 // Make sure the background page loads before any others. 247 // Make sure the background page loads before any others.
248 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, 248 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
249 Source<Extension>(extension_)); 249 Source<Extension>(extension_));
250 return; 250 return;
251 } 251 }
252 252
253 render_view_host_->NavigateToURL(url_); 253 render_view_host_->NavigateToURL(url_);
254 } 254 }
255 255
256 void ExtensionHost::Observe(NotificationType type, 256 void ExtensionHost::Observe(NotificationType type,
257 const NotificationSource& source, 257 const NotificationSource& source,
258 const NotificationDetails& details) { 258 const NotificationDetails& details) {
259 switch (type.value) { 259 switch (type.value) {
260 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: 260 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY:
261 DCHECK(profile_->GetExtensionService()-> 261 DCHECK(profile_->GetExtensionService()->
262 IsBackgroundPageReady(extension_)); 262 IsBackgroundPageReady(extension_));
263 NavigateToURL(url_); 263 NavigateToURL(url_);
264 break; 264 break;
265 case NotificationType::RENDERER_PROCESS_CREATED: 265 case NotificationType::RENDERER_PROCESS_CREATED:
266 NotificationService::current()->Notify( 266 NotificationService::current()->Notify(
267 NotificationType::EXTENSION_PROCESS_CREATED, 267 NotificationType::EXTENSION_PROCESS_CREATED,
268 Source<Profile>(profile_), 268 Source<Profile>(profile_),
269 Details<ExtensionHost>(this)); 269 Details<ExtensionHost>(this));
270 break; 270 break;
271 case NotificationType::EXTENSION_UNLOADED: 271 case NotificationType::EXTENSION_UNLOADED:
272 // The extension object will be deleted after this notification has been 272 // The extension object will be deleted after this notification has been
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 // This catches two bogus use cases: 336 // This catches two bogus use cases:
337 // (1) URLs that look like chrome-extension://somethingbogus or 337 // (1) URLs that look like chrome-extension://somethingbogus or
338 // chrome-extension://nosuchid/, in other words, no Extension would 338 // chrome-extension://nosuchid/, in other words, no Extension would
339 // be found. 339 // be found.
340 // (2) URLs that refer to a different extension than this one. 340 // (2) URLs that refer to a different extension than this one.
341 // In both cases, we preserve the old URL and reset the EFD to NULL. This 341 // In both cases, we preserve the old URL and reset the EFD to NULL. This
342 // will leave the host in kind of a bad state with poor UI and errors, but 342 // will leave the host in kind of a bad state with poor UI and errors, but
343 // it's better than the alternative. 343 // it's better than the alternative.
344 // TODO(erikkay) Perhaps we should display errors in developer mode. 344 // TODO(erikkay) Perhaps we should display errors in developer mode.
345 if (params.url.host() != extension_->id()) { 345 if (params.url.host() != extension_id()) {
346 extension_function_dispatcher_.reset(NULL); 346 extension_function_dispatcher_.reset(NULL);
347 return; 347 return;
348 } 348 }
349 349
350 url_ = params.url; 350 url_ = params.url;
351 extension_function_dispatcher_.reset( 351 extension_function_dispatcher_.reset(
352 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_)); 352 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_));
353 } 353 }
354 354
355 void ExtensionHost::InsertInfobarCSS() { 355 void ExtensionHost::InsertInfobarCSS() {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 return window_id; 827 return window_id;
828 } 828 }
829 829
830 void ExtensionHost::OnRunFileChooser( 830 void ExtensionHost::OnRunFileChooser(
831 const ViewHostMsg_RunFileChooser_Params& params) { 831 const ViewHostMsg_RunFileChooser_Params& params) {
832 if (file_select_helper_.get() == NULL) 832 if (file_select_helper_.get() == NULL)
833 file_select_helper_.reset(new FileSelectHelper(profile())); 833 file_select_helper_.reset(new FileSelectHelper(profile()));
834 file_select_helper_->RunFileChooser(render_view_host_, 834 file_select_helper_->RunFileChooser(render_view_host_,
835 associated_tab_contents(), params); 835 associated_tab_contents(), params);
836 } 836 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_process_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698